v0.15.0
Loading...
Searching...
No Matches
EshelbianPlasticity::solve_elastic_setup Struct Reference

Static Public Member Functions

static auto setup (EshelbianCore *ep_ptr, TS ts, Vec x, bool set_ts_monitor)
 

Detailed Description

Definition at line 3244 of file EshelbianPlasticity.cpp.

Member Function Documentation

◆ setup()

static auto EshelbianPlasticity::solve_elastic_setup::setup ( EshelbianCore * ep_ptr,
TS ts,
Vec x,
bool set_ts_monitor )
inlinestatic

Definition at line 3246 of file EshelbianPlasticity.cpp.

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";
3262 CHKERR PetscOptionsGetString(PETSC_NULLPTR, PETSC_NULLPTR, "-sdf_file",
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) {
3283 CHKERR TSMonitorSet(ts, TsMonitorSet, ts_ctx.get(), PETSC_NULLPTR);
3284 auto monitor_ptr = boost::make_shared<EshelbianMonitor>(*ep_ptr);
3285 ts_ctx->getLoopsMonitor().push_back(
3286 TsCtx::PairNameFEMethodPtr(ep_ptr->elementVolumeName, monitor_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);
3296 auto snes_ctx = getDMSnesCtx(ep_ptr->dmElastic);
3297 CHKERR SNESMonitorSet(snes,
3298 (MoFEMErrorCode (*)(SNES, PetscInt, PetscReal,
3299 void *))MoFEMSNESMonitorEnergy,
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) {
3312 EshelbianCore *ep_ptr = (EshelbianCore *)cctx;
3313 CHKERR SNESConvergedDefault(snes, it, xnorm, snorm, fnorm, reason,
3314 PETSC_NULLPTR);
3315
3316 Vec x_update, r;
3317 CHKERR SNESGetSolutionUpdate(snes, &x_update);
3318 CHKERR SNESGetFunction(snes, &r, PETSC_NULLPTR, PETSC_NULLPTR);
3319
3320 // *reason = SNES_CONVERGED_ITERATING;
3321 // if (!it) {
3322 // /* set parameter for default relative tolerance convergence test */
3323 // snes->ttol = fnorm * snes->rtol;
3324 // snes->rnorm0 = fnorm;
3325 // }
3326 // if (PetscIsInfOrNanReal(fnorm)) {
3327 // MOFEM_LOG("EP", Sev::error)
3328 // << "SNES convergence test: function norm is NaN";
3329 // *reason = SNES_DIVERGED_FNORM_NAN;
3330 // } else if (fnorm < snes->abstol && (it || !snes->forceiteration)) {
3331 // MOFEM_LOG("EP", Sev::inform)
3332 // << "SNES convergence test: Converged due to function norm "
3333 // << std::setw(14) << std::setprecision(12) << std::scientific
3334 // << fnorm << " < " << std::setw(14) << std::setprecision(12)
3335 // << std::scientific << snes->abstol;
3336
3337 // PetscCall(PetscInfo(
3338 // snes, "Converged due to function norm %14.12e < %14.12e\n",
3339 // (double)fnorm, (double)snes->abstol));
3340 // *reason = SNES_CONVERGED_FNORM_ABS;
3341 // } else if (snes->nfuncs >= snes->max_funcs && snes->max_funcs >= 0) {
3342 // PetscCall(PetscInfo(
3343 // snes,
3344 // "Exceeded maximum number of function evaluations: %" PetscInt_FMT
3345 // " > %" PetscInt_FMT "\n",
3346 // snes->nfuncs, snes->max_funcs));
3347 // *reason = SNES_DIVERGED_FUNCTION_COUNT;
3348 // }
3349
3350 // if (it && !*reason) {
3351 // if (fnorm <= snes->ttol) {
3352 // PetscCall(PetscInfo(snes,
3353 // "Converged due to function norm %14.12e < "
3354 // "%14.12e (relative tolerance)\n",
3355 // (double)fnorm, (double)snes->ttol));
3356 // *reason = SNES_CONVERGED_FNORM_RELATIVE;
3357 // } else if (snorm < snes->stol * xnorm) {
3358 // PetscCall(PetscInfo(snes,
3359 // "Converged due to small update length: %14.12e "
3360 // "< %14.12e * %14.12e\n",
3361 // (double)snorm, (double)snes->stol,
3362 // (double)xnorm));
3363 // *reason = SNES_CONVERGED_SNORM_RELATIVE;
3364 // } else if (snes->divtol != PETSC_UNLIMITED &&
3365 // (fnorm > snes->divtol * snes->rnorm0)) {
3366 // PetscCall(PetscInfo(snes,
3367 // "Diverged due to increase in function norm: "
3368 // "%14.12e > %14.12e * %14.12e\n",
3369 // (double)fnorm, (double)snes->divtol,
3370 // (double)snes->rnorm0));
3371 // *reason = SNES_DIVERGED_DTOL;
3372 // }
3373 // }
3374
3376 };
3377
3378 // SNES snes;
3379 // CHKERR TSGetSNES(ts, &snes);
3380 // CHKERR SNESSetConvergenceTest(snes, snes_convergence_test, ep_ptr,
3381 // PETSC_NULLPTR);
3382 // MOFEM_LOG("EP", Sev::inform) << "SNES convergence test setup";
3384 };
3385
3386 auto setup_section = [&]() {
3387 PetscSection section_raw;
3388 CHKERR DMGetSection(ep_ptr->dmElastic, &section_raw);
3389 int num_fields;
3390 CHKERR PetscSectionGetNumFields(section_raw, &num_fields);
3391 for (int ff = 0; ff != num_fields; ff++) {
3392 const char *field_name;
3393 CHKERR PetscSectionGetFieldName(section_raw, ff, &field_name);
3394 MOFEM_LOG_C("EP", Sev::inform, "Field %d name %s", ff, field_name);
3395 }
3396 return section_raw;
3397 };
3398
3399 auto set_vector_on_mesh = [&]() {
3401 CHKERR DMoFEMMeshToLocalVector(ep_ptr->dmElastic, x, INSERT_VALUES,
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);
3413 CHKERR TSSetDM(ts, ep_ptr->dmElastic);
3414 // Adding field split solver
3415 boost::shared_ptr<EshelbianCore::SetUpSchur> schur_ptr;
3416 if constexpr (A == AssemblyType::BLOCK_MAT) {
3417 schur_ptr =
3419 CHK_THROW_MESSAGE(schur_ptr->setUp(ts), "setup schur");
3420 }
3421 MOFEM_LOG("EP", Sev::inform) << "Setting up Schur block solver done";
3422 return schur_ptr;
3423 };
3424
3425 // Warning: sequence of construction is not guaranteed for tuple. You have
3426 // to enforce order by proper packaging.
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
Definition DMMoFEM.cpp:514
PetscErrorCode DMMoFEMGetTsCtx(DM dm, MoFEM::TsCtx **ts_ctx)
get MoFEM::TsCtx data structure
Definition DMMoFEM.cpp:1132
#define MOFEM_LOG(channel, severity)
Log.
MoFEM::TsCtx * ts_ctx
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
PetscErrorCode TsMonitorSet(TS ts, PetscInt step, PetscReal t, Vec u, void *ctx)
Set monitor for TS solver.
Definition TsCtx.cpp:263
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.
Definition DMMoFEM.hpp:1130
MoFEMErrorCode MoFEMSNESMonitorEnergy(SNES snes, PetscInt its, PetscReal fgnorm, SnesCtx *ctx)
Sens monitor printing residual field by field.
Definition SnesCtx.cpp:648
int r
Definition sdf.py:8
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.
Definition TsCtx.hpp:102

The documentation for this struct was generated from the following file: