4275 {
4276
4277#ifdef ENABLE_PYTHON_BINDING
4279#endif
4280
4281 auto setup_ts_monitor = [&]() {
4282 boost::shared_ptr<TsCtx>
ts_ctx;
4284 "get TS ctx");
4285 if (set_ts_monitor) {
4288 "TS monitor set");
4289 auto monitor_ptr = boost::make_shared<EshelbianMonitor>(*ep_ptr);
4292
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);
4308 CHKERR SNESMonitorSet(snes,
4311 (void *)(snes_ctx.get()), PETSC_NULLPTR);
4312 MOFEM_LOG(
"EP", Sev::inform) <<
"SNES monitor setup";
4314 };
4315
4316 auto setup_snes_convergence_test = [&]() {
4321 auto snes_convergence_test =
4322 [](SNES snes, PetscInt it, PetscReal xnorm, PetscReal snorm,
4323 PetscReal fnorm, SNESConvergedReason *reason, void *cctx) {
4326 CHKERR SNESConvergedDefault(snes, it, xnorm, snorm, fnorm, reason,
4327 PETSC_NULLPTR);
4328
4329 if (it == 0) {
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),
4342 fnorm < ep_ptr->dynamicRtol *
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),
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;
4379 "get DM section");
4380 int num_fields;
4382 "get num fields");
4383 for (int ff = 0; ff != num_fields; ff++) {
4386 PetscSectionGetFieldName(section_raw, ff, &
field_name),
4387 "get field name");
4389 }
4391 };
4392
4393 auto set_vector_on_mesh = [&]() {
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";
4406 "append options prefix");
4409
4410 boost::shared_ptr<EshelbianCore::SetUpSchur> schur_ptr;
4411 if constexpr (
A == AssemblyType::BLOCK_MAT) {
4412 schur_ptr =
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
4424
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
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
#define MOFEM_LOG(channel, severity)
Log.
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.
MoFEMErrorCode MoFEMSNESMonitorEnergy(SNES snes, PetscInt its, PetscReal fgnorm, SnesCtx *ctx)
Sens monitor printing residual field by field.
auto getDMSnesCtx(DM dm)
Get SNES context data structure used by DM.
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.