v0.10.0
Functions | Variables
mesh_insert_interface_atom.cpp File Reference
#include <MoFEM.hpp>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Variables

static char help [] = "teting interface inserting algorithm\n\n"
 
constexpr bool debug = false
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)
Examples
mesh_insert_interface_atom.cpp.

Definition at line 29 of file mesh_insert_interface_atom.cpp.

29  {
30 
31  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
32 
33  try {
34 
35  PetscBool flg = PETSC_TRUE;
36  char mesh_file_name[255];
37 #if PETSC_VERSION_GE(3, 6, 4)
38  CHKERR PetscOptionsGetString(PETSC_NULL, "", "-my_file", mesh_file_name,
39  255, &flg);
40 #else
41  CHKERR PetscOptionsGetString(PETSC_NULL, PETSC_NULL, "-my_file",
42  mesh_file_name, 255, &flg);
43 #endif
44  if (flg != PETSC_TRUE) {
45  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
46  "*** ERROR -my_file (MESH FILE NEEDED)");
47  }
48 
49  moab::Core mb_instance;
50  moab::Interface &moab = mb_instance;
51  const char *option;
52  option = "";
53  CHKERR moab.load_file(mesh_file_name, 0, option);
54  ParallelComm *pcomm = ParallelComm::get_pcomm(&moab, MYPCOMM_INDEX);
55  if (pcomm == NULL)
56  pcomm = new ParallelComm(&moab, PETSC_COMM_WORLD);
57 
58  MoFEM::Core core(moab);
59  MoFEM::Interface &m_field = core;
60 
61  PrismInterface *interface;
62  CHKERR m_field.getInterface(interface);
63 
64  CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
65  0, 3, BitRefLevel().set(0));
66  std::vector<BitRefLevel> bit_levels;
67  bit_levels.push_back(BitRefLevel().set(0));
68 
69  int ll = 1;
71  CHKERR PetscPrintf(PETSC_COMM_WORLD, "Insert Interface %d\n",
72  cit->getMeshsetId());
73  EntityHandle cubit_meshset = cit->getMeshset();
74  {
75  // get tet enties form back bit_level
76  EntityHandle ref_level_meshset = 0;
77  CHKERR moab.create_meshset(MESHSET_SET, ref_level_meshset);
79  ->getEntitiesByTypeAndRefLevel(bit_levels.back(),
80  BitRefLevel().set(), MBTET,
81  ref_level_meshset);
83  ->getEntitiesByTypeAndRefLevel(bit_levels.back(),
84  BitRefLevel().set(), MBPRISM,
85  ref_level_meshset);
86  Range ref_level_tets;
87  CHKERR moab.get_entities_by_handle(ref_level_meshset, ref_level_tets,
88  true);
89  // get faces and test to split
90  CHKERR interface->getSides(cubit_meshset, bit_levels.back(), true, 0);
91  // set new bit level
92  bit_levels.push_back(BitRefLevel().set(ll++));
93  // split faces and
94  CHKERR interface->splitSides(ref_level_meshset, bit_levels.back(),
95  cubit_meshset, true, true, 0);
96  // clean meshsets
97  CHKERR moab.delete_entities(&ref_level_meshset, 1);
98  }
99  // update cubit meshsets
100  for (_IT_CUBITMESHSETS_FOR_LOOP_(m_field, ciit)) {
101  EntityHandle cubit_meshset = ciit->meshset;
103  ->updateMeshsetByEntitiesChildren(cubit_meshset, bit_levels.back(),
104  cubit_meshset, MBVERTEX, true);
106  ->updateMeshsetByEntitiesChildren(cubit_meshset, bit_levels.back(),
107  cubit_meshset, MBEDGE, true);
109  ->updateMeshsetByEntitiesChildren(cubit_meshset, bit_levels.back(),
110  cubit_meshset, MBTRI, true);
112  ->updateMeshsetByEntitiesChildren(cubit_meshset, bit_levels.back(),
113  cubit_meshset, MBTET, true);
114  }
115  }
116 
117  // add fields
118  CHKERR m_field.add_field("H1FIELD_SCALAR", H1, AINSWORTH_LEGENDRE_BASE, 1);
119 
120  // add finite elements
121  CHKERR m_field.add_finite_element("ELEM_SCALAR");
122  CHKERR m_field.modify_finite_element_add_field_row("ELEM_SCALAR",
123  "H1FIELD_SCALAR");
124  CHKERR m_field.modify_finite_element_add_field_col("ELEM_SCALAR",
125  "H1FIELD_SCALAR");
126  CHKERR m_field.modify_finite_element_add_field_data("ELEM_SCALAR",
127  "H1FIELD_SCALAR");
128  // finite element interface
129  CHKERR m_field.add_finite_element("INTERFACE");
130  CHKERR m_field.modify_finite_element_add_field_row("INTERFACE",
131  "H1FIELD_SCALAR");
132  CHKERR m_field.modify_finite_element_add_field_col("INTERFACE",
133  "H1FIELD_SCALAR");
134  CHKERR m_field.modify_finite_element_add_field_data("INTERFACE",
135  "H1FIELD_SCALAR");
136 
137  // add ents to field and set app. order
138  CHKERR m_field.add_ents_to_field_by_type(0, MBTET, "H1FIELD_SCALAR");
139  CHKERR m_field.set_field_order(0, MBVERTEX, "H1FIELD_SCALAR", 1);
140 
141  // add finite elements entities
142  // all TETS and PRIMS are added to finite elements, for testin purposes.
143  // in some practical applications to save memory, you would like to add
144  // elements from particular refinement level (see:
145  // m_field.add_ents_to_finite_element_by_bit_ref(...)
146  CHKERR m_field.add_ents_to_finite_element_by_type(0, MBTET, "ELEM_SCALAR",
147  true);
148  CHKERR m_field.add_ents_to_finite_element_by_type(0, MBPRISM, "INTERFACE",
149  true);
150 
151  // add problems
152  // set problem for all last two levels, only for testing purposes
153  for (int lll = ll - 2; lll < ll; lll++) {
154  std::stringstream problem_name;
155  problem_name << "PROBLEM_SCALAR_" << lll;
156  CHKERR m_field.add_problem(problem_name.str());
157  // define problems and finite elements
158  CHKERR m_field.modify_problem_add_finite_element(problem_name.str(),
159  "ELEM_SCALAR");
160  CHKERR m_field.modify_problem_add_finite_element(problem_name.str(),
161  "INTERFACE");
162  }
163 
164  // set problem level
165  for (int lll = ll - 2; lll < ll; lll++) {
166  std::stringstream problem_name;
167  problem_name << "PROBLEM_SCALAR_" << lll;
168  std::stringstream message;
169  message << "set problem problem < " << problem_name.str()
170  << " > bit level " << bit_levels[lll] << std::endl;
171  CHKERR PetscPrintf(PETSC_COMM_WORLD, message.str().c_str());
172  CHKERR m_field.modify_problem_ref_level_add_bit(problem_name.str(),
173  bit_levels[lll]);
174  }
175 
176  // build fields
177  CHKERR m_field.build_fields();
178  // build finite elements
179  CHKERR m_field.build_finite_elements();
180  // build adjacencies
181  // Its build adjacencies for all elements in database,
182  // for practical applications consider to build adjacencies
183  // only for refinemnt levels which you use for calculations
184  CHKERR m_field.build_adjacencies(BitRefLevel().set());
185 
186  Range tets_back_bit_level;
187  CHKERR m_field.getInterface<BitRefManager>()->getEntitiesByRefLevel(
188  bit_levels.back(), BitRefLevel().set(), tets_back_bit_level);
189 
191 
192  EntityHandle cubit_meshset = cit->getMeshset();
193 
194  BlockSetAttributes mydata;
195  CHKERR cit->getAttributeDataStructure(mydata);
196  std::cout << mydata << std::endl;
197 
198  Range tets;
199  CHKERR moab.get_entities_by_type(cubit_meshset, MBTET, tets, true);
200  tets = intersect(tets_back_bit_level, tets);
201  Range nodes;
202  CHKERR moab.get_connectivity(tets, nodes, true);
203 
204  for (Range::iterator nit = nodes.begin(); nit != nodes.end(); nit++) {
205  double coords[3];
206  CHKERR moab.get_coords(&*nit, 1, coords);
207  coords[0] += mydata.data.User1;
208  coords[1] += mydata.data.User2;
209  coords[2] += mydata.data.User3;
210  CHKERR moab.set_coords(&*nit, 1, coords);
211  }
212  }
213 
214  ProblemsManager *prb_mng_ptr;
215  CHKERR m_field.getInterface(prb_mng_ptr);
216 
217  // partition
218  for (int lll = ll - 2; lll < ll; lll++) {
219  // build problem
220  std::stringstream problem_name;
221  problem_name << "PROBLEM_SCALAR_" << lll;
222  CHKERR prb_mng_ptr->buildProblem(problem_name.str(), true);
223  CHKERR prb_mng_ptr->partitionProblem(problem_name.str());
224  CHKERR prb_mng_ptr->partitionFiniteElements(problem_name.str());
225  CHKERR prb_mng_ptr->partitionGhostDofs(problem_name.str());
226  }
227 
228  std::ofstream myfile;
229  myfile.open((mesh_file_name + std::string("_log")).c_str());
230 
231  EntityHandle out_meshset_tet;
232  CHKERR moab.create_meshset(MESHSET_SET, out_meshset_tet);
233 
234  CHKERR m_field.getInterface<BitRefManager>()->getEntitiesByTypeAndRefLevel(
235  bit_levels.back(), BitRefLevel().set(), MBTET, out_meshset_tet);
236  Range tets;
237  CHKERR moab.get_entities_by_handle(out_meshset_tet, tets, true);
238  for (Range::iterator tit = tets.begin(); tit != tets.end(); tit++) {
239  int num_nodes;
240  const EntityHandle *conn;
241  CHKERR moab.get_connectivity(*tit, conn, num_nodes, true);
242 
243  for (int nn = 0; nn < num_nodes; nn++) {
244  std::cout << conn[nn] << " ";
245  myfile << conn[nn] << " ";
246  }
247  std::cout << std::endl;
248  myfile << std::endl;
249  }
250  EntityHandle out_meshset_prism;
251  CHKERR moab.create_meshset(MESHSET_SET, out_meshset_prism);
252  CHKERR m_field.getInterface<BitRefManager>()->getEntitiesByTypeAndRefLevel(
253  bit_levels.back(), BitRefLevel().set(), MBPRISM, out_meshset_prism);
254  Range prisms;
255  CHKERR moab.get_entities_by_handle(out_meshset_prism, prisms);
256  for (Range::iterator pit = prisms.begin(); pit != prisms.end(); pit++) {
257  int num_nodes;
258  const EntityHandle *conn;
259  CHKERR moab.get_connectivity(*pit, conn, num_nodes, true);
260 
261  for (int nn = 0; nn < num_nodes; nn++) {
262  std::cout << conn[nn] << " ";
263  myfile << conn[nn] << " ";
264  }
265  std::cout << std::endl;
266  myfile << std::endl;
267  }
268  myfile.close();
269 
270  if (debug) {
271  CHKERR moab.write_file("out_tet.vtk", "VTK", "", &out_meshset_tet, 1);
272  CHKERR moab.write_file("out_prism.vtk", "VTK", "", &out_meshset_prism, 1);
273 
274  EntityHandle out_meshset_tets_and_prism;
275  CHKERR moab.create_meshset(MESHSET_SET, out_meshset_tets_and_prism);
276  CHKERR moab.add_entities(out_meshset_tets_and_prism, tets);
277  CHKERR moab.add_entities(out_meshset_tets_and_prism, prisms);
278  CHKERR moab.write_file("out_tets_and_prisms.vtk", "VTK", "",
279  &out_meshset_tets_and_prism, 1);
280 
281  EntityHandle out_meshset_tris;
282  CHKERR moab.create_meshset(MESHSET_SET, out_meshset_tris);
283  Range tris;
284  CHKERR moab.get_adjacencies(prisms, 2, false, tris,
285  moab::Interface::UNION);
286  std::cerr << tris.size() << " : " << prisms.size() << std::endl;
287  CHKERR moab.add_entities(out_meshset_tris, tris);
288  CHKERR moab.write_file("out_tris.vtk", "VTK", "", &out_meshset_tris, 1);
289  }
290  }
291  CATCH_ERRORS;
292 
294 }

Variable Documentation

◆ debug

constexpr bool debug = false
constexpr

◆ help

char help[] = "teting interface inserting algorithm\n\n"
static
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:26
EntityHandle
SIDESET
@ SIDESET
Definition: definitions.h:216
MoFEM::CoreInterface::build_adjacencies
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
MYPCOMM_INDEX
#define MYPCOMM_INDEX
default communicator number PCOMM
Definition: definitions.h:292
MoFEM::ProblemsManager::buildProblem
MoFEMErrorCode buildProblem(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures
Definition: ProblemsManager.cpp:428
H1
@ H1
continuous field
Definition: definitions.h:177
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:50
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::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::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::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1943
MoFEM::PetscOptionsGetString
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
Definition: DeprecatedPetsc.hpp:183
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::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:604
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::CoreInterface::build_finite_elements
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
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::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:60
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
MoFEM::ProblemsManager
Problem manager is used to build and partition problems.
Definition: ProblemsManager.hpp:34
MoFEM::Types::BitRefLevel
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:51
MoFEM::BlockSetAttributes
Arbitrary block attributes data structure.
Definition: MaterialBlocks.hpp:94
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:2416
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
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:77
MoFEM::PrismInterface
Create interface from given surface and insert flat prisms in-between.
Definition: PrismInterface.hpp:36
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:100
mesh_file_name
char mesh_file_name[255]
Definition: mesh_smoothing.cpp:35
MoFEM::BlockSetAttributes::data
_data_ data
Definition: MaterialBlocks.hpp:110
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:441
_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:91
help
static char help[]
Definition: mesh_insert_interface_atom.cpp:25
BLOCKSET
@ BLOCKSET
Definition: definitions.h:217
MoFEM::BitRefManager
Managing BitRefLevels.
Definition: BitRefManager.hpp:34
AINSWORTH_LEGENDRE_BASE
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:152
MoFEM::CoreInterface::build_fields
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
debug
constexpr bool debug
Definition: mesh_insert_interface_atom.cpp:27
_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:54
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:2599
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::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1129
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:520
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(const MOFEMuuid &uuid, IFACE *&iface) const
Get interface by uuid and return reference to pointer of interface.
Definition: UnknownInterface.hpp:130
MOFEM_INVALID_DATA
@ MOFEM_INVALID_DATA
Definition: definitions.h:128
MoFEM::ProblemsManager::partitionProblem
MoFEMErrorCode partitionProblem(const std::string name, int verb=VERBOSE)
partition problem dofs (collective)
Definition: ProblemsManager.cpp:1954