v0.16.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.
 
 TSPrePostProc ()=default
 
virtual ~TSPrePostProc ()=default
 
MoFEMErrorCode tsSetUp (TS ts)
 Used to setup TS solver.
 

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
 
ExampleExRawPtr
 

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.
 
static MoFEMErrorCode tsPreProc (TS ts)
 Pre process time step.
 
static MoFEMErrorCode tsPostProc (TS ts)
 Post process time step.
 
static MoFEMErrorCode tsPreStage (TS ts)
 

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/dynamic_first_order_con_law.cpp, mofem/tutorials/vec-5_free_surface/free_surface.cpp, and thermoplastic.cpp.

Definition at line 380 of file dynamic_first_order_con_law.cpp.

Constructor & Destructor Documentation

◆ TSPrePostProc() [1/3]

TSPrePostProc::TSPrePostProc ( )
default

◆ ~TSPrePostProc() [1/3]

virtual TSPrePostProc::~TSPrePostProc ( )
virtualdefault

◆ TSPrePostProc() [2/3]

TSPrePostProc::TSPrePostProc ( )
default

◆ ~TSPrePostProc() [2/3]

virtual TSPrePostProc::~TSPrePostProc ( )
virtualdefault

◆ TSPrePostProc() [3/3]

TSPrePostProc::TSPrePostProc ( )
default

◆ ~TSPrePostProc() [3/3]

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/free_surface.cpp.

Definition at line 3583 of file free_surface.cpp.

3583 {
3584 if (auto ptr = tsPrePostProc.lock()) {
3585 auto prb_ptr = ptr->fsRawPtr->mField.get_problem("SUB_SOLVER");
3586 if (auto sub_data = prb_ptr->getSubData()) {
3587 auto is = sub_data->getSmartColIs();
3588 VecScatter s;
3589 if (fr == R) {
3590 CHK_THROW_MESSAGE(VecScatterCreate(x, PETSC_NULLPTR, y, is, &s),
3591 "crate scatter");
3592 } else {
3593 CHK_THROW_MESSAGE(VecScatterCreate(x, is, y, PETSC_NULLPTR, &s),
3594 "crate scatter");
3595 }
3596 return SmartPetscObj<VecScatter>(s);
3597 }
3598 }
3601}
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
@ R
intrusive_ptr for managing petsc objects
static boost::weak_ptr< TSPrePostProc > tsPrePostProc

◆ 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/free_surface.cpp.

Definition at line 3603 of file free_surface.cpp.

3603 {
3605}
auto createDMVector(DM dm, RowColData rc=RowColData::COL)
Get smart vector from DM.
Definition DMMoFEM.hpp:1237
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/free_surface.cpp.

Definition at line 3563 of file free_surface.cpp.

3563 {
3565 if (auto ptr = tsPrePostProc.lock()) {
3566 auto sub_x = ptr->getSubVector();
3567 auto sub_f = vectorDuplicate(sub_x);
3568 auto scatter = ptr->getScatter(sub_x, pc_x, R);
3569 CHKERR VecScatterBegin(scatter, pc_f, sub_f, INSERT_VALUES,
3570 SCATTER_REVERSE);
3571 CHKERR VecScatterEnd(scatter, pc_f, sub_f, INSERT_VALUES, SCATTER_REVERSE);
3572 CHKERR KSPSetOperators(ptr->subKSP, ptr->subB, ptr->subB);
3573 MOFEM_LOG("FS", Sev::verbose) << "PCShell solve";
3574 CHKERR KSPSolve(ptr->subKSP, sub_f, sub_x);
3575 MOFEM_LOG("FS", Sev::verbose) << "PCShell solve <- done";
3576 CHKERR VecScatterBegin(scatter, sub_x, pc_x, INSERT_VALUES,
3577 SCATTER_FORWARD);
3578 CHKERR VecScatterEnd(scatter, sub_x, pc_x, INSERT_VALUES, SCATTER_FORWARD);
3579 }
3581};
#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/free_surface.cpp.

Definition at line 3553 of file free_surface.cpp.

3553 {
3555 if (auto ptr = tsPrePostProc.lock()) {
3556 MOFEM_LOG("FS", Sev::verbose) << "SetUP sub PC";
3557 ptr->subKSP = createKSP(ptr->fsRawPtr->mField.get_comm());
3558 CHKERR KSPSetFromOptions(ptr->subKSP);
3559 }
3561};
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/free_surface.cpp.

Definition at line 3528 of file free_surface.cpp.

3529 {
3531 if (auto ptr = tsPrePostProc.lock()) {
3532 auto get_norm = [&](auto x) {
3533 double nrm;
3534 CHKERR VecNorm(x, NORM_2, &nrm);
3535 return nrm;
3536 };
3537
3538 auto sub_u = ptr->getSubVector();
3539 auto scatter = ptr->getScatter(sub_u, u, R);
3540 CHKERR VecScatterBegin(scatter, u, sub_u, INSERT_VALUES, SCATTER_REVERSE);
3541 CHKERR VecScatterEnd(scatter, u, sub_u, INSERT_VALUES, SCATTER_REVERSE);
3542 CHKERR VecGhostUpdateBegin(sub_u, INSERT_VALUES, SCATTER_FORWARD);
3543 CHKERR VecGhostUpdateEnd(sub_u, INSERT_VALUES, SCATTER_FORWARD);
3544
3545 MOFEM_LOG("FS", Sev::verbose)
3546 << "u norm " << get_norm(u) << " u sub nom " << get_norm(sub_u);
3547
3548 CHKERR TsMonitorSet(ts, step, t, sub_u, ptr->tsCtxPtr.get());
3549 }
3551}
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() [1/2]

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/free_surface.cpp, and thermoplastic.cpp.

Definition at line 3463 of file free_surface.cpp.

3463 {
3464 if (auto ptr = tsPrePostProc.lock()) {
3465 auto &m_field = ptr->fsRawPtr->mField;
3466 MOFEM_LOG_CHANNEL("SYNC");
3467 MOFEM_TAG_AND_LOG("SYNC", Sev::verbose, "FS") << "PostProc done";
3468 MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::verbose);
3469 }
3470 return 0;
3471}
#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.

◆ tsPostProc() [2/2]

static MoFEMErrorCode TSPrePostProc::tsPostProc ( TS  ts)
staticprivate

Post process time step.

Currently that function do not make anything major

Parameters
ts
Returns
MoFEMErrorCode

◆ 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/dynamic_first_order_con_law.cpp.

Definition at line 577 of file dynamic_first_order_con_law.cpp.

578 {
580 // cerr << "tsPostStage " <<"\n";
581 if (auto ptr = tsPrePostProc.lock()) {
582 auto &m_field = ptr->fsRawPtr->mField;
583
584 auto fb = m_field.getInterface<FieldBlas>();
585 double dt;
586 CHKERR TSGetTimeStep(ts, &dt);
587 double time;
588 CHKERR TSGetTime(ts, &time);
589 PetscInt num_stages;
590 Vec *stage_solutions;
591
592 CHKERR TSGetStages(ts, &num_stages, &stage_solutions);
593 PetscPrintf(PETSC_COMM_WORLD, "Check timestep %d time %e dt %e\n",
594 num_stages, time, dt);
595
596 const double inv_num_step = (double)num_stages;
597 CHKERR fb->fieldCopy(1., "x_1", "x_2");
598 CHKERR fb->fieldAxpy(dt, "V", "x_2");
599 CHKERR fb->fieldCopy(1., "x_2", "x_1");
600
601 CHKERR fb->fieldCopy(-inv_num_step / dt, "F_0", "F_dot");
602 CHKERR fb->fieldAxpy(inv_num_step / dt, "F", "F_dot");
603 CHKERR fb->fieldCopy(1., "F", "F_0");
604 }
606}
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/dynamic_first_order_con_law.cpp.

Definition at line 608 of file dynamic_first_order_con_law.cpp.

608 {
610
611 if (auto ptr = tsPrePostProc.lock()) {
612 double dt;
613 CHKERR TSGetTimeStep(ts, &dt);
614 double time;
615 CHKERR TSGetTime(ts, &time);
616 }
618}

◆ tsPreProc() [1/2]

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/free_surface.cpp, and thermoplastic.cpp.

Definition at line 3348 of file free_surface.cpp.

3348 {
3350
3351 if (auto ptr = tsPrePostProc.lock()) {
3352
3353 /**
3354 * @brief cut-off values at nodes, i.e. abs("H") <= 1
3355 *
3356 */
3357 auto cut_off_dofs = [&]() {
3359
3360 auto &m_field = ptr->fsRawPtr->mField;
3361
3362 Range current_verts;
3363 auto bit_mng = m_field.getInterface<BitRefManager>();
3365 bit(get_current_bit()), BitRefLevel().set(), MBVERTEX, current_verts);
3366
3367 auto cut_off_verts = [&](boost::shared_ptr<FieldEntity> ent_ptr) {
3369 for (auto &h : ent_ptr->getEntFieldData()) {
3370 h = cut_off(h);
3371 }
3373 };
3374
3375 auto field_blas = m_field.getInterface<FieldBlas>();
3376 CHKERR field_blas->fieldLambdaOnEntities(cut_off_verts, "H",
3377 &current_verts);
3379 };
3380
3381 CHKERR cut_off_dofs();
3382 }
3383
3384 if (auto ptr = tsPrePostProc.lock()) {
3385 MOFEM_LOG("FS", Sev::inform) << "Run step pre proc";
3386
3387 auto &m_field = ptr->fsRawPtr->mField;
3388 auto simple = m_field.getInterface<Simple>();
3389
3390 // get vector norm
3391 auto get_norm = [&](auto x) {
3392 double nrm;
3393 CHKERR VecNorm(x, NORM_2, &nrm);
3394 return nrm;
3395 };
3396
3397 // refine problem and project data, including theta data
3398 auto refine_problem = [&]() {
3400 MOFEM_LOG("FS", Sev::inform) << "Refine problem";
3401 CHKERR ptr->fsRawPtr->refineMesh(refine_overlap);
3402 CHKERR ptr->fsRawPtr->projectData();
3404 };
3405
3406 // set new jacobin operator, since problem and thus tangent matrix size has
3407 // changed
3408 auto set_jacobian_operators = [&]() {
3410 ptr->subB = createDMMatrix(ptr->solverSubDM);
3411 CHKERR KSPReset(ptr->subKSP);
3413 };
3414
3415 // set new solution
3416 auto set_solution = [&]() {
3418 MOFEM_LOG("FS", Sev::inform) << "Set solution";
3419
3420 PetscObjectState state;
3421
3422 // Record the state, and set it again. This is to fool PETSc that solution
3423 // vector is not updated. Otherwise PETSc will treat every step as a first
3424 // step.
3425
3426 // globSol is updated as result mesh refinement - this is not really set
3427 // a new solution.
3428
3429 CHKERR PetscObjectStateGet(getPetscObject(ptr->globSol.get()), &state);
3430 CHKERR DMoFEMMeshToLocalVector(simple->getDM(), ptr->globSol,
3431 INSERT_VALUES, SCATTER_FORWARD);
3432 CHKERR PetscObjectStateSet(getPetscObject(ptr->globSol.get()), state);
3433 MOFEM_LOG("FS", Sev::verbose)
3434 << "Set solution, vector norm " << get_norm(ptr->globSol);
3436 };
3437
3438 PetscBool is_theta;
3439 PetscObjectTypeCompare((PetscObject)ts, TSTHETA, &is_theta);
3440 if (is_theta) {
3441
3442 CHKERR refine_problem(); // refine problem
3443 CHKERR set_jacobian_operators(); // set new jacobian
3444 CHKERR set_solution(); // set solution
3445
3446 } else {
3447 SETERRQ(PETSC_COMM_WORLD, MOFEM_NOT_IMPLEMENTED,
3448 "Sorry, only TSTheta handling is implemented");
3449 }
3450
3451 // Need barriers, some functions in TS solver need are called collectively
3452 // and require the same state of variables
3453 PetscBarrier((PetscObject)ts);
3454
3455 MOFEM_LOG_CHANNEL("SYNC");
3456 MOFEM_TAG_AND_LOG("SYNC", Sev::verbose, "FS") << "PreProc done";
3457 MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::verbose);
3458 }
3459
3461}
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition acoustic.cpp:69
@ MOFEM_NOT_IMPLEMENTED
Definition definitions.h:32
int refine_overlap
auto cut_off
Phase field cutoff function.
auto get_current_bit
dofs bit used to do calculations
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode, RowColData rc=RowColData::COL)
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:1194
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
auto bit
set bit
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)
double h
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

◆ tsPreProc() [2/2]

static MoFEMErrorCode TSPrePostProc::tsPreProc ( TS  ts)
staticprivate

Pre process time step.

Refine mesh and update fields

Parameters
ts
Returns
MoFEMErrorCode

◆ tsPreStage() [1/2]

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/free_surface.cpp, and thermoplastic.cpp.

◆ tsPreStage() [2/2]

static MoFEMErrorCode TSPrePostProc::tsPreStage ( TS  ts)
staticprivate

◆ tsPreStep()

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

Definition at line 620 of file dynamic_first_order_con_law.cpp.

620 {
622
623 if (auto ptr = tsPrePostProc.lock()) {
624 double dt;
625 CHKERR TSGetTimeStep(ts, &dt);
626 double time;
627 CHKERR TSGetTime(ts, &time);
628 int step_num;
629 CHKERR TSGetStepNumber(ts, &step_num);
630 }
632}

◆ 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/free_surface.cpp.

Definition at line 3473 of file free_surface.cpp.

3474 {
3476 if (auto ptr = tsPrePostProc.lock()) {
3477 auto sub_u = ptr->getSubVector();
3478 auto sub_u_t = vectorDuplicate(sub_u);
3479 auto sub_f = vectorDuplicate(sub_u);
3480 auto scatter = ptr->getScatter(sub_u, u, R);
3481
3482 auto apply_scatter_and_update = [&](auto x, auto sub_x) {
3484 CHKERR VecScatterBegin(scatter, x, sub_x, INSERT_VALUES, SCATTER_REVERSE);
3485 CHKERR VecScatterEnd(scatter, x, sub_x, INSERT_VALUES, SCATTER_REVERSE);
3486 CHKERR VecGhostUpdateBegin(sub_x, INSERT_VALUES, SCATTER_FORWARD);
3487 CHKERR VecGhostUpdateEnd(sub_x, INSERT_VALUES, SCATTER_FORWARD);
3489 };
3490
3491 CHKERR apply_scatter_and_update(u, sub_u);
3492 CHKERR apply_scatter_and_update(u_t, sub_u_t);
3493
3494 CHKERR TsSetIFunction(ts, t, sub_u, sub_u_t, sub_f, ptr->tsCtxPtr.get());
3495 CHKERR VecScatterBegin(scatter, sub_f, f, INSERT_VALUES, SCATTER_FORWARD);
3496 CHKERR VecScatterEnd(scatter, sub_f, f, INSERT_VALUES, SCATTER_FORWARD);
3497 }
3499}
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/free_surface.cpp.

Definition at line 3501 of file free_surface.cpp.

3503 {
3505 if (auto ptr = tsPrePostProc.lock()) {
3506 auto sub_u = ptr->getSubVector();
3507 auto sub_u_t = vectorDuplicate(sub_u);
3508 auto scatter = ptr->getScatter(sub_u, u, R);
3509
3510 auto apply_scatter_and_update = [&](auto x, auto sub_x) {
3512 CHKERR VecScatterBegin(scatter, x, sub_x, INSERT_VALUES, SCATTER_REVERSE);
3513 CHKERR VecScatterEnd(scatter, x, sub_x, INSERT_VALUES, SCATTER_REVERSE);
3514 CHKERR VecGhostUpdateBegin(sub_x, INSERT_VALUES, SCATTER_FORWARD);
3515 CHKERR VecGhostUpdateEnd(sub_x, INSERT_VALUES, SCATTER_FORWARD);
3517 };
3518
3519 CHKERR apply_scatter_and_update(u, sub_u);
3520 CHKERR apply_scatter_and_update(u_t, sub_u_t);
3521
3522 CHKERR TsSetIJacobian(ts, t, sub_u, sub_u_t, a, ptr->subB, ptr->subB,
3523 ptr->tsCtxPtr.get());
3524 }
3526}
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/3]

MoFEMErrorCode TSPrePostProc::tsSetUp ( TS  ts)

Used to setup TS solver.

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

Definition at line 3607 of file free_surface.cpp.

3607 {
3608
3609 auto &m_field = fsRawPtr->mField;
3610 auto simple = m_field.getInterface<Simple>();
3611
3613
3614 auto dm = simple->getDM();
3615
3617 CHKERR TSSetIFunction(ts, globRes, tsSetIFunction, nullptr);
3618 CHKERR TSSetIJacobian(ts, PETSC_NULLPTR, PETSC_NULLPTR, tsSetIJacobian, nullptr);
3619 CHKERR TSMonitorSet(ts, tsMonitor, fsRawPtr, PETSC_NULLPTR);
3620
3621 SNES snes;
3622 CHKERR TSGetSNES(ts, &snes);
3623 auto snes_ctx_ptr = getDMSnesCtx(dm);
3624
3625 auto set_section_monitor = [&](auto snes) {
3627 CHKERR SNESMonitorSet(snes,
3628 (MoFEMErrorCode(*)(SNES, PetscInt, PetscReal,
3629 void *))MoFEMSNESMonitorFields,
3630 (void *)(snes_ctx_ptr.get()), nullptr);
3632 };
3633
3634 CHKERR set_section_monitor(snes);
3635
3636 auto ksp = createKSP(m_field.get_comm());
3637 CHKERR KSPSetType(ksp, KSPPREONLY); // Run KSP internally in ShellPC
3638 auto sub_pc = createPC(fsRawPtr->mField.get_comm());
3639 CHKERR PCSetType(sub_pc, PCSHELL);
3640 CHKERR PCShellSetSetUp(sub_pc, pcSetup);
3641 CHKERR PCShellSetApply(sub_pc, pcApply);
3642 CHKERR KSPSetPC(ksp, sub_pc);
3643 CHKERR SNESSetKSP(snes, ksp);
3644
3647
3648 CHKERR TSSetPreStep(ts, tsPreProc);
3649 CHKERR TSSetPostStep(ts, tsPostProc);
3650
3652}
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
auto getDMTsCtx(DM dm)
Get TS context data structure used by DM.
Definition DMMoFEM.hpp:1279
MoFEMErrorCode MoFEMSNESMonitorFields(SNES snes, PetscInt its, PetscReal fgnorm, SnesCtx *ctx)
Sens monitor printing residual field by field.
Definition SnesCtx.cpp:600
auto createPC(MPI_Comm comm)
auto getDMSnesCtx(DM dm)
Get SNES context data structure used by DM.
Definition DMMoFEM.hpp:1265
MoFEM::Interface & mField
Reference to MoFEM interface.
Definition plastic.cpp:227
virtual MPI_Comm & get_comm() const =0
MoFEMErrorCode getDM(DM *dm)
Get DM.
Definition Simple.cpp:799
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/3]

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

◆ tsSetUp() [3/3]

MoFEMErrorCode TSPrePostProc::tsSetUp ( TS  ts)

Used to setup TS solver.

Parameters
ts
Returns
MoFEMErrorCode

Member Data Documentation

◆ ExRawPtr

Example* TSPrePostProc::ExRawPtr
Examples
thermoplastic.cpp.

Definition at line 663 of file thermoplastic.cpp.

◆ fsRawPtr [1/2]

Example* TSPrePostProc::fsRawPtr

◆ fsRawPtr [2/2]

FreeSurface* TSPrePostProc::fsRawPtr

Definition at line 678 of file free_surface.cpp.

◆ globRes

SmartPetscObj<Vec> TSPrePostProc::globRes
private

◆ globSol

SmartPetscObj<Vec> TSPrePostProc::globSol

◆ snesCtxPtr

boost::shared_ptr<SnesCtx> TSPrePostProc::snesCtxPtr
private

◆ solverSubDM

SmartPetscObj<DM> TSPrePostProc::solverSubDM

◆ subB

SmartPetscObj<Mat> TSPrePostProc::subB
private

◆ subKSP

SmartPetscObj<KSP> TSPrePostProc::subKSP
private

◆ tsCtxPtr

boost::shared_ptr<TsCtx> TSPrePostProc::tsCtxPtr
private

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