v0.14.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 #ifndef __KSPCTX_HPP__
6 #define __KSPCTX_HPP__
7 
8 namespace MoFEM {
9 
10 /** \brief Interface for linear (KSP) solver
11  * \ingroup mofem_petsc_solvers
12  */
13 struct KspCtx {
14 
17 
18  std::string problemName; ///< Problem name
19  MoFEMTypes bH; ///< If set to MF_EXIST check if element exist
20 
24 
25  FEMethodsSequence loops_to_do_Mat; ///< Sequence of finite elements instances
26  ///< assembling tangent matrix
27  FEMethodsSequence loops_to_do_Rhs; ///< Sequence of finite elements
28  ///< instances assembling residual vector
29  BasicMethodsSequence preProcess_Mat; ///< Sequence of methods run before
30  ///< tangent matrix is assembled
31  BasicMethodsSequence postProcess_Mat; ///< Sequence of methods run after
32  ///< tangent matrix is assembled
33  BasicMethodsSequence preProcess_Rhs; ///< Sequence of methods run before
34  ///< residual is assembled
35  BasicMethodsSequence postProcess_Rhs; ///< Sequence of methods run after
36  ///< residual is assembled
37 
38  KspCtx(MoFEM::Interface &m_field, const std::string &_problem_name)
39  : mField(m_field), moab(m_field.get_moab()), problemName(_problem_name),
40  bH(MF_EXIST) {
41  PetscLogEventRegister("LoopKSPRhs", 0, &MOFEM_EVENT_KspRhs);
42  PetscLogEventRegister("LoopKSPMat", 0, &MOFEM_EVENT_KspMat);
43  }
44  virtual ~KspCtx() = default;
45 
46  /**
47  * @return return reference to vector with FEMethod to calculate matrix
48  */
50 
51  /**
52  * @return return vector to vector with FEMethod to vector
53  */
55 
56  /**
57  * The sequence of BasicMethod is executed before residual is calculated. It
58  * can be used to setup data structures, e.g. zero global variable which is
59  * integrated in domain, e.g. for calculation of strain energy.
60  *
61  * @return reference to BasicMethod for preprocessing
62  */
64 
65  /**
66  * The sequence of BasicMethod is executed after residual is calculated. It
67  * can be used to setup data structures, e.g. aggregate data from processors
68  * or to apply essential boundary conditions.
69  *
70  * @return reference to BasicMethod for postprocessing
71  */
73 
74  /**
75  * @return reference to BasicMethod for preprocessing
76  */
78 
79  /**
80  * The sequence of BasicMethod is executed after tangent matrix is calculated.
81  * It can be used to setup data structures, e.g. aggregate data from
82  * processors or to apply essential boundary conditions.
83  *
84  * @return reference to BasicMethod for postprocessing
85  */
87 
88  friend PetscErrorCode KspRhs(KSP ksp, Vec f, void *ctx);
89  friend PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx);
90 
91  /**
92  * @brief Clear loops
93  *
94  * @return MoFEMErrorCode
95  */
97 
98  /** @deprecated use getSetOperator */
100  return getSetOperators();
101  }
102 
103  /** @deprecated use getComputeRhs */
105  return getComputeRhs();
106  }
107 
108  /** @deprecated use getPreProcComputeRhs */
110  return getPreProcComputeRhs();
111  }
112 
113  /** @deprecated use getPostProcComputeRhs */
115  return getPostProcComputeRhs();
116  }
117 
118  /** @deprecated use getPreProcSetOperators */
120  return getPreProcSetOperators();
121  }
122 
123  /** @deprecated use getPostProcSetOperators */
125  return getPostProcSetOperators();
126  }
127 
128 private:
129  PetscLogEvent MOFEM_EVENT_KspRhs;
130  PetscLogEvent MOFEM_EVENT_KspMat;
131 
132  boost::movelib::unique_ptr<bool> vecAssembleSwitch;
133  boost::movelib::unique_ptr<bool> matAssembleSwitch;
134 };
135 
136 /**
137  * \brief Run over elements in the lists
138  * @param ksp KSP solver
139  * @param f the right hand side vector
140  * @param ctx data context, i.e. KspCtx
141  * @return error code
142  */
143 PetscErrorCode KspRhs(KSP ksp, Vec f, void *ctx);
144 
145 /**
146  * \brief Run over elements in the list
147  * @param ksp KSP solver
148  * @param A matrix
149  * @param B Preconditioned matrix
150  * @param ctx data context, i.e. KspCtx
151  * @return error code
152  */
153 PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx);
154 
155 } // namespace MoFEM
156 
157 #endif // __KSPCTX_HPP__
MoFEM::KspRhs
PetscErrorCode KspRhs(KSP ksp, Vec f, void *ctx)
Run over elements in the lists.
Definition: KspCtx.cpp:21
DEPRECATED
#define DEPRECATED
Definition: definitions.h:17
MoFEM::KspCtx::getComputeRhs
FEMethodsSequence & getComputeRhs()
Definition: KspCtx.hpp:54
MoFEM::KspCtx::loops_to_do_Rhs
FEMethodsSequence loops_to_do_Rhs
Definition: KspCtx.hpp:27
MoFEM::KspCtx::get_postProcess_to_do_Rhs
BasicMethodsSequence & get_postProcess_to_do_Rhs()
Definition: KspCtx.hpp:114
MoFEM::KspCtx::problemName
std::string problemName
Problem name.
Definition: KspCtx.hpp:18
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
MoFEM::KspCtx::get_loops_to_do_Rhs
DEPRECATED FEMethodsSequence & get_loops_to_do_Rhs()
Definition: KspCtx.hpp:104
MoFEM::KspCtx::bH
MoFEMTypes bH
If set to MF_EXIST check if element exist.
Definition: KspCtx.hpp:19
MoFEM::FEMethodsSequence
std::deque< PairNameFEMethodPtr > FEMethodsSequence
Definition: AuxPETSc.hpp:56
MoFEM::KspCtx::mField
MoFEM::Interface & mField
Definition: KspCtx.hpp:15
MoFEM::KspCtx::get_loops_to_do_Mat
DEPRECATED FEMethodsSequence & get_loops_to_do_Mat()
Definition: KspCtx.hpp:99
A
constexpr AssemblyType A
Definition: operators_tests.cpp:30
MoFEM::KspCtx::postProcess_Rhs
BasicMethodsSequence postProcess_Rhs
Definition: KspCtx.hpp:35
MoFEM::KspCtx::~KspCtx
virtual ~KspCtx()=default
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1975
MoFEM::KspCtx::getPreProcSetOperators
BasicMethodsSequence & getPreProcSetOperators()
Definition: KspCtx.hpp:77
MoFEM::KspCtx::KspRhs
friend PetscErrorCode KspRhs(KSP ksp, Vec f, void *ctx)
Run over elements in the lists.
Definition: KspCtx.cpp:21
MoFEM::KspCtx::loops_to_do_Mat
FEMethodsSequence loops_to_do_Mat
Definition: KspCtx.hpp:25
MoFEM::KspCtx::clearLoops
MoFEMErrorCode clearLoops()
Clear loops.
Definition: KspCtx.cpp:11
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
MoFEM::KspCtx::preProcess_Mat
BasicMethodsSequence preProcess_Mat
Definition: KspCtx.hpp:29
MoFEM::KspCtx::getSetOperators
FEMethodsSequence & getSetOperators()
Definition: KspCtx.hpp:49
MoFEM::KspCtx::KspMat
friend PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx)
Run over elements in the list.
Definition: KspCtx.cpp:86
MoFEM::KspCtx::getPostProcComputeRhs
BasicMethodsSequence & getPostProcComputeRhs()
Definition: KspCtx.hpp:72
MoFEM::KspCtx::matAssembleSwitch
boost::movelib::unique_ptr< bool > matAssembleSwitch
Definition: KspCtx.hpp:133
MoFEM::BasicMethodsSequence
std::deque< BasicMethodPtr > BasicMethodsSequence
Definition: AuxPETSc.hpp:57
MoFEM::KspCtx::postProcess_Mat
BasicMethodsSequence postProcess_Mat
Definition: KspCtx.hpp:31
MoFEM::PairNameFEMethodPtr
Definition: AuxPETSc.hpp:12
MoFEM::KspCtx::get_preProcess_to_do_Mat
DEPRECATED BasicMethodsSequence & get_preProcess_to_do_Mat()
Definition: KspCtx.hpp:119
MoFEM::KspCtx::PairNameFEMethodPtr
MoFEM::PairNameFEMethodPtr PairNameFEMethodPtr
Definition: KspCtx.hpp:21
MoFEM::KspCtx::get_preProcess_to_do_Rhs
DEPRECATED BasicMethodsSequence & get_preProcess_to_do_Rhs()
Definition: KspCtx.hpp:109
MoFEM::KspCtx::get_postProcess_to_do_Mat
DEPRECATED BasicMethodsSequence & get_postProcess_to_do_Mat()
Definition: KspCtx.hpp:124
MoFEM::KspCtx::MOFEM_EVENT_KspRhs
PetscLogEvent MOFEM_EVENT_KspRhs
Definition: KspCtx.hpp:129
MoFEM::KspCtx::MOFEM_EVENT_KspMat
PetscLogEvent MOFEM_EVENT_KspMat
Definition: KspCtx.hpp:130
MoFEM::KspCtx::getPostProcSetOperators
BasicMethodsSequence & getPostProcSetOperators()
Definition: KspCtx.hpp:86
HenckyOps::f
auto f
Definition: HenckyOps.hpp:15
MoFEM::KspMat
PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx)
Run over elements in the list.
Definition: KspCtx.cpp:86
MoFEM::KspCtx::KspCtx
KspCtx(MoFEM::Interface &m_field, const std::string &_problem_name)
Definition: KspCtx.hpp:38
EigenMatrix::Vec
const FTensor::Tensor2< T, Dim, Dim > Vec
Definition: MatrixFunction.hpp:66
MoFEM::KspCtx::getPreProcComputeRhs
BasicMethodsSequence & getPreProcComputeRhs()
Definition: KspCtx.hpp:63
MoFEM::KspCtx
Interface for linear (KSP) solver.
Definition: KspCtx.hpp:13
MoFEMTypes
MoFEMTypes
Those types control how functions respond on arguments, f.e. error handling.
Definition: definitions.h:97
MoFEM::KspCtx::FEMethodsSequence
MoFEM::FEMethodsSequence FEMethodsSequence
Definition: KspCtx.hpp:22
MoFEM::KspCtx::vecAssembleSwitch
boost::movelib::unique_ptr< bool > vecAssembleSwitch
Definition: KspCtx.hpp:132
MF_EXIST
@ MF_EXIST
Definition: definitions.h:100
MoFEM::KspCtx::BasicMethodsSequence
MoFEM::BasicMethodsSequence BasicMethodsSequence
Definition: KspCtx.hpp:23
MoFEM::KspCtx::preProcess_Rhs
BasicMethodsSequence preProcess_Rhs
Definition: KspCtx.hpp:33
MoFEM::KspCtx::moab
moab::Interface & moab
Definition: KspCtx.hpp:16