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