Nektar++
Points.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Points.hpp
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 Points definition
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #ifndef NEKTAR_LIB_UTILITIES_FOUNDATIONS_POINTS_H
36 #define NEKTAR_LIB_UTILITIES_FOUNDATIONS_POINTS_H
37 
38 #include <boost/core/ignore_unused.hpp>
39 
44 
45 //#include <LibUtilities/BasicUtils/BasicUtilsFwd.hpp> // for NekManager
48 
49 namespace Nektar
50 {
51 
52 namespace LibUtilities
53 {
54 // Need to add method to compute total number of points given dimension
55 // and number of points.
56 
57 /// Defines a specification for a set of points.
58 class PointsKey
59 {
60 public:
61  // Used for looking up the creator. The creator for number of points
62  // can generate for any number, so we want the same creator called
63  // for all number.
64  struct opLess
65  {
67  const PointsKey &rhs) const;
68  };
69 
70  /// Default constructor.
71  PointsKey(void)
73  m_factor(NekConstants::kNekUnsetDouble)
74  {
75  }
76 
77  /// Constructor defining the number and distribution of points.
78  PointsKey(const int &numpoints, const PointsType &pointstype,
80  : m_numpoints(numpoints), m_pointstype(pointstype), m_factor(factor)
81  {
82  }
83 
84  /// Destructor.
85  virtual ~PointsKey()
86  {
87  }
88 
89  /// Copy constructor.
90  PointsKey(const PointsKey &key)
91  {
92  *this = key; // defer to assignment operator
93  }
94 
96  {
99  m_factor = key.m_factor;
100 
101  return *this;
102  }
103 
104  inline unsigned int GetNumPoints() const
105  {
106  return m_numpoints;
107  }
108 
109  inline PointsType GetPointsType() const
110  {
111  return m_pointstype;
112  }
113 
114  inline NekDouble GetFactor() const
115  {
116  return m_factor;
117  }
118 
119  inline bool operator==(const PointsKey &key)
120  {
121 
122  if (fabs(m_factor - key.m_factor) < NekConstants::kNekZeroTol)
123  {
124  return (m_numpoints == key.m_numpoints &&
125  m_pointstype == key.m_pointstype);
126  }
127 
128  return false;
129  }
130 
131  inline bool operator==(const PointsKey *y)
132  {
133  return (*this == *y);
134  }
135 
136  inline bool operator!=(const PointsKey &y)
137  {
138  return (!(*this == y));
139  }
140 
141  inline bool operator!=(const PointsKey *y)
142  {
143  return (!(*this == *y));
144  }
145 
146  // If new points are added, this function must be modified
147  inline unsigned int GetPointsDim() const
148  {
149  int dimpoints = 1;
150 
151  switch (m_pointstype)
152  {
153  case eNodalTriElec:
154  case eNodalTriFekete:
156  case eNodalTriSPI:
157  case eNodalQuadElec:
158  dimpoints = 2;
159  break;
160 
161  case eNodalTetElec:
164  case eNodalPrismElec:
165  case eNodalHexElec:
166  dimpoints = 3;
167  break;
168 
169  default:
170  break;
171  }
172 
173  return dimpoints;
174  }
175 
176  // If new points are added, this function must be modified
177  inline unsigned int GetTotNumPoints() const
178  {
179  int totpoints = m_numpoints;
180 
181  switch (m_pointstype)
182  {
183  case eNodalTriElec:
184  case eNodalTriFekete:
186  totpoints = m_numpoints * (m_numpoints + 1) / 2;
187  break;
188  case eNodalTriSPI:
190  "This method cannot be implemented");
191  break;
192 
193  case eNodalQuadElec:
194  totpoints = m_numpoints * m_numpoints;
195  break;
196 
197  case eNodalTetElec:
199  totpoints =
200  m_numpoints * (m_numpoints + 1) * (m_numpoints + 2) / 6;
201  break;
202  case eNodalTetSPI:
204  "This method cannot be implemented");
205  break;
206 
208  case eNodalPrismElec:
209  totpoints = m_numpoints * m_numpoints * (m_numpoints + 1) / 2;
210  break;
211  case eNodalPrismSPI:
213  "This method cannot be implemented");
214  break;
215 
216  case eNodalHexElec:
217  totpoints = m_numpoints * m_numpoints * m_numpoints;
218  break;
219 
220  default:
221  break;
222  }
223 
224  return totpoints;
225  }
226 
227  LIB_UTILITIES_EXPORT friend bool operator==(const PointsKey &lhs,
228  const PointsKey &rhs);
229  LIB_UTILITIES_EXPORT friend bool operator<(const PointsKey &lhs,
230  const PointsKey &rhs);
232  const PointsKey &lhs, const PointsKey &rhs) const;
233 
234 protected:
235  unsigned int m_numpoints; //!< number of the points (as appropriately
236  //!< defined for PointsType)
237  PointsType m_pointstype; //!< Type of Points
238  NekDouble m_factor; //!< optional factor
239 private:
240 };
241 
243 
245  const PointsKey &rhs);
246 LIB_UTILITIES_EXPORT bool operator<(const PointsKey &lhs, const PointsKey &rhs);
247 LIB_UTILITIES_EXPORT std::ostream &operator<<(std::ostream &os,
248  const PointsKey &rhs);
249 
250 typedef std::vector<PointsKey> PointsKeyVector;
251 
252 /// Stores a set of points of datatype DataT, defined by a PointKey.
253 template <typename DataT> class Points
254 {
255 public:
256  typedef DataT DataType;
257  typedef std::shared_ptr<NekMatrix<DataType>> MatrixSharedPtrType;
258 
259  virtual ~Points()
260  {
261  }
262 
263  inline void Initialize(void)
264  {
265  v_Initialize();
266  }
267 
268  inline unsigned int GetPointsDim() const
269  {
270  return m_pointsKey.GetPointsDim();
271  }
272 
273  inline unsigned int GetNumPoints() const
274  {
275  return m_pointsKey.GetNumPoints();
276  }
277 
278  inline unsigned int GetTotNumPoints() const
279  {
280  return m_pointsKey.GetTotNumPoints();
281  }
282 
283  inline PointsType GetPointsType() const
284  {
285  return m_pointsKey.GetPointsType();
286  }
287 
288  inline const Array<OneD, const DataType> &GetZ() const
289  {
290  return m_points[0];
291  }
292 
293  inline const Array<OneD, const DataType> &GetW() const
294  {
295  return m_weights;
296  }
297 
300  {
301  z = m_points[0];
302  w = m_weights;
303  }
304 
306  {
307  return m_bcweights;
308  }
309 
311  {
312  x = m_points[0];
313  }
314 
317  {
318  x = m_points[0];
319  y = m_points[1];
320  }
321 
325  {
326  x = m_points[0];
327  y = m_points[1];
328  z = m_points[2];
329  }
330 
331  inline const MatrixSharedPtrType &GetD(Direction dir = xDir) const
332  {
333  return m_derivmatrix[(int)dir];
334  }
335 
337  {
338  return v_GetI(key);
339  }
340 
342  {
343  return v_GetI(x);
344  }
345 
346  const MatrixSharedPtrType GetI(unsigned int uint,
348  {
349  return v_GetI(uint, x);
350  }
351 
354  {
355  return v_GetI(x, y);
356  }
357 
361  {
362  return v_GetI(x, y, z);
363  }
364 
366  {
367  return v_GetGalerkinProjection(pkey);
368  }
369 
370 protected:
371  /// Points type for this points distributions.
373  /// Storage for the point locations, allowing for up to a 3D points
374  /// storage.
376  /// Quadrature weights for the weights.
378  /// Barycentric weights.
380  /// Derivative matrices.
386 
387  virtual void v_Initialize(void)
388  {
393  }
394 
395  virtual void v_CalculatePoints()
396  {
397  unsigned int pointsDim = GetPointsDim();
398  unsigned int totNumPoints = GetTotNumPoints();
399 
400  for (unsigned int i = 0; i < pointsDim; ++i)
401  {
402  m_points[i] = Array<OneD, DataType>(totNumPoints);
403  }
404  }
405 
406  virtual void v_CalculateWeights()
407  {
409  }
410 
411  /**
412  * @brief This function calculates the barycentric weights used for
413  * enhanced interpolation speed.
414  *
415  * For the points distribution \f$ z_i \f$ with \f% 1\leq z_i \leq N
416  * \f$, the barycentric weights are computed as:
417  *
418  * \f[
419  * b_i=\prod_{\substack{1\leq j\leq N\\ i\neq j}} \frac{1}{z_i-z_j}
420  * \f]
421  */
422  virtual void v_CalculateBaryWeights()
423  {
424  const unsigned int totNumPoints = m_pointsKey.GetNumPoints();
425  m_bcweights = Array<OneD, DataType>(totNumPoints, 1.0);
426 
428 
429  for (unsigned int i = 0; i < totNumPoints; ++i)
430  {
431  for (unsigned int j = 0; j < totNumPoints; ++j)
432  {
433  if (i == j)
434  {
435  continue;
436  }
437 
438  m_bcweights[i] *= (z[i] - z[j]);
439  }
440 
441  m_bcweights[i] = 1.0 / m_bcweights[i];
442  }
443  }
444 
445  virtual void v_CalculateDerivMatrix()
446  {
447  int totNumPoints = GetTotNumPoints();
448  for (unsigned int i = 0; i < m_pointsKey.GetPointsDim(); ++i)
449  {
450  m_derivmatrix[i] =
451  MemoryManager<NekMatrix<DataType>>::AllocateSharedPtr(
452  totNumPoints, totNumPoints);
453  }
454  }
455 
456  Points(const PointsKey &key) : m_pointsKey(key)
457  {
458  }
459 
460  virtual const MatrixSharedPtrType v_GetI(const PointsKey &key)
461  {
462  boost::ignore_unused(key);
463  NEKERROR(ErrorUtil::efatal, "Method not implemented ");
464  std::shared_ptr<NekMatrix<NekDouble>> returnval(
465  MemoryManager<NekMatrix<NekDouble>>::AllocateSharedPtr());
466  return returnval;
467  }
468 
471  {
472  boost::ignore_unused(x);
473  NEKERROR(ErrorUtil::efatal, "Method not implemented");
474  std::shared_ptr<NekMatrix<NekDouble>> returnval(
475  MemoryManager<NekMatrix<NekDouble>>::AllocateSharedPtr());
476  return returnval;
477  }
478 
480  unsigned int, const Array<OneD, const DataType> &x)
481  {
482  boost::ignore_unused(x);
483  NEKERROR(ErrorUtil::efatal, "Method not implemented");
484  std::shared_ptr<NekMatrix<NekDouble>> returnval(
485  MemoryManager<NekMatrix<NekDouble>>::AllocateSharedPtr());
486  return returnval;
487  }
488 
492  {
493  boost::ignore_unused(x, y);
494  NEKERROR(ErrorUtil::efatal, "Method not implemented");
495  std::shared_ptr<NekMatrix<NekDouble>> returnval(
496  MemoryManager<NekMatrix<NekDouble>>::AllocateSharedPtr());
497  return returnval;
498  }
499 
504  {
505  boost::ignore_unused(x, y, z);
506  NEKERROR(ErrorUtil::efatal, "Method not implemented");
507  std::shared_ptr<NekMatrix<NekDouble>> returnval(
508  MemoryManager<NekMatrix<NekDouble>>::AllocateSharedPtr());
509  return returnval;
510  }
511 
513  const PointsKey &pkey)
514  {
515  boost::ignore_unused(pkey);
516  NEKERROR(ErrorUtil::efatal, "Method not implemented ");
517  std::shared_ptr<NekMatrix<NekDouble>> returnval(
518  MemoryManager<NekMatrix<NekDouble>>::AllocateSharedPtr());
519  return returnval;
520  }
521 
522 private:
523  // These should never be called
524  Points(const Points &pts)
525  {
526  boost::ignore_unused(pts);
528  "Copy Constructor for Points should not be called");
529  }
531  {
533  "Default Constructor for Points should not be called");
534  }
535 };
536 
537 } // namespace LibUtilities
538 } // namespace Nektar
539 
540 #endif // NEKTAR_LIB_UTILITIES_FOUNDATIONS_POINTS_H
#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
1D Array of constant elements with garbage collection and bounds checking.
Definition: SharedArray.hpp:58
Stores a set of points of datatype DataT, defined by a PointKey.
Definition: Points.h:254
Array< OneD, DataType > m_points[3]
Storage for the point locations, allowing for up to a 3D points storage.
Definition: Points.h:375
MatrixSharedPtrType m_derivmatrix[3]
Derivative matrices.
Definition: Points.h:381
NekManager< PointsKey, NekMatrix< DataType >, PointsKey::opLess > m_InterpManager
Definition: Points.h:383
const MatrixSharedPtrType & GetD(Direction dir=xDir) const
Definition: Points.h:331
const MatrixSharedPtrType GetI(unsigned int uint, const Array< OneD, const DataType > &x)
Definition: Points.h:346
void GetPoints(Array< OneD, const DataType > &x, Array< OneD, const DataType > &y) const
Definition: Points.h:315
NekManager< PointsKey, NekMatrix< DataType >, PointsKey::opLess > m_GalerkinProjectionManager
Definition: Points.h:385
virtual const MatrixSharedPtrType v_GetI(const Array< OneD, const DataType > &x, const Array< OneD, const DataType > &y)
Definition: Points.h:489
virtual const MatrixSharedPtrType v_GetI(const Array< OneD, const DataType > &x, const Array< OneD, const DataType > &y, const Array< OneD, const DataType > &z)
Definition: Points.h:500
virtual void v_CalculatePoints()
Definition: Points.h:395
PointsKey m_pointsKey
Points type for this points distributions.
Definition: Points.h:372
void GetZW(Array< OneD, const DataType > &z, Array< OneD, const DataType > &w) const
Definition: Points.h:298
unsigned int GetNumPoints() const
Definition: Points.h:273
virtual void v_Initialize(void)
Definition: Points.h:387
void GetPoints(Array< OneD, const DataType > &x) const
Definition: Points.h:310
void GetPoints(Array< OneD, const DataType > &x, Array< OneD, const DataType > &y, Array< OneD, const DataType > &z) const
Definition: Points.h:322
PointsType GetPointsType() const
Definition: Points.h:283
Points(const PointsKey &key)
Definition: Points.h:456
const MatrixSharedPtrType GetI(const Array< OneD, const DataType > &x)
Definition: Points.h:341
virtual const MatrixSharedPtrType v_GetI(const Array< OneD, const DataType > &x)
Definition: Points.h:469
virtual const MatrixSharedPtrType v_GetGalerkinProjection(const PointsKey &pkey)
Definition: Points.h:512
const MatrixSharedPtrType GetI(const Array< OneD, const DataType > &x, const Array< OneD, const DataType > &y, const Array< OneD, const DataType > &z)
Definition: Points.h:358
std::shared_ptr< NekMatrix< DataType > > MatrixSharedPtrType
Definition: Points.h:257
const Array< OneD, const DataType > & GetW() const
Definition: Points.h:293
virtual const MatrixSharedPtrType v_GetI(unsigned int, const Array< OneD, const DataType > &x)
Definition: Points.h:479
unsigned int GetTotNumPoints() const
Definition: Points.h:278
unsigned int GetPointsDim() const
Definition: Points.h:268
Array< OneD, DataType > m_weights
Quadrature weights for the weights.
Definition: Points.h:377
virtual void v_CalculateDerivMatrix()
Definition: Points.h:445
const MatrixSharedPtrType GetI(const Array< OneD, const DataType > &x, const Array< OneD, const DataType > &y)
Definition: Points.h:352
const MatrixSharedPtrType GetI(const PointsKey &key)
Definition: Points.h:336
virtual void v_CalculateWeights()
Definition: Points.h:406
const Array< OneD, const DataType > & GetZ() const
Definition: Points.h:288
virtual void v_CalculateBaryWeights()
This function calculates the barycentric weights used for enhanced interpolation speed.
Definition: Points.h:422
Points(const Points &pts)
Definition: Points.h:524
virtual const MatrixSharedPtrType v_GetI(const PointsKey &key)
Definition: Points.h:460
const MatrixSharedPtrType GetGalerkinProjection(const PointsKey &pkey)
Definition: Points.h:365
Array< OneD, DataType > m_bcweights
Barycentric weights.
Definition: Points.h:379
const Array< OneD, const NekDouble > & GetBaryWeights() const
Definition: Points.h:305
Defines a specification for a set of points.
Definition: Points.h:59
unsigned int m_numpoints
number of the points (as appropriately defined for PointsType)
Definition: Points.h:235
unsigned int GetTotNumPoints() const
Definition: Points.h:177
bool operator==(const PointsKey *y)
Definition: Points.h:131
PointsType GetPointsType() const
Definition: Points.h:109
friend bool operator<(const PointsKey &lhs, const PointsKey &rhs)
PointsType m_pointstype
Type of Points.
Definition: Points.h:237
PointsKey & operator=(const PointsKey &key)
Definition: Points.h:95
PointsKey(const int &numpoints, const PointsType &pointstype, const NekDouble factor=NekConstants::kNekUnsetDouble)
Constructor defining the number and distribution of points.
Definition: Points.h:78
unsigned int GetPointsDim() const
Definition: Points.h:147
bool operator==(const PointsKey &key)
Definition: Points.h:119
PointsKey(const PointsKey &key)
Copy constructor.
Definition: Points.h:90
NekDouble GetFactor() const
Definition: Points.h:114
NekDouble m_factor
optional factor
Definition: Points.h:238
unsigned int GetNumPoints() const
Definition: Points.h:104
virtual ~PointsKey()
Destructor.
Definition: Points.h:85
bool operator!=(const PointsKey &y)
Definition: Points.h:136
PointsKey(void)
Default constructor.
Definition: Points.h:71
bool operator!=(const PointsKey *y)
Definition: Points.h:141
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
bool operator==(const BasisKey &x, const BasisKey &y)
bool operator<(const BasisKey &lhs, const BasisKey &rhs)
std::vector< PointsKey > PointsKeyVector
Definition: Points.h:250
std::ostream & operator<<(std::ostream &os, const BasisKey &rhs)
@ eNodalPrismEvenlySpaced
3D Evenly-spaced points on a Prism
Definition: PointsType.h:88
@ eNodalTriFekete
2D Nodal Fekete Points on a Triangle
Definition: PointsType.h:84
@ eNodalPrismSPI
3D prism SPI
Definition: PointsType.h:94
@ eNodalTriElec
2D Nodal Electrostatic Points on a Triangle
Definition: PointsType.h:83
@ eNodalTriEvenlySpaced
2D Evenly-spaced points on a Triangle
Definition: PointsType.h:85
@ eNodalHexElec
3D GLL for hex
Definition: PointsType.h:96
@ eNodalQuadElec
2D GLL for quad
Definition: PointsType.h:95
@ eNodalTetEvenlySpaced
3D Evenly-spaced points on a Tetrahedron
Definition: PointsType.h:86
@ eNodalTetSPI
3D Nodal Symmetric positive internal tet (Whitherden, Vincent)
Definition: PointsType.h:92
@ eNodalPrismElec
3D electrostatically spaced points on a Prism
Definition: PointsType.h:89
@ eNodalTetElec
3D Nodal Electrostatic Points on a Tetrahedron
Definition: PointsType.h:87
@ eNodalTriSPI
2D Nodal Symmetric positive internal triangle (Whitherden, Vincent)
Definition: PointsType.h:90
static const PointsKey NullPointsKey(0, eNoPointsType)
static const NekDouble kNekUnsetDouble
static const NekDouble kNekZeroTol
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
double NekDouble
bool operator()(const PointsKey &lhs, const PointsKey &rhs) const