v0.14.0
Loading...
Searching...
No Matches
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>
25using namespace MoFEM;
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>
35#include <VolumeLengthQuality.hpp>
36#include <CrackPropagation.hpp>
37#include <CPSolvers.hpp>
38#include <CPMeshCut.hpp>
39#include <AnalyticalFun.hpp>
40
41static char help[] = "Calculate crack release energy and crack propagation"
42 "\n\n";
43
44using namespace FractureMechanics;
45
46bool CrackPropagation::debug = false;
47
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
54int 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 }
167
169
170 return 0;
171}
Solvers for crack propagation.
Main class for crack propagation.
Implementation of linear elastic material.
Implementation of Neo-Hookean elastic material.
int main()
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
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
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
std::map< std::string, BitRefLevel > mapBitLevel
MoFEMErrorCode getOptions()
Get options form command line.
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.