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

Definition at line 383 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.cpp.

Definition at line 3562 of file free_surface.cpp.

3562 {
3563 if (auto ptr = tsPrePostProc.lock()) {
3564 auto prb_ptr = ptr->fsRawPtr->mField.get_problem("SUB_SOLVER");
3565 if (auto sub_data = prb_ptr->getSubData()) {
3566 auto is = sub_data->getSmartColIs();
3567 VecScatter s;
3568 if (fr == R) {
3569 CHK_THROW_MESSAGE(VecScatterCreate(x, PETSC_NULLPTR, y, is, &s),
3570 "crate scatter");
3571 } else {
3572 CHK_THROW_MESSAGE(VecScatterCreate(x, is, y, PETSC_NULLPTR, &s),
3573 "crate scatter");
3574 }
3575 return SmartPetscObj<VecScatter>(s);
3576 }
3577 }
3580}
#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.cpp.

Definition at line 3582 of file free_surface.cpp.

3582 {
3584}
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 3542 of file free_surface.cpp.

3542 {
3544 if (auto ptr = tsPrePostProc.lock()) {
3545 auto sub_x = ptr->getSubVector();
3546 auto sub_f = vectorDuplicate(sub_x);
3547 auto scatter = ptr->getScatter(sub_x, pc_x, R);
3548 CHKERR VecScatterBegin(scatter, pc_f, sub_f, INSERT_VALUES,
3549 SCATTER_REVERSE);
3550 CHKERR VecScatterEnd(scatter, pc_f, sub_f, INSERT_VALUES, SCATTER_REVERSE);
3551 CHKERR KSPSetOperators(ptr->subKSP, ptr->subB, ptr->subB);
3552 MOFEM_LOG("FS", Sev::verbose) << "PCShell solve";
3553 CHKERR KSPSolve(ptr->subKSP, sub_f, sub_x);
3554 MOFEM_LOG("FS", Sev::verbose) << "PCShell solve <- done";
3555 CHKERR VecScatterBegin(scatter, sub_x, pc_x, INSERT_VALUES,
3556 SCATTER_FORWARD);
3557 CHKERR VecScatterEnd(scatter, sub_x, pc_x, INSERT_VALUES, SCATTER_FORWARD);
3558 }
3560};
#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 3532 of file free_surface.cpp.

3532 {
3534 if (auto ptr = tsPrePostProc.lock()) {
3535 MOFEM_LOG("FS", Sev::verbose) << "SetUP sub PC";
3536 ptr->subKSP = createKSP(ptr->fsRawPtr->mField.get_comm());
3537 CHKERR KSPSetFromOptions(ptr->subKSP);
3538 }
3540};
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 3507 of file free_surface.cpp.

3508 {
3510 if (auto ptr = tsPrePostProc.lock()) {
3511 auto get_norm = [&](auto x) {
3512 double nrm;
3513 CHKERR VecNorm(x, NORM_2, &nrm);
3514 return nrm;
3515 };
3516
3517 auto sub_u = ptr->getSubVector();
3518 auto scatter = ptr->getScatter(sub_u, u, R);
3519 CHKERR VecScatterBegin(scatter, u, sub_u, INSERT_VALUES, SCATTER_REVERSE);
3520 CHKERR VecScatterEnd(scatter, u, sub_u, INSERT_VALUES, SCATTER_REVERSE);
3521 CHKERR VecGhostUpdateBegin(sub_u, INSERT_VALUES, SCATTER_FORWARD);
3522 CHKERR VecGhostUpdateEnd(sub_u, INSERT_VALUES, SCATTER_FORWARD);
3523
3524 MOFEM_LOG("FS", Sev::verbose)
3525 << "u norm " << get_norm(u) << " u sub nom " << get_norm(sub_u);
3526
3527 CHKERR TsMonitorSet(ts, step, t, sub_u, ptr->tsCtxPtr.get());
3528 }
3530}
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.cpp, and thermoplastic.cpp.

Definition at line 3442 of file free_surface.cpp.

3442 {
3443 if (auto ptr = tsPrePostProc.lock()) {
3444 auto &m_field = ptr->fsRawPtr->mField;
3445 MOFEM_LOG_CHANNEL("SYNC");
3446 MOFEM_TAG_AND_LOG("SYNC", Sev::verbose, "FS") << "PostProc done";
3447 MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::verbose);
3448 }
3449 return 0;
3450}
#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.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() [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.cpp, and thermoplastic.cpp.

Definition at line 3327 of file free_surface.cpp.

3327 {
3329
3330 if (auto ptr = tsPrePostProc.lock()) {
3331
3332 /**
3333 * @brief cut-off values at nodes, i.e. abs("H") <= 1
3334 *
3335 */
3336 auto cut_off_dofs = [&]() {
3338
3339 auto &m_field = ptr->fsRawPtr->mField;
3340
3341 Range current_verts;
3342 auto bit_mng = m_field.getInterface<BitRefManager>();
3344 bit(get_current_bit()), BitRefLevel().set(), MBVERTEX, current_verts);
3345
3346 auto cut_off_verts = [&](boost::shared_ptr<FieldEntity> ent_ptr) {
3348 for (auto &h : ent_ptr->getEntFieldData()) {
3349 h = cut_off(h);
3350 }
3352 };
3353
3354 auto field_blas = m_field.getInterface<FieldBlas>();
3355 CHKERR field_blas->fieldLambdaOnEntities(cut_off_verts, "H",
3356 &current_verts);
3358 };
3359
3360 CHKERR cut_off_dofs();
3361 }
3362
3363 if (auto ptr = tsPrePostProc.lock()) {
3364 MOFEM_LOG("FS", Sev::inform) << "Run step pre proc";
3365
3366 auto &m_field = ptr->fsRawPtr->mField;
3367 auto simple = m_field.getInterface<Simple>();
3368
3369 // get vector norm
3370 auto get_norm = [&](auto x) {
3371 double nrm;
3372 CHKERR VecNorm(x, NORM_2, &nrm);
3373 return nrm;
3374 };
3375
3376 // refine problem and project data, including theta data
3377 auto refine_problem = [&]() {
3379 MOFEM_LOG("FS", Sev::inform) << "Refine problem";
3380 CHKERR ptr->fsRawPtr->refineMesh(refine_overlap);
3381 CHKERR ptr->fsRawPtr->projectData();
3383 };
3384
3385 // set new jacobin operator, since problem and thus tangent matrix size has
3386 // changed
3387 auto set_jacobian_operators = [&]() {
3389 ptr->subB = createDMMatrix(ptr->solverSubDM);
3390 CHKERR KSPReset(ptr->subKSP);
3392 };
3393
3394 // set new solution
3395 auto set_solution = [&]() {
3397 MOFEM_LOG("FS", Sev::inform) << "Set solution";
3398
3399 PetscObjectState state;
3400
3401 // Record the state, and set it again. This is to fool PETSc that solution
3402 // vector is not updated. Otherwise PETSc will treat every step as a first
3403 // step.
3404
3405 // globSol is updated as result mesh refinement - this is not really set
3406 // a new solution.
3407
3408 CHKERR PetscObjectStateGet(getPetscObject(ptr->globSol.get()), &state);
3409 CHKERR DMoFEMMeshToLocalVector(simple->getDM(), ptr->globSol,
3410 INSERT_VALUES, SCATTER_FORWARD);
3411 CHKERR PetscObjectStateSet(getPetscObject(ptr->globSol.get()), state);
3412 MOFEM_LOG("FS", Sev::verbose)
3413 << "Set solution, vector norm " << get_norm(ptr->globSol);
3415 };
3416
3417 PetscBool is_theta;
3418 PetscObjectTypeCompare((PetscObject)ts, TSTHETA, &is_theta);
3419 if (is_theta) {
3420
3421 CHKERR refine_problem(); // refine problem
3422 CHKERR set_jacobian_operators(); // set new jacobian
3423 CHKERR set_solution(); // set solution
3424
3425 } else {
3426 SETERRQ(PETSC_COMM_WORLD, MOFEM_NOT_IMPLEMENTED,
3427 "Sorry, only TSTheta handling is implemented");
3428 }
3429
3430 // Need barriers, some functions in TS solver need are called collectively
3431 // and require the same state of variables
3432 PetscBarrier((PetscObject)ts);
3433
3434 MOFEM_LOG_CHANNEL("SYNC");
3435 MOFEM_TAG_AND_LOG("SYNC", Sev::verbose, "FS") << "PreProc done";
3436 MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::verbose);
3437 }
3438
3440}
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)
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
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.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.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 3452 of file free_surface.cpp.

3453 {
3455 if (auto ptr = tsPrePostProc.lock()) {
3456 auto sub_u = ptr->getSubVector();
3457 auto sub_u_t = vectorDuplicate(sub_u);
3458 auto sub_f = vectorDuplicate(sub_u);
3459 auto scatter = ptr->getScatter(sub_u, u, R);
3460
3461 auto apply_scatter_and_update = [&](auto x, auto sub_x) {
3463 CHKERR VecScatterBegin(scatter, x, sub_x, INSERT_VALUES, SCATTER_REVERSE);
3464 CHKERR VecScatterEnd(scatter, x, sub_x, INSERT_VALUES, SCATTER_REVERSE);
3465 CHKERR VecGhostUpdateBegin(sub_x, INSERT_VALUES, SCATTER_FORWARD);
3466 CHKERR VecGhostUpdateEnd(sub_x, INSERT_VALUES, SCATTER_FORWARD);
3468 };
3469
3470 CHKERR apply_scatter_and_update(u, sub_u);
3471 CHKERR apply_scatter_and_update(u_t, sub_u_t);
3472
3473 CHKERR TsSetIFunction(ts, t, sub_u, sub_u_t, sub_f, ptr->tsCtxPtr.get());
3474 CHKERR VecScatterBegin(scatter, sub_f, f, INSERT_VALUES, SCATTER_FORWARD);
3475 CHKERR VecScatterEnd(scatter, sub_f, f, INSERT_VALUES, SCATTER_FORWARD);
3476 }
3478}
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 3480 of file free_surface.cpp.

3482 {
3484 if (auto ptr = tsPrePostProc.lock()) {
3485 auto sub_u = ptr->getSubVector();
3486 auto sub_u_t = vectorDuplicate(sub_u);
3487 auto scatter = ptr->getScatter(sub_u, u, R);
3488
3489 auto apply_scatter_and_update = [&](auto x, auto sub_x) {
3491 CHKERR VecScatterBegin(scatter, x, sub_x, INSERT_VALUES, SCATTER_REVERSE);
3492 CHKERR VecScatterEnd(scatter, x, sub_x, INSERT_VALUES, SCATTER_REVERSE);
3493 CHKERR VecGhostUpdateBegin(sub_x, INSERT_VALUES, SCATTER_FORWARD);
3494 CHKERR VecGhostUpdateEnd(sub_x, INSERT_VALUES, SCATTER_FORWARD);
3496 };
3497
3498 CHKERR apply_scatter_and_update(u, sub_u);
3499 CHKERR apply_scatter_and_update(u_t, sub_u_t);
3500
3501 CHKERR TsSetIJacobian(ts, t, sub_u, sub_u_t, a, ptr->subB, ptr->subB,
3502 ptr->tsCtxPtr.get());
3503 }
3505}
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.cpp, mofem/tutorials/vec-5/free_surface.cpp, and thermoplastic.cpp.

Definition at line 3586 of file free_surface.cpp.

3586 {
3587
3588 auto &m_field = fsRawPtr->mField;
3589 auto simple = m_field.getInterface<Simple>();
3590
3592
3593 auto dm = simple->getDM();
3594
3596 CHKERR TSSetIFunction(ts, globRes, tsSetIFunction, nullptr);
3597 CHKERR TSSetIJacobian(ts, PETSC_NULLPTR, PETSC_NULLPTR, tsSetIJacobian, nullptr);
3598 CHKERR TSMonitorSet(ts, tsMonitor, fsRawPtr, PETSC_NULLPTR);
3599
3600 SNES snes;
3601 CHKERR TSGetSNES(ts, &snes);
3602 auto snes_ctx_ptr = getDMSnesCtx(dm);
3603
3604 auto set_section_monitor = [&](auto snes) {
3606 CHKERR SNESMonitorSet(snes,
3607 (MoFEMErrorCode(*)(SNES, PetscInt, PetscReal,
3608 void *))MoFEMSNESMonitorFields,
3609 (void *)(snes_ctx_ptr.get()), nullptr);
3611 };
3612
3613 CHKERR set_section_monitor(snes);
3614
3615 auto ksp = createKSP(m_field.get_comm());
3616 CHKERR KSPSetType(ksp, KSPPREONLY); // Run KSP internally in ShellPC
3617 auto sub_pc = createPC(fsRawPtr->mField.get_comm());
3618 CHKERR PCSetType(sub_pc, PCSHELL);
3619 CHKERR PCShellSetSetUp(sub_pc, pcSetup);
3620 CHKERR PCShellSetApply(sub_pc, pcApply);
3621 CHKERR KSPSetPC(ksp, sub_pc);
3622 CHKERR SNESSetKSP(snes, ksp);
3623
3626
3627 CHKERR TSSetPreStep(ts, tsPreProc);
3628 CHKERR TSSetPostStep(ts, tsPostProc);
3629
3631}
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:596
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/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 601 of file thermoplastic.cpp.

◆ 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: