3355 {
3356
3357#ifdef ENABLE_PYTHON_BINDING
3358 auto setup_sdf = [&]() {
3359 boost::shared_ptr<ContactOps::SDFPython> sdf_python_ptr;
3360
3361 auto file_exists = [](std::string myfile) {
3362 std::ifstream file(myfile.c_str());
3363 if (file) {
3364 return true;
3365 }
3366 return false;
3367 };
3368
3369 char sdf_file_name[255] = "sdf.py";
3371 sdf_file_name, 255, PETSC_NULLPTR);
3372
3373 if (file_exists(sdf_file_name)) {
3374 MOFEM_LOG(
"EP", Sev::inform) << sdf_file_name <<
" file found";
3375 sdf_python_ptr = boost::make_shared<ContactOps::SDFPython>();
3376 CHKERR sdf_python_ptr->sdfInit(sdf_file_name);
3377 ContactOps::sdfPythonWeakPtr = sdf_python_ptr;
3378 MOFEM_LOG(
"EP", Sev::inform) <<
"SdfPython initialized";
3379 } else {
3380 MOFEM_LOG(
"EP", Sev::warning) << sdf_file_name <<
" file NOT found";
3381 }
3382 return sdf_python_ptr;
3383 };
3384 auto sdf_python_ptr = setup_sdf();
3385#endif
3386
3387 auto setup_ts_monitor = [&]() {
3388 boost::shared_ptr<TsCtx>
ts_ctx;
3390 if (set_ts_monitor) {
3392 auto monitor_ptr = boost::make_shared<EshelbianMonitor>(*ep_ptr);
3395 }
3396 MOFEM_LOG(
"EP", Sev::inform) <<
"TS monitor setup";
3397 return std::make_tuple(
ts_ctx);
3398 };
3399
3400 auto setup_snes_monitor = [&]() {
3402 SNES snes;
3403 CHKERR TSGetSNES(ts, &snes);
3405 CHKERR SNESMonitorSet(snes,
3408 (void *)(snes_ctx.get()), PETSC_NULLPTR);
3409 MOFEM_LOG(
"EP", Sev::inform) <<
"SNES monitor setup";
3411 };
3412
3413 auto setup_snes_conergence_test = [&]() {
3415
3416 auto snes_convergence_test = [](SNES snes, PetscInt it, PetscReal xnorm,
3417 PetscReal snorm, PetscReal fnorm,
3418 SNESConvergedReason *reason, void *cctx) {
3420
3421 CHKERR SNESConvergedDefault(snes, it, xnorm, snorm, fnorm, reason,
3422 PETSC_NULLPTR);
3423
3425 CHKERR SNESGetSolutionUpdate(snes, &x_update);
3426 CHKERR SNESGetFunction(snes, &r, PETSC_NULLPTR, PETSC_NULLPTR);
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3484 };
3485
3486
3487
3488
3489
3490
3492 };
3493
3494 auto setup_section = [&]() {
3495 PetscSection section_raw;
3497 int num_fields;
3498 CHKERR PetscSectionGetNumFields(section_raw, &num_fields);
3499 for (int ff = 0; ff != num_fields; ff++) {
3503 }
3504 return section_raw;
3505 };
3506
3507 auto set_vector_on_mesh = [&]() {
3510 SCATTER_FORWARD);
3511 CHKERR VecGhostUpdateBegin(x, INSERT_VALUES, SCATTER_FORWARD);
3512 CHKERR VecGhostUpdateEnd(x, INSERT_VALUES, SCATTER_FORWARD);
3513 MOFEM_LOG(
"EP", Sev::inform) <<
"Vector set on mesh";
3515 };
3516
3517 auto setup_schur_block_solver = [&]() {
3518 MOFEM_LOG(
"EP", Sev::inform) <<
"Setting up Schur block solver";
3519 CHKERR TSAppendOptionsPrefix(ts,
"elastic_");
3520 CHKERR TSSetFromOptions(ts);
3522
3523 boost::shared_ptr<EshelbianCore::SetUpSchur> schur_ptr;
3524 if constexpr (
A == AssemblyType::BLOCK_MAT) {
3525 schur_ptr =
3528 }
3529 MOFEM_LOG(
"EP", Sev::inform) <<
"Setting up Schur block solver done";
3530 return schur_ptr;
3531 };
3532
3533
3534
3535
3536#ifdef ENABLE_PYTHON_BINDING
3537 return std::make_tuple(setup_sdf(), setup_ts_monitor(),
3538 setup_snes_monitor(), setup_snes_conergence_test(),
3539 setup_section(), set_vector_on_mesh(),
3540 setup_schur_block_solver());
3541#else
3542 return std::make_tuple(setup_ts_monitor(), setup_snes_monitor(),
3543 setup_snes_conergence_test(), setup_section(),
3544 set_vector_on_mesh(), setup_schur_block_solver());
3545#endif
3546 }
#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 DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
PetscErrorCode DMMoFEMGetTsCtx(DM dm, MoFEM::TsCtx **ts_ctx)
get MoFEM::TsCtx data structure
#define MOFEM_LOG(channel, severity)
Log.
const FTensor::Tensor2< T, Dim, Dim > Vec
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 PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
auto getDMSnesCtx(DM dm)
Get SNES context data structure used by DM.
constexpr AssemblyType A
[Define dimension]
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.
FEMethodsSequence & getLoopsMonitor()
Get the loops to do Monitor object.