16 {
17
19
20 try {
21
23 PetscBool flg_surf_file = PETSC_FALSE;
25 char mesh_surf_name[255];
26 int surface_side_set = 200;
27 PetscBool flg_vol_block_set;
28 int vol_block_set = 1;
31 PetscBool flg_shift;
32 double shift[] = {0, 0, 0};
33 int nmax = 3;
34 int fraction_level = 2;
35 PetscBool squash_bits = PETSC_TRUE;
36 PetscBool set_coords = PETSC_TRUE;
38 int create_surface_side_set = 201;
39 PetscBool flg_create_surface_side_set;
40 int nb_ref_cut = 0;
41 int nb_ref_trim = 0;
42 PetscBool flg_tol;
43 double tol[] = {1e-2, 2e-1, 2e-1};
44 int nmax_tol = 3;
45 int restricted_side_set = 205;
46 PetscBool
debug = PETSC_FALSE;
47
48 PetscOptionsBegin(PETSC_COMM_WORLD, "", "Mesh cut options", "none");
49 CHKERR PetscOptionsString(
"-my_file",
"mesh file name",
"",
"mesh.h5m",
51 CHKERR PetscOptionsString(
"-my_surface",
"cut mesh file name",
"",
"mesh.h5m",
52 mesh_surf_name, 255, &flg_surf_file);
53 CHKERR PetscOptionsInt(
"-surface_side_set",
"surface side set",
"",
54 surface_side_set, &surface_side_set, PETSC_NULLPTR);
55 CHKERR PetscOptionsInt(
"-vol_block_set",
"volume side set",
"",
56 vol_block_set, &vol_block_set, &flg_vol_block_set);
57 CHKERR PetscOptionsInt(
"-edges_block_set",
"edges block set",
"",
59 CHKERR PetscOptionsInt(
"-vertex_block_set",
"vertex block set",
"",
61 CHKERR PetscOptionsRealArray(
"-shift",
"shift surface by vector",
"", shift,
62 &nmax, &flg_shift);
63 CHKERR PetscOptionsInt(
"-fraction_level",
"fraction of merges merged",
"",
64 fraction_level, &fraction_level, PETSC_NULLPTR);
65 CHKERR PetscOptionsBool(
"-squash_bits",
"true to squash bits at the end",
66 "", squash_bits, &squash_bits, PETSC_NULLPTR);
67 CHKERR PetscOptionsBool(
"-set_coords",
"true to set coords at the end",
"",
68 set_coords, &set_coords, PETSC_NULLPTR);
69 CHKERR PetscOptionsBool(
"-output_vtk",
"if true outout vtk file",
"",
71 CHKERR PetscOptionsInt(
"-create_side_set",
"crete side set",
"",
72 create_surface_side_set, &create_surface_side_set,
73 &flg_create_surface_side_set);
74 CHKERR PetscOptionsInt(
"-nb_ref_cut",
"nb refinements befor cut",
"",
75 nb_ref_cut, &nb_ref_cut, PETSC_NULLPTR);
76 CHKERR PetscOptionsInt(
"-nb_ref_trim",
"nb refinements befor trim",
"",
77 nb_ref_trim, &nb_ref_trim, PETSC_NULLPTR);
78
79 CHKERR PetscOptionsInt(
"-restricted_side_set",
"sideset for constrained surface",
"",
80 restricted_side_set, &restricted_side_set, PETSC_NULLPTR);
81
82 CHKERR PetscOptionsRealArray(
83 "-tol", "tolerances tolCut, tolCutClose, tolTrim, tolTrimClose", "",
84 tol, &nmax_tol, &flg_tol);
85 CHKERR PetscOptionsBool(
"-debug",
"debug (produces many VTK files)",
"",
87 PetscOptionsEnd();
88
91 "*** ERROR -my_file (MESH FILE NEEDED)");
92 }
93 if (flg_shift && nmax != 3) {
95 }
96
97 if (flg_tol && nmax_tol != 3)
99
100 moab::Core mb_instance;
101 moab::Interface &moab = mb_instance;
102 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
103 if (pcomm == NULL)
104 pcomm = new ParallelComm(&moab, PETSC_COMM_WORLD);
105
106 const char *option;
107 option = "";
109
113
114
117
120
123
126 cout << *it << endl;
127 }
128
130
133 if (flg_surf_file) {
134 CHKERR moab.create_meshset(MESHSET_SET, def_set);
135 CHKERR moab.load_file(mesh_surf_name, &def_set, option);
136 CHKERR moab.get_entities_by_dimension(def_set, 2,
surface,
false);
137
140 << "The surface triangles not found. Using the skin.";
141 Skinner skin(&moab);
143 CHKERR moab.get_entities_by_dimension(def_set, 3, ents,
false);
145
146
147 }
148
155 }
156
159
160
161
162
165 else
167 "Side set not found %d", surface_side_set);
168
169
170 Range fixed_edges, corner_nodes;
173 1, fixed_edges, true);
176 1, fixed_edges, true);
180
181
183 if (flg_vol_block_set) {
186 3, tets, true);
187 else
189 "Block set %d not found", vol_block_set);
190 } else
191 CHKERR moab.get_entities_by_dimension(0, 3, tets,
false);
194
197
203 Range intersect_vols;
204
206 cut_edges, 3, false, intersect_vols, moab::Interface::UNION);
209 intersect_vols, 2, false, intersect_adj, moab::Interface::UNION);
211 intersect_adj, 3, false, intersect_vols, moab::Interface::UNION);
212 MOFEM_LOG_C(
"WORLD", Sev::inform,
"Refine %d hexes to tets",
213 intersect_vols.size());
214 CHKERR hex_refine.refineHexToTets(intersect_vols,
216
219 tets = level1;
220 }
221
223 Range restriced_surface;
225 restricted_side_set,
SIDESET, 2, restriced_surface,
true);
227 }
228
231
232
233
235
236
238 "Refine mesh %d times before cut and %d times before trim",
239 nb_ref_cut, nb_ref_trim);
242 auto shift_after_ref = [&]() {
247 mask.set(ll);
251 };
253
254
255 double def_position[] = {0, 0, 0};
257 CHKERR moab.tag_get_handle(
"POSITION", 3, MB_TYPE_DOUBLE,
th,
258 MB_TAG_CREAT | MB_TAG_SPARSE, def_position);
259
261
263
264
266 "Cut mesh, trim surface and merge bad edges on %d levels",
267 fraction_level);
269 tol[1],
tol[2], fixed_edges,
270 corner_nodes, true, false);
271
272
273 if (set_coords)
275
276
277 if (flg_vol_block_set) {
282 }
283
284
285 if (squash_bits) {
288 shift_mask.set(ll);
290 first_bit - 1, shift_mask,
VERBOSE);
291 }
292
296 CHKERR moab.get_adjacencies(cut_mesh->
getSurface(), 1,
false, surface_edges,
297 moab::Interface::UNION);
299 CHKERR moab.delete_entities(surface_edges);
300 CHKERR moab.delete_entities(surface_verts);
301
302 if (flg_create_surface_side_set) {
303
305 create_surface_side_set,
SIDESET))
307 else
309 "Warning >>> sideset %d is on the mesh",
310 create_surface_side_set);
311
314 }
315
316 CHKERR moab.write_file(
"out.h5m");
317
320 CHKERR moab.create_meshset(MESHSET_SET, meshset);
321 if (flg_vol_block_set) {
324 ents, true);
325 CHKERR moab.add_entities(meshset, ents);
326 } else {
330 }
332 CHKERR moab.write_file(
"out.vtk",
"VTK",
"", &meshset, 1);
333 CHKERR moab.delete_entities(&meshset, 1);
334 }
335 }
337
339
340 return 0;
341}
#define MOFEM_LOG_C(channel, severity, format,...)
#define CATCH_ERRORS
Catch errors.
#define MYPCOMM_INDEX
default communicator number PCOMM
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_ATOM_TEST_INVALID
@ MOFEM_DATA_INCONSISTENCY
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
MoFEMErrorCode getEntitiesByDimAndRefLevel(const BitRefLevel bit, const BitRefLevel mask, const int dim, const EntityHandle meshset, int verb=0) const
add all ents from ref level given by bit to meshset
MoFEMErrorCode getEntitiesByTypeAndRefLevel(const BitRefLevel bit, const BitRefLevel mask, const EntityType type, const EntityHandle meshset, int verb=0) const
add all ents from ref level given by bit to meshset
MoFEMErrorCode setBitRefLevelByDim(const EntityHandle meshset, const int dim, const BitRefLevel bit, int verb=QUIET) const
Set the Bit Ref Level By Dim object.
#define MOFEM_LOG(channel, severity)
Log.
MoFEMErrorCode getMeshset(const int ms_id, const unsigned int cubit_bc_type, EntityHandle &meshset) const
get meshset from CUBIT Id and CUBIT type
MoFEMErrorCode addEntitiesToMeshset(const CubitBCType cubit_bc_type, const int ms_id, const Range &ents)
Add entities to CUBIT meshset.
bool checkMeshset(const int ms_id, const CubitBCType cubit_bc_type) const
Check for CUBIT meshset by ID and type.
MoFEMErrorCode addMeshset(const CubitBCType cubit_bc_type, const int ms_id, const std::string name="")
Add CUBIT meshset to manager.
MoFEMErrorCode getEntitiesByDimension(const int ms_id, const unsigned int cubit_bc_type, const int dimension, Range &entities, const bool recursive=true) const
get entities from CUBIT/meshset of a particular entity dimension
#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.
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
auto type_from_handle(const EntityHandle h)
get type from entity handle
virtual moab::Interface & get_moab()=0
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
MoFEMErrorCode copySurface(const Range surface, Tag th=NULL, double *shift=NULL, double *origin=NULL, double *transform=NULL, const std::string save_mesh="")
copy surface entities
const Range & getCutEdges() const
MoFEMErrorCode setCoords(Tag th, const BitRefLevel bit=BitRefLevel(), const BitRefLevel mask=BitRefLevel().set())
set coords from tag
MoFEMErrorCode findEdgesToCut(Range vol, int verb=QUIET, const bool debug=false)
find edges to cut
const Range & getMergedSurfaces() const
MoFEMErrorCode buildTree()
build tree
const Range & getSurface() const
MoFEMErrorCode setConstrainSurface(const Range surf)
Set the constrain surface object.
MoFEMErrorCode setVolume(const Range volume)
set volume entities
MoFEMErrorCode setTagData(Tag th, const BitRefLevel bit=BitRefLevel())
set coords to tag
MoFEMErrorCode cutTrimAndMerge(int &first_bit, const int fraction_level, Tag th, const double tol_geometry, const double tol_cut_close, const double tol_trim_close, Range &fixed_edges, Range &corner_nodes, const bool update_meshsets=false, const bool debug=false)
Cut, trim and merge.
MoFEMErrorCode makeFront(const bool debug=false)
Create front from the surface.
MoFEMErrorCode refineMesh(const int init_bit_level, const int surf_levels, const int front_levels, Range *fixed_edges=nullptr, int verb=QUIET, const bool debug=false)
Refine and set level sets.
MoFEMErrorCode createSurfaceLevelSets(int verb=QUIET, const bool debug=false)
Calculate distance from mesh nodes to cut surface.
Mesh refinement interface.
Interface for managing meshsets containing materials and boundary conditions.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.