Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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  // Provide verbose output
133  bool m_verbose;
134 
135  virtual int v_GetNumBlocks ();
136  virtual DNekScalMatSharedPtr v_GetBlock (unsigned int n);
137  virtual DNekScalBlkMatSharedPtr v_GetStaticCondBlock(unsigned int n);
138  virtual void v_DropStaticCondBlock(unsigned int n);
139 
140  PreconditionerSharedPtr CreatePrecon(AssemblyMapSharedPtr asmMap);
141 
142  private:
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 boost::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 boost::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 boost::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: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:171
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:201
#define MULTI_REGIONS_EXPORT
boost::shared_ptr< Preconditioner > PreconditionerSharedPtr
Definition: GlobalLinSys.h:62
void DropStaticCondBlock(unsigned int n)
Definition: GlobalLinSys.h:232
void Initialise(const boost::shared_ptr< AssemblyMap > &pLocToGloMap)
Definition: GlobalLinSys.h:216
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: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...
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:163
DNekScalBlkMatSharedPtr GetStaticCondBlock(unsigned int n)
Definition: GlobalLinSys.h:227
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()
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:179
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