Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: GlobalLinSys header
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 #ifndef NEKTAR_LIB_MULTIREGIONS_GLOBALLINSYS_H
36 #define NEKTAR_LIB_MULTIREGIONS_GLOBALLINSYS_H
37 
41 #include <boost/enable_shared_from_this.hpp>
42 #include <MultiRegions/ExpList.h>
44 
45 namespace Nektar
46 {
47  namespace MultiRegions
48  {
49  // Forward declarations
50  class ExpList;
51  class GlobalLinSys;
53 
54  /// Pointer to a GlobalLinSys object.
55  typedef boost::shared_ptr<GlobalLinSys> GlobalLinSysSharedPtr;
56  /// Mapping between GlobalLinSys objects and their associated keys.
57  typedef std::map<GlobalLinSysKey,GlobalLinSysSharedPtr> GlobalLinSysMap;
58  /// Pointer to a GlobalLinSys/key map.
59  typedef boost::shared_ptr<GlobalLinSysMap> GlobalLinSysMapShPtr;
60 
61  // Forward declaration
62  typedef boost::shared_ptr<Preconditioner> PreconditionerSharedPtr;
63 
64  /// Datatype of the NekFactory used to instantiate classes derived from
65  /// the EquationSystem class.
66  typedef LibUtilities::NekFactory< std::string, GlobalLinSys,
67  const GlobalLinSysKey&,
68  const boost::weak_ptr<ExpList>&,
69  const boost::shared_ptr<AssemblyMap>& > GlobalLinSysFactory;
70  GlobalLinSysFactory& GetGlobalLinSysFactory();
71 
72 
73  /// A global linear system.
74  class GlobalLinSys: public boost::enable_shared_from_this<GlobalLinSys>
75  {
76  public:
77  /// Constructor for full direct matrix solve.
79  const GlobalLinSysKey &pKey,
80  const boost::weak_ptr<ExpList> &pExpList,
81  const boost::shared_ptr<AssemblyMap> &pLocToGloMap);
82 
84  virtual ~GlobalLinSys() {}
85 
86  /// Returns the key associated with the system.
87  const inline GlobalLinSysKey &GetKey(void) const;
88 
89  //Returns the local matrix associated with the system
90  const inline boost::weak_ptr<ExpList> &GetLocMat(void) const;
91 
92  inline void InitObject();
93  inline void Initialise(
94  const boost::shared_ptr<AssemblyMap>& pLocToGloMap);
95 
96  /// Solve the linear system for given input and output vectors
97  /// using a specified local to global map.
99  inline void Solve(
102  const AssemblyMapSharedPtr &locToGloMap,
103  const Array<OneD, const NekDouble> &dirForcing
105 
106  /// Returns a shared pointer to the current object.
107  boost::shared_ptr<GlobalLinSys> GetSharedThisPtr()
108  {
109  return shared_from_this();
110  }
111 
112  inline int GetNumBlocks ();
113  inline DNekScalMatSharedPtr GetBlock (unsigned int n);
114  inline DNekScalBlkMatSharedPtr GetStaticCondBlock(unsigned int n);
115  inline void DropStaticCondBlock(unsigned int n);
116 
117  /// Solve the linear system for given input and output vectors.
118  inline void SolveLinearSystem(
119  const int pNumRows,
120  const Array<OneD,const NekDouble> &pInput,
121  Array<OneD, NekDouble> &pOutput,
122  const AssemblyMapSharedPtr &locToGloMap,
123  const int pNumDir = 0);
124 
125  protected:
126  /// Key associated with this linear system.
127  const GlobalLinSysKey m_linSysKey;
128  /// Local Matrix System
129  const boost::weak_ptr<ExpList> m_expList;
130  /// Robin boundary info
131  const std::map<int, RobinBCInfoSharedPtr> m_robinBCInfo;
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:
141  /// Solve a linear system based on mapping.
142  virtual void v_Solve(
145  const AssemblyMapSharedPtr &locToGloMap,
146  const Array<OneD, const NekDouble> &dirForcing
147  = NullNekDouble1DArray) = 0;
148 
149  /// Solve a basic matrix system.
150  virtual void v_SolveLinearSystem(
151  const int pNumRows,
152  const Array<OneD,const NekDouble> &pInput,
153  Array<OneD, NekDouble> &pOutput,
154  const AssemblyMapSharedPtr &locToGloMap,
155  const int pNumDir) = 0;
156 
157  virtual void v_InitObject();
158  virtual void v_Initialise(
159  const boost::shared_ptr<AssemblyMap>& pLocToGloMap);
160 
161  static std::string lookupIds[];
162  static std::string def;
163  };
164 
165 
166  /**
167  *
168  */
169  const inline GlobalLinSysKey &GlobalLinSys::GetKey(void) const
170  {
171  return m_linSysKey;
172  }
173 
174  /**
175  *
176  */
177  const inline boost::weak_ptr<ExpList> &GlobalLinSys::GetLocMat(void) const
178  {
179  return m_expList;
180  }
181 
182 
183  /**
184  *
185  */
186  inline void GlobalLinSys::Solve(
189  const AssemblyMapSharedPtr &locToGloMap,
190  const Array<OneD, const NekDouble> &dirForcing)
191  {
192  v_Solve(in,out,locToGloMap,dirForcing);
193  }
194 
195 
196  /**
197  *
198  */
200  const int pNumRows,
201  const Array<OneD,const NekDouble> &pInput,
202  Array<OneD, NekDouble> &pOutput,
203  const AssemblyMapSharedPtr &locToGloMap,
204  const int pNumDir)
205  {
206  v_SolveLinearSystem(pNumRows, pInput, pOutput, locToGloMap, pNumDir);
207  }
208 
210  {
211  v_InitObject();
212  }
213 
215  const boost::shared_ptr<AssemblyMap>& pLocToGloMap)
216  {
217  v_Initialise(pLocToGloMap);
218  }
219 
221  {
222  return v_GetBlock(n);
223  }
224 
226  {
227  return v_GetStaticCondBlock(n);
228  }
229 
230  inline void GlobalLinSys::DropStaticCondBlock(unsigned int n)
231  {
232  return v_DropStaticCondBlock(n);
233  }
234 
236  {
237  return v_GetNumBlocks();
238  }
239  } //end of namespace
240 } //end of namespace
241 
242 #endif
std::map< GlobalLinSysKey, GlobalLinSysSharedPtr > GlobalLinSysMap
Mapping between GlobalLinSys objects and their associated keys.
Definition: GlobalLinSys.h:57
LibUtilities::NekFactory< std::string, GlobalLinSys, const GlobalLinSysKey &, const boost::weak_ptr< ExpList > &, const boost::shared_ptr< AssemblyMap > & > GlobalLinSysFactory
Datatype of the NekFactory used to instantiate classes derived from the EquationSystem class...
Definition: GlobalLinSys.h:69
const GlobalLinSysKey & GetKey(void) const
Returns the key associated with the system.
Definition: GlobalLinSys.h:169
static Array< OneD, NekDouble > NullNekDouble1DArray
boost::shared_ptr< AssemblyMap > AssemblyMapSharedPtr
Definition: AssemblyMap.h:53
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.
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:199
#define MULTI_REGIONS_EXPORT
boost::shared_ptr< Preconditioner > PreconditionerSharedPtr
Definition: GlobalLinSys.h:62
void DropStaticCondBlock(unsigned int n)
Definition: GlobalLinSys.h:230
void Initialise(const boost::shared_ptr< AssemblyMap > &pLocToGloMap)
Definition: GlobalLinSys.h:214
virtual DNekScalBlkMatSharedPtr v_GetStaticCondBlock(unsigned int n)
Retrieves a the static condensation block matrices from n-th expansion using the matrix key provided ...
boost::shared_ptr< DNekScalMat > DNekScalMatSharedPtr
virtual void v_Initialise(const boost::shared_ptr< AssemblyMap > &pLocToGloMap)
DNekScalMatSharedPtr GetBlock(unsigned int n)
Definition: GlobalLinSys.h:220
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...
boost::shared_ptr< GlobalLinSys > GetSharedThisPtr()
Returns a shared pointer to the current object.
Definition: GlobalLinSys.h:107
boost::shared_ptr< DNekScalBlkMat > DNekScalBlkMatSharedPtr
Definition: NekTypeDefs.hpp:74
boost::shared_ptr< GlobalLinSysMap > GlobalLinSysMapShPtr
Pointer to a GlobalLinSys/key map.
Definition: GlobalLinSys.h:59
virtual int v_GetNumBlocks()
Get the number of blocks in this system.
GlobalLinSys(const GlobalLinSysKey &pKey, const boost::weak_ptr< ExpList > &pExpList, const boost::shared_ptr< AssemblyMap > &pLocToGloMap)
Constructor for full direct matrix solve.
Describe a linear system.
const GlobalLinSysKey m_linSysKey
Key associated with this linear system.
Definition: GlobalLinSys.h:127
A global linear system.
Definition: GlobalLinSys.h:74
virtual void v_DropStaticCondBlock(unsigned int n)
Releases the static condensation block matrices from NekManager of n-th expansion using the matrix ke...
boost::shared_ptr< GlobalLinSys > GlobalLinSysSharedPtr
Pointer to a GlobalLinSys object.
Definition: GlobalLinSys.h:52
static std::string lookupIds[]
Definition: GlobalLinSys.h:161
DNekScalBlkMatSharedPtr GetStaticCondBlock(unsigned int n)
Definition: GlobalLinSys.h:225
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:186
GlobalLinSysFactory & GetGlobalLinSysFactory()
const std::map< int, RobinBCInfoSharedPtr > m_robinBCInfo
Robin boundary info.
Definition: GlobalLinSys.h:131
const boost::weak_ptr< ExpList > & GetLocMat(void) const
Definition: GlobalLinSys.h:177
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:116
const boost::weak_ptr< ExpList > m_expList
Local Matrix System.
Definition: GlobalLinSys.h:129