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);
189  LIB_UTILITIES_EXPORT friend bool opLess::operator()( const BasisKey &lhs,
190  const BasisKey &rhs) const;
191 
192  protected:
193  int m_nummodes; ///< Expansion order.
194  BasisType m_basistype; ///< Expansion type.
195  PointsKey m_pointsKey; ///< Points specification.
196 
197  private:
198  BasisKey():m_pointsKey(NullPointsKey)
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 
280  inline const std::shared_ptr<NekMatrix<NekDouble> > & GetD(
281  Direction dir = xDir) const
282  {
283  return m_points->GetD(dir);
284  }
285 
286  const std::shared_ptr<NekMatrix<NekDouble> > GetI(
288  {
289  return m_points->GetI(x);
290  }
291 
292  const std::shared_ptr<NekMatrix<NekDouble> > GetI(
293  const BasisKey &bkey)
294  {
295  ASSERTL0(bkey.GetPointsKey().GetPointsDim()==1,
296  "Interpolation only to other 1d basis");
297  return m_InterpManager[bkey];
298  }
299 
300  /// Determine if basis has exact integration for inner product.
301  inline bool ExactIprodInt() const
302  {
303  return m_basisKey.ExactIprodInt();
304  }
305 
306  /// Determine if basis has collocation properties.
307  inline bool Collocation() const
308  {
309  return m_basisKey.Collocation();
310  }
311 
312  /// Return basis definition array m_bdata.
314  {
315  return m_bdata;
316  }
317 
318  /// Return basis definition array m_dbdata.
320  {
321  return m_dbdata;
322  }
323 
324  /// Returns the specification for the Basis.
325  inline const BasisKey GetBasisKey() const
326  {
327  return m_basisKey;
328  }
329 
330  LIB_UTILITIES_EXPORT virtual void Initialize();
331 
332  protected:
333  BasisKey m_basisKey; ///< Basis specification.
334  PointsSharedPtr m_points; ///< Set of points.
335  Array<OneD, NekDouble> m_bdata; ///< Basis definition.
336  Array<OneD, NekDouble> m_dbdata; ///< Derivative Basis definition.
339 
340  private:
341  static bool initBasisManager[];
342 
343  /// Private constructor with BasisKey.
344  Basis(const BasisKey &bkey);
345 
346  /// Private default constructor.
347  Basis():m_basisKey(NullBasisKey)
348  {
350  "Default Constructor for Basis should not be called");
351  }
352 
353  std::shared_ptr< NekMatrix<NekDouble> > CalculateInterpMatrix(
354  const BasisKey &tbasis0);
355 
356  /// Generate appropriate basis and their derivatives.
357  void GenBasis();
358  };
359 
360  LIB_UTILITIES_EXPORT bool operator<(const BasisKey &lhs, const BasisKey &rhs);
361  LIB_UTILITIES_EXPORT bool operator>(const BasisKey &lhs, const BasisKey &rhs);
362 
363  LIB_UTILITIES_EXPORT std::ostream& operator<<(std::ostream& os, const BasisKey& rhs);
364 
367 
368  } // end of namespace LibUtilities
369 } // end of namespace Nektar
370 
371 #endif //NEKTAR_LIB_UTILIITIES_FOUNDATIONS_BASIS_H
372 
373 
int GetNumPoints() const
Return points order at which basis is defined.
Definition: Basis.h:133
virtual ~Basis()
Destructor.
Definition: Basis.h:218
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:235
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:333
PointsType GetPointsType() const
Definition: Points.h:112
Represents a basis of a given type.
Definition: Basis.h:211
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:241
BasisKey & operator=(const BasisKey &)=default
Assignment operator.
Array< OneD, NekDouble > m_bdata
Basis definition.
Definition: Basis.h:335
BasisType GetBasisType() const
Return type of expansion basis.
Definition: Basis.h:144
bool Collocation() const
Determine if basis has collocation properties.
Principle Modified Functions .
Definition: BasisType.h:48
static BasisSharedPtr NullBasisSharedPtr
Definition: Basis.h:365
~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:274
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:162
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:223
PointsType GetPointsType() const
Return the type of quadrature.
Definition: Basis.h:259
PointsKey GetPointsKey() const
Return distribution of points.
Definition: Basis.h:150
BasisType m_basistype
Expansion type.
Definition: Basis.h:194
PointsKey m_pointsKey
Points specification.
Definition: Basis.h:195
const Array< OneD, const NekDouble > & GetBdata() const
Return basis definition array m_bdata.
Definition: Basis.h:313
BasisType GetBasisType() const
Return the type of expansion basis.
Definition: Basis.h:247
StandardMatrixTag & lhs
const Array< OneD, const NekDouble > & GetW() const
Definition: Basis.h:269
int GetTotNumModes() const
Definition: Basis.h:92
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:336
bool operator()(const BasisKey &lhs, const BasisKey &rhs) const
int GetNumModes() const
Returns the order of the basis.
Definition: Basis.h:86
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:156
PointsSharedPtr m_points
Set of points.
Definition: Basis.h:334
const BasisKey GetBasisKey() const
Returns the specification for the Basis.
Definition: Basis.h:325
int m_nummodes
Expansion order.
Definition: Basis.h:193
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:138
const std::shared_ptr< NekMatrix< NekDouble > > & GetD(Direction dir=xDir) const
Definition: Basis.h:280
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:319
BasisKey(const BasisKey &B)
Copy constructor.
Definition: Basis.h:70
bool Collocation() const
Determine if basis has collocation properties.
Definition: Basis.h:307
Basis()
Private default constructor.
Definition: Basis.h:347
static Array< OneD, BasisSharedPtr > NullBasisSharedPtr1DArray
Definition: Basis.h:366
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:286
Legendre Polynomials . Same as Ortho_A.
Definition: BasisType.h:56
PointsKey GetPointsKey() const
Return the points specification for the basis.
Definition: Basis.h:253
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:338
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:301
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:168
Monomial polynomials .
Definition: BasisType.h:58
int GetTotNumModes() const
Return total number of modes from the basis specification.
Definition: Basis.h:229
const Array< OneD, const NekDouble > & GetZ() const
Definition: Basis.h:264
const std::shared_ptr< NekMatrix< NekDouble > > GetI(const BasisKey &bkey)
Definition: Basis.h:292