Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Basis.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File Basis.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: Header file of Basis definition
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef NEKTAR_LIB_UTILIITIES_FOUNDATIONS_BASIS_H
37 #define NEKTAR_LIB_UTILIITIES_FOUNDATIONS_BASIS_H
38 
44 
45 namespace Nektar
46 {
47  namespace LibUtilities
48  {
49  /// Describes the specification for a Basis.
50  class BasisKey
51  {
52  public:
53  // Use for looking up the creator. The creator for number of points
54  // can generate for any number, so we want the same creator called
55  // for all number.
56  struct opLess
57  {
58  LIB_UTILITIES_EXPORT bool operator()(const BasisKey &lhs, const BasisKey &rhs) const;
59  };
60 
61  /// Constructor
62  BasisKey(const BasisType btype, const int nummodes,
63  const PointsKey pkey):
64  m_nummodes(nummodes),
65  m_basistype(btype),
66  m_pointsKey(pkey)
67  {
68  }
69 
70  /// Copy constructor
71  BasisKey(const BasisKey &B):
75  {
76  }
77 
78  /// Destructor
80  {
81  }
82 
83  /// Returns the order of the basis.
84  inline int GetNumModes() const
85  {
86  return m_nummodes;
87  }
88 
89  /// \todo Generalise to arbitrary polynomials
90  inline int GetTotNumModes() const
91  {
92  int value = 0;
93 
94  switch(m_basistype)
95  {
96  case eOrtho_B:
97  case eModified_B:
98  value = m_nummodes*(m_nummodes+1)/2;
99  break;
100 
101  case eModified_C:
102  case eOrtho_C:
103  value = m_nummodes*(m_nummodes+1)*(m_nummodes+2)/6;
104  break;
105 
106  case eOrtho_A:
107  case eModified_A:
108  case eFourier:
109  case eGLL_Lagrange:
110  case eGauss_Lagrange:
111  case eLegendre:
112  case eChebyshev:
113  case eMonomial:
114  case eFourierSingleMode:
115  case eFourierHalfModeRe:
116  case eFourierHalfModeIm:
117  value = m_nummodes;
118  break;
119 
120  default:
121  NEKERROR(ErrorUtil::efatal,"Unknown basis being used");
122  }
123  return value;
124  }
125 
126 
127  /// Return points order at which basis is defined
128  inline int GetNumPoints() const
129  {
130  return m_pointsKey.GetNumPoints();
131  }
132 
133  inline int GetTotNumPoints() const
134  {
135  return m_pointsKey.GetTotNumPoints();
136  }
137 
138  /// Return type of expansion basis.
139  inline BasisType GetBasisType() const
140  {
141  return m_basistype;
142  }
143 
144  /// Return distribution of points.
145  inline PointsKey GetPointsKey() const
146  {
147  return m_pointsKey;
148  }
149 
150  /// Return type of quadrature.
151  inline PointsType GetPointsType() const
152  {
153  return m_pointsKey.GetPointsType();
154  }
155 
156  /// Determine if quadrature of expansion \a x matches this.
157  inline bool SamePoints(const BasisKey &x) const
158  {
159  return (x.m_pointsKey == m_pointsKey);
160  }
161 
162  /// Determine if basis expansion \a x matches this.
163  inline bool SameExp(const BasisKey &x) const
164  {
165  return ((x.m_nummodes == m_nummodes)
166  &&(x.m_basistype == m_basistype));
167  }
168 
169  /// Determine if basis has exact integration for inner product.
170  LIB_UTILITIES_EXPORT bool ExactIprodInt() const;
171 
172  /// Determine if basis has collocation properties.
173  LIB_UTILITIES_EXPORT bool Collocation() const;
174 
175  /// Overloaded Operators
176  LIB_UTILITIES_EXPORT friend bool operator == (const BasisKey& x, const BasisKey& y);
177  LIB_UTILITIES_EXPORT friend bool operator == (const BasisKey* x, const BasisKey& y);
178  LIB_UTILITIES_EXPORT friend bool operator == (const BasisKey& x, const BasisKey *y);
179  LIB_UTILITIES_EXPORT friend bool operator != (const BasisKey& x, const BasisKey& y);
180  LIB_UTILITIES_EXPORT friend bool operator != (const BasisKey* x, const BasisKey& y);
181  LIB_UTILITIES_EXPORT friend bool operator != (const BasisKey& x, const BasisKey *y);
182 
183  LIB_UTILITIES_EXPORT friend bool operator<(const BasisKey &lhs, const BasisKey &rhs);
185  const BasisKey &rhs) const;
186 
187  protected:
188  int m_nummodes; ///< Expansion order.
189  BasisType m_basistype; ///< Expansion type.
190  PointsKey m_pointsKey; ///< Points specification.
191 
192  private:
194  {
196  "Default Constructor BasisKey should never be called");
197  }
198 
199  };
200 
201  /// Defines a null basis with no type or points.
202  static const BasisKey NullBasisKey(eNoBasisType, 0, NullPointsKey);
203 
204 
205  /// Represents a basis of a given type.
206  class Basis
207  {
208  public:
209  /// Returns a new instance of a Basis with given BasisKey.
210  static boost::shared_ptr<Basis> Create(const BasisKey &bkey);
211 
212  /// Destructor.
213  virtual ~Basis()
214  {
215  };
216 
217  /// Return order of basis from the basis specification.
218  inline int GetNumModes() const
219  {
220  return m_basisKey.GetNumModes();
221  }
222 
223  /// Return total number of modes from the basis specification.
224  inline int GetTotNumModes() const
225  {
226  return m_basisKey.GetTotNumModes();
227  }
228 
229  /// Return the number of points from the basis specification.
230  inline int GetNumPoints() const
231  {
232  return m_basisKey.GetNumPoints();
233  }
234 
235  /// Return total number of points from the basis specification.
236  inline int GetTotNumPoints() const
237  {
238  return m_basisKey.GetTotNumPoints();
239  }
240 
241  /// Return the type of expansion basis.
242  inline BasisType GetBasisType() const
243  {
244  return m_basisKey.GetBasisType();
245  }
246 
247  /// Return the points specification for the basis.
248  inline PointsKey GetPointsKey() const
249  {
250  return m_basisKey.GetPointsKey();
251  }
252 
253  /// Return the type of quadrature.
254  inline PointsType GetPointsType() const
255  {
256  return m_basisKey.GetPointsType();
257  }
258 
259  inline const Array<OneD, const NekDouble>& GetZ() const
260  {
261  return m_points->GetZ();
262  }
263 
264  inline const Array<OneD, const NekDouble>& GetW() const
265  {
266  return m_points->GetW();
267  }
268 
269  inline void GetZW(Array<OneD, const NekDouble> &z,
270  Array<OneD, const NekDouble> &w) const
271  {
272  m_points->GetZW(z,w);
273  }
274 
275  inline const boost::shared_ptr<NekMatrix<NekDouble> > & GetD(
276  Direction dir = xDir) const
277  {
278  return m_points->GetD(dir);
279  }
280 
281  const boost::shared_ptr<NekMatrix<NekDouble> > GetI(
282  const Array<OneD, const NekDouble>& x)
283  {
284  return m_points->GetI(x);
285  }
286 
287  const boost::shared_ptr<NekMatrix<NekDouble> > GetI(
288  const BasisKey &bkey)
289  {
290  ASSERTL0(bkey.GetPointsKey().GetPointsDim()==1,
291  "Interpolation only to other 1d basis");
292  return m_InterpManager[bkey];
293  }
294 
295  /// Determine if basis has exact integration for inner product.
296  inline bool ExactIprodInt() const
297  {
298  return m_basisKey.ExactIprodInt();
299  }
300 
301  /// Determine if basis has collocation properties.
302  inline bool Collocation() const
303  {
304  return m_basisKey.Collocation();
305  }
306 
307  /// Return basis definition array m_bdata.
308  inline const Array<OneD, const NekDouble>& GetBdata() const
309  {
310  return m_bdata;
311  }
312 
313  /// Return basis definition array m_dbdata.
314  inline const Array<OneD, const NekDouble>& GetDbdata() const
315  {
316  return m_dbdata;
317  }
318 
319  /// Returns the specification for the Basis.
320  inline const BasisKey GetBasisKey() const
321  {
322  return m_basisKey;
323  }
324 
325  LIB_UTILITIES_EXPORT virtual void Initialize();
326 
327  protected:
328  BasisKey m_basisKey; ///< Basis specification.
329  PointsSharedPtr m_points; ///< Set of points.
330  Array<OneD, NekDouble> m_bdata; ///< Basis definition.
331  Array<OneD, NekDouble> m_dbdata; ///< Derivative Basis definition.
334 
335  private:
336  /// Private constructor with BasisKey.
337  Basis(const BasisKey &bkey);
338 
339  /// Private default constructor.
341  {
343  "Default Constructor for Basis should not be called");
344  }
345 
346  boost::shared_ptr< NekMatrix<NekDouble> > CalculateInterpMatrix(
347  const BasisKey &tbasis0);
348 
349  /// Generate appropriate basis and their derivatives.
350  void GenBasis();
351  };
352 
353  LIB_UTILITIES_EXPORT bool operator<(const BasisKey &lhs, const BasisKey &rhs);
354  LIB_UTILITIES_EXPORT bool operator>(const BasisKey &lhs, const BasisKey &rhs);
355 
356  LIB_UTILITIES_EXPORT std::ostream& operator<<(std::ostream& os, const BasisKey& rhs);
357 
359  static Array<OneD, BasisSharedPtr> NullBasisSharedPtr1DArray;
360 
361  } // end of namespace LibUtilities
362 } // end of namespace Nektar
363 
364 #endif //NEKTAR_LIB_UTILIITIES_FOUNDATIONS_BASIS_H
365 
366