v0.16.3
Loading...
Searching...
No Matches
plastic.cpp
Go to the documentation of this file.
1/**
2 * \file plastic.cpp
3 * \example mofem/tutorials/adv-0_plasticity/plastic.cpp
4 *
5 * Plasticity in 2d and 3d
6 *
7 */
8
9/* The above code is a preprocessor directive in C++ that checks if the macro
10"EXECUTABLE_DIMENSION" has been defined. If it has not been defined, it replaces
11the " */
12#ifndef EXECUTABLE_DIMENSION
13 #define EXECUTABLE_DIMENSION 3
14#endif
15
16// #undef ADD_CONTACT
17
18#include <MoFEM.hpp>
19#include <MatrixFunction.hpp>
20#include <IntegrationRules.hpp>
21
22using namespace MoFEM;
23
24template <int DIM> struct ElementsAndOps;
25
26template <> struct ElementsAndOps<2> {
30 static constexpr FieldSpace CONTACT_SPACE = HCURL;
31};
32
33template <> struct ElementsAndOps<3> {
37 static constexpr FieldSpace CONTACT_SPACE = HDIV;
38};
39
40constexpr int SPACE_DIM =
41 EXECUTABLE_DIMENSION; //< Space dimension of problem, mesh
42constexpr auto size_symm = (SPACE_DIM * (SPACE_DIM + 1)) / 2;
43
44constexpr AssemblyType AT =
45 (SCHUR_ASSEMBLE) ? AssemblyType::BLOCK_SCHUR
46 : AssemblyType::PETSC; //< selected assembly type
48 IntegrationType::GAUSS; //< selected integration type
49
52[[maybe_unused]] constexpr FieldSpace CONTACT_SPACE =
54
57using DomainEleOp = DomainEle::UserDataOperator;
59using BoundaryEleOp = BoundaryEle::UserDataOperator;
64
65inline double iso_hardening_exp(double tau, double b_iso) {
66 return std::exp(
67 std::max(static_cast<double>(std::numeric_limits<float>::min_exponent10),
68 -b_iso * tau));
69}
70
71/**
72 * Isotropic hardening
73 */
74inline double iso_hardening(double tau, double H, double Qinf, double b_iso,
75 double sigmaY) {
76 return H * tau + Qinf * (1. - iso_hardening_exp(tau, b_iso)) + sigmaY;
77}
78
79inline double iso_hardening_dtau(double tau, double H, double Qinf,
80 double b_iso) {
81 auto r = [&](auto tau) {
82 return H + Qinf * b_iso * iso_hardening_exp(tau, b_iso);
83 };
84 constexpr double eps = 1e-12;
85 return std::max(r(tau), eps * r(0));
86}
87
88/**
89 * Kinematic hardening
90 */
91template <typename T, int DIM>
92inline auto
94 double C1_k) {
95 FTensor::Index<'i', DIM> i;
96 FTensor::Index<'j', DIM> j;
98 if (C1_k < std::numeric_limits<double>::epsilon()) {
99 t_alpha(i, j) = 0;
100 return t_alpha;
101 }
102 t_alpha(i, j) = C1_k * t_plastic_strain(i, j);
103 return t_alpha;
104}
105
106template <int DIM>
108 FTensor::Index<'i', DIM> i;
109 FTensor::Index<'j', DIM> j;
110 FTensor::Index<'k', DIM> k;
111 FTensor::Index<'l', DIM> l;
114 t_diff(i, j, k, l) = C1_k * (t_kd(i, k) ^ t_kd(j, l)) / 4.;
115 return t_diff;
116}
117
118PetscBool is_large_strains = PETSC_TRUE; ///< Large strains
119PetscBool set_timer = PETSC_FALSE; ///< Set timer
120PetscBool do_eval_field = PETSC_FALSE; ///< Evaluate field
121
122int atom_test = 0; ///< Atom test
123
124double scale = 1.;
125
126double young_modulus = 206913; ///< Young modulus
127double poisson_ratio = 0.29; ///< Poisson ratio
128double sigmaY = 450; ///< Yield stress
129double H = 129; ///< Hardening
130double visH = 0; ///< Viscous hardening
131double zeta = 5e-2; ///< Viscous hardening
132double Qinf = 265; ///< Saturation yield stress
133double b_iso = 16.93; ///< Saturation exponent
134double C1_k = 0; ///< Kinematic hardening
135
136double cn0 = 1;
137double cn1 = 1;
138
139int order = 2; ///< Order displacement
140int tau_order = order - 2; ///< Order of tau files
141int ep_order = order - 1; ///< Order of ep files
142int geom_order = 2; ///< Order if fixed.
143
144PetscBool is_quasi_static = PETSC_TRUE;
145double rho = 0.0;
146double alpha_damping = 0;
147
148#include <HenckyOps.hpp>
149#include <PlasticOps.hpp>
150#include <PlasticNaturalBCs.hpp>
151
152#ifdef ADD_CONTACT
153namespace ContactOps {
154
155double cn_contact = 0.1;
156
157}; // namespace ContactOps
158
159 #include <ContactOps.hpp>
160#endif // ADD_CONTACT
161
171
172using namespace PlasticOps;
173using namespace HenckyOps;
174
175namespace PlasticOps {
176
177template <int FE_DIM, int PROBLEM_DIM, int SPACE_DIM> struct AddHOOps;
178
179template <> struct AddHOOps<2, 3, 3> {
180 AddHOOps() = delete;
181 static MoFEMErrorCode
182 add(boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pipeline,
183 std::vector<FieldSpace> space, std::string geom_field_name);
184};
185
186template <> struct AddHOOps<1, 2, 2> {
187 AddHOOps() = delete;
188 static MoFEMErrorCode
189 add(boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pipeline,
190 std::vector<FieldSpace> space, std::string geom_field_name);
191};
192
193template <> struct AddHOOps<3, 3, 3> {
194 AddHOOps() = delete;
195 static MoFEMErrorCode
196 add(boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pipeline,
197 std::vector<FieldSpace> space, std::string geom_field_name);
198};
199
200template <> struct AddHOOps<2, 2, 2> {
201 AddHOOps() = delete;
202 static MoFEMErrorCode
203 add(boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pipeline,
204 std::vector<FieldSpace> space, std::string geom_field_name);
205};
206
207} // namespace PlasticOps
208
209struct Example {
210
211 Example(MoFEM::Interface &m_field) : mField(m_field) {}
212
214
215 enum { VOL, COUNT };
216 static inline std::array<double, 2> meshVolumeAndCount = {0, 0};
217
218private:
220
227
228 std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uXScatter;
229 std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uYScatter;
230 std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uZScatter;
231
234 double getScale(const double time) {
235 return scale * MoFEM::TimeScale::getScale(time);
236 };
237 };
238
239#ifdef ADD_CONTACT
240 #ifdef ENABLE_PYTHON_BINDING
241 boost::shared_ptr<ContactOps::SDFPython> sdfPythonPtr;
242 #endif
243#endif // ADD_CONTACT
244};
245
246//! [Run problem]
251 CHKERR bC();
252 CHKERR OPs();
253 PetscBool test_ops = PETSC_FALSE;
254 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-test_operators", &test_ops,
255 PETSC_NULLPTR);
256 if (test_ops == PETSC_FALSE) {
257 CHKERR tsSolve();
258 } else {
260 }
262}
263//! [Run problem]
264
265//! [Set up problem]
269
270 Range domain_ents;
271 CHKERR mField.get_moab().get_entities_by_dimension(0, SPACE_DIM, domain_ents,
272 true);
273 auto get_ents_by_dim = [&](const auto dim) {
274 if (dim == SPACE_DIM) {
275 return domain_ents;
276 } else {
277 Range ents;
278 if (dim == 0)
279 CHKERR mField.get_moab().get_connectivity(domain_ents, ents, true);
280 else
281 CHKERR mField.get_moab().get_entities_by_dimension(0, dim, ents, true);
282 return ents;
283 }
284 };
285
286 auto get_base = [&]() {
287 auto domain_ents = get_ents_by_dim(SPACE_DIM);
288 if (domain_ents.empty())
289 CHK_THROW_MESSAGE(MOFEM_NOT_FOUND, "Empty mesh");
290 const auto type = type_from_handle(domain_ents[0]);
291 switch (type) {
292 case MBQUAD:
294 case MBHEX:
296 case MBTRI:
298 case MBTET:
300 default:
301 CHK_THROW_MESSAGE(MOFEM_NOT_FOUND, "Element type not handled");
302 }
303 return NOBASE;
304 };
305
306 const auto base = get_base();
307 MOFEM_LOG("PLASTICITY", Sev::inform)
308 << "Base " << ApproximationBaseNames[base];
309
312 CHKERR simple->addDomainField("TAU", L2, base, 1);
314
315 CHKERR simple->addDataField("GEOMETRY", H1, base, SPACE_DIM);
316
317 PetscBool order_edge = PETSC_FALSE;
318 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-order_edge", &order_edge,
319 PETSC_NULLPTR);
320 PetscBool order_face = PETSC_FALSE;
321 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-order_face", &order_face,
322 PETSC_NULLPTR);
323 PetscBool order_volume = PETSC_FALSE;
324 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-order_volume", &order_volume,
325 PETSC_NULLPTR);
326
327 if (order_edge || order_face || order_volume) {
328
329 MOFEM_LOG("PLASTICITY", Sev::inform) << "Order edge " << order_edge
330 ? "true"
331 : "false";
332 MOFEM_LOG("PLASTICITY", Sev::inform) << "Order face " << order_face
333 ? "true"
334 : "false";
335 MOFEM_LOG("PLASTICITY", Sev::inform) << "Order volume " << order_volume
336 ? "true"
337 : "false";
338
339 auto ents = get_ents_by_dim(0);
340 if (order_edge)
341 ents.merge(get_ents_by_dim(1));
342 if (order_face)
343 ents.merge(get_ents_by_dim(2));
344 if (order_volume)
345 ents.merge(get_ents_by_dim(3));
346 CHKERR simple->setFieldOrder("U", order, &ents);
347 } else {
349 }
352
354
355#ifdef ADD_CONTACT
357 SPACE_DIM);
359 SPACE_DIM);
360
361 auto get_skin = [&]() {
362 Range body_ents;
363 CHKERR mField.get_moab().get_entities_by_dimension(0, SPACE_DIM, body_ents);
364 Skinner skin(&mField.get_moab());
365 Range skin_ents;
366 CHKERR skin.find_skin(0, body_ents, false, skin_ents);
367 return skin_ents;
368 };
369
370 auto filter_blocks = [&](auto skin) {
371 bool is_contact_block = true;
372 Range contact_range;
373 for (auto m :
374 mField.getInterface<MeshsetsManager>()->getCubitMeshsetPtr(std::regex(
375
376 (boost::format("%s(.*)") % "CONTACT").str()
377
378 ))
379
380 ) {
381 is_contact_block =
382 true; ///< blocs interation is collective, so that is set irrespective
383 ///< if there are entities in given rank or not in the block
384 MOFEM_LOG("CONTACT", Sev::inform)
385 << "Find contact block set: " << m->getName();
386 auto meshset = m->getMeshset();
387 Range contact_meshset_range;
388 CHKERR mField.get_moab().get_entities_by_dimension(
389 meshset, SPACE_DIM - 1, contact_meshset_range, true);
390
391 CHKERR mField.getInterface<CommInterface>()->synchroniseEntities(
392 contact_meshset_range);
393 contact_range.merge(contact_meshset_range);
394 }
395 if (is_contact_block) {
396 MOFEM_LOG("SYNC", Sev::inform)
397 << "Nb entities in contact surface: " << contact_range.size();
399 skin = intersect(skin, contact_range);
400 }
401 return skin;
402 };
403
404 auto filter_true_skin = [&](auto skin) {
405 Range boundary_ents;
406 ParallelComm *pcomm =
407 ParallelComm::get_pcomm(&mField.get_moab(), MYPCOMM_INDEX);
408 CHKERR pcomm->filter_pstatus(skin, PSTATUS_SHARED | PSTATUS_MULTISHARED,
409 PSTATUS_NOT, -1, &boundary_ents);
410 return boundary_ents;
411 };
412
413 auto boundary_ents = filter_true_skin(filter_blocks(get_skin()));
414 CHKERR simple->setFieldOrder("SIGMA", 0);
415 CHKERR simple->setFieldOrder("SIGMA", order - 1, &boundary_ents);
416#endif
417
420
421 auto project_ho_geometry = [&]() {
422 Projection10NodeCoordsOnField ent_method(mField, "GEOMETRY");
423 return mField.loop_dofs("GEOMETRY", ent_method);
424 };
425 PetscBool project_geometry = PETSC_TRUE;
426 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-project_geometry",
427 &project_geometry, PETSC_NULLPTR);
428 if (project_geometry) {
429 CHKERR project_ho_geometry();
430 }
431
432 auto get_volume = [&]() {
433 using VolOp = DomainEle::UserDataOperator;
434 auto *op_ptr = new VolOp(NOSPACE, VolOp::OPSPACE);
435 std::array<double, 2> volume_and_count;
436 op_ptr->doWorkRhsHook = [&](DataOperator *base_op_ptr, int side,
437 EntityType type,
440 auto op_ptr = static_cast<VolOp *>(base_op_ptr);
441 volume_and_count[VOL] += op_ptr->getMeasure();
442 volume_and_count[COUNT] += 1;
443 // in necessary at integration over Gauss points.
445 };
446 volume_and_count = {0, 0};
447 auto fe = boost::make_shared<DomainEle>(mField);
448 fe->getOpPtrVector().push_back(op_ptr);
449
450 auto dm = simple->getDM();
453 "cac volume");
454 std::array<double, 2> tot_volume_and_count;
455 MPI_Allreduce(volume_and_count.data(), tot_volume_and_count.data(),
456 volume_and_count.size(), MPI_DOUBLE, MPI_SUM,
457 mField.get_comm());
458 return tot_volume_and_count;
459 };
460
461 meshVolumeAndCount = get_volume();
462 MOFEM_LOG("PLASTICITY", Sev::inform)
463 << "Mesh volume " << meshVolumeAndCount[VOL] << " nb. of elements "
465
467}
468//! [Set up problem]
469
470//! [Create common data]
473
474 auto get_command_line_parameters = [&]() {
476
477 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-scale", &scale, PETSC_NULLPTR);
478 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-young_modulus",
479 &young_modulus, PETSC_NULLPTR);
480 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-poisson_ratio",
481 &poisson_ratio, PETSC_NULLPTR);
482 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-hardening", &H, PETSC_NULLPTR);
483 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-hardening_viscous", &visH,
484 PETSC_NULLPTR);
485 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-yield_stress", &sigmaY,
486 PETSC_NULLPTR);
487 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-cn0", &cn0, PETSC_NULLPTR);
488 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-cn1", &cn1, PETSC_NULLPTR);
489 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-zeta", &zeta, PETSC_NULLPTR);
490 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-Qinf", &Qinf, PETSC_NULLPTR);
491 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-b_iso", &b_iso, PETSC_NULLPTR);
492 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-C1_k", &C1_k, PETSC_NULLPTR);
493 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-large_strains",
494 &is_large_strains, PETSC_NULLPTR);
495 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-set_timer", &set_timer,
496 PETSC_NULLPTR);
497 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-atom_test", &atom_test,
498 PETSC_NULLPTR);
499
500 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-order", &order, PETSC_NULLPTR);
501 PetscBool tau_order_is_set; ///< true if tau order is set
502 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-tau_order", &tau_order,
503 &tau_order_is_set);
504 PetscBool ep_order_is_set; ///< true if tau order is set
505 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-ep_order", &ep_order,
506 &ep_order_is_set);
507 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-geom_order", &geom_order,
508 PETSC_NULLPTR);
509
510 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-rho", &rho, PETSC_NULLPTR);
511 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-alpha_damping",
512 &alpha_damping, PETSC_NULLPTR);
513
514 MOFEM_LOG("PLASTICITY", Sev::inform) << "Young modulus " << young_modulus;
515 MOFEM_LOG("PLASTICITY", Sev::inform) << "Poisson ratio " << poisson_ratio;
516 MOFEM_LOG("PLASTICITY", Sev::inform) << "Yield stress " << sigmaY;
517 MOFEM_LOG("PLASTICITY", Sev::inform) << "Hardening " << H;
518 MOFEM_LOG("PLASTICITY", Sev::inform) << "Viscous hardening " << visH;
519 MOFEM_LOG("PLASTICITY", Sev::inform) << "Saturation yield stress " << Qinf;
520 MOFEM_LOG("PLASTICITY", Sev::inform) << "Saturation exponent " << b_iso;
521 MOFEM_LOG("PLASTICITY", Sev::inform) << "Kinematic hardening " << C1_k;
522 MOFEM_LOG("PLASTICITY", Sev::inform) << "cn0 " << cn0;
523 MOFEM_LOG("PLASTICITY", Sev::inform) << "cn1 " << cn1;
524 MOFEM_LOG("PLASTICITY", Sev::inform) << "zeta " << zeta;
525
526 if (tau_order_is_set == PETSC_FALSE)
527 tau_order = order - 2;
528 if (ep_order_is_set == PETSC_FALSE)
529 ep_order = order - 1;
530
531 MOFEM_LOG("PLASTICITY", Sev::inform) << "Approximation order " << order;
532 MOFEM_LOG("PLASTICITY", Sev::inform)
533 << "Ep approximation order " << ep_order;
534 MOFEM_LOG("PLASTICITY", Sev::inform)
535 << "Tau approximation order " << tau_order;
536 MOFEM_LOG("PLASTICITY", Sev::inform)
537 << "Geometry approximation order " << geom_order;
538
539 MOFEM_LOG("PLASTICITY", Sev::inform) << "Density " << rho;
540 MOFEM_LOG("PLASTICITY", Sev::inform) << "alpha_damping " << alpha_damping;
541
542 PetscBool is_scale = PETSC_TRUE;
543 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-is_scale", &is_scale,
544 PETSC_NULLPTR);
545 if (is_scale) {
547 }
548
549 MOFEM_LOG("PLASTICITY", Sev::inform) << "Scale " << scale;
550
551#ifdef ADD_CONTACT
552 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-cn_contact",
553 &ContactOps::cn_contact, PETSC_NULLPTR);
554 MOFEM_LOG("CONTACT", Sev::inform)
555 << "cn_contact " << ContactOps::cn_contact;
556#endif // ADD_CONTACT
557
558 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-quasi_static",
559 &is_quasi_static, PETSC_NULLPTR);
560 MOFEM_LOG("PLASTICITY", Sev::inform)
561 << "Is quasi static: " << (is_quasi_static ? "true" : "false");
562
564 };
565
566 CHKERR get_command_line_parameters();
567
568#ifdef ADD_CONTACT
569 #ifdef ENABLE_PYTHON_BINDING
570 auto file_exists = [](std::string myfile) {
571 std::ifstream file(myfile.c_str());
572 if (file) {
573 return true;
574 }
575 return false;
576 };
577 char sdf_file_name[255] = "sdf.py";
578 CHKERR PetscOptionsGetString(PETSC_NULLPTR, PETSC_NULLPTR, "-sdf_file",
579 sdf_file_name, 255, PETSC_NULLPTR);
580
581 if (file_exists(sdf_file_name)) {
582 MOFEM_LOG("CONTACT", Sev::inform) << sdf_file_name << " file found";
583 sdfPythonPtr = boost::make_shared<ContactOps::SDFPython>();
584 CHKERR sdfPythonPtr->sdfInit(sdf_file_name);
585 CHKERR sdfPythonPtr->requireDerivatives();
586 ContactOps::sdfPythonWeakPtr = sdfPythonPtr;
587 } else {
588 MOFEM_LOG("CONTACT", Sev::warning) << sdf_file_name << " file NOT found";
589 }
590 #endif
591#endif // ADD_CONTACT
592
594}
595//! [Create common data]
596
597//! [Boundary condition]
600
602 auto bc_mng = mField.getInterface<BcManager>();
603
604 CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), "REMOVE_X",
605 "U", 0, 0);
606 CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), "REMOVE_Y",
607 "U", 1, 1);
608 CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), "REMOVE_Z",
609 "U", 2, 2);
610 CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(),
611 "REMOVE_ALL", "U", 0, 3);
612
613#ifdef ADD_CONTACT
614 for (auto b : {"FIX_X", "REMOVE_X"})
615 CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), b,
616 "SIGMA", 0, 0, false, true);
617 for (auto b : {"FIX_Y", "REMOVE_Y"})
618 CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), b,
619 "SIGMA", 1, 1, false, true);
620 for (auto b : {"FIX_Z", "REMOVE_Z"})
621 CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), b,
622 "SIGMA", 2, 2, false, true);
623 for (auto b : {"FIX_ALL", "REMOVE_ALL"})
624 CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), b,
625 "SIGMA", 0, 3, false, true);
626 CHKERR bc_mng->removeBlockDOFsOnEntities(
627 simple->getProblemName(), "NO_CONTACT", "SIGMA", 0, 3, false, true);
628#endif
629
630 CHKERR bc_mng->pushMarkDOFsOnEntities<DisplacementCubitBcData>(
631 simple->getProblemName(), "U");
632
633 auto &bc_map = bc_mng->getBcMapByBlockName();
634 for (auto bc : bc_map)
635 MOFEM_LOG("PLASTICITY", Sev::verbose) << "Marker " << bc.first;
636
638}
639//! [Boundary condition]
640
641//! [Push operators to pipeline]
644 auto pip_mng = mField.getInterface<PipelineManager>();
645
646 auto integration_rule_bc = [](int, int, int ao) { return 2 * ao; };
647
648 auto vol_rule = [](int, int, int ao) { return 2 * ao + geom_order - 1; };
649
650 auto add_boundary_ops_lhs_mechanical = [&](auto &pip) {
652
654 pip, {HDIV}, "GEOMETRY");
655 pip.push_back(new OpSetHOWeightsOnSubDim<SPACE_DIM>());
656
657 // Add Natural BCs to LHS
659 pip, mField, "U", Sev::inform);
660
661#ifdef ADD_CONTACT
663 CHKERR
664 ContactOps::opFactoryBoundaryLhs<SPACE_DIM, AT, GAUSS, BoundaryEleOp>(
665 pip, "SIGMA", "U");
666 CHKERR
667 ContactOps::opFactoryBoundaryToDomainLhs<SPACE_DIM, AT, IT, DomainEle>(
668 mField, pip, simple->getDomainFEName(), "SIGMA", "U", "GEOMETRY",
669 vol_rule);
670#endif // ADD_CONTACT
671
673 };
674
675 auto add_boundary_ops_rhs_mechanical = [&](auto &pip) {
677
679 pip, {HDIV}, "GEOMETRY");
680 pip.push_back(new OpSetHOWeightsOnSubDim<SPACE_DIM>());
681
682 // Add Natural BCs to RHS
684 pip, mField, "U", {boost::make_shared<ScaledTimeScale>()}, Sev::inform);
685
686#ifdef ADD_CONTACT
687 CHKERR ContactOps::opFactoryBoundaryRhs<SPACE_DIM, AT, IT, BoundaryEleOp>(
688 pip, "SIGMA", "U");
689#endif // ADD_CONTACT
690
692 };
693
694 auto add_domain_ops_lhs = [this](auto &pip) {
697 pip, {H1, HDIV}, "GEOMETRY");
698
699 if (is_quasi_static == PETSC_FALSE) {
700
701 //! [Only used for dynamics]
704 //! [Only used for dynamics]
705
706 auto get_inertia_and_mass_damping = [this](const double, const double,
707 const double) {
708 auto *pip = mField.getInterface<PipelineManager>();
709 auto &fe_domain_lhs = pip->getDomainLhsFE();
710 return (rho / scale) * fe_domain_lhs->ts_aa +
711 (alpha_damping / scale) * fe_domain_lhs->ts_a;
712 };
713 pip.push_back(new OpMass("U", "U", get_inertia_and_mass_damping));
714 }
715
716 CHKERR PlasticOps::opFactoryDomainLhs<SPACE_DIM, AT, IT, DomainEleOp>(
717 mField, "MAT_PLASTIC", pip, "U", "EP", "TAU");
718
720 };
721
722 auto add_domain_ops_rhs = [this](auto &pip) {
724
726 pip, {H1, HDIV}, "GEOMETRY");
727
729 pip, mField, "U",
730 {boost::make_shared<ScaledTimeScale>("body_force_hist.txt")},
731 Sev::inform);
732
733 // only in case of dynamics
734 if (is_quasi_static == PETSC_FALSE) {
735
736 //! [Only used for dynamics]
739 //! [Only used for dynamics]
740
741 auto mat_acceleration = boost::make_shared<MatrixDouble>();
743 "U", mat_acceleration));
744 pip.push_back(
745 new OpInertiaForce("U", mat_acceleration, [](double, double, double) {
746 return rho / scale;
747 }));
748 if (alpha_damping > 0) {
749 auto mat_velocity = boost::make_shared<MatrixDouble>();
750 pip.push_back(
751 new OpCalculateVectorFieldValuesDot<SPACE_DIM>("U", mat_velocity));
752 pip.push_back(
753 new OpInertiaForce("U", mat_velocity, [](double, double, double) {
754 return alpha_damping / scale;
755 }));
756 }
757 }
758
759 CHKERR PlasticOps::opFactoryDomainRhs<SPACE_DIM, AT, IT, DomainEleOp>(
760 mField, "MAT_PLASTIC", pip, "U", "EP", "TAU");
761
762#ifdef ADD_CONTACT
763 CHKERR ContactOps::opFactoryDomainRhs<SPACE_DIM, AT, IT, DomainEleOp>(
764 pip, "SIGMA", "U");
765#endif // ADD_CONTACT
766
768 };
769
770 CHKERR add_domain_ops_lhs(pip_mng->getOpDomainLhsPipeline());
771 CHKERR add_domain_ops_rhs(pip_mng->getOpDomainRhsPipeline());
772
773 // Boundary
774 CHKERR add_boundary_ops_lhs_mechanical(pip_mng->getOpBoundaryLhsPipeline());
775 CHKERR add_boundary_ops_rhs_mechanical(pip_mng->getOpBoundaryRhsPipeline());
776
777 CHKERR pip_mng->setDomainRhsIntegrationRule(vol_rule);
778 CHKERR pip_mng->setDomainLhsIntegrationRule(vol_rule);
779
780 CHKERR pip_mng->setBoundaryLhsIntegrationRule(integration_rule_bc);
781 CHKERR pip_mng->setBoundaryRhsIntegrationRule(integration_rule_bc);
782
783 auto create_reaction_pipeline = [&](auto &pip) {
786 pip, {H1}, "GEOMETRY");
787 CHKERR PlasticOps::opFactoryDomainReactions<SPACE_DIM, AT, IT, DomainEleOp>(
788 mField, "MAT_PLASTIC", pip, "U", "EP", "TAU");
790 };
791
792 CHKERR pip_mng->setEvaluationIntegrationRule(vol_rule);
793 CHKERR create_reaction_pipeline(pip_mng->getOpEvaluationPipeline());
794 auto &reaction_fe = pip_mng->getEvaluationFE();
795 reaction_fe->postProcessHook =
797
799}
800//! [Push operators to pipeline]
801
802//! [Solve]
803struct SetUpSchur {
804
805 /**
806 * @brief Create data structure for handling Schur complement
807 *
808 * @param m_field
809 * @param sub_dm Schur complement sub dm
810 * @param field_split_it IS of Schur block
811 * @param ao_map AO map from sub dm to main problem
812 * @return boost::shared_ptr<SetUpSchur>
813 */
814 static boost::shared_ptr<SetUpSchur> createSetUpSchur(
815
816 MoFEM::Interface &m_field, SmartPetscObj<DM> sub_dm,
817 SmartPetscObj<IS> field_split_it, SmartPetscObj<AO> ao_map
818
819 );
820 virtual MoFEMErrorCode setUp(TS solver) = 0;
821
822protected:
823 SetUpSchur() = default;
824};
825
828
831 ISManager *is_manager = mField.getInterface<ISManager>();
832
833 auto snes_ctx_ptr = getDMSnesCtx(simple->getDM());
834
835 auto set_section_monitor = [&](auto solver) {
837 SNES snes;
838 CHKERR TSGetSNES(solver, &snes);
839 CHKERR SNESMonitorSet(snes,
840 (MoFEMErrorCode(*)(SNES, PetscInt, PetscReal,
842 (void *)(snes_ctx_ptr.get()), nullptr);
844 };
845
846 auto create_post_process_elements = [&]() {
847 auto push_vol_ops = [this](auto &pip) {
849 pip, {H1, HDIV}, "GEOMETRY");
850
851 auto [common_plastic_ptr, common_hencky_ptr] =
852 PlasticOps::createCommonPlasticOps<SPACE_DIM, IT, DomainEleOp>(
853 mField, "MAT_PLASTIC", pip, "U", "EP", "TAU", 1., Sev::inform);
854
855 if (common_hencky_ptr) {
856 if (common_plastic_ptr->mGradPtr != common_hencky_ptr->matGradPtr)
857 CHK_THROW_MESSAGE(MOFEM_DATA_INCONSISTENCY, "Wrong pointer for grad");
858 }
859
860 return std::make_pair(common_plastic_ptr, common_hencky_ptr);
861 };
862
863 auto push_vol_post_proc_ops = [this](auto &pp_fe, auto &&p) {
865
866 auto &pip = pp_fe->getOpPtrVector();
867
868 auto [common_plastic_ptr, common_hencky_ptr] = p;
869
871
872 auto x_ptr = boost::make_shared<MatrixDouble>();
873 pip.push_back(
874 new OpCalculateVectorFieldValues<SPACE_DIM>("GEOMETRY", x_ptr));
875 auto u_ptr = boost::make_shared<MatrixDouble>();
876 pip.push_back(new OpCalculateVectorFieldValues<SPACE_DIM>("U", u_ptr));
877
878 if (is_large_strains) {
879
880 pip.push_back(
881
882 new OpPPMap(
883
884 pp_fe->getPostProcMesh(), pp_fe->getMapGaussPts(),
885
886 {{"PLASTIC_SURFACE",
887 common_plastic_ptr->getPlasticSurfacePtr()},
888 {"PLASTIC_MULTIPLIER",
889 common_plastic_ptr->getPlasticTauPtr()}},
890
891 {{"U", u_ptr}, {"GEOMETRY", x_ptr}},
892
893 {{"GRAD", common_hencky_ptr->matGradPtr},
894 {"FIRST_PIOLA", common_hencky_ptr->getMatFirstPiolaStress()}},
895
896 {{"HENCKY_STRAIN", common_hencky_ptr->getMatLogC()},
897 {"PLASTIC_STRAIN", common_plastic_ptr->getPlasticStrainPtr()},
898 {"PLASTIC_FLOW", common_plastic_ptr->getPlasticFlowPtr()}}
899
900 )
901
902 );
903
904 } else {
905
906 pip.push_back(
907
908 new OpPPMap(
909
910 pp_fe->getPostProcMesh(), pp_fe->getMapGaussPts(),
911
912 {{"PLASTIC_SURFACE",
913 common_plastic_ptr->getPlasticSurfacePtr()},
914 {"PLASTIC_MULTIPLIER",
915 common_plastic_ptr->getPlasticTauPtr()}},
916
917 {{"U", u_ptr}, {"GEOMETRY", x_ptr}},
918
919 {},
920
921 {{"STRAIN", common_plastic_ptr->mStrainPtr},
922 {"STRESS", common_plastic_ptr->mStressPtr},
923 {"PLASTIC_STRAIN", common_plastic_ptr->getPlasticStrainPtr()},
924 {"PLASTIC_FLOW", common_plastic_ptr->getPlasticFlowPtr()}}
925
926 )
927
928 );
929 }
930
932 };
933
934 PetscBool post_proc_vol;
935 PetscBool post_proc_skin;
936
937 if constexpr (SPACE_DIM == 2) {
938 post_proc_vol = PETSC_TRUE;
939 post_proc_skin = PETSC_FALSE;
940 } else {
941 post_proc_vol = PETSC_FALSE;
942 post_proc_skin = PETSC_TRUE;
943 }
944 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-post_proc_vol", &post_proc_vol,
945 PETSC_NULLPTR);
946 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-post_proc_skin",
947 &post_proc_skin, PETSC_NULLPTR);
948
949 auto vol_post_proc = [this, push_vol_post_proc_ops, push_vol_ops,
950 post_proc_vol]() {
951 if (post_proc_vol == PETSC_FALSE)
952 return boost::shared_ptr<PostProcEle>();
953 auto pp_fe = boost::make_shared<PostProcEle>(mField);
955 push_vol_post_proc_ops(pp_fe, push_vol_ops(pp_fe->getOpPtrVector())),
956 "push_vol_post_proc_ops");
957 return pp_fe;
958 };
959
960 auto skin_post_proc = [this, push_vol_post_proc_ops, push_vol_ops,
961 post_proc_skin]() {
962 if (post_proc_skin == PETSC_FALSE)
963 return boost::shared_ptr<SkinPostProcEle>();
964
966 auto pp_fe = boost::make_shared<SkinPostProcEle>(mField);
967 auto op_side = new OpLoopSide<SideEle>(mField, simple->getDomainFEName(),
968 SPACE_DIM, Sev::verbose);
969 pp_fe->getOpPtrVector().push_back(op_side);
970 CHK_MOAB_THROW(push_vol_post_proc_ops(
971 pp_fe, push_vol_ops(op_side->getOpPtrVector())),
972 "push_vol_post_proc_ops");
973 return pp_fe;
974 };
975
976 return std::make_pair(vol_post_proc(), skin_post_proc());
977 };
978
979 auto scatter_create = [&](auto D, auto coeff) {
981 CHKERR is_manager->isCreateProblemFieldAndRank(simple->getProblemName(),
982 ROW, "U", coeff, coeff, is);
983 int loc_size;
984 CHKERR ISGetLocalSize(is, &loc_size);
985 Vec v;
986 CHKERR VecCreateMPI(mField.get_comm(), loc_size, PETSC_DETERMINE, &v);
987 VecScatter scatter;
988 CHKERR VecScatterCreate(D, is, v, PETSC_NULLPTR, &scatter);
989 return std::make_tuple(SmartPetscObj<Vec>(v),
991 };
992
993 boost::shared_ptr<SetPtsData> field_eval_data;
994 boost::shared_ptr<MatrixDouble> u_field_ptr;
995
996 std::array<double, 3> field_eval_coords{0.0, 0.0, 0.0};
997 int coords_dim = 3;
998 CHKERR PetscOptionsGetRealArray(NULL, NULL, "-field_eval_coords",
999 field_eval_coords.data(), &coords_dim,
1000 &do_eval_field);
1001
1002 boost::shared_ptr<std::map<std::string, boost::shared_ptr<VectorDouble>>>
1003 scalar_field_ptrs = boost::make_shared<
1004 std::map<std::string, boost::shared_ptr<VectorDouble>>>();
1005 boost::shared_ptr<std::map<std::string, boost::shared_ptr<MatrixDouble>>>
1006 vector_field_ptrs = boost::make_shared<
1007 std::map<std::string, boost::shared_ptr<MatrixDouble>>>();
1008 boost::shared_ptr<std::map<std::string, boost::shared_ptr<MatrixDouble>>>
1009 sym_tensor_field_ptrs = boost::make_shared<
1010 std::map<std::string, boost::shared_ptr<MatrixDouble>>>();
1011 boost::shared_ptr<std::map<std::string, boost::shared_ptr<MatrixDouble>>>
1012 tensor_field_ptrs = boost::make_shared<
1013 std::map<std::string, boost::shared_ptr<MatrixDouble>>>();
1014
1015 if (do_eval_field) {
1016 auto u_field_ptr = boost::make_shared<MatrixDouble>();
1017 field_eval_data =
1018 mField.getInterface<FieldEvaluatorInterface>()->getData<DomainEle>();
1019
1020 CHKERR mField.getInterface<FieldEvaluatorInterface>()->buildTree<SPACE_DIM>(
1021 field_eval_data, simple->getDomainFEName());
1022
1023 field_eval_data->setEvalPoints(field_eval_coords.data(), 1);
1024 auto no_rule = [](int, int, int) { return -1; };
1025 auto field_eval_fe_ptr = field_eval_data->feMethodPtr;
1026 field_eval_fe_ptr->getRuleHook = no_rule;
1027
1029 field_eval_fe_ptr->getOpPtrVector(), {H1, HDIV}, "GEOMETRY");
1030
1031 auto [common_plastic_ptr, common_hencky_ptr] =
1032 PlasticOps::createCommonPlasticOps<SPACE_DIM, IT, DomainEleOp>(
1033 mField, "MAT_PLASTIC", field_eval_fe_ptr->getOpPtrVector(), "U",
1034 "EP", "TAU", 1., Sev::inform);
1035
1036 field_eval_fe_ptr->getOpPtrVector().push_back(
1037 new OpCalculateVectorFieldValues<SPACE_DIM>("U", u_field_ptr));
1038
1039 if ((common_plastic_ptr) && (common_hencky_ptr) && (scalar_field_ptrs)) {
1040 if (is_large_strains) {
1041 scalar_field_ptrs->insert(
1042 {"PLASTIC_SURFACE", common_plastic_ptr->getPlasticSurfacePtr()});
1043 scalar_field_ptrs->insert(
1044 {"PLASTIC_MULTIPLIER", common_plastic_ptr->getPlasticTauPtr()});
1045 vector_field_ptrs->insert({"U", u_field_ptr});
1046 sym_tensor_field_ptrs->insert(
1047 {"PLASTIC_STRAIN", common_plastic_ptr->getPlasticStrainPtr()});
1048 sym_tensor_field_ptrs->insert(
1049 {"PLASTIC_FLOW", common_plastic_ptr->getPlasticFlowPtr()});
1050 sym_tensor_field_ptrs->insert(
1051 {"HENCKY_STRAIN", common_hencky_ptr->getMatLogC()});
1052 tensor_field_ptrs->insert({"GRAD", common_hencky_ptr->matGradPtr});
1053 tensor_field_ptrs->insert(
1054 {"FIRST_PIOLA", common_hencky_ptr->getMatFirstPiolaStress()});
1055 } else {
1056 scalar_field_ptrs->insert(
1057 {"PLASTIC_SURFACE", common_plastic_ptr->getPlasticSurfacePtr()});
1058 scalar_field_ptrs->insert(
1059 {"PLASTIC_MULTIPLIER", common_plastic_ptr->getPlasticTauPtr()});
1060 vector_field_ptrs->insert({"U", u_field_ptr});
1061 sym_tensor_field_ptrs->insert(
1062 {"STRAIN", common_plastic_ptr->mStrainPtr});
1063 sym_tensor_field_ptrs->insert(
1064 {"STRESS", common_plastic_ptr->mStressPtr});
1065 sym_tensor_field_ptrs->insert(
1066 {"PLASTIC_STRAIN", common_plastic_ptr->getPlasticStrainPtr()});
1067 sym_tensor_field_ptrs->insert(
1068 {"PLASTIC_FLOW", common_plastic_ptr->getPlasticFlowPtr()});
1069 }
1070 }
1071 }
1072
1073 auto test_monitor_ptr = boost::make_shared<FEMethod>();
1074
1075 auto set_time_monitor = [&](auto dm, auto solver) {
1077 boost::shared_ptr<Monitor<SPACE_DIM>> monitor_ptr(new Monitor<SPACE_DIM>(
1078 dm, create_post_process_elements(), uXScatter, uYScatter, uZScatter,
1079 field_eval_coords, field_eval_data, scalar_field_ptrs,
1080 vector_field_ptrs, sym_tensor_field_ptrs, tensor_field_ptrs));
1081 boost::shared_ptr<ForcesAndSourcesCore> null;
1082
1083 test_monitor_ptr->postProcessHook = [&]() {
1085
1086 if (atom_test && fabs(test_monitor_ptr->ts_t - 0.5) < 1e-12 &&
1087 test_monitor_ptr->ts_step == 25) {
1088
1089 if (scalar_field_ptrs->at("PLASTIC_MULTIPLIER")->size()) {
1090 auto t_tau =
1091 getFTensor0FromVec(*scalar_field_ptrs->at("PLASTIC_MULTIPLIER"));
1092 MOFEM_LOG("PlasticSync", Sev::inform) << "Eval point tau: " << t_tau;
1093
1094 if (atom_test == 1 && fabs(t_tau - 0.688861) > 1e-5) {
1095 SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
1096 "atom test %d failed: wrong plastic multiplier value",
1097 atom_test);
1098 }
1099 }
1100
1101 if (vector_field_ptrs->at("U")->size1()) {
1103 auto t_disp =
1104 getFTensor1FromMat<SPACE_DIM>(*vector_field_ptrs->at("U"));
1105 MOFEM_LOG("PlasticSync", Sev::inform) << "Eval point U: " << t_disp;
1106
1107 if (atom_test == 1 && fabs(t_disp(0) - 0.25 / 2.) > 1e-5 ||
1108 fabs(t_disp(1) + 0.0526736) > 1e-5) {
1109 SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
1110 "atom test %d failed: wrong displacement value",
1111 atom_test);
1112 }
1113 }
1114
1115 if (sym_tensor_field_ptrs->at("PLASTIC_STRAIN")->size1()) {
1116 auto t_plastic_strain = getFTensor2SymmetricFromMat<SPACE_DIM>(
1117 *sym_tensor_field_ptrs->at("PLASTIC_STRAIN"));
1118 MOFEM_LOG("PlasticSync", Sev::inform)
1119 << "Eval point EP: " << t_plastic_strain;
1120
1121 if (atom_test == 1 &&
1122 fabs(t_plastic_strain(0, 0) - 0.221943) > 1e-5 ||
1123 fabs(t_plastic_strain(0, 1)) > 1e-5 ||
1124 fabs(t_plastic_strain(1, 1) + 0.110971) > 1e-5) {
1125 SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
1126 "atom test %d failed: wrong plastic strain value",
1127 atom_test);
1128 }
1129 }
1130
1131 if (tensor_field_ptrs->at("FIRST_PIOLA")->size1()) {
1132 auto t_piola_stress = getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(
1133 *tensor_field_ptrs->at("FIRST_PIOLA"));
1134 MOFEM_LOG("PlasticSync", Sev::inform)
1135 << "Eval point Piola stress: " << t_piola_stress;
1136
1137 if (atom_test == 1 && fabs((t_piola_stress(0, 0) - 198.775) /
1138 t_piola_stress(0, 0)) > 1e-5 ||
1139 fabs(t_piola_stress(0, 1)) + fabs(t_piola_stress(1, 0)) +
1140 fabs(t_piola_stress(1, 1)) >
1141 1e-5) {
1142 SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
1143 "atom test %d failed: wrong Piola stress value",
1144 atom_test);
1145 }
1146 }
1147 }
1148
1151 };
1152
1153 CHKERR DMMoFEMTSSetMonitor(dm, solver, simple->getDomainFEName(),
1154 monitor_ptr, null, test_monitor_ptr);
1155
1157 };
1158
1159 auto set_schur_pc = [&](auto solver,
1160 boost::shared_ptr<SetUpSchur> &schur_ptr) {
1162
1163 auto name_prb = simple->getProblemName();
1164
1165 // create sub dm for Schur complement
1166 auto create_schur_dm = [&](SmartPetscObj<DM> base_dm,
1167 SmartPetscObj<DM> &dm_sub) {
1169 dm_sub = createDM(mField.get_comm(), "DMMOFEM");
1170 CHKERR DMMoFEMCreateSubDM(dm_sub, base_dm, "SCHUR");
1171 CHKERR DMMoFEMSetSquareProblem(dm_sub, PETSC_TRUE);
1172 CHKERR DMMoFEMAddElement(dm_sub, simple->getDomainFEName());
1173 CHKERR DMMoFEMAddElement(dm_sub, simple->getBoundaryFEName());
1174 for (auto f : {"U"}) {
1177 }
1178 CHKERR DMSetUp(dm_sub);
1179
1181 };
1182
1183 auto create_block_dm = [&](SmartPetscObj<DM> base_dm,
1184 SmartPetscObj<DM> &dm_sub) {
1186 dm_sub = createDM(mField.get_comm(), "DMMOFEM");
1187 CHKERR DMMoFEMCreateSubDM(dm_sub, base_dm, "BLOCK");
1188 CHKERR DMMoFEMSetSquareProblem(dm_sub, PETSC_TRUE);
1189 CHKERR DMMoFEMAddElement(dm_sub, simple->getDomainFEName());
1190 CHKERR DMMoFEMAddElement(dm_sub, simple->getBoundaryFEName());
1191#ifdef ADD_CONTACT
1192 for (auto f : {"SIGMA", "EP", "TAU"}) {
1195 }
1196#else
1197 for (auto f : {"EP", "TAU"}) {
1200 }
1201#endif
1202 CHKERR DMSetUp(dm_sub);
1204 };
1205
1206 // Create nested (sub BC) Schur DM
1207 if constexpr (AT == AssemblyType::BLOCK_SCHUR) {
1208
1209 SmartPetscObj<DM> dm_schur;
1210 CHKERR create_schur_dm(simple->getDM(), dm_schur);
1211 SmartPetscObj<DM> dm_block;
1212 CHKERR create_block_dm(simple->getDM(), dm_block);
1213
1214#ifdef ADD_CONTACT
1215
1216 auto get_nested_mat_data = [&](auto schur_dm, auto block_dm) {
1217 auto block_mat_data = createBlockMatStructure(
1218 simple->getDM(),
1219
1220 {
1221
1222 {simple->getDomainFEName(),
1223
1224 {{"U", "U"},
1225 {"SIGMA", "SIGMA"},
1226 {"U", "SIGMA"},
1227 {"SIGMA", "U"},
1228 {"EP", "EP"},
1229 {"TAU", "TAU"},
1230 {"U", "EP"},
1231 {"EP", "U"},
1232 {"EP", "TAU"},
1233 {"TAU", "EP"},
1234 {"TAU", "U"}
1235
1236 }},
1237
1238 {simple->getBoundaryFEName(),
1239
1240 {{"SIGMA", "SIGMA"}, {"U", "SIGMA"}, {"SIGMA", "U"}
1241
1242 }}
1243
1244 }
1245
1246 );
1247
1249
1250 {dm_schur, dm_block}, block_mat_data,
1251
1252 {"SIGMA", "EP", "TAU"}, {nullptr, nullptr, nullptr}, true
1253
1254 );
1255 };
1256
1257#else
1258
1259 auto get_nested_mat_data = [&](auto schur_dm, auto block_dm) {
1260 auto block_mat_data =
1262
1263 {{simple->getDomainFEName(),
1264
1265 {{"U", "U"},
1266 {"EP", "EP"},
1267 {"TAU", "TAU"},
1268 {"U", "EP"},
1269 {"EP", "U"},
1270 {"EP", "TAU"},
1271 {"TAU", "U"},
1272 {"TAU", "EP"}
1273
1274 }}}
1275
1276 );
1277
1279
1280 {dm_schur, dm_block}, block_mat_data,
1281
1282 {"EP", "TAU"}, {nullptr, nullptr}, false
1283
1284 );
1285 };
1286
1287#endif
1288
1289 auto nested_mat_data = get_nested_mat_data(dm_schur, dm_block);
1290 CHKERR DMMoFEMSetNestSchurData(simple->getDM(), nested_mat_data);
1291
1292 auto block_is = getDMSubData(dm_block)->getSmartRowIs();
1293 auto ao_schur = getDMSubData(dm_schur)->getSmartRowMap();
1294
1295 // Indices has to be map fro very to level, while assembling Schur
1296 // complement.
1297 schur_ptr =
1298 SetUpSchur::createSetUpSchur(mField, dm_schur, block_is, ao_schur);
1299 CHKERR schur_ptr->setUp(solver);
1300 }
1301
1303 };
1304
1305 auto dm = simple->getDM();
1306 auto D = createDMVector(dm);
1307 auto DD = vectorDuplicate(D);
1308 CHKERR VecSetDM(D, PETSC_NULLPTR);
1309 CHKERR VecSetDM(DD, PETSC_NULLPTR);
1310 uXScatter = scatter_create(D, 0);
1311 uYScatter = scatter_create(D, 1);
1312 if constexpr (SPACE_DIM == 3)
1313 uZScatter = scatter_create(D, 2);
1314
1315 auto create_solver = [pip_mng]() {
1316 if (is_quasi_static == PETSC_TRUE)
1317 return pip_mng->createTSIM();
1318 else
1319 return pip_mng->createTSIM2();
1320 };
1321
1322 auto solver = create_solver();
1323
1324 auto active_pre_lhs = []() {
1326 std::fill(PlasticOps::CommonData::activityData.begin(),
1329 };
1330
1331 auto active_post_lhs = [&]() {
1333 auto get_iter = [&]() {
1334 SNES snes;
1335 CHK_THROW_MESSAGE(TSGetSNES(solver, &snes), "Can not get SNES");
1336 int iter;
1337 CHK_THROW_MESSAGE(SNESGetIterationNumber(snes, &iter),
1338 "Can not get iter");
1339 return iter;
1340 };
1341
1342 auto iter = get_iter();
1343 if (iter >= 0) {
1344
1345 std::array<int, 5> activity_data;
1346 std::fill(activity_data.begin(), activity_data.end(), 0);
1347 MPI_Allreduce(PlasticOps::CommonData::activityData.data(),
1348 activity_data.data(), activity_data.size(), MPI_INT,
1349 MPI_SUM, mField.get_comm());
1350
1351 int &active_points = activity_data[0];
1352 int &avtive_full_elems = activity_data[1];
1353 int &avtive_elems = activity_data[2];
1354 int &nb_points = activity_data[3];
1355 int &nb_elements = activity_data[4];
1356
1357 if (nb_points) {
1358
1359 double proc_nb_points =
1360 100 * static_cast<double>(active_points) / nb_points;
1361 double proc_nb_active =
1362 100 * static_cast<double>(avtive_elems) / nb_elements;
1363 double proc_nb_full_active = 100;
1364 if (avtive_elems)
1365 proc_nb_full_active =
1366 100 * static_cast<double>(avtive_full_elems) / avtive_elems;
1367
1368 MOFEM_LOG_C("PLASTICITY", Sev::inform,
1369 "Iter %d nb pts %d nb active pts %d (%3.3f\%) nb active "
1370 "elements %d "
1371 "(%3.3f\%) nb full active elems %d (%3.3f\%)",
1372 iter, nb_points, active_points, proc_nb_points,
1373 avtive_elems, proc_nb_active, avtive_full_elems,
1374 proc_nb_full_active, iter);
1375 }
1376 }
1377
1379 };
1380
1381 auto add_active_dofs_elem = [&](auto dm) {
1383 auto fe_pre_proc = boost::make_shared<FEMethod>();
1384 fe_pre_proc->preProcessHook = active_pre_lhs;
1385 auto fe_post_proc = boost::make_shared<FEMethod>();
1386 fe_post_proc->postProcessHook = active_post_lhs;
1387 auto ts_ctx_ptr = getDMTsCtx(dm);
1388 ts_ctx_ptr->getPreProcessIJacobian().push_front(fe_pre_proc);
1389 ts_ctx_ptr->getPostProcessIJacobian().push_back(fe_post_proc);
1391 };
1392
1393 auto set_essential_bc = [&](auto dm, auto solver) {
1395 // This is low level pushing finite elements (pipelines) to solver
1396
1397 auto pre_proc_ptr = boost::make_shared<FEMethod>();
1398 auto post_proc_rhs_ptr = boost::make_shared<FEMethod>();
1399 auto post_proc_lhs_ptr = boost::make_shared<FEMethod>();
1400 auto ts_ctx_ptr = getDMTsCtx(dm);
1401 ts_ctx_ptr->getPreProcessIFunction().push_front(pre_proc_ptr);
1402 ts_ctx_ptr->getPreProcessIJacobian().push_front(pre_proc_ptr);
1403 ts_ctx_ptr->getPostProcessIFunction().push_back(post_proc_rhs_ptr);
1404 ts_ctx_ptr->getPostProcessIJacobian().push_back(post_proc_lhs_ptr);
1405
1406 // Add boundary condition scaling
1407 auto disp_time_scale = boost::make_shared<TimeScale>();
1408
1409 auto get_bc_hook_rhs = [&]() {
1411 mField, pre_proc_ptr, {disp_time_scale}, false);
1412 };
1413 pre_proc_ptr->preProcessHook = get_bc_hook_rhs();
1414
1415 auto waak_post_proc_rhs_ptr = boost::weak_ptr<FEMethod>(
1416 post_proc_rhs_ptr); // fe method passed to lambda, have to be weak ptr to avoid circular shared ptr reference
1417 auto get_post_proc_hook_rhs = [this, waak_post_proc_rhs_ptr]() {
1420 mField, waak_post_proc_rhs_ptr.lock(), nullptr, Sev::verbose)();
1422 mField, waak_post_proc_rhs_ptr.lock(), 1.)();
1424 };
1425 auto get_post_proc_hook_lhs = [&]() {
1427 mField, post_proc_lhs_ptr, 1.);
1428 };
1429
1430 post_proc_rhs_ptr->postProcessHook = get_post_proc_hook_rhs;
1431 post_proc_lhs_ptr->postProcessHook = get_post_proc_hook_lhs();
1432
1434 };
1435
1436 auto B = createDMMatrix(dm);
1437 if (is_quasi_static == PETSC_FALSE) {
1438 CHKERR TSSetIJacobian(solver, B, B, PETSC_NULLPTR, PETSC_NULLPTR);
1439 } else {
1440 CHKERR TSSetI2Jacobian(solver, B, B, PETSC_NULLPTR, PETSC_NULLPTR);
1441 }
1442 if (is_quasi_static == PETSC_TRUE) {
1443 CHKERR TSSetSolution(solver, D);
1444 } else {
1445 CHKERR TS2SetSolution(solver, D, DD);
1446 }
1447 CHKERR set_section_monitor(solver);
1448 CHKERR set_time_monitor(dm, solver);
1449 CHKERR TSSetFromOptions(solver);
1450
1451 CHKERR add_active_dofs_elem(dm);
1452 boost::shared_ptr<SetUpSchur> schur_ptr;
1453 CHKERR set_schur_pc(solver, schur_ptr);
1454 CHKERR set_essential_bc(dm, solver);
1455
1456 MOFEM_LOG_CHANNEL("TIMER");
1457 MOFEM_LOG_TAG("TIMER", "timer");
1458 if (set_timer)
1459 BOOST_LOG_SCOPED_THREAD_ATTR("Timeline", attrs::timer());
1460 MOFEM_LOG("TIMER", Sev::verbose) << "TSSetUp";
1461 CHKERR TSSetUp(solver);
1462 MOFEM_LOG("TIMER", Sev::verbose) << "TSSetUp <= done";
1463 MOFEM_LOG("TIMER", Sev::verbose) << "TSSolve";
1464 CHKERR TSSolve(solver, NULL);
1465 // Solver convergence is cheap to check and carries no magic numbers, so it
1466 // stands alone rather than waiting on a "-test_nb"/"-test_name" selector.
1467 {
1468 PetscReal expected_time;
1469 CHKERR TSGetTime(solver, &expected_time);
1471 solver, expected_time, {1e-12, 1e-12}, "plasticity");
1472 }
1473 MOFEM_LOG("TIMER", Sev::verbose) << "TSSolve <= done";
1474
1475 if (mField.get_comm_rank() == 0) {
1476 auto ts_ctx_ptr = getDMTsCtx(dm);
1478 "ts_manager_graph.dot");
1479 }
1480
1482}
1483//! [Solve]
1484
1485//! [TestOperators]
1488
1489 // get operators tester
1490 auto simple = mField.getInterface<Simple>();
1491 auto opt = mField.getInterface<OperatorsTester>(); // get interface to
1492 // OperatorsTester
1493 auto pip = mField.getInterface<PipelineManager>(); // get interface to
1494 // pipeline manager
1495
1496 constexpr double eps = 1e-9;
1497
1498 auto x = opt->setRandomFields(simple->getDM(), {
1499
1500 {"U", {-1e-4, 1e-4}},
1501
1502 {"EP", {-1e-4, 1e-4}},
1503
1504 {"TAU", {0, 1e-4}}
1505
1506 });
1507
1508 auto dot_x_plastic_active =
1509 opt->setRandomFields(simple->getDM(), {
1510
1511 {"U", {-1, 1}},
1512
1513 {"EP", {-1, 1}},
1514
1515 {"TAU", {0.1, 0.5}}
1516
1517 });
1518 auto diff_x_plastic_active =
1519 opt->setRandomFields(simple->getDM(), {
1520
1521 {"U", {-1, 1}},
1522
1523 {"EP", {-1, 1}},
1524
1525 {"TAU", {-1, 1}}
1526
1527 });
1528
1529 auto dot_x_elastic =
1530 opt->setRandomFields(simple->getDM(), {
1531
1532 {"U", {-1, 1}},
1533
1534 {"EP", {-1, 1}},
1535
1536 {"TAU", {-1, -0.1}}
1537
1538 });
1539 auto diff_x_elastic =
1540 opt->setRandomFields(simple->getDM(), {
1541
1542 {"U", {-1, 1}},
1543
1544 {"EP", {-1, 1}},
1545
1546 {"TAU", {-1, 1}}
1547
1548 });
1549
1550 auto test_domain_ops = [&](auto fe_name, auto lhs_pipeline, auto rhs_pipeline,
1551 auto dot_x, auto diff_x) {
1553
1554 auto diff_res = opt->checkCentralFiniteDifference(
1555 simple->getDM(), fe_name, rhs_pipeline, lhs_pipeline, x, dot_x,
1556 SmartPetscObj<Vec>(), diff_x, 0, 0.5, eps);
1557
1558 // Calculate norm of difference between directional derivative calculated
1559 // from finite difference, and tangent matrix.
1560 double fnorm;
1561 CHKERR VecNorm(diff_res, NORM_2, &fnorm);
1562 MOFEM_LOG_C("PLASTICITY", Sev::inform,
1563 "Test consistency of tangent matrix %3.4e", fnorm);
1564
1565 constexpr double err = 1e-5;
1566 if (fnorm > err)
1567 SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
1568 "Norm of directional derivative too large err = %3.4e", fnorm);
1569
1571 };
1572
1573 MOFEM_LOG("PLASTICITY", Sev::inform) << "Elastic active";
1574 CHKERR test_domain_ops(simple->getDomainFEName(), pip->getDomainLhsFE(),
1575 pip->getDomainRhsFE(), dot_x_elastic, diff_x_elastic);
1576
1577 MOFEM_LOG("PLASTICITY", Sev::inform) << "Plastic active";
1578 CHKERR test_domain_ops(simple->getDomainFEName(), pip->getDomainLhsFE(),
1579 pip->getDomainRhsFE(), dot_x_plastic_active,
1580 diff_x_plastic_active);
1581
1583};
1584
1585//! [TestOperators]
1586
1587static char help[] = "...\n\n";
1588
1589int main(int argc, char *argv[]) {
1590
1591 // Initialisation of MoFEM/PETSc and MOAB data structures
1592 const char param_file[] = "param_file.petsc";
1593 MoFEM::Core::Initialize(&argc, &argv, param_file, help);
1594
1595 // Add logging channel for example
1596 auto core_log = logging::core::get();
1597 core_log->add_sink(
1599 core_log->add_sink(
1601 LogManager::setLog("PLASTICITY");
1602 MOFEM_LOG_TAG("PLASTICITY", "Plasticity");
1603
1604#ifdef ADD_CONTACT
1605 core_log->add_sink(
1607 LogManager::setLog("CONTACT");
1608 MOFEM_LOG_TAG("CONTACT", "Contact");
1609#endif // ADD_CONTACT
1610
1611 core_log->add_sink(
1613 LogManager::setLog("PlasticSync");
1614 MOFEM_LOG_TAG("PlasticSync", "PlasticSync");
1615
1616 try {
1617#if defined(ADD_CONTACT) && defined(ENABLE_PYTHON_BINDING)
1619#endif
1620
1621 //! [Register MoFEM discrete manager in PETSc]
1622 DMType dm_name = "DMMOFEM";
1623 CHKERR DMRegister_MoFEM(dm_name);
1624 //! [Register MoFEM discrete manager in PETSc
1625
1626 //! [Create MoAB]
1627 moab::Core mb_instance; ///< mesh database
1628 moab::Interface &moab = mb_instance; ///< mesh database interface
1629 //! [Create MoAB]
1630
1631 //! [Create MoFEM]
1632 MoFEM::Core core(moab); ///< finite element database
1633 MoFEM::Interface &m_field = core; ///< finite element database interface
1634 //! [Create MoFEM]
1635
1636 //! [Load mesh]
1637 Simple *simple = m_field.getInterface<Simple>();
1639 CHKERR simple->loadFile();
1640 //! [Load mesh]
1641
1642 //! [Example]
1643 Example ex(m_field);
1644 CHKERR ex.runProblem();
1645 //! [Example]
1646 }
1648
1649#if defined(ADD_CONTACT) && defined(ENABLE_PYTHON_BINDING)
1651#endif
1653
1654 return 0;
1655}
1656
1657struct SetUpSchurImpl : public SetUpSchur {
1658
1660 SmartPetscObj<IS> field_split_is, SmartPetscObj<AO> ao_up)
1661 : SetUpSchur(), mField(m_field), subDM(sub_dm),
1662 fieldSplitIS(field_split_is), aoSchur(ao_up) {
1663 if (S) {
1665 "Is expected that schur matrix is not "
1666 "allocated. This is "
1667 "possible only is if PC is set up twice");
1668 }
1669 }
1670 virtual ~SetUpSchurImpl() { S.reset(); }
1671
1672 MoFEMErrorCode setUp(TS solver);
1675
1676private:
1678
1680 SmartPetscObj<DM> subDM; ///< field split sub dm
1681 SmartPetscObj<IS> fieldSplitIS; ///< IS for split Schur block
1682 SmartPetscObj<AO> aoSchur; ///> main DM to subDM
1683};
1684
1687 auto simple = mField.getInterface<Simple>();
1688 auto pip_mng = mField.getInterface<PipelineManager>();
1689
1690 SNES snes;
1691 CHKERR TSGetSNES(solver, &snes);
1692 KSP ksp;
1693 CHKERR SNESGetKSP(snes, &ksp);
1694 CHKERR KSPSetFromOptions(ksp);
1695
1696 PC pc;
1697 CHKERR KSPGetPC(ksp, &pc);
1698 PetscBool is_pcfs = PETSC_FALSE;
1699 PetscObjectTypeCompare((PetscObject)pc, PCFIELDSPLIT, &is_pcfs);
1700 if (is_pcfs) {
1701 if (S) {
1703 "Is expected that schur matrix is not "
1704 "allocated. This is "
1705 "possible only is if PC is set up twice");
1706 }
1707
1709 CHKERR MatSetBlockSize(S, SPACE_DIM);
1710
1711 // Set DM to use shell block matrix
1712 DM solver_dm;
1713 CHKERR TSGetDM(solver, &solver_dm);
1714 CHKERR DMSetMatType(solver_dm, MATSHELL);
1715
1716 auto ts_ctx_ptr = getDMTsCtx(solver_dm);
1717 auto A = createDMBlockMat(simple->getDM());
1718 auto P = createDMNestSchurMat(simple->getDM());
1719
1720 if (is_quasi_static == PETSC_TRUE) {
1721 auto swap_assemble = [](TS ts, PetscReal t, Vec u, Vec u_t, PetscReal a,
1722 Mat A, Mat B, void *ctx) {
1723 return TsSetIJacobian(ts, t, u, u_t, a, B, A, ctx);
1724 };
1725 CHKERR TSSetIJacobian(solver, A, P, swap_assemble, ts_ctx_ptr.get());
1726 } else {
1727 auto swap_assemble = [](TS ts, PetscReal t, Vec u, Vec u_t, Vec utt,
1728 PetscReal a, PetscReal aa, Mat A, Mat B,
1729 void *ctx) {
1730 return TsSetI2Jacobian(ts, t, u, u_t, utt, a, aa, B, A, ctx);
1731 };
1732 CHKERR TSSetI2Jacobian(solver, A, P, swap_assemble, ts_ctx_ptr.get());
1733 }
1734 CHKERR KSPSetOperators(ksp, A, P);
1735
1736 auto set_ops = [&]() {
1738 auto pip_mng = mField.getInterface<PipelineManager>();
1739
1740#ifndef ADD_CONTACT
1741 // Boundary
1742 pip_mng->getOpBoundaryLhsPipeline().push_front(
1744 pip_mng->getOpBoundaryLhsPipeline().push_back(createOpSchurAssembleEnd(
1745
1746 {"EP", "TAU"}, {nullptr, nullptr}, aoSchur, S, false, false
1747
1748 ));
1749 // Domain
1750 pip_mng->getOpDomainLhsPipeline().push_front(
1752 pip_mng->getOpDomainLhsPipeline().push_back(createOpSchurAssembleEnd(
1753
1754 {"EP", "TAU"}, {nullptr, nullptr}, aoSchur, S, false, false
1755
1756 ));
1757#else
1758
1759 double eps_stab = 1e-4;
1760 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-eps_stab", &eps_stab,
1761 PETSC_NULLPTR);
1762
1765 using OpMassStab = B::OpMass<3, SPACE_DIM * SPACE_DIM>;
1766
1767 // Boundary
1768 pip_mng->getOpBoundaryLhsPipeline().push_front(
1770 pip_mng->getOpBoundaryLhsPipeline().push_back(
1771 new OpMassStab("SIGMA", "SIGMA", [eps_stab](double, double, double) {
1772 return eps_stab;
1773 }));
1774 pip_mng->getOpBoundaryLhsPipeline().push_back(createOpSchurAssembleEnd(
1775
1776 {"SIGMA", "EP", "TAU"}, {nullptr, nullptr, nullptr}, aoSchur, S,
1777 false, false
1778
1779 ));
1780 // Domain
1781 pip_mng->getOpDomainLhsPipeline().push_front(
1783 pip_mng->getOpDomainLhsPipeline().push_back(createOpSchurAssembleEnd(
1784
1785 {"SIGMA", "EP", "TAU"}, {nullptr, nullptr, nullptr}, aoSchur, S,
1786 false, false
1787
1788 ));
1789#endif // ADD_CONTACT
1791 };
1792
1793 auto set_assemble_elems = [&]() {
1795 auto schur_asmb_pre_proc = boost::make_shared<FEMethod>();
1796 schur_asmb_pre_proc->preProcessHook = [this]() {
1798 CHKERR MatZeroEntries(S);
1799 MOFEM_LOG("TIMER", Sev::verbose) << "Lhs Assemble Begin";
1801 };
1802 auto schur_asmb_post_proc = boost::make_shared<FEMethod>();
1803 auto weak_schur_asmb_post_proc = boost::weak_ptr<FEMethod>(
1804 schur_asmb_post_proc); // fe method passed to lambda, have to be weak ptr to avoid circular shared ptr reference
1805
1806 schur_asmb_post_proc->postProcessHook = [this,
1807 weak_schur_asmb_post_proc]() {
1809 MOFEM_LOG("TIMER", Sev::verbose) << "Lhs Assemble End";
1810
1811 // Apply essential constrains to Schur complement
1812 CHKERR MatAssemblyBegin(S, MAT_FINAL_ASSEMBLY);
1813 CHKERR MatAssemblyEnd(S, MAT_FINAL_ASSEMBLY);
1815 mField, weak_schur_asmb_post_proc.lock(), 1, S, aoSchur)();
1816
1818 };
1819 auto ts_ctx_ptr = getDMTsCtx(simple->getDM());
1820 ts_ctx_ptr->getPreProcessIJacobian().push_front(schur_asmb_pre_proc);
1821 ts_ctx_ptr->getPostProcessIJacobian().push_front(schur_asmb_post_proc);
1823 };
1824
1825 auto set_pc = [&]() {
1827 CHKERR PCFieldSplitSetIS(pc, NULL, fieldSplitIS);
1828 CHKERR PCFieldSplitSetSchurPre(pc, PC_FIELDSPLIT_SCHUR_PRE_USER, S);
1830 };
1831
1832 auto set_diagonal_pc = [&]() {
1834 KSP *subksp;
1835 CHKERR PCFieldSplitSchurGetSubKSP(pc, PETSC_NULLPTR, &subksp);
1836 auto get_pc = [](auto ksp) {
1837 PC pc_raw;
1838 CHKERR KSPGetPC(ksp, &pc_raw);
1839 return SmartPetscObj<PC>(pc_raw,
1840 true); // bump reference
1841 };
1842 CHKERR setSchurA00MatSolvePC(get_pc(subksp[0]));
1843 CHKERR PetscFree(subksp);
1845 };
1846
1847 CHKERR set_ops();
1848 CHKERR set_pc();
1849 CHKERR set_assemble_elems();
1850
1851 CHKERR TSSetUp(solver);
1852 CHKERR KSPSetUp(ksp);
1853 CHKERR set_diagonal_pc();
1854
1855 } else {
1856 pip_mng->getOpBoundaryLhsPipeline().push_front(
1858 pip_mng->getOpBoundaryLhsPipeline().push_back(
1859 createOpSchurAssembleEnd({}, {}));
1860 pip_mng->getOpDomainLhsPipeline().push_front(createOpSchurAssembleBegin());
1861 pip_mng->getOpDomainLhsPipeline().push_back(
1862 createOpSchurAssembleEnd({}, {}));
1863 }
1864
1865 // fieldSplitIS.reset();
1866 // aoSchur.reset();
1868}
1869
1870boost::shared_ptr<SetUpSchur>
1872 SmartPetscObj<DM> sub_dm, SmartPetscObj<IS> is_sub,
1873 SmartPetscObj<AO> ao_up) {
1874 return boost::shared_ptr<SetUpSchur>(
1875 new SetUpSchurImpl(m_field, sub_dm, is_sub, ao_up));
1876}
1877
1878namespace PlasticOps {
1879
1881 boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pipeline,
1882 std::vector<FieldSpace> spaces, std::string geom_field_name) {
1884 CHKERR MoFEM::AddHOOps<2, 3, 3>::add(pipeline, spaces, geom_field_name);
1886}
1887
1889 boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pipeline,
1890 std::vector<FieldSpace> spaces, std::string geom_field_name) {
1892 CHKERR MoFEM::AddHOOps<1, 2, 2>::add(pipeline, spaces, geom_field_name);
1894}
1895
1896template <int FE_DIM, int PROBLEM_DIM, int SPACE_DIM>
1898scaleL2(boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pipeline,
1899 std::string geom_field_name) {
1901
1902 auto jac_ptr = boost::make_shared<MatrixDouble>();
1903 auto det_ptr = boost::make_shared<VectorDouble>();
1905 geom_field_name, jac_ptr));
1906 pipeline.push_back(new OpInvertMatrix<SPACE_DIM>(jac_ptr, det_ptr, nullptr));
1907
1908 auto scale_ptr = boost::make_shared<double>(1.);
1910 Example::meshVolumeAndCount[1]; // average volume of elements
1912 auto op_scale = new OP(NOSPACE, OP::OPSPACE);
1913 op_scale->doWorkRhsHook = [scale_ptr, det_ptr,
1914 scale](DataOperator *base_op_ptr, int, EntityType,
1916 *scale_ptr = scale / det_ptr->size(); // distribute average element size
1917 // over integration points
1918 return 0;
1919 };
1920 pipeline.push_back(op_scale);
1921
1924 pipeline.push_back(
1925 new OpScaleBaseBySpaceInverseOfMeasure(L2, base, det_ptr, scale_ptr));
1926 }
1927
1929}
1930
1932 boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pipeline,
1933 std::vector<FieldSpace> spaces, std::string geom_field_name) {
1935 constexpr bool scale_l2 = false;
1936 if (scale_l2) {
1937 CHKERR scaleL2<3, 3, 3>(pipeline, geom_field_name);
1938 }
1939 CHKERR MoFEM::AddHOOps<3, 3, 3>::add(pipeline, spaces, geom_field_name,
1940 nullptr, nullptr, nullptr);
1942}
1943
1945 boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pipeline,
1946 std::vector<FieldSpace> spaces, std::string geom_field_name) {
1948 constexpr bool scale_l2 = false;
1949 if (scale_l2) {
1950 CHKERR scaleL2<2, 2, 2>(pipeline, geom_field_name);
1951 }
1952 CHKERR MoFEM::AddHOOps<2, 2, 2>::add(pipeline, spaces, geom_field_name,
1953 nullptr, nullptr, nullptr);
1955}
1956
1957} // namespace PlasticOps
MoFEM::Interface & mField
FaceSet skin
WorkMesh base
Vec t
Removal: the ring edge.
SmartPetscObj< KSP > ksp
std::string type
#define MOFEM_LOG_SYNCHRONISE(comm)
Synchronise "SYNC" channel.
#define MOFEM_LOG_C(channel, severity, format,...)
It end
Definition Schur.cpp:2568
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition acoustic.cpp:69
int main()
constexpr double a
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
ElementsAndOps< SPACE_DIM >::BoundaryEle BoundaryEle
Kronecker Delta class symmetric.
#define SCHUR_ASSEMBLE
Definition contact.cpp:18
@ ROW
#define CATCH_ERRORS
Catch errors.
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition definitions.h:60
@ AINSWORTH_LOBATTO_BASE
Definition definitions.h:62
@ NOBASE
Definition definitions.h:59
@ 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
@ NOSPACE
Definition definitions.h:83
@ 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 ...
#define CHK_MOAB_THROW(err, msg)
Check error code of MoAB function and throw MoFEM exception.
@ MOFEM_NOT_FOUND
Definition definitions.h:33
@ MOFEM_ATOM_TEST_INVALID
Definition definitions.h:40
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
static const char *const ApproximationBaseNames[]
Definition definitions.h:72
#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 ...
constexpr int order
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::LinearForm< GAUSS >::OpBaseTimesVector< 1, SPACE_DIM, SPACE_DIM > OpInertiaForce
constexpr auto t_kd
constexpr int SPACE_DIM
[Define dimension]
Definition gradient.cpp:19
constexpr double poisson_ratio
Poisson's ratio ν
Definition gradient.cpp:30
constexpr double young_modulus
[Material properties for linear elasticity]
Definition gradient.cpp:29
PetscErrorCode DMMoFEMCreateSubDM(DM subdm, DM dm, const char problem_name[])
Must be called by user to set Sub DM MoFEM data structures.
Definition DMMoFEM.cpp:244
PetscErrorCode DMMoFEMAddElement(DM dm, std::string fe_name)
add element to dm
Definition DMMoFEM.cpp:574
PetscErrorCode DMMoFEMSetSquareProblem(DM dm, PetscBool square_problem)
set squared problem
Definition DMMoFEM.cpp:536
PetscErrorCode DMMoFEMAddSubFieldRow(DM dm, const char field_name[])
Definition DMMoFEM.cpp:267
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 DMMoFEMAddSubFieldCol(DM dm, const char field_name[])
Definition DMMoFEM.cpp:309
auto createDMMatrix(DM dm)
Get smart matrix from DM.
Definition DMMoFEM.hpp:1236
IntegrationType
Form integrator integration types.
AssemblyType
[Storage and set boundary conditions]
@ GAUSS
Gaussian quadrature integration.
@ PETSC
Standard PETSc assembly.
@ BLOCK_PRECONDITIONER_SCHUR
Block preconditioner Schur 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.
FTensor::Index< 'i', SPACE_DIM > i
double D
const double v
phase velocity of light in medium (cm/ns)
FTensor::Index< 'l', 3 > l
FTensor::Index< 'j', 3 > j
FTensor::Index< 'k', 3 > k
double cn_contact
Definition contact.cpp:88
const FTensor::Tensor2< T, Dim, Dim > Vec
[HenckyOps]
Definition HenckyOps.hpp:12
static const double eps
Definition HenckyOps.hpp:14
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
auto type_from_handle(const EntityHandle h)
get type from entity handle
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
PetscErrorCode TsSetIJacobian(TS ts, PetscReal t, Vec u, Vec u_t, PetscReal a, Mat A, Mat B, void *ctx)
Set function evaluating jacobian in TS solver.
Definition TsCtx.cpp:169
auto getDMTsCtx(DM dm)
Get TS context data structure used by DM.
Definition DMMoFEM.hpp:1321
OpSchurAssembleBase * createOpSchurAssembleEnd(std::vector< std::string > fields_name, std::vector< boost::shared_ptr< Range > > field_ents, SmartPetscObj< AO > ao, SmartPetscObj< Mat > schur, bool sym_schur, bool symm_op)
Construct a new Op Schur Assemble End object.
Definition Schur.cpp:4892
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
MoFEMErrorCode setSchurA00MatSolvePC(SmartPetscObj< PC > pc)
Set PC for A00 block.
Definition Schur.cpp:4934
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.
PetscErrorCode PetscOptionsGetRealArray(PetscOptions *, const char pre[], const char name[], PetscReal dval[], PetscInt *nmax, PetscBool *set)
auto getDMSubData(DM dm)
Get sub problem data structure.
Definition DMMoFEM.hpp:1337
PetscErrorCode TsSetI2Jacobian(TS ts, PetscReal t, Vec u, Vec u_t, Vec u_tt, PetscReal a, PetscReal aa, Mat A, Mat B, void *ctx)
Calculation Jacobian for second order PDE in time.
Definition TsCtx.cpp:519
boost::shared_ptr< BlockStructure > createBlockMatStructure(DM dm, SchurFEOpsFEandFields schur_fe_op_vec)
Create block matrix structure.
Definition Schur.cpp:2819
boost::shared_ptr< NestSchurData > createSchurNestedMatrixStruture(std::pair< SmartPetscObj< DM >, SmartPetscObj< DM > > dms, boost::shared_ptr< BlockStructure > block_mat_data_ptr, std::vector< std::string > fields_names, std::vector< boost::shared_ptr< Range > > field_ents, bool add_preconditioner_block)
Create structure of nested matrix [A11 A10; A01 A00].
Definition Schur.cpp:4760
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
MoFEMErrorCode DMMoFEMSetNestSchurData(DM dm, boost::shared_ptr< NestSchurData >)
Definition DMMoFEM.cpp:1641
static auto getFTensor0FromVec(V &data)
Get tensor rank 0 (scalar) form data vector.
auto getDMSnesCtx(DM dm)
Get SNES context data structure used by DM.
Definition DMMoFEM.hpp:1307
auto createDMNestSchurMat(DM dm)
Definition DMMoFEM.hpp:1263
auto createDM(MPI_Comm comm, const std::string dm_type_name)
Creates smart DM object.
OpSchurAssembleBase * createOpSchurAssembleBegin()
Definition Schur.cpp:4887
auto createDMBlockMat(DM dm)
Definition DMMoFEM.hpp:1256
MoFEMErrorCode scaleL2(boost::ptr_deque< ForcesAndSourcesCore::UserDataOperator > &pipeline, std::string geom_field_name)
Definition plastic.cpp:1898
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
double young_modulus
Young modulus.
Definition plastic.cpp:126
constexpr AssemblyType AT
Definition plastic.cpp:44
double C1_k
Kinematic hardening.
Definition plastic.cpp:134
double Qinf
Saturation yield stress.
Definition plastic.cpp:132
constexpr IntegrationType IT
Definition plastic.cpp:47
static char help[]
[TestOperators]
Definition plastic.cpp:1587
double rho
Definition plastic.cpp:145
int atom_test
Atom test.
Definition plastic.cpp:122
#define EXECUTABLE_DIMENSION
Definition plastic.cpp:13
PetscBool do_eval_field
Evaluate field.
Definition plastic.cpp:120
PetscBool is_quasi_static
Definition plastic.cpp:144
double alpha_damping
Definition plastic.cpp:146
constexpr int SPACE_DIM
Definition plastic.cpp:40
double visH
Viscous hardening.
Definition plastic.cpp:130
double poisson_ratio
Poisson ratio.
Definition plastic.cpp:127
auto kinematic_hardening(FTensor::Tensor2_symmetric< T, DIM > &t_plastic_strain, double C1_k)
Definition plastic.cpp:93
PetscBool set_timer
Set timer.
Definition plastic.cpp:119
double iso_hardening_dtau(double tau, double H, double Qinf, double b_iso)
Definition plastic.cpp:79
double scale
Definition plastic.cpp:124
constexpr auto size_symm
Definition plastic.cpp:42
double zeta
Viscous hardening.
Definition plastic.cpp:131
double H
Hardening.
Definition plastic.cpp:129
int tau_order
Order of tau files.
Definition plastic.cpp:140
double iso_hardening_exp(double tau, double b_iso)
Definition plastic.cpp:65
double cn0
Definition plastic.cpp:136
int order
Order displacement.
Definition plastic.cpp:139
double b_iso
Saturation exponent.
Definition plastic.cpp:133
PetscBool is_large_strains
Large strains.
Definition plastic.cpp:118
int geom_order
Order if fixed.
Definition plastic.cpp:142
double sigmaY
Yield stress.
Definition plastic.cpp:128
double iso_hardening(double tau, double H, double Qinf, double b_iso, double sigmaY)
Definition plastic.cpp:74
auto kinematic_hardening_dplastic_strain(double C1_k)
Definition plastic.cpp:107
ElementsAndOps< SPACE_DIM >::SideEle SideEle
Definition plastic.cpp:62
int ep_order
Order of ep files.
Definition plastic.cpp:141
double cn1
Definition plastic.cpp:137
constexpr FieldSpace CONTACT_SPACE
Definition plastic.cpp:52
constexpr int SPACE_DIM
[Define dimension]
constexpr AssemblyType A
[Define dimension]
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpMass< 1, SPACE_DIM > OpMass
[Only used with Hooke equation (linear material model)]
Definition seepage.cpp:56
FTensor::Index< 'm', 3 > m
PipelineManager::ElementsAndOpsByDim< 2 >::FaceSideEle SideEle
Definition plastic.cpp:29
PipelineManager::ElementsAndOpsByDim< 3 >::FaceSideEle SideEle
Definition plastic.cpp:36
[Operators_definition]
double getScale(const double time)
Get scaling at given time.
Definition plastic.cpp:234
[Example]
Definition plastic.cpp:209
std::tuple< SmartPetscObj< Vec >, SmartPetscObj< VecScatter > > uZScatter
Definition plastic.cpp:230
std::tuple< SmartPetscObj< Vec >, SmartPetscObj< VecScatter > > uXScatter
Definition plastic.cpp:228
MoFEMErrorCode testOperators()
[Solve]
Definition plastic.cpp:1486
MoFEMErrorCode tsSolve()
Definition plastic.cpp:826
FieldApproximationBase base
Choice of finite element basis functions.
Definition plot_base.cpp:68
Simple * simple
MoFEMErrorCode createCommonData()
[Set up problem]
Definition plastic.cpp:471
SmartPetscObj< Mat > H
static std::array< double, 2 > meshVolumeAndCount
Definition plastic.cpp:216
std::tuple< SmartPetscObj< Vec >, SmartPetscObj< VecScatter > > uYScatter
Definition plastic.cpp:229
Example(MoFEM::Interface &m_field)
Definition plastic.cpp:211
MoFEMErrorCode OPs()
[Boundary condition]
Definition plastic.cpp:642
MoFEMErrorCode runProblem()
[Run problem]
Definition plastic.cpp:247
MoFEM::Interface & mField
Reference to MoFEM interface.
Definition plastic.cpp:219
MoFEMErrorCode setupProblem()
[Run problem]
Definition plastic.cpp:266
MoFEMErrorCode bC()
[Create common data]
Definition plastic.cpp:598
SmartPetscObj< EPS > eps
std::array< double, 3 > scale
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
base operator to do operations at Gauss Pt. level
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
Field evaluator interface.
SetIntegrationPtsMethodData SetPtsData
double getMeasure() const
get measure of element
@ OPSPACE
operator do Work is execute on space data
Section manager is used to create indexes and sections.
Definition ISManager.hpp:23
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.
Interface for managing meshsets containing materials and boundary conditions.
Assembly methods.
Definition Natural.hpp:65
Get field gradients at integration pts for scalar field rank 0, i.e. vector field.
Approximate field values for given petsc vector.
Specialization for MatrixDouble vector field values calculation.
Operator for inverting matrices at integration points.
Element used to execute operators on side of the element.
Post post-proc data at points from hash maps.
Scale base functions by inverses of measure of element.
Calculate directional derivative of the right hand side and compare it with tangent matrix derivative...
static MoFEMErrorCode writeTSGraphGraphviz(TsCtx *ts_ctx, std::string file_name)
TS graph to Graphviz file.
Template struct for dimension-specific finite element types.
PipelineManager interface.
MoFEM::VolumeElementForcesAndSourcesCore VolEle
boost::shared_ptr< FEMethod > & getDomainLhsFE()
Get domain left-hand side finite element.
MoFEM::FaceElementForcesAndSourcesCore FaceEle
MoFEM::EdgeElementForcesAndSourcesCore EdgeEle
Projection of edge entities with one mid-node on hierarchical basis.
static MoFEMErrorCode initialise()
Definition SDFPython.cpp:84
static MoFEMErrorCode finalise()
Simple interface for fast problem set-up.
Definition Simple.hpp:27
MoFEMErrorCode addDomainField(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add field on domain.
Definition Simple.cpp:264
MoFEMErrorCode addBoundaryField(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add field on boundary.
Definition Simple.cpp:358
MoFEMErrorCode addFieldToEmptyFieldBlocks(const std::string row_field, const std::string col_field) const
Add empty block to problem.
Definition Simple.cpp:837
MoFEMErrorCode getOptions()
get options
Definition Simple.cpp:180
MoFEMErrorCode getDM(DM *dm)
Get DM.
Definition Simple.cpp:802
MoFEMErrorCode setFieldOrder(const std::string field_name, const int order, const Range *ents=NULL)
Set field order.
Definition Simple.cpp:578
MoFEMErrorCode addDataField(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add data field.
Definition Simple.cpp:396
MoFEMErrorCode setUp(const PetscBool is_partitioned=PETSC_TRUE)
Setup problem.
Definition Simple.cpp:738
const std::string getProblemName() const
Get the Problem Name.
Definition Simple.hpp:450
const std::string getDomainFEName() const
Get the Domain FE Name.
Definition Simple.hpp:429
intrusive_ptr for managing petsc objects
Force scale operator for reading two columns.
double getScale(const double time)
Get scaling at a given time.
TimeScale(std::string file_name="", bool error_if_file_not_given=false, ScalingFun def_scaling_fun=[](double time) { return time;})
TimeScale constructor.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
static std::array< int, 5 > activityData
SmartPetscObj< DM > subDM
field split sub dm
Definition plastic.cpp:1680
SmartPetscObj< Mat > S
SmartPetscObj< AO > aoSchur
Definition plastic.cpp:1682
SetUpSchurImpl(MoFEM::Interface &m_field, SmartPetscObj< DM > sub_dm, SmartPetscObj< IS > field_split_is, SmartPetscObj< AO > ao_up)
Definition plastic.cpp:1659
MoFEMErrorCode setUp(SmartPetscObj< KSP >)
SmartPetscObj< IS > fieldSplitIS
IS for split Schur block.
Definition plastic.cpp:1681
virtual ~SetUpSchurImpl()
Definition plastic.cpp:1670
MoFEMErrorCode postProc()
MoFEMErrorCode preProc()
MoFEM::Interface & mField
[Push operators to pipeline]
SetUpSchur()=default
static boost::shared_ptr< SetUpSchur > createSetUpSchur(MoFEM::Interface &m_field)
virtual MoFEMErrorCode setUp(TS solver)=0
static auto get_skin(MoFEM::Interface &m_field, Range body_ents)
static auto filter_true_skin(MoFEM::Interface &m_field, Range &&skin)
constexpr AssemblyType AT
VolEle::UserDataOperator VolOp