Nektar++
GlobalLinSysIterative.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: GlobalLinSysIterative.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: GlobalLinSysIterative header
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 #ifndef NEKTAR_LIB_MULTIREGIONS_GLOBALLINSYSITERATIVE_H
35 #define NEKTAR_LIB_MULTIREGIONS_GLOBALLINSYSITERATIVE_H
36 
41 
42 namespace Nektar
43 {
44 namespace MultiRegions
45 {
46 // Forward declarations
47 class ExpList;
48 
49 /// A global linear system.
50 class GlobalLinSysIterative : virtual public GlobalLinSys
51 {
52 public:
53  /// Constructor for full direct matrix solve.
55  const GlobalLinSysKey &pKey, const std::weak_ptr<ExpList> &pExpList,
56  const std::shared_ptr<AssemblyMap> &pLocToGloMap);
57 
59 
60 protected:
61  /// Global to universal unique map
63 
64  /// maximum iterations
65  int m_maxiter;
66 
67  /// Tolerance of iterative solver.
69 
70  /// dot product of rhs to normalise stopping criterion
72 
73  /// cnt to how many times rhs_magnitude is called
75 
77 
79 
81 
82  /// Whether to apply projection technique
84 
85  /// Root if parallel
86  bool m_root;
87 
88  /// Iterative solver: Conjugate Gradient, GMRES
89  std::string m_linSysIterSolver;
90 
91  /// Storage for solutions to previous linear problems
92  std::vector<Array<OneD, NekDouble>> m_prevLinSol;
93  std::vector<Array<OneD, NekDouble>> m_prevBasis;
100 
102 
104 
105  static std::string IteratSolverlookupIds[];
106  static std::string IteratSolverdef;
107 
108  /// projection technique
109  void DoProjection(const int pNumRows,
110  const Array<OneD, const NekDouble> &pInput,
111  Array<OneD, NekDouble> &pOutput, const int pNumDir,
112  const NekDouble tol, const bool isAconjugate);
113 
114  void Set_Rhs_Magnitude(const NekVector<NekDouble> &pIn);
115 
116  virtual void v_UniqueMap() = 0;
117 
118  /// Solve the matrix system
119  virtual void v_SolveLinearSystem(const int pNumRows,
120  const Array<OneD, const NekDouble> &pInput,
121  Array<OneD, NekDouble> &pOutput,
122  const AssemblyMapSharedPtr &locToGloMap,
123  const int pNumDir) override;
124 
125  virtual void v_DoMatrixMultiply(const Array<OneD, NekDouble> &pInput,
126  Array<OneD, NekDouble> &pOutput) = 0;
127 
128 private:
129  void UpdateKnownSolutions(const int pGlobalBndDofs,
130  const Array<OneD, const NekDouble> &pSolution,
131  const int pNumDirBndDofs,
132  const bool isAconjugate);
133 
135 
137  Array<OneD, NekDouble> &pOutput,
138  const bool &controlFlag)
139  {
140  boost::ignore_unused(controlFlag);
141 
142  v_DoMatrixMultiply(pInput, pOutput);
143  }
144 
146  Array<OneD, NekDouble> &pOutput,
147  const bool &controlFlag)
148  {
149  boost::ignore_unused(controlFlag);
150 
151  m_precon->DoPreconditioner(pInput, pOutput);
152  }
153 };
154 } // namespace MultiRegions
155 } // namespace Nektar
156 
157 #endif
#define MULTI_REGIONS_EXPORT
A global linear system.
Definition: GlobalLinSys.h:72
GlobalLinSysIterative(const GlobalLinSysKey &pKey, const std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Constructor for full direct matrix solve.
std::vector< Array< OneD, NekDouble > > m_prevBasis
LibUtilities::NekLinSysIterSharedPtr m_linsol
void DoProjection(const int pNumRows, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const int pNumDir, const NekDouble tol, const bool isAconjugate)
projection technique
void UpdateKnownSolutions(const int pGlobalBndDofs, const Array< OneD, const NekDouble > &pSolution, const int pNumDirBndDofs, const bool isAconjugate)
std::vector< Array< OneD, NekDouble > > m_prevLinSol
Storage for solutions to previous linear problems.
void DoMatrixMultiplyFlag(const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const bool &controlFlag)
virtual void v_DoMatrixMultiply(const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput)=0
bool m_useProjection
Whether to apply projection technique.
virtual void v_SolveLinearSystem(const int pNumRows, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const AssemblyMapSharedPtr &locToGloMap, const int pNumDir) override
Solve the matrix system.
NekDouble m_tolerance
Tolerance of iterative solver.
void DoPreconditionerFlag(const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const bool &controlFlag)
Array< OneD, int > m_map
Global to universal unique map.
NekDouble m_rhs_magnitude
dot product of rhs to normalise stopping criterion
MultiRegions::PreconditionerType m_precontype
std::string m_linSysIterSolver
Iterative solver: Conjugate Gradient, GMRES.
void Set_Rhs_Magnitude(const NekVector< NekDouble > &pIn)
NekDouble m_rhs_mag_sm
cnt to how many times rhs_magnitude is called
std::shared_ptr< NekLinSysIter > NekLinSysIterSharedPtr
Definition: NekLinSysIter.h:46
std::shared_ptr< Preconditioner > PreconditionerSharedPtr
Definition: GlobalLinSys.h:60
std::shared_ptr< AssemblyMap > AssemblyMapSharedPtr
Definition: AssemblyMap.h:51
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
std::shared_ptr< DNekMat > DNekMatSharedPtr
Definition: NekTypeDefs.hpp:75
double NekDouble