v0.16.0
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 4030 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 4032 of file EshelbianPlasticity.cpp.

4033 {
4034
4035#ifdef ENABLE_PYTHON_BINDING
4036 auto setup_sdf = [&]() { return setupContactSdf(); };
4037#endif
4038
4039 auto setup_ts_monitor = [&]() {
4040 boost::shared_ptr<TsCtx> ts_ctx;
4042 "get TS ctx");
4043 if (set_ts_monitor) {
4045 TSMonitorSet(ts, TsMonitorSet, ts_ctx.get(), PETSC_NULLPTR),
4046 "TS monitor set");
4047 auto monitor_ptr = boost::make_shared<EshelbianMonitor>(*ep_ptr);
4048 auto testing_monitor_ptr =
4049 boost::make_shared<EshelbianTestingMonitor>(*ep_ptr, monitor_ptr);
4050 ts_ctx->getLoopsMonitor().push_back(
4051 TsCtx::PairNameFEMethodPtr(ep_ptr->elementVolumeName, monitor_ptr));
4052
4053 PetscBool test_cook_flg = PETSC_FALSE;
4054 PetscBool test_cook_pts_flg = PETSC_FALSE;
4055 PetscInt atom_test = 0;
4056 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-test_cook",
4057 &test_cook_flg, PETSC_NULLPTR);
4058 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-test_cook_pts",
4059 &test_cook_pts_flg, PETSC_NULLPTR);
4060 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-atom_test", &atom_test,
4061 PETSC_NULLPTR);
4062 if (atom_test || test_cook_flg || test_cook_pts_flg) {
4064 ep_ptr->elementVolumeName, testing_monitor_ptr));
4065 }
4066 }
4067 MOFEM_LOG("EP", Sev::inform) << "TS monitor setup";
4068 return std::make_tuple(ts_ctx);
4069 };
4070
4071 auto setup_snes_monitor = [&]() {
4073 SNES snes;
4074 CHKERR TSGetSNES(ts, &snes);
4075 auto snes_ctx = getDMSnesCtx(ep_ptr->dmElastic);
4076 CHKERR SNESMonitorSet(snes,
4077 (MoFEMErrorCode(*)(SNES, PetscInt, PetscReal,
4078 void *))MoFEMSNESMonitorEnergy,
4079 (void *)(snes_ctx.get()), PETSC_NULLPTR);
4080 MOFEM_LOG("EP", Sev::inform) << "SNES monitor setup";
4082 };
4083
4084 auto setup_snes_conergence_test = [&]() {
4086
4087 auto snes_convergence_test = [](SNES snes, PetscInt it, PetscReal xnorm,
4088 PetscReal snorm, PetscReal fnorm,
4089 SNESConvergedReason *reason, void *cctx) {
4091 // EshelbianCore *ep_ptr = (EshelbianCore *)cctx;
4092 CHKERR SNESConvergedDefault(snes, it, xnorm, snorm, fnorm, reason,
4093 PETSC_NULLPTR);
4094
4095 Vec x_update, r;
4096 CHKERR SNESGetSolutionUpdate(snes, &x_update);
4097 CHKERR SNESGetFunction(snes, &r, PETSC_NULLPTR, PETSC_NULLPTR);
4098
4100 };
4101
4102 // SNES snes;
4103 // CHKERR TSGetSNES(ts, &snes);
4104 // CHKERR SNESSetConvergenceTest(snes, snes_convergence_test, ep_ptr,
4105 // PETSC_NULLPTR);
4106 // MOFEM_LOG("EP", Sev::inform) << "SNES convergence test setup";
4108 };
4109
4110 auto setup_section = [&]() {
4111 PetscSection section_raw;
4112 CHK_THROW_MESSAGE(DMGetSection(ep_ptr->dmElastic, &section_raw),
4113 "get DM section");
4114 int num_fields;
4115 CHK_THROW_MESSAGE(PetscSectionGetNumFields(section_raw, &num_fields),
4116 "get num fields");
4117 for (int ff = 0; ff != num_fields; ff++) {
4118 const char *field_name;
4120 PetscSectionGetFieldName(section_raw, ff, &field_name),
4121 "get field name");
4122 MOFEM_LOG_C("EP", Sev::inform, "Field %d name %s", ff, field_name);
4123 }
4124 return SmartPetscObj<PetscSection>(section_raw, true);
4125 };
4126
4127 auto set_vector_on_mesh = [&]() {
4129 CHKERR DMoFEMMeshToLocalVector(ep_ptr->dmElastic, x, INSERT_VALUES,
4130 SCATTER_FORWARD);
4131 CHKERR VecGhostUpdateBegin(x, INSERT_VALUES, SCATTER_FORWARD);
4132 CHKERR VecGhostUpdateEnd(x, INSERT_VALUES, SCATTER_FORWARD);
4133 MOFEM_LOG("EP", Sev::inform) << "Vector set on mesh";
4135 };
4136
4137 auto setup_schur_block_solver = [&]() {
4138 MOFEM_LOG("EP", Sev::inform) << "Setting up Schur block solver";
4139 CHK_THROW_MESSAGE(TSAppendOptionsPrefix(ts, "elastic_"),
4140 "append options prefix");
4141 CHK_THROW_MESSAGE(TSSetFromOptions(ts), "set from options");
4142 CHK_THROW_MESSAGE(TSSetDM(ts, ep_ptr->dmElastic), "set DM");
4143 // Adding field split solver
4144 boost::shared_ptr<EshelbianCore::SetUpSchur> schur_ptr;
4145 if constexpr (A == AssemblyType::BLOCK_MAT) {
4146 schur_ptr =
4148 CHK_THROW_MESSAGE(schur_ptr->setUp(ts), "setup schur");
4149 }
4150 MOFEM_LOG("EP", Sev::inform) << "Setting up Schur block solver done";
4151 return schur_ptr;
4152 };
4153
4154 // Warning: sequence of construction is not guaranteed for tuple. You have
4155 // to enforce order by proper packaging.
4156
4157#ifdef ENABLE_PYTHON_BINDING
4158 return std::make_tuple(setup_sdf(), setup_ts_monitor(),
4159 setup_snes_monitor(), setup_snes_conergence_test(),
4160 setup_section(), set_vector_on_mesh(),
4161 setup_schur_block_solver());
4162#else
4163 return std::make_tuple(setup_ts_monitor(), setup_snes_monitor(),
4164 setup_snes_conergence_test(), setup_section(),
4165 set_vector_on_mesh(), setup_schur_block_solver());
4166#endif
4167 }
#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 DMMoFEMGetTsCtx(DM dm, MoFEM::TsCtx **ts_ctx)
get MoFEM::TsCtx data structure
Definition DMMoFEM.cpp:1132
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:514
#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:656
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)
auto getDMSnesCtx(DM dm)
Get SNES context data structure used by DM.
Definition DMMoFEM.hpp:1265
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
int atom_test
Atom test.
Definition plastic.cpp:122

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