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