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 
40 #include <MultiRegions/ExpList.h>
42 
43 namespace Nektar
44 {
45  namespace MultiRegions
46  {
47  // Forward declarations
48  class ExpList;
49  class GlobalLinSys;
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.
64  typedef LibUtilities::NekFactory< std::string, GlobalLinSys,
65  const GlobalLinSysKey&,
66  const std::weak_ptr<ExpList>&,
67  const std::shared_ptr<AssemblyMap>& > GlobalLinSysFactory;
68  GlobalLinSysFactory& GetGlobalLinSysFactory();
69 
70 
71  /// A global linear system.
72  class GlobalLinSys: public std::enable_shared_from_this<GlobalLinSys>
73  {
74  public:
75  /// Constructor for full direct matrix solve.
77  const GlobalLinSysKey &pKey,
78  const std::weak_ptr<ExpList> &pExpList,
79  const std::shared_ptr<AssemblyMap> &pLocToGloMap);
80 
82  virtual ~GlobalLinSys() {}
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(
92  const std::shared_ptr<AssemblyMap>& pLocToGloMap);
93 
94  /// Solve the linear system for given input and output vectors
95  /// using a specified local to global map.
97  inline void Solve(
100  const AssemblyMapSharedPtr &locToGloMap,
101  const Array<OneD, const NekDouble> &dirForcing
103 
104  /// Returns a shared pointer to the current object.
105  std::shared_ptr<GlobalLinSys> GetSharedThisPtr()
106  {
107  return shared_from_this();
108  }
109 
110  inline int GetNumBlocks ();
111  inline DNekScalMatSharedPtr GetBlock (unsigned int n);
112  inline DNekScalBlkMatSharedPtr GetStaticCondBlock(unsigned int n);
113  inline void DropStaticCondBlock(unsigned int n);
114 
115  /// Solve the linear system for given input and output vectors.
116  inline void SolveLinearSystem(
117  const int pNumRows,
118  const Array<OneD,const NekDouble> &pInput,
119  Array<OneD, NekDouble> &pOutput,
120  const AssemblyMapSharedPtr &locToGloMap,
121  const int pNumDir = 0);
122 
123  protected:
124  /// Key associated with this linear system.
125  const GlobalLinSysKey m_linSysKey;
126  /// Local Matrix System
127  const std::weak_ptr<ExpList> m_expList;
128  /// Robin boundary info
129  const std::map<int, RobinBCInfoSharedPtr> m_robinBCInfo;
130  // Provide verbose output
131  bool m_verbose;
132 
133  virtual int v_GetNumBlocks ();
134  virtual DNekScalMatSharedPtr v_GetBlock (unsigned int n);
135  virtual DNekScalBlkMatSharedPtr v_GetStaticCondBlock(unsigned int n);
136  virtual void v_DropStaticCondBlock(unsigned int n);
137 
138  PreconditionerSharedPtr CreatePrecon(AssemblyMapSharedPtr asmMap);
139 
140  private:
142 
143  /// Solve a linear system based on mapping.
144  virtual void v_Solve(
147  const AssemblyMapSharedPtr &locToGloMap,
148  const Array<OneD, const NekDouble> &dirForcing
149  = NullNekDouble1DArray) = 0;
150 
151  /// Solve a basic matrix system.
152  virtual void v_SolveLinearSystem(
153  const int pNumRows,
154  const Array<OneD,const NekDouble> &pInput,
155  Array<OneD, NekDouble> &pOutput,
156  const AssemblyMapSharedPtr &locToGloMap,
157  const int pNumDir) = 0;
158 
159  virtual void v_InitObject();
160  virtual void v_Initialise(
161  const std::shared_ptr<AssemblyMap>& pLocToGloMap);
162 
163  static std::string lookupIds[];
164  static std::string def;
165  };
166 
167 
168  /**
169  *
170  */
171  const inline GlobalLinSysKey &GlobalLinSys::GetKey(void) const
172  {
173  return m_linSysKey;
174  }
175 
176  /**
177  *
178  */
179  const inline std::weak_ptr<ExpList> &GlobalLinSys::GetLocMat(void) const
180  {
181  return m_expList;
182  }
183 
184 
185  /**
186  *
187  */
188  inline void GlobalLinSys::Solve(
191  const AssemblyMapSharedPtr &locToGloMap,
192  const Array<OneD, const NekDouble> &dirForcing)
193  {
194  v_Solve(in,out,locToGloMap,dirForcing);
195  }
196 
197 
198  /**
199  *
200  */
202  const int pNumRows,
203  const Array<OneD,const NekDouble> &pInput,
204  Array<OneD, NekDouble> &pOutput,
205  const AssemblyMapSharedPtr &locToGloMap,
206  const int pNumDir)
207  {
208  v_SolveLinearSystem(pNumRows, pInput, pOutput, locToGloMap, pNumDir);
209  }
210 
212  {
213  v_InitObject();
214  }
215 
217  const std::shared_ptr<AssemblyMap>& pLocToGloMap)
218  {
219  v_Initialise(pLocToGloMap);
220  }
221 
223  {
224  return v_GetBlock(n);
225  }
226 
228  {
229  return v_GetStaticCondBlock(n);
230  }
231 
232  inline void GlobalLinSys::DropStaticCondBlock(unsigned int n)
233  {
234  return v_DropStaticCondBlock(n);
235  }
236 
238  {
239  return v_GetNumBlocks();
240  }
241  } //end of namespace
242 } //end of namespace
243 
244 #endif
std::map< GlobalLinSysKey, GlobalLinSysSharedPtr > GlobalLinSysMap
Mapping between GlobalLinSys objects and their associated keys.
Definition: GlobalLinSys.h:55
static Array< OneD, NekDouble > NullNekDouble1DArray
std::shared_ptr< DNekScalMat > DNekScalMatSharedPtr
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.
std::shared_ptr< DNekScalBlkMat > DNekScalBlkMatSharedPtr
Definition: NekTypeDefs.hpp:73
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:201
#define MULTI_REGIONS_EXPORT
std::shared_ptr< GlobalLinSys > GlobalLinSysSharedPtr
Pointer to a GlobalLinSys object.
Definition: GlobalLinSys.h:50
void DropStaticCondBlock(unsigned int n)
Definition: GlobalLinSys.h:232
const GlobalLinSysKey & GetKey(void) const
Returns the key associated with the system.
Definition: GlobalLinSys.h:171
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
virtual DNekScalBlkMatSharedPtr v_GetStaticCondBlock(unsigned int n)
Retrieves a the static condensation block matrices from n-th expansion using the matrix key provided ...
std::shared_ptr< AssemblyMap > AssemblyMapSharedPtr
Definition: AssemblyMap.h:52
DNekScalMatSharedPtr GetBlock(unsigned int n)
Definition: GlobalLinSys.h:222
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.
virtual DNekScalMatSharedPtr v_GetBlock(unsigned int n)
Retrieves the block matrix from n-th expansion using the matrix key provided by the m_linSysKey...
std::shared_ptr< GlobalLinSysMap > GlobalLinSysMapShPtr
Pointer to a GlobalLinSys/key map.
Definition: GlobalLinSys.h:57
virtual int v_GetNumBlocks()
Get the number of blocks in this system.
virtual void v_Initialise(const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Describe a linear system.
std::shared_ptr< GlobalLinSys > GetSharedThisPtr()
Returns a shared pointer to the current object.
Definition: GlobalLinSys.h:105
const std::weak_ptr< ExpList > & GetLocMat(void) const
Definition: GlobalLinSys.h:179
const GlobalLinSysKey m_linSysKey
Key associated with this linear system.
Definition: GlobalLinSys.h:125
LocalRegions::MatrixKey GetBlockMatrixKey(unsigned int n)
A global linear system.
Definition: GlobalLinSys.h:72
const std::weak_ptr< ExpList > m_expList
Local Matrix System.
Definition: GlobalLinSys.h:127
virtual void v_DropStaticCondBlock(unsigned int n)
Releases the static condensation block matrices from NekManager of n-th expansion using the matrix ke...
static std::string lookupIds[]
Definition: GlobalLinSys.h:163
DNekScalBlkMatSharedPtr GetStaticCondBlock(unsigned int n)
Definition: GlobalLinSys.h:227
std::shared_ptr< Preconditioner > PreconditionerSharedPtr
Definition: GlobalLinSys.h:60
void Initialise(const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Definition: GlobalLinSys.h:216
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:188
GlobalLinSysFactory & GetGlobalLinSysFactory()
GlobalLinSys(const GlobalLinSysKey &pKey, const std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Constructor for full direct matrix solve.
const std::map< int, RobinBCInfoSharedPtr > m_robinBCInfo
Robin boundary info.
Definition: GlobalLinSys.h:129
PreconditionerSharedPtr CreatePrecon(AssemblyMapSharedPtr asmMap)
Create a preconditioner object from the parameters defined in the supplied assembly map...
Provides a generic Factory class.
Definition: NekFactory.hpp:103