v0.16.3
Loading...
Searching...
No Matches
adolc_plasticity.cpp
Go to the documentation of this file.
1/**
2 * \file adolc_plasticity.cpp
3 * \ingroup adoc_plasticity
4 * \example mofem/users_modules/adolc-plasticity/adolc_plasticity.cpp
5 *
6 * \brife Implementation of plasticity problem using ADOLC-C
7 *
8 */
9#include <MoFEM.hpp>
10#include <MatrixFunction.hpp>
11
12using namespace MoFEM;
13
14constexpr int SPACE_DIM =
15 EXECUTABLE_DIMENSION; //< Space dimension of problem, mesh
16
18
19/** Select finite element type for integration on domain based on problem
20 * dimension
21 */
23
24/** Select finite element type for integrate on boundary based on problem
25 * dimension
26 */
29/** Operators used to assemble domain integrals
30 */
31using DomainEleOp = DomainEle::UserDataOperator;
32
33/** Operators used to assemble boundary integrals
34 */
35using BoundaryEleOp = BoundaryEle::UserDataOperator;
36
37/** Linear forms used to integrate body forces
38 */
41
42/** Select linear froms reading data from blockest (e.g. "BODY_FORCE") and
43 * applying body force.
44 */
47
48// Select natural BC boundary condition
49
50// Use natural boundary conditions implemented with adv-1 example which includes
51// spring BC
52#include <ContactNaturalBC.hpp>
53
54/** Use Gauss quadrature rule and PETSc assembly to integrate neural boundary
55 * conditions. Select linear forms operators.
56 */
59
60/* Use specialization from adv-1 integrating boundary conditions on forces and
61 * with springs. OP is used to integrate the right hand side
62 */
65
66/** Use Gauss quadrature rule and PETSc assembly to integrate neural boundary
67 * conditions. Select bi-linear forms operators.
68 */
71
72/** Use specialization from adv-1 integrating boundary conditions on forces and
73 * with springs
74 */
77
78// Note: We create only skin post-processing mesh.
79
80template <int DIM>
81struct ElementsAndOps; //< Select finite elements and operators used for
82 // postprocessing and contact space
83
84template <> struct ElementsAndOps<2> {
88 static constexpr FieldSpace CONTACT_SPACE = HCURL;
89};
90
91template <> struct ElementsAndOps<3> {
95 static constexpr FieldSpace CONTACT_SPACE = HDIV;
96};
97// Define contact space by dimension
101
105
106double scale = 1.;
107#include <HenckyOps.hpp>
108#include <ADOLCPlasticity.hpp>
111using namespace HenckyOps;
112using namespace ADOLCPlasticity;
113#ifdef ADD_CONTACT
114#ifdef ENABLE_PYTHON_BINDING
115#include <boost/python.hpp>
116#include <boost/python/def.hpp>
117#include <boost/python/numpy.hpp>
118namespace bp = boost::python;
119namespace np = boost::python::numpy;
120#endif
121namespace ContactOps {
122
123double cn_contact = 0.1;
124
125}; // namespace ContactOps
126
127#include <ContactOps.hpp>
128#endif // ADD_CONTACT
129
131
132 PlasticProblem(MoFEM::Interface &m_field) : mField(m_field) {}
133
135
136private:
138
147
148 int approxOrder = 2;
149 int geomOrder = 2;
150 PetscBool largeStrain = PETSC_FALSE; ///< Large strain flag
152 boost::shared_ptr<ClosestPointProjection> cpPtr; ///< Closest point
153 ///< projection
154#ifdef ADD_CONTACT
155#ifdef ENABLE_PYTHON_BINDING
156 boost::shared_ptr<ContactOps::SDFPython> sdfPythonPtr;
157#endif
158#endif // ADD_CONTACT
159};
160
161//! [Run problem]
174//! [Run problem]
175
176//! [Read mesh]
181 CHKERR simple->loadFile();
182
183 if (simple->getDim() != SPACE_DIM)
184 SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
185 "Wrong dimension of mesh %d != %d", simple->getDim(), SPACE_DIM);
186
187 // Check if mesh has boundary conditions tag and set yield strength as elastic
188 Tag th_boundary_conditions;
189 ErrorCode rval_bc = mField.get_moab().tag_get_handle(
190 "BOUNDARY_CONDITIONS", 1, MB_TYPE_INTEGER, th_boundary_conditions,
191 MB_TAG_SPARSE);
192
193 // Set yield strength as elastic if boundary conditions tag is set
194 if (rval_bc == MB_SUCCESS) {
195
196 auto yield_strength_compressive = std::numeric_limits<double>::max();
197 auto yield_strength_tension = std::numeric_limits<double>::max();
198
199 Tag th_compressive_yield_stress;
200 Tag th_tension_yield_stress;
201
202 ErrorCode rval_compressive = mField.get_moab().tag_get_handle(
203 "Yield_Strength_C", 1, MB_TYPE_DOUBLE, th_compressive_yield_stress,
204 MB_TAG_SPARSE);
205
206 ErrorCode rval_tension = mField.get_moab().tag_get_handle(
207 "Yield_Strength_T", 1, MB_TYPE_DOUBLE, th_tension_yield_stress,
208 MB_TAG_SPARSE);
209
210 Range fe_ents;
211 CHKERR mField.get_moab().get_entities_by_dimension(0, SPACE_DIM, fe_ents);
212
213 for (auto fe_ent : fe_ents) {
214 Range nodes;
215 // get nodes of the element
216 CHKERR mField.get_moab().get_adjacencies(&fe_ent, 1, 0, false, nodes);
217
218 std::vector<double> v_bc_val;
219 for (auto node : nodes) {
220 int bc_val;
221 CHKERR mField.get_moab().tag_get_data(th_boundary_conditions, &node, 1,
222 static_cast<void *>(&bc_val));
223 v_bc_val.push_back(bc_val);
224 }
225
226 // Set yield strength as elastic if boundary conditions is FIX_X or
227 // CONTACT
228 if (std::find_if(v_bc_val.begin(), v_bc_val.end(), [](int val) {
229 return val == 5 || val == 20;
230 }) != v_bc_val.end()) {
231
232 if (rval_compressive == MB_SUCCESS) {
233
234 CHKERR mField.get_moab().tag_set_data(th_compressive_yield_stress,
235 &fe_ent, 1,
236 &yield_strength_compressive);
237 } else {
238 MOFEM_LOG("ADOLCPlasticityWold", Sev::warning)
239 << "Yield_Strength_C tag does not exist using default value";
240 }
241 if (rval_tension == MB_SUCCESS) {
242
243 CHKERR mField.get_moab().tag_set_data(
244 th_tension_yield_stress, &fe_ent, 1, &yield_strength_tension);
245 } else {
246 MOFEM_LOG("ADOLCPlasticityWold", Sev::warning)
247 << "Yield_Strength_T tag does not exist using default value";
248 }
249 }
250 }
251 }
252
254}
255//! [Read mesh]
256
257//! [Set up problem]
261
262 enum bases { AINSWORTH, DEMKOWICZ, LASBASETOPT };
263 const char *list_bases[LASBASETOPT] = {"ainsworth", "demkowicz"};
264 PetscInt choice_base_value = AINSWORTH;
265 CHKERR PetscOptionsGetEList(PETSC_NULLPTR, NULL, "-base", list_bases,
266 LASBASETOPT, &choice_base_value, PETSC_NULLPTR);
267 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-order", &approxOrder,
268 PETSC_NULLPTR);
269 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-geom_order", &geomOrder,
270 PETSC_NULLPTR);
271 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-large_strain", &largeStrain,
272 PETSC_NULLPTR);
273
274 switch (choice_base_value) {
275 case AINSWORTH:
277 MOFEM_LOG("WORLD", Sev::inform)
278 << "Set AINSWORTH_LEGENDRE_BASE for displacements";
279 break;
280 case DEMKOWICZ:
282 MOFEM_LOG("WORLD", Sev::inform)
283 << "Set DEMKOWICZ_JACOBI_BASE for displacements";
284 break;
285 default:
287 break;
288 }
289
290 // Add field
291 CHKERR simple->addDomainField("U", H1, approxBase, SPACE_DIM);
292 CHKERR simple->addBoundaryField("U", H1, approxBase, SPACE_DIM);
293 CHKERR simple->addDataField("GEOMETRY", H1, approxBase, SPACE_DIM);
294
295#ifdef ADD_CONTACT
296 CHKERR simple->addDomainField("SIGMA", CONTACT_SPACE, DEMKOWICZ_JACOBI_BASE,
297 SPACE_DIM);
298 CHKERR simple->addBoundaryField("SIGMA", CONTACT_SPACE, DEMKOWICZ_JACOBI_BASE,
299 SPACE_DIM);
300 auto get_skin = [&]() {
301 Range body_ents;
302 CHKERR mField.get_moab().get_entities_by_dimension(0, SPACE_DIM, body_ents);
303 Skinner skin(&mField.get_moab());
304 Range skin_ents;
305 CHKERR skin.find_skin(0, body_ents, false, skin_ents);
306 return skin_ents;
307 };
308
309 auto filter_blocks = [&](auto skin) {
310 bool is_contact_block = false;
311 Range contact_range;
312 for (auto m :
313 mField.getInterface<MeshsetsManager>()->getCubitMeshsetPtr(std::regex(
314
315 (boost::format("%s(.*)") % "CONTACT").str()
316
317 ))
318
319 ) {
320 is_contact_block =
321 true; ///< bloks interation is collectibe, so that is set irrespective
322 ///< if there are enerities in given rank or not in the block
323 MOFEM_LOG("CONTACT", Sev::inform)
324 << "Find contact block set: " << m->getName();
325 auto meshset = m->getMeshset();
326 Range contact_meshset_range;
327 CHKERR mField.get_moab().get_entities_by_dimension(
328 meshset, SPACE_DIM - 1, contact_meshset_range, true);
329
330 CHKERR mField.getInterface<CommInterface>()->synchroniseEntities(
331 contact_meshset_range);
332 contact_range.merge(contact_meshset_range);
333 }
334 if (is_contact_block) {
335 MOFEM_LOG("SYNC", Sev::inform)
336 << "Nb entities in contact surface: " << contact_range.size();
338 skin = intersect(skin, contact_range);
339 }
340 return skin;
341 };
342
343 auto filter_true_skin = [&](auto skin) {
344 Range boundary_ents;
345 ParallelComm *pcomm =
346 ParallelComm::get_pcomm(&mField.get_moab(), MYPCOMM_INDEX);
347 CHKERR pcomm->filter_pstatus(skin, PSTATUS_SHARED | PSTATUS_MULTISHARED,
348 PSTATUS_NOT, -1, &boundary_ents);
349 return boundary_ents;
350 };
351
352 auto boundary_ents = filter_true_skin(filter_blocks(get_skin()));
353#ifdef ADD_CONTACT
354 CHKERR simple->setFieldOrder("SIGMA", 0);
355 CHKERR simple->setFieldOrder("SIGMA", approxOrder - 1, &boundary_ents);
356 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-cn_contact",
357 &ContactOps::cn_contact, PETSC_NULLPTR);
358 MOFEM_LOG("CONTACT", Sev::inform) << "cn_contact " << ContactOps::cn_contact;
359
360#endif
361
362#ifdef ENABLE_PYTHON_BINDING
363 sdfPythonPtr = boost::make_shared<ContactOps::SDFPython>();
364 CHKERR sdfPythonPtr->sdfInit("sdf.py");
365 ContactOps::sdfPythonWeakPtr = sdfPythonPtr;
366#endif
367#endif
368
369 CHKERR simple->setFieldOrder("U", approxOrder);
370 CHKERR simple->setFieldOrder("GEOMETRY", geomOrder);
371 CHKERR simple->setUp();
372
373 auto project_ho_geometry = [&]() {
374 Projection10NodeCoordsOnField ent_method(mField, "GEOMETRY");
375 return mField.loop_dofs("GEOMETRY", ent_method);
376 };
377 PetscBool project_geometry = PETSC_TRUE;
378 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-project_geometry",
379 &project_geometry, PETSC_NULLPTR);
380 if (project_geometry) {
381 CHKERR project_ho_geometry();
382 }
383
384 //! [Material models selection]
385
386 /**
387 * FIXME: Here only array of material models is initalized. Each model has
388 * unique set of the ADOL-C tags. Pointer is attached based on block name to
389 * which entity belongs. That will enable heterogeneity of the model, in
390 * addition of heterogeneity of the material properties.
391 */
392
393 enum MaterialModel {
394 VonMisses,
395 VonMissesPlaneStress,
396 Paraboloidal,
397 HeterogeneousParaboloidal,
398 LastModel
399 };
400 const char *list_materials[LastModel] = {"VonMisses", "VonMissesPlaneStress",
401 "Paraboloidal",
402 "HeterogeneousParaboloidal"};
403 PetscInt choice_material = VonMisses;
404 CHKERR PetscOptionsGetEList(PETSC_NULLPTR, NULL, "-material", list_materials,
405 LastModel, &choice_material, PETSC_NULLPTR);
406
407 switch (choice_material) {
408 case VonMisses:
409 cpPtr = createMaterial<J2Plasticity<3>>();
410 break;
411 case VonMissesPlaneStress:
412 if (SPACE_DIM != 2)
413 SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
414 "VonMissesPlaneStrain is only for 2D case");
415 cpPtr = createMaterial<J2Plasticity<2>>();
416 break;
417 case Paraboloidal:
418 cpPtr = createMaterial<ParaboloidalPlasticity>();
419 break;
420 case HeterogeneousParaboloidal:
421 cpPtr = createMaterial<HeterogeneousParaboloidalPlasticity>();
422 break;
423 default:
424 SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY, "Wrong material model");
425 }
426
428 cpPtr->integrationRule = [](int, int, int p) { return 2 * (p - 2); };
429
430 //! [Material models selection]
431
433}
434//! [Set up problem]
435
436//! [Boundary condition]
439 auto *pipeline_mng = mField.getInterface<PipelineManager>();
441 auto bc_mng = mField.getInterface<BcManager>();
442 auto time_scale = boost::make_shared<TimeScale>();
443
444 auto rule = [](int, int, int p) { return 2 * p; };
445 CHKERR pipeline_mng->setDomainRhsIntegrationRule(cpPtr->integrationRule);
446 CHKERR pipeline_mng->setDomainLhsIntegrationRule(cpPtr->integrationRule);
447 CHKERR pipeline_mng->setBoundaryRhsIntegrationRule(rule);
448 CHKERR pipeline_mng->setBoundaryLhsIntegrationRule(rule);
449
451 pipeline_mng->getOpBoundaryLhsPipeline(), {HDIV}, "GEOMETRY");
452 pipeline_mng->getOpBoundaryLhsPipeline().push_back(
454
456 pipeline_mng->getOpBoundaryRhsPipeline(), {HDIV}, "GEOMETRY");
457 pipeline_mng->getOpBoundaryRhsPipeline().push_back(
459
460 // Add Natural BCs to RHS
462 pipeline_mng->getOpBoundaryRhsPipeline(), mField, "U", {time_scale},
463 Sev::inform);
464 // Add Natural BCs to LHS
466 pipeline_mng->getOpBoundaryLhsPipeline(), mField, "U", Sev::inform);
467
468#ifdef ADD_CONTACT
469 CHKERR
470 ContactOps::opFactoryBoundaryLhs<SPACE_DIM, PETSC, GAUSS, BoundaryEleOp>(
471 pipeline_mng->getOpBoundaryLhsPipeline(), "SIGMA", "U");
472 CHKERR
473 ContactOps::opFactoryBoundaryToDomainLhs<SPACE_DIM, PETSC, GAUSS, DomainEle>(
474 mField, pipeline_mng->getOpBoundaryLhsPipeline(),
475 simple->getDomainFEName(), "SIGMA", "U", "GEOMETRY",
476 cpPtr->integrationRule);
477
478 CHKERR
479 ContactOps::opFactoryBoundaryRhs<SPACE_DIM, PETSC, GAUSS, BoundaryEleOp>(
480 pipeline_mng->getOpBoundaryRhsPipeline(), "SIGMA", "U");
481#endif // ADD_CONTACT
482
483 //! Add body froces
485 pipeline_mng->getOpDomainRhsPipeline(), mField, "U", {time_scale},
486 "BODY_FORCE", Sev::inform);
487
488 // Essential BC
489 CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), "REMOVE_X",
490 "U", 0, 0);
491 CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), "REMOVE_Y",
492 "U", 1, 1);
493 CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), "REMOVE_Z",
494 "U", 2, 2);
495#ifdef ADD_CONTACT
496 for (auto b : {"FIX_X", "REMOVE_X"})
497 CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), b,
498 "SIGMA", 0, 0, false, true);
499 for (auto b : {"FIX_Y", "REMOVE_Y"})
500 CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), b,
501 "SIGMA", 1, 1, false, true);
502 for (auto b : {"FIX_Z", "REMOVE_Z"})
503 CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), b,
504 "SIGMA", 2, 2, false, true);
505 for (auto b : {"FIX_ALL", "REMOVE_ALL"})
506 CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), b,
507 "SIGMA", 0, 3, false, true);
508 CHKERR bc_mng->removeBlockDOFsOnEntities(
509 simple->getProblemName(), "NO_CONTACT", "SIGMA", 0, 3, false, true);
510#endif
511
512 CHKERR bc_mng->pushMarkDOFsOnEntities<DisplacementCubitBcData>(
513 simple->getProblemName(), "U");
514
516}
517//! [Boundary condition]
518
519//! [Push operators to pipeline]
522 auto *pipeline_mng = mField.getInterface<PipelineManager>();
523
524 // assemble operator to the right hand side
525 auto add_domain_ops_lhs = [&](auto &pip) {
527 // push forward finite element bases from reference to physical element
529 "GEOMETRY");
530 // create local common data
531 auto common_data_ptr = boost::make_shared<ADOLCPlasticity::CommonData>();
532
533 if (largeStrain) {
534 CHKERR
535 opFactoryDomainHenckyStrainLhs<SPACE_DIM, GAUSS, DomainEleOp>(
536 mField, "U", pip, "ADOLCMAT", common_data_ptr, cpPtr);
537 using B = typename FormsIntegrators<DomainEleOp>::template Assembly<
538 PETSC>::template BiLinearForm<GAUSS>;
539 using OpKPiola =
540 typename B::template OpGradTensorGrad<1, SPACE_DIM, SPACE_DIM, -1>;
541 pip.push_back(
542 new OpKPiola("U", "U", common_data_ptr->getMatTangentPtr()));
543 } else {
545 "U", common_data_ptr->getGradAtGaussPtsPtr()));
546 CHKERR opFactoryDomainLhs<SPACE_DIM, PETSC, GAUSS, DomainEleOp>(
547 mField, "U", pip, "ADOLCMAT", common_data_ptr, cpPtr);
548 }
549
551 };
552
553 auto add_domain_ops_rhs = [&](auto &pip) {
555 // push forward finite element bases from reference to physical element
557 "GEOMETRY");
558 // create local common data
559 auto common_data_ptr = boost::make_shared<ADOLCPlasticity::CommonData>();
560
561 if (largeStrain) {
562 CHKERR
563 opFactoryDomainHenckyStrainRhs<SPACE_DIM, GAUSS, DomainEleOp>(
564 mField, "U", pip, "ADOLCMAT", common_data_ptr, cpPtr);
565 using B = typename FormsIntegrators<DomainEleOp>::template Assembly<
566 PETSC>::template LinearForm<GAUSS>;
569 pip.push_back(
570 new OpInternalForcePiola("U", common_data_ptr->getStressMatrixPtr()));
571 } else {
573 "U", common_data_ptr->getGradAtGaussPtsPtr()));
574 CHKERR opFactoryDomainRhs<SPACE_DIM, PETSC, GAUSS, DomainEleOp>(
575 mField, "U", pip, "ADOLCMAT", common_data_ptr, cpPtr);
576 }
577
578#ifdef ADD_CONTACT
579 CHKERR ContactOps::opFactoryDomainRhs<SPACE_DIM, PETSC, GAUSS, DomainEleOp>(
580 pip, "SIGMA", "U");
581#endif // ADD_CONTACT
583 };
584
585 // Push operators to the left hand side pipeline. Indicate that domain (i.e.
586 // volume/interior) element is used.
587 CHKERR add_domain_ops_lhs(pipeline_mng->getOpDomainLhsPipeline());
588 // Push operators to the right hand side pipeline.
589 CHKERR add_domain_ops_rhs(pipeline_mng->getOpDomainRhsPipeline());
590
592}
593//! [Push operators to pipeline]
594
595/**
596 * @brief Monitor solution
597 *
598 * This functions is called by TS solver at the end of each step. It is used
599 * to output results to the hard drive.
600 */
601struct Monitor : public FEMethod {
603 std::pair<boost::shared_ptr<PostProcEleDomain>,
604 boost::shared_ptr<PostProcEleBdy>>
605 pair_post_proc_fe,
606 boost::shared_ptr<DomainEle> reaction_fe,
607 std::vector<boost::shared_ptr<ScalingMethod>> smv)
608 : dM(dm), reactionFE(reaction_fe), vecOfTimeScalingMethods(smv) {
610 domainPostProcFe = pair_post_proc_fe.first;
611 skinPostProcFe = pair_post_proc_fe.second;
612
613 MoFEM::Interface *m_field_ptr;
614 CHKERR DMoFEMGetInterfacePtr(dM, &m_field_ptr);
615#ifdef ADD_CONTACT
616 auto get_integrate_traction = [&]() {
617 auto integrate_traction = boost::make_shared<BoundaryEle>(*m_field_ptr);
618 auto common_data_ptr = boost::make_shared<ContactOps::CommonData>();
621 integrate_traction->getOpPtrVector(), {HDIV}, "GEOMETRY")),
622 "Apply transform");
623 // We have to integrate on curved face geometry, thus integration weight
624 // have to adjusted.
625 integrate_traction->getOpPtrVector().push_back(
627 integrate_traction->getRuleHook = [](int, int, int approx_order) {
628 return 2 * approx_order + 2 - 1;
629 };
630
634 integrate_traction->getOpPtrVector(), "SIGMA", 0)),
635 "push operators to calculate traction");
636
637 return integrate_traction;
638 };
639
640 integrateTraction = get_integrate_traction();
641#endif
642 }
645 int save_every_nth_step = 1;
646 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-save_every_nth_step",
647 &save_every_nth_step, PETSC_NULLPTR);
648#ifdef ADD_CONTACT
649 auto print_traction = [&](const std::string msg) {
651 MoFEM::Interface *m_field_ptr;
652 CHKERR DMoFEMGetInterfacePtr(dM, &m_field_ptr);
653 if (!m_field_ptr->get_comm_rank()) {
654 const double *t_ptr;
656 MOFEM_LOG_C("CONTACT", Sev::inform, "%s time %3.4e %3.4e %3.4e %3.4e",
657 msg.c_str(), ts_t, t_ptr[0], t_ptr[1], t_ptr[2]);
659 &t_ptr);
660 }
662 };
663#endif
664
665 auto make_vtk = [&]() {
667 if (domainPostProcFe) {
669 getCacheWeakPtr());
670 CHKERR domainPostProcFe->writeFile(
671 "out_plastic_" + boost::lexical_cast<std::string>(ts_step) +
672 ".h5m");
673 }
674 if (skinPostProcFe) {
676 getCacheWeakPtr());
677 CHKERR skinPostProcFe->writeFile(
678 "out_skin_plastic_" + boost::lexical_cast<std::string>(ts_step) +
679 ".h5m");
680 }
682 };
683
684 if (!(ts_step % save_every_nth_step)) {
685 CHKERR make_vtk();
686 }
687 if (reactionFE) {
688 CHKERR VecZeroEntries(fRes);
689 reactionFE->f = fRes;
690 CHKERR DMoFEMLoopFiniteElements(dM, "dFE", reactionFE, getCacheWeakPtr());
691 CHKERR VecAssemblyBegin(fRes);
692 CHKERR VecAssemblyEnd(fRes);
693 CHKERR VecGhostUpdateBegin(fRes, ADD_VALUES, SCATTER_REVERSE);
694 CHKERR VecGhostUpdateEnd(fRes, ADD_VALUES, SCATTER_REVERSE);
695
696 MoFEM::Interface *m_field_ptr;
697 CHKERR DMoFEMGetInterfacePtr(dM, &m_field_ptr);
699 *m_field_ptr, reactionFE, fRes)();
700
701 double nrm;
702 CHKERR VecNorm(fRes, NORM_2, &nrm);
703 MOFEM_LOG("PlasticPrb", Sev::verbose)
704 << "Residual norm " << nrm << " at time step " << ts_step;
705 }
706
707#ifdef ADD_CONTACT
708 auto calculate_traction = [&] {
715 };
716#endif
717
718 auto get_min_max_displacement = [&]() {
720 MoFEM::Interface *m_field_ptr;
721 CHKERR DMoFEMGetInterfacePtr(dM, &m_field_ptr);
722
723 std::array<double, 4> a_min = {DBL_MAX, DBL_MAX, DBL_MAX, 0};
724 std::array<double, 4> a_max = {-DBL_MAX, -DBL_MAX, -DBL_MAX, 0};
725
726 auto get_min_max = [&](boost::shared_ptr<FieldEntity> field_entity_ptr) {
728 int d = 0;
729 for (auto v : field_entity_ptr->getEntFieldData()) {
730 a_min[d] = std::min(a_min[d], v);
731 a_max[d] = std::max(a_max[d], v);
732 ++d;
733 }
735 };
736
737 a_min[SPACE_DIM] = 0;
738 a_max[SPACE_DIM] = 0;
739
740 Range verts;
741 CHKERR m_field_ptr->get_field_entities_by_type("U", MBVERTEX, verts);
742 CHKERR m_field_ptr->getInterface<FieldBlas>()->fieldLambdaOnEntities(
743 get_min_max, "U", &verts);
744
745 auto mpi_reduce = [&](auto &a, auto op) {
746 std::array<double, 3> a_mpi = {0, 0, 0};
747 MPI_Allreduce(a.data(), a_mpi.data(), 3, MPI_DOUBLE, op,
748 m_field_ptr->get_comm());
749 return a_mpi;
750 };
751
752 auto a_min_mpi = mpi_reduce(a_min, MPI_MIN);
753 auto a_max_mpi = mpi_reduce(a_max, MPI_MAX);
754
755 MOFEM_LOG("PlasticPrb", Sev::inform)
756 << "Min displacement " << a_min_mpi[0] << " " << a_min_mpi[1] << " "
757 << a_min_mpi[2];
758 MOFEM_LOG("PlasticPrb", Sev::inform)
759 << "Max displacement " << a_max_mpi[0] << " " << a_max_mpi[1] << " "
760 << a_max_mpi[2];
762 };
763 CHKERR get_min_max_displacement();
764#ifdef ADD_CONTACT
765 CHKERR calculate_traction();
766 CHKERR print_traction("Contact force");
767#endif
768 double scale = 1;
769 for (auto s : vecOfTimeScalingMethods) {
770 scale *= s->getScale(this->ts_t);
771 }
772
773 MOFEM_LOG("PlasticPrb", Sev::inform)
774 << "Time: " << this->ts_t << " scale: " << scale;
775
777 }
778
779private:
781 boost::shared_ptr<PostProcEleDomain> domainPostProcFe;
782 boost::shared_ptr<PostProcEleBdy> skinPostProcFe;
783 boost::shared_ptr<FEMethod> reactionFE;
784
785 boost::shared_ptr<BoundaryEle> integrateTraction;
786
789};
790
791static boost::shared_ptr<TSUpdate> ts_update_ptr = nullptr;
792
793//! [Solve]
796 auto *simple = mField.getInterface<Simple>();
797 auto *pipeline_mng = mField.getInterface<PipelineManager>();
798
799 auto dm = simple->getDM();
800 auto time_scale = boost::make_shared<TimeScale>();
801 auto snes_ctx_ptr = getDMSnesCtx(simple->getDM());
802
803 // Setup postprocessing
804 auto create_post_proc_fe = [dm, this, simple]() {
805 //! [DG projection]
806 // Post-process domain, i.e. volume elements. If 3d case creates stresses
807 // are evaluated at points which are trace of the volume element on boundary
808 auto post_proc_ele_domain = [this](auto &pip_domain, auto &fe_name) {
809 // Push bases on reference element to the phyiscal element
811 pip_domain, {H1, HDIV}, "GEOMETRY");
812
813 // calculate displacement gradients at nodes of post processing mesh. For
814 // gradient DG projection is obsolete, since displacements can be
815 // evaluated at arbitrary points.
816 auto grad_ptr = boost::make_shared<MatrixDouble>();
817 pip_domain.push_back(
819 grad_ptr));
820
821 // Create operator to run (neted) pipeline in operator. InteriorElem
822 // element will have iteration rule and bases as domain element used to
823 // solve problem, and remember history variables.
824 using InteriorElem = DomainEle;
825 auto op_this = new OpLoopThis<InteriorElem>(mField, fe_name, Sev::noisy);
826 // add interior element to post-processing pipeline
827 pip_domain.push_back(op_this);
828
829 // get pointer to interior element, which is in essence pipeline which
830 // pipeline.
831 auto fe_physics = op_this->getThisFEPtr();
832
833 auto evaluate_stress_on_physical_element = [&]() {
834 // evaluate stress and plastic strain at Gauss points
835 fe_physics->getRuleHook = cpPtr->integrationRule;
837 fe_physics->getOpPtrVector(), {H1});
838 auto common_data_ptr =
839 boost::make_shared<ADOLCPlasticity::CommonData>();
840 // note that gradient of displacements is evaluate again, at
841 // physical nodes
842 if (largeStrain) {
843 CHKERR
844 opFactoryDomainHenckyStrainRhs<SPACE_DIM, GAUSS, DomainEleOp>(
845 mField, "U", fe_physics->getOpPtrVector(), "ADOLCMAT",
846 common_data_ptr, cpPtr);
847
848 } else {
849 fe_physics->getOpPtrVector().push_back(
851 "U", common_data_ptr->getGradAtGaussPtsPtr()));
852 CHKERR cpPtr->addMatBlockOps(mField, fe_physics->getOpPtrVector(),
853 "ADOLCMAT", Sev::inform);
854 fe_physics->getOpPtrVector().push_back(
855 getRawPtrOpCalculateStress<SPACE_DIM, SMALL_STRAIN>(
856 mField, common_data_ptr, cpPtr, false));
857 }
858 return common_data_ptr;
859 };
860
861 auto dg_projection_froward_and_back = [&](auto &common_data_ptr) {
862 // here we do actual projection of stress and plastic strain to DG space
863 int dg_order = approxOrder - 1;
864 auto entity_data_l2 =
865 boost::make_shared<EntitiesFieldData>(MBENTITYSET);
866 auto mass_ptr =
867 boost::make_shared<MatrixDouble>(); //< projection operator (mass
868 // matrix)
869 fe_physics->getOpPtrVector().push_back(new OpDGProjectionMassMatrix(
870 dg_order, mass_ptr, entity_data_l2, approxBase, L2));
871
872 auto coeffs_ptr_stress = boost::make_shared<MatrixDouble>();
873 // project stress on DG space on physical element
874 fe_physics->getOpPtrVector().push_back(new OpDGProjectionCoefficients(
875 common_data_ptr->getStressMatrixPtr(), coeffs_ptr_stress, mass_ptr,
876 entity_data_l2, approxBase, L2));
877 // project strains plastic strains DG space on physical element
878 auto coeffs_ptr_plastic_strain = boost::make_shared<MatrixDouble>();
879 fe_physics->getOpPtrVector().push_back(new OpDGProjectionCoefficients(
880 common_data_ptr->getPlasticStrainMatrixPtr(),
881 coeffs_ptr_plastic_strain, mass_ptr, entity_data_l2, approxBase,
882 L2));
883
884 // project stress and plastic strain for DG space on post-process
885 // element
886 pip_domain.push_back(new OpDGProjectionEvaluation(
887 common_data_ptr->getStressMatrixPtr(), coeffs_ptr_stress,
888 entity_data_l2, approxBase, L2));
889 pip_domain.push_back(new OpDGProjectionEvaluation(
890 common_data_ptr->getPlasticStrainMatrixPtr(),
891 coeffs_ptr_plastic_strain, entity_data_l2, approxBase, L2));
892 };
893
894 auto common_data_ptr = evaluate_stress_on_physical_element();
895 dg_projection_froward_and_back(common_data_ptr);
896
897 return boost::make_tuple(grad_ptr, common_data_ptr->getStressMatrixPtr(),
898 common_data_ptr->getPlasticStrainMatrixPtr());
899 };
900 //! [DG projection]
901
902 // Create tags on post-processing mesh, i.e. those tags are visible in
903 // Preview
904 auto add_post_proc_map = [&](auto post_proc_fe, auto u_ptr, auto grad_ptr,
905 auto stress_ptr, auto plastic_strain_ptr,
906 auto contact_stress_ptr, auto X_ptr) {
907 using OpPPMapSpaceDim = OpPostProcMapInMoab<SPACE_DIM, SPACE_DIM>;
908 using DataMapMat = typename OpPPMapSpaceDim::DataMapMat;
909 DataMapMat tensor_data_space_dim = {{"GRAD", grad_ptr},
910 {"SIGMA", contact_stress_ptr}};
911 if (largeStrain)
912 tensor_data_space_dim["PK1"] = stress_ptr;
913
914 post_proc_fe->getOpPtrVector().push_back(
915
916 new OpPPMapSpaceDim(
917
918 post_proc_fe->getPostProcMesh(), post_proc_fe->getMapGaussPts(),
919
920 {},
921
922 {{"U", u_ptr}, {"GEOMETRY", X_ptr}},
923
924 tensor_data_space_dim,
925
926 {}
927
928 )
929
930 );
931
932 DataMapMat tensor_data_3d = {{"PLASTIC_STRAIN", plastic_strain_ptr}};
933 if (!largeStrain)
934 tensor_data_3d["STRESS"] = stress_ptr;
935
936 using OpPPMap3D = OpPostProcMapInMoab<3, 3>;
937 post_proc_fe->getOpPtrVector().push_back(
938
939 new OpPPMap3D(
940
941 post_proc_fe->getPostProcMesh(), post_proc_fe->getMapGaussPts(),
942
943 {},
944
945 {},
946
947 {},
948
949 tensor_data_3d
950
951 )
952
953 );
954
955 return post_proc_fe;
956 };
957
958 auto vol_post_proc = [this, simple, post_proc_ele_domain,
959 add_post_proc_map]() {
960 PetscBool post_proc_vol = PETSC_FALSE;
961 if (SPACE_DIM == 2)
962 post_proc_vol = PETSC_TRUE;
963
964 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-post_proc_vol",
965 &post_proc_vol, PETSC_NULLPTR);
966 if (post_proc_vol == PETSC_FALSE)
967 return boost::shared_ptr<PostProcEleDomain>();
968 auto post_proc_fe = boost::make_shared<PostProcEleDomain>(mField);
969 auto u_ptr = boost::make_shared<MatrixDouble>();
970 post_proc_fe->getOpPtrVector().push_back(
972 auto X_ptr = boost::make_shared<MatrixDouble>();
973 post_proc_fe->getOpPtrVector().push_back(
974 new OpCalculateVectorFieldValues<SPACE_DIM>("GEOMETRY", X_ptr));
975 auto contact_stress_ptr = boost::make_shared<MatrixDouble>();
976#ifdef ADD_CONTACT
977 post_proc_fe->getOpPtrVector().push_back(
979 "SIGMA", contact_stress_ptr));
980#else
981 contact_stress_ptr = nullptr;
982#endif
983 auto [grad_ptr, stress_ptr, plastic_strain_ptr] = post_proc_ele_domain(
984 post_proc_fe->getOpPtrVector(), simple->getDomainFEName());
985
986 return add_post_proc_map(post_proc_fe, u_ptr, grad_ptr, stress_ptr,
987 plastic_strain_ptr, contact_stress_ptr, X_ptr);
988 };
989
990 auto skin_post_proc = [this, simple, post_proc_ele_domain,
991 add_post_proc_map]() {
992 // create skin of the volume mesh for post-processing,
993 // i.e. boundary of the volume mesh
994 PetscBool post_proc_skin = PETSC_TRUE;
995 if (SPACE_DIM == 2)
996 post_proc_skin = PETSC_FALSE;
997
998 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-post_proc_skin",
999 &post_proc_skin, PETSC_NULLPTR);
1000
1001 if (post_proc_skin == PETSC_FALSE)
1002 return boost::shared_ptr<PostProcEleBdy>();
1003
1004 auto post_proc_fe = boost::make_shared<PostProcEleBdy>(mField);
1005 auto u_ptr = boost::make_shared<MatrixDouble>();
1006 post_proc_fe->getOpPtrVector().push_back(
1008 auto X_ptr = boost::make_shared<MatrixDouble>();
1009 post_proc_fe->getOpPtrVector().push_back(
1010 new OpCalculateVectorFieldValues<SPACE_DIM>("GEOMETRY", X_ptr));
1011 auto contact_stress_ptr = boost::make_shared<MatrixDouble>();
1012 auto op_loop_side =
1013 new OpLoopSide<SideEle>(mField, simple->getDomainFEName(), SPACE_DIM);
1014 auto [grad_ptr, stress_ptr, plastic_strain_ptr] = post_proc_ele_domain(
1015 op_loop_side->getOpPtrVector(), simple->getDomainFEName());
1016#ifdef ADD_CONTACT
1017 op_loop_side->getOpPtrVector().push_back(
1019 "SIGMA", contact_stress_ptr));
1020#else
1021 contact_stress_ptr = nullptr;
1022#endif
1023 post_proc_fe->getOpPtrVector().push_back(op_loop_side);
1024
1025 return add_post_proc_map(post_proc_fe, u_ptr, grad_ptr, stress_ptr,
1026 plastic_strain_ptr, contact_stress_ptr, X_ptr);
1027 };
1028
1029 return std::make_pair(vol_post_proc(), skin_post_proc());
1030 };
1031
1032 auto create_reaction_fe = [&]() {
1033 auto fe_ptr = boost::make_shared<DomainEle>(mField);
1034 fe_ptr->getRuleHook = cpPtr->integrationRule;
1035
1036 auto &pip = fe_ptr->getOpPtrVector();
1038 auto common_data_ptr = boost::make_shared<ADOLCPlasticity::CommonData>();
1039
1040 if (largeStrain) {
1041 CHKERR
1042 opFactoryDomainHenckyStrainRhs<SPACE_DIM, GAUSS, DomainEleOp>(
1043 mField, "U", pip, "ADOLCMAT", common_data_ptr, cpPtr);
1044 using B = typename FormsIntegrators<DomainEleOp>::template Assembly<
1045 PETSC>::template LinearForm<GAUSS>;
1046 using OpInternalForcePiola =
1047 typename B::template OpGradTimesTensor<1, SPACE_DIM, SPACE_DIM>;
1048 pip.push_back(
1049 new OpInternalForcePiola("U", common_data_ptr->getStressMatrixPtr()));
1050 } else {
1052 "U", common_data_ptr->getGradAtGaussPtsPtr()));
1053 CHKERR opFactoryDomainRhs<SPACE_DIM, PETSC, GAUSS, DomainEleOp>(
1054 mField, "U", pip, "ADOLCMAT", common_data_ptr, cpPtr);
1055 }
1056
1057 return fe_ptr;
1058 };
1059
1060 auto add_extra_finite_elements_to_ksp_solver_pipelines = [&]() {
1062
1063 auto pre_proc_ptr = boost::make_shared<FEMethod>();
1064 auto post_proc_rhs_ptr = boost::make_shared<FEMethod>();
1065 auto post_proc_lhs_ptr = boost::make_shared<FEMethod>();
1066
1067 auto get_bc_hook_rhs = [this, pre_proc_ptr, time_scale]() {
1070 {time_scale}, false)();
1072 };
1073
1074 pre_proc_ptr->preProcessHook = get_bc_hook_rhs;
1075
1076 auto get_post_proc_hook_rhs = [this, post_proc_rhs_ptr]() {
1079 mField, post_proc_rhs_ptr, nullptr, Sev::verbose)();
1081 mField, post_proc_rhs_ptr, 1.)();
1083 };
1084 auto get_post_proc_hook_lhs = [this, post_proc_lhs_ptr]() {
1087 mField, post_proc_lhs_ptr, 1.)();
1089 };
1090 post_proc_rhs_ptr->postProcessHook = get_post_proc_hook_rhs;
1091 post_proc_lhs_ptr->postProcessHook = get_post_proc_hook_lhs;
1092
1093 // This is low level pushing finite elements (pipelines) to solver
1094 auto ts_ctx_ptr = getDMTsCtx(simple->getDM());
1095 ts_ctx_ptr->getPreProcessIFunction().push_front(pre_proc_ptr);
1096 ts_ctx_ptr->getPreProcessIJacobian().push_front(pre_proc_ptr);
1097 ts_ctx_ptr->getPostProcessIFunction().push_back(post_proc_rhs_ptr);
1098 ts_ctx_ptr->getPostProcessIJacobian().push_back(post_proc_lhs_ptr);
1100 };
1101
1102 // Add extra finite elements to SNES solver pipelines to resolve essential
1103 // boundary conditions
1104 CHKERR add_extra_finite_elements_to_ksp_solver_pipelines();
1105
1106 auto create_monitor_fe = [dm, time_scale](auto &&post_proc_fe,
1107 auto &&reaction_fe) {
1108 return boost::make_shared<Monitor>(
1109 dm, post_proc_fe, reaction_fe,
1110 std::vector<boost::shared_ptr<ScalingMethod>>{time_scale});
1111 };
1112
1113 //! [Set up post-step]
1114 auto set_up_post_step = [&](auto ts) {
1116
1117 // create finite element (pipeline) and populate it with operators to
1118 // update history variables
1119 auto create_update_ptr = [&]() {
1120 auto fe_ptr = boost::make_shared<DomainEle>(mField);
1121 fe_ptr->getRuleHook = cpPtr->integrationRule;
1122 AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(fe_ptr->getOpPtrVector(),
1123 {H1});
1124 auto common_data_ptr = boost::make_shared<ADOLCPlasticity::CommonData>();
1125
1126 if (largeStrain) {
1127 CHKERR opFactoryDomainHenckyStrainRhs<SPACE_DIM, GAUSS, DomainEleOp>(
1128 mField, "U", fe_ptr->getOpPtrVector(), "ADOLCMAT", common_data_ptr,
1129 cpPtr);
1130 } else {
1131 fe_ptr->getOpPtrVector().push_back(
1133 "U", common_data_ptr->getGradAtGaussPtsPtr()));
1134 CHKERR cpPtr->addMatBlockOps(mField, fe_ptr->getOpPtrVector(),
1135 "ADOLCMAT", Sev::noisy);
1136 fe_ptr->getOpPtrVector().push_back(
1137 getRawPtrOpCalculateStress<SPACE_DIM, SMALL_STRAIN>(
1138 mField, common_data_ptr, cpPtr, false));
1139 }
1140
1142 opFactoryDomainUpdate<SPACE_DIM>(mField, fe_ptr->getOpPtrVector(),
1143 "ADOLCMAT", common_data_ptr, cpPtr),
1144 "push update ops");
1145 return fe_ptr;
1146 };
1147
1148 // ts_update_ptr is global static variable
1150 createTSUpdate(simple->getDomainFEName(), create_update_ptr());
1151
1152 //! [TS post-step function]
1153 // This is pure "C" function which we can to the TS solver
1154 auto ts_step_post_proc = [](TS ts) {
1156 if (ts_update_ptr)
1157 CHKERR ts_update_ptr->postProcess(ts);
1159 };
1160 //! [TS post-step function]
1161
1162 // finally set up post-step
1163 CHKERR TSSetPostStep(ts, ts_step_post_proc);
1165 };
1166 //! [Set up post-step]
1167
1168 // Set monitor which postprocessing results and saves them to the hard drive
1169 auto set_up_monitor = [&](auto ts) {
1171 boost::shared_ptr<FEMethod> null_fe;
1172 auto monitor_ptr =
1173 create_monitor_fe(create_post_proc_fe(), create_reaction_fe());
1174 CHKERR DMMoFEMTSSetMonitor(dm, ts, simple->getDomainFEName(), null_fe,
1175 null_fe, monitor_ptr);
1177 };
1178
1179 auto set_section_monitor = [&](auto solver) {
1181 SNES snes;
1182 CHKERR TSGetSNES(solver, &snes);
1183 CHKERR SNESMonitorSet(snes,
1184 (MoFEMErrorCode(*)(SNES, PetscInt, PetscReal,
1185 void *))MoFEMSNESMonitorFields,
1186 (void *)(snes_ctx_ptr.get()), nullptr);
1188 };
1189
1190 auto set_up_adapt = [&](auto ts) {
1192 CHKERR TSAdaptRegister(TSADAPTMOFEM, TSAdaptCreateMoFEM);
1193 TSAdapt adapt;
1194 CHKERR TSGetAdapt(ts, &adapt);
1196 };
1197
1198 //! [Create TS]
1199 auto ts = pipeline_mng->createTSIM();
1200
1201 // Set time solver
1202 double ftime = 1;
1203 CHKERR TSSetMaxTime(ts, ftime);
1204 CHKERR TSSetExactFinalTime(ts, TS_EXACTFINALTIME_MATCHSTEP);
1205 auto D = createDMVector(simple->getDM());
1206 auto B = createDMMatrix(dm);
1207 CHKERR TSSetIJacobian(ts, B, B, PETSC_NULLPTR, PETSC_NULLPTR);
1208#ifdef ADD_CONTACT
1210#endif
1211 CHKERR TSSetSolution(ts, D);
1212 CHKERR set_section_monitor(ts);
1213
1214 // Set monitor, step adaptivity, and post-step to update history variables
1215 CHKERR set_up_monitor(ts);
1216 CHKERR set_up_post_step(ts);
1217 CHKERR set_up_adapt(ts);
1218 CHKERR TSSetFromOptions(ts);
1219
1220 CHKERR TSSolve(ts, NULL);
1221 //! [Create TS]
1222
1223 CHKERR TSGetTime(ts, &ftime);
1224
1225 PetscInt steps, snesfails, rejects, nonlinits, linits;
1226 CHKERR TSGetStepNumber(ts, &steps);
1227 CHKERR TSGetSNESFailures(ts, &snesfails);
1228 CHKERR TSGetStepRejections(ts, &rejects);
1229 CHKERR TSGetSNESIterations(ts, &nonlinits);
1230 CHKERR TSGetKSPIterations(ts, &linits);
1231 MOFEM_LOG_C("PlasticPrb", Sev::inform,
1232 "steps %d (%d rejected, %d SNES fails), ftime %g, nonlinits "
1233 "%d, linits %d",
1234 steps, rejects, snesfails, ftime, nonlinits, linits);
1235
1237}
1238//! [Solve]
1239
1240//! [Getting norms]
1243
1244 auto simple = mField.getInterface<Simple>();
1245 auto dm = simple->getDM();
1246
1247 auto T = createDMVector(simple->getDM());
1248 CHKERR DMoFEMMeshToLocalVector(simple->getDM(), T, INSERT_VALUES,
1249 SCATTER_FORWARD);
1250 double nrm2;
1251 CHKERR VecNorm(T, NORM_2, &nrm2);
1252 MOFEM_LOG("PlasticPrb", Sev::inform) << "Solution norm " << nrm2;
1253
1254 auto post_proc_norm_fe = boost::make_shared<DomainEle>(mField);
1255
1256 post_proc_norm_fe->getRuleHook = cpPtr->integrationRule;
1257
1259 post_proc_norm_fe->getOpPtrVector(), {H1});
1260
1261 enum NORMS { U_NORM_L2 = 0, PIOLA_NORM, LAST_NORM };
1262 auto norms_vec =
1264 (mField.get_comm_rank() == 0) ? LAST_NORM : 0, LAST_NORM);
1265 CHKERR VecZeroEntries(norms_vec);
1266
1267 auto u_ptr = boost::make_shared<MatrixDouble>();
1268 post_proc_norm_fe->getOpPtrVector().push_back(
1270
1271 post_proc_norm_fe->getOpPtrVector().push_back(
1272 new OpCalcNormL2Tensor1<SPACE_DIM>(u_ptr, norms_vec, U_NORM_L2));
1273
1275 post_proc_norm_fe);
1276
1277 CHKERR VecAssemblyBegin(norms_vec);
1278 CHKERR VecAssemblyEnd(norms_vec);
1279
1280 MOFEM_LOG_CHANNEL("SELF"); // Clear channel from old tags
1281 if (mField.get_comm_rank() == 0) {
1282 const double *norms;
1283 CHKERR VecGetArrayRead(norms_vec, &norms);
1284 MOFEM_TAG_AND_LOG("SELF", Sev::inform, "example")
1285 << "norm_u: " << std::scientific << std::sqrt(norms[U_NORM_L2]);
1286 CHKERR VecRestoreArrayRead(norms_vec, &norms);
1287 }
1288
1290}
1291//! [Getting norms]
1292
1293//! [Postprocessing results]
1296 PetscInt test_nb = 0;
1297 PetscBool test_flg = PETSC_FALSE;
1298 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-test", &test_nb, &test_flg);
1299
1300 if (test_flg) {
1301 auto simple = mField.getInterface<Simple>();
1302 auto T = createDMVector(simple->getDM());
1303 CHKERR DMoFEMMeshToLocalVector(simple->getDM(), T, INSERT_VALUES,
1304 SCATTER_FORWARD);
1305 double nrm2;
1306 CHKERR VecNorm(T, NORM_2, &nrm2);
1307 MOFEM_LOG("PlasticPrb", Sev::verbose) << "Regression norm " << nrm2;
1308 double regression_value = 0;
1309 switch (test_nb) {
1310 default:
1311 SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID, "Wrong test number.");
1312 break;
1313 }
1314 if (fabs(nrm2 - regression_value) > 1e-2)
1315 SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
1316 "Regression test field; wrong norm value. %6.4e != %6.4e", nrm2,
1317 regression_value);
1318 }
1320}
1321//! [Postprocessing results]
1322
1323//! [Check]
1331//! [Check]
1332
1333static char help[] = "...\n\n";
1334
1335int main(int argc, char *argv[]) {
1336
1337#ifdef ADD_CONTACT
1338#ifdef ENABLE_PYTHON_BINDING
1339 Py_Initialize();
1340 np::initialize();
1341#endif
1342#endif // ADD_CONTACT
1343
1344 // Initialisation of MoFEM/PETSc and MOAB data structures
1345 const char param_file[] = "param_file.petsc";
1346 MoFEM::Core::Initialize(&argc, &argv, param_file, help);
1347
1348 // Add logging channel for example
1349 auto core_log = logging::core::get();
1350 core_log->add_sink(
1352 LogManager::setLog("PlasticPrb");
1353 MOFEM_LOG_TAG("PlasticPrb", "PlasticPrb");
1354 MOFEM_LOG("PlasticPrb", Sev::inform) << "SPACE_DIM " << SPACE_DIM;
1355#ifdef ADD_CONTACT
1356 core_log->add_sink(
1358 LogManager::setLog("CONTACT");
1359 MOFEM_LOG_TAG("CONTACT", "Contact");
1360#endif // ADD_CONTACT
1361
1362 try {
1363
1364 //! [Register MoFEM discrete manager in PETSc]
1365 DMType dm_name = "DMMOFEM";
1366 CHKERR DMRegister_MoFEM(dm_name);
1367 //! [Register MoFEM discrete manager in PETSc
1368
1369 //! [Create MoAB]
1370 moab::Core mb_instance; ///< mesh database
1371 moab::Interface &moab = mb_instance; ///< mesh database interface
1372 //! [Create MoAB]
1373
1374 //! [Create MoFEM]
1375 MoFEM::Core core(moab); ///< finite element database
1376 MoFEM::Interface &m_field = core; ///< finite element database interface
1377 //! [Create MoFEM]
1378
1379 //! [PlasticProblem]
1380 PlasticProblem ex(m_field);
1381 CHKERR ex.runProblem();
1382 //! [PlasticProblem]
1383 }
1385
1387#ifdef ADD_CONTACT
1388#ifdef ENABLE_PYTHON_BINDING
1389 if (Py_FinalizeEx() < 0) {
1390 exit(120);
1391 }
1392#endif
1393#endif // ADD_CONTACT
1394 return 0;
1395}
Matetial models for plasticity.
MoFEM::Interface & mField
FaceSet skin
#define MOFEM_LOG_SYNCHRONISE(comm)
Synchronise "SYNC" channel.
#define MOFEM_LOG_C(channel, severity, format,...)
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
#define TSADAPTMOFEM
Definition TsCtx.hpp:10
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition acoustic.cpp:69
int main()
static char help[]
[Check]
constexpr int SPACE_DIM
double scale
static boost::shared_ptr< TSUpdate > ts_update_ptr
PipelineManager::ElementsAndOpsByDim< SPACE_DIM >::DomainEle DomainEle
constexpr FieldSpace CONTACT_SPACE
constexpr double a
constexpr int SPACE_DIM
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
ElementsAndOps< SPACE_DIM >::BoundaryEle BoundaryEle
#define CATCH_ERRORS
Catch errors.
FieldApproximationBase
approximation base
Definition definitions.h:58
@ LASTBASE
Definition definitions.h:69
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition definitions.h:60
@ DEMKOWICZ_JACOBI_BASE
Definition definitions.h:66
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
FieldSpace
approximation spaces
Definition definitions.h:82
@ L2
field with C-1 continuity
Definition definitions.h:88
@ H1
continuous field
Definition definitions.h:85
@ HCURL
field with continuous tangents
Definition definitions.h:86
@ HDIV
field with continuous normal traction
Definition definitions.h:87
#define MYPCOMM_INDEX
default communicator number PCOMM
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_ATOM_TEST_INVALID
Definition definitions.h:40
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
PostProcEleByDim< SPACE_DIM >::PostProcEleDomain PostProcEleDomain
PostProcEleByDim< SPACE_DIM >::PostProcEleBdy PostProcEleBdy
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:600
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition DMMoFEM.cpp:43
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
Definition DMMoFEM.cpp:662
auto createDMVector(DM dm, RowColData rc=RowColData::COL)
Get smart vector from DM.
Definition DMMoFEM.hpp:1279
PetscErrorCode DMoFEMGetInterfacePtr(DM dm, MoFEM::Interface **m_field_ptr)
Get pointer to MoFEM::Interface.
Definition DMMoFEM.cpp:439
auto createDMMatrix(DM dm)
Get smart matrix from DM.
Definition DMMoFEM.hpp:1236
virtual MoFEMErrorCode get_field_entities_by_type(const std::string name, EntityType type, Range &ents) const =0
get entities in the field by type
@ GAUSS
Gaussian quadrature integration.
@ PETSC
Standard PETSc assembly.
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.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
virtual MoFEMErrorCode loop_dofs(const Problem *problem_ptr, const std::string &field_name, RowColData rc, DofMethod &method, int lower_rank, int upper_rank, int verb=DEFAULT_VERBOSITY)=0
Make a loop over dofs.
double D
const double v
phase velocity of light in medium (cm/ns)
boost::shared_ptr< TSUpdate > createTSUpdate(std::string fe_name, boost::shared_ptr< FEMethod > fe_ptr)
double cn_contact
Definition contact.cpp:88
MoFEMErrorCode opFactoryCalculateTraction(boost::ptr_deque< ForcesAndSourcesCore::UserDataOperator > &pip, std::string sigma, bool is_axisymmetric=false)
[HenckyOps]
Definition HenckyOps.hpp:12
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
PetscErrorCode DMMoFEMTSSetMonitor(DM dm, TS ts, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
Set Monitor To TS solver.
Definition DMMoFEM.cpp:1132
auto getDMTsCtx(DM dm)
Get TS context data structure used by DM.
Definition DMMoFEM.hpp:1321
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
MoFEMErrorCode MoFEMSNESMonitorFields(SNES snes, PetscInt its, PetscReal fgnorm, SnesCtx *ctx)
Sens monitor printing residual field by field.
Definition SnesCtx.cpp:600
std::vector< boost::shared_ptr< ScalingMethod > > VecOfTimeScalingMethods
Vector of time scaling methods.
Definition Natural.hpp:20
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 createVectorMPI(MPI_Comm comm, PetscInt n, PetscInt N)
Create MPI Vector.
PetscErrorCode PetscOptionsGetEList(PetscOptions *, const char pre[], const char name[], const char *const *list, PetscInt next, PetscInt *value, PetscBool *set)
auto getDMSnesCtx(DM dm)
Get SNES context data structure used by DM.
Definition DMMoFEM.hpp:1307
PetscErrorCode TSAdaptCreateMoFEM(TSAdapt adapt)
Craete MOFEM adapt.
Definition TsCtx.cpp:829
FormsIntegrators< DomainEleOp >::Assembly< A >::LinearForm< I >::OpGradTimesTensor< 1, FIELD_DIM, SPACE_DIM > OpGradTimesTensor
int save_every_nth_step
#define EXECUTABLE_DIMENSION
Definition plastic.cpp:13
double scale
Definition plastic.cpp:124
ElementsAndOps< SPACE_DIM >::SideEle SideEle
Definition plastic.cpp:62
constexpr FieldSpace CONTACT_SPACE
Definition plastic.cpp:52
static constexpr int approx_order
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::LinearForm< GAUSS >::OpGradTimesTensor< 1, SPACE_DIM, SPACE_DIM > OpInternalForcePiola
Definition seepage.cpp:65
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpGradTensorGrad< 1, SPACE_DIM, SPACE_DIM, -1 > OpKPiola
[Only used for dynamics]
Definition seepage.cpp:63
FTensor::Index< 'm', 3 > m
static SmartPetscObj< Vec > totalTractionAndArea
static auto createTotalTraction(MoFEM::Interface &m_field)
PipelineManager::ElementsAndOpsByDim< 2 >::FaceSideEle SideEle
Definition plastic.cpp:29
PipelineManager::ElementsAndOpsByDim< 3 >::FaceSideEle SideEle
Definition plastic.cpp:36
[Operators_definition]
Add operators pushing bases from local to physical configuration.
Boundary condition manager for finite element problem setup.
Managing BitRefLevels.
virtual moab::Interface & get_moab()=0
virtual MPI_Comm & get_comm() const =0
virtual int get_comm_rank() 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.
Definition of the displacement bc data structure.
Definition BCData.hpp:72
Data on single entity (This is passed as argument to DataOperator::doWork)
Class (Function) to enforce essential constrains on the left hand side diagonal.
Definition Essential.hpp:33
Class (Function) to enforce essential constrains on the right hand side diagonal.
Definition Essential.hpp:41
Class (Function) to calculate residual side diagonal.
Definition Essential.hpp:49
Class (Function) to enforce essential constrains.
Definition Essential.hpp:25
Structure for user loop methods on finite elements.
Basic algebra on fields.
Definition FieldBlas.hpp:21
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.
Interface for managing meshsets containing materials and boundary conditions.
Assembly methods.
Definition Natural.hpp:65
Get norm of input MatrixDouble for Tensor1.
Calculate tenor field using vectorial base, i.e. Hdiv/Hcurl.
Get field gradients at integration pts for scalar field rank 0, i.e. vector field.
Specialization for MatrixDouble vector field values calculation.
Solve a local L2 system for integration-point data.
Evaluate local L2 coefficients, also with no attached field.
Element used to execute operators on side of the element.
Execute "this" element in the operator.
Post post-proc data at points from hash maps.
Template struct for dimension-specific finite element types.
PipelineManager interface.
Projection of edge entities with one mid-node on hierarchical basis.
Simple interface for fast problem set-up.
Definition Simple.hpp:27
MoFEMErrorCode getOptions()
get options
Definition Simple.cpp:180
MoFEMErrorCode getDM(DM *dm)
Get DM.
Definition Simple.cpp:802
const std::string getDomainFEName() const
Get the Domain FE Name.
Definition Simple.hpp:429
intrusive_ptr for managing petsc objects
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
[Push operators to pipeline]
boost::shared_ptr< PostProcEleDomain > domainPostProcFe
boost::shared_ptr< BoundaryEle > integrateTraction
boost::shared_ptr< FEMethod > reactionFE
Monitor(SmartPetscObj< DM > dm, std::pair< boost::shared_ptr< PostProcEleDomain >, boost::shared_ptr< PostProcEleBdy > > pair_post_proc_fe, boost::shared_ptr< DomainEle > reaction_fe, std::vector< boost::shared_ptr< ScalingMethod > > smv)
VecOfTimeScalingMethods vecOfTimeScalingMethods
boost::shared_ptr< PostProcEleBdy > skinPostProcFe
SmartPetscObj< Vec > fRes
MoFEMErrorCode postProcess()
SmartPetscObj< DM > dM
PlasticProblem(MoFEM::Interface &m_field)
MoFEMErrorCode setupProblem()
[Read mesh]
MoFEMErrorCode readMesh()
[Run problem]
FieldApproximationBase approxBase
MoFEMErrorCode outputResults()
[Getting norms]
boost::shared_ptr< ClosestPointProjection > cpPtr
MoFEMErrorCode checkResults()
[Postprocessing results]
MoFEMErrorCode boundaryCondition()
[Set up problem]
MoFEM::Interface & mField
PetscBool largeStrain
Large strain flag.
MoFEMErrorCode assembleSystem()
[Boundary condition]
MoFEMErrorCode gettingNorms()
[Solve]
MoFEMErrorCode runProblem()
[Run problem]
MoFEMErrorCode solveSystem()
[Solve]