v0.16.3
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
NonlinearElasticExample Struct Reference

#include "tutorials/vec-2_nonlinear_elasticity/src/NonlinearElasticExample.hpp"

Inheritance diagram for NonlinearElasticExample:
[legend]
Collaboration diagram for NonlinearElasticExample:
[legend]

Classes

struct  TSElasticPostStep
 

Public Member Functions

 NonlinearElasticExample (MoFEM::Interface &m_field)
 
MoFEMErrorCode runProblem ()
 [Run problem]
 

Protected Member Functions

MoFEMErrorCode readMesh ()
 [Run problem]
 
MoFEMErrorCode setupProblem ()
 [Read mesh]
 
MoFEMErrorCode boundaryCondition ()
 [Set up problem]
 
MoFEMErrorCode assembleSystemHencky ()
 [Boundary condition]
 
MoFEMErrorCode assembleSystemAdolc ()
 
MoFEMErrorCode opTest ()
 [Push operators to pipeline]
 
MoFEMErrorCode TsSolve ()
 [TS Solve]
 
MoFEMErrorCode gettingNorms ()
 [TS Solve]
 
MoFEMErrorCode outputResults ()
 [Getting norms]
 
MoFEMErrorCode checkResults ()
 [Postprocessing results]
 

Static Protected Member Functions

static auto get_skin (MoFEM::Interface &m_field, Range body_ents)
 
static auto filter_true_skin (MoFEM::Interface &m_field, Range &&skin)
 

Protected Attributes

MoFEM::Interface & mField
 
boost::shared_ptr< DomainEle > updateFe
 
boost::shared_ptr< PostProcEleDomain > postProcDomainFe
 
boost::shared_ptr< PostProcEleBdy > postProcBdyFe
 
PetscBool useAdolcMaterial = PETSC_FALSE
 
FieldApproximationBase approximationBase = AINSWORTH_LEGENDRE_BASE
 
std::vector< Tag > listTagsToTransfer
 list of tags to transfer to postprocessor
 
boost::shared_ptr< MatOps::PhysicalEquations > physicalEquationsPtr
 
boost::shared_ptr< MatOps::PhysicalEquations > physicalHuHuPtr
 

Static Protected Attributes

static constexpr int MAT_DIM = SPACE_DIM
 
static constexpr int modelType
 

Detailed Description

Examples
mofem/tutorials/vec-2_nonlinear_elasticity/nonlinear_elastic.cpp, mofem/tutorials/vec-2_nonlinear_elasticity/src/NonlinearElasticExample.hpp, and mofem/tutorials/vec-9_arc_length/src/ArcLengthExample.hpp.

Definition at line 22 of file NonlinearElasticExample.hpp.

Constructor & Destructor Documentation

◆ NonlinearElasticExample()

NonlinearElasticExample::NonlinearElasticExample ( MoFEM::Interface &  m_field)
inline

Definition at line 24 of file NonlinearElasticExample.hpp.

24: mField(m_field) {}

Member Function Documentation

◆ assembleSystemAdolc()

MoFEMErrorCode NonlinearElasticExample::assembleSystemAdolc ( )
protected
Examples
mofem/tutorials/vec-2_nonlinear_elasticity/src/NonlinearElasticExample.hpp, and mofem/tutorials/vec-9_arc_length/src/ArcLengthExample.hpp.

Definition at line 525 of file NonlinearElasticExample.hpp.

525 {
527
528 auto *simple = mField.getInterface<Simple>();
529 auto *pipeline_mng = mField.getInterface<PipelineManager>();
530
531 auto integration_rule = [](int, int, int approx_order) {
532 return 2 * (approx_order - 1) + 1;
533 };
534
535 CHKERR pipeline_mng->setDomainRhsIntegrationRule(integration_rule);
536 CHKERR pipeline_mng->setDomainLhsIntegrationRule(integration_rule);
537 CHKERR pipeline_mng->setBoundaryRhsIntegrationRule(integration_rule);
538 CHKERR pipeline_mng->setEvaluationIntegrationRule(integration_rule);
539
540#ifdef WITH_ADOL_C
541 auto mat_ops_data_ptr = MatOps::createMatOpsDataPtr();
542
543 #ifdef WITH_ADOL_C_UMAT
544 {
545 constexpr int umat_model_type =
547 auto umat_physical_equations_ptr =
548 MatOps::createMatOpsPhysicalEquationsPtr<MatOps::UMAT, umat_model_type>(
549 mat_ops_data_ptr, MatOps::MatOpsTagsRegistry::setTagName("Umat"));
550
551 CHKERR umat_physical_equations_ptr->getOptions(&mField);
552 CHKERR umat_physical_equations_ptr->recordTape();
553
554 physicalEquationsPtr = umat_physical_equations_ptr;
555 }
556 #else
560 modelType>(
561 mat_ops_data_ptr,
562 MatOps::MatOpsTagsRegistry::setTagName("MetaPiolaResponse", 0));
563 }
564
565 #ifdef WITH_ADOL_C_GENERIC_ELASTIC
566 if (true) {
567 auto generic_physical_equations_ptr =
569 modelType>(
570 mat_ops_data_ptr,
572
574 // In example, lets do a simple linear elastic material, so we can verify the tangent matrix
575 generic_physical_equations_ptr->hookEvaluateVariable =
577 generic_physical_equations_ptr->hookEvaluateDerivatives =
579 generic_physical_equations_ptr->hookUpdateState =
581
582 CHKERR generic_physical_equations_ptr->getOptions(&mField);
583 CHKERR generic_physical_equations_ptr->recordTape();
584
585 // That adds material to meta material models
586 auto &material_map = getMetaPiolaResponseMap(
587 boost::static_pointer_cast<MatOps::MatPiolaResponse>(
589 material_map[generic_physical_equations_ptr->tAg] =
590 boost::static_pointer_cast<MatOps::MatPiolaResponse>(
591 generic_physical_equations_ptr);
592 physicalEquationsPtr->tAg = generic_physical_equations_ptr->tAg;
593 }
594 #endif // WITH_ADOL_C_GENERIC_ELASTIC
595
596 #ifdef WITH_ADOL_C_SIMPLE_DAMAGE
597 {
598 auto generic_physical_equations_ptr =
600 modelType>(
602 "GenericElasticSimpleDamage"));
603
605 mField, boost::dynamic_pointer_cast<MatOps::GenericElastic>(
606 generic_physical_equations_ptr));
607
608 CHKERR generic_physical_equations_ptr->getOptions(&mField);
609 CHKERR generic_physical_equations_ptr->recordTape();
610
611 // That adds deamge model to meta material models
612 auto &material_map = getMetaPiolaResponseMap(
613 boost::static_pointer_cast<MatOps::MatPiolaResponse>(
615 material_map[generic_physical_equations_ptr->tAg] =
616 boost::static_pointer_cast<MatOps::MatPiolaResponse>(
617 generic_physical_equations_ptr);
618 physicalEquationsPtr->tAg = generic_physical_equations_ptr->tAg;
619 }
620 #endif // WITH_ADOL_C_SIMPLE_DAMAGE
621
623 CHKERR physicalEquationsPtr->getOptions(&mField);
624 CHKERR physicalEquationsPtr->recordTape();
625 }
626
627 if (!physicalHuHuPtr && !mField.getInterface<MeshsetsManager>()
628 ->getCubitMeshsetPtr(std::regex("MAT_HUHU(.*)"))
629 .empty()) {
630 const int tag_hu_hu = MatOps::MatOpsTagsRegistry::setTagName("HuHU");
632 MatOps::createMatOpsPhysicalEquationsPtr<MatOps::HUHU, modelType>(
633 MatOps::createMatOpsDataPtr(), tag_hu_hu);
634 CHKERR physicalHuHuPtr->getOptions(&mField);
635 CHKERR physicalHuHuPtr->recordTape();
636 }
637 #endif // WITH_ADOL_C_UMAT
638
639 auto add_domain_ops_lhs = [&](auto &pip) {
641 CHKERR AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(pip, {H1},
642 "GEOMETRY");
645 template opLhsFactory<PETSC, GAUSS, DomainEleOp>(
646 mField, pip, "U", physicalEquationsPtr);
647 }
648 if (physicalHuHuPtr) {
650 template opLhsFactory<PETSC, GAUSS, DomainEleOp>(
651 mField, pip, simple->getDomainFEName(), "U", physicalHuHuPtr);
652 }
654 };
655
656 auto add_domain_ops_rhs = [&](auto &pip) {
658 CHKERR AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(pip, {H1},
659 "GEOMETRY");
662 template opRhsFactory<PETSC, GAUSS, DomainEleOp>(
663 mField, pip, "U", physicalEquationsPtr);
664 }
665 if (physicalHuHuPtr) {
667 template opRhsFactory<PETSC, GAUSS, DomainEleOp>(
668 mField, pip, simple->getDomainFEName(), "U", physicalHuHuPtr);
669 }
671 };
672
673 auto add_domain_ops_update = [&](auto &pip) {
675 CHKERR AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(pip, {H1},
676 "GEOMETRY");
680 }
682 };
683
684 CHKERR add_domain_ops_lhs(pipeline_mng->getOpDomainLhsPipeline());
685 CHKERR add_domain_ops_rhs(pipeline_mng->getOpDomainRhsPipeline());
686
687 updateFe = boost::make_shared<DomainEle>(mField);
688 updateFe->getRuleHook = integration_rule;
689 CHKERR add_domain_ops_update(updateFe->getOpPtrVector());
690
691 CHKERR add_domain_ops_rhs(pipeline_mng->getOpEvaluationPipeline());
692 auto &domain_reaction_fe = pipeline_mng->getEvaluationFE();
693 domain_reaction_fe->postProcessHook =
694 EssentialPreProcReaction<DisplacementCubitBcData>(mField,
695 domain_reaction_fe);
696
697 PetscBool post_proc_vol;
698 PetscBool post_proc_skin;
699
700 if constexpr (SPACE_DIM == 2) {
701 post_proc_vol = PETSC_TRUE;
702 post_proc_skin = PETSC_FALSE;
703 } else {
704 post_proc_vol = PETSC_FALSE;
705 post_proc_skin = PETSC_TRUE;
706 }
707
708 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-post_proc_vol",
709 &post_proc_vol, PETSC_NULLPTR);
710 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-post_proc_skin",
711 &post_proc_skin, PETSC_NULLPTR);
712
713 // Setup postprocessing
714 auto create_post_proc_fe = [&]() {
715 using OpPPMap = OpPostProcMapInMoab<SPACE_DIM, SPACE_DIM>;
716
717 auto post_proc_ele_domain = [&](auto &pip_domain) {
719 CHKERR AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(pip_domain, {H1},
720 "GEOMETRY");
724 }
726 };
727
728 auto post_proc_map = [&](auto &pip, auto u_ptr) {
731 auto grad_ptr =
732 physicalEquationsPtr->matOpsDataPtr->getCommonDataPtr("grad");
733 auto first_piola_ptr =
734 physicalEquationsPtr->matOpsDataPtr->getCommonDataPtr("P");
735 pip->getOpPtrVector().push_back(new OpPPMap(pip->getPostProcMesh(),
736 pip->getMapGaussPts(), {},
737 {{"U", u_ptr}}, {}, {}));
738 pip->getOpPtrVector().push_back(
739 new OpPostProcMapInMoab<MAT_DIM, MAT_DIM>(
740 pip->getPostProcMesh(), pip->getMapGaussPts(), {}, {},
741 {{"GRAD", grad_ptr}, {"FIRST_PIOLA", first_piola_ptr}}, {}));
742 }
744 };
745
746 auto push_post_proc_bdy = [&](auto &pip_bdy) {
747 if (post_proc_skin == PETSC_FALSE)
748 return boost::shared_ptr<PostProcEleBdy>();
749 auto simple = mField.getInterface<Simple>();
750 auto domain_fe_name = simple->getDomainFEName();
751 auto u_ptr = boost::make_shared<MatrixDouble>();
752 pip_bdy->getOpPtrVector().push_back(
753 new OpCalculateVectorFieldValues<SPACE_DIM>("U", u_ptr));
754 auto op_loop_side =
755 new OpLoopSide<SideEle>(mField, domain_fe_name, SPACE_DIM);
756 CHKERR post_proc_ele_domain(op_loop_side->getOpPtrVector());
757 pip_bdy->getOpPtrVector().push_back(op_loop_side);
758 CHKERR post_proc_map(pip_bdy, u_ptr);
759 return pip_bdy;
760 };
761
762 auto push_post_proc_domain = [&](auto &pip_domain) {
763 if (post_proc_vol == PETSC_FALSE)
764 return boost::shared_ptr<PostProcEleDomain>();
765 auto u_ptr = boost::make_shared<MatrixDouble>();
766 pip_domain->getOpPtrVector().push_back(
767 new OpCalculateVectorFieldValues<SPACE_DIM>("U", u_ptr));
768 CHKERR post_proc_ele_domain(pip_domain->getOpPtrVector());
769
771 auto state_tags = physicalEquationsPtr->matOpsDataPtr->getStateTags();
772 if (!state_tags.empty()) {
773 MatOps::StateTags selected_state_tags;
774 MatOps::StateTags statev_tags;
775 selected_state_tags.reserve(state_tags.size());
776 statev_tags.reserve(state_tags.size());
777
778 constexpr auto statev_prefix = "UMAT_STATEV_";
779 constexpr auto statev_prefix_len = sizeof("UMAT_STATEV_") - 1;
780 auto get_statev_index = [&](const std::string &name) {
781 return std::stoi(name.substr(statev_prefix_len));
782 };
783
784 for (const auto &state_tag : state_tags) {
785 const auto &name = state_tag.name;
786
787 if (name == "UMAT_DFGRD0" || name == "UMAT_STRESS") {
788 selected_state_tags.push_back(state_tag);
789 continue;
790 }
791
792 if (name.rfind(statev_prefix, 0) == 0) {
793 statev_tags.push_back(state_tag);
794 }
795 }
796
797 std::sort(statev_tags.begin(), statev_tags.end(),
798 [&](const auto &lhs, const auto &rhs) {
799 return get_statev_index(lhs.name) <
800 get_statev_index(rhs.name);
801 });
802 if (statev_tags.size() > 10)
803 statev_tags.resize(10);
804 selected_state_tags.insert(selected_state_tags.end(),
805 statev_tags.begin(), statev_tags.end());
806
807 if (selected_state_tags.empty())
808 return pip_domain;
809
810 auto simple = mField.getInterface<Simple>();
811 int state_order = 2;
812 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-order", &state_order,
813 PETSC_NULLPTR);
814 auto op_loop_this = new OpLoopThis<DomainEle>(
815 mField, simple->getDomainFEName(), Sev::noisy);
816 op_loop_this->getThisFEPtr()->getRuleHook = integration_rule;
817 pip_domain->getOpPtrVector().push_back(op_loop_this);
818 CHKERR addTagDGProjectionOps<SPACE_DIM, SPACE_DIM>(
819 mField.get_moab(), pip_domain->getOpPtrVector(),
820 op_loop_this->getThisFEPtr()->getOpPtrVector(),
821 pip_domain->getPostProcMesh(), pip_domain->getMapGaussPts(),
822 selected_state_tags, state_order, approximationBase);
823 }
824 }
825
826 CHKERR post_proc_map(pip_domain, u_ptr);
827
828 return pip_domain;
829 };
830
831 auto post_proc_fe_domain = boost::make_shared<PostProcEleDomain>(mField);
832 auto post_proc_fe_bdy = boost::make_shared<PostProcEleBdy>(mField);
833
834 return std::make_pair(push_post_proc_domain(post_proc_fe_domain),
835 push_post_proc_bdy(post_proc_fe_bdy));
836 };
837
838 auto post_proc_pair = create_post_proc_fe();
839 postProcDomainFe = post_proc_pair.first;
840 postProcBdyFe = post_proc_pair.second;
841
842#else
843 SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
844 "ADOL-C support is not enabled. Please reconfigure with "
845 "-DWITH_ADOL_C=ON and recompile to use AdolC material model.");
846
847#endif // WITH_ADOL
849}
std::string name
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition acoustic.cpp:69
constexpr int SPACE_DIM
@ H1
continuous field
Definition definitions.h:85
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ 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.
auto integration_rule
MoFEMErrorCode configureSimpleDamage(MoFEM::Interface &m_field, boost::shared_ptr< MatOps::GenericElastic > physical_ptr)
@ MODEL_3D
Definition MatOps.hpp:234
@ MODEL_2D_PLANE_STRAIN
Definition MatOps.hpp:235
std::vector< StateTag > StateTags
Definition MatOps.hpp:21
std::map< int, boost::shared_ptr< MatPiolaResponse > > & getMetaPiolaResponseMap(boost::shared_ptr< MatPiolaResponse > meta_ptr)
boost::shared_ptr< PhysicalEquations > createMatOpsPhysicalEquationsPtr(boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag)
boost::shared_ptr< MatOpsData > createMatOpsDataPtr()
Definition MatOps.cpp:709
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
static constexpr int approx_order
static MoFEMErrorCode hookEvaluateVariable(boost::shared_ptr< MatOps::MatOpsData > mat_ops_data_ptr, int, EntityHandle, int)
static MoFEMErrorCode hookEvaluateDerivatives(boost::shared_ptr< MatOps::MatOpsData > mat_ops_data_ptr, int, EntityHandle, int)
static MoFEMErrorCode hookUpdateState(boost::shared_ptr< MatOps::MatOpsData >, int, EntityHandle, int)
static int setTagName(std::string name, int tag=-1)
Definition MatOps.cpp:29
virtual moab::Interface & get_moab()=0
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
FieldApproximationBase approximationBase
boost::shared_ptr< PostProcEleBdy > postProcBdyFe
boost::shared_ptr< MatOps::PhysicalEquations > physicalEquationsPtr
boost::shared_ptr< PostProcEleDomain > postProcDomainFe
boost::shared_ptr< MatOps::PhysicalEquations > physicalHuHuPtr
boost::shared_ptr< DomainEle > updateFe

◆ assembleSystemHencky()

MoFEMErrorCode NonlinearElasticExample::assembleSystemHencky ( )
protected

[Boundary condition]

[Push operators to pipeline]

Examples
mofem/tutorials/vec-2_nonlinear_elasticity/src/NonlinearElasticExample.hpp, and mofem/tutorials/vec-9_arc_length/src/ArcLengthExample.hpp.

Definition at line 334 of file NonlinearElasticExample.hpp.

334 {
336
337 auto *pipeline_mng = mField.getInterface<PipelineManager>();
338
339 auto integration_rule = [](int, int, int approx_order) {
340 return 2 * (approx_order - 1) + 1;
341 };
342
343 CHKERR pipeline_mng->setDomainRhsIntegrationRule(integration_rule);
344 CHKERR pipeline_mng->setDomainLhsIntegrationRule(integration_rule);
345 CHKERR pipeline_mng->setBoundaryRhsIntegrationRule(integration_rule);
346 CHKERR pipeline_mng->setEvaluationIntegrationRule(integration_rule);
347
348 auto add_domain_ops_lhs = [&](auto &pip) {
350 CHKERR AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(pip, {H1},
351 "GEOMETRY");
352 CHKERR
353 HenckyOps::opFactoryDomainLhs<SPACE_DIM, PETSC, GAUSS, DomainEleOp>(
354 mField, pip, "U", "MAT_ELASTIC", Sev::inform);
356 };
357
358 auto add_domain_ops_rhs = [&](auto &pip) {
360 CHKERR AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(pip, {H1},
361 "GEOMETRY");
362 CHKERR
363 HenckyOps::opFactoryDomainRhs<SPACE_DIM, PETSC, GAUSS, DomainEleOp>(
364 mField, pip, "U", "MAT_ELASTIC", Sev::inform);
366 };
367
368 CHKERR add_domain_ops_lhs(pipeline_mng->getOpDomainLhsPipeline());
369 CHKERR add_domain_ops_rhs(pipeline_mng->getOpDomainRhsPipeline());
370
371 // push operators to evaluation pipeline
372 CHKERR add_domain_ops_rhs(pipeline_mng->getOpEvaluationPipeline());
373 auto &domain_reaction_fe = pipeline_mng->getEvaluationFE();
374 domain_reaction_fe->postProcessHook =
375 EssentialPreProcReaction<DisplacementCubitBcData>(mField,
376 domain_reaction_fe);
377
378 PetscBool post_proc_vol;
379 PetscBool post_proc_skin;
380
381 if constexpr (SPACE_DIM == 2) {
382 post_proc_vol = PETSC_TRUE;
383 post_proc_skin = PETSC_FALSE;
384 } else {
385 post_proc_vol = PETSC_FALSE;
386 post_proc_skin = PETSC_TRUE;
387 }
388
389 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-post_proc_vol",
390 &post_proc_vol, PETSC_NULLPTR);
391 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-post_proc_skin",
392 &post_proc_skin, PETSC_NULLPTR);
393
394 // Setup postprocessing
395 auto create_post_proc_fe = [&]() {
396 auto post_proc_ele_domain = [this](auto &pip_domain) {
397 CHKERR AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(pip_domain, {H1},
398 "GEOMETRY");
399 auto common_ptr = commonDataFactory<SPACE_DIM, GAUSS, DomainEleOp>(
400 mField, pip_domain, "U", "MAT_ELASTIC", Sev::inform);
401 return common_ptr;
402 };
403
404 auto post_proc_map = [&](auto &pip, auto u_ptr, auto common_ptr) {
406
407 using OpPPMap = OpPostProcMapInMoab<SPACE_DIM, SPACE_DIM>;
408
409 pip->getOpPtrVector().push_back(
410
411 new OpPPMap(pip->getPostProcMesh(), pip->getMapGaussPts(), {},
412 {{"U", u_ptr}},
413 {{"GRAD", common_ptr->matGradPtr},
414 {"FIRST_PIOLA", common_ptr->getMatFirstPiolaStress()}},
415 {}));
417 };
418
419 auto push_post_proc_bdy = [&](auto &pip_bdy) {
420 if (post_proc_skin == PETSC_FALSE)
421 return boost::shared_ptr<PostProcEleBdy>();
422 auto simple = mField.getInterface<Simple>();
423 auto domain_fe_name = simple->getDomainFEName();
424 auto u_ptr = boost::make_shared<MatrixDouble>();
425 pip_bdy->getOpPtrVector().push_back(
426 new OpCalculateVectorFieldValues<SPACE_DIM>("U", u_ptr));
427 auto op_loop_side =
428 new OpLoopSide<SideEle>(mField, domain_fe_name, SPACE_DIM);
429 auto common_ptr = post_proc_ele_domain(op_loop_side->getOpPtrVector());
430 pip_bdy->getOpPtrVector().push_back(op_loop_side);
431 CHKERR post_proc_map(pip_bdy, u_ptr, common_ptr);
432 return pip_bdy;
433 };
434
435 auto push_post_proc_domain = [&](auto &pip_domain) {
436 if (post_proc_vol == PETSC_FALSE)
437 return boost::shared_ptr<PostProcEleDomain>();
438
439 auto u_ptr = boost::make_shared<MatrixDouble>();
440 pip_domain->getOpPtrVector().push_back(
441 new OpCalculateVectorFieldValues<SPACE_DIM>("U", u_ptr));
442 auto common_ptr = post_proc_ele_domain(pip_domain->getOpPtrVector());
443
444 CHKERR post_proc_map(pip_domain, u_ptr, common_ptr);
445
446 return pip_domain;
447 };
448
449 auto post_proc_fe_domain = boost::make_shared<PostProcEleDomain>(mField);
450 auto post_proc_fe_bdy = boost::make_shared<PostProcEleBdy>(mField);
451
452 return std::make_pair(push_post_proc_domain(post_proc_fe_domain),
453 push_post_proc_bdy(post_proc_fe_bdy));
454 };
455
456 auto post_proc_pair = create_post_proc_fe();
457 postProcDomainFe = post_proc_pair.first;
458 postProcBdyFe = post_proc_pair.second;
459
461}

◆ boundaryCondition()

MoFEMErrorCode NonlinearElasticExample::boundaryCondition ( )
protected

[Set up problem]

[Boundary condition]

[Define gravity vector]

Examples
mofem/tutorials/vec-2_nonlinear_elasticity/src/NonlinearElasticExample.hpp, and mofem/tutorials/vec-9_arc_length/src/ArcLengthExample.hpp.

Definition at line 303 of file NonlinearElasticExample.hpp.

303 {
305 auto *pipeline_mng = mField.getInterface<PipelineManager>();
306 auto simple = mField.getInterface<Simple>();
307 auto bc_mng = mField.getInterface<BcManager>();
308 auto time_scale = boost::make_shared<ExampleTimeScale>();
309
310 CHKERR BoundaryNaturalBC::AddFluxToPipeline<OpForce>::add(
311 pipeline_mng->getOpBoundaryRhsPipeline(), mField, "U", {time_scale},
312 "FORCE", "PRESSURE", Sev::inform);
313
314 //! [Define gravity vector]
315 CHKERR DomainNaturalBC::AddFluxToPipeline<OpBodyForce>::add(
316 pipeline_mng->getOpDomainRhsPipeline(), mField, "U", {time_scale},
317 "BODY_FORCE", Sev::inform);
318
319 // Essential BC
320 CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), "REMOVE_X",
321 "U", 0, 0);
322 CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), "REMOVE_Y",
323 "U", 1, 1);
324 CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), "REMOVE_Z",
325 "U", 2, 2);
326 CHKERR bc_mng->pushMarkDOFsOnEntities<DisplacementCubitBcData>(
327 simple->getProblemName(), "U");
328
330}

◆ checkResults()

MoFEMErrorCode NonlinearElasticExample::checkResults ( )
protected

[Postprocessing results]

[Check]

Examples
mofem/tutorials/vec-2_nonlinear_elasticity/src/NonlinearElasticExample.hpp.

Definition at line 1261 of file NonlinearElasticExample.hpp.

1261 {
1263 auto testing = mField.getInterface<TestingInterface>();
1264
1265 // -test_solution_norm <value> both supplies the golden value and is the
1266 // trigger for this check, so it is read right here, where it is used,
1267 // rather than through addTestCommandLine's own "-test_nb"/"-test_name"
1268 // selectors, and rather than a class member set earlier in runProblem().
1269 PetscReal expected_solution_norm = 0;
1270 PetscBool test_solution_norm = PETSC_FALSE;
1271 CHKERR PetscOptionsGetReal(nullptr, "", "-test_solution_norm",
1272 &expected_solution_norm, &test_solution_norm);
1273 if (test_solution_norm) {
1274 CHKERR testing->addTest(1, "solution coefficient norm", [&]() {
1276 auto simple = mField.getInterface<Simple>();
1277 auto T = createDMVector(simple->getDM());
1278 CHKERR DMoFEMMeshToLocalVector(simple->getDM(), T, INSERT_VALUES,
1279 SCATTER_FORWARD);
1280 double nrm2;
1281 CHKERR VecNorm(T, NORM_2, &nrm2);
1282 MOFEM_LOG("EXAMPLE", Sev::verbose) << "Regression norm " << nrm2;
1283 CHKERR testing->checkValue<TestType::SCALAR>("solution coefficient norm",
1284 nrm2, expected_solution_norm,
1285 {1e-2, 0.});
1287 });
1288 }
1289
1290 CHKERR testing->runTests();
1292}
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
auto createDMVector(DM dm, RowColData rc=RowColData::COL)
Get smart vector from DM.
Definition DMMoFEM.hpp:1279
#define MOFEM_LOG(channel, severity)
Log.
PetscBool testing
PetscErrorCode PetscOptionsGetReal(PetscOptions *, const char pre[], const char name[], PetscReal *dval, PetscBool *set)

◆ filter_true_skin()

static auto NonlinearElasticExample::filter_true_skin ( MoFEM::Interface &  m_field,
Range &&  skin 
)
inlinestaticprotected
Examples
mofem/tutorials/vec-2_nonlinear_elasticity/src/NonlinearElasticExample.hpp.

Definition at line 102 of file NonlinearElasticExample.hpp.

102 {
103 Range boundary_ents;
104 ParallelComm *pcomm =
105 ParallelComm::get_pcomm(&m_field.get_moab(), MYPCOMM_INDEX);
106 CHK_MOAB_THROW(pcomm->filter_pstatus(skin,
107 PSTATUS_SHARED | PSTATUS_MULTISHARED,
108 PSTATUS_NOT, -1, &boundary_ents),
109 "filter_pstatus");
110 return boundary_ents;
111 };
FaceSet skin
#define MYPCOMM_INDEX
default communicator number PCOMM
#define CHK_MOAB_THROW(err, msg)
Check error code of MoAB function and throw MoFEM exception.

◆ get_skin()

static auto NonlinearElasticExample::get_skin ( MoFEM::Interface &  m_field,
Range  body_ents 
)
inlinestaticprotected

Definition at line 95 of file NonlinearElasticExample.hpp.

95 {
96 Skinner skin(&m_field.get_moab());
97 Range skin_ents;
98 CHK_MOAB_THROW(skin.find_skin(0, body_ents, false, skin_ents), "find_skin");
99 return skin_ents;
100 };

◆ gettingNorms()

MoFEMErrorCode NonlinearElasticExample::gettingNorms ( )
protected

[TS Solve]

[Getting norms]

Examples
mofem/tutorials/vec-2_nonlinear_elasticity/src/NonlinearElasticExample.hpp, and mofem/tutorials/vec-9_arc_length/src/ArcLengthExample.hpp.

Definition at line 1173 of file NonlinearElasticExample.hpp.

1173 {
1175
1176 auto simple = mField.getInterface<Simple>();
1177 auto dm = simple->getDM();
1178
1179 auto T = createDMVector(simple->getDM());
1180 CHKERR DMoFEMMeshToLocalVector(simple->getDM(), T, INSERT_VALUES,
1181 SCATTER_FORWARD);
1182 double nrm2;
1183 CHKERR VecNorm(T, NORM_2, &nrm2);
1184 MOFEM_LOG("EXAMPLE", Sev::inform) << "Solution norm " << nrm2;
1185
1186 auto post_proc_norm_fe = boost::make_shared<DomainEle>(mField);
1187
1188 auto post_proc_norm_rule_hook = [](int, int, int p) -> int { return 2 * p; };
1189 post_proc_norm_fe->getRuleHook = post_proc_norm_rule_hook;
1190
1191 CHKERR AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(
1192 post_proc_norm_fe->getOpPtrVector(), {H1}, "GEOMETRY");
1193
1194 enum NORMS { U_NORM_L2 = 0, PIOLA_NORM, LAST_NORM };
1195 auto norms_vec =
1197 (mField.get_comm_rank() == 0) ? LAST_NORM : 0, LAST_NORM);
1198 CHKERR VecZeroEntries(norms_vec);
1199
1200 auto u_ptr = boost::make_shared<MatrixDouble>();
1201 post_proc_norm_fe->getOpPtrVector().push_back(
1202 new OpCalculateVectorFieldValues<SPACE_DIM>("U", u_ptr));
1203
1204 post_proc_norm_fe->getOpPtrVector().push_back(
1205 new OpCalcNormL2Tensor1<SPACE_DIM>(u_ptr, norms_vec, U_NORM_L2));
1206
1207 if (useAdolcMaterial == PETSC_TRUE) {
1208#ifdef WITH_ADOL_C
1211 opPostProcFactory(mField, post_proc_norm_fe->getOpPtrVector(), "U",
1213 auto m_P = physicalEquationsPtr->matOpsDataPtr->getCommonDataPtr("P");
1214 post_proc_norm_fe->getOpPtrVector().push_back(
1215 new OpCalcNormL2Tensor2<MAT_DIM, MAT_DIM>(m_P, norms_vec,
1216 PIOLA_NORM));
1217 }
1218#else
1219 SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
1220 "ADOL-C support is not enabled. Please reconfigure with "
1221 "-DWITH_ADOL_C=ON and recompile to use AdolC material model.");
1222#endif
1223 } else {
1224 auto common_ptr = commonDataFactory<SPACE_DIM, GAUSS, DomainEleOp>(
1225 mField, post_proc_norm_fe->getOpPtrVector(), "U", "MAT_ELASTIC",
1226 Sev::inform);
1227 post_proc_norm_fe->getOpPtrVector().push_back(
1228 new OpCalcNormL2Tensor2<SPACE_DIM, SPACE_DIM>(
1229 common_ptr->getMatFirstPiolaStress(), norms_vec, PIOLA_NORM));
1230 }
1231
1232 CHKERR DMoFEMLoopFiniteElements(dm, simple->getDomainFEName(),
1233 post_proc_norm_fe);
1234
1235 CHKERR VecAssemblyBegin(norms_vec);
1236 CHKERR VecAssemblyEnd(norms_vec);
1237
1238 MOFEM_LOG_CHANNEL("SELF"); // Clear channel from old tags
1239 if (mField.get_comm_rank() == 0) {
1240 const double *norms;
1241 CHKERR VecGetArrayRead(norms_vec, &norms);
1242 MOFEM_TAG_AND_LOG("SELF", Sev::inform, "example")
1243 << "norm_u: " << std::scientific << std::sqrt(norms[U_NORM_L2]);
1244 MOFEM_TAG_AND_LOG("SELF", Sev::inform, "example")
1245 << "norm_piola: " << std::scientific << std::sqrt(norms[PIOLA_NORM]);
1246 CHKERR VecRestoreArrayRead(norms_vec, &norms);
1247 }
1248
1250}
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
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
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
auto createVectorMPI(MPI_Comm comm, PetscInt n, PetscInt N)
Create MPI Vector.
virtual MPI_Comm & get_comm() const =0
virtual int get_comm_rank() const =0

◆ opTest()

MoFEMErrorCode NonlinearElasticExample::opTest ( )
protected

[Push operators to pipeline]

Examples
mofem/tutorials/vec-2_nonlinear_elasticity/src/NonlinearElasticExample.hpp, and mofem/tutorials/vec-9_arc_length/src/ArcLengthExample.hpp.

Definition at line 464 of file NonlinearElasticExample.hpp.

464 {
466
467 // get operators tester
468 auto simple = mField.getInterface<Simple>();
469 auto opt = mField.getInterface<OperatorsTester>(); // get interface to
470 // OperatorsTester
471 auto pip = mField.getInterface<PipelineManager>(); // get interface to
472 // pipeline manager
473
474 constexpr double eps = 1e-9;
475
476 auto x = opt->setRandomFields(simple->getDM(), {
477
478 {"U", {-1e-6, 1e-6}}
479
480 });
481
482 auto dot_x = opt->setRandomFields(simple->getDM(), {
483
484 {"U", {-1, 1}}
485
486 });
487
488 auto diff_x = opt->setRandomFields(simple->getDM(), {
489
490 {"U", {-1, 1}}
491
492 });
493
494 auto test_domain_ops = [&](auto fe_name, auto lhs_pipeline,
495 auto rhs_pipeline) {
497
498 auto diff_res = opt->checkCentralFiniteDifference(
499 simple->getDM(), fe_name, rhs_pipeline, lhs_pipeline, x, dot_x,
500 SmartPetscObj<Vec>(), diff_x, 0, 0.5, eps);
501
502 // Calculate norm of difference between directional derivative calculated
503 // from finite difference, and tangent matrix.
504 double fnorm;
505 CHKERR VecNorm(diff_res, NORM_2, &fnorm);
506 MOFEM_LOG_C("EXAMPLE", Sev::inform,
507 "Test consistency of tangent matrix %3.4e", fnorm);
508
509 CHKERR mField.getInterface<TestingInterface>()
510 ->checkError<TestType::DERIVATIVE>("domain tangent", fnorm, 0.,
511 {1e-5, 0.});
512
514 };
515
516 MOFEM_LOG("EXAMPLE", Sev::inform)
517 << "Test operators with finite difference of directional "
518 "derivative";
519 CHKERR test_domain_ops(simple->getDomainFEName(), pip->getDomainLhsFE(),
520 pip->getDomainRhsFE());
521
523}
#define MOFEM_LOG_C(channel, severity, format,...)
static const double eps

◆ outputResults()

MoFEMErrorCode NonlinearElasticExample::outputResults ( )
protected

◆ readMesh()

MoFEMErrorCode NonlinearElasticExample::readMesh ( )
protected

[Run problem]

[Read mesh]

Examples
mofem/tutorials/vec-2_nonlinear_elasticity/src/NonlinearElasticExample.hpp, and mofem/tutorials/vec-9_arc_length/src/ArcLengthExample.hpp.

Definition at line 143 of file NonlinearElasticExample.hpp.

143 {
145 auto simple = mField.getInterface<Simple>();
146 CHKERR simple->getOptions();
147 CHKERR simple->loadFile();
148 CHKERR mField.getInterface<MeshsetsManager>()->setMeshsetFromFile();
150}

◆ runProblem()

MoFEMErrorCode NonlinearElasticExample::runProblem ( )

[Run problem]

Examples
mofem/tutorials/vec-2_nonlinear_elasticity/src/NonlinearElasticExample.hpp.

Definition at line 115 of file NonlinearElasticExample.hpp.

115 {
120
121 PetscBool test_op = PETSC_FALSE;
122 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-test_op", &test_op,
123 PETSC_NULLPTR);
124
125 if (useAdolcMaterial == PETSC_TRUE) {
127 } else {
129 }
130
131 if (test_op == PETSC_TRUE) {
132 CHKERR opTest();
133 }
134 CHKERR TsSolve();
139}
MoFEMErrorCode setupProblem()
[Read mesh]
MoFEMErrorCode readMesh()
[Run problem]
MoFEMErrorCode assembleSystemHencky()
[Boundary condition]
MoFEMErrorCode boundaryCondition()
[Set up problem]
MoFEMErrorCode opTest()
[Push operators to pipeline]
MoFEMErrorCode TsSolve()
[TS Solve]
MoFEMErrorCode outputResults()
[Getting norms]
MoFEMErrorCode checkResults()
[Postprocessing results]
MoFEMErrorCode gettingNorms()
[TS Solve]

◆ setupProblem()

MoFEMErrorCode NonlinearElasticExample::setupProblem ( )
protected

[Read mesh]

[Set up problem]

Examples
mofem/tutorials/vec-2_nonlinear_elasticity/src/NonlinearElasticExample.hpp, and mofem/tutorials/vec-9_arc_length/src/ArcLengthExample.hpp.

Definition at line 154 of file NonlinearElasticExample.hpp.

154 {
156 Simple *simple = mField.getInterface<Simple>();
157
158 enum bases { AINSWORTH, DEMKOWICZ, LASBASETOPT };
159 const char *list_bases[LASBASETOPT] = {"ainsworth", "demkowicz"};
160 PetscInt choice_base_value = AINSWORTH;
161 CHKERR PetscOptionsGetEList(PETSC_NULLPTR, NULL, "-base", list_bases,
162 LASBASETOPT, &choice_base_value, PETSC_NULLPTR);
163
164 switch (choice_base_value) {
165 case AINSWORTH:
167 MOFEM_LOG("WORLD", Sev::inform)
168 << "Set AINSWORTH_LEGENDRE_BASE for displacements";
169 break;
170 case DEMKOWICZ:
172 MOFEM_LOG("WORLD", Sev::inform)
173 << "Set DEMKOWICZ_JACOBI_BASE for displacements";
174 break;
175 default:
177 break;
178 }
179
180 // Add field
181 CHKERR simple->addDomainField("U", H1, approximationBase, SPACE_DIM);
182 CHKERR simple->addBoundaryField("U", H1, approximationBase, SPACE_DIM);
183 CHKERR simple->addDataField("GEOMETRY", H1, approximationBase, SPACE_DIM);
184 int order = 2;
185 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-order", &order, PETSC_NULLPTR);
186 CHKERR simple->setFieldOrder("U", order);
187 CHKERR simple->setFieldOrder("GEOMETRY", 2);
188 CHKERR simple->setUp();
189
190 auto project_ho_geometry = [&]() {
191 Projection10NodeCoordsOnField ent_method(mField, "GEOMETRY");
192 return mField.loop_dofs("GEOMETRY", ent_method);
193 };
194 CHKERR project_ho_geometry();
195
196 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-use_adolc_material",
197 &useAdolcMaterial, PETSC_NULLPTR);
198#ifndef WITH_ADOL_C
199 if (useAdolcMaterial == PETSC_TRUE) {
200 SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
201 "ADOL-C support is not enabled. Please reconfigure with "
202 "-DWITH_ADOL_C=ON and recompile to use AdolC material model.");
203 }
204#endif
205 if (useAdolcMaterial == PETSC_TRUE) {
206 MOFEM_LOG("WORLD", Sev::inform) << "Use ADOL-C material model";
207 } else {
208 MOFEM_LOG("WORLD", Sev::inform) << "Use Hencky material model";
209 }
210
211 auto tag_meshest = [&]() {
213
214 auto set_block = [&](auto name, int dim) {
215 std::map<int, Range> map;
216 auto set_tag_impl = [&](auto name) {
218 auto mesh_mng = mField.getInterface<MeshsetsManager>();
219 auto bcs = mesh_mng->getCubitMeshsetPtr(
220
221 std::regex((boost::format("%s(.*)") % name).str())
222
223 );
224 std::map<int, int> ids_map;
225 int bit_id = 1;
226 for (auto bc : bcs) {
227 int id = bc->getMeshsetId();
228 ids_map[id] = bit_id;
229 bit_id <<= 1;
230 }
231 for (auto bc : bcs) {
232 Range r;
233 CHKERR bc->getMeshsetIdEntitiesByDimension(mField.get_moab(), dim, r,
234 true);
235 map[ids_map[bc->getMeshsetId()]] = r;
236 MOFEM_LOG("EXAMPLE", Sev::inform)
237 << "Block " << name << " id " << bc->getMeshsetId() << " : "
238 << ids_map[bc->getMeshsetId()] << " has " << r.size()
239 << " entities";
240 }
242 };
243
244 CHKERR set_tag_impl(name);
245
246 return std::make_pair(name, map);
247 };
248
249 auto set_skin = [&](auto &&map) {
250 for (auto &m : map.second) {
251 auto s = filter_true_skin(mField, get_skin(mField, m.second));
252 m.second.swap(s);
253 MOFEM_LOG("EXAMPLE", Sev::inform)
254 << "Skin for block " << map.first << " id " << m.first << " has "
255 << m.second.size() << " entities";
256 }
257 return map;
258 };
259
260 auto set_tag = [&](auto &&map) {
261 Tag th;
262 auto name = map.first;
263 int def_val[] = {-1};
264 CHK_MOAB_THROW(mField.get_moab().tag_get_handle(
265 name, 1, MB_TYPE_INTEGER, th,
266 MB_TAG_SPARSE | MB_TAG_CREAT, def_val),
267 "create tag");
268 for (auto &m : map.second) {
269 int id = m.first;
270 for (auto ent : m.second) {
271 int current_id;
273 mField.get_moab().tag_get_data(th, &ent, 1, &current_id),
274 "get tag data");
275 if (current_id != -1) {
276 id |= current_id;
277 }
278 CHK_MOAB_THROW(mField.get_moab().tag_set_data(th, &ent, 1, &id),
279 "set tag data");
280 }
281 }
282 return th;
283 };
284
285 if (SPACE_DIM == 3) {
286 listTagsToTransfer.push_back(set_tag(set_block("MAT_", 3)));
287 listTagsToTransfer.push_back(set_tag(set_skin(set_block("MAT_", 3))));
288 } else {
289 listTagsToTransfer.push_back(set_tag(set_block("MAT_", 2)));
290 }
291
293 };
294
295 CHKERR tag_meshest();
296
298}
@ LASTBASE
Definition definitions.h:69
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition definitions.h:60
@ DEMKOWICZ_JACOBI_BASE
Definition definitions.h:66
constexpr int order
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.
PetscErrorCode PetscOptionsGetEList(PetscOptions *, const char pre[], const char name[], const char *const *list, PetscInt next, PetscInt *value, PetscBool *set)
int r
Definition sdf.py:205
FTensor::Index< 'm', 3 > m
std::vector< Tag > listTagsToTransfer
list of tags to transfer to postprocessor
static auto get_skin(MoFEM::Interface &m_field, Range body_ents)
static auto filter_true_skin(MoFEM::Interface &m_field, Range &&skin)

◆ TsSolve()

MoFEMErrorCode NonlinearElasticExample::TsSolve ( )
protected

[TS Solve]

Examples
mofem/tutorials/vec-2_nonlinear_elasticity/src/NonlinearElasticExample.hpp.

Definition at line 852 of file NonlinearElasticExample.hpp.

852 {
854 auto *simple = mField.getInterface<Simple>();
855 auto *pipeline_mng = mField.getInterface<PipelineManager>();
856
857 auto dm = simple->getDM();
858 auto ts = pipeline_mng->createTSIM();
859
860 auto add_extra_finite_elements_to_solver_pipelines = [&]() {
862
863 auto pre_proc_ptr = boost::make_shared<FEMethod>();
864 auto post_proc_rhs_ptr = boost::make_shared<FEMethod>();
865 auto post_proc_lhs_ptr = boost::make_shared<FEMethod>();
866
867 auto time_scale = boost::make_shared<ExampleTimeScale>();
868
869 auto get_bc_hook_rhs = [this, pre_proc_ptr, time_scale]() {
871 CHKERR EssentialPreProc<DisplacementCubitBcData>(mField, pre_proc_ptr,
872 {time_scale}, false)();
874 };
875
876 pre_proc_ptr->preProcessHook = get_bc_hook_rhs;
877
878 auto get_post_proc_hook_rhs = [this, post_proc_rhs_ptr]() {
880 CHKERR EssentialPreProcReaction<DisplacementCubitBcData>(
881 mField, post_proc_rhs_ptr, nullptr, Sev::verbose)();
882 CHKERR EssentialPostProcRhs<DisplacementCubitBcData>(
883 mField, post_proc_rhs_ptr, 1.)();
885 };
886 auto get_post_proc_hook_lhs = [this, post_proc_lhs_ptr]() {
888 CHKERR EssentialPostProcLhs<DisplacementCubitBcData>(
889 mField, post_proc_lhs_ptr, 1.)();
891 };
892 post_proc_rhs_ptr->postProcessHook = get_post_proc_hook_rhs;
893 post_proc_lhs_ptr->postProcessHook = get_post_proc_hook_lhs;
894
895 // This is low level pushing finite elements (pipelines) to solver
896 auto ts_ctx_ptr = getDMTsCtx(simple->getDM());
897 ts_ctx_ptr->getPreProcessIFunction().push_front(pre_proc_ptr);
898 ts_ctx_ptr->getPreProcessIJacobian().push_front(pre_proc_ptr);
899 ts_ctx_ptr->getPostProcessIFunction().push_back(post_proc_rhs_ptr);
900 ts_ctx_ptr->getPostProcessIJacobian().push_back(post_proc_lhs_ptr);
902 };
903
904 // Add extra finite elements to SNES solver pipelines to resolve essential
905 // boundary conditions
906 CHKERR add_extra_finite_elements_to_solver_pipelines();
907
908 auto create_monitor_fe = [dm](auto &&post_proc_fe) {
909 return boost::make_shared<Monitor>(dm.get(), post_proc_fe);
910 };
911
912 // Set monitor which postprocessing results and saves them to the hard drive
913 boost::shared_ptr<FEMethod> null_fe;
915 CHKERR postProcDomainFe->setTagsToTransfer(
916 std::vector<Tag>(listTagsToTransfer));
917 if (postProcBdyFe)
918 CHKERR postProcBdyFe->setTagsToTransfer(
919 std::vector<Tag>(listTagsToTransfer));
920 auto monitor_ptr =
921 create_monitor_fe(std::make_pair(postProcDomainFe, postProcBdyFe));
922 CHKERR DMMoFEMTSSetMonitor(dm, ts, simple->getDomainFEName(), null_fe,
923 null_fe, monitor_ptr);
924
925 // Set time solver
926 double ftime = 1;
927 CHKERR TSSetMaxTime(ts, ftime);
928 CHKERR TSSetExactFinalTime(ts, TS_EXACTFINALTIME_MATCHSTEP);
929
930 auto B = createDMMatrix(dm);
931 CHKERR TSSetI2Jacobian(ts, B, B, PETSC_NULLPTR, PETSC_NULLPTR);
932 auto D = createDMVector(simple->getDM());
933 CHKERR TSSetSolution(ts, D);
934 CHKERR TSSetFromOptions(ts);
935
936 PetscBool test_steps = PETSC_FALSE;
937 PetscBool test_piola_stress = PETSC_FALSE;
938 CHKERR PetscOptionsGetBool(nullptr, "", "-test_piola_stress",
939 &test_piola_stress, nullptr);
940 CHKERR PetscOptionsGetBool(nullptr, "", "-test_step_monitor", &test_steps,
941 nullptr);
942
943 const bool check_steps = test_steps || test_piola_stress;
944
945 auto check_piola_stress = [this](PetscReal time) {
947 auto simple = mField.getInterface<Simple>();
948
953
954 auto displacement_ptr = boost::make_shared<MatrixDouble>();
955
956 // These homogeneous cube fixtures prescribe Fzz = 1 - 0.1 * load time.
957 const double applied_F_zz = 1. - 0.1 * time;
958
959 t_P_expected(i, J) = 0.;
960 auto set_linear_elastic_piola = [&](const double strain_zz,
961 const double d_strain_d_F_zz) {
962 constexpr double E = 1.;
963 constexpr double nu = 0.3;
964 const double lambda = E * nu / ((1. + nu) * (1. - 2. * nu));
965 const double mu = E / (2. * (1. + nu));
966 for (int d = 0; d != SPACE_DIM - 1; ++d)
967 t_P_expected(d, d) = lambda * strain_zz;
968 t_P_expected(SPACE_DIM - 1, SPACE_DIM - 1) =
969 (lambda + 2. * mu) * strain_zz * d_strain_d_F_zz;
970 };
971
972#ifndef AXISYMMETRIC
973 auto set_neohookean_piola = [&](const double F_zz, const double J) {
974 constexpr double c10 = 1.;
975 constexpr double K = 1.;
976 double I1 = (SPACE_DIM - 1) + F_zz * F_zz;
977 if constexpr (SPACE_DIM == 2)
978 I1 += 1.; // Plane strain has F33 = 1.
979 const double J_to_minus_two_thirds = std::pow(J, -2. / 3.);
980 for (int d = 0; d != SPACE_DIM; ++d) {
981 const double F_dd = d == SPACE_DIM - 1 ? F_zz : 1.;
982 const double inv_F_dd = 1. / F_dd;
983 t_P_expected(d, d) =
984 2. * c10 * J_to_minus_two_thirds * (F_dd - (I1 / 3.) * inv_F_dd) +
985 K * J * (J - 1.) * inv_F_dd;
986 }
987 };
988
989#endif
990
991 auto eval_piola_at_point = [&](boost::shared_ptr<MatrixDouble> &mat_p,
992 std::array<double, 3> field_eval_coords) {
994 CHKERR mField.getInterface<TestingInterface>()
995 ->addFieldEvaluator<SPACE_DIM>(
996 simple->getProblemName(), simple->getDomainFEName(),
997 field_eval_coords, [&](auto &pipeline) {
999 CHKERR AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(
1000 pipeline, {H1}, "GEOMETRY");
1001
1002 pipeline.push_back(new OpCalculateVectorFieldValues<SPACE_DIM>(
1003 "U", displacement_ptr));
1004
1005 if (useAdolcMaterial == PETSC_FALSE) {
1006 auto common_ptr =
1007 commonDataFactory<SPACE_DIM, GAUSS, DomainEleOp>(
1008 mField, pipeline, "U", "MAT_ELASTIC", Sev::inform);
1009 mat_p = common_ptr->getMatFirstPiolaStress();
1010 } else {
1011#ifdef WITH_ADOL_C
1014 modelType>::opPostProcFactory(mField, pipeline, "U",
1016 mat_p = physicalEquationsPtr->matOpsDataPtr->getCommonDataPtr(
1017 "P");
1018#else
1019 SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
1020 "ADOL-C support is not enabled. Please reconfigure with "
1021 "-DWITH_ADOL_C=ON and recompile to use MatOps material model.");
1022#endif
1023 }
1025 });
1027 };
1028
1029 boost::shared_ptr<MatrixDouble> mat_p;
1030 using DL = DataLayoutTraits<DataLayout::GaussByCoeffs>;
1031 // Infer the homogeneous fixture's response from the configured material
1032 // dispatcher. The default MetaPiolaResponse tag represents Neo-Hookean.
1033 std::string material_name = "Hencky";
1034#ifdef WITH_ADOL_C
1035 if (useAdolcMaterial) {
1036 int material_tag = physicalEquationsPtr->tAg;
1037 bool found_range = false;
1038 if (physicalEquationsPtr->tagVsRangePtr) {
1039 for (const auto &[tag, range] : *physicalEquationsPtr->tagVsRangePtr) {
1040 if (range.empty())
1041 continue;
1042 if (found_range && tag != material_tag)
1044 "The analytical fixture requires a homogeneous material");
1045 material_tag = tag;
1046 found_range = true;
1047 }
1048 }
1049 material_name = MatOps::MatOpsTagsRegistry::getTagName(material_tag);
1050 }
1051#endif
1052
1053#ifdef AXISYMMETRIC
1054 if (material_name != "MetaPiolaResponse")
1055 SETERRQ(
1057 "The axisymmetric analytical fixture requires Neo-Hookean material");
1058#endif
1059
1060 if (material_name == "Hencky") {
1061 // Homogeneous cube: E = 1, nu = 0.3.
1062 set_linear_elastic_piola(std::log(applied_F_zz), 1. / applied_F_zz);
1063 } else if (material_name == "MetaPiolaResponse") {
1064#ifdef AXISYMMETRIC
1065 // Uniform expansion, c10 = K = 1, including hoop stretch. The
1066 // deviatoric stress vanishes; P = K J (J - 1) F^{-T}.
1067 const double stretch = 1. + 0.01 * time;
1068 const double jacobian = stretch * stretch * stretch;
1069 const double piola = jacobian * (jacobian - 1.) / stretch;
1071 t_P_expected(i, J) = piola * delta(i, J);
1072 CHKERR eval_piola_at_point(mat_p, {1.37, 0.41, 0.});
1073 auto t_u = MatrixSizeHelper<GetFTensor1FromMatType<2, -1, DL>, DL>::get(
1074 *displacement_ptr, 1)();
1075 const double u_err = std::hypot(t_u(0) - (stretch - 1.) * 1.37,
1076 t_u(1) - (stretch - 1.) * 0.41);
1077 CHKERR mField.getInterface<TestingInterface>()
1078 ->checkError<TestType::POINTWISE>("axisymmetric displacement", u_err,
1079 0., {1e-8, 0.});
1080#else
1081 set_neohookean_piola(applied_F_zz, applied_F_zz);
1082#endif
1083 } else if (material_name == "Umat") {
1084 // Reference for this tutorial's linear-elastic UMAT fixture only.
1085 char strain_type[32] = "small";
1086 CHKERR PetscOptionsGetString(nullptr, "", "-umat_strain_type",
1087 strain_type, sizeof(strain_type), nullptr);
1088 if (std::string(strain_type) != "small")
1090 "The analytical UMAT fixture requires small strain");
1091 set_linear_elastic_piola(applied_F_zz - 1., 1.);
1092 } else {
1094 "No analytical fixture for material %s", material_name.c_str());
1095 }
1096
1097 if (!mat_p)
1098 CHKERR eval_piola_at_point(mat_p, {0.123, -0.087, 0.193});
1099 auto t_P =
1100 MatrixSizeHelper<GetFTensor2FromMatType<MAT_DIM, MAT_DIM, -1, DL>,
1101 DL>::get(*mat_p, 1)();
1102 t_P_diff(i, J) = t_P(i, J) - t_P_expected(i, J);
1103 const double p_err = std::sqrt(t_P_diff(i, J) * t_P_diff(i, J));
1104 for (int r = 0; r != MAT_DIM; ++r)
1105 for (int c = 0; c != MAT_DIM; ++c)
1106 MOFEM_LOG("EXAMPLE", Sev::inform)
1107 << "Piola stress (" << material_name << ") P(" << r << ", " << c
1108 << ") actual " << std::scientific << t_P(r, c) << " expected "
1109 << t_P_expected(r, c) << " diff " << t_P_diff(r, c);
1110 MOFEM_LOG("EXAMPLE", Sev::inform) << "Piola stress (" << material_name
1111 << ") error " << std::scientific << p_err;
1112 CHKERR mField.getInterface<TestingInterface>()
1113 ->checkError<TestType::POINTWISE>("Piola stress", p_err, 0.,
1114 {1e-8, 0.});
1115
1117 };
1118
1119 if (check_steps) {
1120 CHKERR mField.getInterface<TestingInterface>()->addTSMonitor(
1121 ts, [this, check_piola_stress](TS, PetscInt step, PetscReal time,
1122 Vec solution) {
1124 auto simple = mField.getInterface<Simple>();
1125 CHKERR VecGhostUpdateBegin(solution, INSERT_VALUES, SCATTER_FORWARD);
1126 CHKERR VecGhostUpdateEnd(solution, INSERT_VALUES, SCATTER_FORWARD);
1127 CHKERR DMoFEMMeshToLocalVector(simple->getDM(), solution,
1128 INSERT_VALUES, SCATTER_REVERSE);
1129 CHKERR check_piola_stress(time);
1130 MOFEM_LOG("EXAMPLE", Sev::inform)
1131 << "Numerical checks passed at TS step " << step << ", time "
1132 << time;
1134 });
1135 }
1136
1138 CHKERR TSSetPreStep(ts, TSElasticPostStep::preStepFun);
1139 CHKERR TSSetPostStep(ts, TSElasticPostStep::postStepFun);
1140 const auto solve_error = TSSolve(ts, nullptr);
1142 CHKERR solve_error;
1143
1144 // Solver convergence is cheap to check and carries no magic numbers, so it
1145 // stands alone right after the solve rather than being deferred to
1146 // checkResults() through stored state.
1147 {
1148 PetscReal expected_time;
1149 CHKERR TSGetMaxTime(ts, &expected_time);
1150 auto testing = mField.getInterface<TestingInterface>();
1151 CHKERR testing->checkSolver(ts, expected_time, {1e-12, 1e-12},
1152 "nonlinear elasticity");
1153 }
1154
1155 CHKERR TSGetTime(ts, &ftime);
1156
1157 PetscInt steps, snesfails, rejects, nonlinits, linits;
1158 CHKERR TSGetStepNumber(ts, &steps);
1159 CHKERR TSGetSNESFailures(ts, &snesfails);
1160 CHKERR TSGetStepRejections(ts, &rejects);
1161 CHKERR TSGetSNESIterations(ts, &nonlinits);
1162 CHKERR TSGetKSPIterations(ts, &linits);
1163 MOFEM_LOG_C("EXAMPLE", Sev::inform,
1164 "steps %d (%d rejected, %d SNES fails), ftime %g, nonlinits "
1165 "%d, linits %d",
1166 steps, rejects, snesfails, ftime, nonlinits, linits);
1167
1169}
Tag tag
SmartPetscObj< Mat > jacobian
#define FTENSOR_INDEX(DIM, I)
Kronecker Delta class.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
@ MOFEM_ATOM_TEST_INVALID
Definition definitions.h:40
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
auto createDMMatrix(DM dm)
Get smart matrix from DM.
Definition DMMoFEM.hpp:1236
FTensor::Index< 'i', SPACE_DIM > i
static double lambda
const double c
speed of light (cm/ns)
double D
FTensor::Index< 'J', DIM1 > J
Definition level_set.cpp:30
DataLayoutTraits< DataLayout::GaussByCoeffs > DL
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
decltype(GetFTensor1FromMatImpl< Tensor_Dim, S, DL, M >::get(std::declval< M & >(), 0, 0)) GetFTensor1FromMatType
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
decltype(GetFTensor2FromMatImpl< Tensor_Dim0, Tensor_Dim1, S, DL, M >::get(std::declval< M & >(), 0, 0)) GetFTensor2FromMatType
static constexpr double delta
static std::string getTagName(int tag)
Definition MatOps.cpp:90
static MoFEMErrorCode postStepInitialise(NonlinearElasticExample *example_ptr)

Member Data Documentation

◆ approximationBase

FieldApproximationBase NonlinearElasticExample::approximationBase = AINSWORTH_LEGENDRE_BASE
protected

◆ listTagsToTransfer

std::vector<Tag> NonlinearElasticExample::listTagsToTransfer
protected

list of tags to transfer to postprocessor

Examples
mofem/tutorials/vec-2_nonlinear_elasticity/src/NonlinearElasticExample.hpp.

Definition at line 82 of file NonlinearElasticExample.hpp.

◆ MAT_DIM

constexpr int NonlinearElasticExample::MAT_DIM = SPACE_DIM
staticconstexprprotected

◆ mField

MoFEM::Interface& NonlinearElasticExample::mField
protected

◆ modelType

constexpr int NonlinearElasticExample::modelType
inlinestaticconstexprprotected
Initial value:
=
(SPACE_DIM == 3) ? MatOps::MODEL_3D : MatOps::MODEL_2D_PLANE_STRAIN
Examples
mofem/tutorials/vec-2_nonlinear_elasticity/src/NonlinearElasticExample.hpp.

Definition at line 88 of file NonlinearElasticExample.hpp.

◆ physicalEquationsPtr

boost::shared_ptr<MatOps::PhysicalEquations> NonlinearElasticExample::physicalEquationsPtr
protected

◆ physicalHuHuPtr

boost::shared_ptr<MatOps::PhysicalEquations> NonlinearElasticExample::physicalHuHuPtr
protected

◆ postProcBdyFe

boost::shared_ptr<PostProcEleBdy> NonlinearElasticExample::postProcBdyFe
protected

◆ postProcDomainFe

boost::shared_ptr<PostProcEleDomain> NonlinearElasticExample::postProcDomainFe
protected

◆ updateFe

boost::shared_ptr<DomainEle> NonlinearElasticExample::updateFe
protected

◆ useAdolcMaterial

PetscBool NonlinearElasticExample::useAdolcMaterial = PETSC_FALSE
protected

The documentation for this struct was generated from the following file: