v0.13.0
KspCtx.hpp
Go to the documentation of this file.
1 /** \file KspCtx.hpp
2  * \brief Context for PETSc KSP, i.e. nonlinear solver
3  */
4 
5 /* This file is part of MoFEM.
6  * MoFEM is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * MoFEM is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>. */
18 
19 #ifndef __KSPCTX_HPP__
20 #define __KSPCTX_HPP__
21 
22 namespace MoFEM {
23 
24 /** \brief Interface for linear (KSP) solver
25  * \ingroup mofem_petsc_solvers
26  */
27 struct KspCtx {
28 
31 
32  std::string problemName; ///< Problem name
33  MoFEMTypes bH; ///< If set to MF_EXIST check if element exist
34 
38 
39  FEMethodsSequence loops_to_do_Mat; ///< Sequence of finite elements instances
40  ///< assembling tangent matrix
41  FEMethodsSequence loops_to_do_Rhs; ///< Sequence of finite elements
42  ///< instances assembling residual vector
43  BasicMethodsSequence preProcess_Mat; ///< Sequence of methods run before
44  ///< tangent matrix is assembled
45  BasicMethodsSequence postProcess_Mat; ///< Sequence of methods run after
46  ///< tangent matrix is assembled
47  BasicMethodsSequence preProcess_Rhs; ///< Sequence of methods run before
48  ///< residual is assembled
49  BasicMethodsSequence postProcess_Rhs; ///< Sequence of methods run after
50  ///< residual is assembled
51 
52  KspCtx(MoFEM::Interface &m_field, const std::string &_problem_name)
53  : mField(m_field), moab(m_field.get_moab()), problemName(_problem_name),
54  bH(MF_EXIST) {
55  PetscLogEventRegister("LoopKSPRhs", 0, &MOFEM_EVENT_KspRhs);
56  PetscLogEventRegister("LoopKSPMat", 0, &MOFEM_EVENT_KspMat);
57  }
58  virtual ~KspCtx() = default;
59 
60  /**
61  * @return return reference to vector with FEMethod to calculate matrix
62  */
64 
65  /**
66  * @return return vector to vector with FEMethod to vector
67  */
69 
70  /**
71  * The sequence of BasicMethod is executed before residual is calculated. It
72  * can be used to setup data structures, e.g. zero global variable which is
73  * integrated in domain, e.g. for calculation of strain energy.
74  *
75  * @return reference to BasicMethod for preprocessing
76  */
78 
79  /**
80  * The sequence of BasicMethod is executed after residual is calculated. It
81  * can be used to setup data structures, e.g. aggregate data from processors
82  * or to apply essential boundary conditions.
83  *
84  * @return reference to BasicMethod for postprocessing
85  */
87 
88  /**
89  * @return reference to BasicMethod for preprocessing
90  */
92 
93  /**
94  * The sequence of BasicMethod is executed after tangent matrix is calculated.
95  * It can be used to setup data structures, e.g. aggregate data from
96  * processors or to apply essential boundary conditions.
97  *
98  * @return reference to BasicMethod for postprocessing
99  */
101 
102  friend PetscErrorCode KspRhs(KSP ksp, Vec f, void *ctx);
103  friend PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx);
104 
105  /**
106  * @brief Clear loops
107  *
108  * @return MoFEMErrorCode
109  */
111 
112 private:
113  PetscLogEvent MOFEM_EVENT_KspRhs;
114  PetscLogEvent MOFEM_EVENT_KspMat;
115 
116  boost::movelib::unique_ptr<bool> vecAssembleSwitch;
117  boost::movelib::unique_ptr<bool> matAssembleSwitch;
118 };
119 
120 /**
121  * \brief Run over elements in the lists
122  * @param ksp KSP solver
123  * @param f the right hand side vector
124  * @param ctx data context, i.e. KspCtx
125  * @return error code
126  */
127 PetscErrorCode KspRhs(KSP ksp, Vec f, void *ctx);
128 
129 /**
130  * \brief Run over elenents in the list
131  * @param ksp KSP solver
132  * @param A matrix
133  * @param B Preconditioner matrix
134  * @param ctx data context, i.e. KspCtx
135  * @return error code
136  */
137 PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx);
138 
139 } // namespace MoFEM
140 
141 #endif // __KSPCTX_HPP__
MoFEMTypes
Those types control how functions respond on arguments, f.e. error handling.
Definition: definitions.h:110
@ MF_EXIST
Definition: definitions.h:113
const FTensor::Tensor2< T, Dim, Dim > Vec
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:67
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
PetscErrorCode KspRhs(KSP ksp, Vec f, void *ctx)
Run over elements in the lists.
Definition: KspCtx.cpp:33
std::deque< BasicMethodPtr > BasicMethodsSequence
Definition: AuxPETSc.hpp:65
PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx)
Run over elenents in the list.
Definition: KspCtx.cpp:97
std::deque< PairNameFEMethodPtr > FEMethodsSequence
Definition: AuxPETSc.hpp:64
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1965
double A
Deprecated interface functions.
Interface for linear (KSP) solver.
Definition: KspCtx.hpp:27
FEMethodsSequence loops_to_do_Rhs
Definition: KspCtx.hpp:41
moab::Interface & moab
Definition: KspCtx.hpp:30
BasicMethodsSequence & get_postProcess_to_do_Rhs()
Definition: KspCtx.hpp:86
BasicMethodsSequence & get_preProcess_to_do_Rhs()
Definition: KspCtx.hpp:77
PetscLogEvent MOFEM_EVENT_KspRhs
Definition: KspCtx.hpp:113
BasicMethodsSequence preProcess_Rhs
Definition: KspCtx.hpp:47
KspCtx(MoFEM::Interface &m_field, const std::string &_problem_name)
Definition: KspCtx.hpp:52
BasicMethodsSequence postProcess_Rhs
Definition: KspCtx.hpp:49
virtual ~KspCtx()=default
BasicMethodsSequence postProcess_Mat
Definition: KspCtx.hpp:45
friend PetscErrorCode KspRhs(KSP ksp, Vec f, void *ctx)
Run over elements in the lists.
Definition: KspCtx.cpp:33
MoFEM::PairNameFEMethodPtr PairNameFEMethodPtr
Definition: KspCtx.hpp:35
BasicMethodsSequence & get_preProcess_to_do_Mat()
Definition: KspCtx.hpp:91
boost::movelib::unique_ptr< bool > matAssembleSwitch
Definition: KspCtx.hpp:117
PetscLogEvent MOFEM_EVENT_KspMat
Definition: KspCtx.hpp:114
MoFEMErrorCode clearLoops()
Clear loops.
Definition: KspCtx.cpp:23
BasicMethodsSequence & get_postProcess_to_do_Mat()
Definition: KspCtx.hpp:100
BasicMethodsSequence preProcess_Mat
Definition: KspCtx.hpp:43
FEMethodsSequence & get_loops_to_do_Mat()
Definition: KspCtx.hpp:63
MoFEM::BasicMethodsSequence BasicMethodsSequence
Definition: KspCtx.hpp:37
MoFEM::FEMethodsSequence FEMethodsSequence
Definition: KspCtx.hpp:36
MoFEM::Interface & mField
Definition: KspCtx.hpp:29
MoFEMTypes bH
If set to MF_EXIST check if element exist.
Definition: KspCtx.hpp:33
std::string problemName
Problem name.
Definition: KspCtx.hpp:32
friend PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx)
Run over elenents in the list.
Definition: KspCtx.cpp:97
FEMethodsSequence & get_loops_to_do_Rhs()
Definition: KspCtx.hpp:68
boost::movelib::unique_ptr< bool > vecAssembleSwitch
Definition: KspCtx.hpp:116
FEMethodsSequence loops_to_do_Mat
Definition: KspCtx.hpp:39