v0.9.1
field_to_vertices.cpp
Go to the documentation of this file.
1 /** \file field_to_vertices.cpp
2  \brief Field to vertices
3  \example field_to_vertices.cpp
4 
5 */
6 
7 /* This file is part of MoFEM.
8  * MoFEM is free software: you can redistribute it and/or modify it under
9  * the terms of the GNU Lesser General Public License as published by the
10  * Free Software Foundation, either version 3 of the License, or (at your
11  * option) any later version.
12  *
13  * MoFEM is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16  * License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>. */
20 
21 #include <MoFEM.hpp>
22 #include <BasicFiniteElements.hpp>
23 
24 using namespace MoFEM;
25 
26 static char help[] = "...\n\n";
27 
28 int main(int argc, char *argv[]) {
29  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
30 
31  try {
32 
33  // global variables
34  char mesh_file_name[255];
35  PetscBool flg_file = PETSC_FALSE;
36  char field_name_param[255] = "RHO";
37  CHKERR PetscOptionsBegin(PETSC_COMM_WORLD, "", "Field to vertices options", "none");
38  CHKERR PetscOptionsString("-my_file", "mesh file name", "", "mesh.h5m",
39  mesh_file_name, 255, &flg_file);
40  CHKERR PetscOptionsString("-my_field", "field name", "", "FIELD",
41  field_name_param, 255, PETSC_NULL);
42  ierr = PetscOptionsEnd(); CHKERRG(ierr);
43 
44  std::string field_name(field_name_param);
45 
46  moab::Core mb_instance;
47  moab::Interface &moab = mb_instance;
48  ParallelComm *pcomm = ParallelComm::get_pcomm(&moab, MYPCOMM_INDEX);
49  if (pcomm == NULL)
50  pcomm = new ParallelComm(&moab, PETSC_COMM_WORLD);
51  const char *option;
52  option = "";
53  CHKERR moab.load_file(mesh_file_name, 0, option);
54 
55  // Create MoFEM database
56  MoFEM::Core core(moab);
57  MoFEM::Interface &m_field = core;
58 
59  if (flg_file != PETSC_TRUE) {
60  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
61  "*** ERROR -my_file (MESH FILE NEEDED)");
62  }
63  BitRefLevel bit_level0;
64  bit_level0.set(0);
65  CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
66  0, 3, bit_level0);
67  CHKERR m_field.build_fields();
68 
69  bool field_flg = false;
70  const Field_multiIndex *fields_ptr;
71  CHKERR m_field.get_fields(&fields_ptr);
72  for(auto field : (*fields_ptr)) {
73  bool check_space = field->getSpace() == H1;
74  if(field->getName() == field_name && check_space) field_flg = true;
75  }
76  if (!field_flg) {
77  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
78  "*** ERROR -my_field (FIELD (in H1 space) is NOT FOUND)");
79  }
80 
81 
82  SaveVertexDofOnTag ent_method(m_field, field_name.c_str());
83 
84  CHKERR m_field.loop_dofs(field_name.c_str(),ent_method);
85  PetscPrintf(PETSC_COMM_WORLD, "\nDone. Saving files... \n");
86 
87  //TODO: Higher order field mapping
88  CHKERR m_field.getInterface<BitRefManager>()->writeBitLevelByType(
89  bit_level0, BitRefLevel().set(), MBTET, "out_mesh.vtk", "VTK", "");
90  CHKERR moab.write_file("out.h5m");
91  }
93 
95 
96  return 0;
97 }
Deprecated interface functions.
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:549
multi_index_container< boost::shared_ptr< Field >, indexed_by< hashed_unique< tag< BitFieldId_mi_tag >, const_mem_fun< Field, const BitFieldId &, &Field::getId >, HashBit< BitFieldId >, EqBit< BitFieldId > >, ordered_unique< tag< Meshset_mi_tag >, member< Field, EntityHandle, &Field::meshSet > >, ordered_unique< tag< FieldName_mi_tag >, const_mem_fun< Field, boost::string_ref, &Field::getNameRef > >, ordered_non_unique< tag< BitFieldId_space_mi_tag >, const_mem_fun< Field, FieldSpace, &Field::getSpace > > > > Field_multiIndex
Field_multiIndex for Field.
int main(int argc, char *argv[])
Core (interface) class.
Definition: Core.hpp:50
Save field DOFS on vertices/tags.
static char help[]
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
char mesh_file_name[255]
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:51
MoFEMErrorCode getInterface(const MOFEMuuid &uuid, IFACE *&iface) const
Get interface by uuid and return reference to pointer of interface.
Managing BitRefLevels.
virtual MoFEMErrorCode loop_dofs(const Problem *problem_ptr, const std::string &field_name, RowColData rc, DofMethod &method, int lower_rank, int upper_rank, int verb=DEFAULT_VERBOSITY)=0
Make a loop over dofs.
#define CHKERR
Inline error check.
Definition: definitions.h:601
#define MYPCOMM_INDEX
default communicator number PCOMM
Definition: definitions.h:290
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:51
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1791
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:438
continuous field
Definition: definitions.h:176
virtual MoFEMErrorCode get_fields(const Field_multiIndex **fields_ptr) const =0
Get fields multi-index from database.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:61