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;
52 
53  /// Pointer to a GlobalLinSys object.
54  typedef boost::shared_ptr<GlobalLinSys> GlobalLinSysSharedPtr;
55  /// Mapping between GlobalLinSys objects and their associated keys.
56  typedef map<GlobalLinSysKey,GlobalLinSysSharedPtr> GlobalLinSysMap;
57  /// Pointer to a GlobalLinSys/key map.
58  typedef boost::shared_ptr<GlobalLinSysMap> GlobalLinSysMapShPtr;
59 
60  /// Datatype of the NekFactory used to instantiate classes derived from
61  /// the EquationSystem class.
62  typedef LibUtilities::NekFactory< std::string, GlobalLinSys,
63  const GlobalLinSysKey&,
64  const boost::weak_ptr<ExpList>&,
65  const boost::shared_ptr<AssemblyMap>& > GlobalLinSysFactory;
67 
68 
69  /// A global linear system.
70  class GlobalLinSys: public boost::enable_shared_from_this<GlobalLinSys>
71  {
72  public:
73  /// Constructor for full direct matrix solve.
75  const GlobalLinSysKey &pKey,
76  const boost::weak_ptr<ExpList> &pExpList,
77  const boost::shared_ptr<AssemblyMap> &pLocToGloMap);
78 
80  virtual ~GlobalLinSys() {}
81 
82  /// Returns the key associated with the system.
83  const inline GlobalLinSysKey &GetKey(void) const;
84 
85  //Returns the local matrix associated with the system
86  const inline boost::weak_ptr<ExpList> &GetLocMat(void) const;
87 
88  inline void InitObject();
89  inline void Initialise(
90  const boost::shared_ptr<AssemblyMap>& pLocToGloMap);
91 
92  /// Solve the linear system for given input and output vectors
93  /// using a specified local to global map.
95  inline void Solve(
96  const Array<OneD, const NekDouble> &in,
97  Array<OneD, NekDouble> &out,
98  const AssemblyMapSharedPtr &locToGloMap,
99  const Array<OneD, const NekDouble> &dirForcing
101 
102  /// Returns a shared pointer to the current object.
103  boost::shared_ptr<GlobalLinSys> GetSharedThisPtr()
104  {
105  return shared_from_this();
106  }
107 
108  inline int GetNumBlocks ();
109  inline DNekScalMatSharedPtr GetBlock (unsigned int n);
110  inline DNekScalBlkMatSharedPtr GetStaticCondBlock(unsigned int n);
111  inline void DropStaticCondBlock(unsigned int n);
112 
113  /// Solve the linear system for given input and output vectors.
114  inline void SolveLinearSystem(
115  const int pNumRows,
116  const Array<OneD,const NekDouble> &pInput,
117  Array<OneD, NekDouble> &pOutput,
118  const AssemblyMapSharedPtr &locToGloMap,
119  const int pNumDir = 0);
120 
121  protected:
122  /// Key associated with this linear system.
124  /// Local Matrix System
125  const boost::weak_ptr<ExpList> m_expList;
126  /// Robin boundary info
127  const map<int, RobinBCInfoSharedPtr> m_robinBCInfo;
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 
134  private:
135  /// Solve a linear system based on mapping.
136  virtual void v_Solve(
137  const Array<OneD, const NekDouble> &in,
138  Array<OneD, NekDouble> &out,
139  const AssemblyMapSharedPtr &locToGloMap,
140  const Array<OneD, const NekDouble> &dirForcing
141  = NullNekDouble1DArray) = 0;
142 
143  /// Solve a basic matrix system.
144  virtual void v_SolveLinearSystem(
145  const int pNumRows,
146  const Array<OneD,const NekDouble> &pInput,
147  Array<OneD, NekDouble> &pOutput,
148  const AssemblyMapSharedPtr &locToGloMap,
149  const int pNumDir) = 0;
150 
151  virtual void v_InitObject();
152  virtual void v_Initialise(
153  const boost::shared_ptr<AssemblyMap>& pLocToGloMap);
154 
155  static std::string lookupIds[];
156  static std::string def;
157  };
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 boost::weak_ptr<ExpList> &GlobalLinSys::GetLocMat(void) const
172  {
173  return m_expList;
174  }
175 
176 
177  /**
178  *
179  */
180  inline void GlobalLinSys::Solve(
181  const Array<OneD, const NekDouble> &in,
182  Array<OneD, NekDouble> &out,
183  const AssemblyMapSharedPtr &locToGloMap,
184  const Array<OneD, const NekDouble> &dirForcing)
185  {
186  v_Solve(in,out,locToGloMap,dirForcing);
187  }
188 
189 
190  /**
191  *
192  */
194  const int pNumRows,
195  const Array<OneD,const NekDouble> &pInput,
196  Array<OneD, NekDouble> &pOutput,
197  const AssemblyMapSharedPtr &locToGloMap,
198  const int pNumDir)
199  {
200  v_SolveLinearSystem(pNumRows, pInput, pOutput, locToGloMap, pNumDir);
201  }
202 
204  {
205  v_InitObject();
206  }
207 
209  const boost::shared_ptr<AssemblyMap>& pLocToGloMap)
210  {
211  v_Initialise(pLocToGloMap);
212  }
213 
215  {
216  return v_GetBlock(n);
217  }
218 
220  {
221  return v_GetStaticCondBlock(n);
222  }
223 
224  inline void GlobalLinSys::DropStaticCondBlock(unsigned int n)
225  {
226  return v_DropStaticCondBlock(n);
227  }
228 
230  {
231  return v_GetNumBlocks();
232  }
233  } //end of namespace
234 } //end of namespace
235 
236 #endif