3237 {
3238
3239#ifdef ENABLE_PYTHON_BINDING
3240 auto setup_sdf = [&]() {
3241 boost::shared_ptr<ContactOps::SDFPython> sdf_python_ptr;
3242
3243 auto file_exists = [](std::string myfile) {
3244 std::ifstream file(myfile.c_str());
3245 if (file) {
3246 return true;
3247 }
3248 return false;
3249 };
3250
3251 char sdf_file_name[255] = "sdf.py";
3253 sdf_file_name, 255, PETSC_NULLPTR);
3254
3255 if (file_exists(sdf_file_name)) {
3256 MOFEM_LOG(
"EP", Sev::inform) << sdf_file_name <<
" file found";
3257 sdf_python_ptr = boost::make_shared<ContactOps::SDFPython>();
3258 CHKERR sdf_python_ptr->sdfInit(sdf_file_name);
3259 ContactOps::sdfPythonWeakPtr = sdf_python_ptr;
3260 MOFEM_LOG(
"EP", Sev::inform) <<
"SdfPython initialized";
3261 } else {
3262 MOFEM_LOG(
"EP", Sev::warning) << sdf_file_name <<
" file NOT found";
3263 }
3264 return sdf_python_ptr;
3265 };
3266 auto sdf_python_ptr = setup_sdf();
3267#endif
3268
3269 auto setup_ts_monitor = [&]() {
3270 boost::shared_ptr<TsCtx>
ts_ctx;
3272 if (set_ts_monitor) {
3274 auto monitor_ptr = boost::make_shared<EshelbianMonitor>(*ep_ptr);
3277 }
3278 MOFEM_LOG(
"EP", Sev::inform) <<
"TS monitor setup";
3279 return std::make_tuple(
ts_ctx);
3280 };
3281
3282 auto setup_snes_monitor = [&]() {
3284 SNES snes;
3285 CHKERR TSGetSNES(ts, &snes);
3287 CHKERR SNESMonitorSet(snes,
3290 (void *)(snes_ctx.get()), PETSC_NULLPTR);
3291 MOFEM_LOG(
"EP", Sev::inform) <<
"SNES monitor setup";
3293 };
3294
3295 auto setup_snes_conergence_test = [&]() {
3297
3298 auto snes_convergence_test = [](SNES snes, PetscInt it, PetscReal xnorm,
3299 PetscReal snorm, PetscReal fnorm,
3300 SNESConvergedReason *reason, void *cctx) {
3303 CHKERR SNESConvergedDefault(snes, it, xnorm, snorm, fnorm, reason,
3304 PETSC_NULLPTR);
3305
3307 CHKERR SNESGetSolutionUpdate(snes, &x_update);
3308 CHKERR SNESGetFunction(snes, &r, PETSC_NULLPTR, PETSC_NULLPTR);
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
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
3366 };
3367
3368
3369
3370
3371
3372
3374 };
3375
3376 auto setup_section = [&]() {
3377 PetscSection section_raw;
3379 int num_fields;
3380 CHKERR PetscSectionGetNumFields(section_raw, &num_fields);
3381 for (int ff = 0; ff != num_fields; ff++) {
3385 }
3386 return section_raw;
3387 };
3388
3389 auto set_vector_on_mesh = [&]() {
3392 SCATTER_FORWARD);
3393 CHKERR VecGhostUpdateBegin(x, INSERT_VALUES, SCATTER_FORWARD);
3394 CHKERR VecGhostUpdateEnd(x, INSERT_VALUES, SCATTER_FORWARD);
3395 MOFEM_LOG(
"EP", Sev::inform) <<
"Vector set on mesh";
3397 };
3398
3399 auto setup_schur_block_solver = [&]() {
3400 MOFEM_LOG(
"EP", Sev::inform) <<
"Setting up Schur block solver";
3401 CHKERR TSAppendOptionsPrefix(ts,
"elastic_");
3402 CHKERR TSSetFromOptions(ts);
3404
3405 boost::shared_ptr<EshelbianCore::SetUpSchur> schur_ptr;
3406 if constexpr (
A == AssemblyType::BLOCK_MAT) {
3407 schur_ptr =
3410 }
3411 MOFEM_LOG(
"EP", Sev::inform) <<
"Setting up Schur block solver done";
3412 return schur_ptr;
3413 };
3414
3415
3416
3417
3418#ifdef ENABLE_PYTHON_BINDING
3419 return std::make_tuple(setup_sdf(), setup_ts_monitor(),
3420 setup_snes_monitor(), setup_snes_conergence_test(),
3421 setup_section(), set_vector_on_mesh(),
3422 setup_schur_block_solver());
3423#else
3424 return std::make_tuple(setup_ts_monitor(), setup_snes_monitor(),
3425 setup_snes_conergence_test(), setup_section(),
3426 set_vector_on_mesh(), setup_schur_block_solver());
3427#endif
3428 }
#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 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.