Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Header file of Basis definition
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef NEKTAR_LIB_UTILIITIES_FOUNDATIONS_BASIS_H
37 #define NEKTAR_LIB_UTILIITIES_FOUNDATIONS_BASIS_H
38 
44 
45 namespace Nektar
46 {
47  namespace LibUtilities
48  {
49  /// Describes the specification for a Basis.
50  class BasisKey
51  {
52  public:
53  // Use for looking up the creator. The creator for number of points
54  // can generate for any number, so we want the same creator called
55  // for all number.
56  struct opLess
57  {
58  LIB_UTILITIES_EXPORT bool operator()(const BasisKey &lhs, const BasisKey &rhs) const;
59  };
60 
61  /// Constructor
62  BasisKey(const BasisType btype, const int nummodes,
63  const PointsKey pkey):
64  m_nummodes(nummodes),
65  m_basistype(btype),
66  m_pointsKey(pkey)
67  {
68  }
69 
70  /// Copy constructor
71  BasisKey(const BasisKey &B):
75  {
76  }
77 
78  /// Destructor
80  {
81  }
82 
83  /// Returns the order of the basis.
84  inline int GetNumModes() const
85  {
86  return m_nummodes;
87  }
88 
89  /// \todo Generalise to arbitrary polynomials
90  inline int GetTotNumModes() const
91  {
92  int value = 0;
93 
94  switch(m_basistype)
95  {
96  case eOrtho_B:
97  case eModified_B:
98  value = m_nummodes*(m_nummodes+1)/2;
99  break;
100 
101  case eModified_C:
102  case eOrtho_C:
103  value = m_nummodes*(m_nummodes+1)*(m_nummodes+2)/6;
104  break;
105 
106  case eOrtho_A:
107  case eModified_A:
108  case eFourier:
109  case eGLL_Lagrange:
110  case eGauss_Lagrange:
111  case eLegendre:
112  case eChebyshev:
113  case eMonomial:
114  case eFourierSingleMode:
115  case eFourierHalfModeRe:
116  case eFourierHalfModeIm:
117  value = m_nummodes;
118  break;
119 
120  default:
121  NEKERROR(ErrorUtil::efatal,"Unknown basis being used");
122  }
123  return value;
124  }
125 
126 
127  /// Return points order at which basis is defined
128  inline int GetNumPoints() const
129  {
130  return m_pointsKey.GetNumPoints();
131  }
132 
133  inline int GetTotNumPoints() const
134  {
135  return m_pointsKey.GetTotNumPoints();
136  }
137 
138  /// Return type of expansion basis.
139  inline BasisType GetBasisType() const
140  {
141  return m_basistype;
142  }
143 
144  /// Return distribution of points.
145  inline PointsKey GetPointsKey() const
146  {
147  return m_pointsKey;
148  }
149 
150  /// Return type of quadrature.
151  inline PointsType GetPointsType() const
152  {
153  return m_pointsKey.GetPointsType();
154  }
155 
156  /// Determine if quadrature of expansion \a x matches this.
157  inline bool SamePoints(const BasisKey &x) const
158  {
159  return (x.m_pointsKey == m_pointsKey);
160  }
161 
162  /// Determine if basis expansion \a x matches this.
163  inline bool SameExp(const BasisKey &x) const
164  {
165  return ((x.m_nummodes == m_nummodes)
166  &&(x.m_basistype == m_basistype));
167  }
168 
169  /// Determine if basis has exact integration for inner product.
170  LIB_UTILITIES_EXPORT bool ExactIprodInt() const;
171 
172  /// Determine if basis has collocation properties.
173  LIB_UTILITIES_EXPORT bool Collocation() const;
174 
175  /// Overloaded Operators
176  LIB_UTILITIES_EXPORT friend bool operator == (const BasisKey& x, const BasisKey& y);
177  LIB_UTILITIES_EXPORT friend bool operator == (const BasisKey* x, const BasisKey& y);
178  LIB_UTILITIES_EXPORT friend bool operator == (const BasisKey& x, const BasisKey *y);
179  LIB_UTILITIES_EXPORT friend bool operator != (const BasisKey& x, const BasisKey& y);
180  LIB_UTILITIES_EXPORT friend bool operator != (const BasisKey* x, const BasisKey& y);
181  LIB_UTILITIES_EXPORT friend bool operator != (const BasisKey& x, const BasisKey *y);
182 
183  LIB_UTILITIES_EXPORT friend bool operator<(const BasisKey &lhs, const BasisKey &rhs);
185  const BasisKey &rhs) const;
186 
187  protected:
188  int m_nummodes; ///< Expansion order.
189  BasisType m_basistype; ///< Expansion type.
190  PointsKey m_pointsKey; ///< Points specification.
191 
192  private:
193  BasisKey():m_pointsKey(NullPointsKey)
194  {
196  "Default Constructor BasisKey should never be called");
197  }
198 
199  };
200 
201  /// Defines a null basis with no type or points.
202  static const BasisKey NullBasisKey(eNoBasisType, 0, NullPointsKey);
203 
204 
205  /// Represents a basis of a given type.
206  class Basis
207  {
208  public:
209  /// Returns a new instance of a Basis with given BasisKey.
210  static boost::shared_ptr<Basis> Create(const BasisKey &bkey);
211 
212  /// Destructor.
213  virtual ~Basis()
214  {
215  };
216 
217  /// Return order of basis from the basis specification.
218  inline int GetNumModes() const
219  {
220  return m_basisKey.GetNumModes();
221  }
222 
223  /// Return total number of modes from the basis specification.
224  inline int GetTotNumModes() const
225  {
226  return m_basisKey.GetTotNumModes();
227  }
228 
229  /// Return the number of points from the basis specification.
230  inline int GetNumPoints() const
231  {
232  return m_basisKey.GetNumPoints();
233  }
234 
235  /// Return total number of points from the basis specification.
236  inline int GetTotNumPoints() const
237  {
238  return m_basisKey.GetTotNumPoints();
239  }
240 
241  /// Return the type of expansion basis.
242  inline BasisType GetBasisType() const
243  {
244  return m_basisKey.GetBasisType();
245  }
246 
247  /// Return the points specification for the basis.
248  inline PointsKey GetPointsKey() const
249  {
250  return m_basisKey.GetPointsKey();
251  }
252 
253  /// Return the type of quadrature.
254  inline PointsType GetPointsType() const
255  {
256  return m_basisKey.GetPointsType();
257  }
258 
259  inline const Array<OneD, const NekDouble>& GetZ() const
260  {
261  return m_points->GetZ();
262  }
263 
264  inline const Array<OneD, const NekDouble>& GetW() const
265  {
266  return m_points->GetW();
267  }
268 
271  {
272  m_points->GetZW(z,w);
273  }
274 
275  inline const boost::shared_ptr<NekMatrix<NekDouble> > & GetD(
276  Direction dir = xDir) const
277  {
278  return m_points->GetD(dir);
279  }
280 
281  const boost::shared_ptr<NekMatrix<NekDouble> > GetI(
283  {
284  return m_points->GetI(x);
285  }
286 
287  const boost::shared_ptr<NekMatrix<NekDouble> > GetI(
288  const BasisKey &bkey)
289  {
290  ASSERTL0(bkey.GetPointsKey().GetPointsDim()==1,
291  "Interpolation only to other 1d basis");
292  return m_InterpManager[bkey];
293  }
294 
295  /// Determine if basis has exact integration for inner product.
296  inline bool ExactIprodInt() const
297  {
298  return m_basisKey.ExactIprodInt();
299  }
300 
301  /// Determine if basis has collocation properties.
302  inline bool Collocation() const
303  {
304  return m_basisKey.Collocation();
305  }
306 
307  /// Return basis definition array m_bdata.
309  {
310  return m_bdata;
311  }
312 
313  /// Return basis definition array m_dbdata.
315  {
316  return m_dbdata;
317  }
318 
319  /// Returns the specification for the Basis.
320  inline const BasisKey GetBasisKey() const
321  {
322  return m_basisKey;
323  }
324 
325  LIB_UTILITIES_EXPORT virtual void Initialize();
326 
327  protected:
328  BasisKey m_basisKey; ///< Basis specification.
329  PointsSharedPtr m_points; ///< Set of points.
330  Array<OneD, NekDouble> m_bdata; ///< Basis definition.
331  Array<OneD, NekDouble> m_dbdata; ///< Derivative Basis definition.
334 
335  private:
336  /// Private constructor with BasisKey.
337  Basis(const BasisKey &bkey);
338 
339  /// Private default constructor.
340  Basis():m_basisKey(NullBasisKey)
341  {
343  "Default Constructor for Basis should not be called");
344  }
345 
346  boost::shared_ptr< NekMatrix<NekDouble> > CalculateInterpMatrix(
347  const BasisKey &tbasis0);
348 
349  /// Generate appropriate basis and their derivatives.
350  void GenBasis();
351  };
352 
353  LIB_UTILITIES_EXPORT bool operator<(const BasisKey &lhs, const BasisKey &rhs);
354  LIB_UTILITIES_EXPORT bool operator>(const BasisKey &lhs, const BasisKey &rhs);
355 
356  LIB_UTILITIES_EXPORT std::ostream& operator<<(std::ostream& os, const BasisKey& rhs);
357 
360 
361  } // end of namespace LibUtilities
362 } // end of namespace Nektar
363 
364 #endif //NEKTAR_LIB_UTILIITIES_FOUNDATIONS_BASIS_H
365 
366 
int GetTotNumModes() const
Return total number of modes from the basis specification.
Definition: Basis.h:224
virtual ~Basis()
Destructor.
Definition: Basis.h:213
static const PointsKey NullPointsKey(0, eNoPointsType)
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
BasisKey(const BasisType btype, const int nummodes, const PointsKey pkey)
Constructor.
Definition: Basis.h:62
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
Definition: ErrorUtil.hpp:191
friend bool operator!=(const BasisKey &x, const BasisKey &y)
Definition: Basis.cpp:723
BasisKey m_basisKey
Basis specification.
Definition: Basis.h:328
Represents a basis of a given type.
Definition: Basis.h:206
Principle Modified Functions .
Definition: BasisType.h:51
friend bool operator==(const BasisKey &x, const BasisKey &y)
Overloaded Operators.
Definition: Basis.cpp:703
PointsType GetPointsType() const
Return the type of quadrature.
Definition: Basis.h:254
const BasisKey GetBasisKey() const
Returns the specification for the Basis.
Definition: Basis.h:320
BasisType GetBasisType() const
Return type of expansion basis.
Definition: Basis.h:139
bool ExactIprodInt() const
Determine if basis has exact integration for inner product.
Definition: Basis.h:296
Array< OneD, NekDouble > m_bdata
Basis definition.
Definition: Basis.h:330
Principle Modified Functions .
Definition: BasisType.h:49
static BasisSharedPtr NullBasisSharedPtr
Definition: Basis.h:358
~BasisKey()
Destructor.
Definition: Basis.h:79
Lagrange Polynomials using the Gauss points .
Definition: BasisType.h:54
PointsType GetPointsType() const
Return type of quadrature.
Definition: Basis.h:151
const boost::shared_ptr< NekMatrix< NekDouble > > GetI(const Array< OneD, const NekDouble > &x)
Definition: Basis.h:281
boost::shared_ptr< Points< NekDouble > > PointsSharedPtr
bool operator>(const BasisKey &lhs, const BasisKey &rhs)
Definition: Basis.cpp:75
Fourier Expansion .
Definition: BasisType.h:52
Chebyshev Polynomials .
Definition: BasisType.h:56
bool Collocation() const
Determine if basis has collocation properties.
Definition: Basis.h:302
BasisType m_basistype
Expansion type.
Definition: Basis.h:189
PointsKey m_pointsKey
Points specification.
Definition: Basis.h:190
StandardMatrixTag & lhs
const boost::shared_ptr< NekMatrix< NekDouble > > & GetD(Direction dir=xDir) const
Definition: Basis.h:275
Principle Orthogonal Functions .
Definition: BasisType.h:47
const Array< OneD, const NekDouble > & GetZ() const
Definition: Basis.h:259
std::ostream & operator<<(std::ostream &os, const BasisKey &rhs)
Definition: Basis.cpp:85
Array< OneD, NekDouble > m_dbdata
Derivative Basis definition.
Definition: Basis.h:331
PointsKey GetPointsKey() const
Return the points specification for the basis.
Definition: Basis.h:248
int GetNumModes() const
Return order of basis from the basis specification.
Definition: Basis.h:218
virtual void Initialize()
Definition: Basis.cpp:110
Fourier Modified expansions with just the real part of the first mode .
Definition: BasisType.h:59
int GetTotNumPoints() const
Return total number of points from the basis specification.
Definition: Basis.h:236
Principle Modified Functions .
Definition: BasisType.h:50
#define LIB_UTILITIES_EXPORT
void GenBasis()
Generate appropriate basis and their derivatives.
Definition: Basis.cpp:215
PointsSharedPtr m_points
Set of points.
Definition: Basis.h:329
void GetZW(Array< OneD, const NekDouble > &z, Array< OneD, const NekDouble > &w) const
Definition: Basis.h:269
int GetNumPoints() const
Return points order at which basis is defined.
Definition: Basis.h:128
unsigned int GetTotNumPoints() const
Definition: Points.h:179
int m_nummodes
Expansion order.
Definition: Basis.h:188
Principle Orthogonal Functions .
Definition: BasisType.h:48
unsigned int GetPointsDim() const
Definition: Points.h:149
int GetTotNumModes() const
Definition: Basis.h:90
Principle Orthogonal Functions .
Definition: BasisType.h:46
Defines a specification for a set of points.
Definition: Points.h:58
boost::shared_ptr< NekMatrix< NekDouble > > CalculateInterpMatrix(const BasisKey &tbasis0)
Calculate the interpolation Matrix for coefficient from one base (m_basisKey) to another (tbasis0) ...
Definition: Basis.cpp:122
const Array< OneD, const NekDouble > & GetW() const
Definition: Basis.h:264
bool operator<(const BasisKey &lhs, const BasisKey &rhs)
Definition: Basis.cpp:49
Fourier Modified expansions with just the imaginary part of the first mode .
Definition: BasisType.h:60
BasisKey(const BasisKey &B)
Copy constructor.
Definition: Basis.h:71
PointsKey GetPointsKey() const
Return distribution of points.
Definition: Basis.h:145
Basis()
Private default constructor.
Definition: Basis.h:340
static Array< OneD, BasisSharedPtr > NullBasisSharedPtr1DArray
Definition: Basis.h:359
Fourier ModifiedExpansion with just the first mode .
Definition: BasisType.h:58
unsigned int GetNumPoints() const
Definition: Points.h:106
const Array< OneD, const NekDouble > & GetDbdata() const
Return basis definition array m_dbdata.
Definition: Basis.h:314
int GetNumPoints() const
Return the number of points from the basis specification.
Definition: Basis.h:230
Legendre Polynomials . Same as Ortho_A.
Definition: BasisType.h:55
bool SamePoints(const BasisKey &x) const
Determine if quadrature of expansion x matches this.
Definition: Basis.h:157
static const BasisKey NullBasisKey(eNoBasisType, 0, NullPointsKey)
Defines a null basis with no type or points.
int GetNumModes() const
Returns the order of the basis.
Definition: Basis.h:84
NekManager< BasisKey, NekMatrix< NekDouble >, BasisKey::opLess > m_InterpManager
Definition: Basis.h:333
boost::shared_ptr< Basis > BasisSharedPtr
bool operator()(const BasisKey &lhs, const BasisKey &rhs) const
Definition: Basis.cpp:80
bool SameExp(const BasisKey &x) const
Determine if basis expansion x matches this.
Definition: Basis.h:163
static boost::shared_ptr< Basis > Create(const BasisKey &bkey)
Returns a new instance of a Basis with given BasisKey.
Definition: Basis.cpp:102
Lagrange for SEM basis .
Definition: BasisType.h:53
const Array< OneD, const NekDouble > & GetBdata() const
Return basis definition array m_bdata.
Definition: Basis.h:308
int GetTotNumPoints() const
Definition: Basis.h:133
const boost::shared_ptr< NekMatrix< NekDouble > > GetI(const BasisKey &bkey)
Definition: Basis.h:287
Describes the specification for a Basis.
Definition: Basis.h:50
bool ExactIprodInt() const
Determine if basis has exact integration for inner product.
Definition: Basis.cpp:665
friend bool operator<(const BasisKey &lhs, const BasisKey &rhs)
Definition: Basis.cpp:49
BasisType GetBasisType() const
Return the type of expansion basis.
Definition: Basis.h:242
bool Collocation() const
Determine if basis has collocation properties.
Definition: Basis.cpp:692
Monomial polynomials .
Definition: BasisType.h:57
PointsType GetPointsType() const
Definition: Points.h:111