v0.14.0
Loading...
Searching...
No Matches
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
8namespace MoFEM {
9
10/** \brief Interface for linear (KSP) solver
11 * \ingroup mofem_petsc_solvers
12 */
13struct KspCtx {
14
16 moab::Interface &moab;
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 */
126 }
127
128private:
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 */
143PetscErrorCode 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 */
153PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx);
154
155} // namespace MoFEM
156
157#endif // __KSPCTX_HPP__
MoFEMTypes
Those types control how functions respond on arguments, f.e. error handling.
Definition: definitions.h:97
@ MF_EXIST
Definition: definitions.h:100
#define DEPRECATED
Definition: definitions.h:17
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
PetscErrorCode KspRhs(KSP ksp, Vec f, void *ctx)
Run over elements in the lists.
Definition: KspCtx.cpp:21
std::deque< BasicMethodPtr > BasicMethodsSequence
Definition: AuxPETSc.hpp:57
PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx)
Run over elements in the list.
Definition: KspCtx.cpp:86
std::deque< PairNameFEMethodPtr > FEMethodsSequence
Definition: AuxPETSc.hpp:56
constexpr AssemblyType A
Deprecated interface functions.
Interface for linear (KSP) solver.
Definition: KspCtx.hpp:13
FEMethodsSequence loops_to_do_Rhs
Definition: KspCtx.hpp:27
moab::Interface & moab
Definition: KspCtx.hpp:16
DEPRECATED BasicMethodsSequence & get_preProcess_to_do_Rhs()
Definition: KspCtx.hpp:109
BasicMethodsSequence & getPostProcComputeRhs()
Definition: KspCtx.hpp:72
BasicMethodsSequence & getPreProcComputeRhs()
Definition: KspCtx.hpp:63
BasicMethodsSequence & getPreProcSetOperators()
Definition: KspCtx.hpp:77
PetscLogEvent MOFEM_EVENT_KspRhs
Definition: KspCtx.hpp:129
BasicMethodsSequence preProcess_Rhs
Definition: KspCtx.hpp:33
KspCtx(MoFEM::Interface &m_field, const std::string &_problem_name)
Definition: KspCtx.hpp:38
BasicMethodsSequence postProcess_Rhs
Definition: KspCtx.hpp:35
DEPRECATED BasicMethodsSequence & get_postProcess_to_do_Mat()
Definition: KspCtx.hpp:124
FEMethodsSequence & getSetOperators()
Definition: KspCtx.hpp:49
DEPRECATED BasicMethodsSequence & get_preProcess_to_do_Mat()
Definition: KspCtx.hpp:119
virtual ~KspCtx()=default
BasicMethodsSequence postProcess_Mat
Definition: KspCtx.hpp:31
friend PetscErrorCode KspRhs(KSP ksp, Vec f, void *ctx)
Run over elements in the lists.
Definition: KspCtx.cpp:21
MoFEM::PairNameFEMethodPtr PairNameFEMethodPtr
Definition: KspCtx.hpp:21
boost::movelib::unique_ptr< bool > matAssembleSwitch
Definition: KspCtx.hpp:133
PetscLogEvent MOFEM_EVENT_KspMat
Definition: KspCtx.hpp:130
FEMethodsSequence & getComputeRhs()
Definition: KspCtx.hpp:54
MoFEMErrorCode clearLoops()
Clear loops.
Definition: KspCtx.cpp:11
BasicMethodsSequence preProcess_Mat
Definition: KspCtx.hpp:29
MoFEM::BasicMethodsSequence BasicMethodsSequence
Definition: KspCtx.hpp:23
MoFEM::FEMethodsSequence FEMethodsSequence
Definition: KspCtx.hpp:22
MoFEM::Interface & mField
Definition: KspCtx.hpp:15
MoFEMTypes bH
If set to MF_EXIST check if element exist.
Definition: KspCtx.hpp:19
BasicMethodsSequence & get_postProcess_to_do_Rhs()
Definition: KspCtx.hpp:114
DEPRECATED FEMethodsSequence & get_loops_to_do_Rhs()
Definition: KspCtx.hpp:104
std::string problemName
Problem name.
Definition: KspCtx.hpp:18
friend PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx)
Run over elements in the list.
Definition: KspCtx.cpp:86
boost::movelib::unique_ptr< bool > vecAssembleSwitch
Definition: KspCtx.hpp:132
DEPRECATED FEMethodsSequence & get_loops_to_do_Mat()
Definition: KspCtx.hpp:99
FEMethodsSequence loops_to_do_Mat
Definition: KspCtx.hpp:25
BasicMethodsSequence & getPostProcSetOperators()
Definition: KspCtx.hpp:86