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  {
58  const BasisKey &rhs) const;
59  };
60 
61  /// Constructor
62  BasisKey(const BasisType btype, const int nummodes, const PointsKey pkey)
63  : m_nummodes(nummodes), m_basistype(btype), m_pointsKey(pkey)
64  {
65  }
66 
67  /// Copy constructor
68  BasisKey(const BasisKey &B)
71  {
72  }
73 
74  /// Destructor
76  {
77  }
78 
79  /// Assignment operator
80  BasisKey &operator=(const BasisKey &) = default;
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 =
107  m_nummodes * (m_nummodes + 1) * (2 * m_nummodes + 1) / 6;
108  break;
109  case eOrtho_A:
110  case eModified_A:
111  case eFourier:
112  case eGLL_Lagrange:
113  case eGauss_Lagrange:
114  case eLegendre:
115  case eChebyshev:
116  case eMonomial:
117  case eFourierSingleMode:
118  case eFourierHalfModeRe:
119  case eFourierHalfModeIm:
120  value = m_nummodes;
121  break;
122 
123  default:
124  NEKERROR(ErrorUtil::efatal, "Unknown basis being used");
125  }
126  return value;
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) && (x.m_basistype == m_basistype));
168  }
169 
170  /// Determine if basis has exact integration for inner product.
171  LIB_UTILITIES_EXPORT bool ExactIprodInt() const;
172 
173  /// Determine if basis has collocation properties.
174  LIB_UTILITIES_EXPORT bool Collocation() const;
175 
176  /// Overloaded Operators
177  LIB_UTILITIES_EXPORT friend bool operator==(const BasisKey &x,
178  const BasisKey &y);
179  LIB_UTILITIES_EXPORT friend bool operator==(const BasisKey *x,
180  const BasisKey &y);
181  LIB_UTILITIES_EXPORT friend bool operator==(const BasisKey &x,
182  const BasisKey *y);
183  LIB_UTILITIES_EXPORT friend bool operator!=(const BasisKey &x,
184  const BasisKey &y);
185  LIB_UTILITIES_EXPORT friend bool operator!=(const BasisKey *x,
186  const BasisKey &y);
187  LIB_UTILITIES_EXPORT friend bool operator!=(const BasisKey &x,
188  const BasisKey *y);
189 
190  LIB_UTILITIES_EXPORT friend bool operator<(const BasisKey &lhs,
191  const BasisKey &rhs);
193  const BasisKey &lhs, const BasisKey &rhs) const;
194 
195 protected:
196  unsigned int m_nummodes; ///< Expansion order.
197  BasisType m_basistype; ///< Expansion type.
198  PointsKey m_pointsKey; ///< Points specification.
199 
200 private:
202  {
204  "Default Constructor BasisKey should never be called");
205  }
206 };
207 
208 /// Defines a null basis with no type or points.
210 
211 /// Represents a basis of a given type.
212 class Basis
213 {
214 public:
215  /// Returns a new instance of a Basis with given BasisKey.
216  static std::shared_ptr<Basis> Create(const BasisKey &bkey);
217 
218  /// Destructor.
219  virtual ~Basis(){};
220 
221  /// Return order of basis from the basis specification.
222  inline int GetNumModes() const
223  {
224  return m_basisKey.GetNumModes();
225  }
226 
227  /// Return total number of modes from the basis specification.
228  inline int GetTotNumModes() const
229  {
230  return m_basisKey.GetTotNumModes();
231  }
232 
233  /// Return the number of points from the basis specification.
234  inline int GetNumPoints() const
235  {
236  return m_basisKey.GetNumPoints();
237  }
238 
239  /// Return total number of points from the basis specification.
240  inline int GetTotNumPoints() const
241  {
242  return m_basisKey.GetTotNumPoints();
243  }
244 
245  /// Return the type of expansion basis.
246  inline BasisType GetBasisType() const
247  {
248  return m_basisKey.GetBasisType();
249  }
250 
251  /// Return the points specification for the basis.
252  inline PointsKey GetPointsKey() const
253  {
254  return m_basisKey.GetPointsKey();
255  }
256 
257  /// Return the type of quadrature.
258  inline PointsType GetPointsType() const
259  {
260  return m_basisKey.GetPointsType();
261  }
262 
263  inline const Array<OneD, const NekDouble> &GetZ() const
264  {
265  return m_points->GetZ();
266  }
267 
268  inline const Array<OneD, const NekDouble> &GetW() const
269  {
270  return m_points->GetW();
271  }
272 
275  {
276  m_points->GetZW(z, w);
277  }
278 
280  {
281  return m_points->GetBaryWeights();
282  }
283 
284  inline const std::shared_ptr<NekMatrix<NekDouble>> &GetD(
285  Direction dir = xDir) const
286  {
287  return m_points->GetD(dir);
288  }
289 
290  const std::shared_ptr<NekMatrix<NekDouble>> GetI(
292  {
293  return m_points->GetI(x);
294  }
295 
296  const std::shared_ptr<NekMatrix<NekDouble>> GetI(const BasisKey &bkey)
297  {
298  ASSERTL0(bkey.GetPointsKey().GetPointsDim() == 1,
299  "Interpolation only to other 1d basis");
300  return m_InterpManager[bkey];
301  }
302 
303  /// Determine if basis has exact integration for inner product.
304  inline bool ExactIprodInt() const
305  {
306  return m_basisKey.ExactIprodInt();
307  }
308 
309  /// Determine if basis has collocation properties.
310  inline bool Collocation() const
311  {
312  return m_basisKey.Collocation();
313  }
314 
315  /// Return basis definition array m_bdata.
317  {
318  return m_bdata;
319  }
320 
321  /// Return basis definition array m_dbdata.
323  {
324  return m_dbdata;
325  }
326 
327  /// Returns the specification for the Basis.
328  inline const BasisKey GetBasisKey() const
329  {
330  return m_basisKey;
331  }
332 
334 
335 protected:
336  BasisKey m_basisKey; ///< Basis specification.
337  PointsSharedPtr m_points; ///< Set of points.
338  Array<OneD, NekDouble> m_bdata; ///< Basis definition.
339  Array<OneD, NekDouble> m_dbdata; ///< Derivative Basis definition.
342 
343 private:
344  static bool initBasisManager[];
345 
346  /// Private constructor with BasisKey.
347  Basis(const BasisKey &bkey);
348 
349  /// Private default constructor.
351  {
353  "Default Constructor for Basis should not be called");
354  }
355 
356  std::shared_ptr<NekMatrix<NekDouble>> CalculateInterpMatrix(
357  const BasisKey &tbasis0);
358 
359  /// Generate appropriate basis and their derivatives.
360  void GenBasis();
361 };
362 
363 LIB_UTILITIES_EXPORT bool operator<(const BasisKey &lhs, const BasisKey &rhs);
364 LIB_UTILITIES_EXPORT bool operator>(const BasisKey &lhs, const BasisKey &rhs);
365 
366 LIB_UTILITIES_EXPORT std::ostream &operator<<(std::ostream &os,
367  const BasisKey &rhs);
368 
371 
372 } // end of namespace LibUtilities
373 } // end of namespace Nektar
374 
375 #endif // NEKTAR_LIB_UTILIITIES_FOUNDATIONS_BASIS_H
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
#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:213
const std::shared_ptr< NekMatrix< NekDouble > > GetI(const Array< OneD, const NekDouble > &x)
Definition: Basis.h:290
int GetNumModes() const
Return order of basis from the basis specification.
Definition: Basis.h:222
Array< OneD, NekDouble > m_dbdata
Derivative Basis definition.
Definition: Basis.h:339
int GetTotNumModes() const
Return total number of modes from the basis specification.
Definition: Basis.h:228
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:316
PointsKey GetPointsKey() const
Return the points specification for the basis.
Definition: Basis.h:252
bool Collocation() const
Determine if basis has collocation properties.
Definition: Basis.h:310
const std::shared_ptr< NekMatrix< NekDouble > > GetI(const BasisKey &bkey)
Definition: Basis.h:296
PointsSharedPtr m_points
Set of points.
Definition: Basis.h:337
int GetTotNumPoints() const
Return total number of points from the basis specification.
Definition: Basis.h:240
const Array< OneD, const NekDouble > & GetZ() const
Definition: Basis.h:263
const Array< OneD, const NekDouble > & GetW() const
Definition: Basis.h:268
PointsType GetPointsType() const
Return the type of quadrature.
Definition: Basis.h:258
void GetZW(Array< OneD, const NekDouble > &z, Array< OneD, const NekDouble > &w) const
Definition: Basis.h:273
BasisKey m_basisKey
Basis specification.
Definition: Basis.h:336
const BasisKey GetBasisKey() const
Returns the specification for the Basis.
Definition: Basis.h:328
static bool initBasisManager[]
Definition: Basis.h:344
Basis()
Private default constructor.
Definition: Basis.h:350
BasisType GetBasisType() const
Return the type of expansion basis.
Definition: Basis.h:246
const std::shared_ptr< NekMatrix< NekDouble > > & GetD(Direction dir=xDir) const
Definition: Basis.h:284
int GetNumPoints() const
Return the number of points from the basis specification.
Definition: Basis.h:234
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:304
const Array< OneD, const NekDouble > & GetDbdata() const
Return basis definition array m_dbdata.
Definition: Basis.h:322
NekManager< BasisKey, NekMatrix< NekDouble >, BasisKey::opLess > m_InterpManager
Definition: Basis.h:341
virtual ~Basis()
Destructor.
Definition: Basis.h:219
const Array< OneD, const NekDouble > & GetBaryWeights() const
Definition: Basis.h:279
void GenBasis()
Generate appropriate basis and their derivatives.
Array< OneD, NekDouble > m_bdata
Basis definition.
Definition: Basis.h:338
Describes the specification for a Basis.
Definition: Basis.h:50
unsigned int m_nummodes
Expansion order.
Definition: Basis.h:196
BasisKey(const BasisKey &B)
Copy constructor.
Definition: Basis.h:68
BasisKey(const BasisType btype, const int nummodes, const PointsKey pkey)
Constructor.
Definition: Basis.h:62
int GetNumPoints() const
Return points order at which basis is defined.
Definition: Basis.h:130
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:198
BasisType GetBasisType() const
Return type of expansion basis.
Definition: Basis.h:141
bool SameExp(const BasisKey &x) const
Determine if basis expansion x matches this.
Definition: Basis.h:165
friend bool operator!=(const BasisKey &x, const BasisKey &y)
PointsKey GetPointsKey() const
Return distribution of points.
Definition: Basis.h:147
bool SamePoints(const BasisKey &x) const
Determine if quadrature of expansion x matches this.
Definition: Basis.h:159
int GetTotNumPoints() const
Definition: Basis.h:135
int GetTotNumModes() const
Definition: Basis.h:89
BasisKey & operator=(const BasisKey &)=default
Assignment operator.
int GetNumModes() const
Returns the order of the basis.
Definition: Basis.h:83
PointsType GetPointsType() const
Return type of quadrature.
Definition: Basis.h:153
BasisType m_basistype
Expansion type.
Definition: Basis.h:197
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:75
Defines a specification for a set of points.
Definition: Points.h:59
unsigned int GetTotNumPoints() const
Definition: Points.h:177
PointsType GetPointsType() const
Definition: Points.h:109
unsigned int GetPointsDim() const
Definition: Points.h:147
unsigned int GetNumPoints() const
Definition: Points.h:104
static BasisSharedPtr NullBasisSharedPtr
Definition: Basis.h:369
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:370
@ eModified_B
Principle Modified Functions .
Definition: BasisType.h:51
@ eGauss_Lagrange
Lagrange Polynomials using the Gauss points.
Definition: BasisType.h:59
@ eOrtho_A
Principle Orthogonal Functions .
Definition: BasisType.h:44
@ eModified_C
Principle Modified Functions .
Definition: BasisType.h:52
@ eGLL_Lagrange
Lagrange for SEM basis .
Definition: BasisType.h:58
@ eFourierSingleMode
Fourier ModifiedExpansion with just the first mode .
Definition: BasisType.h:66
@ eChebyshev
Chebyshev Polynomials.
Definition: BasisType.h:63
@ eOrtho_C
Principle Orthogonal Functions .
Definition: BasisType.h:48
@ eModifiedPyr_C
Principle Modified Functions.
Definition: BasisType.h:55
@ eOrtho_B
Principle Orthogonal Functions .
Definition: BasisType.h:46
@ eModified_A
Principle Modified Functions .
Definition: BasisType.h:50
@ eFourierHalfModeIm
Fourier Modified expansions with just the imaginary part of the first mode .
Definition: BasisType.h:70
@ eFourierHalfModeRe
Fourier Modified expansions with just the real part of the first mode .
Definition: BasisType.h:68
@ eOrthoPyr_C
Principle Orthogonal Functions .
Definition: BasisType.h:53
@ eFourier
Fourier Expansion .
Definition: BasisType.h:57
static const PointsKey NullPointsKey(0, eNoPointsType)
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
bool operator()(const BasisKey &lhs, const BasisKey &rhs) const