v0.16.3
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 4272 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 4274 of file EshelbianPlasticity.cpp.

4275 {
4276
4277#ifdef ENABLE_PYTHON_BINDING
4278 auto setup_sdf = [&]() { return setupContactSdf(ep_ptr->mField); };
4279#endif
4280
4281 auto setup_ts_monitor = [&]() {
4282 boost::shared_ptr<TsCtx> ts_ctx;
4284 "get TS ctx");
4285 if (set_ts_monitor) {
4287 TSMonitorSet(ts, TsMonitorSet, ts_ctx.get(), PETSC_NULLPTR),
4288 "TS monitor set");
4289 auto monitor_ptr = boost::make_shared<EshelbianMonitor>(*ep_ptr);
4290 ts_ctx->getLoopsMonitor().push_back(
4291 TsCtx::PairNameFEMethodPtr(ep_ptr->elementVolumeName, monitor_ptr));
4292 // Registered after TsMonitorSet so they see this step's reactions.
4294 EshelbianTesting::addMonitorTests(*ep_ptr, ts, monitor_ptr),
4295 "add monitor tests");
4297 "add final tests");
4298 }
4299 MOFEM_LOG("EP", Sev::inform) << "TS monitor setup";
4300 return std::make_tuple(ts_ctx);
4301 };
4302
4303 auto setup_snes_monitor = [&]() {
4305 SNES snes;
4306 CHKERR TSGetSNES(ts, &snes);
4307 auto snes_ctx = getDMSnesCtx(ep_ptr->dmElastic);
4308 CHKERR SNESMonitorSet(snes,
4309 (MoFEMErrorCode (*)(SNES, PetscInt, PetscReal,
4310 void *))MoFEMSNESMonitorEnergy,
4311 (void *)(snes_ctx.get()), PETSC_NULLPTR);
4312 MOFEM_LOG("EP", Sev::inform) << "SNES monitor setup";
4314 };
4315
4316 auto setup_snes_convergence_test = [&]() {
4320 (ep_ptr->dynamicAtol > 0 || ep_ptr->dynamicRtol > 0)) {
4321 auto snes_convergence_test =
4322 [](SNES snes, PetscInt it, PetscReal xnorm, PetscReal snorm,
4323 PetscReal fnorm, SNESConvergedReason *reason, void *cctx) {
4325 auto ep_ptr = static_cast<EshelbianCore *>(cctx);
4326 CHKERR SNESConvergedDefault(snes, it, xnorm, snorm, fnorm, reason,
4327 PETSC_NULLPTR);
4328
4329 if (it == 0) {
4330 if (ep_ptr->dynamicInitialResidual < 0)
4331 ep_ptr->dynamicInitialResidual = fnorm;
4332
4333 if (ep_ptr->dynamicAtol > 0 && fnorm < ep_ptr->dynamicAtol) {
4334 *reason = SNES_BREAKOUT_INNER_ITER;
4336 "EP", Sev::inform,
4337 "Stopping dynamic relaxation: SNES iteration 0 residual "
4338 "%3.4e < %3.4e",
4339 static_cast<double>(fnorm),
4340 static_cast<double>(ep_ptr->dynamicAtol));
4341 } else if (ep_ptr->dynamicRtol > 0 &&
4342 fnorm < ep_ptr->dynamicRtol *
4343 ep_ptr->dynamicInitialResidual) {
4344 *reason = SNES_BREAKOUT_INNER_ITER;
4346 "EP", Sev::inform,
4347 "Stopping dynamic relaxation: SNES iteration 0 residual "
4348 "%3.4e < %3.4e * initial residual %3.4e",
4349 static_cast<double>(fnorm),
4350 static_cast<double>(ep_ptr->dynamicRtol),
4351 static_cast<double>(ep_ptr->dynamicInitialResidual));
4352 }
4353
4354 if (*reason == SNES_BREAKOUT_INNER_ITER) {
4355 PetscObject ts_obj = PETSC_NULLPTR;
4356 CHKERR PetscObjectQuery((PetscObject)snes,
4357 "dynamic_relaxation_ts", &ts_obj);
4358 CHKERR TSSetConvergedReason((TS)ts_obj, TS_CONVERGED_USER);
4359 }
4360 }
4361
4363 };
4364
4365 SNES snes;
4366 CHKERR TSGetSNES(ts, &snes);
4367 CHKERR PetscObjectCompose((PetscObject)snes, "dynamic_relaxation_ts",
4368 (PetscObject)ts);
4369 CHKERR SNESSetConvergenceTest(snes, snes_convergence_test, ep_ptr,
4370 PETSC_NULLPTR);
4371 MOFEM_LOG("EP", Sev::inform) << "SNES convergence test setup";
4372 }
4374 };
4375
4376 auto setup_section = [&]() {
4377 PetscSection section_raw;
4378 CHK_THROW_MESSAGE(DMGetSection(ep_ptr->dmElastic, &section_raw),
4379 "get DM section");
4380 int num_fields;
4381 CHK_THROW_MESSAGE(PetscSectionGetNumFields(section_raw, &num_fields),
4382 "get num fields");
4383 for (int ff = 0; ff != num_fields; ff++) {
4384 const char *field_name;
4386 PetscSectionGetFieldName(section_raw, ff, &field_name),
4387 "get field name");
4388 MOFEM_LOG_C("EP", Sev::inform, "Field %d name %s", ff, field_name);
4389 }
4390 return SmartPetscObj<PetscSection>(section_raw, true);
4391 };
4392
4393 auto set_vector_on_mesh = [&]() {
4395 CHKERR DMoFEMMeshToLocalVector(ep_ptr->dmElastic, x, INSERT_VALUES,
4396 SCATTER_FORWARD);
4397 CHKERR VecGhostUpdateBegin(x, INSERT_VALUES, SCATTER_FORWARD);
4398 CHKERR VecGhostUpdateEnd(x, INSERT_VALUES, SCATTER_FORWARD);
4399 MOFEM_LOG("EP", Sev::inform) << "Vector set on mesh";
4401 };
4402
4403 auto setup_schur_block_solver = [&]() {
4404 MOFEM_LOG("EP", Sev::inform) << "Setting up Schur block solver";
4405 CHK_THROW_MESSAGE(TSAppendOptionsPrefix(ts, "elastic_"),
4406 "append options prefix");
4407 CHK_THROW_MESSAGE(TSSetFromOptions(ts), "set from options");
4408 CHK_THROW_MESSAGE(TSSetDM(ts, ep_ptr->dmElastic), "set DM");
4409 // Adding field split solver
4410 boost::shared_ptr<EshelbianCore::SetUpSchur> schur_ptr;
4411 if constexpr (A == AssemblyType::BLOCK_MAT) {
4412 schur_ptr =
4414 CHK_THROW_MESSAGE(schur_ptr->setUp(ts), "setup schur");
4415 }
4416 MOFEM_LOG("EP", Sev::inform) << "Setting up Schur block solver done";
4417 return schur_ptr;
4418 };
4419
4421 "setup elastic pre-step");
4422
4423 // Warning: sequence of construction is not guaranteed for tuple. You have
4424 // to enforce order by proper packaging.
4425
4426#ifdef ENABLE_PYTHON_BINDING
4427 return std::make_tuple(setup_sdf(), setup_ts_monitor(),
4428 setup_snes_monitor(), setup_snes_convergence_test(),
4429 setup_section(), set_vector_on_mesh(),
4430 setup_schur_block_solver());
4431#else
4432 return std::make_tuple(setup_ts_monitor(), setup_snes_monitor(),
4433 setup_snes_convergence_test(), setup_section(),
4434 set_vector_on_mesh(), setup_schur_block_solver());
4435#endif
4436 }
#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:1161
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:543
#define MOFEM_LOG(channel, severity)
Log.
MoFEM::TsCtx * ts_ctx
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
auto getDMSnesCtx(DM dm)
Get SNES context data structure used by DM.
Definition DMMoFEM.hpp:1278
constexpr AssemblyType A
constexpr auto field_name
static boost::shared_ptr< SetUpSchur > createSetUpSchur(MoFEM::Interface &m_field, EshelbianCore *ep_core_ptr)
double dynamicInitialResidual
MoFEM::Interface & mField
static enum SolverType solverType
const std::string elementVolumeName
SmartPetscObj< DM > dmElastic
Elastic problem.
static MoFEMErrorCode setPreStep(EshelbianCore *ep_ptr, TS ts, bool h1_update=false)
static MoFEMErrorCode addMonitorTests(EshelbianCore &ep, TS ts, MonitorPtr monitor)
static MoFEMErrorCode addFinalTests(EshelbianCore &ep, MonitorPtr monitor)
Register final-state checks; the solver runs them with runTests().
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: