v0.14.0
Loading...
Searching...
No Matches
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 ()=default
 
FEMethodsSequencegetSetOperators ()
 
FEMethodsSequencegetComputeRhs ()
 
BasicMethodsSequencegetPreProcComputeRhs ()
 
BasicMethodsSequencegetPostProcComputeRhs ()
 
BasicMethodsSequencegetPreProcSetOperators ()
 
BasicMethodsSequencegetPostProcSetOperators ()
 
MoFEMErrorCode clearLoops ()
 Clear loops. More...
 
DEPRECATED FEMethodsSequenceget_loops_to_do_Mat ()
 
DEPRECATED FEMethodsSequenceget_loops_to_do_Rhs ()
 
DEPRECATED BasicMethodsSequenceget_preProcess_to_do_Rhs ()
 
BasicMethodsSequenceget_postProcess_to_do_Rhs ()
 
DEPRECATED BasicMethodsSequenceget_preProcess_to_do_Mat ()
 
DEPRECATED BasicMethodsSequenceget_postProcess_to_do_Mat ()
 

Public Attributes

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
 
BasicMethodsSequence postProcess_Rhs
 

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 elements in the list. More...
 

Detailed Description

Interface for linear (KSP) solver.

Definition at line 13 of file KspCtx.hpp.

Member Typedef Documentation

◆ BasicMethodsSequence

Definition at line 23 of file KspCtx.hpp.

◆ FEMethodsSequence

Definition at line 22 of file KspCtx.hpp.

◆ PairNameFEMethodPtr

Definition at line 21 of file KspCtx.hpp.

Constructor & Destructor Documentation

◆ KspCtx()

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

Definition at line 38 of file KspCtx.hpp.

39 : mField(m_field), moab(m_field.get_moab()), problemName(_problem_name),
40 bH(MF_EXIST) {
41 PetscLogEventRegister("LoopKSPRhs", 0, &MOFEM_EVENT_KspRhs);
42 PetscLogEventRegister("LoopKSPMat", 0, &MOFEM_EVENT_KspMat);
43 }
@ MF_EXIST
Definition: definitions.h:100
virtual moab::Interface & get_moab()=0
moab::Interface & moab
Definition: KspCtx.hpp:16
PetscLogEvent MOFEM_EVENT_KspRhs
Definition: KspCtx.hpp:129
PetscLogEvent MOFEM_EVENT_KspMat
Definition: KspCtx.hpp:130
MoFEM::Interface & mField
Definition: KspCtx.hpp:15
MoFEMTypes bH
If set to MF_EXIST check if element exist.
Definition: KspCtx.hpp:19
std::string problemName
Problem name.
Definition: KspCtx.hpp:18

◆ ~KspCtx()

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

Member Function Documentation

◆ clearLoops()

MoFEMErrorCode MoFEM::KspCtx::clearLoops ( )

Clear loops.

Returns
MoFEMErrorCode

Definition at line 11 of file KspCtx.cpp.

11 {
13 loops_to_do_Mat.clear();
14 loops_to_do_Rhs.clear();
15 preProcess_Mat.clear();
16 postProcess_Mat.clear();
17 preProcess_Rhs.clear();
19}
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
FEMethodsSequence loops_to_do_Rhs
Definition: KspCtx.hpp:27
BasicMethodsSequence preProcess_Rhs
Definition: KspCtx.hpp:33
BasicMethodsSequence postProcess_Mat
Definition: KspCtx.hpp:31
BasicMethodsSequence preProcess_Mat
Definition: KspCtx.hpp:29
FEMethodsSequence loops_to_do_Mat
Definition: KspCtx.hpp:25

◆ get_loops_to_do_Mat()

DEPRECATED FEMethodsSequence & MoFEM::KspCtx::get_loops_to_do_Mat ( )
inline
Deprecated:
use getSetOperator

Definition at line 99 of file KspCtx.hpp.

99 {
100 return getSetOperators();
101 }
FEMethodsSequence & getSetOperators()
Definition: KspCtx.hpp:49

◆ get_loops_to_do_Rhs()

DEPRECATED FEMethodsSequence & MoFEM::KspCtx::get_loops_to_do_Rhs ( )
inline
Deprecated:
use getComputeRhs

Definition at line 104 of file KspCtx.hpp.

104 {
105 return getComputeRhs();
106 }
FEMethodsSequence & getComputeRhs()
Definition: KspCtx.hpp:54

◆ get_postProcess_to_do_Mat()

DEPRECATED BasicMethodsSequence & MoFEM::KspCtx::get_postProcess_to_do_Mat ( )
inline
Deprecated:
use getPostProcSetOperators

Definition at line 124 of file KspCtx.hpp.

124 {
126 }
BasicMethodsSequence & getPostProcSetOperators()
Definition: KspCtx.hpp:86

◆ get_postProcess_to_do_Rhs()

BasicMethodsSequence & MoFEM::KspCtx::get_postProcess_to_do_Rhs ( )
inline
Deprecated:
use getPostProcComputeRhs

Definition at line 114 of file KspCtx.hpp.

114 {
115 return getPostProcComputeRhs();
116 }
BasicMethodsSequence & getPostProcComputeRhs()
Definition: KspCtx.hpp:72

◆ get_preProcess_to_do_Mat()

DEPRECATED BasicMethodsSequence & MoFEM::KspCtx::get_preProcess_to_do_Mat ( )
inline
Deprecated:
use getPreProcSetOperators

Definition at line 119 of file KspCtx.hpp.

119 {
120 return getPreProcSetOperators();
121 }
BasicMethodsSequence & getPreProcSetOperators()
Definition: KspCtx.hpp:77

◆ get_preProcess_to_do_Rhs()

DEPRECATED BasicMethodsSequence & MoFEM::KspCtx::get_preProcess_to_do_Rhs ( )
inline
Deprecated:
use getPreProcComputeRhs

Definition at line 109 of file KspCtx.hpp.

109 {
110 return getPreProcComputeRhs();
111 }
BasicMethodsSequence & getPreProcComputeRhs()
Definition: KspCtx.hpp:63

◆ getComputeRhs()

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

Definition at line 54 of file KspCtx.hpp.

54{ return loops_to_do_Rhs; }

◆ getPostProcComputeRhs()

BasicMethodsSequence & MoFEM::KspCtx::getPostProcComputeRhs ( )
inline

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 72 of file KspCtx.hpp.

72{ return postProcess_Rhs; }
BasicMethodsSequence postProcess_Rhs
Definition: KspCtx.hpp:35

◆ getPostProcSetOperators()

BasicMethodsSequence & MoFEM::KspCtx::getPostProcSetOperators ( )
inline

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 86 of file KspCtx.hpp.

86{ return postProcess_Mat; }

◆ getPreProcComputeRhs()

BasicMethodsSequence & MoFEM::KspCtx::getPreProcComputeRhs ( )
inline

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 63 of file KspCtx.hpp.

63{ return preProcess_Rhs; }

◆ getPreProcSetOperators()

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

Definition at line 77 of file KspCtx.hpp.

77{ return preProcess_Mat; }

◆ getSetOperators()

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

Definition at line 49 of file KspCtx.hpp.

49{ return loops_to_do_Mat; }

Friends And Related Function Documentation

◆ KspMat

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

Run over elements in the list.

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

Definition at line 86 of file KspCtx.cpp.

86 {
87 // PetscValidHeaderSpecific(ksp,KSP_CLASSID,1);
89 KspCtx *ksp_ctx = static_cast<KspCtx *>(ctx);
90 PetscLogEventBegin(ksp_ctx->MOFEM_EVENT_KspMat, 0, 0, 0, 0);
91
92 ksp_ctx->matAssembleSwitch = boost::movelib::make_unique<bool>(true);
93 auto cache_ptr = boost::make_shared<CacheTuple>();
94 CHKERR ksp_ctx->mField.cache_problem_entities(ksp_ctx->problemName,
95 cache_ptr);
96
97 auto set = [&](auto &fe) {
98 fe.ksp = ksp;
99 fe.ksp_A = A;
100 fe.ksp_B = B;
101 fe.ksp_ctx = KspMethod::CTX_OPERATORS;
103 fe.cacheWeakPtr = cache_ptr;
104 };
105
106 auto unset = [&](auto &fe) {
107 fe.ksp_ctx = KspMethod::CTX_KSPNONE;
108 fe.data_ctx = PetscData::CtxSetNone;
109 };
110
111 auto ent_data_cache = boost::make_shared<std::vector<EntityCacheDofs>>();
112 auto ent_row_cache =
113 boost::make_shared<std::vector<EntityCacheNumeredDofs>>();
114 auto ent_col_cache =
115 boost::make_shared<std::vector<EntityCacheNumeredDofs>>();
116
117 // pre-procsess
118 for (auto &bit : ksp_ctx->preProcess_Mat) {
119 bit->matAssembleSwitch = boost::move(ksp_ctx->matAssembleSwitch);
120 set(*bit);
121 CHKERR ksp_ctx->mField.problem_basic_method_preProcess(ksp_ctx->problemName,
122 *bit);
123 unset(*bit);
124 ksp_ctx->matAssembleSwitch = boost::move(bit->matAssembleSwitch);
125 }
126
127 // operators
128 for (auto &lit : ksp_ctx->loops_to_do_Mat) {
129 lit.second->matAssembleSwitch = boost::move(ksp_ctx->matAssembleSwitch);
130 set(*lit.second);
131 CHKERR ksp_ctx->mField.loop_finite_elements(ksp_ctx->problemName, lit.first,
132 *(lit.second), nullptr,
133 ksp_ctx->bH, cache_ptr);
134 unset(*lit.second);
135 ksp_ctx->matAssembleSwitch = boost::move(lit.second->matAssembleSwitch);
136 }
137
138 // post-process
139 for (auto &bit : ksp_ctx->postProcess_Mat) {
140 bit->matAssembleSwitch = boost::move(ksp_ctx->matAssembleSwitch);
141 set(*bit);
142 CHKERR ksp_ctx->mField.problem_basic_method_postProcess(
143 ksp_ctx->problemName, *bit);
144 unset(*bit);
145 ksp_ctx->matAssembleSwitch = boost::move(bit->matAssembleSwitch);
146 }
147
148 if (ksp_ctx->matAssembleSwitch) {
149 CHKERR MatAssemblyBegin(B, MAT_FINAL_ASSEMBLY);
150 CHKERR MatAssemblyEnd(B, MAT_FINAL_ASSEMBLY);
151 }
152 PetscLogEventEnd(ksp_ctx->MOFEM_EVENT_KspMat, 0, 0, 0, 0);
154}
#define CHKERR
Inline error check.
Definition: definitions.h:535
auto bit
set bit
constexpr AssemblyType A
KspCtx(MoFEM::Interface &m_field, const std::string &_problem_name)
Definition: KspCtx.hpp:38
static constexpr Switches CtxSetA
Definition: LoopMethods.hpp:37
static constexpr Switches CtxSetNone
Definition: LoopMethods.hpp:35
static constexpr Switches CtxSetB
Definition: LoopMethods.hpp:38

◆ 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 21 of file KspCtx.cpp.

21 {
22 // PetscValidHeaderSpecific(ksp,KSP_CLASSID,1);
24 KspCtx *ksp_ctx = static_cast<KspCtx *>(ctx);
25 PetscLogEventBegin(ksp_ctx->MOFEM_EVENT_KspRhs, 0, 0, 0, 0);
26
27 ksp_ctx->vecAssembleSwitch = boost::movelib::make_unique<bool>(true);
28
29 auto cache_ptr = boost::make_shared<CacheTuple>();
30 CHKERR ksp_ctx->mField.cache_problem_entities(ksp_ctx->problemName,
31 cache_ptr);
32
33 auto set = [&](auto &fe) {
34 fe.ksp = ksp;
35 fe.ksp_ctx = KspMethod::CTX_SETFUNCTION;
36 fe.data_ctx = PetscData::CtxSetF;
37 fe.ksp_f = f;
38 fe.cacheWeakPtr = cache_ptr;
39 };
40
41 auto unset = [&](auto &fe) {
42 fe.ksp_ctx = KspMethod::CTX_KSPNONE;
43 fe.data_ctx = PetscData::CtxSetNone;
44 };
45
46 // pre-process
47 for (auto &bit : ksp_ctx->preProcess_Rhs) {
48 bit->vecAssembleSwitch = boost::move(ksp_ctx->vecAssembleSwitch);
49 set(*bit);
50 CHKERR ksp_ctx->mField.problem_basic_method_preProcess(ksp_ctx->problemName,
51 *bit);
52 unset(*bit);
53 ksp_ctx->vecAssembleSwitch = boost::move(bit->vecAssembleSwitch);
54 }
55
56 // operators
57 for (auto &lit : ksp_ctx->loops_to_do_Rhs) {
58 lit.second->vecAssembleSwitch = boost::move(ksp_ctx->vecAssembleSwitch);
59 set(*lit.second);
60 CHKERR ksp_ctx->mField.loop_finite_elements(ksp_ctx->problemName, lit.first,
61 *(lit.second), nullptr,
62 ksp_ctx->bH, cache_ptr);
63 unset(*lit.second);
64 ksp_ctx->vecAssembleSwitch = boost::move(lit.second->vecAssembleSwitch);
65 }
66
67 // post-process
68 for (auto &bit : ksp_ctx->postProcess_Rhs) {
69 bit->vecAssembleSwitch = boost::move(ksp_ctx->vecAssembleSwitch);
70 set(*bit);
71 CHKERR ksp_ctx->mField.problem_basic_method_postProcess(
72 ksp_ctx->problemName, *bit);
73 unset(*bit);
74 ksp_ctx->vecAssembleSwitch = boost::move(bit->vecAssembleSwitch);
75 }
76
77 if (*ksp_ctx->vecAssembleSwitch) {
78 CHKERR VecGhostUpdateBegin(f, ADD_VALUES, SCATTER_REVERSE);
79 CHKERR VecGhostUpdateEnd(f, ADD_VALUES, SCATTER_REVERSE);
80 CHKERR VecAssemblyBegin(f);
81 CHKERR VecAssemblyEnd(f);
82 }
83 PetscLogEventEnd(ksp_ctx->MOFEM_EVENT_KspRhs, 0, 0, 0, 0);
85}
static constexpr Switches CtxSetF
Definition: LoopMethods.hpp:36

Member Data Documentation

◆ bH

MoFEMTypes MoFEM::KspCtx::bH

If set to MF_EXIST check if element exist.

Definition at line 19 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 25 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 27 of file KspCtx.hpp.

◆ matAssembleSwitch

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

Definition at line 133 of file KspCtx.hpp.

◆ mField

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

Definition at line 15 of file KspCtx.hpp.

◆ moab

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

Definition at line 16 of file KspCtx.hpp.

◆ MOFEM_EVENT_KspMat

PetscLogEvent MoFEM::KspCtx::MOFEM_EVENT_KspMat
private

Definition at line 130 of file KspCtx.hpp.

◆ MOFEM_EVENT_KspRhs

PetscLogEvent MoFEM::KspCtx::MOFEM_EVENT_KspRhs
private

Definition at line 129 of file KspCtx.hpp.

◆ postProcess_Mat

BasicMethodsSequence MoFEM::KspCtx::postProcess_Mat

Sequence of methods run after tangent matrix is assembled

Definition at line 31 of file KspCtx.hpp.

◆ postProcess_Rhs

BasicMethodsSequence MoFEM::KspCtx::postProcess_Rhs

Sequence of methods run after residual is assembled

Definition at line 35 of file KspCtx.hpp.

◆ preProcess_Mat

BasicMethodsSequence MoFEM::KspCtx::preProcess_Mat

Sequence of methods run before tangent matrix is assembled

Definition at line 29 of file KspCtx.hpp.

◆ preProcess_Rhs

BasicMethodsSequence MoFEM::KspCtx::preProcess_Rhs

Sequence of methods run before residual is assembled

Definition at line 33 of file KspCtx.hpp.

◆ problemName

std::string MoFEM::KspCtx::problemName

Problem name.

Definition at line 18 of file KspCtx.hpp.

◆ vecAssembleSwitch

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

Definition at line 132 of file KspCtx.hpp.


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