v0.14.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 
8 
9 #include <MoFEM.hpp>
10 #include <SaveVertexDofOnTag.hpp>
11 
12 using namespace MoFEM;
13 
14 static char help[] = "...\n\n";
15 
16 int main(int argc, char *argv[]) {
17  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
18 
19  try {
20 
21  // global variables
22  char mesh_file_name[255];
23  PetscBool flg_file = PETSC_FALSE;
24  char field_name_param[255] = "RHO";
25  CHKERR PetscOptionsBegin(PETSC_COMM_WORLD, "", "Field to vertices options", "none");
26  CHKERR PetscOptionsString("-my_file", "mesh file name", "", "mesh.h5m",
27  mesh_file_name, 255, &flg_file);
28  CHKERR PetscOptionsString("-my_field", "field name", "", "FIELD",
29  field_name_param, 255, PETSC_NULL);
30  ierr = PetscOptionsEnd(); CHKERRG(ierr);
31 
32  std::string field_name(field_name_param);
33 
34  moab::Core mb_instance;
35  moab::Interface &moab = mb_instance;
36  ParallelComm *pcomm = ParallelComm::get_pcomm(&moab, MYPCOMM_INDEX);
37  if (pcomm == NULL)
38  pcomm = new ParallelComm(&moab, PETSC_COMM_WORLD);
39  const char *option;
40  option = "";
41  CHKERR moab.load_file(mesh_file_name, 0, option);
42 
43  // Create MoFEM database
44  MoFEM::Core core(moab);
45  MoFEM::Interface &m_field = core;
46 
47  if (flg_file != PETSC_TRUE) {
48  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
49  "*** ERROR -my_file (MESH FILE NEEDED)");
50  }
51  BitRefLevel bit_level0;
52  bit_level0.set(0);
53  CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
54  0, 3, bit_level0);
55  CHKERR m_field.build_fields();
56 
57  bool field_flg = false;
58  auto fields_ptr = m_field.get_fields();
59  for(auto field : (*fields_ptr)) {
60  bool check_space = field->getSpace() == H1;
61  if(field->getName() == field_name && check_space) field_flg = true;
62  }
63  if (!field_flg) {
64  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
65  "*** ERROR -my_field (FIELD (in H1 space) is NOT FOUND)");
66  }
67 
68 
69  BasicFiniteElements::SaveVertexDofOnTag ent_method(m_field, field_name.c_str());
70 
71  CHKERR m_field.loop_dofs(field_name.c_str(),ent_method);
72  PetscPrintf(PETSC_COMM_WORLD, "\nDone. Saving files... \n");
73 
74  //TODO: Higher order field mapping
75  CHKERR m_field.getInterface<BitRefManager>()->writeBitLevelByType(
76  bit_level0, BitRefLevel().set(), MBTET, "out_mesh.vtk", "VTK", "");
77  CHKERR moab.write_file("out.h5m");
78  }
80 
82 
83  return 0;
84 }
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Definition: UnknownInterface.hpp:93
MYPCOMM_INDEX
#define MYPCOMM_INDEX
default communicator number PCOMM
Definition: definitions.h:228
MoFEM::CoreInterface::loop_dofs
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.
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
H1
@ H1
continuous field
Definition: definitions.h:85
MoFEM.hpp
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
main
int main(int argc, char *argv[])
Definition: field_to_vertices.cpp:16
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:2010
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
field_name
constexpr auto field_name
Definition: poisson_2d_homogeneous.cpp:13
mesh_file_name
char mesh_file_name[255]
Definition: mesh_smoothing.cpp:22
MoFEM::CoreInterface::get_fields
virtual const Field_multiIndex * get_fields() const =0
Get the fields object.
help
static char help[]
Definition: field_to_vertices.cpp:14
BasicFiniteElements::SaveVertexDofOnTag
Save field DOFS on vertices/tags.
Definition: SaveVertexDofOnTag.hpp:21
MoFEM::CoreTmp< 0 >::Initialize
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:72
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:385
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1148
MoFEM::Exceptions::ierr
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Exceptions.hpp:76
MoFEM::CoreInterface::build_fields
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
MoFEM::BitRefManager
Managing BitRefLevels.
Definition: BitRefManager.hpp:21
MoFEM::Types::BitRefLevel
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:40
CHKERRG
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:496
MOFEM_INVALID_DATA
@ MOFEM_INVALID_DATA
Definition: definitions.h:36