v0.14.0
add_blockset.cpp
Go to the documentation of this file.
1 /**
2  * \file add_blockset.cpp
3  * \example add_blockset.cpp
4  *
5  * Create blockset and add entities. Next check if entities are in the blockset.
6  *
7  */
8 
9 #include <MoFEM.hpp>
10 
11 using namespace MoFEM;
12 
13 static char help[] = "...\n\n";
14 
15 int main(int argc, char *argv[]) {
16 
17  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
18 
19  try {
20 
21  moab::Core mb_instance;
22  moab::Interface &moab = mb_instance;
23 
24  // Create MoFEM instance
25  MoFEM::Core core(moab);
26  MoFEM::Interface &m_field = core;
27  const char *option = "";
28  CHKERR moab.load_file("rectangle_tri.h5m", 0, option);
29 
30  auto meshsets_mng = m_field.getInterface<MeshsetsManager>();
31 
32  auto get_ents_on_mesh_skin = [&]() {
33  Range faces;
34  CHKERR m_field.get_moab().get_entities_by_type(0, MBTRI, faces);
35  Skinner skin(&m_field.get_moab());
36  Range skin_edges;
37  CHKERR skin.find_skin(0, faces, false, skin_edges);
38  Range skin_verts;
39  CHKERR moab.get_connectivity(skin_edges, skin_verts, true);
40  skin_edges.merge(skin_verts);
41  return skin_edges;
42  };
43 
44  auto add_blockset = [&](const Range skin_ents) {
46  CHKERR meshsets_mng->addMeshset(BLOCKSET, 1);
47  CHKERR meshsets_mng->addEntitiesToMeshset(BLOCKSET, 1, skin_ents);
49  };
50 
51  auto print_blocksets = [&]() {
53  for (auto &it : meshsets_mng->getMeshsetsMultindex())
54  cout << it << endl;
56  };
57 
58  auto check_meshset = [&](const Range skin_ents) {
60  std::vector<EntityHandle> ents(skin_ents.size());
61  std::copy(skin_ents.begin(), skin_ents.end(), ents.begin());
62  const bool test = meshsets_mng->checkIfMeshsetContainsEntities(
63  1, BLOCKSET, &*ents.begin(), ents.size());
64  if (!test)
65  SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
66  "All entities should be in blockset");
68  };
69 
70  auto skin_ents = get_ents_on_mesh_skin();
71  CHKERR add_blockset(skin_ents);
72  CHKERR print_blocksets();
73  CHKERR check_meshset(skin_ents);
74  }
76 
78 }
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Definition: UnknownInterface.hpp:93
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
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
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1975
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
MoFEM::CoreInterface::get_moab
virtual moab::Interface & get_moab()=0
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
Range
help
static char help[]
Definition: add_blockset.cpp:13
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:372
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1094
BLOCKSET
@ BLOCKSET
Definition: definitions.h:148
MoFEM::MeshsetsManager
Interface for managing meshsets containing materials and boundary conditions.
Definition: MeshsetsManager.hpp:104
MOFEM_ATOM_TEST_INVALID
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:40
main
int main(int argc, char *argv[])
Definition: add_blockset.cpp:15
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346