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 4228 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 4230 of file EshelbianPlasticity.cpp.

4231 {
4232
4233#ifdef ENABLE_PYTHON_BINDING
4234 auto setup_sdf = [&]() { return setupContactSdf(ep_ptr->mField); };
4235#endif
4236
4237 auto setup_ts_monitor = [&]() {
4238 boost::shared_ptr<TsCtx> ts_ctx;
4240 "get TS ctx");
4241 if (set_ts_monitor) {
4243 TSMonitorSet(ts, TsMonitorSet, ts_ctx.get(), PETSC_NULLPTR),
4244 "TS monitor set");
4245 auto monitor_ptr = boost::make_shared<EshelbianMonitor>(*ep_ptr);
4246 auto testing_monitor_ptr =
4247 boost::make_shared<EshelbianTestingMonitor>(*ep_ptr, monitor_ptr);
4248 ts_ctx->getLoopsMonitor().push_back(
4249 TsCtx::PairNameFEMethodPtr(ep_ptr->elementVolumeName, monitor_ptr));
4250
4251 PetscBool test_cook_flg = PETSC_FALSE;
4252 PetscBool test_cook_pts_flg = PETSC_FALSE;
4253 PetscInt atom_test = 0;
4254 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-test_cook",
4255 &test_cook_flg, PETSC_NULLPTR);
4256 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-test_cook_pts",
4257 &test_cook_pts_flg, PETSC_NULLPTR);
4258 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-atom_test", &atom_test,
4259 PETSC_NULLPTR);
4260 if (atom_test || test_cook_flg || test_cook_pts_flg) {
4262 ep_ptr->elementVolumeName, testing_monitor_ptr));
4263 }
4264 }
4265 MOFEM_LOG("EP", Sev::inform) << "TS monitor setup";
4266 return std::make_tuple(ts_ctx);
4267 };
4268
4269 auto setup_snes_monitor = [&]() {
4271 SNES snes;
4272 CHKERR TSGetSNES(ts, &snes);
4273 auto snes_ctx = getDMSnesCtx(ep_ptr->dmElastic);
4274 CHKERR SNESMonitorSet(snes,
4275 (MoFEMErrorCode (*)(SNES, PetscInt, PetscReal,
4276 void *))MoFEMSNESMonitorEnergy,
4277 (void *)(snes_ctx.get()), PETSC_NULLPTR);
4278 MOFEM_LOG("EP", Sev::inform) << "SNES monitor setup";
4280 };
4281
4282 auto setup_snes_conergence_test = [&]() {
4284
4285 auto snes_convergence_test = [](SNES snes, PetscInt it, PetscReal xnorm,
4286 PetscReal snorm, PetscReal fnorm,
4287 SNESConvergedReason *reason, void *cctx) {
4289 // EshelbianCore *ep_ptr = (EshelbianCore *)cctx;
4290 CHKERR SNESConvergedDefault(snes, it, xnorm, snorm, fnorm, reason,
4291 PETSC_NULLPTR);
4292
4293 Vec x_update, r;
4294 CHKERR SNESGetSolutionUpdate(snes, &x_update);
4295 CHKERR SNESGetFunction(snes, &r, PETSC_NULLPTR, PETSC_NULLPTR);
4296
4298 };
4299
4300 // SNES snes;
4301 // CHKERR TSGetSNES(ts, &snes);
4302 // CHKERR SNESSetConvergenceTest(snes, snes_convergence_test, ep_ptr,
4303 // PETSC_NULLPTR);
4304 // MOFEM_LOG("EP", Sev::inform) << "SNES convergence test setup";
4306 };
4307
4308 auto setup_section = [&]() {
4309 PetscSection section_raw;
4310 CHK_THROW_MESSAGE(DMGetSection(ep_ptr->dmElastic, &section_raw),
4311 "get DM section");
4312 int num_fields;
4313 CHK_THROW_MESSAGE(PetscSectionGetNumFields(section_raw, &num_fields),
4314 "get num fields");
4315 for (int ff = 0; ff != num_fields; ff++) {
4316 const char *field_name;
4318 PetscSectionGetFieldName(section_raw, ff, &field_name),
4319 "get field name");
4320 MOFEM_LOG_C("EP", Sev::inform, "Field %d name %s", ff, field_name);
4321 }
4322 return SmartPetscObj<PetscSection>(section_raw, true);
4323 };
4324
4325 auto set_vector_on_mesh = [&]() {
4327 CHKERR DMoFEMMeshToLocalVector(ep_ptr->dmElastic, x, INSERT_VALUES,
4328 SCATTER_FORWARD);
4329 CHKERR VecGhostUpdateBegin(x, INSERT_VALUES, SCATTER_FORWARD);
4330 CHKERR VecGhostUpdateEnd(x, INSERT_VALUES, SCATTER_FORWARD);
4331 MOFEM_LOG("EP", Sev::inform) << "Vector set on mesh";
4333 };
4334
4335 auto setup_schur_block_solver = [&]() {
4336 MOFEM_LOG("EP", Sev::inform) << "Setting up Schur block solver";
4337 CHK_THROW_MESSAGE(TSAppendOptionsPrefix(ts, "elastic_"),
4338 "append options prefix");
4339 CHK_THROW_MESSAGE(TSSetFromOptions(ts), "set from options");
4340 CHK_THROW_MESSAGE(TSSetDM(ts, ep_ptr->dmElastic), "set DM");
4341 // Adding field split solver
4342 boost::shared_ptr<EshelbianCore::SetUpSchur> schur_ptr;
4343 if constexpr (A == AssemblyType::BLOCK_MAT) {
4344 schur_ptr =
4346 CHK_THROW_MESSAGE(schur_ptr->setUp(ts), "setup schur");
4347 }
4348 MOFEM_LOG("EP", Sev::inform) << "Setting up Schur block solver done";
4349 return schur_ptr;
4350 };
4351
4352 // Warning: sequence of construction is not guaranteed for tuple. You have
4353 // to enforce order by proper packaging.
4354
4355#ifdef ENABLE_PYTHON_BINDING
4356 return std::make_tuple(setup_sdf(), setup_ts_monitor(),
4357 setup_snes_monitor(), setup_snes_conergence_test(),
4358 setup_section(), set_vector_on_mesh(),
4359 setup_schur_block_solver());
4360#else
4361 return std::make_tuple(setup_ts_monitor(), setup_snes_monitor(),
4362 setup_snes_conergence_test(), setup_section(),
4363 set_vector_on_mesh(), setup_schur_block_solver());
4364#endif
4365 }
#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(MoFEM::Interface &m_field)
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: