v0.15.0
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
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 3234 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 3236 of file EshelbianPlasticity.cpp.

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";
3252 CHKERR PetscOptionsGetString(PETSC_NULLPTR, PETSC_NULLPTR, "-sdf_file",
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) {
3273 CHKERR TSMonitorSet(ts, TsMonitorSet, ts_ctx.get(), PETSC_NULLPTR);
3274 auto monitor_ptr = boost::make_shared<EshelbianMonitor>(*ep_ptr);
3275 ts_ctx->getLoopsMonitor().push_back(
3276 TsCtx::PairNameFEMethodPtr(ep_ptr->elementVolumeName, monitor_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);
3286 auto snes_ctx = getDMSnesCtx(ep_ptr->dmElastic);
3287 CHKERR SNESMonitorSet(snes,
3288 (MoFEMErrorCode (*)(SNES, PetscInt, PetscReal,
3289 void *))MoFEMSNESMonitorEnergy,
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) {
3302 EshelbianCore *ep_ptr = (EshelbianCore *)cctx;
3303 CHKERR SNESConvergedDefault(snes, it, xnorm, snorm, fnorm, reason,
3304 PETSC_NULLPTR);
3305
3306 Vec x_update, r;
3307 CHKERR SNESGetSolutionUpdate(snes, &x_update);
3308 CHKERR SNESGetFunction(snes, &r, PETSC_NULLPTR, PETSC_NULLPTR);
3309
3310 // *reason = SNES_CONVERGED_ITERATING;
3311 // if (!it) {
3312 // /* set parameter for default relative tolerance convergence test */
3313 // snes->ttol = fnorm * snes->rtol;
3314 // snes->rnorm0 = fnorm;
3315 // }
3316 // if (PetscIsInfOrNanReal(fnorm)) {
3317 // MOFEM_LOG("EP", Sev::error)
3318 // << "SNES convergence test: function norm is NaN";
3319 // *reason = SNES_DIVERGED_FNORM_NAN;
3320 // } else if (fnorm < snes->abstol && (it || !snes->forceiteration)) {
3321 // MOFEM_LOG("EP", Sev::inform)
3322 // << "SNES convergence test: Converged due to function norm "
3323 // << std::setw(14) << std::setprecision(12) << std::scientific
3324 // << fnorm << " < " << std::setw(14) << std::setprecision(12)
3325 // << std::scientific << snes->abstol;
3326
3327 // PetscCall(PetscInfo(
3328 // snes, "Converged due to function norm %14.12e < %14.12e\n",
3329 // (double)fnorm, (double)snes->abstol));
3330 // *reason = SNES_CONVERGED_FNORM_ABS;
3331 // } else if (snes->nfuncs >= snes->max_funcs && snes->max_funcs >= 0) {
3332 // PetscCall(PetscInfo(
3333 // snes,
3334 // "Exceeded maximum number of function evaluations: %" PetscInt_FMT
3335 // " > %" PetscInt_FMT "\n",
3336 // snes->nfuncs, snes->max_funcs));
3337 // *reason = SNES_DIVERGED_FUNCTION_COUNT;
3338 // }
3339
3340 // if (it && !*reason) {
3341 // if (fnorm <= snes->ttol) {
3342 // PetscCall(PetscInfo(snes,
3343 // "Converged due to function norm %14.12e < "
3344 // "%14.12e (relative tolerance)\n",
3345 // (double)fnorm, (double)snes->ttol));
3346 // *reason = SNES_CONVERGED_FNORM_RELATIVE;
3347 // } else if (snorm < snes->stol * xnorm) {
3348 // PetscCall(PetscInfo(snes,
3349 // "Converged due to small update length: %14.12e "
3350 // "< %14.12e * %14.12e\n",
3351 // (double)snorm, (double)snes->stol,
3352 // (double)xnorm));
3353 // *reason = SNES_CONVERGED_SNORM_RELATIVE;
3354 // } else if (snes->divtol != PETSC_UNLIMITED &&
3355 // (fnorm > snes->divtol * snes->rnorm0)) {
3356 // PetscCall(PetscInfo(snes,
3357 // "Diverged due to increase in function norm: "
3358 // "%14.12e > %14.12e * %14.12e\n",
3359 // (double)fnorm, (double)snes->divtol,
3360 // (double)snes->rnorm0));
3361 // *reason = SNES_DIVERGED_DTOL;
3362 // }
3363 // }
3364
3366 };
3367
3368 // SNES snes;
3369 // CHKERR TSGetSNES(ts, &snes);
3370 // CHKERR SNESSetConvergenceTest(snes, snes_convergence_test, ep_ptr,
3371 // PETSC_NULLPTR);
3372 // MOFEM_LOG("EP", Sev::inform) << "SNES convergence test setup";
3374 };
3375
3376 auto setup_section = [&]() {
3377 PetscSection section_raw;
3378 CHKERR DMGetSection(ep_ptr->dmElastic, &section_raw);
3379 int num_fields;
3380 CHKERR PetscSectionGetNumFields(section_raw, &num_fields);
3381 for (int ff = 0; ff != num_fields; ff++) {
3382 const char *field_name;
3383 CHKERR PetscSectionGetFieldName(section_raw, ff, &field_name);
3384 MOFEM_LOG_C("EP", Sev::inform, "Field %d name %s", ff, field_name);
3385 }
3386 return section_raw;
3387 };
3388
3389 auto set_vector_on_mesh = [&]() {
3391 CHKERR DMoFEMMeshToLocalVector(ep_ptr->dmElastic, x, INSERT_VALUES,
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);
3403 CHKERR TSSetDM(ts, ep_ptr->dmElastic);
3404 // Adding field split solver
3405 boost::shared_ptr<EshelbianCore::SetUpSchur> schur_ptr;
3406 if constexpr (A == AssemblyType::BLOCK_MAT) {
3407 schur_ptr =
3409 CHK_THROW_MESSAGE(schur_ptr->setUp(ts), "setup schur");
3410 }
3411 MOFEM_LOG("EP", Sev::inform) << "Setting up Schur block solver done";
3412 return schur_ptr;
3413 };
3414
3415 // Warning: sequence of construction is not guaranteed for tuple. You have
3416 // to enforce order by proper packaging.
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
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
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.
Definition TsCtx.cpp:263
MoFEMErrorCode MoFEMSNESMonitorEnergy(SNES snes, PetscInt its, PetscReal fgnorm, SnesCtx *ctx)
Sens monitor printing residual field by field.
Definition SnesCtx.cpp:648
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:1147
int r
Definition sdf.py:8
constexpr AssemblyType A
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.
Definition TsCtx.hpp:102

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