v0.14.0
Loading...
Searching...
No Matches
loop_entities.cpp
Go to the documentation of this file.
1/** \file loop_entities.cpp
2 \example loop_entities.cpp
3 \brief Make a loop over entities
4
5*/
6
7
8
9#include <MoFEM.hpp>
10
11using namespace MoFEM;
12
13static char help[] = "...\n\n";
14
17 : EntityMethod(), allEnts(ents) {}
18
21 entsIt = allEnts.begin();
23 }
24
27 if (entPtr->getEnt() != *entsIt)
28 SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
29 "Entity and entity iterator should be the same");
30 ++entsIt;
32 }
33
36 if(entsIt != allEnts.end())
37 SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
38 "All entities should be iterated");
40 }
41
42private:
44 Range::const_iterator entsIt;
45};
46
47int main(int argc, char *argv[]) {
48 // initialize petsc
49 MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
50
51 try {
52
53 // read mesh and create moab and mofem data structures
54 moab::Core mb_instance;
55 moab::Interface &moab = mb_instance;
56
57 MoFEM::Core core(moab, PETSC_COMM_WORLD);
58 MoFEM::Interface &m_field = core;
59
60 // Register DM Manager
61 DMType dm_name = "DMMOFEM";
62 CHKERR DMRegister_MoFEM(dm_name);
63
64 EntityHandle root_set = moab.get_root_set();
65
66 // Simple interface
67 Simple *simple_interface;
68 CHKERR m_field.getInterface(simple_interface);
69 {
70 // get options from command line
71 CHKERR simple_interface->getOptions();
72 // load mesh file
73 CHKERR simple_interface->loadFile();
74 // add fields
75 CHKERR simple_interface->addDomainField("FIELD1", H1,
77 // set fields order
78 CHKERR simple_interface->setFieldOrder("FIELD1", 4);
79 // setup problem
80 CHKERR simple_interface->setUp();
81
82 Range all_ents;
83 CHKERR m_field.get_moab().get_entities_by_handle(root_set, all_ents);
84 all_ents = subtract(all_ents, all_ents.subset_by_type(MBENTITYSET));
85
86 auto testingEntitiesInDatabase = [&]() {
88 TestEntityMethod method(all_ents);
89 CHKERR m_field.loop_entities("FIELD1", method);
91 };
92
93 CHKERR testingEntitiesInDatabase();
94
95 auto testingEntitiesInDatabaseSubRange = [&]() {
97 Range edges = all_ents.subset_by_type(MBEDGE);
98 TestEntityMethod method(edges);
99 CHKERR m_field.loop_entities("FIELD1", method, &edges);
101 };
102
103 CHKERR testingEntitiesInDatabaseSubRange();
104
105 auto dm = simple_interface->getDM();
106
107 auto testingEntitiesInDM = [&]() {
109 TestEntityMethod method(all_ents);
110 const MoFEM::Problem *prb_ptr;
111 CHKERR DMMoFEMGetProblemPtr(dm, &prb_ptr);
112 CHKERR m_field.loop_entities(prb_ptr, "FIELD1", ROW, method, 0,
113 m_field.get_comm_size());
115 };
116
117 CHKERR testingEntitiesInDM();
118
119 }
120 }
122
123 // finish work cleaning memory, getting statistics, ect.
125
126 return 0;
127}
int main()
Definition: adol-c_atom.cpp:46
@ ROW
Definition: definitions.h:123
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:372
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:60
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
@ H1
continuous field
Definition: definitions.h:85
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:40
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
#define CHKERR
Inline error check.
Definition: definitions.h:535
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:440
PetscErrorCode DMMoFEMGetProblemPtr(DM dm, const MoFEM::Problem **problem_ptr)
Get pointer to problem data structure.
Definition: DMMoFEM.cpp:412
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition: DMMoFEM.cpp:47
virtual MoFEMErrorCode loop_entities(const std::string field_name, EntityMethod &method, Range const *const ents=nullptr, int verb=DEFAULT_VERBOSITY)=0
Loop over field entities.
static char help[]
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
virtual int get_comm_size() const =0
virtual moab::Interface & get_moab()=0
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.
Data structure to exchange data between mofem and User Loop Methods on entities.
boost::shared_ptr< FieldEntity > entPtr
keeps basic data about problem
Simple interface for fast problem set-up.
Definition: Simple.hpp:27
MoFEMErrorCode loadFile(const std::string options, const std::string mesh_file_name, LoadFileFunc loadFunc=defaultLoadFileFunc)
Load mesh file.
Definition: Simple.cpp:194
MoFEMErrorCode addDomainField(const std::string &name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add field on domain.
Definition: Simple.cpp:264
MoFEMErrorCode getOptions()
get options
Definition: Simple.cpp:180
MoFEMErrorCode getDM(DM *dm)
Get DM.
Definition: Simple.cpp:667
MoFEMErrorCode setFieldOrder(const std::string field_name, const int order, const Range *ents=NULL)
Set field order.
Definition: Simple.cpp:473
MoFEMErrorCode setUp(const PetscBool is_partitioned=PETSC_TRUE)
Setup problem.
Definition: Simple.cpp:611
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
MoFEMErrorCode operator()()
function is run for every finite element
TestEntityMethod(const Range &ents)
MoFEMErrorCode preProcess()
function is run at the beginning of loop
MoFEMErrorCode postProcess()
function is run at the end of loop
Range::const_iterator entsIt
const Range allEnts