v0.8.23
Public Types | Public Member Functions | Public Attributes | Private Attributes | Friends | List of all members
MoFEM::KspCtx Struct Reference

Interface for linear (KSP) solver. More...

#include <src/petsc/KspCtx.hpp>

Collaboration diagram for MoFEM::KspCtx:
[legend]

Public Types

typedef MoFEM::PairNameFEMethodPtr PairNameFEMethodPtr
 
typedef MoFEM::FEMethodsSequence FEMethodsSequence
 
typedef MoFEM::BasicMethodsSequence BasicMethodsSequence
 

Public Member Functions

 KspCtx (MoFEM::Interface &m_field, const std::string &_problem_name)
 
virtual ~KspCtx ()
 
FEMethodsSequenceget_loops_to_do_Mat ()
 
FEMethodsSequenceget_loops_to_do_Rhs ()
 
BasicMethodsSequenceget_preProcess_to_do_Rhs ()
 
BasicMethodsSequenceget_postProcess_to_do_Rhs ()
 
BasicMethodsSequenceget_preProcess_to_do_Mat ()
 
BasicMethodsSequenceget_postProcess_to_do_Mat ()
 

Public Attributes

DEPRECATED typedef MoFEM::PairNameFEMethodPtr loop_pair_type
 
DEPRECATED typedef MoFEM::FEMethodsSequence loops_to_do_type
 
DEPRECATED typedef MoFEM::BasicMethodsSequence basic_method_to_do
 
MoFEM::InterfacemField
 
moab::Interface & moab
 
std::string problemName
 Problem name. More...
 
MoFEMTypes bH
 If set to MF_EXIST check if element exist. More...
 
FEMethodsSequence loops_to_do_Mat
 
FEMethodsSequence loops_to_do_Rhs
 
BasicMethodsSequence preProcess_Mat
 
BasicMethodsSequence postProcess_Mat
 
BasicMethodsSequence preProcess_Rhs
 Sequence of methods run before residual is assembled. More...
 
BasicMethodsSequence postProcess_Rhs
 Sequence of methods run after residual is assembled. More...
 

Private Attributes

PetscLogEvent MOFEM_EVENT_KspRhs
 
PetscLogEvent MOFEM_EVENT_KspMat
 
boost::movelib::unique_ptr< boolvecAssembleSwitch
 
boost::movelib::unique_ptr< boolmatAssembleSwitch
 

Friends

PetscErrorCode KspRhs (KSP ksp, Vec f, void *ctx)
 Run over elements in the lists. More...
 
PetscErrorCode KspMat (KSP ksp, Mat A, Mat B, void *ctx)
 Run over elenents in the list. More...
 

Detailed Description

Interface for linear (KSP) solver.

Definition at line 27 of file KspCtx.hpp.

Member Typedef Documentation

◆ BasicMethodsSequence

Definition at line 46 of file KspCtx.hpp.

◆ FEMethodsSequence

Definition at line 45 of file KspCtx.hpp.

◆ PairNameFEMethodPtr

Definition at line 44 of file KspCtx.hpp.

Constructor & Destructor Documentation

◆ KspCtx()

MoFEM::KspCtx::KspCtx ( MoFEM::Interface m_field,
const std::string &  _problem_name 
)

Definition at line 61 of file KspCtx.hpp.

62  : mField(m_field), moab(m_field.get_moab()), problemName(_problem_name),
63  bH(MF_EXIST) {
64  PetscLogEventRegister("LoopKSPRhs", 0, &MOFEM_EVENT_KspRhs);
65  PetscLogEventRegister("LoopKSPMat", 0, &MOFEM_EVENT_KspMat);
66  }
virtual moab::Interface & get_moab()=0
std::string problemName
Problem name.
Definition: KspCtx.hpp:32
MoFEMTypes bH
If set to MF_EXIST check if element exist.
Definition: KspCtx.hpp:33
MoFEM::Interface & mField
Definition: KspCtx.hpp:29
PetscLogEvent MOFEM_EVENT_KspRhs
Definition: KspCtx.hpp:116
moab::Interface & moab
Definition: KspCtx.hpp:30
PetscLogEvent MOFEM_EVENT_KspMat
Definition: KspCtx.hpp:117

◆ ~KspCtx()

virtual MoFEM::KspCtx::~KspCtx ( )
virtual

Definition at line 67 of file KspCtx.hpp.

67 {}

Member Function Documentation

◆ get_loops_to_do_Mat()

FEMethodsSequence& MoFEM::KspCtx::get_loops_to_do_Mat ( )
Returns
return reference to vector with FEMethod to calculate matrix

Definition at line 72 of file KspCtx.hpp.

72 { return loops_to_do_Mat; }
FEMethodsSequence loops_to_do_Mat
Definition: KspCtx.hpp:48

◆ get_loops_to_do_Rhs()

FEMethodsSequence& MoFEM::KspCtx::get_loops_to_do_Rhs ( )
Returns
return vector to vector with FEMethod to vector

Definition at line 77 of file KspCtx.hpp.

77 { return loops_to_do_Rhs; }
FEMethodsSequence loops_to_do_Rhs
Definition: KspCtx.hpp:50

◆ get_postProcess_to_do_Mat()

BasicMethodsSequence& MoFEM::KspCtx::get_postProcess_to_do_Mat ( )

The sequence of BasicMethod is executed after tangent matrix is calculated. It can be used to setup data structures, e.g. aggregate data from processors or to apply essential boundary conditions.

Returns
reference to BasicMethod for postprocessing

Definition at line 109 of file KspCtx.hpp.

109 { return postProcess_Mat; }
BasicMethodsSequence postProcess_Mat
Definition: KspCtx.hpp:54

◆ get_postProcess_to_do_Rhs()

BasicMethodsSequence& MoFEM::KspCtx::get_postProcess_to_do_Rhs ( )

The sequence of BasicMethod is executed after residual is calculated. It can be used to setup data structures, e.g. aggregate data from processors or to apply essential boundary conditions.

Returns
reference to BasicMethod for postprocessing

Definition at line 95 of file KspCtx.hpp.

95 { return postProcess_Rhs; }
BasicMethodsSequence postProcess_Rhs
Sequence of methods run after residual is assembled.
Definition: KspCtx.hpp:59

◆ get_preProcess_to_do_Mat()

BasicMethodsSequence& MoFEM::KspCtx::get_preProcess_to_do_Mat ( )
Returns
reference to BasicMethod for preprocessing

Definition at line 100 of file KspCtx.hpp.

100 { return preProcess_Mat; }
BasicMethodsSequence preProcess_Mat
Definition: KspCtx.hpp:52

◆ get_preProcess_to_do_Rhs()

BasicMethodsSequence& MoFEM::KspCtx::get_preProcess_to_do_Rhs ( )

The sequence of BasicMethod is executed before residual is calculated. It can be used to setup data structures, e.g. zero global variable which is integrated in domain, e.g. for calculation of strain energy.

Returns
reference to BasicMethod for preprocessing

Definition at line 86 of file KspCtx.hpp.

86 { return preProcess_Rhs; }
BasicMethodsSequence preProcess_Rhs
Sequence of methods run before residual is assembled.
Definition: KspCtx.hpp:57

Friends And Related Function Documentation

◆ KspMat

PetscErrorCode KspMat ( KSP  ksp,
Mat  A,
Mat  B,
void *  ctx 
)
friend

Run over elenents in the list.

Parameters
kspKSP solver
Amatrix
BPreconditioner matrix
ctxdata context, i.e. KspCtx
Returns
error code

Definition at line 71 of file KspCtx.cpp.

71  {
72  // PetscValidHeaderSpecific(ksp,KSP_CLASSID,1);
74  KspCtx *ksp_ctx = static_cast<KspCtx *>(ctx);
75  PetscLogEventBegin(ksp_ctx->MOFEM_EVENT_KspMat, 0, 0, 0, 0);
76 
77  ksp_ctx->matAssembleSwitch = boost::movelib::make_unique<bool>(true);
78 
79  for (auto &bit : ksp_ctx->preProcess_Mat) {
80  bit->matAssembleSwitch = boost::move(ksp_ctx->matAssembleSwitch);
81  CHKERR bit->setKsp(ksp);
82  bit->ksp_A = A;
83  bit->ksp_B = B;
84  CHKERR bit->setKspCtx(KspMethod::CTX_OPERATORS);
85  CHKERR ksp_ctx->mField.problem_basic_method_preProcess(ksp_ctx->problemName,
86  *bit);
87  CHKERR bit->setKspCtx(KspMethod::CTX_KSPNONE);
88  ksp_ctx->matAssembleSwitch = boost::move(bit->matAssembleSwitch);
89  }
90  for (auto &lit : ksp_ctx->loops_to_do_Mat) {
91  lit.second->matAssembleSwitch = boost::move(ksp_ctx->matAssembleSwitch);
92  lit.second->ksp_A = A;
93  lit.second->ksp_B = B;
94  CHKERR lit.second->setKsp(ksp);
95  CHKERR lit.second->setKspCtx(KspMethod::CTX_OPERATORS);
96  CHKERR ksp_ctx->mField.loop_finite_elements(
97  ksp_ctx->problemName, lit.first, *(lit.second), nullptr, ksp_ctx->bH);
98  CHKERR lit.second->setKspCtx(KspMethod::CTX_KSPNONE);
99  ksp_ctx->matAssembleSwitch = boost::move(lit.second->matAssembleSwitch);
100  }
101  for (auto &bit : ksp_ctx->postProcess_Mat) {
102  bit->matAssembleSwitch = boost::move(ksp_ctx->matAssembleSwitch);
103  CHKERR bit->setKsp(ksp);
104  bit->ksp_A = A;
105  bit->ksp_B = B;
106  CHKERR bit->setKspCtx(KspMethod::CTX_OPERATORS);
107  CHKERR ksp_ctx->mField.problem_basic_method_postProcess(
108  ksp_ctx->problemName, *bit);
109  CHKERR bit->setKspCtx(KspMethod::CTX_KSPNONE);
110  ksp_ctx->matAssembleSwitch = boost::move(bit->matAssembleSwitch);
111  }
112 
113  if (ksp_ctx->matAssembleSwitch) {
114  CHKERR MatAssemblyBegin(B, MAT_FINAL_ASSEMBLY);
115  CHKERR MatAssemblyEnd(B, MAT_FINAL_ASSEMBLY);
116  }
117  PetscLogEventEnd(ksp_ctx->MOFEM_EVENT_KspMat, 0, 0, 0, 0);
119 }
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:476
KspCtx(MoFEM::Interface &m_field, const std::string &_problem_name)
Definition: KspCtx.hpp:61
#define CHKERR
Inline error check.
Definition: definitions.h:595
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:406

◆ KspRhs

PetscErrorCode KspRhs ( KSP  ksp,
Vec  f,
void *  ctx 
)
friend

Run over elements in the lists.

Parameters
kspKSP solver
fthe right hand side vector
ctxdata context, i.e. KspCtx
Returns
error code

Definition at line 23 of file KspCtx.cpp.

23  {
24  // PetscValidHeaderSpecific(ksp,KSP_CLASSID,1);
26  KspCtx *ksp_ctx = static_cast<KspCtx *>(ctx);
27  PetscLogEventBegin(ksp_ctx->MOFEM_EVENT_KspRhs, 0, 0, 0, 0);
28 
29  ksp_ctx->vecAssembleSwitch = boost::movelib::make_unique<bool>(true);
30 
31  for (auto &bit : ksp_ctx->preProcess_Rhs) {
32  bit->vecAssembleSwitch = boost::move(ksp_ctx->vecAssembleSwitch);
33  CHKERR bit->setKsp(ksp);
34  bit->ksp_f = f;
35  CHKERR bit->setKspCtx(KspMethod::CTX_SETFUNCTION);
36  CHKERR ksp_ctx->mField.problem_basic_method_preProcess(ksp_ctx->problemName,
37  *bit);
38  CHKERR bit->setKspCtx(KspMethod::CTX_KSPNONE);
39  ksp_ctx->vecAssembleSwitch = boost::move(bit->vecAssembleSwitch);
40  }
41  for (auto &lit : ksp_ctx->loops_to_do_Rhs) {
42  lit.second->vecAssembleSwitch = boost::move(ksp_ctx->vecAssembleSwitch);
43  CHKERR lit.second->setKspCtx(KspMethod::CTX_SETFUNCTION);
44  CHKERR lit.second->setKsp(ksp);
45  lit.second->ksp_f = f;
46  CHKERR ksp_ctx->mField.loop_finite_elements(
47  ksp_ctx->problemName, lit.first, *(lit.second), nullptr, ksp_ctx->bH);
48  CHKERR lit.second->setKspCtx(KspMethod::CTX_KSPNONE);
49  ksp_ctx->vecAssembleSwitch = boost::move(lit.second->vecAssembleSwitch);
50  }
51  for (auto &bit : ksp_ctx->postProcess_Rhs) {
52  bit->vecAssembleSwitch = boost::move(ksp_ctx->vecAssembleSwitch);
53  CHKERR bit->setKsp(ksp);
54  bit->ksp_f = f;
55  CHKERR bit->setKspCtx(KspMethod::CTX_SETFUNCTION);
56  CHKERR ksp_ctx->mField.problem_basic_method_postProcess(
57  ksp_ctx->problemName, *bit);
58  CHKERR bit->setKspCtx(KspMethod::CTX_KSPNONE);
59  ksp_ctx->vecAssembleSwitch = boost::move(bit->vecAssembleSwitch);
60  }
61 
62  if (*ksp_ctx->vecAssembleSwitch) {
63  CHKERR VecGhostUpdateBegin(f, ADD_VALUES, SCATTER_REVERSE);
64  CHKERR VecGhostUpdateEnd(f, ADD_VALUES, SCATTER_REVERSE);
65  CHKERR VecAssemblyBegin(f);
66  CHKERR VecAssemblyEnd(f);
67  }
68  PetscLogEventEnd(ksp_ctx->MOFEM_EVENT_KspRhs, 0, 0, 0, 0);
70 }
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:476
KspCtx(MoFEM::Interface &m_field, const std::string &_problem_name)
Definition: KspCtx.hpp:61
#define CHKERR
Inline error check.
Definition: definitions.h:595
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:406

Member Data Documentation

◆ basic_method_to_do

DEPRECATED typedef MoFEM::BasicMethodsSequence MoFEM::KspCtx::basic_method_to_do
Deprecated:
use BasicMethodsSequence

Definition at line 42 of file KspCtx.hpp.

◆ bH

MoFEMTypes MoFEM::KspCtx::bH

If set to MF_EXIST check if element exist.

Definition at line 33 of file KspCtx.hpp.

◆ loop_pair_type

DEPRECATED typedef MoFEM::PairNameFEMethodPtr MoFEM::KspCtx::loop_pair_type
Deprecated:
use PairNameFEMethodPtr

Definition at line 36 of file KspCtx.hpp.

◆ loops_to_do_Mat

FEMethodsSequence MoFEM::KspCtx::loops_to_do_Mat

Sequence of finite elements instances assembling tangent matrix

Definition at line 48 of file KspCtx.hpp.

◆ loops_to_do_Rhs

FEMethodsSequence MoFEM::KspCtx::loops_to_do_Rhs

Sequence of finite elements instances assembling residual vector

Definition at line 50 of file KspCtx.hpp.

◆ loops_to_do_type

DEPRECATED typedef MoFEM::FEMethodsSequence MoFEM::KspCtx::loops_to_do_type
Deprecated:
use FEMethodsSequence

Definition at line 39 of file KspCtx.hpp.

◆ matAssembleSwitch

boost::movelib::unique_ptr<bool> MoFEM::KspCtx::matAssembleSwitch
private

Definition at line 120 of file KspCtx.hpp.

◆ mField

MoFEM::Interface& MoFEM::KspCtx::mField

Definition at line 29 of file KspCtx.hpp.

◆ moab

moab::Interface& MoFEM::KspCtx::moab

Definition at line 30 of file KspCtx.hpp.

◆ MOFEM_EVENT_KspMat

PetscLogEvent MoFEM::KspCtx::MOFEM_EVENT_KspMat
private

Definition at line 117 of file KspCtx.hpp.

◆ MOFEM_EVENT_KspRhs

PetscLogEvent MoFEM::KspCtx::MOFEM_EVENT_KspRhs
private

Definition at line 116 of file KspCtx.hpp.

◆ postProcess_Mat

BasicMethodsSequence MoFEM::KspCtx::postProcess_Mat

Sequence of methods run after tangent matrix is assembled

Definition at line 54 of file KspCtx.hpp.

◆ postProcess_Rhs

BasicMethodsSequence MoFEM::KspCtx::postProcess_Rhs

Sequence of methods run after residual is assembled.

Definition at line 59 of file KspCtx.hpp.

◆ preProcess_Mat

BasicMethodsSequence MoFEM::KspCtx::preProcess_Mat

Sequence of methods run before tangent matrix is assembled

Definition at line 52 of file KspCtx.hpp.

◆ preProcess_Rhs

BasicMethodsSequence MoFEM::KspCtx::preProcess_Rhs

Sequence of methods run before residual is assembled.

Definition at line 57 of file KspCtx.hpp.

◆ problemName

std::string MoFEM::KspCtx::problemName

Problem name.

Definition at line 32 of file KspCtx.hpp.

◆ vecAssembleSwitch

boost::movelib::unique_ptr<bool> MoFEM::KspCtx::vecAssembleSwitch
private

Definition at line 119 of file KspCtx.hpp.


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