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