v0.15.4
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
EshelbianPlasticity::solve_elastic_setup Struct Reference

Static Public Member Functions

static auto setup (EshelbianCore *ep_ptr, TS ts, Vec x, bool set_ts_monitor)
 

Detailed Description

Definition at line 3624 of file EshelbianPlasticity.cpp.

Member Function Documentation

◆ setup()

static auto EshelbianPlasticity::solve_elastic_setup::setup ( EshelbianCore ep_ptr,
TS  ts,
Vec  x,
bool  set_ts_monitor 
)
inlinestatic

Definition at line 3626 of file EshelbianPlasticity.cpp.

3627 {
3628
3629#ifdef ENABLE_PYTHON_BINDING
3630 auto setup_sdf = [&]() { return setupContactSdf(); };
3631#endif
3632
3633 auto setup_ts_monitor = [&]() {
3634 boost::shared_ptr<TsCtx> ts_ctx;
3636 "get TS ctx");
3637 if (set_ts_monitor) {
3639 TSMonitorSet(ts, TsMonitorSet, ts_ctx.get(), PETSC_NULLPTR),
3640 "TS monitor set");
3641 auto monitor_ptr = boost::make_shared<EshelbianMonitor>(*ep_ptr);
3642 ts_ctx->getLoopsMonitor().push_back(
3643 TsCtx::PairNameFEMethodPtr(ep_ptr->elementVolumeName, monitor_ptr));
3644 }
3645 MOFEM_LOG("EP", Sev::inform) << "TS monitor setup";
3646 return std::make_tuple(ts_ctx);
3647 };
3648
3649 auto setup_snes_monitor = [&]() {
3651 SNES snes;
3652 CHKERR TSGetSNES(ts, &snes);
3653 auto snes_ctx = getDMSnesCtx(ep_ptr->dmElastic);
3654 CHKERR SNESMonitorSet(snes,
3655 (MoFEMErrorCode(*)(SNES, PetscInt, PetscReal,
3656 void *))MoFEMSNESMonitorEnergy,
3657 (void *)(snes_ctx.get()), PETSC_NULLPTR);
3658 MOFEM_LOG("EP", Sev::inform) << "SNES monitor setup";
3660 };
3661
3662 auto setup_snes_conergence_test = [&]() {
3664
3665 auto snes_convergence_test = [](SNES snes, PetscInt it, PetscReal xnorm,
3666 PetscReal snorm, PetscReal fnorm,
3667 SNESConvergedReason *reason, void *cctx) {
3669 // EshelbianCore *ep_ptr = (EshelbianCore *)cctx;
3670 CHKERR SNESConvergedDefault(snes, it, xnorm, snorm, fnorm, reason,
3671 PETSC_NULLPTR);
3672
3673 Vec x_update, r;
3674 CHKERR SNESGetSolutionUpdate(snes, &x_update);
3675 CHKERR SNESGetFunction(snes, &r, PETSC_NULLPTR, PETSC_NULLPTR);
3676
3678 };
3679
3680 // SNES snes;
3681 // CHKERR TSGetSNES(ts, &snes);
3682 // CHKERR SNESSetConvergenceTest(snes, snes_convergence_test, ep_ptr,
3683 // PETSC_NULLPTR);
3684 // MOFEM_LOG("EP", Sev::inform) << "SNES convergence test setup";
3686 };
3687
3688 auto setup_section = [&]() {
3689 PetscSection section_raw;
3690 CHK_THROW_MESSAGE(DMGetSection(ep_ptr->dmElastic, &section_raw),
3691 "get DM section");
3692 int num_fields;
3693 CHK_THROW_MESSAGE(PetscSectionGetNumFields(section_raw, &num_fields),
3694 "get num fields");
3695 for (int ff = 0; ff != num_fields; ff++) {
3696 const char *field_name;
3698 PetscSectionGetFieldName(section_raw, ff, &field_name),
3699 "get field name");
3700 MOFEM_LOG_C("EP", Sev::inform, "Field %d name %s", ff, field_name);
3701 }
3702 return SmartPetscObj<PetscSection>(section_raw, true);
3703 };
3704
3705 auto set_vector_on_mesh = [&]() {
3707 CHKERR DMoFEMMeshToLocalVector(ep_ptr->dmElastic, x, INSERT_VALUES,
3708 SCATTER_FORWARD);
3709 CHKERR VecGhostUpdateBegin(x, INSERT_VALUES, SCATTER_FORWARD);
3710 CHKERR VecGhostUpdateEnd(x, INSERT_VALUES, SCATTER_FORWARD);
3711 MOFEM_LOG("EP", Sev::inform) << "Vector set on mesh";
3713 };
3714
3715 auto setup_schur_block_solver = [&]() {
3716 MOFEM_LOG("EP", Sev::inform) << "Setting up Schur block solver";
3717 CHK_THROW_MESSAGE(TSAppendOptionsPrefix(ts, "elastic_"),
3718 "append options prefix");
3719 CHK_THROW_MESSAGE(TSSetFromOptions(ts), "set from options");
3720 CHK_THROW_MESSAGE(TSSetDM(ts, ep_ptr->dmElastic), "set DM");
3721 // Adding field split solver
3722 boost::shared_ptr<EshelbianCore::SetUpSchur> schur_ptr;
3723 if constexpr (A == AssemblyType::BLOCK_MAT) {
3724 schur_ptr =
3726 CHK_THROW_MESSAGE(schur_ptr->setUp(ts), "setup schur");
3727 }
3728 MOFEM_LOG("EP", Sev::inform) << "Setting up Schur block solver done";
3729 return schur_ptr;
3730 };
3731
3732 // Warning: sequence of construction is not guaranteed for tuple. You have
3733 // to enforce order by proper packaging.
3734
3735#ifdef ENABLE_PYTHON_BINDING
3736 return std::make_tuple(setup_sdf(), setup_ts_monitor(),
3737 setup_snes_monitor(), setup_snes_conergence_test(),
3738 setup_section(), set_vector_on_mesh(),
3739 setup_schur_block_solver());
3740#else
3741 return std::make_tuple(setup_ts_monitor(), setup_snes_monitor(),
3742 setup_snes_conergence_test(), setup_section(),
3743 set_vector_on_mesh(), setup_schur_block_solver());
3744#endif
3745 }
#define MOFEM_LOG_C(channel, severity, format,...)
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
Definition DMMoFEM.cpp:514
PetscErrorCode DMMoFEMGetTsCtx(DM dm, MoFEM::TsCtx **ts_ctx)
get MoFEM::TsCtx data structure
Definition DMMoFEM.cpp:1132
#define MOFEM_LOG(channel, severity)
Log.
MoFEM::TsCtx * ts_ctx
const FTensor::Tensor2< T, Dim, Dim > Vec
boost::shared_ptr< ContactSDFPython > setupContactSdf()
Read SDF file and setup contact SDF.
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
PetscErrorCode TsMonitorSet(TS ts, PetscInt step, PetscReal t, Vec u, void *ctx)
Set monitor for TS solver.
Definition TsCtx.cpp:263
MoFEMErrorCode MoFEMSNESMonitorEnergy(SNES snes, PetscInt its, PetscReal fgnorm, SnesCtx *ctx)
Sens monitor printing residual field by field.
Definition SnesCtx.cpp:652
auto getDMSnesCtx(DM dm)
Get SNES context data structure used by DM.
Definition DMMoFEM.hpp:1262
int r
Definition sdf.py:205
constexpr AssemblyType A
constexpr auto field_name
static boost::shared_ptr< SetUpSchur > createSetUpSchur(MoFEM::Interface &m_field, EshelbianCore *ep_core_ptr)
MoFEM::Interface & mField
const std::string elementVolumeName
SmartPetscObj< DM > dmElastic
Elastic problem.
intrusive_ptr for managing petsc objects
FEMethodsSequence & getLoopsMonitor()
Get the loops to do Monitor object.
Definition TsCtx.hpp:102

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