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

4229 {
4230
4231#ifdef ENABLE_PYTHON_BINDING
4232 auto setup_sdf = [&]() { return setupContactSdf(ep_ptr->mField); };
4233#endif
4234
4235 auto setup_ts_monitor = [&]() {
4236 boost::shared_ptr<TsCtx> ts_ctx;
4238 "get TS ctx");
4239 if (set_ts_monitor) {
4241 TSMonitorSet(ts, TsMonitorSet, ts_ctx.get(), PETSC_NULLPTR),
4242 "TS monitor set");
4243 auto monitor_ptr = boost::make_shared<EshelbianMonitor>(*ep_ptr);
4244 auto testing_monitor_ptr =
4245 boost::make_shared<EshelbianTestingMonitor>(*ep_ptr, monitor_ptr);
4246 ts_ctx->getLoopsMonitor().push_back(
4247 TsCtx::PairNameFEMethodPtr(ep_ptr->elementVolumeName, monitor_ptr));
4248
4249 PetscBool test_cook_flg = PETSC_FALSE;
4250 PetscBool test_cook_pts_flg = PETSC_FALSE;
4251 PetscInt atom_test = 0;
4252 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-test_cook",
4253 &test_cook_flg, PETSC_NULLPTR);
4254 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-test_cook_pts",
4255 &test_cook_pts_flg, PETSC_NULLPTR);
4256 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-atom_test", &atom_test,
4257 PETSC_NULLPTR);
4258 if (atom_test || test_cook_flg || test_cook_pts_flg) {
4260 ep_ptr->elementVolumeName, testing_monitor_ptr));
4261 }
4262 }
4263 MOFEM_LOG("EP", Sev::inform) << "TS monitor setup";
4264 return std::make_tuple(ts_ctx);
4265 };
4266
4267 auto setup_snes_monitor = [&]() {
4269 SNES snes;
4270 CHKERR TSGetSNES(ts, &snes);
4271 auto snes_ctx = getDMSnesCtx(ep_ptr->dmElastic);
4272 CHKERR SNESMonitorSet(snes,
4273 (MoFEMErrorCode (*)(SNES, PetscInt, PetscReal,
4274 void *))MoFEMSNESMonitorEnergy,
4275 (void *)(snes_ctx.get()), PETSC_NULLPTR);
4276 MOFEM_LOG("EP", Sev::inform) << "SNES monitor setup";
4278 };
4279
4280 auto setup_snes_convergence_test = [&]() {
4284 (ep_ptr->dynamicAtol > 0 || ep_ptr->dynamicRtol > 0)) {
4285 auto snes_convergence_test =
4286 [](SNES snes, PetscInt it, PetscReal xnorm, PetscReal snorm,
4287 PetscReal fnorm, SNESConvergedReason *reason, void *cctx) {
4289 auto ep_ptr = static_cast<EshelbianCore *>(cctx);
4290 CHKERR SNESConvergedDefault(snes, it, xnorm, snorm, fnorm, reason,
4291 PETSC_NULLPTR);
4292
4293 if (it == 0) {
4294 if (ep_ptr->dynamicInitialResidual < 0)
4295 ep_ptr->dynamicInitialResidual = fnorm;
4296
4297 if (ep_ptr->dynamicAtol > 0 && fnorm < ep_ptr->dynamicAtol) {
4298 *reason = SNES_BREAKOUT_INNER_ITER;
4300 "EP", Sev::inform,
4301 "Stopping dynamic relaxation: SNES iteration 0 residual "
4302 "%3.4e < %3.4e",
4303 static_cast<double>(fnorm),
4304 static_cast<double>(ep_ptr->dynamicAtol));
4305 } else if (ep_ptr->dynamicRtol > 0 &&
4306 fnorm < ep_ptr->dynamicRtol *
4307 ep_ptr->dynamicInitialResidual) {
4308 *reason = SNES_BREAKOUT_INNER_ITER;
4310 "EP", Sev::inform,
4311 "Stopping dynamic relaxation: SNES iteration 0 residual "
4312 "%3.4e < %3.4e * initial residual %3.4e",
4313 static_cast<double>(fnorm),
4314 static_cast<double>(ep_ptr->dynamicRtol),
4315 static_cast<double>(ep_ptr->dynamicInitialResidual));
4316 }
4317
4318 if (*reason == SNES_BREAKOUT_INNER_ITER) {
4319 PetscObject ts_obj = PETSC_NULLPTR;
4320 CHKERR PetscObjectQuery((PetscObject)snes,
4321 "dynamic_relaxation_ts", &ts_obj);
4322 CHKERR TSSetConvergedReason((TS)ts_obj, TS_CONVERGED_USER);
4323 }
4324 }
4325
4327 };
4328
4329 SNES snes;
4330 CHKERR TSGetSNES(ts, &snes);
4331 CHKERR PetscObjectCompose((PetscObject)snes, "dynamic_relaxation_ts",
4332 (PetscObject)ts);
4333 CHKERR SNESSetConvergenceTest(snes, snes_convergence_test, ep_ptr,
4334 PETSC_NULLPTR);
4335 MOFEM_LOG("EP", Sev::inform) << "SNES convergence test setup";
4336 }
4338 };
4339
4340 auto setup_section = [&]() {
4341 PetscSection section_raw;
4342 CHK_THROW_MESSAGE(DMGetSection(ep_ptr->dmElastic, &section_raw),
4343 "get DM section");
4344 int num_fields;
4345 CHK_THROW_MESSAGE(PetscSectionGetNumFields(section_raw, &num_fields),
4346 "get num fields");
4347 for (int ff = 0; ff != num_fields; ff++) {
4348 const char *field_name;
4350 PetscSectionGetFieldName(section_raw, ff, &field_name),
4351 "get field name");
4352 MOFEM_LOG_C("EP", Sev::inform, "Field %d name %s", ff, field_name);
4353 }
4354 return SmartPetscObj<PetscSection>(section_raw, true);
4355 };
4356
4357 auto set_vector_on_mesh = [&]() {
4359 CHKERR DMoFEMMeshToLocalVector(ep_ptr->dmElastic, x, INSERT_VALUES,
4360 SCATTER_FORWARD);
4361 CHKERR VecGhostUpdateBegin(x, INSERT_VALUES, SCATTER_FORWARD);
4362 CHKERR VecGhostUpdateEnd(x, INSERT_VALUES, SCATTER_FORWARD);
4363 MOFEM_LOG("EP", Sev::inform) << "Vector set on mesh";
4365 };
4366
4367 auto setup_schur_block_solver = [&]() {
4368 MOFEM_LOG("EP", Sev::inform) << "Setting up Schur block solver";
4369 CHK_THROW_MESSAGE(TSAppendOptionsPrefix(ts, "elastic_"),
4370 "append options prefix");
4371 CHK_THROW_MESSAGE(TSSetFromOptions(ts), "set from options");
4372 CHK_THROW_MESSAGE(TSSetDM(ts, ep_ptr->dmElastic), "set DM");
4373 // Adding field split solver
4374 boost::shared_ptr<EshelbianCore::SetUpSchur> schur_ptr;
4375 if constexpr (A == AssemblyType::BLOCK_MAT) {
4376 schur_ptr =
4378 CHK_THROW_MESSAGE(schur_ptr->setUp(ts), "setup schur");
4379 }
4380 MOFEM_LOG("EP", Sev::inform) << "Setting up Schur block solver done";
4381 return schur_ptr;
4382 };
4383
4384 // Warning: sequence of construction is not guaranteed for tuple. You have
4385 // to enforce order by proper packaging.
4386
4387#ifdef ENABLE_PYTHON_BINDING
4388 return std::make_tuple(setup_sdf(), setup_ts_monitor(),
4389 setup_snes_monitor(), setup_snes_convergence_test(),
4390 setup_section(), set_vector_on_mesh(),
4391 setup_schur_block_solver());
4392#else
4393 return std::make_tuple(setup_ts_monitor(), setup_snes_monitor(),
4394 setup_snes_convergence_test(), setup_section(),
4395 set_vector_on_mesh(), setup_schur_block_solver());
4396#endif
4397 }
#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
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
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.
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:121

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