4229 {
4230
4231#ifdef ENABLE_PYTHON_BINDING
4233#endif
4234
4235 auto setup_ts_monitor = [&]() {
4236 boost::shared_ptr<TsCtx>
ts_ctx;
4238 "get TS ctx");
4239 if (set_ts_monitor) {
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);
4248
4249 PetscBool test_cook_flg = PETSC_FALSE;
4250 PetscBool test_cook_pts_flg = PETSC_FALSE;
4253 &test_cook_flg, PETSC_NULLPTR);
4255 &test_cook_pts_flg, PETSC_NULLPTR);
4257 PETSC_NULLPTR);
4258 if (
atom_test || test_cook_flg || test_cook_pts_flg) {
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);
4272 CHKERR SNESMonitorSet(snes,
4275 (void *)(snes_ctx.get()), PETSC_NULLPTR);
4276 MOFEM_LOG(
"EP", Sev::inform) <<
"SNES monitor setup";
4278 };
4279
4280 auto setup_snes_convergence_test = [&]() {
4285 auto snes_convergence_test =
4286 [](SNES snes, PetscInt it, PetscReal xnorm, PetscReal snorm,
4287 PetscReal fnorm, SNESConvergedReason *reason, void *cctx) {
4290 CHKERR SNESConvergedDefault(snes, it, xnorm, snorm, fnorm, reason,
4291 PETSC_NULLPTR);
4292
4293 if (it == 0) {
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),
4306 fnorm < ep_ptr->dynamicRtol *
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),
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;
4343 "get DM section");
4344 int num_fields;
4346 "get num fields");
4347 for (int ff = 0; ff != num_fields; ff++) {
4350 PetscSectionGetFieldName(section_raw, ff, &
field_name),
4351 "get field name");
4353 }
4355 };
4356
4357 auto set_vector_on_mesh = [&]() {
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";
4370 "append options prefix");
4373
4374 boost::shared_ptr<EshelbianCore::SetUpSchur> schur_ptr;
4375 if constexpr (
A == AssemblyType::BLOCK_MAT) {
4376 schur_ptr =
4379 }
4380 MOFEM_LOG(
"EP", Sev::inform) <<
"Setting up Schur block solver done";
4381 return schur_ptr;
4382 };
4383
4384
4385
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
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.
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.
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.