v0.8.23
KspCtx.cpp
Go to the documentation of this file.
1 /* This file is part of MoFEM.
2  * MoFEM is free software: you can redistribute it and/or modify it under
3  * the terms of the GNU Lesser General Public License as published by the
4  * Free Software Foundation, either version 3 of the License, or (at your
5  * option) any later version.
6  *
7  * MoFEM is distributed in the hope that it will be useful, but WITHOUT
8  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  * License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>. */
14 
15 // #if PETSC_VERSION_GE(3,6,0)
16 // #include <petsc/private/kspimpl.h>
17 // #else
18 // #include <petsc-private/kspimpl.h>
19 // #endif
20 
21 namespace MoFEM {
22 
23 PetscErrorCode KspRhs(KSP ksp, Vec f, void *ctx) {
24  // PetscValidHeaderSpecific(ksp,KSP_CLASSID,1);
26  KspCtx *ksp_ctx = (KspCtx *)ctx;
27  PetscLogEventBegin(ksp_ctx->MOFEM_EVENT_KspRhs, 0, 0, 0, 0);
28  KspCtx::BasicMethodsSequence::iterator bit = ksp_ctx->preProcess_Rhs.begin();
29  for (; bit != ksp_ctx->preProcess_Rhs.end(); bit++) {
30  CHKERR(*bit)->setKsp(ksp);
31  (*bit)->ksp_f = f;
32  CHKERR(*bit)->setKspCtx(KspMethod::CTX_SETFUNCTION);
34  *(*(bit)));
35  CHKERR(*bit)->setKspCtx(KspMethod::CTX_KSPNONE);
36  }
37  KspCtx::FEMethodsSequence::iterator lit = ksp_ctx->loops_to_do_Rhs.begin();
38  for (; lit != ksp_ctx->loops_to_do_Rhs.end(); lit++) {
39  CHKERR lit->second->setKspCtx(KspMethod::CTX_SETFUNCTION);
40  CHKERR lit->second->setKsp(ksp);
41  lit->second->ksp_f = f;
43  ksp_ctx->problemName, lit->first, *(lit->second), nullptr, ksp_ctx->bH);
44  CHKERR lit->second->setKspCtx(KspMethod::CTX_KSPNONE);
45  }
46  bit = ksp_ctx->postProcess_Rhs.begin();
47  for (; bit != ksp_ctx->postProcess_Rhs.end(); bit++) {
48  CHKERR(*bit)->setKsp(ksp);
49  (*bit)->ksp_f = f;
50  CHKERR(*bit)->setKspCtx(KspMethod::CTX_SETFUNCTION);
52  ksp_ctx->problemName, *(*(bit)));
53  CHKERR(*bit)->setKspCtx(KspMethod::CTX_KSPNONE);
54  }
55  CHKERR VecGhostUpdateBegin(f, ADD_VALUES, SCATTER_REVERSE);
56  CHKERR VecGhostUpdateEnd(f, ADD_VALUES, SCATTER_REVERSE);
57  CHKERR VecAssemblyBegin(f);
58  CHKERR VecAssemblyEnd(f);
59  PetscLogEventEnd(ksp_ctx->MOFEM_EVENT_KspRhs, 0, 0, 0, 0);
61 }
62 PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx) {
63  // PetscValidHeaderSpecific(ksp,KSP_CLASSID,1);
65  KspCtx *ksp_ctx = (KspCtx *)ctx;
66  PetscLogEventBegin(ksp_ctx->MOFEM_EVENT_KspMat, 0, 0, 0, 0);
67  KspCtx::BasicMethodsSequence::iterator bit = ksp_ctx->preProcess_Mat.begin();
68  for (; bit != ksp_ctx->preProcess_Mat.end(); bit++) {
69  CHKERR(*bit)->setKsp(ksp);
70  (*bit)->ksp_A = A;
71  (*bit)->ksp_B = B;
72  CHKERR(*bit)->setKspCtx(KspMethod::CTX_OPERATORS);
74  *(*(bit)));
75  CHKERR(*bit)->setKspCtx(KspMethod::CTX_KSPNONE);
76  }
77  KspCtx::FEMethodsSequence::iterator lit = ksp_ctx->loops_to_do_Mat.begin();
78  for (; lit != ksp_ctx->loops_to_do_Mat.end(); lit++) {
79  lit->second->ksp_A = A;
80  lit->second->ksp_B = B;
81  CHKERR lit->second->setKsp(ksp);
82  CHKERR lit->second->setKspCtx(KspMethod::CTX_OPERATORS);
84  ksp_ctx->problemName, lit->first, *(lit->second), nullptr, ksp_ctx->bH);
85  CHKERR lit->second->setKspCtx(KspMethod::CTX_KSPNONE);
86  }
87  bit = ksp_ctx->postProcess_Mat.begin();
88  for (; bit != ksp_ctx->postProcess_Mat.end(); bit++) {
89  CHKERR(*bit)->setKsp(ksp);
90  (*bit)->ksp_A = A;
91  (*bit)->ksp_B = B;
92  CHKERR(*bit)->setKspCtx(KspMethod::CTX_OPERATORS);
94  ksp_ctx->problemName, *(*(bit)));
95  CHKERR(*bit)->setKspCtx(KspMethod::CTX_KSPNONE);
96  }
97  CHKERR MatAssemblyBegin(B, MAT_FINAL_ASSEMBLY);
98  CHKERR MatAssemblyEnd(B, MAT_FINAL_ASSEMBLY);
99  // MatView(A,PETSC_VIEWER_DRAW_WORLD);
100  // std::string wait;
101  // std::cin >> wait;
102  PetscLogEventEnd(ksp_ctx->MOFEM_EVENT_KspMat, 0, 0, 0, 0);
104 }
105 
106 } // namespace MoFEM
BasicMethodsSequence postProcess_Rhs
Sequence of methods run after residual is assembled.
Definition: KspCtx.hpp:59
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:476
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
std::string problemName
Problem name.
Definition: KspCtx.hpp:32
BasicMethodsSequence postProcess_Mat
Definition: KspCtx.hpp:54
PetscErrorCode KspRhs(KSP ksp, Vec f, void *ctx)
Run over elements in the lists.
Definition: KspCtx.cpp:23
MoFEMTypes bH
If set to MF_EXIST check if element exist.
Definition: KspCtx.hpp:33
MoFEM::Interface & mField
Definition: KspCtx.hpp:29
BasicMethodsSequence preProcess_Mat
Definition: KspCtx.hpp:52
PetscLogEvent MOFEM_EVENT_KspRhs
Definition: KspCtx.hpp:61
BasicMethodsSequence preProcess_Rhs
Sequence of methods run before residual is assembled.
Definition: KspCtx.hpp:57
PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx)
Run over elenents in the list.
Definition: KspCtx.cpp:62
virtual MoFEMErrorCode problem_basic_method_preProcess(const Problem *problem_ptr, BasicMethod &method, int verb=DEFAULT_VERBOSITY)=0
Set data for BasicMethod.
#define CHKERR
Inline error check.
Definition: definitions.h:595
FEMethodsSequence loops_to_do_Rhs
Definition: KspCtx.hpp:50
Interface for linear (KSP) solver.
Definition: KspCtx.hpp:27
PetscLogEvent MOFEM_EVENT_KspMat
Definition: KspCtx.hpp:62
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:406
virtual MoFEMErrorCode problem_basic_method_postProcess(const Problem *problem_ptr, BasicMethod &method, int verb=DEFAULT_VERBOSITY)=0
Set data for BasicMethodThis function set data about problem, adjacencies and other multi-indices in ...
FEMethodsSequence loops_to_do_Mat
Definition: KspCtx.hpp:48
DEPRECATED MoFEMErrorCode loop_finite_elements(const Problem *problem_ptr, const std::string &fe_name, FEMethod &method, int lower_rank, int upper_rank, MoFEMTypes bh, int verb=DEFAULT_VERBOSITY)