v0.14.0
crack_mesh_cut.cpp
Go to the documentation of this file.
1 /* This file is part of MoFEM.
2  * MoFEM is free software: you can redistribute it and/or modify it under
3  * the terms of the GNU Lesser General Public License as published by the
4  * Free Software Foundation, either version 3 of the License, or (at your
5  * option) any later version.
6  *
7  * MoFEM is distributed in the hope that it will be useful, but WITHOUT
8  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  * License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>. */
14 
15 #ifdef WITH_TETGEN
16 
17 #include <tetgen.h>
18 #ifdef REAL
19 #undef REAL
20 #endif
21 
22 #endif
23 
24 #include <MoFEM.hpp>
25 using namespace MoFEM;
26 #include <BasicFiniteElements.hpp>
27 #include <Mortar.hpp>
28 #include <NeoHookean.hpp>
29 #include <Hooke.hpp>
30 
31 #include <CrackFrontElement.hpp>
32 #include <ComplexConstArea.hpp>
33 #include <MWLS.hpp>
34 #include <GriffithForceElement.hpp>
35 #include <VolumeLengthQuality.hpp>
36 #include <CrackPropagation.hpp>
37 #include <CPSolvers.hpp>
38 #include <CPMeshCut.hpp>
39 #include <AnalyticalFun.hpp>
40 
41 static char help[] = "Calculate crack release energy and crack propagation"
42  "\n\n";
43 
44 using namespace FractureMechanics;
45 
46 bool CrackPropagation::debug = false;
47 
48 bool CrackPropagation::parallelReadAndBroadcast =
49  false; ///< That is unstable development, for
50  ///< some meshses (propably generated by
51  ///< cubit) this is not working. Error can
52  ///< be attributed to bug in MOAB.
53 
54 int main(int argc, char *argv[]) {
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  }
166  CATCH_ERRORS;
167 
169 
170  return 0;
171 }
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Definition: UnknownInterface.hpp:93
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
EntityHandle
MWLS.hpp
Mortar.hpp
MoFEM.hpp
BasicFiniteElements.hpp
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
FractureMechanics::CPMeshCut
Definition: CPMeshCut.hpp:24
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1975
CPSolvers.hpp
Solvers for crack propagation.
CPMeshCut.hpp
FractureMechanics::CPMeshCut::getCutSurfMeshName
const std::string & getCutSurfMeshName() const
Definition: CPMeshCut.hpp:157
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
Hooke.hpp
Implementation of linear elastic material.
main
int main(int argc, char *argv[])
Definition: crack_mesh_cut.cpp:54
CrackFrontElement.hpp
debug
static const bool debug
Definition: dm_create_subdm.cpp:12
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
AnalyticalFun.hpp
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1094
BITREFLEVEL_SIZE
#define BITREFLEVEL_SIZE
max number of refinements
Definition: definitions.h:219
FractureMechanics::CrackPropagation
Definition: CrackPropagation.hpp:77
help
static char help[]
Definition: crack_mesh_cut.cpp:41
ComplexConstArea.hpp
MoFEM::PetscOptionsGetString
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
Definition: DeprecatedPetsc.hpp:172
VolumeLengthQuality.hpp
Implementation of Volume-Length-Quality measure with barrier.
m
FTensor::Index< 'm', 3 > m
Definition: shallow_wave.cpp:80
MoFEM::BitRefManager
Managing BitRefLevels.
Definition: BitRefManager.hpp:21
CrackPropagation.hpp
Main class for crack propagation.
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
QUIET
@ QUIET
Definition: definitions.h:208
NeoHookean.hpp
Implementation of Neo-Hookean elastic material.
GriffithForceElement.hpp
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
FractureMechanics
Definition: AnalyticalFun.hpp:15
MoFEM::PetscOptionsGetBool
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
Definition: DeprecatedPetsc.hpp:182