v0.14.0
mesh_insert_interface_atom.cpp
Go to the documentation of this file.
1 /** \file mesh_insert_interface_atom.cpp
2  \example mesh_insert_interface_atom.cpp
3  \brief Adding prims on the interface
4 
5 */
6 
7 
8 
9 #include <MoFEM.hpp>
10 
11 using namespace MoFEM;
12 
13 static char help[] = "teting interface inserting algorithm\n\n";
14 
15 constexpr bool debug = false;
16 
17 int main(int argc, char *argv[]) {
18 
19  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
20 
21  try {
22 
23  PetscBool flg = PETSC_TRUE;
24  char mesh_file_name[255];
25 #if PETSC_VERSION_GE(3, 6, 4)
26  CHKERR PetscOptionsGetString(PETSC_NULL, "", "-my_file", mesh_file_name,
27  255, &flg);
28 #else
29  CHKERR PetscOptionsGetString(PETSC_NULL, PETSC_NULL, "-my_file",
30  mesh_file_name, 255, &flg);
31 #endif
32  if (flg != PETSC_TRUE) {
33  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
34  "*** ERROR -my_file (MESH FILE NEEDED)");
35  }
36 
37  moab::Core mb_instance;
38  moab::Interface &moab = mb_instance;
39  const char *option;
40  option = "";
41  CHKERR moab.load_file(mesh_file_name, 0, option);
42 
43  MoFEM::Core core(moab);
44  MoFEM::Interface &m_field = core;
45 
46  PrismInterface *interface;
47  CHKERR m_field.getInterface(interface);
48 
49  CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
50  0, 3, BitRefLevel().set(0));
51  std::vector<BitRefLevel> bit_levels;
52  bit_levels.push_back(BitRefLevel().set(0));
53 
54  int ll = 1;
56  CHKERR PetscPrintf(PETSC_COMM_WORLD, "Insert Interface %d\n",
57  cit->getMeshsetId());
58  EntityHandle cubit_meshset = cit->getMeshset();
59  {
60  // get tet enties form back bit_level
61  EntityHandle ref_level_meshset = 0;
62  CHKERR moab.create_meshset(MESHSET_SET, ref_level_meshset);
64  ->getEntitiesByTypeAndRefLevel(bit_levels.back(),
65  BitRefLevel().set(), MBTET,
66  ref_level_meshset);
68  ->getEntitiesByTypeAndRefLevel(bit_levels.back(),
69  BitRefLevel().set(), MBPRISM,
70  ref_level_meshset);
71  Range ref_level_tets;
72  CHKERR moab.get_entities_by_handle(ref_level_meshset, ref_level_tets,
73  true);
74  // get faces and test to split
75  CHKERR interface->getSides(cubit_meshset, bit_levels.back(), true, 0);
76  // set new bit level
77  bit_levels.push_back(BitRefLevel().set(ll++));
78  // split faces and
79  CHKERR interface->splitSides(ref_level_meshset, bit_levels.back(),
80  cubit_meshset, true, true, 0);
81  // clean meshsets
82  CHKERR moab.delete_entities(&ref_level_meshset, 1);
83  }
84  // update cubit meshsets
85  for (_IT_CUBITMESHSETS_FOR_LOOP_(m_field, ciit)) {
86  EntityHandle cubit_meshset = ciit->meshset;
88  ->updateMeshsetByEntitiesChildren(cubit_meshset, bit_levels.back(),
89  cubit_meshset, MBMAXTYPE, true);
90  }
91  }
92 
93  // add fields
94  CHKERR m_field.add_field("H1FIELD_SCALAR", H1, AINSWORTH_LEGENDRE_BASE, 1);
95 
96  // add finite elements
97  CHKERR m_field.add_finite_element("ELEM_SCALAR");
98  CHKERR m_field.modify_finite_element_add_field_row("ELEM_SCALAR",
99  "H1FIELD_SCALAR");
100  CHKERR m_field.modify_finite_element_add_field_col("ELEM_SCALAR",
101  "H1FIELD_SCALAR");
102  CHKERR m_field.modify_finite_element_add_field_data("ELEM_SCALAR",
103  "H1FIELD_SCALAR");
104  // finite element interface
105  CHKERR m_field.add_finite_element("INTERFACE");
106  CHKERR m_field.modify_finite_element_add_field_row("INTERFACE",
107  "H1FIELD_SCALAR");
108  CHKERR m_field.modify_finite_element_add_field_col("INTERFACE",
109  "H1FIELD_SCALAR");
110  CHKERR m_field.modify_finite_element_add_field_data("INTERFACE",
111  "H1FIELD_SCALAR");
112 
113  // add ents to field and set app. order
114  CHKERR m_field.add_ents_to_field_by_type(0, MBTET, "H1FIELD_SCALAR");
115  CHKERR m_field.set_field_order(0, MBVERTEX, "H1FIELD_SCALAR", 1);
116 
117  // add finite elements entities
118  // all TETS and PRIMS are added to finite elements, for testin purposes.
119  // in some practical applications to save memory, you would like to add
120  // elements from particular refinement level (see:
121  // m_field.add_ents_to_finite_element_by_bit_ref(...)
122  CHKERR m_field.add_ents_to_finite_element_by_type(0, MBTET, "ELEM_SCALAR",
123  true);
124  CHKERR m_field.add_ents_to_finite_element_by_type(0, MBPRISM, "INTERFACE",
125  true);
126 
127  // add problems
128  // set problem for all last two levels, only for testing purposes
129  for (int lll = ll - 2; lll < ll; lll++) {
130  std::stringstream problem_name;
131  problem_name << "PROBLEM_SCALAR_" << lll;
132  CHKERR m_field.add_problem(problem_name.str());
133  // define problems and finite elements
134  CHKERR m_field.modify_problem_add_finite_element(problem_name.str(),
135  "ELEM_SCALAR");
136  CHKERR m_field.modify_problem_add_finite_element(problem_name.str(),
137  "INTERFACE");
138  }
139 
140  // set problem level
141  for (int lll = ll - 2; lll < ll; lll++) {
142  std::stringstream problem_name;
143  problem_name << "PROBLEM_SCALAR_" << lll;
144  std::stringstream message;
145  message << "set problem problem < " << problem_name.str()
146  << " > bit level " << bit_levels[lll] << std::endl;
147  CHKERR PetscPrintf(PETSC_COMM_WORLD, message.str().c_str());
148  CHKERR m_field.modify_problem_ref_level_add_bit(problem_name.str(),
149  bit_levels[lll]);
150  }
151 
152  // build fields
153  CHKERR m_field.build_fields();
154  // build finite elements
155  CHKERR m_field.build_finite_elements();
156  // build adjacencies
157  // Its build adjacencies for all elements in database,
158  // for practical applications consider to build adjacencies
159  // only for refinemnt levels which you use for calculations
160  CHKERR m_field.build_adjacencies(BitRefLevel().set());
161 
162  Range tets_back_bit_level;
163  CHKERR m_field.getInterface<BitRefManager>()->getEntitiesByRefLevel(
164  bit_levels.back(), BitRefLevel().set(), tets_back_bit_level);
165 
167 
168  EntityHandle cubit_meshset = cit->getMeshset();
169 
170  BlockSetAttributes mydata;
171  CHKERR cit->getAttributeDataStructure(mydata);
172  std::cout << mydata << std::endl;
173 
174  Range tets;
175  CHKERR moab.get_entities_by_type(cubit_meshset, MBTET, tets, true);
176  tets = intersect(tets_back_bit_level, tets);
177  Range nodes;
178  CHKERR moab.get_connectivity(tets, nodes, true);
179 
180  for (Range::iterator nit = nodes.begin(); nit != nodes.end(); nit++) {
181  double coords[3];
182  CHKERR moab.get_coords(&*nit, 1, coords);
183  coords[0] += mydata.data.User1;
184  coords[1] += mydata.data.User2;
185  coords[2] += mydata.data.User3;
186  CHKERR moab.set_coords(&*nit, 1, coords);
187  }
188  }
189 
190  ProblemsManager *prb_mng_ptr;
191  CHKERR m_field.getInterface(prb_mng_ptr);
192 
193  // partition
194  for (int lll = ll - 2; lll < ll; lll++) {
195  // build problem
196  std::stringstream problem_name;
197  problem_name << "PROBLEM_SCALAR_" << lll;
198  CHKERR prb_mng_ptr->buildProblem(problem_name.str(), true);
199  CHKERR prb_mng_ptr->partitionProblem(problem_name.str());
200  CHKERR prb_mng_ptr->partitionFiniteElements(problem_name.str());
201  CHKERR prb_mng_ptr->partitionGhostDofs(problem_name.str());
202  }
203 
204  std::ofstream myfile;
205  myfile.open((mesh_file_name + std::string("_log")).c_str());
206 
207  EntityHandle out_meshset_tet;
208  CHKERR moab.create_meshset(MESHSET_SET, out_meshset_tet);
209 
210  CHKERR m_field.getInterface<BitRefManager>()->getEntitiesByTypeAndRefLevel(
211  bit_levels.back(), BitRefLevel().set(), MBTET, out_meshset_tet);
212  Range tets;
213  CHKERR moab.get_entities_by_handle(out_meshset_tet, tets, true);
214  for (Range::iterator tit = tets.begin(); tit != tets.end(); tit++) {
215  int num_nodes;
216  const EntityHandle *conn;
217  CHKERR moab.get_connectivity(*tit, conn, num_nodes, true);
218 
219  for (int nn = 0; nn < num_nodes; nn++) {
220  std::cout << conn[nn] << " ";
221  myfile << conn[nn] << " ";
222  }
223  std::cout << std::endl;
224  myfile << std::endl;
225  }
226  EntityHandle out_meshset_prism;
227  CHKERR moab.create_meshset(MESHSET_SET, out_meshset_prism);
228  CHKERR m_field.getInterface<BitRefManager>()->getEntitiesByTypeAndRefLevel(
229  bit_levels.back(), BitRefLevel().set(), MBPRISM, out_meshset_prism);
230  Range prisms;
231  CHKERR moab.get_entities_by_handle(out_meshset_prism, prisms);
232  for (Range::iterator pit = prisms.begin(); pit != prisms.end(); pit++) {
233  int num_nodes;
234  const EntityHandle *conn;
235  CHKERR moab.get_connectivity(*pit, conn, num_nodes, true);
236 
237  for (int nn = 0; nn < num_nodes; nn++) {
238  std::cout << conn[nn] << " ";
239  myfile << conn[nn] << " ";
240  }
241  std::cout << std::endl;
242  myfile << std::endl;
243  }
244  myfile.close();
245 
246  if (debug) {
247  CHKERR moab.write_file("out_tet.vtk", "VTK", "", &out_meshset_tet, 1);
248  CHKERR moab.write_file("out_prism.vtk", "VTK", "", &out_meshset_prism, 1);
249 
250  EntityHandle out_meshset_tets_and_prism;
251  CHKERR moab.create_meshset(MESHSET_SET, out_meshset_tets_and_prism);
252  CHKERR moab.add_entities(out_meshset_tets_and_prism, tets);
253  CHKERR moab.add_entities(out_meshset_tets_and_prism, prisms);
254  CHKERR moab.write_file("out_tets_and_prisms.vtk", "VTK", "",
255  &out_meshset_tets_and_prism, 1);
256 
257  EntityHandle out_meshset_tris;
258  CHKERR moab.create_meshset(MESHSET_SET, out_meshset_tris);
259  Range tris;
260  CHKERR moab.get_adjacencies(prisms, 2, false, tris,
261  moab::Interface::UNION);
262  std::cerr << tris.size() << " : " << prisms.size() << std::endl;
263  CHKERR moab.add_entities(out_meshset_tris, tris);
264  CHKERR moab.write_file("out_tris.vtk", "VTK", "", &out_meshset_tris, 1);
265  }
266  }
267  CATCH_ERRORS;
268 
270 }
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Definition: UnknownInterface.hpp:93
SIDESET
@ SIDESET
Definition: definitions.h:147
MoFEM::ProblemsManager::buildProblem
MoFEMErrorCode buildProblem(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures
Definition: ProblemsManager.cpp:87
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
H1
@ H1
continuous field
Definition: definitions.h:85
EntityHandle
MoFEM::ProblemsManager
Problem manager is used to build and partition problems.
Definition: ProblemsManager.hpp:21
main
int main(int argc, char *argv[])
Definition: mesh_insert_interface_atom.cpp:17
MoFEM::PrismInterface
Create interface from given surface and insert flat prisms in-between.
Definition: PrismInterface.hpp:23
MoFEM::CoreInterface::modify_finite_element_add_field_row
virtual MoFEMErrorCode modify_finite_element_add_field_row(const std::string &fe_name, const std::string name_row)=0
set field row which finite element use
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::CoreInterface::add_ents_to_field_by_type
virtual MoFEMErrorCode add_ents_to_field_by_type(const Range &ents, const EntityType type, const std::string &name, int verb=DEFAULT_VERBOSITY)=0
Add entities to field meshset.
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1975
MoFEM::CoreInterface::add_ents_to_finite_element_by_type
virtual MoFEMErrorCode add_ents_to_finite_element_by_type(const EntityHandle entities, const EntityType type, const std::string &name, const bool recursive=true)=0
add entities to finite element
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
MoFEM::CoreInterface::add_finite_element
virtual MoFEMErrorCode add_finite_element(const std::string &fe_name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
add finite element
MoFEM::BlockSetAttributes
Arbitrary block attributes data structure.
Definition: MaterialBlocks.hpp:81
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
MoFEM::CoreInterface::modify_finite_element_add_field_col
virtual MoFEMErrorCode modify_finite_element_add_field_col(const std::string &fe_name, const std::string name_row)=0
set field col which finite element use
MoFEM::CoreInterface::build_finite_elements
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
MoFEM::CoreInterface::add_field
virtual MoFEMErrorCode add_field(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_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add field.
MoFEM::PrismInterface::splitSides
MoFEMErrorCode splitSides(const EntityHandle meshset, const BitRefLevel &bit, const int msId, const CubitBCType cubit_bc_type, const bool add_interface_entities, const bool recursive=false, int verb=QUIET)
Split nodes and other entities of tetrahedra on both sides of the interface and insert flat prisms in...
Definition: PrismInterface.cpp:519
MoFEM::ProblemsManager::partitionFiniteElements
MoFEMErrorCode partitionFiniteElements(const std::string name, bool part_from_moab=false, int low_proc=-1, int hi_proc=-1, int verb=VERBOSE)
partition finite elements
Definition: ProblemsManager.cpp:2167
MoFEM::CoreInterface::modify_problem_ref_level_add_bit
virtual MoFEMErrorCode modify_problem_ref_level_add_bit(const std::string &name_problem, const BitRefLevel &bit)=0
add ref level to problem
mesh_file_name
char mesh_file_name[255]
Definition: mesh_smoothing.cpp:23
Range
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
_IT_CUBITMESHSETS_BY_SET_TYPE_FOR_LOOP_
#define _IT_CUBITMESHSETS_BY_SET_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet having a particular BC meshset in a moFEM field.
Definition: MeshsetsManager.hpp:71
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1094
MoFEM::PrismInterface::getSides
MoFEMErrorCode getSides(const int msId, const CubitBCType cubit_bc_type, const BitRefLevel mesh_bit_level, const bool recursive, int verb=QUIET)
Store tetrahedra from each side of the interface separately in two child meshsets of the parent meshs...
Definition: PrismInterface.cpp:56
help
static char help[]
Definition: mesh_insert_interface_atom.cpp:13
BLOCKSET
@ BLOCKSET
Definition: definitions.h:148
AINSWORTH_LEGENDRE_BASE
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:60
MoFEM::PetscOptionsGetString
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
Definition: DeprecatedPetsc.hpp:172
MoFEM::CoreInterface::build_fields
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
MoFEM::CoreInterface::modify_finite_element_add_field_data
virtual MoFEMErrorCode modify_finite_element_add_field_data(const std::string &fe_name, const std::string name_filed)=0
set finite element field data
debug
constexpr bool debug
Definition: mesh_insert_interface_atom.cpp:15
_IT_CUBITMESHSETS_FOR_LOOP_
#define _IT_CUBITMESHSETS_FOR_LOOP_(MESHSET_MANAGER, IT)
Iterator that loops over all the Cubit MeshSets in a moFEM field.
Definition: MeshsetsManager.hpp:34
MoFEM::BitRefManager
Managing BitRefLevels.
Definition: BitRefManager.hpp:21
MoFEM::CoreInterface::modify_problem_add_finite_element
virtual MoFEMErrorCode modify_problem_add_finite_element(const std::string name_problem, const std::string &fe_name)=0
add finite element to problem, this add entities assigned to finite element to a particular problem
MoFEM::BlockSetAttributes::data
_data_ data
Definition: MaterialBlocks.hpp:97
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
MoFEM::CoreInterface::build_adjacencies
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
MoFEM::CoreInterface::set_field_order
virtual MoFEMErrorCode set_field_order(const EntityHandle meshset, const EntityType type, const std::string &name, const ApproximationOrder order, int verb=DEFAULT_VERBOSITY)=0
Set order approximation of the entities in the field.
MoFEM::ProblemsManager::partitionGhostDofs
MoFEMErrorCode partitionGhostDofs(const std::string name, int verb=VERBOSE)
determine ghost nodes
Definition: ProblemsManager.cpp:2339
MoFEM::CoreInterface::add_problem
virtual MoFEMErrorCode add_problem(const std::string &name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add problem.
MOFEM_INVALID_DATA
@ MOFEM_INVALID_DATA
Definition: definitions.h:36
MoFEM::ProblemsManager::partitionProblem
MoFEMErrorCode partitionProblem(const std::string name, int verb=VERBOSE)
partition problem dofs (collective)
Definition: ProblemsManager.cpp:1683