v0.8.23
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 petsc_context_struture
26  */
27 struct KspCtx {
28 
30  moab::Interface &moab;
31 
32  std::string problemName; ///< Problem name
33  MoFEMTypes bH; ///< If set to MF_EXIST check if element exist
34 
35  /// \deprecated use PairNameFEMethodPtr
37 
38  /// \deprecated use FEMethodsSequence
40 
41  /// \deprecated use BasicMethodsSequence
43 
47 
48  FEMethodsSequence loops_to_do_Mat; ///< Sequence of finite elements instances
49  ///< assembling tangent matrix
50  FEMethodsSequence loops_to_do_Rhs; ///< Sequence of finite elements instances
51  ///< assembling residual vector
52  BasicMethodsSequence preProcess_Mat; ///< Sequence of methods run before
53  ///< tangent matrix is assembled
54  BasicMethodsSequence postProcess_Mat; ///< Sequence of methods run after
55  ///< tangent matrix is assembled
57  preProcess_Rhs; ///< Sequence of methods run before residual is assembled
59  postProcess_Rhs; ///< Sequence of methods run after residual is assembled
60 
61  KspCtx(MoFEM::Interface &m_field, const std::string &_problem_name)
62  : mField(m_field), moab(m_field.get_moab()), problemName(_problem_name),
63  bH(MF_EXIST) {
64  PetscLogEventRegister("LoopKSPRhs", 0, &MOFEM_EVENT_KspRhs);
65  PetscLogEventRegister("LoopKSPMat", 0, &MOFEM_EVENT_KspMat);
66  }
67  virtual ~KspCtx() {}
68 
69  /**
70  * @return return reference to vector with FEMethod to calculate matrix
71  */
73 
74  /**
75  * @return return vector to vector with FEMethod to vector
76  */
78 
79  /**
80  * The sequence of BasicMethod is executed before residual is calculated. It
81  * can be used to setup data structures, e.g. zero global variable which is
82  * integrated in domain, e.g. for calculation of strain energy.
83  *
84  * @return reference to BasicMethod for preprocessing
85  */
87 
88  /**
89  * The sequence of BasicMethod is executed after residual is calculated. It
90  * can be used to setup data structures, e.g. aggregate data from processors
91  * or to apply essential boundary conditions.
92  *
93  * @return reference to BasicMethod for postprocessing
94  */
96 
97  /**
98  * @return reference to BasicMethod for preprocessing
99  */
101 
102  /**
103  * The sequence of BasicMethod is executed after tangent matrix is calculated.
104  * It can be used to setup data structures, e.g. aggregate data from
105  * processors or to apply essential boundary conditions.
106  *
107  * @return reference to BasicMethod for postprocessing
108  */
110 
111  friend PetscErrorCode KspRhs(KSP ksp, Vec f, void *ctx);
112  friend PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx);
113 
114 private:
115 
116  PetscLogEvent MOFEM_EVENT_KspRhs;
117  PetscLogEvent MOFEM_EVENT_KspMat;
118 
119  boost::movelib::unique_ptr<bool> vecAssembleSwitch;
120  boost::movelib::unique_ptr<bool> matAssembleSwitch;
121 
122 };
123 
124 /**
125  * \brief Run over elements in the lists
126  * @param ksp KSP solver
127  * @param f the right hand side vector
128  * @param ctx data context, i.e. KspCtx
129  * @return error code
130  */
131 PetscErrorCode KspRhs(KSP ksp, Vec f, void *ctx);
132 
133 /**
134  * \brief Run over elenents in the list
135  * @param ksp KSP solver
136  * @param A matrix
137  * @param B Preconditioner matrix
138  * @param ctx data context, i.e. KspCtx
139  * @return error code
140  */
141 PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx);
142 
143 } // namespace MoFEM
144 
145 /**
146  * \defgroup petsc_context_struture Solver context structures
147  * \brief Context structures for KSP solver
148  *
149  * \ingroup mofem
150  **/
151 
152 #endif // __KSPCTX_HPP__
BasicMethodsSequence postProcess_Rhs
Sequence of methods run after residual is assembled.
Definition: KspCtx.hpp:59
friend PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx)
Run over elenents in the list.
Definition: KspCtx.cpp:71
DEPRECATED typedef MoFEM::FEMethodsSequence loops_to_do_type
Definition: KspCtx.hpp:39
BasicMethodsSequence & get_postProcess_to_do_Rhs()
Definition: KspCtx.hpp:95
DEPRECATED typedef MoFEM::PairNameFEMethodPtr loop_pair_type
Definition: KspCtx.hpp:36
MoFEM::BasicMethodsSequence BasicMethodsSequence
Definition: KspCtx.hpp:46
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:116
std::vector< BasicMethodPtr > BasicMethodsSequence
Definition: AuxPETSc.hpp:108
KspCtx(MoFEM::Interface &m_field, const std::string &_problem_name)
Definition: KspCtx.hpp:61
boost::movelib::unique_ptr< bool > vecAssembleSwitch
Definition: KspCtx.hpp:119
moab::Interface & moab
Definition: KspCtx.hpp:30
BasicMethodsSequence & get_preProcess_to_do_Rhs()
Definition: KspCtx.hpp:86
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:71
FEMethodsSequence & get_loops_to_do_Rhs()
Definition: KspCtx.hpp:77
BasicMethodsSequence & get_preProcess_to_do_Mat()
Definition: KspCtx.hpp:100
MoFEM::PairNameFEMethodPtr PairNameFEMethodPtr
Definition: KspCtx.hpp:44
std::vector< PairNameFEMethodPtr > FEMethodsSequence
Definition: AuxPETSc.hpp:107
boost::movelib::unique_ptr< bool > matAssembleSwitch
Definition: KspCtx.hpp:120
FEMethodsSequence loops_to_do_Rhs
Definition: KspCtx.hpp:50
Interface for linear (KSP) solver.
Definition: KspCtx.hpp:27
#define DEPRECATED
Definition: definitions.h:29
PetscLogEvent MOFEM_EVENT_KspMat
Definition: KspCtx.hpp:117
FEMethodsSequence & get_loops_to_do_Mat()
Definition: KspCtx.hpp:72
virtual ~KspCtx()
Definition: KspCtx.hpp:67
MoFEM::FEMethodsSequence FEMethodsSequence
Definition: KspCtx.hpp:45
BasicMethodsSequence & get_postProcess_to_do_Mat()
Definition: KspCtx.hpp:109
friend PetscErrorCode KspRhs(KSP ksp, Vec f, void *ctx)
Run over elements in the lists.
Definition: KspCtx.cpp:23
MoFEMTypes
Those types control how functions respond on arguments, f.e. error handling.
Definition: definitions.h:182
FEMethodsSequence loops_to_do_Mat
Definition: KspCtx.hpp:48
DEPRECATED typedef MoFEM::BasicMethodsSequence basic_method_to_do
Definition: KspCtx.hpp:42