v0.16.3
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 */
8
9/* This file is part of MoFEM.
10 * MoFEM is free software: you can redistribute it and/or modify it under
11 * the terms of the GNU Lesser General Public License as published by the
12 * Free Software Foundation, either version 3 of the License, or (at your
13 * option) any later version.
14 *
15 * MoFEM is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>. */
22
23constexpr int adolc_tag = 1;
24
25#define SINGULARITY
26
27#include <MoFEM.hpp>
28#include <EshelbianRestart.hpp>
29using namespace MoFEM;
30using namespace boost::multi_index;
31using namespace boost::multiprecision;
32using namespace boost::numeric;
33#include <cmath>
34
35#include <cholesky.hpp>
36#ifdef ENABLE_PYTHON_BINDING
37 #include <boost/python.hpp>
38 #include <boost/python/def.hpp>
39 #include <boost/python/numpy.hpp>
40namespace bp = boost::python;
41namespace np = boost::python::numpy;
42#endif
43
45#include <MatElastic.hpp>
46#include <MatOps.hpp>
47using namespace EshelbianPlasticity;
48
49static char help[] = "...\n\n";
50
51int main(int argc, char *argv[]) {
52
53 // initialize petsc
54 const char param_file[] = "param_file.petsc";
55 MoFEM::Core::Initialize(&argc, &argv, param_file, help);
56
57 // Add logging channel for example
58 auto core_log = logging::core::get();
59 core_log->add_sink(LogManager::createSink(LogManager::getStrmWorld(), "EP"));
61 MOFEM_LOG_TAG("EP", "ep");
62 core_log->add_sink(
64 LogManager::setLog("EPSELF");
65 MOFEM_LOG_TAG("EPSELF", "ep");
66
67#ifdef ENABLE_PYTHON_BINDING
68 Py_Initialize();
69 np::initialize();
70 MOFEM_LOG("EP", Sev::inform) << "Python initialised";
71#else
72 MOFEM_LOG("EP", Sev::inform) << "Python NOT initialised";
73#endif
74
75 core_log->add_sink(
77 LogManager::setLog("EPSYNC");
78 MOFEM_LOG_TAG("EPSYNC", "ep");
79
80 try {
81
83
84 // Get mesh file
85 PetscBool flg = PETSC_FALSE;
86 char mesh_file_name[255] = "";
87 CHKERR PetscOptionsGetString(PETSC_NULLPTR, "", "-my_file", mesh_file_name,
88 255, &flg);
89 if (!flg) {
90 CHKERR PetscOptionsGetString(PETSC_NULLPTR, "", "-file_name",
91 mesh_file_name, 255, &flg);
92 }
93 if (!flg) {
94 SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
95 "Missing required mesh option: use -file_name or -my_file");
96 }
97 char restart_file[255] = "no_restart_file";
98 PetscBool restart_flg = PETSC_TRUE;
99 CHKERR PetscOptionsGetString(PETSC_NULLPTR, "", "-restart", restart_file,
100 255, &restart_flg);
101 double time = 0;
102 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-time", &time,
103 PETSC_NULLPTR);
104
105 MOFEM_LOG("EP", Sev::inform) << "Mesh file: " << mesh_file_name;
106 MOFEM_LOG("EP", Sev::inform) << "Restart file: " << restart_file;
107 MOFEM_LOG("EP", Sev::inform) << "Time: " << time;
108
109 // Register DM Manager
110 DMType dm_name = "DMMOFEM";
111 CHKERR DMRegister_MoFEM(dm_name);
112 DMType dm_name_mg = "DMMOFEM_MG";
114
115 // Create MoAB database
116 moab::Core moab_core;
117 moab::Interface &moab = moab_core;
118
119 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab, MYPCOMM_INDEX);
120 if (pcomm == NULL)
121 pcomm = new ParallelComm(&moab, PETSC_COMM_WORLD);
122 // Read mesh to MOAB
123 PetscBool fully_distributed = PETSC_FALSE;
124 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-fully_distributed",
125 &fully_distributed, PETSC_NULLPTR);
126 if (fully_distributed) {
127 const char *option;
128 if (pcomm->proc_config().proc_size() == 1)
129 option = "";
130 else
131 option = "PARALLEL=READ_PART;"
132 "PARALLEL_RESOLVE_SHARED_ENTS;"
133 "PARTITION=PARALLEL_PARTITION";
134 CHKERR moab.load_file(mesh_file_name, 0, option);
135 } else {
137 moab, mesh_file_name, SPACE_DIM);
138 }
139
140 // Create MoFEM database and link it to MoAB
141 MOFEM_LOG("EP", Sev::inform) << "Initialise MoFEM database";
142 MoFEM::Core mofem_core(moab);
143 MoFEM::Interface &m_field = mofem_core;
144 MOFEM_LOG("EP", Sev::inform) << "Initialise MoFEM database <- done";
146 {"kn", "kt"}); // TODO: remove this line and add kn kt to the core
147 // JsonConfigManagerCanonicalAttributes.hpp
148 CHKERR m_field.getInterface<MeshsetsManager>()->setMeshsetFromFile();
149
150 // Register mofem DM
151 CHKERR DMRegister_MoFEM("DMMOFEM");
152
153 BitRefLevel bit_level0 = BitRefLevel().set(0);
154 CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
155 0, 3, bit_level0);
156
157 // Data stuctures
158 EshelbianCore ep(m_field);
160
161 auto meshset_ptr = get_temp_meshset_ptr(moab);
162 CHKERR moab.add_entities(
163 *meshset_ptr, CommInterface::getPartEntities(moab, pcomm->rank()));
164 auto get_adj = [&](Range ents, int dim) {
165 Range adj;
166 CHKERR moab.get_adjacencies(ents, dim, false, adj,
167 moab::Interface::UNION);
168 return adj;
169 };
170 CHKERR moab.add_entities(
171 *meshset_ptr,
172 get_adj(CommInterface::getPartEntities(moab, pcomm->rank())
173 .subset_by_dimension(SPACE_DIM),
174 2));
175 CHKERR moab.add_entities(
176 *meshset_ptr,
177 get_adj(CommInterface::getPartEntities(moab, pcomm->rank())
178 .subset_by_dimension(SPACE_DIM),
179 1));
180 CHKERR moab.add_entities(
181 *meshset_ptr,
182 get_adj(CommInterface::getPartEntities(moab, pcomm->rank())
183 .subset_by_dimension(SPACE_DIM),
184 0));
185
186 // create growing crack surface meshset
188
195
196 CHKERR ep.createExchangeVectors(Sev::inform);
197
199 CHKERR ep.resolveDissipationEntities(*meshset_ptr);
200 CHKERR ep.addFields(*meshset_ptr);
201 CHKERR ep.projectGeometry(*meshset_ptr, 0.0);
202 CHKERR ep.addVolumeFiniteElement(*meshset_ptr);
203 CHKERR ep.addBoundaryFiniteElement(*meshset_ptr);
204 CHKERR ep.addDMs();
205
208
209 auto x_elastic = createDMVector(ep.dmElastic);
210
211 PetscInt start_step = 0;
212 if (restart_flg) {
219 TestIncrementalOptimizationTransaction ||
221 EshelbianCore::SolverType::
222 TestIncrementalOptimizationObjectiveDerivative ||
226 SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
227 "Incremental optimization does not support -restart");
229 PetscViewer viewer;
230 CHKERR PetscViewerBinaryOpen(PETSC_COMM_WORLD, restart_file,
231 FILE_MODE_READ, &viewer);
232 CHKERR VecLoad(x_elastic, viewer);
233 CHKERR PetscViewerDestroy(&viewer);
234 CHKERR VecGhostUpdateBegin(x_elastic, INSERT_VALUES, SCATTER_FORWARD);
235 CHKERR VecGhostUpdateEnd(x_elastic, INSERT_VALUES, SCATTER_FORWARD);
236 // Solver setup gathers its initial vector from mesh coefficients.
237 CHKERR DMoFEMMeshToLocalVector(ep.dmElastic, x_elastic, INSERT_VALUES,
238 SCATTER_REVERSE);
239 CHKERR VecCopy(x_elastic, ep.solTSStep);
240 CHKERR VecGhostUpdateBegin(ep.solTSStep, INSERT_VALUES, SCATTER_FORWARD);
241 CHKERR VecGhostUpdateEnd(ep.solTSStep, INSERT_VALUES, SCATTER_FORWARD);
242
243 std::string restart_file_str(restart_file);
244 std::regex restart_pattern(R"(restart_([1-9]\d*)\.dat)");
245 std::smatch match;
246 if (std::regex_search(restart_file_str, match, restart_pattern)) {
247 start_step = std::stoi(match[1]);
248 } else {
249 SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
250 "Restart file name must be in the format restart_##.dat");
251 }
252 }
253
254 auto ts_elastic = createTS(PETSC_COMM_WORLD);
255 CHKERR TSSetType(ts_elastic, TSBEULER);
256 CHKERR TSAdaptRegister(TSADAPTMOFEM, TSAdaptCreateMoFEM);
257 TSAdapt adapt;
258 CHKERR TSGetAdapt(ts_elastic, &adapt);
259 CHKERR TSAdaptSetType(adapt, TSADAPTNONE);
260
263 MOFEM_LOG("EP", Sev::inform) << "Solver type: TS";
264 CHKERR TSSetTime(ts_elastic, time);
265 CHKERR TSSetStepNumber(ts_elastic, start_step);
266 CHKERR ep.solveElastic(ts_elastic, x_elastic);
267 break;
269 MOFEM_LOG("EP", Sev::inform) << "Solver type: Dynamic Relaxation";
270 CHKERR DMoFEMMeshToLocalVector(ep.dmElastic, x_elastic, INSERT_VALUES,
271 SCATTER_REVERSE);
272 CHKERR ep.solveDynamicRelaxation(ts_elastic, x_elastic, start_step, time);
273 break;
275 MOFEM_LOG("EP", Sev::inform) << "Solver type: Incremental Optimization";
276 CHKERR DMoFEMMeshToLocalVector(ep.dmElastic, x_elastic, INSERT_VALUES,
277 SCATTER_REVERSE);
278 CHKERR ep.solveIncrementalOptimizationTAO(ts_elastic, x_elastic,
279 start_step, time);
280 break;
282 MOFEM_LOG("EP", Sev::inform) << "Solver type: Load Factor";
283 CHKERR DMoFEMMeshToLocalVector(ep.dmElastic, x_elastic, INSERT_VALUES,
284 SCATTER_REVERSE);
285 CHKERR ep.solveLoadFactor(ts_elastic, x_elastic, start_step, time);
286 break;
288 MOFEM_LOG("EP", Sev::inform) << "Solver type: Shape Optimization";
289 CHKERR DMoFEMMeshToLocalVector(ep.dmElastic, x_elastic, INSERT_VALUES,
290 SCATTER_REVERSE);
291 CHKERR ep.solveSchapeOptimisation(ts_elastic, x_elastic, start_step,
292 time);
293 break;
295 MOFEM_LOG("EP", Sev::inform)
296 << "Solver type: Test Topological Derivative";
297 CHKERR DMoFEMMeshToLocalVector(ep.dmElastic, x_elastic, INSERT_VALUES,
298 SCATTER_REVERSE);
299 CHKERR ep.solveTestTopologicalDerivative(ts_elastic, x_elastic,
300 start_step, time);
301 break;
303 MOFEM_LOG("EP", Sev::inform)
304 << "Solver type: Test Equilibrated Mechanical Value";
305 CHKERR DMoFEMMeshToLocalVector(ep.dmElastic, x_elastic, INSERT_VALUES,
306 SCATTER_REVERSE);
307 CHKERR ep.solveTestEquilibratedMechanicalValue(ts_elastic, x_elastic,
308 start_step, time);
309 break;
311 MOFEM_LOG("EP", Sev::inform)
312 << "Solver type: Test Incremental Optimization Layout";
313 CHKERR ep.solveTestIncrementalOptimizationLayout(ts_elastic, x_elastic,
314 start_step, time);
315 break;
317 MOFEM_LOG("EP", Sev::inform)
318 << "Solver type: Test Incremental Optimization Transaction";
319 CHKERR DMoFEMMeshToLocalVector(ep.dmElastic, x_elastic, INSERT_VALUES,
320 SCATTER_REVERSE);
322 ts_elastic, x_elastic, start_step, time);
323 break;
326 MOFEM_LOG("EP", Sev::inform)
327 << "Solver type: Test Incremental Optimization Objective Derivative";
328 CHKERR DMoFEMMeshToLocalVector(ep.dmElastic, x_elastic, INSERT_VALUES,
329 SCATTER_REVERSE);
331 ts_elastic, x_elastic, start_step, time);
332 break;
335 MOFEM_LOG("EP", Sev::inform)
336 << "Solver type: Test Incremental Optimization Constraint Derivative";
337 CHKERR DMoFEMMeshToLocalVector(ep.dmElastic, x_elastic, INSERT_VALUES,
338 SCATTER_REVERSE);
340 ts_elastic, x_elastic, start_step, time);
341 break;
342 default:
343 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
344 "Unknown solver type");
345 break;
346 }
347 }
349
350 // finish work cleaning memory, getting statistics, etc.
352
353#ifdef ENABLE_PYTHON_BINDING
354 if (Py_FinalizeEx() < 0) {
355 exit(120);
356 }
357#endif
358}
Eshelbian plasticity interface.
Native restart vector layout validation.
#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:49
constexpr int adolc_tag
Definition ep.cpp:23
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.
MoFEM::MoFEMErrorCode validateRestartLayout(const EshelbianCore &ep, Vec state, const std::string &binary_file)
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)
auto createTS(MPI_Comm comm)
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()
static enum SolverType solverType
MoFEMErrorCode solveSchapeOptimisation(TS ts, Vec x, int start_step, double start_time)
Solve shape optimisation problem.
MoFEMErrorCode setBlockTagsOnSkin()
MoFEMErrorCode solveTestIncrementalOptimizationLayout(TS ts, Vec x, int start_step, double start_time)
MoFEMErrorCode solveElastic(TS ts, Vec x)
@ TestIncrementalOptimizationConstraintDerivative
@ TestIncrementalOptimizationLayout
@ TestIncrementalOptimizationTransaction
@ TestIncrementalOptimizationObjectiveDerivative
@ TestEquilibratedMechanicalValue
MoFEMErrorCode solveTestIncrementalOptimizationTransaction(TS ts, Vec x, int start_step, double start_time)
MoFEMErrorCode setElasticElementToTs(DM dm)
MoFEMErrorCode solveTestEquilibratedMechanicalValue(TS ts, Vec x, int start_step, double start_time)
MoFEMErrorCode solveIncrementalOptimizationTAO(TS ts, Vec x, int start_step, double start_time)
Solve the incremental constitutive optimization with TAO.
MoFEMErrorCode solveTestIncrementalOptimizationObjectiveDerivative(TS ts, Vec x, int start_step, double start_time)
MoFEMErrorCode resolveDissipationEntities(const EntityHandle meshset=0)
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 solveTestIncrementalOptimizationConstraintDerivative(TS ts, Vec x, int start_step, double start_time)
MoFEMErrorCode getSpatialTractionFreeBc(const EntityHandle meshset=0)
MoFEMErrorCode getExternalStrain()
MoFEMErrorCode getSpatialTractionBc()
MoFEMErrorCode addDMs(const BitRefLevel bit=BitRefLevel().set(0), const EntityHandle meshset=0)
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)
SmartPetscObj< Vec > solTSStep
SmartPetscObj< DM > dmElastic
Elastic problem.
MoFEMErrorCode addFields(const EntityHandle meshset=0, const bool add_bubble=true)
static MoFEMErrorCode create(EshelbianCore &ep)
Select and configure the material before registering fields and DMs.
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 MoFEMErrorCode setMeshFileFromJson()
Set -file_name from JSON before Core is available.
static MoFEMErrorCode addCanonicalAttributeNames(const std::vector< std::string > &names)
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