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  PetscLogEvent MOFEM_EVENT_KspRhs;
62  PetscLogEvent MOFEM_EVENT_KspMat;
63 
64  KspCtx(MoFEM::Interface &m_field, const std::string &_problem_name)
65  : mField(m_field), moab(m_field.get_moab()), problemName(_problem_name),
66  bH(MF_EXIST) {
67  PetscLogEventRegister("LoopKSPRhs", 0, &MOFEM_EVENT_KspRhs);
68  PetscLogEventRegister("LoopKSPMat", 0, &MOFEM_EVENT_KspMat);
69  }
70  virtual ~KspCtx() {}
71 
72  /**
73  * @return return reference to vector with FEMethod to calculate matrix
74  */
76 
77  /**
78  * @return return vector to vector with FEMethod to vector
79  */
81 
82  /**
83  * The sequence of BasicMethod is executed before residual is calculated. It
84  * can be used to setup data structures, e.g. zero global variable which is
85  * integrated in domain, e.g. for calculation of strain energy.
86  *
87  * @return reference to BasicMethod for preprocessing
88  */
90 
91  /**
92  * The sequence of BasicMethod is executed after residual is calculated. It
93  * can be used to setup data structures, e.g. aggregate data from processors
94  * or to apply essential boundary conditions.
95  *
96  * @return reference to BasicMethod for postprocessing
97  */
99 
100  /**
101  * @return reference to BasicMethod for preprocessing
102  */
104 
105  /**
106  * The sequence of BasicMethod is executed after tangent matrix is calculated.
107  * It can be used to setup data structures, e.g. aggregate data from
108  * processors or to apply essential boundary conditions.
109  *
110  * @return reference to BasicMethod for postprocessing
111  */
113 
114  friend PetscErrorCode KspRhs(KSP ksp, Vec f, void *ctx);
115  friend PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx);
116 };
117 
118 /**
119  * \brief Run over elements in the lists
120  * @param ksp KSP solver
121  * @param f the right hand side vector
122  * @param ctx data context, i.e. KspCtx
123  * @return error code
124  */
125 PetscErrorCode KspRhs(KSP ksp, Vec f, void *ctx);
126 
127 /**
128  * \brief Run over elenents in the list
129  * @param ksp KSP solver
130  * @param A matrix
131  * @param B Preconditioner matrix
132  * @param ctx data context, i.e. KspCtx
133  * @return error code
134  */
135 PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx);
136 
137 } // namespace MoFEM
138 
139 /***************************************************************************/ /**
140 * \defgroup petsc_context_struture Solver context structures
141 * \brief Context structures used to exchange information between PETSc and MoFEM
142 *
143 * \ingroup mofem
144 ******************************************************************************/
145 
146 #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:62
DEPRECATED typedef MoFEM::FEMethodsSequence loops_to_do_type
Definition: KspCtx.hpp:39
BasicMethodsSequence & get_postProcess_to_do_Rhs()
Definition: KspCtx.hpp:98
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:61
std::vector< BasicMethodPtr > BasicMethodsSequence
Definition: AuxPETSc.hpp:65
KspCtx(MoFEM::Interface &m_field, const std::string &_problem_name)
Definition: KspCtx.hpp:64
moab::Interface & moab
Definition: KspCtx.hpp:30
BasicMethodsSequence & get_preProcess_to_do_Rhs()
Definition: KspCtx.hpp:89
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:62
FEMethodsSequence & get_loops_to_do_Rhs()
Definition: KspCtx.hpp:80
BasicMethodsSequence & get_preProcess_to_do_Mat()
Definition: KspCtx.hpp:103
MoFEM::PairNameFEMethodPtr PairNameFEMethodPtr
Definition: KspCtx.hpp:44
std::vector< PairNameFEMethodPtr > FEMethodsSequence
Definition: AuxPETSc.hpp:64
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:62
FEMethodsSequence & get_loops_to_do_Mat()
Definition: KspCtx.hpp:75
virtual ~KspCtx()
Definition: KspCtx.hpp:70
MoFEM::FEMethodsSequence FEMethodsSequence
Definition: KspCtx.hpp:45
BasicMethodsSequence & get_postProcess_to_do_Mat()
Definition: KspCtx.hpp:112
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