v0.16.0
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Friends | List of all members
MoFEM::KspCtx::KspCtx::KspCtxImpl Struct Reference
Collaboration diagram for MoFEM::KspCtx::KspCtx::KspCtxImpl:
[legend]

Public Member Functions

 KspCtxImpl (MoFEM::Interface &m_field, std::string problem_name)
 
virtual ~KspCtxImpl ()=default
 
FEMethodsSequencegetSetOperators ()
 
FEMethodsSequencegetComputeRhs ()
 
BasicMethodsSequencegetPreProcComputeRhs ()
 
BasicMethodsSequencegetPostProcComputeRhs ()
 
BasicMethodsSequencegetPreProcSetOperators ()
 
BasicMethodsSequencegetPostProcSetOperators ()
 
MoFEMErrorCode clearLoops ()
 Clear loops.
 

Protected Attributes

PetscLogEvent MOFEM_EVENT_KspRhs
 
PetscLogEvent MOFEM_EVENT_KspMat
 
boost::movelib::unique_ptr< boolvecAssembleSwitch
 
boost::movelib::unique_ptr< boolmatAssembleSwitch
 
MoFEM::InterfacemField
 
moab::Interface & moab
 
std::string problemName
 Problem name.
 
MoFEMTypes bH
 If set to MF_EXIST check if element exist.
 
FEMethodsSequence loopsOperator
 
FEMethodsSequence loopsRhs
 
BasicMethodsSequence preProcessOperator
 
BasicMethodsSequence postProcessOperator
 
BasicMethodsSequence preProcessRhs
 
BasicMethodsSequence postProcessRhs
 

Friends

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

Detailed Description

Definition at line 9 of file KspCtx.cpp.

Constructor & Destructor Documentation

◆ KspCtxImpl()

MoFEM::KspCtx::KspCtxImpl::KspCtxImpl ( MoFEM::Interface m_field,
std::string  problem_name 
)

Definition at line 128 of file KspCtx.cpp.

130 : mField(m_field), moab(m_field.get_moab()), problemName(problem_name),
131 bH(MF_EXIST) {
132 PetscLogEventRegister("LoopKSPRhs", 0, &MOFEM_EVENT_KspRhs);
133 PetscLogEventRegister("LoopKSPMat", 0, &MOFEM_EVENT_KspMat);
134}
@ MF_EXIST
virtual moab::Interface & get_moab()=0
MoFEM::Interface & mField
Definition KspCtx.cpp:76
std::string problemName
Problem name.
Definition KspCtx.cpp:79
MoFEMTypes bH
If set to MF_EXIST check if element exist.
Definition KspCtx.cpp:80

◆ ~KspCtxImpl()

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

Member Function Documentation

◆ clearLoops()

MoFEMErrorCode MoFEM::KspCtx::KspCtxImpl::clearLoops ( )

Clear loops.

Returns
MoFEMErrorCode

Definition at line 136 of file KspCtx.cpp.

136 {
138 loopsOperator.clear();
139 loopsRhs.clear();
140 preProcessOperator.clear();
141 postProcessOperator.clear();
142 preProcessRhs.clear();
143 postProcessRhs.clear();
145}
#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()
BasicMethodsSequence preProcessOperator
Definition KspCtx.cpp:86
BasicMethodsSequence postProcessOperator
Definition KspCtx.cpp:88
FEMethodsSequence loopsOperator
Definition KspCtx.cpp:82
BasicMethodsSequence postProcessRhs
Definition KspCtx.cpp:92
BasicMethodsSequence preProcessRhs
Definition KspCtx.cpp:90

◆ getComputeRhs()

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

Definition at line 23 of file KspCtx.cpp.

23{ return loopsRhs; }

◆ getPostProcComputeRhs()

BasicMethodsSequence & MoFEM::KspCtx::KspCtx::KspCtxImpl::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 41 of file KspCtx.cpp.

41{ return postProcessRhs; }

◆ getPostProcSetOperators()

BasicMethodsSequence & MoFEM::KspCtx::KspCtx::KspCtxImpl::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 55 of file KspCtx.cpp.

55 {
57 }

◆ getPreProcComputeRhs()

BasicMethodsSequence & MoFEM::KspCtx::KspCtx::KspCtxImpl::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 32 of file KspCtx.cpp.

32{ return preProcessRhs; }

◆ getPreProcSetOperators()

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

Definition at line 46 of file KspCtx.cpp.

46{ return preProcessOperator; }

◆ getSetOperators()

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

Definition at line 18 of file KspCtx.cpp.

18{ return loopsOperator; }

Friends And Related Symbol 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 211 of file KspCtx.cpp.

211 {
212 // PetscValidHeaderSpecific(ksp,KSP_CLASSID,1);
214 KspCtx::KspCtxImpl *ksp_ctx = static_cast<KspCtx *>(ctx)->kspCtxImpl.get();
215 PetscLogEventBegin(ksp_ctx->MOFEM_EVENT_KspMat, 0, 0, 0, 0);
216
217 ksp_ctx->matAssembleSwitch = boost::movelib::make_unique<bool>(true);
218 auto cache_ptr = boost::make_shared<CacheTuple>();
219 CHKERR ksp_ctx->mField.cache_problem_entities(ksp_ctx->problemName,
220 cache_ptr);
221
222 auto set = [&](auto &fe) {
223 fe.ksp = ksp;
224 fe.ksp_A = A;
225 fe.ksp_B = B;
226 fe.ksp_ctx = KspMethod::CTX_OPERATORS;
227 fe.data_ctx = PetscData::CtxSetA | PetscData::CtxSetB;
228 fe.cacheWeakPtr = cache_ptr;
229 };
230
231 auto unset = [&](auto &fe) {
232 fe.ksp_ctx = KspMethod::CTX_KSPNONE;
233 fe.data_ctx = PetscData::CtxSetNone;
234 };
235
236 auto ent_data_cache = boost::make_shared<std::vector<EntityCacheDofs>>();
237 auto ent_row_cache =
238 boost::make_shared<std::vector<EntityCacheNumeredDofs>>();
239 auto ent_col_cache =
240 boost::make_shared<std::vector<EntityCacheNumeredDofs>>();
241
242 // pre-procsess
243 for (auto &bit : ksp_ctx->preProcessOperator) {
244 bit->matAssembleSwitch = boost::move(ksp_ctx->matAssembleSwitch);
245 set(*bit);
246 CHKERR ksp_ctx->mField.problem_basic_method_preProcess(ksp_ctx->problemName,
247 *bit);
248 unset(*bit);
249 ksp_ctx->matAssembleSwitch = boost::move(bit->matAssembleSwitch);
250 }
251
252 // operators
253 for (auto &lit : ksp_ctx->loopsOperator) {
254 lit.second->matAssembleSwitch = boost::move(ksp_ctx->matAssembleSwitch);
255 set(*lit.second);
256 CHKERR ksp_ctx->mField.loop_finite_elements(ksp_ctx->problemName, lit.first,
257 *(lit.second), nullptr,
258 ksp_ctx->bH, cache_ptr);
259 unset(*lit.second);
260 ksp_ctx->matAssembleSwitch = boost::move(lit.second->matAssembleSwitch);
261 }
262
263 // post-process
264 for (auto &bit : ksp_ctx->postProcessOperator) {
265 bit->matAssembleSwitch = boost::move(ksp_ctx->matAssembleSwitch);
266 set(*bit);
267 CHKERR ksp_ctx->mField.problem_basic_method_postProcess(
268 ksp_ctx->problemName, *bit);
269 unset(*bit);
270 ksp_ctx->matAssembleSwitch = boost::move(bit->matAssembleSwitch);
271 }
272
273 if (ksp_ctx->matAssembleSwitch) {
274 CHKERR MatAssemblyBegin(B, MAT_FINAL_ASSEMBLY);
275 CHKERR MatAssemblyEnd(B, MAT_FINAL_ASSEMBLY);
276 }
277 PetscLogEventEnd(ksp_ctx->MOFEM_EVENT_KspMat, 0, 0, 0, 0);
279}
#define CHKERR
Inline error check.
auto bit
set bit
constexpr AssemblyType A

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

147 {
149 KspCtx::KspCtxImpl *ksp_ctx = static_cast<KspCtx *>(ctx)->kspCtxImpl.get();
150 PetscLogEventBegin(ksp_ctx->MOFEM_EVENT_KspRhs, 0, 0, 0, 0);
151
152 ksp_ctx->vecAssembleSwitch = boost::movelib::make_unique<bool>(true);
153
154 auto cache_ptr = boost::make_shared<CacheTuple>();
155 CHKERR ksp_ctx->mField.cache_problem_entities(ksp_ctx->problemName,
156 cache_ptr);
157
158 auto set = [&](auto &fe) {
159 fe.ksp = ksp;
160 fe.ksp_ctx = KspMethod::CTX_SETFUNCTION;
161 fe.data_ctx = PetscData::CtxSetF;
162 fe.ksp_f = f;
163 fe.cacheWeakPtr = cache_ptr;
164 };
165
166 auto unset = [&](auto &fe) {
167 fe.ksp_ctx = KspMethod::CTX_KSPNONE;
168 fe.data_ctx = PetscData::CtxSetNone;
169 };
170
171 // pre-process
172 for (auto &bit : ksp_ctx->preProcessRhs) {
173 bit->vecAssembleSwitch = boost::move(ksp_ctx->vecAssembleSwitch);
174 set(*bit);
175 CHKERR ksp_ctx->mField.problem_basic_method_preProcess(ksp_ctx->problemName,
176 *bit);
177 unset(*bit);
178 ksp_ctx->vecAssembleSwitch = boost::move(bit->vecAssembleSwitch);
179 }
180
181 // operators
182 for (auto &lit : ksp_ctx->loopsRhs) {
183 lit.second->vecAssembleSwitch = boost::move(ksp_ctx->vecAssembleSwitch);
184 set(*lit.second);
185 CHKERR ksp_ctx->mField.loop_finite_elements(ksp_ctx->problemName, lit.first,
186 *(lit.second), nullptr,
187 ksp_ctx->bH, cache_ptr);
188 unset(*lit.second);
189 ksp_ctx->vecAssembleSwitch = boost::move(lit.second->vecAssembleSwitch);
190 }
191
192 // post-process
193 for (auto &bit : ksp_ctx->postProcessRhs) {
194 bit->vecAssembleSwitch = boost::move(ksp_ctx->vecAssembleSwitch);
195 set(*bit);
196 CHKERR ksp_ctx->mField.problem_basic_method_postProcess(
197 ksp_ctx->problemName, *bit);
198 unset(*bit);
199 ksp_ctx->vecAssembleSwitch = boost::move(bit->vecAssembleSwitch);
200 }
201
202 if (*ksp_ctx->vecAssembleSwitch) {
203 CHKERR VecGhostUpdateBegin(f, ADD_VALUES, SCATTER_REVERSE);
204 CHKERR VecGhostUpdateEnd(f, ADD_VALUES, SCATTER_REVERSE);
205 CHKERR VecAssemblyBegin(f);
206 CHKERR VecAssemblyEnd(f);
207 }
208 PetscLogEventEnd(ksp_ctx->MOFEM_EVENT_KspRhs, 0, 0, 0, 0);
210}

Member Data Documentation

◆ bH

MoFEMTypes MoFEM::KspCtx::KspCtx::KspCtxImpl::bH
protected

If set to MF_EXIST check if element exist.

Definition at line 80 of file KspCtx.cpp.

◆ loopsOperator

FEMethodsSequence MoFEM::KspCtx::KspCtx::KspCtxImpl::loopsOperator
protected

Sequence of finite elements instances assembling tangent matrix

Definition at line 82 of file KspCtx.cpp.

◆ loopsRhs

FEMethodsSequence MoFEM::KspCtx::KspCtx::KspCtxImpl::loopsRhs
protected

Sequence of finite elements instances assembling residual vector

Definition at line 84 of file KspCtx.cpp.

◆ matAssembleSwitch

boost::movelib::unique_ptr<bool> MoFEM::KspCtx::KspCtx::KspCtxImpl::matAssembleSwitch
protected

Definition at line 74 of file KspCtx.cpp.

◆ mField

MoFEM::Interface& MoFEM::KspCtx::KspCtx::KspCtxImpl::mField
protected

Definition at line 76 of file KspCtx.cpp.

◆ moab

moab::Interface& MoFEM::KspCtx::KspCtx::KspCtxImpl::moab
protected

Definition at line 77 of file KspCtx.cpp.

◆ MOFEM_EVENT_KspMat

PetscLogEvent MoFEM::KspCtx::KspCtx::KspCtxImpl::MOFEM_EVENT_KspMat
protected

Definition at line 71 of file KspCtx.cpp.

◆ MOFEM_EVENT_KspRhs

PetscLogEvent MoFEM::KspCtx::KspCtx::KspCtxImpl::MOFEM_EVENT_KspRhs
protected

Definition at line 70 of file KspCtx.cpp.

◆ postProcessOperator

BasicMethodsSequence MoFEM::KspCtx::KspCtx::KspCtxImpl::postProcessOperator
protected

Sequence of methods run after tangent matrix is assembled

Definition at line 88 of file KspCtx.cpp.

◆ postProcessRhs

BasicMethodsSequence MoFEM::KspCtx::KspCtx::KspCtxImpl::postProcessRhs
protected

Sequence of methods run after residual is assembled

Definition at line 92 of file KspCtx.cpp.

◆ preProcessOperator

BasicMethodsSequence MoFEM::KspCtx::KspCtx::KspCtxImpl::preProcessOperator
protected

Sequence of methods run before tangent matrix is assembled

Definition at line 86 of file KspCtx.cpp.

◆ preProcessRhs

BasicMethodsSequence MoFEM::KspCtx::KspCtx::KspCtxImpl::preProcessRhs
protected

Sequence of methods run before residual is assembled

Definition at line 90 of file KspCtx.cpp.

◆ problemName

std::string MoFEM::KspCtx::KspCtx::KspCtxImpl::problemName
protected

Problem name.

Definition at line 79 of file KspCtx.cpp.

◆ vecAssembleSwitch

boost::movelib::unique_ptr<bool> MoFEM::KspCtx::KspCtx::KspCtxImpl::vecAssembleSwitch
protected

Definition at line 73 of file KspCtx.cpp.


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