v0.16.0
Loading...
Searching...
No Matches
ep.cpp
Go to the documentation of this file.
1/**
2 * \file ep.cpp
3 * \example mofem/users_modules/eshelbian_plasticity/ep.cpp
4 *
5 * \brief Implementation of mix-element for Large strains
6 *
7 * \todo Implementation of plasticity
8 *
9 */
10
11/* This file is part of MoFEM.
12 * MoFEM is free software: you can redistribute it and/or modify it under
13 * the terms of the GNU Lesser General Public License as published by the
14 * Free Software Foundation, either version 3 of the License, or (at your
15 * option) any later version.
16 *
17 * MoFEM is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
20 * License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>. */
24
25constexpr int adolc_tag = 1;
26
27#define SINGULARITY
28
29#include <MoFEM.hpp>
30using namespace MoFEM;
31using namespace boost::multi_index;
32using namespace boost::multiprecision;
33using namespace boost::numeric;
34#include <cmath>
35
36#include <cholesky.hpp>
37#ifdef ENABLE_PYTHON_BINDING
38 #include <boost/python.hpp>
39 #include <boost/python/def.hpp>
40 #include <boost/python/numpy.hpp>
41namespace bp = boost::python;
42namespace np = boost::python::numpy;
43#endif
44
45#include <MatOps.hpp>
46#include <MatElastic.hpp>
48using namespace EshelbianPlasticity;
49
50static char help[] = "...\n\n";
51
52int main(int argc, char *argv[]) {
53
54 // initialize petsc
55 const char param_file[] = "param_file.petsc";
56 MoFEM::Core::Initialize(&argc, &argv, param_file, help);
57
58 // Add logging channel for example
59 auto core_log = logging::core::get();
60 core_log->add_sink(LogManager::createSink(LogManager::getStrmWorld(), "EP"));
62 MOFEM_LOG_TAG("EP", "ep");
63 core_log->add_sink(
65 LogManager::setLog("EPSELF");
66 MOFEM_LOG_TAG("EPSELF", "ep");
67
68 #ifdef ENABLE_PYTHON_BINDING
69 Py_Initialize();
70 np::initialize();
71 MOFEM_LOG("EP", Sev::inform) << "Python initialised";
72#else
73 MOFEM_LOG("EP", Sev::inform) << "Python NOT initialised";
74#endif
75
76 core_log->add_sink(
78 LogManager::setLog("EPSYNC");
79 MOFEM_LOG_TAG("EPSYNC", "ep");
80
81 try {
82
83 // Get mesh file
84 PetscBool flg = PETSC_FALSE;
85 char mesh_file_name[255] = "";
86 CHKERR PetscOptionsGetString(PETSC_NULLPTR, "", "-my_file", mesh_file_name,
87 255, &flg);
88 if (!flg) {
89 CHKERR PetscOptionsGetString(PETSC_NULLPTR, "", "-file_name",
90 mesh_file_name, 255, &flg);
91 }
92 if (!flg) {
93 SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
94 "Missing required mesh option: use -file_name or -my_file");
95 }
96 char restart_file[255] = "no_restart_file";
97 PetscBool restart_flg = PETSC_TRUE;
98 CHKERR PetscOptionsGetString(PETSC_NULLPTR, "", "-restart", restart_file, 255,
100 double time = 0;
101 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-time", &time, PETSC_NULLPTR);
102
103
104 MOFEM_LOG("EP", Sev::inform) << "Mesh file: " << mesh_file_name;
105 MOFEM_LOG("EP", Sev::inform) << "Restart file: " << restart_file;
106 MOFEM_LOG("EP", Sev::inform) << "Time: " << time;
107
108 // Register DM Manager
109 DMType dm_name = "DMMOFEM";
110 CHKERR DMRegister_MoFEM(dm_name);
111 DMType dm_name_mg = "DMMOFEM_MG";
113
114 // Create MoAB database
115 moab::Core moab_core;
116 moab::Interface &moab = moab_core;
117
118 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab, MYPCOMM_INDEX);
119 if (pcomm == NULL)
120 pcomm = new ParallelComm(&moab, PETSC_COMM_WORLD);
121 // Read mesh to MOAB
122 PetscBool fully_distributed = PETSC_FALSE;
123 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-fully_distributed",
124 &fully_distributed, PETSC_NULLPTR);
125 if (fully_distributed) {
126 const char *option;
127 if (pcomm->proc_config().proc_size() == 1)
128 option = "";
129 else
130 option = "PARALLEL=READ_PART;"
131 "PARALLEL_RESOLVE_SHARED_ENTS;"
132 "PARTITION=PARALLEL_PARTITION";
133 CHKERR moab.load_file(mesh_file_name, 0, option);
134 } else {
136 moab, mesh_file_name, SPACE_DIM);
137 }
138
139 // Create MoFEM database and link it to MoAB
140 MOFEM_LOG("EP", Sev::inform) << "Initialise MoFEM database";
141 MoFEM::Core mofem_core(moab);
142 MoFEM::Interface &m_field = mofem_core;
143 MOFEM_LOG("EP", Sev::inform) << "Initialise MoFEM database <- done";
144
145 CHKERR m_field.getInterface<MeshsetsManager>()->setMeshsetFromFile();
146
147 // Register mofem DM
148 CHKERR DMRegister_MoFEM("DMMOFEM");
149
150 BitRefLevel bit_level0 = BitRefLevel().set(0);
151 CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
152 0, 3, bit_level0);
153
154 // Data stuctures
155 EshelbianCore ep(m_field);
156
157 auto meshset_ptr = get_temp_meshset_ptr(moab);
158 CHKERR moab.add_entities(
159 *meshset_ptr, CommInterface::getPartEntities(moab, pcomm->rank()));
160 auto get_adj = [&](Range ents, int dim) {
161 Range adj;
162 CHKERR moab.get_adjacencies(ents, dim, false, adj,
163 moab::Interface::UNION);
164 return adj;
165 };
166 CHKERR moab.add_entities(
167 *meshset_ptr,
168 get_adj(CommInterface::getPartEntities(moab, pcomm->rank())
169 .subset_by_dimension(SPACE_DIM),
170 2));
171 CHKERR moab.add_entities(
172 *meshset_ptr,
173 get_adj(CommInterface::getPartEntities(moab, pcomm->rank())
174 .subset_by_dimension(SPACE_DIM),
175 1));
176 CHKERR moab.add_entities(
177 *meshset_ptr,
178 get_adj(CommInterface::getPartEntities(moab, pcomm->rank())
179 .subset_by_dimension(SPACE_DIM),
180 0));
181
182 // create growing crack surface meshset
184
191
192 CHKERR ep.createExchangeVectors(Sev::inform);
193
195 CHKERR ep.addFields(*meshset_ptr);
196 CHKERR ep.projectGeometry(*meshset_ptr, 0.0);
197 CHKERR ep.addVolumeFiniteElement(*meshset_ptr);
198 CHKERR ep.addBoundaryFiniteElement(*meshset_ptr);
199 CHKERR ep.addDMs();
200
201 const char *list_materials[EshelbianCore::MaterialModel::LastMaterial] = {
202 "stvenant_kirchhoff", "mooney_rivlin", "hencky", "neo_hookean", "meta"};
203 PetscInt choice_material = EshelbianCore::materialModel;
204 CHKERR PetscOptionsGetEList(PETSC_NULLPTR, NULL, "-material",
205 list_materials,
207 &choice_material, PETSC_NULLPTR);
209 static_cast<EshelbianCore::MaterialModel>(choice_material);
210
211 auto material_model_names_dictionary = std::map<std::string, std::string>{
212 {"grad", "stretchH1AtPts"}, {"P", "PAtPts"}, {"P_dF", "PAtPts_du"}};
214 true; // by default use deformation gradient as common data
215
216 switch (choice_material) {
218 MOFEM_LOG("EP", Sev::inform) << "St. Venant-Kirchhoff material model";
219 MOFEM_LOG("EP", Sev::inform) << "Meta Material model";
220 ep.dataAtPts = boost::make_shared<DataAtIntegrationPts>();
221 auto physical_equations_ptr = MatOps::createMatOpsPhysicalEquationsPtr<
224 material_model_names_dictionary),
226 CHKERR physical_equations_ptr->getOptions(&m_field);
227 CHKERR physical_equations_ptr->recordTape();
228 CHKERR ep.addMaterial_Core(physical_equations_ptr);
229 };
231 MOFEM_LOG("EP", Sev::inform) << "Mooney-Rivlin material model";
232 ep.dataAtPts = boost::make_shared<DataAtIntegrationPts>();
233 auto physical_equations_ptr = MatOps::createMatOpsPhysicalEquationsPtr<
236 material_model_names_dictionary),
238 CHKERR physical_equations_ptr->getOptions(&m_field);
239 CHKERR physical_equations_ptr->recordTape();
240 CHKERR ep.addMaterial_Core(physical_equations_ptr);
241 }; break;
243 MOFEM_LOG("EP", Sev::inform) << "Hencky material model";
244 CHKERR ep.addMaterial_Hencky(5., 0.25);
245 break;
247 MOFEM_LOG("EP", Sev::inform) << "Neo-Hookean material model";
249 break;
251 MOFEM_LOG("EP", Sev::inform) << "Meta Material model";
252 ep.dataAtPts = boost::make_shared<DataAtIntegrationPts>();
253 auto physical_equations_ptr =
257 material_model_names_dictionary),
259 CHKERR physical_equations_ptr->getOptions(&m_field);
260 CHKERR physical_equations_ptr->recordTape();
261 CHKERR ep.addMaterial_Core(physical_equations_ptr);
262 }; break;
263 default:
264 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY, "Unknown material");
265 break;
266 }
267
270
271 auto x_elastic = createDMVector(ep.dmElastic);
272 auto f_elastic = vectorDuplicate(x_elastic);
273 CHKERR VecSetOption(f_elastic, VEC_IGNORE_NEGATIVE_INDICES, PETSC_TRUE);
274
275 PetscInt start_step = 0;
276 if (restart_flg) {
277 PetscViewer viewer;
278 CHKERR PetscViewerBinaryOpen(PETSC_COMM_WORLD, restart_file,
279 FILE_MODE_READ, &viewer);
280 CHKERR VecLoad(x_elastic, viewer);
281 CHKERR PetscViewerDestroy(&viewer);
282 CHKERR VecGhostUpdateBegin(x_elastic, INSERT_VALUES, SCATTER_FORWARD);
283 CHKERR VecGhostUpdateEnd(x_elastic, INSERT_VALUES, SCATTER_FORWARD);
284
285 std::string restart_file_str(restart_file);
286 std::regex restart_pattern(R"(restart_([1-9]\d*)\.dat)");
287 std::smatch match;
288 if (std::regex_search(restart_file_str, match, restart_pattern)) {
289 start_step = std::stoi(match[1]);
290 } else {
291 SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
292 "Restart file name must be in the format restart_##.dat");
293 }
294 }
295
296 auto ts_elastic = createTS(PETSC_COMM_WORLD);
297 CHKERR TSSetType(ts_elastic, TSBEULER);
298 CHKERR TSAdaptRegister(TSADAPTMOFEM, TSAdaptCreateMoFEM);
299 TSAdapt adapt;
300 CHKERR TSGetAdapt(ts_elastic, &adapt);
301 CHKERR TSAdaptSetType(adapt, TSADAPTNONE);
302
305 MOFEM_LOG("EP", Sev::inform) << "Solver type: TS";
306 CHKERR TSSetTime(ts_elastic, time);
307 CHKERR TSSetStepNumber(ts_elastic, start_step);
308 CHKERR ep.solveElastic(ts_elastic, x_elastic);
309 break;
311 MOFEM_LOG("EP", Sev::inform) << "Solver type: Dynamic Relaxation";
312 CHKERR DMoFEMMeshToLocalVector(ep.dmElastic, x_elastic, INSERT_VALUES,
313 SCATTER_REVERSE);
314 CHKERR ep.solveDynamicRelaxation(ts_elastic, x_elastic, start_step, time);
315 break;
317 MOFEM_LOG("EP", Sev::inform) << "Solver type: Cohesive";
318 CHKERR DMoFEMMeshToLocalVector(ep.dmElastic, x_elastic, INSERT_VALUES,
319 SCATTER_REVERSE);
320 CHKERR ep.solveCohesiveCrackGrowth(ts_elastic, x_elastic, start_step,
321 time);
322 break;
324 MOFEM_LOG("EP", Sev::inform) << "Solver type: Load Factor";
325 CHKERR DMoFEMMeshToLocalVector(ep.dmElastic, x_elastic, INSERT_VALUES,
326 SCATTER_REVERSE);
327 CHKERR ep.solveLoadFactor(ts_elastic, x_elastic, start_step, time);
328 break;
330 MOFEM_LOG("EP", Sev::inform) << "Solver type: Shape Optimization";
331 CHKERR DMoFEMMeshToLocalVector(ep.dmElastic, x_elastic, INSERT_VALUES,
332 SCATTER_REVERSE);
333 CHKERR ep.solveSchapeOptimisation(ts_elastic, x_elastic, start_step,
334 time);
335 break;
337 MOFEM_LOG("EP", Sev::inform)
338 << "Solver type: Test Topological Derivative";
339 CHKERR DMoFEMMeshToLocalVector(ep.dmElastic, x_elastic, INSERT_VALUES,
340 SCATTER_REVERSE);
341 CHKERR ep.solveTestTopologicalDerivative(ts_elastic, x_elastic,
342 start_step, time);
343 break;
344 default:
345 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
346 "Unknown solver type");
347 break;
348 }
349
350 }
352
353 // finish work cleaning memory, getting statistics, etc.
355
356#ifdef ENABLE_PYTHON_BINDING
357 if (Py_FinalizeEx() < 0) {
358 exit(120);
359 }
360#endif
361}
Eshelbian plasticity interface.
#define TSADAPTMOFEM
Definition TsCtx.hpp:10
int main()
constexpr int SPACE_DIM
cholesky decomposition
#define CATCH_ERRORS
Catch errors.
#define MYPCOMM_INDEX
default communicator number PCOMM
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
#define CHKERR
Inline error check.
static char help[]
Definition ep.cpp:50
constexpr int adolc_tag
Definition ep.cpp:25
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode, RowColData rc=RowColData::COL)
set local (or ghosted) vector values on mesh for partition only
Definition DMMoFEM.cpp:514
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition DMMoFEM.cpp:43
MoFEMErrorCode DMRegister_MGViaApproxOrders(const char sname[])
Register DM for Multi-Grid via approximation orders.
auto createDMVector(DM dm, RowColData rc=RowColData::COL)
Get smart vector from DM.
Definition DMMoFEM.hpp:1237
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
@ MODEL_3D
Definition MatOps.hpp:171
boost::shared_ptr< PhysicalEquations > createMatOpsPhysicalEquationsPtr(boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag)
boost::shared_ptr< MatOpsData > createMatOpsDataPtr()
Definition MatOps.cpp:671
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 PetscOptionsGetScalar(PetscOptions *, const char pre[], const char name[], PetscScalar *dval, PetscBool *set)
SmartPetscObj< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.
auto createTS(MPI_Comm comm)
PetscErrorCode PetscOptionsGetEList(PetscOptions *, const char pre[], const char name[], const char *const *list, PetscInt next, PetscInt *value, PetscBool *set)
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
auto get_temp_meshset_ptr(moab::Interface &moab)
Create smart pointer to temporary meshset.
PetscErrorCode TSAdaptCreateMoFEM(TSAdapt adapt)
Craete MOFEM adapt.
Definition TsCtx.cpp:829
MoFEMErrorCode setElasticElementOps(const int tag)
MoFEMErrorCode createCrackSurfaceMeshset()
MoFEMErrorCode addBoundaryFiniteElement(const EntityHandle meshset=0)
MoFEMErrorCode getSpatialRotationBc()
MoFEMErrorCode addMaterial_Hencky(double E, double nu)
static enum SolverType solverType
MoFEMErrorCode solveSchapeOptimisation(TS ts, Vec x, int start_step, double start_time)
Solve shape optimisation problem.
MoFEMErrorCode setBlockTagsOnSkin()
MoFEMErrorCode solveElastic(TS ts, Vec x)
static enum MaterialModel materialModel
MoFEMErrorCode setElasticElementToTs(DM dm)
MoFEMErrorCode projectGeometry(const EntityHandle meshset=0, double time=0)
MoFEMErrorCode projectMaterialTags(const EntityHandle meshset=0)
MoFEMErrorCode solveDynamicRelaxation(TS ts, Vec x, int start_step, double start_time)
Solve problem using dynamic relaxation method.
MoFEMErrorCode solveTestTopologicalDerivative(TS ts, Vec x, int start_step, double start_time)
MoFEMErrorCode addVolumeFiniteElement(const EntityHandle meshset=0, const bool add_bubble=true)
MoFEMErrorCode addMaterial_Core(boost::weak_ptr< MatOps::PhysicalEquations > mat_physical_equations_ptr)
MoFEMErrorCode getSpatialTractionFreeBc(const EntityHandle meshset=0)
MoFEMErrorCode getExternalStrain()
MoFEMErrorCode getSpatialTractionBc()
MoFEMErrorCode addDMs(const BitRefLevel bit=BitRefLevel().set(0), const EntityHandle meshset=0)
MoFEMErrorCode solveCohesiveCrackGrowth(TS ts, Vec x, int start_step, double start_time)
Solve cohesive crack growth problem.
MoFEMErrorCode getSpatialDispBc()
[Getting norms]
MoFEMErrorCode solveLoadFactor(TS ts, Vec x, int start_step, double start_time)
Solve load factor crack growth problem.
MoFEMErrorCode createExchangeVectors(Sev sev)
boost::shared_ptr< DataAtIntegrationPts > dataAtPts
MoFEMErrorCode addMaterial_HMHNeohookean(const int tape, const double c10, const double K)
SmartPetscObj< DM > dmElastic
Elastic problem.
MoFEMErrorCode addFields(const EntityHandle meshset=0, const bool add_bubble=true)
static bool useDeformationGradient
static int setTagName(std::string name, int tag=-1)
Definition MatOps.cpp:30
Managing BitRefLevels.
static Range getPartEntities(moab::Interface &moab, int part)
static MoFEMErrorCode loadFileRootProcAllRestDistributed(moab::Interface &moab, const char *file_name, int dim, LoadFileFun proc_skin_fun=defaultProcSkinFun, const char *options="PARALLEL=BCAST;PARTITION=")
Root proc has whole mesh, other procs only part of it.
virtual MPI_Comm & get_comm() const =0
Core (interface) class.
Definition Core.hpp:83
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition Core.cpp:68
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition Core.cpp:123
Deprecated interface functions.
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
static boost::shared_ptr< std::ostream > getStrmWorld()
Get the strm world object.
static boost::shared_ptr< std::ostream > getStrmSync()
Get the strm sync object.
static boost::shared_ptr< std::ostream > getStrmSelf()
Get the strm self object.
Interface for managing meshsets containing materials and boundary conditions.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
char restart_file[255]
PetscBool restart_flg