Nektar++
GlobalLinSys.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: GlobalLinSys.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: GlobalLinSys header
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 #ifndef NEKTAR_LIB_MULTIREGIONS_GLOBALLINSYS_H
35 #define NEKTAR_LIB_MULTIREGIONS_GLOBALLINSYS_H
36 
39 #include <MultiRegions/ExpList.h>
42 
43 namespace Nektar
44 {
45 namespace MultiRegions
46 {
47 // Forward declarations
48 class ExpList;
49 class GlobalLinSys;
50 class Preconditioner;
51 
52 /// Pointer to a GlobalLinSys object.
53 typedef std::shared_ptr<GlobalLinSys> GlobalLinSysSharedPtr;
54 /// Mapping between GlobalLinSys objects and their associated keys.
55 typedef std::map<GlobalLinSysKey, GlobalLinSysSharedPtr> GlobalLinSysMap;
56 /// Pointer to a GlobalLinSys/key map.
57 typedef std::shared_ptr<GlobalLinSysMap> GlobalLinSysMapShPtr;
58 
59 // Forward declaration
60 typedef std::shared_ptr<Preconditioner> PreconditionerSharedPtr;
61 
62 /// Datatype of the NekFactory used to instantiate classes derived from
63 /// the EquationSystem class.
65  std::string, GlobalLinSys, const GlobalLinSysKey &,
66  const std::weak_ptr<ExpList> &, const std::shared_ptr<AssemblyMap> &>
69 
70 /// A global linear system.
71 class GlobalLinSys : public std::enable_shared_from_this<GlobalLinSys>
72 {
73 public:
74  /// Constructor for full direct matrix solve.
76  const GlobalLinSysKey &pKey, const std::weak_ptr<ExpList> &pExpList,
77  const std::shared_ptr<AssemblyMap> &pLocToGloMap);
78 
80  virtual ~GlobalLinSys()
81  {
82  }
83 
84  /// Returns the key associated with the system.
85  const inline GlobalLinSysKey &GetKey(void) const;
86 
87  // Returns the local matrix associated with the system
88  const inline std::weak_ptr<ExpList> &GetLocMat(void) const;
89 
90  inline void InitObject();
91  inline void Initialise(const std::shared_ptr<AssemblyMap> &pLocToGloMap);
92 
93  /// Solve the linear system for given input and output vectors
94  /// using a specified local to global map.
96  inline void Solve(
98  const AssemblyMapSharedPtr &locToGloMap,
100 
101  /// Returns a shared pointer to the current object.
102  std::shared_ptr<GlobalLinSys> GetSharedThisPtr()
103  {
104  return shared_from_this();
105  }
106 
107  inline int GetNumBlocks();
108  inline DNekScalMatSharedPtr GetBlock(unsigned int n);
109  inline DNekScalBlkMatSharedPtr GetStaticCondBlock(unsigned int n);
110  inline void DropStaticCondBlock(unsigned int n);
111 
112  /// Solve the linear system for given input and output vectors.
113  inline void SolveLinearSystem(const int pNumRows,
114  const Array<OneD, const NekDouble> &pInput,
115  Array<OneD, NekDouble> &pOutput,
116  const AssemblyMapSharedPtr &locToGloMap,
117  const int pNumDir = 0);
118 
119 protected:
120  /// Key associated with this linear system.
122  /// Local Matrix System
123  const std::weak_ptr<ExpList> m_expList;
124  /// Robin boundary info
125  const std::map<int, RobinBCInfoSharedPtr> m_robinBCInfo;
126  // Provide verbose output
127  bool m_verbose;
128 
129  virtual int v_GetNumBlocks();
130  virtual DNekScalMatSharedPtr v_GetBlock(unsigned int n);
131  virtual DNekScalBlkMatSharedPtr v_GetStaticCondBlock(unsigned int n);
132  virtual void v_DropStaticCondBlock(unsigned int n);
133 
135 
136 private:
138 
139  /// Solve a linear system based on mapping.
140  virtual void v_Solve(const Array<OneD, const NekDouble> &in,
142  const AssemblyMapSharedPtr &locToGloMap,
143  const Array<OneD, const NekDouble> &dirForcing =
145 
146  /// Solve a basic matrix system.
147  virtual void v_SolveLinearSystem(const int pNumRows,
148  const Array<OneD, const NekDouble> &pInput,
149  Array<OneD, NekDouble> &pOutput,
150  const AssemblyMapSharedPtr &locToGloMap,
151  const int pNumDir) = 0;
152 
153  virtual void v_InitObject();
154  virtual void v_Initialise(const std::shared_ptr<AssemblyMap> &pLocToGloMap);
155 
156  static std::string lookupIds[];
157  static std::string def;
158 };
159 
160 /**
161  *
162  */
163 const inline GlobalLinSysKey &GlobalLinSys::GetKey(void) const
164 {
165  return m_linSysKey;
166 }
167 
168 /**
169  *
170  */
171 const inline std::weak_ptr<ExpList> &GlobalLinSys::GetLocMat(void) const
172 {
173  return m_expList;
174 }
175 
176 /**
177  *
178  */
181  const AssemblyMapSharedPtr &locToGloMap,
182  const Array<OneD, const NekDouble> &dirForcing)
183 {
184  v_Solve(in, out, locToGloMap, dirForcing);
185 }
186 
187 /**
188  *
189  */
191  const int pNumRows, const Array<OneD, const NekDouble> &pInput,
192  Array<OneD, NekDouble> &pOutput, const AssemblyMapSharedPtr &locToGloMap,
193  const int pNumDir)
194 {
195  v_SolveLinearSystem(pNumRows, pInput, pOutput, locToGloMap, pNumDir);
196 }
197 
199 {
200  v_InitObject();
201 }
202 
204  const std::shared_ptr<AssemblyMap> &pLocToGloMap)
205 {
206  v_Initialise(pLocToGloMap);
207 }
208 
210 {
211  return v_GetBlock(n);
212 }
213 
215 {
216  return v_GetStaticCondBlock(n);
217 }
218 
219 inline void GlobalLinSys::DropStaticCondBlock(unsigned int n)
220 {
221  return v_DropStaticCondBlock(n);
222 }
223 
225 {
226  return v_GetNumBlocks();
227 }
228 } // namespace MultiRegions
229 } // namespace Nektar
230 
231 #endif
#define MULTI_REGIONS_EXPORT
Provides a generic Factory class.
Definition: NekFactory.hpp:105
A global linear system.
Definition: GlobalLinSys.h:72
virtual void v_SolveLinearSystem(const int pNumRows, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const AssemblyMapSharedPtr &locToGloMap, const int pNumDir)=0
Solve a basic matrix system.
virtual int v_GetNumBlocks()
Get the number of blocks in this system.
const std::weak_ptr< ExpList > m_expList
Local Matrix System.
Definition: GlobalLinSys.h:123
void DropStaticCondBlock(unsigned int n)
Definition: GlobalLinSys.h:219
static std::string lookupIds[]
Definition: GlobalLinSys.h:156
std::shared_ptr< GlobalLinSys > GetSharedThisPtr()
Returns a shared pointer to the current object.
Definition: GlobalLinSys.h:102
LocalRegions::MatrixKey GetBlockMatrixKey(unsigned int n)
const GlobalLinSysKey & GetKey(void) const
Returns the key associated with the system.
Definition: GlobalLinSys.h:163
const std::map< int, RobinBCInfoSharedPtr > m_robinBCInfo
Robin boundary info.
Definition: GlobalLinSys.h:125
virtual void v_Solve(const Array< OneD, const NekDouble > &in, Array< OneD, NekDouble > &out, const AssemblyMapSharedPtr &locToGloMap, const Array< OneD, const NekDouble > &dirForcing=NullNekDouble1DArray)=0
Solve a linear system based on mapping.
GlobalLinSys(const GlobalLinSysKey &pKey, const std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Constructor for full direct matrix solve.
void Solve(const Array< OneD, const NekDouble > &in, Array< OneD, NekDouble > &out, const AssemblyMapSharedPtr &locToGloMap, const Array< OneD, const NekDouble > &dirForcing=NullNekDouble1DArray)
Solve the linear system for given input and output vectors using a specified local to global map.
Definition: GlobalLinSys.h:179
void SolveLinearSystem(const int pNumRows, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const AssemblyMapSharedPtr &locToGloMap, const int pNumDir=0)
Solve the linear system for given input and output vectors.
Definition: GlobalLinSys.h:190
const GlobalLinSysKey m_linSysKey
Key associated with this linear system.
Definition: GlobalLinSys.h:121
virtual DNekScalMatSharedPtr v_GetBlock(unsigned int n)
Retrieves the block matrix from n-th expansion using the matrix key provided by the m_linSysKey.
DNekScalMatSharedPtr GetBlock(unsigned int n)
Definition: GlobalLinSys.h:209
const std::weak_ptr< ExpList > & GetLocMat(void) const
Definition: GlobalLinSys.h:171
PreconditionerSharedPtr CreatePrecon(AssemblyMapSharedPtr asmMap)
Create a preconditioner object from the parameters defined in the supplied assembly map.
virtual DNekScalBlkMatSharedPtr v_GetStaticCondBlock(unsigned int n)
Retrieves a the static condensation block matrices from n-th expansion using the matrix key provided ...
virtual void v_Initialise(const std::shared_ptr< AssemblyMap > &pLocToGloMap)
virtual void v_DropStaticCondBlock(unsigned int n)
Releases the static condensation block matrices from NekManager of n-th expansion using the matrix ke...
void Initialise(const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Definition: GlobalLinSys.h:203
DNekScalBlkMatSharedPtr GetStaticCondBlock(unsigned int n)
Definition: GlobalLinSys.h:214
LibUtilities::NekFactory< std::string, GlobalLinSys, const GlobalLinSysKey &, const std::weak_ptr< ExpList > &, const std::shared_ptr< AssemblyMap > & > GlobalLinSysFactory
Datatype of the NekFactory used to instantiate classes derived from the EquationSystem class.
Definition: GlobalLinSys.h:67
std::shared_ptr< GlobalLinSys > GlobalLinSysSharedPtr
Pointer to a GlobalLinSys object.
Definition: GlobalLinSys.h:50
std::map< GlobalLinSysKey, GlobalLinSysSharedPtr > GlobalLinSysMap
Mapping between GlobalLinSys objects and their associated keys.
Definition: GlobalLinSys.h:55
GlobalLinSysFactory & GetGlobalLinSysFactory()
std::shared_ptr< Preconditioner > PreconditionerSharedPtr
Definition: GlobalLinSys.h:60
std::shared_ptr< AssemblyMap > AssemblyMapSharedPtr
Definition: AssemblyMap.h:51
std::shared_ptr< GlobalLinSysMap > GlobalLinSysMapShPtr
Pointer to a GlobalLinSys/key map.
Definition: GlobalLinSys.h:57
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
std::shared_ptr< DNekScalMat > DNekScalMatSharedPtr
std::shared_ptr< DNekScalBlkMat > DNekScalBlkMatSharedPtr
Definition: NekTypeDefs.hpp:79
static Array< OneD, NekDouble > NullNekDouble1DArray