v0.10.0
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  auto fields_ptr = m_field.get_fields();
71  for(auto field : (*fields_ptr)) {
72  bool check_space = field->getSpace() == H1;
73  if(field->getName() == field_name && check_space) field_flg = true;
74  }
75  if (!field_flg) {
76  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
77  "*** ERROR -my_field (FIELD (in H1 space) is NOT FOUND)");
78  }
79 
80 
81  SaveVertexDofOnTag ent_method(m_field, field_name.c_str());
82 
83  CHKERR m_field.loop_dofs(field_name.c_str(),ent_method);
84  PetscPrintf(PETSC_COMM_WORLD, "\nDone. Saving files... \n");
85 
86  //TODO: Higher order field mapping
87  CHKERR m_field.getInterface<BitRefManager>()->writeBitLevelByType(
88  bit_level0, BitRefLevel().set(), MBTET, "out_mesh.vtk", "VTK", "");
89  CHKERR moab.write_file("out.h5m");
90  }
92 
94 
95  return 0;
96 }
Deprecated interface functions.
CoreTmp< 0 > Core
Definition: Core.hpp:1129
virtual const Field_multiIndex * get_fields() const =0
Get the fields object.
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:60
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:552
int main(int argc, char *argv[])
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]
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:604
#define MYPCOMM_INDEX
default communicator number PCOMM
Definition: definitions.h:292
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:1943
Core (interface) class.
Definition: Core.hpp:77
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:441
continuous field
Definition: definitions.h:177
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:100