v0.14.0
Loading...
Searching...
No Matches
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
12using namespace MoFEM;
13
14static char help[] = "...\n\n";
15
16int 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}
int main()
#define CATCH_ERRORS
Catch errors.
@ H1
continuous field
Definition definitions.h:85
#define MYPCOMM_INDEX
default communicator number PCOMM
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
@ MOFEM_INVALID_DATA
Definition definitions.h:36
#define CHKERR
Inline error check.
static char help[]
virtual const Field_multiIndex * get_fields() const =0
Get the fields object.
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
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.
char mesh_file_name[255]
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition Types.hpp:40
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
constexpr auto field_name
Save field DOFS on vertices/tags.
Managing BitRefLevels.
Core (interface) class.
Definition Core.hpp:82
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
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition Core.cpp:112
Deprecated interface functions.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.