v0.14.0
Loading...
Searching...
No Matches
crack_mesh_cut.cpp File Reference
#include <tetgen.h>
#include <MoFEM.hpp>
#include <BasicFiniteElements.hpp>
#include <Mortar.hpp>

Go to the source code of this file.

Functions

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

Variables

static char help []
 

Function Documentation

◆ main()

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

Definition at line 54 of file crack_mesh_cut.cpp.

54 {
55
56 const char param_file[] = "param_file.petsc";
57 MoFEM::Core::Initialize(&argc, &argv, param_file, help);
58
59 try {
60
61 PetscBool flg = PETSC_FALSE;
62 CHKERR PetscOptionsGetBool(PETSC_NULL, "", "-debug", &flg, PETSC_NULL);
63 if (flg == PETSC_TRUE)
65
66 char mesh_file_name[255];
67 CHKERR PetscOptionsGetString(PETSC_NULL, "", "-my_file", mesh_file_name,
68 255, &flg);
69 moab::Core mb_instance;
70 moab::Interface &moab = mb_instance;
71
72 // Read mesh file
73 if (flg) {
74 const char *option;
75 option = "";
76 CHKERR moab.load_file(mesh_file_name, 0, option);
77 }
78
79 // Create mofem database
80 MoFEM::Core core(moab);
81 MoFEM::Interface &m_field = core;
82
83 auto add_last_twenty = [&]() {
85 BitRefLevel mask;
86 for (int ll = 20; ll != BITREFLEVEL_SIZE; ++ll)
87 mask.set(ll);
89 ->addToDatabaseBitRefLevelByType(MBTET, mask, BitRefLevel().set());
91 };
92
93 auto add_first_four = [&]() {
95 BitRefLevel mask;
96 for (int ll = 0; ll != 5; ++ll)
97 mask.set(ll);
99 ->addToDatabaseBitRefLevelByType(MBTET, mask, BitRefLevel().set());
101 };
102
103 CHKERR add_last_twenty();
104 CHKERR add_first_four();
105
108 ->writeEntitiesAllBitLevelsByType(BitRefLevel().set(), MBTET,
109 "all_start.vtk", "VTK", "");
110
111 // Create data structure for crack propagation
112 CrackPropagation cp(m_field);
113 CHKERR cp.getOptions();
114
115 if (string(mesh_file_name).compare(0, 8, "restart_") == 0) {
116 Range ents;
117 CHKERR m_field.getInterface<BitRefManager>()->getAllEntitiesNotInDatabase(
118 ents);
119 if (!ents.empty()) {
120 EntityHandle meshset;
121 CHKERR moab.create_meshset(MESHSET_SET, meshset);
122 CHKERR moab.add_entities(meshset, ents);
123 CHKERR moab.write_file("ents_not_in_database_to_delete.vtk", "VTK", "",
124 &meshset, 1);
125 CHKERR moab.delete_entities(&meshset, 1);
126
127 Range meshsets;
128 CHKERR moab.get_entities_by_type(0, MBENTITYSET, meshsets, false);
129 for (auto m : meshsets)
130 CHKERR moab.remove_entities(m, ents);
131 CHKERR moab.delete_entities(ents);
132 }
133 CHKERR cp.getInterface<CPMeshCut>()->rebuildCrackSurface(
134 cp.crackAccelerationFactor, "cutting_surface.vtk", QUIET,
136
137 CHKERR cp.getInterface<CPMeshCut>()->refineMesh(nullptr, false, QUIET,
139 } else {
140
141 if (!cp.getInterface<CPMeshCut>()->getCutSurfMeshName().empty())
142 CHKERR cp.getInterface<CPMeshCut>()->setCutSurfaceFromFile();
143 CHKERR cp.getInterface<CPMeshCut>()->copySurface("cutting_surface.vtk");
144 Range vol;
145 CHKERR moab.get_entities_by_type(0, MBTET, vol, false);
146 CHKERR cp.getInterface<CPMeshCut>()->refineMesh(&vol, true, QUIET,
148 }
149
150 CHKERR cp.getInterface<CPMeshCut>()->cutRefineAndSplit(
152
153 CHKERR moab.write_mesh("cut_mesh_out.h5m");
154
155 CHKERR core.getInterface<BitRefManager>()->writeBitLevelByType(
156 cp.mapBitLevel["mesh_cut"], BitRefLevel().set(), MBTET,
157 "out_level0.vtk", "VTK", "");
158 CHKERR core.getInterface<BitRefManager>()->writeBitLevelByType(
159 cp.mapBitLevel["spatial_domain"], BitRefLevel().set(), MBTET,
160 "out_level1_tets.vtk", "VTK", "");
161 CHKERR core.getInterface<BitRefManager>()->writeBitLevelByType(
162 cp.mapBitLevel["spatial_domain"], BitRefLevel().set(), MBPRISM,
163 "out_level1_prisms.vtk", "VTK", "");
164
165 }
167
169
170 return 0;
171}
static char help[]
@ QUIET
#define CATCH_ERRORS
Catch errors.
#define BITREFLEVEL_SIZE
max number of refinements
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
char mesh_file_name[255]
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition Types.hpp:40
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
FTensor::Index< 'm', 3 > m
const std::string & getCutSurfMeshName() const
Managing BitRefLevels.
Core (interface) class.
Definition Core.hpp:82
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
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition Core.cpp:112
Deprecated interface functions.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.

Variable Documentation

◆ help

char help[]
static
Initial value:
= "Calculate crack release energy and crack propagation"
"\n\n"

Definition at line 41 of file crack_mesh_cut.cpp.