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