v0.15.0
Loading...
Searching...
No Matches
MoFEM::KspCtx Struct Reference

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

#include "src/petsc/KspCtx.hpp"

Collaboration diagram for MoFEM::KspCtx:
[legend]

Public Member Functions

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

Private Attributes

boost::movelib::unique_ptr< KspCtxImpl > kspCtxImpl
 

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

Interface for linear (KSP) solver.

Definition at line 14 of file KspCtx.hpp.

Constructor & Destructor Documentation

◆ KspCtx()

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

Definition at line 96 of file KspCtx.cpp.

97 : kspCtxImpl(boost::movelib::make_unique<KspCtx::KspCtxImpl>(
98 m_field, problem_name)) {}
boost::movelib::unique_ptr< KspCtxImpl > kspCtxImpl
Definition KspCtx.hpp:74

◆ ~KspCtx()

MoFEM::KspCtx::~KspCtx ( )
virtualdefault

Member Function Documentation

◆ clearLoops()

MoFEMErrorCode MoFEM::KspCtx::clearLoops ( )

Clear loops.

Returns
MoFEMErrorCode

Definition at line 126 of file KspCtx.cpp.

126{ return kspCtxImpl->clearLoops(); }

◆ getComputeRhs()

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

Definition at line 106 of file KspCtx.cpp.

106 {
107 return kspCtxImpl->getComputeRhs();
108}

◆ getPostProcComputeRhs()

BasicMethodsSequence & MoFEM::KspCtx::getPostProcComputeRhs ( )

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

114 {
115 return kspCtxImpl->getPostProcComputeRhs();
116}

◆ getPostProcSetOperators()

BasicMethodsSequence & MoFEM::KspCtx::getPostProcSetOperators ( )

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

122 {
123 return kspCtxImpl->getPostProcSetOperators();
124}

◆ getPreProcComputeRhs()

BasicMethodsSequence & MoFEM::KspCtx::getPreProcComputeRhs ( )

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

110 {
111 return kspCtxImpl->getPreProcComputeRhs();
112}

◆ getPreProcSetOperators()

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

Definition at line 118 of file KspCtx.cpp.

118 {
119 return kspCtxImpl->getPreProcSetOperators();
120}

◆ getSetOperators()

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

Definition at line 102 of file KspCtx.cpp.

102 {
103 return kspCtxImpl->getSetOperators();
104}

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

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

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

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

Member Data Documentation

◆ kspCtxImpl

boost::movelib::unique_ptr<KspCtxImpl> MoFEM::KspCtx::kspCtxImpl
private

Definition at line 74 of file KspCtx.hpp.


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