3247 {
3248
3249#ifdef ENABLE_PYTHON_BINDING
3250 auto setup_sdf = [&]() {
3251 boost::shared_ptr<ContactOps::SDFPython> sdf_python_ptr;
3252
3253 auto file_exists = [](std::string myfile) {
3254 std::ifstream file(myfile.c_str());
3255 if (file) {
3256 return true;
3257 }
3258 return false;
3259 };
3260
3261 char sdf_file_name[255] = "sdf.py";
3263 sdf_file_name, 255, PETSC_NULLPTR);
3264
3265 if (file_exists(sdf_file_name)) {
3266 MOFEM_LOG(
"EP", Sev::inform) << sdf_file_name <<
" file found";
3267 sdf_python_ptr = boost::make_shared<ContactOps::SDFPython>();
3268 CHKERR sdf_python_ptr->sdfInit(sdf_file_name);
3269 ContactOps::sdfPythonWeakPtr = sdf_python_ptr;
3270 MOFEM_LOG(
"EP", Sev::inform) <<
"SdfPython initialized";
3271 } else {
3272 MOFEM_LOG(
"EP", Sev::warning) << sdf_file_name <<
" file NOT found";
3273 }
3274 return sdf_python_ptr;
3275 };
3276 auto sdf_python_ptr = setup_sdf();
3277#endif
3278
3279 auto setup_ts_monitor = [&]() {
3280 boost::shared_ptr<TsCtx>
ts_ctx;
3282 if (set_ts_monitor) {
3284 auto monitor_ptr = boost::make_shared<EshelbianMonitor>(*ep_ptr);
3287 }
3288 MOFEM_LOG(
"EP", Sev::inform) <<
"TS monitor setup";
3289 return std::make_tuple(
ts_ctx);
3290 };
3291
3292 auto setup_snes_monitor = [&]() {
3294 SNES snes;
3295 CHKERR TSGetSNES(ts, &snes);
3297 CHKERR SNESMonitorSet(snes,
3300 (void *)(snes_ctx.get()), PETSC_NULLPTR);
3301 MOFEM_LOG(
"EP", Sev::inform) <<
"SNES monitor setup";
3303 };
3304
3305 auto setup_snes_conergence_test = [&]() {
3307
3308 auto snes_convergence_test = [](SNES snes, PetscInt it, PetscReal xnorm,
3309 PetscReal snorm, PetscReal fnorm,
3310 SNESConvergedReason *reason, void *cctx) {
3313 CHKERR SNESConvergedDefault(snes, it, xnorm, snorm, fnorm, reason,
3314 PETSC_NULLPTR);
3315
3317 CHKERR SNESGetSolutionUpdate(snes, &x_update);
3318 CHKERR SNESGetFunction(snes, &r, PETSC_NULLPTR, PETSC_NULLPTR);
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3376 };
3377
3378
3379
3380
3381
3382
3384 };
3385
3386 auto setup_section = [&]() {
3387 PetscSection section_raw;
3389 int num_fields;
3390 CHKERR PetscSectionGetNumFields(section_raw, &num_fields);
3391 for (int ff = 0; ff != num_fields; ff++) {
3395 }
3396 return section_raw;
3397 };
3398
3399 auto set_vector_on_mesh = [&]() {
3402 SCATTER_FORWARD);
3403 CHKERR VecGhostUpdateBegin(x, INSERT_VALUES, SCATTER_FORWARD);
3404 CHKERR VecGhostUpdateEnd(x, INSERT_VALUES, SCATTER_FORWARD);
3405 MOFEM_LOG(
"EP", Sev::inform) <<
"Vector set on mesh";
3407 };
3408
3409 auto setup_schur_block_solver = [&]() {
3410 MOFEM_LOG(
"EP", Sev::inform) <<
"Setting up Schur block solver";
3411 CHKERR TSAppendOptionsPrefix(ts,
"elastic_");
3412 CHKERR TSSetFromOptions(ts);
3414
3415 boost::shared_ptr<EshelbianCore::SetUpSchur> schur_ptr;
3416 if constexpr (A == AssemblyType::BLOCK_MAT) {
3417 schur_ptr =
3420 }
3421 MOFEM_LOG(
"EP", Sev::inform) <<
"Setting up Schur block solver done";
3422 return schur_ptr;
3423 };
3424
3425
3426
3427
3428#ifdef ENABLE_PYTHON_BINDING
3429 return std::make_tuple(setup_sdf(), setup_ts_monitor(),
3430 setup_snes_monitor(), setup_snes_conergence_test(),
3431 setup_section(), set_vector_on_mesh(),
3432 setup_schur_block_solver());
3433#else
3434 return std::make_tuple(setup_ts_monitor(), setup_snes_monitor(),
3435 setup_snes_conergence_test(), setup_section(),
3436 set_vector_on_mesh(), setup_schur_block_solver());
3437#endif
3438 }
#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.
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
PetscErrorCode TsMonitorSet(TS ts, PetscInt step, PetscReal t, Vec u, void *ctx)
Set monitor for TS solver.
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.
MoFEMErrorCode MoFEMSNESMonitorEnergy(SNES snes, PetscInt its, PetscReal fgnorm, SnesCtx *ctx)
Sens monitor printing residual field by field.
constexpr auto field_name
MoFEM::Interface & mField
const std::string elementVolumeName
SmartPetscObj< DM > dmElastic
Elastic problem.
static boost::shared_ptr< SetUpSchur > createSetUpSchur(MoFEM::Interface &m_field, EshelbianCore *ep_core_ptr)
FEMethodsSequence & getLoopsMonitor()
Get the loops to do Monitor object.