16int main(
int argc,
char *argv[]) {
22 PetscBool flg_myfile = PETSC_TRUE;
23 PetscBool flg_surf_file = PETSC_FALSE;
24 char mesh_file_name[255];
25 char mesh_surf_name[255];
26 int surface_side_set = 200;
27 PetscBool flg_vol_block_set;
28 int vol_block_set = 1;
32 double shift[] = {0, 0, 0};
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;
43 double tol[] = {1e-2, 2e-1, 2e-1};
45 int restricted_side_set = 205;
46 PetscBool
debug = PETSC_FALSE;
48 PetscOptionsBegin(PETSC_COMM_WORLD,
"",
"Mesh cut options",
"none");
49 CHKERR PetscOptionsString(
"-my_file",
"mesh file name",
"",
"mesh.h5m",
50 mesh_file_name, 255, &flg_myfile);
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,
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);
79 CHKERR PetscOptionsInt(
"-restricted_side_set",
"sideset for constrained surface",
"",
80 restricted_side_set, &restricted_side_set, PETSC_NULLPTR);
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)",
"",
89 if (flg_myfile != PETSC_TRUE) {
91 "*** ERROR -my_file (MESH FILE NEEDED)");
93 if (flg_shift && nmax != 3) {
97 if (flg_tol && nmax_tol != 3)
100 moab::Core mb_instance;
101 moab::Interface &moab = mb_instance;
102 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
104 pcomm =
new ParallelComm(&moab, PETSC_COMM_WORLD);
108 CHKERR moab.load_file(mesh_file_name, 0, option);
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);
140 <<
"The surface triangles not found. Using the skin.";
143 CHKERR moab.get_entities_by_dimension(def_set, 3, ents,
false);
167 "Side set not found %d", surface_side_set);
170 Range fixed_edges, corner_nodes;
173 1, fixed_edges,
true);
176 1, fixed_edges,
true);
183 if (flg_vol_block_set) {
189 "Block set %d not found", vol_block_set);
191 CHKERR moab.get_entities_by_dimension(0, 3, tets,
false);
203 Range intersect_vols;
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());
223 Range restriced_surface;
225 restricted_side_set,
SIDESET, 2, restriced_surface,
true);
238 "Refine mesh %d times before cut and %d times before trim",
239 nb_ref_cut, nb_ref_trim);
242 auto shift_after_ref = [&]() {
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);
266 "Cut mesh, trim surface and merge bad edges on %d levels",
269 tol[1],
tol[2], fixed_edges,
270 corner_nodes,
true,
false);
277 if (flg_vol_block_set) {
290 first_bit - 1, shift_mask,
VERBOSE);
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);
302 if (flg_create_surface_side_set) {
305 create_surface_side_set,
SIDESET))
309 "Warning >>> sideset %d is on the mesh",
310 create_surface_side_set);
316 CHKERR moab.write_file(
"out.h5m");
320 CHKERR moab.create_meshset(MESHSET_SET, meshset);
321 if (flg_vol_block_set) {
325 CHKERR moab.add_entities(meshset, ents);
332 CHKERR moab.write_file(
"out.vtk",
"VTK",
"", &meshset, 1);
333 CHKERR moab.delete_entities(&meshset, 1);