9struct KspCtx::KspCtx::KspCtxImpl {
59 friend PetscErrorCode KspRhs(KSP ksp, Vec f,
void *ctx);
60 friend PetscErrorCode KspMat(KSP ksp, Mat
A, Mat
B,
void *ctx);
97 : kspCtxImpl(boost::movelib::make_unique<
KspCtx::KspCtxImpl>(
98 m_field, problem_name)) {}
129 std::string problem_name)
130 : mField(m_field), moab(m_field.get_moab()), problemName(problem_name),
138 loopsOperator.clear();
140 preProcessOperator.clear();
141 postProcessOperator.clear();
142 preProcessRhs.clear();
143 postProcessRhs.clear();
147PetscErrorCode
KspRhs(KSP ksp, Vec f,
void *ctx) {
150 PetscLogEventBegin(ksp_ctx->MOFEM_EVENT_KspRhs, 0, 0, 0, 0);
152 ksp_ctx->vecAssembleSwitch = boost::movelib::make_unique<bool>(
true);
154 auto cache_ptr = boost::make_shared<CacheTuple>();
155 CHKERR ksp_ctx->mField.cache_problem_entities(ksp_ctx->problemName,
158 auto set = [&](
auto &fe) {
163 fe.cacheWeakPtr = cache_ptr;
166 auto unset = [&](
auto &fe) {
172 for (
auto &
bit : ksp_ctx->preProcessRhs) {
173 bit->vecAssembleSwitch = boost::move(ksp_ctx->vecAssembleSwitch);
175 CHKERR ksp_ctx->mField.problem_basic_method_preProcess(ksp_ctx->problemName,
178 ksp_ctx->vecAssembleSwitch = boost::move(
bit->vecAssembleSwitch);
182 for (
auto &lit : ksp_ctx->loopsRhs) {
183 lit.second->vecAssembleSwitch = boost::move(ksp_ctx->vecAssembleSwitch);
185 CHKERR ksp_ctx->mField.loop_finite_elements(ksp_ctx->problemName, lit.first,
186 *(lit.second),
nullptr,
187 ksp_ctx->bH, cache_ptr);
189 ksp_ctx->vecAssembleSwitch = boost::move(lit.second->vecAssembleSwitch);
193 for (
auto &
bit : ksp_ctx->postProcessRhs) {
194 bit->vecAssembleSwitch = boost::move(ksp_ctx->vecAssembleSwitch);
196 CHKERR ksp_ctx->mField.problem_basic_method_postProcess(
197 ksp_ctx->problemName, *
bit);
199 ksp_ctx->vecAssembleSwitch = boost::move(
bit->vecAssembleSwitch);
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);
208 PetscLogEventEnd(ksp_ctx->MOFEM_EVENT_KspRhs, 0, 0, 0, 0);
211PetscErrorCode
KspMat(KSP ksp, Mat
A, Mat
B,
void *ctx) {
215 PetscLogEventBegin(ksp_ctx->MOFEM_EVENT_KspMat, 0, 0, 0, 0);
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,
222 auto set = [&](
auto &fe) {
228 fe.cacheWeakPtr = cache_ptr;
231 auto unset = [&](
auto &fe) {
236 auto ent_data_cache = boost::make_shared<std::vector<EntityCacheDofs>>();
238 boost::make_shared<std::vector<EntityCacheNumeredDofs>>();
240 boost::make_shared<std::vector<EntityCacheNumeredDofs>>();
243 for (
auto &
bit : ksp_ctx->preProcessOperator) {
244 bit->matAssembleSwitch = boost::move(ksp_ctx->matAssembleSwitch);
246 CHKERR ksp_ctx->mField.problem_basic_method_preProcess(ksp_ctx->problemName,
249 ksp_ctx->matAssembleSwitch = boost::move(
bit->matAssembleSwitch);
253 for (
auto &lit : ksp_ctx->loopsOperator) {
254 lit.second->matAssembleSwitch = boost::move(ksp_ctx->matAssembleSwitch);
256 CHKERR ksp_ctx->mField.loop_finite_elements(ksp_ctx->problemName, lit.first,
257 *(lit.second),
nullptr,
258 ksp_ctx->bH, cache_ptr);
260 ksp_ctx->matAssembleSwitch = boost::move(lit.second->matAssembleSwitch);
264 for (
auto &
bit : ksp_ctx->postProcessOperator) {
265 bit->matAssembleSwitch = boost::move(ksp_ctx->matAssembleSwitch);
267 CHKERR ksp_ctx->mField.problem_basic_method_postProcess(
268 ksp_ctx->problemName, *
bit);
270 ksp_ctx->matAssembleSwitch = boost::move(
bit->matAssembleSwitch);
273 if (ksp_ctx->matAssembleSwitch) {
274 CHKERR MatAssemblyBegin(
B, MAT_FINAL_ASSEMBLY);
275 CHKERR MatAssemblyEnd(
B, MAT_FINAL_ASSEMBLY);
277 PetscLogEventEnd(ksp_ctx->MOFEM_EVENT_KspMat, 0, 0, 0, 0);
MoFEMTypes
Those types control how functions respond on arguments, f.e. error handling.
#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.
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
std::deque< BasicMethodPtr > BasicMethodsSequence
std::deque< PairNameFEMethodPtr > FEMethodsSequence
Deprecated interface functions.
MoFEM::Interface & mField
BasicMethodsSequence preProcessOperator
boost::movelib::unique_ptr< bool > matAssembleSwitch
BasicMethodsSequence & getPreProcSetOperators()
BasicMethodsSequence postProcessOperator
FEMethodsSequence loopsRhs
std::string problemName
Problem name.
FEMethodsSequence & getSetOperators()
PetscLogEvent MOFEM_EVENT_KspMat
MoFEMTypes bH
If set to MF_EXIST check if element exist.
FEMethodsSequence loopsOperator
BasicMethodsSequence & getPostProcComputeRhs()
FEMethodsSequence & getComputeRhs()
virtual ~KspCtxImpl()=default
BasicMethodsSequence postProcessRhs
boost::movelib::unique_ptr< bool > vecAssembleSwitch
PetscLogEvent MOFEM_EVENT_KspRhs
BasicMethodsSequence & getPostProcSetOperators()
BasicMethodsSequence preProcessRhs
BasicMethodsSequence & getPreProcComputeRhs()
Interface for linear (KSP) solver.
boost::movelib::unique_ptr< KspCtxImpl > kspCtxImpl
BasicMethodsSequence & getPostProcComputeRhs()
BasicMethodsSequence & getPreProcComputeRhs()
BasicMethodsSequence & getPreProcSetOperators()
FEMethodsSequence & getSetOperators()
friend PetscErrorCode KspRhs(KSP ksp, Vec f, void *ctx)
Run over elements in the lists.
FEMethodsSequence & getComputeRhs()
MoFEMErrorCode clearLoops()
Clear loops.
friend PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx)
Run over elements in the list.
BasicMethodsSequence & getPostProcSetOperators()
@ CTX_KSPNONE
No specific KSP context.
@ CTX_SETFUNCTION
Setting up the linear system function.
@ CTX_OPERATORS
Setting up linear operators.
static constexpr Switches CtxSetA
Jacobian matrix switch.
static constexpr Switches CtxSetNone
No data switch.
static constexpr Switches CtxSetF
Residual vector switch.
static constexpr Switches CtxSetB
Preconditioner matrix switch.