Nektar++
PreconCfsOp.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File PreconCfsOp.h
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: PreconCfsOp header
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #ifndef NEKTAR_SOLVERS_COMPRESSIBLEFLOWSOLVER_PRECONCFSOP
36 #define NEKTAR_SOLVERS_COMPRESSIBLEFLOWSOLVER_PRECONCFSOP
37 
41 
42 namespace Nektar
43 {
44 // =====================================================================
45 // ==== DEFINITION OF THE CLASS PreconCfsOps
46 // ==== Defines operators needed by operator based preconditioner in the
47 // ==== CFS solver
48 // =====================================================================
50 {
51 public:
54 
55  typedef std::function<void(
56  const Array<OneD, const Array<OneD, NekDouble>> &,
62 
63  typedef std::function<void(InArrayType &, InArrayType &, OutArrayType &,
64  const bool &)>
68  static const int nfunctor1 = 1;
69  static const int nfunctor2 = 0;
70 
72  {
73  }
76  {
77  for (int i = 0; i < nfunctor1; ++i)
78  {
79  m_functors1[i] = in.m_functors1[i];
80  }
81  for (int i = 0; i < nfunctor2; ++i)
82  {
83  m_functors2[i] = in.m_functors2[i];
84  }
85  }
86 
88  {
89  for (int i = 0; i < nfunctor1; ++i)
90  {
91  m_functors1[i] = in.m_functors1[i];
92  }
93  for (int i = 0; i < nfunctor2; ++i)
94  {
95  m_functors2[i] = in.m_functors2[i];
96  }
97 
98  return *this;
99  }
100 
101  template <typename FuncPointerT, typename ObjectPointerT>
102  void DefineCalcPreconMatBRJCoeff(FuncPointerT func, ObjectPointerT obj)
103  {
104  m_functors1[0] = std::bind(
105  func, obj, std::placeholders::_1, std::placeholders::_2,
106  std::placeholders::_3, std::placeholders::_4, std::placeholders::_5,
107  std::placeholders::_6, std::placeholders::_7, std::placeholders::_8,
108  std::placeholders::_9);
109  }
110 
112  const Array<OneD, const Array<OneD, NekDouble>> &inarray,
115  Array<OneD, SNekBlkMatSharedPtr> &TraceJacDeriv,
116  Array<OneD, Array<OneD, NekSingle>> &TraceJacDerivSign,
117  TensorOfArray4D<NekSingle> &TraceJacArray,
118  TensorOfArray4D<NekSingle> &TraceJacDerivArray,
119  TensorOfArray5D<NekSingle> &TraceIPSymJacArray)
120  {
121  ASSERTL1(m_functors1[0], "DoNekSysResEval should be defined");
122  m_functors1[0](inarray, gmtxarray, gmtVar, TraceJac, TraceJacDeriv,
123  TraceJacDerivSign, TraceJacArray, TraceJacDerivArray,
124  TraceIPSymJacArray);
125  }
126 
127 protected:
128  /* Defines three operators
129  DoNekSysResEval :
130  evaluations the residual of the Nonlinear/Linear system
131  ie. the residual b-Ax and N(x) for linear and
132  nonlinear systems, respectively
133  May not be used for linear system.
134  DoNekSysLhsEval :
135  evaluations the LHS of the Nonlinear/Linear system (Ax),
136  where A is the matrix and x is solution vector.
137  For linear system A is the coefficient matrix;
138  For nonlinear system A is the coefficient matrix in
139  each nonlinear iterations, for example A is the
140  Jacobian matrix for Newton method;
141  DoNekSysPrecon :
142  Preconditioning operator of the system.
143  DoNekSysFixPointIte :
144  Operator to calculate RHS of fixed point iterations
145  (x^{n+1}=M^{-1}(b-N*x^{n}), with M+N=A).
146  */
149 };
150 
151 // Forward declaration
152 class PreconCfsOp;
153 
154 typedef std::shared_ptr<PreconCfsOp> PreconCfsOpSharedPtr;
155 
156 /// Declaration of the boundary condition factory
158  std::string, PreconCfsOp,
163 
164 /// Declaration of the boundary condition factory singleton
166 
167 /**
168  * High level abstraction of operator based preconditioner.
169  * In some cases, the operators is not presented in matrix form
170  * (matrix-free implementation for example), thus operator classes needs to
171  * be provided to perform the operators needed in preconditioning.
172  *
173  * A brother class, PreconCfsMat for example, which stores the system
174  * coefficient matrix, could be designed. With the matrix, preconditioning
175  * matrix could be formed directly within this class
176  * (for example the ILU factorization).
177  * The operator defined in this class is not necessary in PreconCfsMat.
178  *
179  */
180 class PreconCfsOp : public PreconCfs
181 {
182 public:
184  const LibUtilities::SessionReaderSharedPtr &pSession,
185  const LibUtilities::CommSharedPtr &vComm);
186  virtual ~PreconCfsOp()
187  {
188  }
189 
190  inline void SetOperators(const NekPreconCfsOperators &in)
191  {
192  m_operator = in;
193  }
194 
195 protected:
197 
198  virtual void v_InitObject();
199 
200 private:
201  void NullPreconCfsOp(void);
202 
203  virtual void v_DoPreconCfs(
205  const Array<OneD, NekDouble> &pInput, Array<OneD, NekDouble> &pOutput,
206  const bool &flag);
207 
208  virtual void v_BuildPreconCfs(
210  const Array<OneD, const Array<OneD, NekDouble>> &intmp,
211  const NekDouble time, const NekDouble lambda);
212 
213  static std::string lookupIds[];
214  static std::string def;
215 };
216 typedef std::shared_ptr<PreconCfsOp> PreconCfsOpSharedPtr;
217 } // namespace Nektar
218 
219 #endif
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:250
Provides a generic Factory class.
Definition: NekFactory.hpp:105
FunctorType2Array m_functors2
Definition: PreconCfsOp.h:148
void DoCalcPreconMatBRJCoeff(const Array< OneD, const Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, SNekBlkMatSharedPtr >> &gmtxarray, SNekBlkMatSharedPtr &gmtVar, Array< OneD, SNekBlkMatSharedPtr > &TraceJac, Array< OneD, SNekBlkMatSharedPtr > &TraceJacDeriv, Array< OneD, Array< OneD, NekSingle >> &TraceJacDerivSign, TensorOfArray4D< NekSingle > &TraceJacArray, TensorOfArray4D< NekSingle > &TraceJacDerivArray, TensorOfArray5D< NekSingle > &TraceIPSymJacArray)
Definition: PreconCfsOp.h:111
std::function< void(const Array< OneD, const Array< OneD, NekDouble >> &, Array< OneD, Array< OneD, SNekBlkMatSharedPtr >> &, SNekBlkMatSharedPtr &, Array< OneD, SNekBlkMatSharedPtr > &, Array< OneD, SNekBlkMatSharedPtr > &, Array< OneD, Array< OneD, NekSingle >> &, TensorOfArray4D< NekSingle > &, TensorOfArray4D< NekSingle > &, TensorOfArray5D< NekSingle > &)> FunctorType1
Definition: PreconCfsOp.h:61
Array< OneD, NekDouble > OutArrayType
Definition: PreconCfsOp.h:53
std::function< void(InArrayType &, InArrayType &, OutArrayType &, const bool &)> FunctorType2
Definition: PreconCfsOp.h:65
NekPreconCfsOperators(const NekPreconCfsOperators &in)
Definition: PreconCfsOp.h:74
FunctorType1Array m_functors1
Definition: PreconCfsOp.h:147
NekPreconCfsOperators & operator=(const NekPreconCfsOperators &in)
Definition: PreconCfsOp.h:87
static const int nfunctor2
Definition: PreconCfsOp.h:69
const Array< OneD, NekDouble > InArrayType
Definition: PreconCfsOp.h:52
Array< OneD, FunctorType2 > FunctorType2Array
Definition: PreconCfsOp.h:67
void DefineCalcPreconMatBRJCoeff(FuncPointerT func, ObjectPointerT obj)
Definition: PreconCfsOp.h:102
static const int nfunctor1
Definition: PreconCfsOp.h:68
Array< OneD, FunctorType1 > FunctorType1Array
Definition: PreconCfsOp.h:66
virtual void v_InitObject()
Definition: PreconCfsOp.cpp:56
static std::string lookupIds[]
Definition: PreconCfsOp.h:213
virtual ~PreconCfsOp()
Definition: PreconCfsOp.h:186
virtual void v_DoPreconCfs(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const bool &flag)
Definition: PreconCfsOp.cpp:61
NekPreconCfsOperators m_operator
Definition: PreconCfsOp.h:196
void SetOperators(const NekPreconCfsOperators &in)
Definition: PreconCfsOp.h:190
void NullPreconCfsOp(void)
static std::string def
Definition: PreconCfsOp.h:214
virtual void v_BuildPreconCfs(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const Array< OneD, const Array< OneD, NekDouble >> &intmp, const NekDouble time, const NekDouble lambda)
Definition: PreconCfsOp.cpp:69
PreconCfsOp(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const LibUtilities::SessionReaderSharedPtr &pSession, const LibUtilities::CommSharedPtr &vComm)
Definition: PreconCfsOp.cpp:48
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:54
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
std::shared_ptr< SNekBlkMat > SNekBlkMatSharedPtr
std::shared_ptr< PreconCfsOp > PreconCfsOpSharedPtr
Definition: PreconCfsOp.h:152
double NekDouble
PreconCfsOpFactory & GetPreconCfsOpFactory()
Declaration of the boundary condition factory singleton.
Definition: PreconCfsOp.cpp:42
LibUtilities::NekFactory< std::string, PreconCfsOp, const Array< OneD, MultiRegions::ExpListSharedPtr > &, const LibUtilities::SessionReaderSharedPtr &, const LibUtilities::CommSharedPtr & > PreconCfsOpFactory
Declaration of the boundary condition factory.
Definition: PreconCfsOp.h:162