v0.16.0
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ArcLengthInterfaceExample Struct Reference
Collaboration diagram for ArcLengthInterfaceExample:
[legend]

Public Member Functions

 ArcLengthInterfaceExample (moab::Interface &moab)
 
MoFEMErrorCode runProblem ()
 [Run problem]
 

Protected Member Functions

MoFEMErrorCode readMesh ()
 [Run problem]
 
MoFEMErrorCode setupProblem ()
 [Read mesh]
 
MoFEMErrorCode boundaryCondition ()
 [Set up problem]
 
MoFEMErrorCode assembleSystem ()
 [Boundary condition]
 
MoFEMErrorCode solveSystem ()
 [Solve]
 
MoFEMErrorCode outputResults ()
 [Solve]
 
MoFEMErrorCode checkResults ()
 [Postprocess results]
 
MoFEMErrorCode evaluateFieldAtPoint (const int load_step)
 [Assemble system]
 

Protected Attributes

moab::Interface & mOab
 
boost::shared_ptr< MoFEM::CorecorePtr
 
MoFEM::InterfacemField = nullptr
 
doublestepSizePtr = nullptr
 
int * stepPtr = nullptr
 
PetscScalar stepSizeReduction = 1.
 
PetscInt maxSteps = 5
 
PetscInt itsD = 6
 
PetscInt order = 2
 
const std::string naturalBcFeName = "NATURAL_BC"
 
SmartPetscObj< Vec > f
 
SmartPetscObj< Vec > d
 
Vec dRaw = nullptr
 
SmartPetscObj< Mat > aij
 
SmartPetscObj< Mat > shellAij
 
SmartPetscObj< SNES > snes
 
boost::ptr_vector< CohesiveInterfaceElement::PhysicalEquationinterfaceMaterials
 
boost::shared_ptr< ArcLengthCtxarcCtx
 
boost::shared_ptr< ArcLengthIntElemFEMethodarcMethodPtr
 
boost::shared_ptr< ArcLengthSnesCtx > snesCtxPtr
 
boost::shared_ptr< AssembleRhsVectorsprePostProcFePtr
 
boost::shared_ptr< CohesiveInterfaceElementcohesiveElementsPtr
 
boost::shared_ptr< DomainEleelasticRhsFe
 
boost::shared_ptr< DomainEleelasticLhsFe
 
boost::shared_ptr< BoundaryElenaturalBcFe
 
boost::shared_ptr< PostProcElepostProcPtr
 
boost::scoped_ptr< ArcLengthMatShellmatCtx
 
boost::scoped_ptr< PCArcLengthCtxpcCtx
 
std::array< double, SPACE_DIMfieldEvalCoords {0., 0., 0.}
 
PetscBool doEvalField = PETSC_FALSE
 
boost::shared_ptr< FieldEvaluatorInterface::SetPtsDatafieldEvalData
 
boost::shared_ptr< MatrixDoublefieldEvalDispPtr
 
boost::shared_ptr< MatrixDoublefieldEvalStressPtr
 
double gamma = 0.5
 
double reduction = 1.
 

Detailed Description

Examples
mofem/tutorials/cor-12_cohesive_interface/arc_length_interface.cpp.

Definition at line 104 of file arc_length_interface.cpp.

Constructor & Destructor Documentation

◆ ArcLengthInterfaceExample()

ArcLengthInterfaceExample::ArcLengthInterfaceExample ( moab::Interface &  moab)
inline

Definition at line 106 of file arc_length_interface.cpp.

106: mOab(moab) {}

Member Function Documentation

◆ assembleSystem()

MoFEMErrorCode ArcLengthInterfaceExample::assembleSystem ( )
protected

[Boundary condition]

[Assemble system]

Examples
mofem/tutorials/cor-12_cohesive_interface/arc_length_interface.cpp.

Definition at line 582 of file arc_length_interface.cpp.

582 {
584 auto &m_field = *mField;
585 auto &step = *stepPtr;
586 auto &step_size = *stepSizePtr;
587
588 // create matrices
589 CHKERR m_field.getInterface<VecManager>()->vecCreateGhost("ELASTIC_MECHANICS",
590 COL, f);
592 dRaw = d;
593 CHKERR m_field.getInterface<MatrixManager>()
594 ->createMPIAIJWithArrays<PetscGlobalIdx_mi_tag>("ELASTIC_MECHANICS", aij);
595
596 auto meshsets_manager = m_field.getInterface<MeshsetsManager>();
597 const std::string interface_block_name = "MAT_INTERF";
598 for (auto m : meshsets_manager->getCubitMeshsetPtr(std::regex(
599 (boost::format("%s(.*)") % interface_block_name).str()))) {
600 MOFEM_LOG("ARC_LENGTH", Sev::inform) << *m;
601 Mat_Interf mydata;
602 CHKERR m->getAttributeDataStructure(mydata);
603 MOFEM_LOG("ARC_LENGTH", Sev::inform) << mydata;
604
605 interfaceMaterials.push_back(
607 interfaceMaterials.back().h = 1;
608 interfaceMaterials.back().youngModulus = mydata.data.alpha;
609 interfaceMaterials.back().beta = mydata.data.beta;
610 interfaceMaterials.back().ft = mydata.data.ft;
611 interfaceMaterials.back().Gf = mydata.data.Gf;
612
613 EntityHandle meshset = m->getMeshset();
614 Range tris;
615 CHKERR mOab.get_entities_by_type(meshset, MBTRI, tris, true);
616 Range ents3d;
617 CHKERR mOab.get_adjacencies(tris, 3, false, ents3d, moab::Interface::UNION);
618 interfaceMaterials.back().pRisms = ents3d.subset_by_type(MBPRISM);
619 }
620
621 arcCtx = boost::make_shared<ArcLengthCtx>(m_field, "ELASTIC_MECHANICS");
623 boost::make_shared<ArcLengthIntElemFEMethod>(m_field.get_moab(), arcCtx);
624 snesCtxPtr = boost::make_shared<ArcLengthSnesCtx>(
625 m_field, "ELASTIC_MECHANICS", arcCtx);
626 prePostProcFePtr = boost::make_shared<AssembleRhsVectors>(arcCtx);
627 auto &snes_ctx = *snesCtxPtr;
628 auto &pre_post_proc_fe = *prePostProcFePtr;
629
630 auto essential_pre_proc_zero_rhs = boost::make_shared<FEMethod>();
631 auto essential_pre_proc_lhs = boost::make_shared<FEMethod>();
632 auto essential_post_proc_rhs = boost::make_shared<FEMethod>();
633 auto essential_post_proc_lhs = boost::make_shared<FEMethod>();
634
635 struct ArcScale : public ScalingMethod {
636 boost::shared_ptr<ArcLengthCtx> arcCtx;
637
638 ArcScale(boost::shared_ptr<ArcLengthCtx> arc_ctx) : arcCtx(arc_ctx) {}
639
640 double getScale(const double time) override {
641 return arcCtx->getFieldData();
642 }
643 };
644 auto arc_scale = boost::make_shared<ArcScale>(arcCtx);
645
646 struct ArcZero : public ScalingMethod {
647 double getScale(const double time) override {
648 return 0.0;
649 }
650 };
651 auto arc_zero = boost::make_shared<ArcZero>();
652
653 auto get_essential_pre_proc_zero =
654 [&m_field, essential_pre_proc_zero_rhs, arc_zero]() {
656 m_field, essential_pre_proc_zero_rhs, {arc_zero});
657 };
658 essential_pre_proc_zero_rhs->preProcessHook =
659 get_essential_pre_proc_zero();
660 auto get_essential_pre_proc_lhs =
661 [&m_field, essential_pre_proc_lhs, arc_scale]() {
663 m_field, essential_pre_proc_lhs, {arc_scale});
664 };
665 essential_pre_proc_lhs->preProcessHook = get_essential_pre_proc_lhs();
666
667 essential_post_proc_rhs->postProcessHook =
668 [&m_field, essential_post_proc_rhs, arc_scale]() {
671 m_field, essential_post_proc_rhs, {arc_scale})();
673 m_field, essential_post_proc_rhs, 1.)();
675 };
676
677 // ArcScale sets the reference prescribed field to lambda * F_lambda, so
678 // the constrained residual is u_D - lambda * F_lambda,D.
679 essential_post_proc_lhs->postProcessHook =
681 m_field, essential_post_proc_lhs, 1.);
682
683 elasticRhsFe = boost::make_shared<DomainEle>(m_field);
684 elasticLhsFe = boost::make_shared<DomainEle>(m_field);
685 auto elastic_integration_rule = [](int, int, int approx_order) {
686 return 2 * approx_order + 1;
687 };
688 elasticRhsFe->getRuleHook = elastic_integration_rule;
689 elasticLhsFe->getRuleHook = elastic_integration_rule;
690
692 elasticRhsFe->getOpPtrVector(), {H1}, "GEOMETRY");
694 elasticLhsFe->getOpPtrVector(), {H1}, "GEOMETRY");
695 CHKERR HookeOps::opFactoryDomainRhs<SPACE_DIM, PETSC, GAUSS, DomainEleOp>(
696 m_field, elasticRhsFe->getOpPtrVector(), "DISPLACEMENT", "MAT_ELASTIC",
697 Sev::verbose, true);
698 CHKERR HookeOps::opFactoryDomainLhs<SPACE_DIM, PETSC, GAUSS, DomainEleOp>(
699 m_field, elasticLhsFe->getOpPtrVector(), "DISPLACEMENT", "MAT_ELASTIC",
700 Sev::verbose);
701
702 cohesiveElementsPtr = boost::make_shared<CohesiveInterfaceElement>(m_field);
703 auto &cohesive_elements = *cohesiveElementsPtr;
704 CHKERR cohesive_elements.addOps("DISPLACEMENT", interfaceMaterials);
705
706 PetscInt M, N;
707 CHKERR MatGetSize(aij, &M, &N);
708 PetscInt m, n;
709 CHKERR MatGetLocalSize(aij, &m, &n);
710 matCtx.reset(new ArcLengthMatShell(aij, arcCtx, "ELASTIC_MECHANICS"));
711 Mat shell_aij;
712 CHKERR MatCreateShell(PETSC_COMM_WORLD, m, n, M, N, (void *)matCtx.get(),
713 &shell_aij);
714 shellAij = SmartPetscObj<Mat>(shell_aij);
715 CHKERR MatShellSetOperation(shellAij, MATOP_MULT,
716 (void (*)(void))ArcLengthMatMultShellOp);
717
721
722 naturalBcFe = boost::make_shared<BoundaryEle>(m_field);
723 naturalBcFe->getRuleHook = [](int, int, int approx_order) {
724 return 2 * approx_order + 1;
725 };
726 CHKERR AddHOOps<2, 3, 3>::add(naturalBcFe->getOpPtrVector(), {NOSPACE},
727 "GEOMETRY");
729 naturalBcFe->getOpPtrVector(), m_field, "DISPLACEMENT", Sev::inform);
730
731 snes = createSNES(PETSC_COMM_WORLD);
732 CHKERR SNESSetApplicationContext(snes, &snes_ctx);
733 CHKERR SNESSetFunction(snes, f, SnesRhs, &snes_ctx);
734 CHKERR SNESSetJacobian(snes, shellAij, aij, SnesMat, &snes_ctx);
735 CHKERR SNESSetFromOptions(snes);
736
737 KSP ksp;
738 CHKERR SNESGetKSP(snes, &ksp);
739 PC pc;
740 CHKERR KSPGetPC(ksp, &pc);
741 pcCtx.reset(new PCArcLengthCtx(shellAij, aij, arcCtx));
742 CHKERR PCSetType(pc, PCSHELL);
743 CHKERR PCShellSetContext(pc, pcCtx.get());
744 CHKERR PCShellSetApply(pc, PCApplyArcLength);
745 CHKERR PCShellSetSetUp(pc, PCSetupArcLength);
746
747 // Rhs
748 SnesCtx::FEMethodsSequence &loops_to_do_Rhs = snes_ctx.getComputeRhs();
749 snes_ctx.getPreProcComputeRhs().push_back(essential_pre_proc_zero_rhs);
750 snes_ctx.getPreProcComputeRhs().push_back(&pre_post_proc_fe);
751 loops_to_do_Rhs.push_back(
752 SnesCtx::PairNameFEMethodPtr("INTERFACE", &cohesive_elements.getFeRhs()));
753 loops_to_do_Rhs.push_back(
755 loops_to_do_Rhs.push_back(
756 SnesCtx::PairNameFEMethodPtr("ARC_LENGTH", arcMethodPtr.get()));
757 // Add F_lambda before essential processing replaces the constrained rows
758 // with u_D - lambda * F_lambda,D.
759 snes_ctx.getPostProcComputeRhs().push_back(&pre_post_proc_fe);
760 snes_ctx.getPostProcComputeRhs().push_back(essential_post_proc_rhs);
761
762 // Mat
763 SnesCtx::FEMethodsSequence &loops_to_do_Mat = snes_ctx.getSetOperators();
764 snes_ctx.getPreProcSetOperators().push_back(essential_pre_proc_lhs);
765 loops_to_do_Mat.push_back(
766 SnesCtx::PairNameFEMethodPtr("INTERFACE", &cohesive_elements.getFeLhs()));
767 loops_to_do_Mat.push_back(
769 loops_to_do_Mat.push_back(
770 SnesCtx::PairNameFEMethodPtr("ARC_LENGTH", arcMethodPtr.get()));
771 snes_ctx.getPostProcSetOperators().push_back(essential_post_proc_lhs);
772
773 // step = 1;
774 if (step == 1) {
775 step_size = stepSizeReduction;
776 } else {
778 step++;
779 }
780
781 auto f_lambda_on_essential_bc = boost::make_shared<FEMethod>();
782 f_lambda_on_essential_bc->preProcessHook =
784 m_field, f_lambda_on_essential_bc, {}, false);
785 // EssentialPreProc stores the unit prescribed field. Its derivative in
786 // u_D - lambda * F_lambda,D has the opposite sign, hence vDiag = -1.
787 f_lambda_on_essential_bc->postProcessHook =
789 m_field, f_lambda_on_essential_bc, -1., arcCtx->F_lambda);
790
791 CHKERR VecZeroEntries(arcCtx->F_lambda);
792 CHKERR VecGhostUpdateBegin(arcCtx->F_lambda, INSERT_VALUES, SCATTER_FORWARD);
793 CHKERR VecGhostUpdateEnd(arcCtx->F_lambda, INSERT_VALUES, SCATTER_FORWARD);
794 CHKERR m_field.problem_basic_method_preProcess("ELASTIC_MECHANICS",
795 *f_lambda_on_essential_bc);
796 elasticRhsFe->ksp_f = arcCtx->F_lambda;
797 CHKERR m_field.loop_finite_elements("ELASTIC_MECHANICS", "ELASTIC",
798 *elasticRhsFe);
799 naturalBcFe->ksp_f = arcCtx->F_lambda;
800 CHKERR m_field.loop_finite_elements("ELASTIC_MECHANICS", naturalBcFeName,
801 *naturalBcFe);
802 CHKERR m_field.problem_basic_method_postProcess("ELASTIC_MECHANICS",
803 *f_lambda_on_essential_bc);
804 CHKERR VecGhostUpdateBegin(arcCtx->F_lambda, ADD_VALUES, SCATTER_REVERSE);
805 CHKERR VecGhostUpdateEnd(arcCtx->F_lambda, ADD_VALUES, SCATTER_REVERSE);
806 CHKERR VecAssemblyBegin(arcCtx->F_lambda);
807 CHKERR VecAssemblyEnd(arcCtx->F_lambda);
808
809 // F_lambda2
810 CHKERR VecDot(arcCtx->F_lambda, arcCtx->F_lambda, &arcCtx->F_lambda2);
811 MOFEM_LOG_C("ARC_LENGTH", Sev::inform, "\tFlambda2 = %6.4e",
812 arcCtx->F_lambda2);
813
814 if (step > 1) {
815 CHKERR m_field.getInterface<VecManager>()->setLocalGhostVector(
816 "ELASTIC_MECHANICS", COL, d, INSERT_VALUES, SCATTER_FORWARD);
817 CHKERR m_field.getInterface<VecManager>()->setOtherGlobalGhostVector(
818 "ELASTIC_MECHANICS", "DISPLACEMENT", "X0_DISPLACEMENT", COL, arcCtx->x0,
819 INSERT_VALUES, SCATTER_FORWARD);
820 double x0_nrm;
821 CHKERR VecNorm(arcCtx->x0, NORM_2, &x0_nrm);
822 MOFEM_LOG_C("ARC_LENGTH", Sev::inform,
823 "\tRead x0_nrm = %6.4e dlambda = %6.4e", x0_nrm,
824 arcCtx->dLambda);
825 CHKERR arcCtx->setAlphaBeta(1, 0);
826 } else {
827 CHKERR arcCtx->setS(0);
828 CHKERR arcCtx->setAlphaBeta(0, 1);
829 }
830 CHKERR SnesRhs(snes, d, f, &snes_ctx);
831
832 postProcPtr = boost::make_shared<PostProcEle>(m_field);
833 auto &post_proc = *postProcPtr;
834 auto disp_ptr = boost::make_shared<MatrixDouble>();
836 post_proc.getOpPtrVector(), {H1}, "GEOMETRY");
837 auto hooke_common_ptr =
838 HookeOps::commonDataFactory<SPACE_DIM, GAUSS, DomainEleOp>(
839 m_field, post_proc.getOpPtrVector(), "DISPLACEMENT", "MAT_ELASTIC",
840 Sev::verbose);
841 post_proc.getOpPtrVector().push_back(
842 new OpCalculateVectorFieldValues<SPACE_DIM>("DISPLACEMENT", disp_ptr));
844 post_proc.getOpPtrVector().push_back(
845 new OpPPMap(post_proc.getPostProcMesh(), post_proc.getMapGaussPts(), {},
846 {{"DISPLACEMENT", disp_ptr}},
847 {{"DISPLACEMENT_GRAD", hooke_common_ptr->matGradPtr}},
848 {{"STRAIN", hooke_common_ptr->getMatStrain()},
849 {"STRESS", hooke_common_ptr->getMatCauchyStress()}}));
850
851 int coords_dim = SPACE_DIM;
852 CHKERR PetscOptionsGetRealArray(PETSC_NULLPTR, PETSC_NULLPTR,
853 "-field_eval_coords", fieldEvalCoords.data(),
854 &coords_dim, &doEvalField);
855 if (doEvalField && coords_dim != SPACE_DIM)
856 SETERRQ(PETSC_COMM_WORLD, MOFEM_INVALID_DATA,
857 "-field_eval_coords requires exactly three coordinates");
858
859 if (doEvalField) {
861 m_field.getInterface<FieldEvaluatorInterface>()->getData<DomainEle>();
862 CHKERR m_field.getInterface<FieldEvaluatorInterface>()
863 ->buildTree<SPACE_DIM>(fieldEvalData, "ELASTIC");
864 fieldEvalData->setEvalPoints(fieldEvalCoords.data(), 1);
865
866 auto field_eval_fe = fieldEvalData->feMethodPtr;
867 field_eval_fe->getRuleHook = [](int, int, int) { return -1; };
869 field_eval_fe->getOpPtrVector(), {H1}, "GEOMETRY");
870
871 auto field_eval_hooke_common_ptr =
872 HookeOps::commonDataFactory<SPACE_DIM, GAUSS, DomainEleOp>(
873 m_field, field_eval_fe->getOpPtrVector(), "DISPLACEMENT",
874 "MAT_ELASTIC", Sev::verbose);
875 fieldEvalStressPtr = field_eval_hooke_common_ptr->getMatCauchyStress();
876 fieldEvalDispPtr = boost::make_shared<MatrixDouble>();
877 field_eval_fe->getOpPtrVector().push_back(
880 }
881
883}
#define MOFEM_LOG_C(channel, severity, format,...)
constexpr int SPACE_DIM
@ COL
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_INVALID_DATA
Definition definitions.h:36
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
@ PETSC
Standard PETSc assembly.
#define MOFEM_LOG(channel, severity)
Log.
const double n
refractive index of diffusive medium
auto createSNES(MPI_Comm comm)
PetscErrorCode SnesMat(SNES snes, Vec x, Mat A, Mat B, void *ctx)
This is MoFEM implementation for the left hand side (tangent matrix) evaluation in SNES solver.
Definition SnesCtx.cpp:491
PetscErrorCode SnesRhs(SNES snes, Vec x, Vec f, void *ctx)
This is MoFEM implementation for the right hand side (residual vector) evaluation in SNES solver.
Definition SnesCtx.cpp:227
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)
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
static constexpr int approx_order
FTensor::Index< 'm', 3 > m
const int N
Definition speed_test.cpp:3
boost::shared_ptr< ArcLengthIntElemFEMethod > arcMethodPtr
boost::shared_ptr< MatrixDouble > fieldEvalStressPtr
boost::ptr_vector< CohesiveInterfaceElement::PhysicalEquation > interfaceMaterials
boost::scoped_ptr< PCArcLengthCtx > pcCtx
boost::shared_ptr< PostProcEle > postProcPtr
boost::shared_ptr< CohesiveInterfaceElement > cohesiveElementsPtr
boost::shared_ptr< AssembleRhsVectors > prePostProcFePtr
boost::shared_ptr< ArcLengthCtx > arcCtx
boost::shared_ptr< MatrixDouble > fieldEvalDispPtr
boost::shared_ptr< FieldEvaluatorInterface::SetPtsData > fieldEvalData
boost::scoped_ptr< ArcLengthMatShell > matCtx
std::array< double, SPACE_DIM > fieldEvalCoords
boost::shared_ptr< ArcLengthSnesCtx > snesCtxPtr
boost::shared_ptr< DomainEle > elasticLhsFe
boost::shared_ptr< BoundaryEle > naturalBcFe
boost::shared_ptr< DomainEle > elasticRhsFe
shell matrix for arc-length method
Add operators pushing bases from local to physical configuration.
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 enforce essential constrains.
Definition Essential.hpp:25
Field evaluator interface.
Linear interface data structure.
Matrix manager is used to build and partition problems.
Interface for managing meshsets containing materials and boundary conditions.
Assembly methods.
Definition Natural.hpp:65
Specialization for MatrixDouble vector field values calculation.
Post post-proc data at points from hash maps.
intrusive_ptr for managing petsc objects
MoFEM::FEMethodsSequence FEMethodsSequence
Definition SnesCtx.hpp:18
Vector manager is used to create vectors \mofem_vectors.
structure for Arc Length pre-conditioner
MoFEMErrorCode PCApplyArcLength(PC pc, Vec pc_f, Vec pc_x)
MoFEMErrorCode ArcLengthMatMultShellOp(Mat A, Vec x, Vec f)
MoFEMErrorCode PCSetupArcLength(PC pc)

◆ boundaryCondition()

MoFEMErrorCode ArcLengthInterfaceExample::boundaryCondition ( )
protected

[Set up problem]

[Boundary condition]

Examples
mofem/tutorials/cor-12_cohesive_interface/arc_length_interface.cpp.

Definition at line 561 of file arc_length_interface.cpp.

561 {
563 auto &m_field = *mField;
564
565 auto bc_mng = m_field.getInterface<BcManager>();
567 "ELASTIC_MECHANICS", "DISPLACEMENT");
568
569 // print bcs
570 MeshsetsManager *mmanager_ptr;
571 CHKERR m_field.getInterface(mmanager_ptr);
572 CHKERR mmanager_ptr->printDisplacementSet();
573 CHKERR mmanager_ptr->printForceSet();
574 // print block sets with materials
575 CHKERR mmanager_ptr->printMaterialsSet();
576
578}
MoFEMErrorCode pushMarkDOFsOnEntities(const std::string problem_name, const std::string block_name, const std::string field_name, int lo, int hi, bool get_low_dim_ents=true)
Mark DOFs on block entities for boundary conditions.
Boundary condition manager for finite element problem setup.
Definition of the displacement bc data structure.
Definition BCData.hpp:72
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.

◆ checkResults()

MoFEMErrorCode ArcLengthInterfaceExample::checkResults ( )
protected

[Postprocess results]

[Check]

Examples
mofem/tutorials/cor-12_cohesive_interface/arc_length_interface.cpp.

Definition at line 1081 of file arc_length_interface.cpp.

1081 {
1084}

◆ evaluateFieldAtPoint()

MoFEMErrorCode ArcLengthInterfaceExample::evaluateFieldAtPoint ( const int  load_step)
protected

[Assemble system]

Examples
mofem/tutorials/cor-12_cohesive_interface/arc_length_interface.cpp.

Definition at line 887 of file arc_length_interface.cpp.

887 {
889 auto &m_field = *mField;
890
891 if (!doEvalField)
893
894 CHKERR m_field.getInterface<FieldEvaluatorInterface>()
895 ->evalFEAtThePoint<SPACE_DIM>(
896 fieldEvalCoords.data(), 1e-12, "ELASTIC_MECHANICS", "ELASTIC",
897 fieldEvalData, m_field.get_comm_rank(), m_field.get_comm_rank(),
898 nullptr, MF_EXIST, QUIET);
899
900 int point_found = fieldEvalDispPtr->size1() && fieldEvalStressPtr->size1();
901 int global_point_found = 0;
902 MPI_Allreduce(&point_found, &global_point_found, 1, MPI_INT, MPI_SUM,
903 m_field.get_comm());
904
905 if (point_found) {
906 auto t_disp = getFTensor1FromMat<SPACE_DIM>(*fieldEvalDispPtr);
907 auto t_stress = getFTensor2SymmetricFromMat<SPACE_DIM>(*fieldEvalStressPtr);
908 MOFEM_LOG_C("SYNC", Sev::inform,
909 "FieldEvaluator step %d lambda %6.4e point [%6.4e, %6.4e, "
910 "%6.4e]",
911 load_step, arcCtx->getFieldData(), fieldEvalCoords[0],
913 MOFEM_LOG_C("SYNC", Sev::inform,
914 "FieldEvaluator displacement [Ux, Uy, Uz] = [%6.4e, "
915 "%6.4e, %6.4e]",
916 t_disp(0), t_disp(1), t_disp(2));
917 MOFEM_LOG_C("SYNC", Sev::inform,
918 "FieldEvaluator Cauchy stress [Sxx, Syy, Szz, Sxy, Syz, Sxz] "
919 "= [%6.4e, %6.4e, %6.4e, %6.4e, %6.4e, %6.4e]",
920 t_stress(0, 0), t_stress(1, 1), t_stress(2, 2), t_stress(0, 1),
921 t_stress(1, 2), t_stress(0, 2));
922 } else if (!global_point_found && !m_field.get_comm_rank()) {
923 MOFEM_LOG_C("ARC_LENGTH", Sev::warning,
924 "FieldEvaluator did not find point [%6.4e, %6.4e, %6.4e] in "
925 "the ELASTIC domain",
927 }
928 MOFEM_LOG_SYNCHRONISE(m_field.get_comm());
929
931}
#define MOFEM_LOG_SYNCHRONISE(comm)
Synchronise "SYNC" channel.
@ QUIET
@ MF_EXIST
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()

◆ outputResults()

MoFEMErrorCode ArcLengthInterfaceExample::outputResults ( )
protected

[Solve]

[Postprocess results]

Examples
mofem/tutorials/cor-12_cohesive_interface/arc_length_interface.cpp.

Definition at line 1074 of file arc_length_interface.cpp.

1074 {
1077}

◆ readMesh()

MoFEMErrorCode ArcLengthInterfaceExample::readMesh ( )
protected

[Run problem]

[Read mesh]

Examples
mofem/tutorials/cor-12_cohesive_interface/arc_length_interface.cpp.

Definition at line 178 of file arc_length_interface.cpp.

178 {
180
182
183 // Read the mesh file before constructing MoFEM::Core so that the MOAB
184 // database can be populated first. JsonConfigManager::setMeshFileFromJson()
185 // maps the primary JSON mesh to -file_name.
186 PetscBool flg = PETSC_TRUE;
187 char mesh_file_name[PETSC_MAX_PATH_LEN] = "";
188 CHKERR PetscOptionsGetString(PETSC_NULLPTR, PETSC_NULLPTR, "-my_file",
189 mesh_file_name, sizeof(mesh_file_name), &flg);
190 if (flg != PETSC_TRUE) {
191 CHKERR PetscOptionsGetString(PETSC_NULLPTR, PETSC_NULLPTR, "-file_name",
192 mesh_file_name, sizeof(mesh_file_name), &flg);
193 if (flg != PETSC_TRUE)
194 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
195 "*** ERROR -my_file or -file_name (MESH FILE NEEDED)");
196 }
197
198 // Read mesh to MOAB
199 const char *option;
200 option = "";
201 CHKERR mOab.load_file(mesh_file_name, 0, option);
202
203 // Data stored on mesh for restart
204 Tag th_step_size, th_step;
205 double def_step_size = 1;
206 rval = mOab.tag_get_handle("_STEPSIZE", 1, MB_TYPE_DOUBLE, th_step_size,
207 MB_TAG_CREAT | MB_TAG_MESH, &def_step_size);
208 if (rval == MB_ALREADY_ALLOCATED)
209 rval = MB_SUCCESS;
210 CHKERR rval;
211 int def_step = 1;
212 rval = mOab.tag_get_handle("_STEP", 1, MB_TYPE_INTEGER, th_step,
213 MB_TAG_CREAT | MB_TAG_MESH, &def_step);
214 if (rval == MB_ALREADY_ALLOCATED)
215 rval = MB_SUCCESS;
216 CHKERR rval;
217 const void *tag_data_step_size[1];
218 EntityHandle root = 0;
219 CHKERR mOab.tag_get_by_ptr(th_step_size, &root, 1, tag_data_step_size);
220 double &step_size = *(double *)tag_data_step_size[0];
221 const void *tag_data_step[1];
222 CHKERR mOab.tag_get_by_ptr(th_step, &root, 1, tag_data_step);
223 int &step = *(int *)tag_data_step[0];
224 // end of data stored for restart
225 MOFEM_LOG_C("ARC_LENGTH", Sev::inform, "Start step %d and step_size = %6.4e",
226 step, step_size);
227
228 stepSizePtr = (double *)tag_data_step_size[0];
229 stepPtr = (int *)tag_data_step[0];
230
231 // Create MoFEM database after loading the mesh. This preserves loading of
232 // JSON options by the Core constructor.
233 corePtr = boost::make_shared<MoFEM::Core>(mOab);
234 mField = corePtr.get();
235
237}
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
boost::shared_ptr< MoFEM::Core > corePtr
static MoFEMErrorCode setMeshFileFromJson()
Set -file_name from JSON before Core is available.

◆ runProblem()

MoFEMErrorCode ArcLengthInterfaceExample::runProblem ( )

[Run problem]

Examples
mofem/tutorials/cor-12_cohesive_interface/arc_length_interface.cpp.

Definition at line 164 of file arc_length_interface.cpp.

164 {
174}
MoFEMErrorCode boundaryCondition()
[Set up problem]
MoFEMErrorCode checkResults()
[Postprocess results]
MoFEMErrorCode readMesh()
[Run problem]
MoFEMErrorCode setupProblem()
[Read mesh]
MoFEMErrorCode assembleSystem()
[Boundary condition]
MoFEMErrorCode solveSystem()
[Solve]
MoFEMErrorCode outputResults()
[Solve]

◆ setupProblem()

MoFEMErrorCode ArcLengthInterfaceExample::setupProblem ( )
protected

[Read mesh]

[Set up problem]

Examples
mofem/tutorials/cor-12_cohesive_interface/arc_length_interface.cpp.

Definition at line 241 of file arc_length_interface.cpp.

241 {
243 auto &m_field = *mField;
244 auto &step = *stepPtr;
245 PetscBool flg = PETSC_FALSE;
246
247 // Constructing MoFEM::Core loads -json_config and inserts its "petsc" and
248 // "mofem" sections into the PETSc options database. Read application
249 // controls only after that point so they can be supplied by JSON.
250 CHKERR PetscOptionsGetReal(PETSC_NULLPTR, PETSC_NULLPTR, "-my_sr",
251 &stepSizeReduction, &flg);
252 if (flg != PETSC_TRUE) {
254 }
255
256 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, PETSC_NULLPTR, "-my_ms", &maxSteps,
257 &flg);
258 if (flg != PETSC_TRUE) {
259 maxSteps = 5;
260 }
261
262 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, PETSC_NULLPTR, "-my_its_d", &itsD,
263 &flg);
264 if (flg != PETSC_TRUE) {
265 itsD = 6;
266 }
267
268 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, PETSC_NULLPTR, "-my_order", &order,
269 &flg);
270 if (flg != PETSC_TRUE) {
271 order = 2;
272 }
273
274 MeshsetsManager *meshsets_manager_ptr;
275 CHKERR m_field.getInterface(meshsets_manager_ptr);
276 CHKERR meshsets_manager_ptr->setMeshsetFromFile();
277
278 PrismInterface *interface_ptr;
279 CHKERR m_field.getInterface(interface_ptr);
280
281 Tag th_my_ref_level;
282 BitRefLevel def_bit_level = 0;
283 CHKERR m_field.get_moab().tag_get_handle(
284 "_MY_REFINEMENT_LEVEL", sizeof(BitRefLevel), MB_TYPE_OPAQUE,
285 th_my_ref_level, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_BYTES,
286 &def_bit_level);
287 const EntityHandle root_meshset = m_field.get_moab().get_root_set();
288 BitRefLevel *ptr_bit_level0;
289 CHKERR m_field.get_moab().tag_get_by_ptr(th_my_ref_level, &root_meshset, 1,
290 (const void **)&ptr_bit_level0);
291 BitRefLevel &bit_level0 = *ptr_bit_level0;
292 BitRefLevel problem_bit_level = bit_level0;
293
294 if (step == 1) {
295
296 // ref meshset ref level 0
297 CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
298 0, 3, BitRefLevel().set(0));
299
300 std::vector<BitRefLevel> bit_levels;
301 bit_levels.push_back(BitRefLevel().set(0));
302
303 int ll = 1;
304
305 auto split_interface = [&](const EntityHandle cubit_meshset,
306 const int meshset_id) -> MoFEMErrorCode {
308 MOFEM_LOG_C("ARC_LENGTH", Sev::inform, "Insert Interface %d", meshset_id);
309 {
310 // get tet entities form back bit_level
311 EntityHandle ref_level_meshset = 0;
312 CHKERR mOab.create_meshset(MESHSET_SET, ref_level_meshset);
313 CHKERR m_field.getInterface<BitRefManager>()
314 ->getEntitiesByTypeAndRefLevel(bit_levels.back(),
315 BitRefLevel().set(), MBTET,
316 ref_level_meshset);
318 ->getEntitiesByTypeAndRefLevel(bit_levels.back(),
319 BitRefLevel().set(), MBPRISM,
320 ref_level_meshset);
321 Range ref_level_tets;
322 CHKERR mOab.get_entities_by_handle(ref_level_meshset, ref_level_tets,
323 true);
324 // get faces and test to split
325 CHKERR interface_ptr->getSides(cubit_meshset, bit_levels.back(), true,
326 0);
327 // set new bit level
328 bit_levels.push_back(BitRefLevel().set(ll++));
329 // split faces and
330 CHKERR interface_ptr->splitSides(ref_level_meshset, bit_levels.back(),
331 cubit_meshset, true, true, 0);
332 // clean meshsets
333 CHKERR mOab.delete_entities(&ref_level_meshset, 1);
334 }
335 // Update cubit meshsets
336 for (_IT_CUBITMESHSETS_FOR_LOOP_(m_field, ciit)) {
337 EntityHandle cubit_meshset = ciit->meshset;
338 CHKERR m_field.getInterface<BitRefManager>()
339 ->updateMeshsetByEntitiesChildren(cubit_meshset, bit_levels.back(),
340 cubit_meshset, MBMAXTYPE, true);
341 }
343 };
344
345 // Prefer Cubit INTERFACESET side sets. Use MAT_INTERF blocksets only as
346 // a fallback for meshes configured through JsonConfigManager, since a
347 // legacy mesh can store the same interface under both set types.
348 std::set<int> split_interface_ids;
349 bool split_from_sideset = false;
351 m_field, SIDESET | INTERFACESET, cit)) {
352 if (split_interface_ids.insert(cit->getMeshsetId()).second) {
353 CHKERR split_interface(cit->getMeshset(), cit->getMeshsetId());
354 split_from_sideset = true;
355 }
356 }
357 if (!split_from_sideset) {
358 const std::string block_name = "MAT_INTERF";
359 for (auto m : m_field.getInterface<MeshsetsManager>()->getCubitMeshsetPtr(
360 std::regex((boost::format("%s(.*)") % block_name).str()))) {
361 if (split_interface_ids.insert(m->getMeshsetId()).second)
362 CHKERR split_interface(m->getMeshset(), m->getMeshsetId());
363 }
364 }
365
366 bit_level0 = bit_levels.back();
367 problem_bit_level = bit_level0;
368
369 /***/
370 // Define problem
371
372 // Fields
373 CHKERR m_field.add_field("DISPLACEMENT", H1, AINSWORTH_LEGENDRE_BASE, 3);
374 CHKERR
375 m_field.add_field("GEOMETRY", H1, AINSWORTH_LEGENDRE_BASE, 3);
376
377 CHKERR m_field.add_field("LAMBDA", NOFIELD, NOBASE, 1);
378
379 // Field for ArcLength
380 CHKERR
381 m_field.add_field("X0_DISPLACEMENT", H1, AINSWORTH_LEGENDRE_BASE, 3);
382
383 // FE
384 CHKERR m_field.add_finite_element("ELASTIC");
385
386 // Define rows/cols and element data
387 CHKERR m_field.modify_finite_element_add_field_row("ELASTIC",
388 "DISPLACEMENT");
389 CHKERR m_field.modify_finite_element_add_field_col("ELASTIC",
390 "DISPLACEMENT");
391 CHKERR m_field.modify_finite_element_add_field_data("ELASTIC",
392 "DISPLACEMENT");
393 CHKERR
394 m_field.modify_finite_element_add_field_data("ELASTIC", "GEOMETRY");
395 CHKERR m_field.modify_finite_element_add_field_row("ELASTIC", "LAMBDA");
396 CHKERR m_field.modify_finite_element_add_field_col("ELASTIC", "LAMBDA");
397 // this is for paremtis
398 CHKERR m_field.modify_finite_element_add_field_data("ELASTIC", "LAMBDA");
399
400 // FE Interface
401 CHKERR m_field.add_finite_element("INTERFACE");
402 CHKERR m_field.modify_finite_element_add_field_row("INTERFACE",
403 "DISPLACEMENT");
404 CHKERR m_field.modify_finite_element_add_field_col("INTERFACE",
405 "DISPLACEMENT");
406 CHKERR m_field.modify_finite_element_add_field_data("INTERFACE",
407 "DISPLACEMENT");
408 CHKERR
409 m_field.modify_finite_element_add_field_data("INTERFACE", "GEOMETRY");
410
411 // FE ArcLength
412 CHKERR m_field.add_finite_element("ARC_LENGTH");
413
414 // Define rows/cols and element data
415 CHKERR m_field.modify_finite_element_add_field_row("ARC_LENGTH", "LAMBDA");
416 CHKERR m_field.modify_finite_element_add_field_col("ARC_LENGTH", "LAMBDA");
417
418 // elem data
419 CHKERR
420 m_field.modify_finite_element_add_field_data("ARC_LENGTH", "LAMBDA");
421
422 // define problems
423 CHKERR m_field.add_problem("ELASTIC_MECHANICS");
424
425 // set finite elements for problem
426 CHKERR m_field.modify_problem_add_finite_element("ELASTIC_MECHANICS",
427 "ELASTIC");
428 CHKERR m_field.modify_problem_add_finite_element("ELASTIC_MECHANICS",
429 "INTERFACE");
430 CHKERR m_field.modify_problem_add_finite_element("ELASTIC_MECHANICS",
431 "ARC_LENGTH");
432 // set refinement level for problem
433 CHKERR m_field.modify_problem_ref_level_add_bit("ELASTIC_MECHANICS",
434 problem_bit_level);
435
436 /***/
437 // Declare problem
438
439 // add entities (by tets) to the field
440 CHKERR m_field.add_ents_to_field_by_type(0, MBTET, "DISPLACEMENT");
441 CHKERR m_field.add_ents_to_field_by_type(0, MBTET, "X0_DISPLACEMENT");
442 CHKERR m_field.add_ents_to_field_by_type(0, MBTET, "GEOMETRY");
443
444 // add finite elements entities
445 CHKERR m_field.add_ents_to_finite_element_by_bit_ref(
446 problem_bit_level, BitRefLevel().set(), "ELASTIC", MBTET);
447 CHKERR m_field.add_ents_to_finite_element_by_bit_ref(
448 problem_bit_level, BitRefLevel().set(), "INTERFACE", MBPRISM);
449
450 // Setting up LAMBDA field and ARC_LENGTH interface
451 {
452 // Add dummy no-field vertex
453 EntityHandle no_field_vertex;
454 {
455 const double coords[] = {0, 0, 0};
456 CHKERR m_field.get_moab().create_vertex(coords, no_field_vertex);
457 Range range_no_field_vertex;
458 range_no_field_vertex.insert(no_field_vertex);
459 CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevel(
460 range_no_field_vertex, BitRefLevel().set());
461
462 EntityHandle lambda_meshset = m_field.get_field_meshset("LAMBDA");
463 CHKERR m_field.get_moab().add_entities(lambda_meshset,
464 range_no_field_vertex);
465 }
466 // this entity will carray data for this finite element
467 EntityHandle meshset_fe_arc_length;
468 {
469 CHKERR mOab.create_meshset(MESHSET_SET, meshset_fe_arc_length);
470 CHKERR mOab.add_entities(meshset_fe_arc_length, &no_field_vertex, 1);
471 CHKERR m_field.getInterface<BitRefManager>()->setBitLevelToMeshset(
472 meshset_fe_arc_length, BitRefLevel().set());
473 }
474 // finally add created meshset to the ARC_LENGTH finite element
475 CHKERR m_field.add_ents_to_finite_element_by_MESHSET(
476 meshset_fe_arc_length, "ARC_LENGTH", false);
477 }
478
479 // set app. order
480 // see Hierarchic Finite Element Bases on Unstructured Tetrahedral Meshes
481 // (Mark Ainsworth & Joe Coyle)
482 CHKERR m_field.set_field_order(0, MBTET, "DISPLACEMENT", order);
483 CHKERR m_field.set_field_order(0, MBTRI, "DISPLACEMENT", order);
484 CHKERR m_field.set_field_order(0, MBEDGE, "DISPLACEMENT", order);
485 CHKERR m_field.set_field_order(0, MBVERTEX, "DISPLACEMENT", 1);
486
487 CHKERR m_field.set_field_order(0, MBTET, "X0_DISPLACEMENT", order);
488 CHKERR m_field.set_field_order(0, MBTRI, "X0_DISPLACEMENT", order);
489 CHKERR m_field.set_field_order(0, MBEDGE, "X0_DISPLACEMENT", order);
490 CHKERR m_field.set_field_order(0, MBVERTEX, "X0_DISPLACEMENT", 1);
491
492 CHKERR m_field.set_field_order(0, MBTET, "GEOMETRY", 2);
493 CHKERR m_field.set_field_order(0, MBTRI, "GEOMETRY", 2);
494 CHKERR m_field.set_field_order(0, MBEDGE, "GEOMETRY", 2);
495 CHKERR m_field.set_field_order(0, MBVERTEX, "GEOMETRY", 1);
496 }
497
498 if (!m_field.check_finite_element(naturalBcFeName)) {
499 CHKERR m_field.add_finite_element(naturalBcFeName);
500 CHKERR m_field.modify_finite_element_add_field_row(naturalBcFeName,
501 "DISPLACEMENT");
502 CHKERR m_field.modify_finite_element_add_field_col(naturalBcFeName,
503 "DISPLACEMENT");
504 CHKERR m_field.modify_finite_element_add_field_data(naturalBcFeName,
505 "DISPLACEMENT");
506 CHKERR m_field.modify_finite_element_add_field_data(naturalBcFeName,
507 "GEOMETRY");
508 CHKERR m_field.modify_problem_add_finite_element("ELASTIC_MECHANICS",
510
511 Range natural_bc_faces;
512 auto meshsets_manager = m_field.getInterface<MeshsetsManager>();
513 for (auto m : meshsets_manager->getCubitMeshsetPtr(NODESET | FORCESET)) {
514 CHKERR mOab.get_entities_by_type(m->getMeshset(), MBTRI, natural_bc_faces,
515 true);
516 }
517 for (auto m : meshsets_manager->getCubitMeshsetPtr(SIDESET | PRESSURESET)) {
518 CHKERR mOab.get_entities_by_type(m->getMeshset(), MBTRI, natural_bc_faces,
519 true);
520 }
521 for (auto m : meshsets_manager->getCubitMeshsetPtr(
522 std::regex("(FORCE|PRESSURE)(.*)"))) {
523 CHKERR mOab.get_entities_by_type(m->getMeshset(), MBTRI, natural_bc_faces,
524 true);
525 }
526 CHKERR m_field.add_ents_to_finite_element_by_type(natural_bc_faces, MBTRI,
528 }
529
530 /****/
531 // build database
532
533 // build field
534 CHKERR m_field.build_fields();
535 Projection10NodeCoordsOnField ent_method_material(m_field, "GEOMETRY");
536 CHKERR m_field.loop_dofs("GEOMETRY", ent_method_material);
537
538 // build finite elemnts
539 CHKERR m_field.build_finite_elements();
540
541 // build adjacencies
542 CHKERR m_field.build_adjacencies(problem_bit_level);
543
544 /****/
545 ProblemsManager *prb_mng_ptr;
546 CHKERR m_field.getInterface(prb_mng_ptr);
547 // build problem
548 CHKERR prb_mng_ptr->buildProblem("ELASTIC_MECHANICS", true);
549 // partition
550 CHKERR prb_mng_ptr->partitionProblem("ELASTIC_MECHANICS");
551 CHKERR prb_mng_ptr->partitionFiniteElements("ELASTIC_MECHANICS", false, 0,
552 m_field.get_comm_size());
553 // what are ghost nodes, see Petsc Manual
554 CHKERR prb_mng_ptr->partitionGhostDofs("ELASTIC_MECHANICS");
555
557}
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition definitions.h:60
@ NOBASE
Definition definitions.h:59
@ NOFIELD
scalar or vector of scalars describe (no true field)
Definition definitions.h:84
@ H1
continuous field
Definition definitions.h:85
@ PRESSURESET
@ FORCESET
@ NODESET
@ SIDESET
@ INTERFACESET
#define _IT_CUBITMESHSETS_BY_BCDATA_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet in a moFEM field.
#define _IT_CUBITMESHSETS_FOR_LOOP_(MESHSET_MANAGER, IT)
Iterator that loops over all the Cubit MeshSets in a moFEM field.
MoFEMErrorCode partitionGhostDofs(const std::string name, int verb=VERBOSE)
determine ghost nodes
MoFEMErrorCode buildProblem(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures
MoFEMErrorCode partitionProblem(const std::string name, int verb=VERBOSE)
partition problem dofs (collective)
MoFEMErrorCode partitionFiniteElements(const std::string name, bool part_from_moab=false, int low_proc=-1, int hi_proc=-1, int verb=VERBOSE)
partition finite elements
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition Types.hpp:40
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
PetscErrorCode PetscOptionsGetReal(PetscOptions *, const char pre[], const char name[], PetscReal *dval, PetscBool *set)
Managing BitRefLevels.
MoFEMErrorCode setMeshsetFromFile(const string file_name, const bool clean_file_options=true)
add blocksets reading config file
Create interface from given surface and insert flat prisms in-between.
MoFEMErrorCode getSides(const int msId, const CubitBCType cubit_bc_type, const BitRefLevel mesh_bit_level, const bool recursive, int verb=QUIET)
Store tetrahedra from each side of the interface separately in two child meshsets of the parent meshs...
MoFEMErrorCode splitSides(const EntityHandle meshset, const BitRefLevel &bit, const int msId, const CubitBCType cubit_bc_type, const bool add_interface_entities, const bool recursive=false, int verb=QUIET)
Split nodes and other entities of tetrahedra on both sides of the interface and insert flat prisms in...
Problem manager is used to build and partition problems.
Projection of edge entities with one mid-node on hierarchical basis.

◆ solveSystem()

MoFEMErrorCode ArcLengthInterfaceExample::solveSystem ( )
protected

[Solve]

Examples
mofem/tutorials/cor-12_cohesive_interface/arc_length_interface.cpp.

Definition at line 934 of file arc_length_interface.cpp.

934 {
936
937 double min_arc_length_step = std::numeric_limits<double>::epsilon();
938 double max_arc_length_step = std::numeric_limits<double>::max();
939 CHKERR PetscOptionsGetReal(PETSC_NULLPTR, PETSC_NULLPTR, "-gamma", &gamma,
940 PETSC_NULLPTR);
941 CHKERR PetscOptionsGetReal(PETSC_NULLPTR, PETSC_NULLPTR,
942 "-min_arc_length_step", &min_arc_length_step,
943 PETSC_NULLPTR);
944 CHKERR PetscOptionsGetReal(PETSC_NULLPTR, PETSC_NULLPTR,
945 "-max_arc_length_step", &max_arc_length_step,
946 PETSC_NULLPTR);
947
948 if (min_arc_length_step <= 0.)
949 SETERRQ(PETSC_COMM_WORLD, MOFEM_INVALID_DATA,
950 "-min_arc_length_step must be positive");
951 if (max_arc_length_step <= 0.)
952 SETERRQ(PETSC_COMM_WORLD, MOFEM_INVALID_DATA,
953 "-max_arc_length_step must be positive");
954 if (min_arc_length_step > max_arc_length_step)
955 SETERRQ(PETSC_COMM_WORLD, MOFEM_INVALID_DATA,
956 "-min_arc_length_step must not exceed -max_arc_length_step");
957
958 auto &m_field = *mField;
959 auto &step = *stepPtr;
960 auto &step_size = *stepSizePtr;
961
962 auto &cohesive_elements = *cohesiveElementsPtr;
963 auto &post_proc = *postProcPtr;
964
965 bool converged_state = false;
966 for (; step < maxSteps; step++) {
967
968 if (step == 1) {
969 MOFEM_LOG_C("ARC_LENGTH", Sev::inform, "Load Step %d step_size = %6.4e",
970 step, step_size);
971 CHKERR arcCtx->setS(step_size);
972 CHKERR arcCtx->setAlphaBeta(0, 1);
973 CHKERR VecCopy(d, arcCtx->x0);
974 double dlambda;
975 CHKERR arcMethodPtr->calculate_init_dlambda(&dlambda);
976 CHKERR arcMethodPtr->set_dlambda_to_x(dRaw, dlambda);
977 } else if (step == 2) {
978 CHKERR arcCtx->setAlphaBeta(1, 0);
979 CHKERR arcMethodPtr->calculate_dx_and_dlambda(dRaw);
980 CHKERR arcMethodPtr->calculate_lambda_int(step_size);
981 CHKERR arcCtx->setS(step_size);
982 double dlambda = arcCtx->dLambda;
983 double dx_nrm;
984 CHKERR VecNorm(arcCtx->dx, NORM_2, &dx_nrm);
985 MOFEM_LOG_C("ARC_LENGTH", Sev::inform,
986 "Load Step %d step_size = %6.4e dlambda0 = %6.4e "
987 "dx_nrm = %6.4e dx2 = %6.4e",
988 step, step_size, dlambda, dx_nrm, arcCtx->dx2);
989 CHKERR VecCopy(d, arcCtx->x0);
990 CHKERR VecAXPY(d, 1., arcCtx->dx);
991 CHKERR arcMethodPtr->set_dlambda_to_x(dRaw, dlambda);
992 } else {
993 CHKERR arcMethodPtr->calculate_dx_and_dlambda(dRaw);
994 CHKERR arcMethodPtr->calculate_lambda_int(step_size);
995 // step_size0_1/step_size0 = step_stize1/step_size
996 // step_size0_1 = step_size0*(step_stize1/step_size)
997 step_size *= reduction;
998 CHKERR arcCtx->setS(step_size);
999 double dlambda = reduction * arcCtx->dLambda;
1000 CHKERR VecScale(arcCtx->dx, reduction);
1001 double dx_nrm;
1002 CHKERR VecNorm(arcCtx->dx, NORM_2, &dx_nrm);
1003 MOFEM_LOG_C("ARC_LENGTH", Sev::inform,
1004 "Load Step %d step_size = %6.4e dlambda0 = %6.4e "
1005 "dx_nrm = %6.4e dx2 = %6.4e",
1006 step, step_size, dlambda, dx_nrm, arcCtx->dx2);
1007 CHKERR VecCopy(d, arcCtx->x0);
1008 CHKERR VecAXPY(d, 1., arcCtx->dx);
1009 CHKERR arcMethodPtr->set_dlambda_to_x(dRaw, dlambda);
1010 }
1011
1012 CHKERR SNESSolve(snes, PETSC_NULLPTR, d);
1013
1014 // Distribute displacements on all processors
1015 CHKERR m_field.getInterface<VecManager>()->setGlobalGhostVector(
1016 "ELASTIC_MECHANICS", COL, d, INSERT_VALUES, SCATTER_REVERSE);
1017 CHKERR m_field.loop_finite_elements("ELASTIC_MECHANICS", "INTERFACE",
1018 cohesive_elements.getFeHistory(), 0,
1019 m_field.get_comm_size());
1020 // Remove nodes of damaged prisms
1021 CHKERR arcMethodPtr->remove_damaged_prisms_nodes();
1022
1023 int its;
1024 CHKERR SNESGetIterationNumber(snes, &its);
1025 MOFEM_LOG_C("ARC_LENGTH", Sev::inform, "number of Newton iterations = %d",
1026 its);
1027
1028 SNESConvergedReason reason;
1029 CHKERR SNESGetConvergedReason(snes, &reason);
1030
1031 if (reason < 0) {
1032 CHKERR arcCtx->setAlphaBeta(1, 0);
1033 reduction = 0.1;
1034 converged_state = false;
1035 continue;
1036 } else {
1037 if (step > 1 && converged_state) {
1038 reduction = pow((double)itsD / (double)(its + 1), gamma);
1039 reduction =
1040 std::clamp(reduction, min_arc_length_step / std::abs(step_size),
1041 max_arc_length_step / std::abs(step_size));
1042 MOFEM_LOG_C("ARC_LENGTH", Sev::inform, "reduction step_size = %6.4e",
1043 reduction);
1044 }
1045
1046 // Save data on mesh
1047 CHKERR m_field.getInterface<VecManager>()->setGlobalGhostVector(
1048 "ELASTIC_MECHANICS", COL, d, INSERT_VALUES, SCATTER_REVERSE);
1049 CHKERR m_field.getInterface<VecManager>()->setOtherGlobalGhostVector(
1050 "ELASTIC_MECHANICS", "DISPLACEMENT", "X0_DISPLACEMENT", COL,
1051 arcCtx->x0, INSERT_VALUES, SCATTER_REVERSE);
1052 converged_state = true;
1053 }
1054 //
1055 if (reason > 0) {
1057 }
1058
1059 if (step % 1 == 0) {
1060
1061 CHKERR m_field.loop_finite_elements("ELASTIC_MECHANICS", "ELASTIC",
1062 post_proc);
1063 std::ostringstream ss;
1064 ss << "out_values_" << step << ".h5m";
1065 CHKERR post_proc.writeFile(ss.str().c_str());
1066 }
1067 }
1068
1070}
MoFEMErrorCode evaluateFieldAtPoint(const int load_step)
[Assemble system]

Member Data Documentation

◆ aij

SmartPetscObj<Mat> ArcLengthInterfaceExample::aij
protected

◆ arcCtx

boost::shared_ptr<ArcLengthCtx> ArcLengthInterfaceExample::arcCtx
protected

◆ arcMethodPtr

boost::shared_ptr<ArcLengthIntElemFEMethod> ArcLengthInterfaceExample::arcMethodPtr
protected

◆ cohesiveElementsPtr

boost::shared_ptr<CohesiveInterfaceElement> ArcLengthInterfaceExample::cohesiveElementsPtr
protected

◆ corePtr

boost::shared_ptr<MoFEM::Core> ArcLengthInterfaceExample::corePtr
protected

◆ d

SmartPetscObj<Vec> ArcLengthInterfaceExample::d
protected

◆ doEvalField

PetscBool ArcLengthInterfaceExample::doEvalField = PETSC_FALSE
protected

◆ dRaw

Vec ArcLengthInterfaceExample::dRaw = nullptr
protected

◆ elasticLhsFe

boost::shared_ptr<DomainEle> ArcLengthInterfaceExample::elasticLhsFe
protected

◆ elasticRhsFe

boost::shared_ptr<DomainEle> ArcLengthInterfaceExample::elasticRhsFe
protected

◆ f

SmartPetscObj<Vec> ArcLengthInterfaceExample::f
protected

◆ fieldEvalCoords

std::array<double, SPACE_DIM> ArcLengthInterfaceExample::fieldEvalCoords {0., 0., 0.}
protected

◆ fieldEvalData

boost::shared_ptr<FieldEvaluatorInterface::SetPtsData> ArcLengthInterfaceExample::fieldEvalData
protected

◆ fieldEvalDispPtr

boost::shared_ptr<MatrixDouble> ArcLengthInterfaceExample::fieldEvalDispPtr
protected

◆ fieldEvalStressPtr

boost::shared_ptr<MatrixDouble> ArcLengthInterfaceExample::fieldEvalStressPtr
protected

◆ gamma

double ArcLengthInterfaceExample::gamma = 0.5
protected

◆ interfaceMaterials

boost::ptr_vector<CohesiveInterfaceElement::PhysicalEquation> ArcLengthInterfaceExample::interfaceMaterials
protected

◆ itsD

PetscInt ArcLengthInterfaceExample::itsD = 6
protected

◆ matCtx

boost::scoped_ptr<ArcLengthMatShell> ArcLengthInterfaceExample::matCtx
protected

◆ maxSteps

PetscInt ArcLengthInterfaceExample::maxSteps = 5
protected

◆ mField

MoFEM::Interface* ArcLengthInterfaceExample::mField = nullptr
protected

◆ mOab

moab::Interface& ArcLengthInterfaceExample::mOab
protected

◆ naturalBcFe

boost::shared_ptr<BoundaryEle> ArcLengthInterfaceExample::naturalBcFe
protected

◆ naturalBcFeName

const std::string ArcLengthInterfaceExample::naturalBcFeName = "NATURAL_BC"
protected

◆ order

PetscInt ArcLengthInterfaceExample::order = 2
protected

◆ pcCtx

boost::scoped_ptr<PCArcLengthCtx> ArcLengthInterfaceExample::pcCtx
protected

◆ postProcPtr

boost::shared_ptr<PostProcEle> ArcLengthInterfaceExample::postProcPtr
protected

◆ prePostProcFePtr

boost::shared_ptr<AssembleRhsVectors> ArcLengthInterfaceExample::prePostProcFePtr
protected

◆ reduction

double ArcLengthInterfaceExample::reduction = 1.
protected

◆ shellAij

SmartPetscObj<Mat> ArcLengthInterfaceExample::shellAij
protected

◆ snes

SmartPetscObj<SNES> ArcLengthInterfaceExample::snes
protected

◆ snesCtxPtr

boost::shared_ptr<ArcLengthSnesCtx> ArcLengthInterfaceExample::snesCtxPtr
protected

◆ stepPtr

int* ArcLengthInterfaceExample::stepPtr = nullptr
protected

◆ stepSizePtr

double* ArcLengthInterfaceExample::stepSizePtr = nullptr
protected

◆ stepSizeReduction

PetscScalar ArcLengthInterfaceExample::stepSizeReduction = 1.
protected

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