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