v0.15.0
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Private Member Functions | Private Attributes | List of all members
TSPrePostProc Struct Reference

Set of functions called by PETSc solver used to refine and update mesh. More...

Collaboration diagram for TSPrePostProc:
[legend]

Public Member Functions

 TSPrePostProc ()=default
 
virtual ~TSPrePostProc ()=default
 
MoFEMErrorCode tsSetUp (TS ts)
 Used to setup TS solver.
 
 TSPrePostProc ()=default
 
virtual ~TSPrePostProc ()=default
 
MoFEMErrorCode tsSetUp (TS ts)
 Used to setup TS solver.
 
SmartPetscObj< VecScatter > getScatter (Vec x, Vec y, enum FR fr)
 Get scatter context for vector operations.
 
SmartPetscObj< Vec > getSubVector ()
 Create sub-problem vector.
 

Static Public Member Functions

static MoFEMErrorCode tsPostStage (TS ts, PetscReal stagetime, PetscInt stageindex, Vec *Y)
 [Boundary condition]
 
static MoFEMErrorCode tsPostStep (TS ts)
 
static MoFEMErrorCode tsPreStep (TS ts)
 

Public Attributes

ExamplefsRawPtr
 
SmartPetscObj< DM > solverSubDM
 
SmartPetscObj< Vec > globSol
 
FreeSurfacefsRawPtr
 

Static Private Member Functions

static MoFEMErrorCode tsPreProc (TS ts)
 Pre process time step.
 
static MoFEMErrorCode tsPostProc (TS ts)
 Post process time step.
 
static MoFEMErrorCode tsPreStage (TS ts)
 Pre-stage processing for time stepping.
 
static MoFEMErrorCode tsSetIFunction (TS ts, PetscReal t, Vec u, Vec u_t, Vec f, void *ctx)
 Set implicit function for time stepping.
 
static MoFEMErrorCode tsSetIJacobian (TS ts, PetscReal t, Vec u, Vec u_t, PetscReal a, Mat A, Mat B, void *ctx)
 Set implicit Jacobian for time stepping.
 
static MoFEMErrorCode tsMonitor (TS ts, PetscInt step, PetscReal t, Vec u, void *ctx)
 Monitor solution during time stepping.
 
static MoFEMErrorCode pcSetup (PC pc)
 Setup preconditioner.
 
static MoFEMErrorCode pcApply (PC pc, Vec pc_f, Vec pc_x)
 Apply preconditioner.
 

Private Attributes

SmartPetscObj< Vec > globRes
 
SmartPetscObj< Mat > subB
 
SmartPetscObj< KSP > subKSP
 
boost::shared_ptr< SnesCtxsnesCtxPtr
 
boost::shared_ptr< TsCtxtsCtxPtr
 

Detailed Description

Set of functions called by PETSc solver used to refine and update mesh.

Note
Currently theta method is only handled by this code.
Examples
mofem/tutorials/adv-4/dynamic_first_order_con_law.cpp, and mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 383 of file dynamic_first_order_con_law.cpp.

Constructor & Destructor Documentation

◆ TSPrePostProc() [1/2]

TSPrePostProc::TSPrePostProc ( )
default

◆ ~TSPrePostProc() [1/2]

virtual TSPrePostProc::~TSPrePostProc ( )
virtualdefault

◆ TSPrePostProc() [2/2]

TSPrePostProc::TSPrePostProc ( )
default

◆ ~TSPrePostProc() [2/2]

virtual TSPrePostProc::~TSPrePostProc ( )
virtualdefault

Member Function Documentation

◆ getScatter()

SmartPetscObj< VecScatter > TSPrePostProc::getScatter ( Vec  x,
Vec  y,
enum FR  fr 
)

Get scatter context for vector operations.

Parameters
xLocal sub-vector
yGlobal vector
frDirection flag (F=forward, R=reverse)
Returns
SmartPetscObj<VecScatter> Scatter context for vector operations

Creates scatter context to transfer data between global and sub-problem vectors

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 3559 of file free_surface.cpp.

3559 {
3560 if (auto ptr = tsPrePostProc.lock()) {
3561 auto prb_ptr = ptr->fsRawPtr->mField.get_problem("SUB_SOLVER");
3562 if (auto sub_data = prb_ptr->getSubData()) {
3563 auto is = sub_data->getSmartColIs();
3564 VecScatter s;
3565 if (fr == R) {
3566 CHK_THROW_MESSAGE(VecScatterCreate(x, PETSC_NULLPTR, y, is, &s),
3567 "crate scatter");
3568 } else {
3569 CHK_THROW_MESSAGE(VecScatterCreate(x, is, y, PETSC_NULLPTR, &s),
3570 "crate scatter");
3571 }
3572 return SmartPetscObj<VecScatter>(s);
3573 }
3574 }
3577}
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
static boost::weak_ptr< TSPrePostProc > tsPrePostProc
@ R
intrusive_ptr for managing petsc objects

◆ getSubVector()

SmartPetscObj< Vec > TSPrePostProc::getSubVector ( )

Create sub-problem vector.

Returns
SmartPetscObj<Vec> Vector compatible with sub-problem DM

Creates a vector with proper size and ghost structure for sub-problem

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 3579 of file free_surface.cpp.

3579 {
3581}
auto createDMVector(DM dm)
Get smart vector from DM.
Definition DMMoFEM.hpp:1234
SmartPetscObj< DM > solverSubDM

◆ pcApply()

MoFEMErrorCode TSPrePostProc::pcApply ( PC  pc,
Vec  pc_f,
Vec  pc_x 
)
staticprivate

Apply preconditioner.

Parameters
pcPETSc preconditioner object
pc_fInput vector (right-hand side)
pc_xOutput vector (preconditioned solution)
Returns
MoFEMErrorCode Success/failure code

Applies preconditioner by solving sub-problem with KSP

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 3539 of file free_surface.cpp.

3539 {
3541 if (auto ptr = tsPrePostProc.lock()) {
3542 auto sub_x = ptr->getSubVector();
3543 auto sub_f = vectorDuplicate(sub_x);
3544 auto scatter = ptr->getScatter(sub_x, pc_x, R);
3545 CHKERR VecScatterBegin(scatter, pc_f, sub_f, INSERT_VALUES,
3546 SCATTER_REVERSE);
3547 CHKERR VecScatterEnd(scatter, pc_f, sub_f, INSERT_VALUES, SCATTER_REVERSE);
3548 CHKERR KSPSetOperators(ptr->subKSP, ptr->subB, ptr->subB);
3549 MOFEM_LOG("FS", Sev::verbose) << "PCShell solve";
3550 CHKERR KSPSolve(ptr->subKSP, sub_f, sub_x);
3551 MOFEM_LOG("FS", Sev::verbose) << "PCShell solve <- done";
3552 CHKERR VecScatterBegin(scatter, sub_x, pc_x, INSERT_VALUES,
3553 SCATTER_FORWARD);
3554 CHKERR VecScatterEnd(scatter, sub_x, pc_x, INSERT_VALUES, SCATTER_FORWARD);
3555 }
3557};
#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 MOFEM_LOG(channel, severity)
Log.
SmartPetscObj< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.

◆ pcSetup()

MoFEMErrorCode TSPrePostProc::pcSetup ( PC  pc)
staticprivate

Setup preconditioner.

Parameters
pcPETSc preconditioner object
Returns
MoFEMErrorCode Success/failure code

Initializes KSP solver for shell preconditioner

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 3529 of file free_surface.cpp.

3529 {
3531 if (auto ptr = tsPrePostProc.lock()) {
3532 MOFEM_LOG("FS", Sev::verbose) << "SetUP sub PC";
3533 ptr->subKSP = createKSP(ptr->fsRawPtr->mField.get_comm());
3534 CHKERR KSPSetFromOptions(ptr->subKSP);
3535 }
3537};
auto createKSP(MPI_Comm comm)

◆ tsMonitor()

MoFEMErrorCode TSPrePostProc::tsMonitor ( TS  ts,
PetscInt  step,
PetscReal  t,
Vec  u,
void *  ctx 
)
staticprivate

Monitor solution during time stepping.

Parameters
tsPETSc time stepping object
stepCurrent time step number
tCurrent time value
uCurrent solution vector
ctxUser context (pointer to FreeSurface)
Returns
MoFEMErrorCode Success/failure code

Called after each time step to monitor solution and save output Wrapper for TS monitor

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 3504 of file free_surface.cpp.

3505 {
3507 if (auto ptr = tsPrePostProc.lock()) {
3508 auto get_norm = [&](auto x) {
3509 double nrm;
3510 CHKERR VecNorm(x, NORM_2, &nrm);
3511 return nrm;
3512 };
3513
3514 auto sub_u = ptr->getSubVector();
3515 auto scatter = ptr->getScatter(sub_u, u, R);
3516 CHKERR VecScatterBegin(scatter, u, sub_u, INSERT_VALUES, SCATTER_REVERSE);
3517 CHKERR VecScatterEnd(scatter, u, sub_u, INSERT_VALUES, SCATTER_REVERSE);
3518 CHKERR VecGhostUpdateBegin(sub_u, INSERT_VALUES, SCATTER_FORWARD);
3519 CHKERR VecGhostUpdateEnd(sub_u, INSERT_VALUES, SCATTER_FORWARD);
3520
3521 MOFEM_LOG("FS", Sev::verbose)
3522 << "u norm " << get_norm(u) << " u sub nom " << get_norm(sub_u);
3523
3524 CHKERR TsMonitorSet(ts, step, t, sub_u, ptr->tsCtxPtr.get());
3525 }
3527}
PetscErrorCode TsMonitorSet(TS ts, PetscInt step, PetscReal t, Vec u, void *ctx)
Set monitor for TS solver.
Definition TsCtx.cpp:263
constexpr double t
plate stiffness
Definition plate.cpp:58

◆ tsPostProc()

MoFEMErrorCode TSPrePostProc::tsPostProc ( TS  ts)
staticprivate

Post process time step.

Currently this function does not make anything major

Parameters
tsPETSc time stepping object
Returns
MoFEMErrorCode Success/failure code

Called after each time step completion for cleanup operations

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 3439 of file free_surface.cpp.

3439 {
3440 if (auto ptr = tsPrePostProc.lock()) {
3441 auto &m_field = ptr->fsRawPtr->mField;
3442 MOFEM_LOG_CHANNEL("SYNC");
3443 MOFEM_TAG_AND_LOG("SYNC", Sev::verbose, "FS") << "PostProc done";
3444 MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::verbose);
3445 }
3446 return 0;
3447}
#define MOFEM_LOG_SEVERITY_SYNC(comm, severity)
Synchronise "SYNC" on curtain severity level.
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.

◆ tsPostStage()

MoFEMErrorCode TSPrePostProc::tsPostStage ( TS  ts,
PetscReal  stagetime,
PetscInt  stageindex,
Vec *  Y 
)
static

[Boundary condition]

Examples
mofem/tutorials/adv-4/dynamic_first_order_con_law.cpp.

Definition at line 580 of file dynamic_first_order_con_law.cpp.

581 {
583 // cerr << "tsPostStage " <<"\n";
584 if (auto ptr = tsPrePostProc.lock()) {
585 auto &m_field = ptr->fsRawPtr->mField;
586
587 auto fb = m_field.getInterface<FieldBlas>();
588 double dt;
589 CHKERR TSGetTimeStep(ts, &dt);
590 double time;
591 CHKERR TSGetTime(ts, &time);
592 PetscInt num_stages;
593 Vec *stage_solutions;
594
595 CHKERR TSGetStages(ts, &num_stages, &stage_solutions);
596 PetscPrintf(PETSC_COMM_WORLD, "Check timestep %d time %e dt %e\n",
597 num_stages, time, dt);
598
599 const double inv_num_step = (double)num_stages;
600 CHKERR fb->fieldCopy(1., "x_1", "x_2");
601 CHKERR fb->fieldAxpy(dt, "V", "x_2");
602 CHKERR fb->fieldCopy(1., "x_2", "x_1");
603
604 CHKERR fb->fieldCopy(-inv_num_step / dt, "F_0", "F_dot");
605 CHKERR fb->fieldAxpy(inv_num_step / dt, "F", "F_dot");
606 CHKERR fb->fieldCopy(1., "F", "F_0");
607 }
609}
double dt
const FTensor::Tensor2< T, Dim, Dim > Vec
Basic algebra on fields.
Definition FieldBlas.hpp:21

◆ tsPostStep()

MoFEMErrorCode TSPrePostProc::tsPostStep ( TS  ts)
static
Examples
mofem/tutorials/adv-4/dynamic_first_order_con_law.cpp.

Definition at line 611 of file dynamic_first_order_con_law.cpp.

611 {
613
614 if (auto ptr = tsPrePostProc.lock()) {
615 auto &m_field = ptr->fsRawPtr->mField;
616 double dt;
617 CHKERR TSGetTimeStep(ts, &dt);
618 double time;
619 CHKERR TSGetTime(ts, &time);
620 }
622}

◆ tsPreProc()

MoFEMErrorCode TSPrePostProc::tsPreProc ( TS  ts)
staticprivate

Pre process time step.

Refine mesh and update fields before each time step

Parameters
tsPETSc time stepping object
Returns
MoFEMErrorCode Success/failure code

This function is called before each time step to:

  • Apply phase field cutoff constraints
  • Refine mesh based on interface location
  • Project solution data to new mesh
  • Update solver operators

cut-off values at nodes, i.e. abs("H") <= 1

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 3324 of file free_surface.cpp.

3324 {
3326
3327 if (auto ptr = tsPrePostProc.lock()) {
3328
3329 /**
3330 * @brief cut-off values at nodes, i.e. abs("H") <= 1
3331 *
3332 */
3333 auto cut_off_dofs = [&]() {
3335
3336 auto &m_field = ptr->fsRawPtr->mField;
3337
3338 Range current_verts;
3339 auto bit_mng = m_field.getInterface<BitRefManager>();
3341 bit(get_current_bit()), BitRefLevel().set(), MBVERTEX, current_verts);
3342
3343 auto cut_off_verts = [&](boost::shared_ptr<FieldEntity> ent_ptr) {
3345 for (auto &h : ent_ptr->getEntFieldData()) {
3346 h = cut_off(h);
3347 }
3349 };
3350
3351 auto field_blas = m_field.getInterface<FieldBlas>();
3352 CHKERR field_blas->fieldLambdaOnEntities(cut_off_verts, "H",
3353 &current_verts);
3355 };
3356
3357 CHKERR cut_off_dofs();
3358 }
3359
3360 if (auto ptr = tsPrePostProc.lock()) {
3361 MOFEM_LOG("FS", Sev::inform) << "Run step pre proc";
3362
3363 auto &m_field = ptr->fsRawPtr->mField;
3364 auto simple = m_field.getInterface<Simple>();
3365
3366 // get vector norm
3367 auto get_norm = [&](auto x) {
3368 double nrm;
3369 CHKERR VecNorm(x, NORM_2, &nrm);
3370 return nrm;
3371 };
3372
3373 // refine problem and project data, including theta data
3374 auto refine_problem = [&]() {
3376 MOFEM_LOG("FS", Sev::inform) << "Refine problem";
3377 CHKERR ptr->fsRawPtr->refineMesh(refine_overlap);
3378 CHKERR ptr->fsRawPtr->projectData();
3380 };
3381
3382 // set new jacobin operator, since problem and thus tangent matrix size has
3383 // changed
3384 auto set_jacobian_operators = [&]() {
3386 ptr->subB = createDMMatrix(ptr->solverSubDM);
3387 CHKERR KSPReset(ptr->subKSP);
3389 };
3390
3391 // set new solution
3392 auto set_solution = [&]() {
3394 MOFEM_LOG("FS", Sev::inform) << "Set solution";
3395
3396 PetscObjectState state;
3397
3398 // Record the state, and set it again. This is to fool PETSc that solution
3399 // vector is not updated. Otherwise PETSc will treat every step as a first
3400 // step.
3401
3402 // globSol is updated as result mesh refinement - this is not really set
3403 // a new solution.
3404
3405 CHKERR PetscObjectStateGet(getPetscObject(ptr->globSol.get()), &state);
3406 CHKERR DMoFEMMeshToLocalVector(simple->getDM(), ptr->globSol,
3407 INSERT_VALUES, SCATTER_FORWARD);
3408 CHKERR PetscObjectStateSet(getPetscObject(ptr->globSol.get()), state);
3409 MOFEM_LOG("FS", Sev::verbose)
3410 << "Set solution, vector norm " << get_norm(ptr->globSol);
3412 };
3413
3414 PetscBool is_theta;
3415 PetscObjectTypeCompare((PetscObject)ts, TSTHETA, &is_theta);
3416 if (is_theta) {
3417
3418 CHKERR refine_problem(); // refine problem
3419 CHKERR set_jacobian_operators(); // set new jacobian
3420 CHKERR set_solution(); // set solution
3421
3422 } else {
3423 SETERRQ(PETSC_COMM_WORLD, MOFEM_NOT_IMPLEMENTED,
3424 "Sorry, only TSTheta handling is implemented");
3425 }
3426
3427 // Need barriers, some functions in TS solver need are called collectively
3428 // and require the same state of variables
3429 PetscBarrier((PetscObject)ts);
3430
3431 MOFEM_LOG_CHANNEL("SYNC");
3432 MOFEM_TAG_AND_LOG("SYNC", Sev::verbose, "FS") << "PreProc done";
3433 MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::verbose);
3434 }
3435
3437}
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition acoustic.cpp:69
@ MOFEM_NOT_IMPLEMENTED
Definition definitions.h:32
double h
int refine_overlap
auto cut_off
Phase field cutoff function.
auto get_current_bit
dofs bit used to do calculations
auto bit
Create bit reference level.
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
auto createDMMatrix(DM dm)
Get smart matrix from DM.
Definition DMMoFEM.hpp:1191
MoFEMErrorCode getEntitiesByTypeAndRefLevel(const BitRefLevel bit, const BitRefLevel mask, const EntityType type, const EntityHandle meshset, int verb=0) const
add all ents from ref level given by bit to meshset
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition Types.hpp:40
PetscObject getPetscObject(T obj)
Managing BitRefLevels.
MoFEMErrorCode fieldLambdaOnEntities(OneFieldFunctionOnEntities lambda, const std::string field_name, Range *ents_ptr=nullptr)
field lambda
Definition FieldBlas.cpp:50
Simple interface for fast problem set-up.
Definition Simple.hpp:27

◆ tsPreStage()

static MoFEMErrorCode TSPrePostProc::tsPreStage ( TS  ts)
staticprivate

Pre-stage processing for time stepping.

Parameters
tsPETSc time stepping object
Returns
MoFEMErrorCode Success/failure code
Examples
mofem/tutorials/vec-5/free_surface.cpp.

◆ tsPreStep()

MoFEMErrorCode TSPrePostProc::tsPreStep ( TS  ts)
static
Examples
mofem/tutorials/adv-4/dynamic_first_order_con_law.cpp.

Definition at line 624 of file dynamic_first_order_con_law.cpp.

624 {
626
627 if (auto ptr = tsPrePostProc.lock()) {
628 auto &m_field = ptr->fsRawPtr->mField;
629 double dt;
630 CHKERR TSGetTimeStep(ts, &dt);
631 double time;
632 CHKERR TSGetTime(ts, &time);
633 int step_num;
634 CHKERR TSGetStepNumber(ts, &step_num);
635 }
637}

◆ tsSetIFunction()

MoFEMErrorCode TSPrePostProc::tsSetIFunction ( TS  ts,
PetscReal  t,
Vec  u,
Vec  u_t,
Vec  f,
void *  ctx 
)
staticprivate

Set implicit function for time stepping.

Parameters
tsPETSc time stepping object
tCurrent time
uSolution vector at current time
u_tTime derivative of solution
fOutput residual vector F(t,u,u_t)
ctxUser context (unused)
Returns
MoFEMErrorCode Success/failure code

Wrapper that scatters global vectors to sub-problem and evaluates residual

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 3449 of file free_surface.cpp.

3450 {
3452 if (auto ptr = tsPrePostProc.lock()) {
3453 auto sub_u = ptr->getSubVector();
3454 auto sub_u_t = vectorDuplicate(sub_u);
3455 auto sub_f = vectorDuplicate(sub_u);
3456 auto scatter = ptr->getScatter(sub_u, u, R);
3457
3458 auto apply_scatter_and_update = [&](auto x, auto sub_x) {
3460 CHKERR VecScatterBegin(scatter, x, sub_x, INSERT_VALUES, SCATTER_REVERSE);
3461 CHKERR VecScatterEnd(scatter, x, sub_x, INSERT_VALUES, SCATTER_REVERSE);
3462 CHKERR VecGhostUpdateBegin(sub_x, INSERT_VALUES, SCATTER_FORWARD);
3463 CHKERR VecGhostUpdateEnd(sub_x, INSERT_VALUES, SCATTER_FORWARD);
3465 };
3466
3467 CHKERR apply_scatter_and_update(u, sub_u);
3468 CHKERR apply_scatter_and_update(u_t, sub_u_t);
3469
3470 CHKERR TsSetIFunction(ts, t, sub_u, sub_u_t, sub_f, ptr->tsCtxPtr.get());
3471 CHKERR VecScatterBegin(scatter, sub_f, f, INSERT_VALUES, SCATTER_FORWARD);
3472 CHKERR VecScatterEnd(scatter, sub_f, f, INSERT_VALUES, SCATTER_FORWARD);
3473 }
3475}
PetscErrorCode TsSetIFunction(TS ts, PetscReal t, Vec u, Vec u_t, Vec F, void *ctx)
Set IFunction for TS solver.
Definition TsCtx.cpp:56

◆ tsSetIJacobian()

MoFEMErrorCode TSPrePostProc::tsSetIJacobian ( TS  ts,
PetscReal  t,
Vec  u,
Vec  u_t,
PetscReal  a,
Mat  A,
Mat  B,
void *  ctx 
)
staticprivate

Set implicit Jacobian for time stepping.

Parameters
tsPETSc time stepping object
tCurrent time
uSolution vector at current time
u_tTime derivative of solution
aShift parameter for implicit methods
AJacobian matrix (input)
BJacobian matrix (output, often same as A)
ctxUser context (unused)
Returns
MoFEMErrorCode Success/failure code

Wrapper that assembles Jacobian matrix for sub-problem Wrapper for SNES Lhs

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 3477 of file free_surface.cpp.

3479 {
3481 if (auto ptr = tsPrePostProc.lock()) {
3482 auto sub_u = ptr->getSubVector();
3483 auto sub_u_t = vectorDuplicate(sub_u);
3484 auto scatter = ptr->getScatter(sub_u, u, R);
3485
3486 auto apply_scatter_and_update = [&](auto x, auto sub_x) {
3488 CHKERR VecScatterBegin(scatter, x, sub_x, INSERT_VALUES, SCATTER_REVERSE);
3489 CHKERR VecScatterEnd(scatter, x, sub_x, INSERT_VALUES, SCATTER_REVERSE);
3490 CHKERR VecGhostUpdateBegin(sub_x, INSERT_VALUES, SCATTER_FORWARD);
3491 CHKERR VecGhostUpdateEnd(sub_x, INSERT_VALUES, SCATTER_FORWARD);
3493 };
3494
3495 CHKERR apply_scatter_and_update(u, sub_u);
3496 CHKERR apply_scatter_and_update(u_t, sub_u_t);
3497
3498 CHKERR TsSetIJacobian(ts, t, sub_u, sub_u_t, a, ptr->subB, ptr->subB,
3499 ptr->tsCtxPtr.get());
3500 }
3502}
constexpr double a
PetscErrorCode TsSetIJacobian(TS ts, PetscReal t, Vec u, Vec u_t, PetscReal a, Mat A, Mat B, void *ctx)
Set function evaluating jacobian in TS solver.
Definition TsCtx.cpp:169

◆ tsSetUp() [1/2]

MoFEMErrorCode TSPrePostProc::tsSetUp ( TS  ts)

Used to setup TS solver.

Parameters
ts
Returns
MoFEMErrorCode
Examples
mofem/tutorials/adv-4/dynamic_first_order_con_law.cpp, and mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 3583 of file free_surface.cpp.

3583 {
3584
3585 auto &m_field = fsRawPtr->mField;
3586 auto simple = m_field.getInterface<Simple>();
3587
3589
3590 auto dm = simple->getDM();
3591
3593 CHKERR TSSetIFunction(ts, globRes, tsSetIFunction, nullptr);
3594 CHKERR TSSetIJacobian(ts, PETSC_NULLPTR, PETSC_NULLPTR, tsSetIJacobian, nullptr);
3595 CHKERR TSMonitorSet(ts, tsMonitor, fsRawPtr, PETSC_NULLPTR);
3596
3597 SNES snes;
3598 CHKERR TSGetSNES(ts, &snes);
3599 auto snes_ctx_ptr = getDMSnesCtx(dm);
3600
3601 auto set_section_monitor = [&](auto snes) {
3603 CHKERR SNESMonitorSet(snes,
3604 (MoFEMErrorCode(*)(SNES, PetscInt, PetscReal,
3605 void *))MoFEMSNESMonitorFields,
3606 (void *)(snes_ctx_ptr.get()), nullptr);
3608 };
3609
3610 CHKERR set_section_monitor(snes);
3611
3612 auto ksp = createKSP(m_field.get_comm());
3613 CHKERR KSPSetType(ksp, KSPPREONLY); // Run KSP internally in ShellPC
3614 auto sub_pc = createPC(fsRawPtr->mField.get_comm());
3615 CHKERR PCSetType(sub_pc, PCSHELL);
3616 CHKERR PCShellSetSetUp(sub_pc, pcSetup);
3617 CHKERR PCShellSetApply(sub_pc, pcApply);
3618 CHKERR KSPSetPC(ksp, sub_pc);
3619 CHKERR SNESSetKSP(snes, ksp);
3620
3623
3624 CHKERR TSSetPreStep(ts, tsPreProc);
3625 CHKERR TSSetPostStep(ts, tsPostProc);
3626
3628}
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
auto getDMTsCtx(DM dm)
Get TS context data structure used by DM.
Definition DMMoFEM.hpp:1276
MoFEMErrorCode MoFEMSNESMonitorFields(SNES snes, PetscInt its, PetscReal fgnorm, SnesCtx *ctx)
Sens monitor printing residual field by field.
Definition SnesCtx.cpp:592
auto createPC(MPI_Comm comm)
auto getDMSnesCtx(DM dm)
Get SNES context data structure used by DM.
Definition DMMoFEM.hpp:1262
MoFEM::Interface & mField
Reference to MoFEM interface.
Definition plastic.cpp:226
virtual MPI_Comm & get_comm() const =0
MoFEMErrorCode getDM(DM *dm)
Get DM.
Definition Simple.cpp:800
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
boost::shared_ptr< TsCtx > tsCtxPtr
SmartPetscObj< Vec > globRes
SmartPetscObj< Vec > globSol
static MoFEMErrorCode tsMonitor(TS ts, PetscInt step, PetscReal t, Vec u, void *ctx)
Monitor solution during time stepping.
static MoFEMErrorCode pcApply(PC pc, Vec pc_f, Vec pc_x)
Apply preconditioner.
static MoFEMErrorCode tsSetIJacobian(TS ts, PetscReal t, Vec u, Vec u_t, PetscReal a, Mat A, Mat B, void *ctx)
Set implicit Jacobian for time stepping.
boost::shared_ptr< SnesCtx > snesCtxPtr
static MoFEMErrorCode tsPreProc(TS ts)
Pre process time step.
static MoFEMErrorCode tsSetIFunction(TS ts, PetscReal t, Vec u, Vec u_t, Vec f, void *ctx)
Set implicit function for time stepping.
static MoFEMErrorCode pcSetup(PC pc)
Setup preconditioner.
static MoFEMErrorCode tsPostProc(TS ts)
Post process time step.

◆ tsSetUp() [2/2]

MoFEMErrorCode TSPrePostProc::tsSetUp ( TS  ts)

Used to setup TS solver.

Parameters
tsPETSc time stepping object to configure
Returns
MoFEMErrorCode Success/failure code

Sets up time stepping solver with custom preconditioner, monitors, and callback functions for mesh refinement and solution projection

Member Data Documentation

◆ fsRawPtr [1/2]

Example* TSPrePostProc::fsRawPtr

◆ fsRawPtr [2/2]

FreeSurface* TSPrePostProc::fsRawPtr

Definition at line 672 of file free_surface.cpp.

◆ globRes

SmartPetscObj<Vec> TSPrePostProc::globRes
private
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 784 of file free_surface.cpp.

◆ globSol

SmartPetscObj<Vec> TSPrePostProc::globSol
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 671 of file free_surface.cpp.

◆ snesCtxPtr

boost::shared_ptr<SnesCtx> TSPrePostProc::snesCtxPtr
private
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 789 of file free_surface.cpp.

◆ solverSubDM

SmartPetscObj<DM> TSPrePostProc::solverSubDM
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 670 of file free_surface.cpp.

◆ subB

SmartPetscObj<Mat> TSPrePostProc::subB
private
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 785 of file free_surface.cpp.

◆ subKSP

SmartPetscObj<KSP> TSPrePostProc::subKSP
private
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 786 of file free_surface.cpp.

◆ tsCtxPtr

boost::shared_ptr<TsCtx> TSPrePostProc::tsCtxPtr
private
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 791 of file free_surface.cpp.


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