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 
50 namespace Nektar
51 {
52 
53  namespace LibUtilities
54  {
55  // Need to add method to compute total number of points given dimension
56  // and number of points.
57 
58  /// Defines a specification for a set of points.
59  class PointsKey
60  {
61  public:
62  // Used for looking up the creator. The creator for number of points
63  // can generate for any number, so we want the same creator called
64  // for all number.
65  struct opLess
66  {
67  LIB_UTILITIES_EXPORT bool operator()(const PointsKey &lhs, const PointsKey &rhs) const;
68  };
69 
70  /// Default constructor.
71  PointsKey(void):
72  m_numpoints(0),
74  m_factor(NekConstants::kNekUnsetDouble)
75  {
76  }
77 
78  /// Constructor defining the number and distribution of points.
79  PointsKey(const int &numpoints, const PointsType &pointstype,
81  m_numpoints(numpoints),
82  m_pointstype(pointstype),
83  m_factor(factor)
84  {
85  }
86 
87  /// Destructor.
88  virtual ~PointsKey()
89  {
90  }
91 
92  /// Copy constructor.
93  PointsKey(const PointsKey &key)
94  {
95  *this = key; // defer to assignment operator
96  }
97 
99  {
100  m_numpoints = key.m_numpoints;
102  m_factor = key.m_factor;
103 
104  return *this;
105  }
106 
107  inline unsigned int GetNumPoints() const
108  {
109  return m_numpoints;
110  }
111 
112  inline PointsType GetPointsType() const
113  {
114  return m_pointstype;
115  }
116 
117  inline NekDouble GetFactor() const
118  {
119  return m_factor;
120  }
121 
122  inline bool operator==(const PointsKey &key)
123  {
124 
126  {
127  return (m_numpoints == key.m_numpoints &&
128  m_pointstype == key.m_pointstype);
129  }
130 
131  return false;
132  }
133 
134  inline bool operator== (const PointsKey *y)
135  {
136  return (*this == *y);
137  }
138 
139  inline bool operator != (const PointsKey& y)
140  {
141  return (!(*this == y));
142  }
143 
144  inline bool operator != (const PointsKey *y)
145  {
146  return (!(*this == *y));
147  }
148 
149  // If new points are added, this function must be modified
150  inline unsigned int GetPointsDim() const
151  {
152  int dimpoints = 1;
153 
154  switch(m_pointstype)
155  {
156  case eNodalTriElec:
157  case eNodalTriFekete:
159  case eNodalTriSPI:
160  case eNodalQuadElec:
161  dimpoints = 2;
162  break;
163 
164  case eNodalTetElec:
167  case eNodalPrismElec:
168  case eNodalHexElec:
169  dimpoints = 3;
170  break;
171 
172  default:
173  break;
174  }
175 
176  return dimpoints;
177  }
178 
179  // If new points are added, this function must be modified
180  inline unsigned int GetTotNumPoints() const
181  {
182  int totpoints = m_numpoints;
183 
184  switch(m_pointstype)
185  {
186  case eNodalTriElec:
187  case eNodalTriFekete:
189  totpoints = m_numpoints*(m_numpoints+1)/2;
190  break;
191  case eNodalTriSPI:
193  "This method cannot be implemented");
194  break;
195 
196  case eNodalQuadElec:
197  totpoints = m_numpoints*m_numpoints;
198  break;
199 
200  case eNodalTetElec:
202  totpoints = m_numpoints*(m_numpoints+1)*(m_numpoints+2)/6;
203  break;
204  case eNodalTetSPI:
206  "This method cannot be implemented");
207  break;
208 
210  case eNodalPrismElec:
211  totpoints = m_numpoints*m_numpoints*(m_numpoints+1)/2;
212  break;
213  case eNodalPrismSPI:
215  "This method cannot be implemented");
216  break;
217 
218  case eNodalHexElec:
219  totpoints = m_numpoints*m_numpoints*m_numpoints;
220  break;
221 
222  default:
223  break;
224  }
225 
226  return totpoints;
227  }
228 
229  LIB_UTILITIES_EXPORT friend bool operator==(const PointsKey &lhs, const PointsKey &rhs);
230  LIB_UTILITIES_EXPORT friend bool operator<(const PointsKey &lhs, const PointsKey &rhs);
231  LIB_UTILITIES_EXPORT friend bool opLess::operator()(const PointsKey &lhs, const PointsKey &rhs) const;
232 
233  protected:
234  unsigned int m_numpoints; //!< number of the points (as appropriately defined for PointsType)
235  PointsType m_pointstype; //!< Type of Points
236  NekDouble m_factor; //!< optional factor
237  private:
238  };
239 
241 
242  LIB_UTILITIES_EXPORT bool operator==(const PointsKey &lhs, const PointsKey &rhs);
243  LIB_UTILITIES_EXPORT bool operator<(const PointsKey &lhs, const PointsKey &rhs);
244  LIB_UTILITIES_EXPORT std::ostream& operator<<(std::ostream& os, const PointsKey& rhs);
245 
246  typedef std::vector<PointsKey> PointsKeyVector;
247 
248  /// Stores a set of points of datatype DataT, defined by a PointKey.
249  template<typename DataT>
250  class Points
251  {
252  public:
253  typedef DataT DataType;
254  typedef std::shared_ptr<NekMatrix<DataType> > MatrixSharedPtrType;
255 
256  virtual ~Points()
257  {
258  }
259 
260  virtual void Initialize(void)
261  {
262  CalculatePoints();
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 
336  virtual const MatrixSharedPtrType GetI(const PointsKey &key)
337  {
338  boost::ignore_unused(key);
339  NEKERROR(ErrorUtil::efatal, "Method not implemented ");
340  std::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
341  return returnval;
342  }
343 
345  {
346  boost::ignore_unused(x);
347  NEKERROR(ErrorUtil::efatal, "Method not implemented");
348  std::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
349  return returnval;
350  }
351 
352  virtual const MatrixSharedPtrType GetI(unsigned int, const Array<OneD, const DataType>& x)
353  {
354  boost::ignore_unused(x);
355  NEKERROR(ErrorUtil::efatal, "Method not implemented");
356  std::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
357  return returnval;
358  }
359 
361  {
362  boost::ignore_unused(x, y);
363  NEKERROR(ErrorUtil::efatal, "Method not implemented");
364  std::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
365  return returnval;
366  }
367 
370  {
371  boost::ignore_unused(x, y, z);
372  NEKERROR(ErrorUtil::efatal, "Method not implemented");
373  std::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
374  return returnval;
375  }
376 
378  {
379  boost::ignore_unused(pkey);
380  NEKERROR(ErrorUtil::efatal, "Method not implemented ");
381  std::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
382  return returnval;
383  }
384 
385  protected:
386  /// Points type for this points distributions.
388  /// Storage for the point locations, allowing for up to a 3D points
389  /// storage.
391  /// Quadrature weights for the weights.
393  /// Barycentric weights.
395  /// Derivative matrices.
399 
400  virtual void CalculatePoints()
401  {
402  unsigned int pointsDim = GetPointsDim();
403  unsigned int totNumPoints = GetTotNumPoints();
404 
405  for (unsigned int i=0; i<pointsDim; ++i)
406  {
407  m_points[i] = Array<OneD, DataType>(totNumPoints);
408  }
409  }
410 
411  virtual void CalculateWeights()
412  {
414  }
415 
416  /**
417  * @brief This function calculates the barycentric weights used for
418  * enhanced interpolation speed.
419  *
420  * For the points distribution \f$ z_i \f$ with \f% 1\leq z_i \leq N
421  * \f$, the barycentric weights are computed as:
422  *
423  * \f[
424  * b_i=\prod_{\substack{1\leq j\leq N\\ i\neq j}} \frac{1}{z_i-z_j}
425  * \f]
426  */
427  virtual void CalculateBaryWeights()
428  {
429  const unsigned int totNumPoints = m_pointsKey.GetNumPoints();
430  m_bcweights = Array<OneD, DataType>(totNumPoints, 1.0);
431 
433 
434  for (unsigned int i = 0; i < totNumPoints; ++i)
435  {
436  for (unsigned int j = 0; j < totNumPoints; ++j)
437  {
438  if (i == j)
439  {
440  continue;
441  }
442 
443  m_bcweights[i] *= (z[i] - z[j]);
444  }
445 
446  m_bcweights[i] = 1.0 / m_bcweights[i];
447  }
448  }
449 
450  virtual void CalculateDerivMatrix()
451  {
452  int totNumPoints = GetTotNumPoints();
453  for(unsigned int i = 0; i < m_pointsKey.GetPointsDim(); ++i)
454  {
455  m_derivmatrix[i] = MemoryManager<NekMatrix<DataType> >::AllocateSharedPtr(totNumPoints,totNumPoints);
456  }
457  }
458 
459  Points(const PointsKey &key):m_pointsKey(key)
460  {
461  }
462 
463  private:
464  // These should never be called
465  Points(const Points &pts)
466  {
467  boost::ignore_unused(pts);
469  "Copy Constructor for Points should not be called");
470  }
472  {
474  "Default Constructor for Points should not be called");
475  }
476  };
477 
478  } // end of namespace
479 } // end of namespace
480 
481 #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:59
Stores a set of points of datatype DataT, defined by a PointKey.
Definition: Points.h:251
Array< OneD, DataType > m_points[3]
Storage for the point locations, allowing for up to a 3D points storage.
Definition: Points.h:390
MatrixSharedPtrType m_derivmatrix[3]
Derivative matrices.
Definition: Points.h:396
NekManager< PointsKey, NekMatrix< DataType >, PointsKey::opLess > m_InterpManager
Definition: Points.h:397
const MatrixSharedPtrType & GetD(Direction dir=xDir) const
Definition: Points.h:331
virtual void CalculateWeights()
Definition: Points.h:411
void GetPoints(Array< OneD, const DataType > &x, Array< OneD, const DataType > &y) const
Definition: Points.h:315
virtual const MatrixSharedPtrType GetGalerkinProjection(const PointsKey &pkey)
Definition: Points.h:377
virtual void CalculateDerivMatrix()
Definition: Points.h:450
NekManager< PointsKey, NekMatrix< DataType >, PointsKey::opLess > m_GalerkinProjectionManager
Definition: Points.h:398
PointsKey m_pointsKey
Points type for this points distributions.
Definition: Points.h:387
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
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:459
std::shared_ptr< NekMatrix< DataType > > MatrixSharedPtrType
Definition: Points.h:254
virtual const MatrixSharedPtrType GetI(const Array< OneD, const DataType > &x, const Array< OneD, const DataType > &y, const Array< OneD, const DataType > &z)
Definition: Points.h:368
virtual void Initialize(void)
Definition: Points.h:260
const Array< OneD, const DataType > & GetW() const
Definition: Points.h:293
virtual void CalculatePoints()
Definition: Points.h:400
virtual const MatrixSharedPtrType GetI(const Array< OneD, const DataType > &x, const Array< OneD, const DataType > &y)
Definition: Points.h:360
virtual const MatrixSharedPtrType GetI(const Array< OneD, const DataType > &x)
Definition: Points.h:344
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:392
const Array< OneD, const DataType > & GetZ() const
Definition: Points.h:288
virtual void CalculateBaryWeights()
This function calculates the barycentric weights used for enhanced interpolation speed.
Definition: Points.h:427
Points(const Points &pts)
Definition: Points.h:465
Array< OneD, DataType > m_bcweights
Barycentric weights.
Definition: Points.h:394
virtual const MatrixSharedPtrType GetI(unsigned int, const Array< OneD, const DataType > &x)
Definition: Points.h:352
virtual const MatrixSharedPtrType GetI(const PointsKey &key)
Definition: Points.h:336
const Array< OneD, const NekDouble > & GetBaryWeights() const
Definition: Points.h:305
Defines a specification for a set of points.
Definition: Points.h:60
unsigned int m_numpoints
number of the points (as appropriately defined for PointsType)
Definition: Points.h:234
unsigned int GetTotNumPoints() const
Definition: Points.h:180
PointsType GetPointsType() const
Definition: Points.h:112
friend bool operator<(const PointsKey &lhs, const PointsKey &rhs)
PointsType m_pointstype
Type of Points.
Definition: Points.h:235
PointsKey & operator=(const PointsKey &key)
Definition: Points.h:98
PointsKey(const int &numpoints, const PointsType &pointstype, const NekDouble factor=NekConstants::kNekUnsetDouble)
Constructor defining the number and distribution of points.
Definition: Points.h:79
unsigned int GetPointsDim() const
Definition: Points.h:150
bool operator==(const PointsKey &key)
Definition: Points.h:122
PointsKey(const PointsKey &key)
Copy constructor.
Definition: Points.h:93
NekDouble GetFactor() const
Definition: Points.h:117
NekDouble m_factor
optional factor
Definition: Points.h:236
unsigned int GetNumPoints() const
Definition: Points.h:107
virtual ~PointsKey()
Destructor.
Definition: Points.h:88
bool operator!=(const PointsKey &y)
Definition: Points.h:139
PointsKey(void)
Default constructor.
Definition: Points.h:71
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:246
std::ostream & operator<<(std::ostream &os, const BasisKey &rhs)
@ eNodalPrismEvenlySpaced
3D Evenly-spaced points on a Prism
Definition: PointsType.h:74
@ eNodalTriFekete
2D Nodal Fekete Points on a Triangle
Definition: PointsType.h:70
@ eNodalPrismSPI
3D prism SPI
Definition: PointsType.h:78
@ eNodalTriElec
2D Nodal Electrostatic Points on a Triangle
Definition: PointsType.h:69
@ eNodalTriEvenlySpaced
2D Evenly-spaced points on a Triangle
Definition: PointsType.h:71
@ eNodalHexElec
3D GLL for hex
Definition: PointsType.h:80
@ eNodalQuadElec
2D GLL for quad
Definition: PointsType.h:79
@ eNodalTetEvenlySpaced
3D Evenly-spaced points on a Tetrahedron
Definition: PointsType.h:72
@ eNodalTetSPI
3D Nodal Symmetric positive internal tet (Whitherden, Vincent)
Definition: PointsType.h:77
@ eNodalPrismElec
3D electrostatically spaced points on a Prism
Definition: PointsType.h:75
@ eNodalTetElec
3D Nodal Electrostatic Points on a Tetrahedron
Definition: PointsType.h:73
@ eNodalTriSPI
2D Nodal Symmetric positive internal triangle (Whitherden, Vincent)
Definition: PointsType.h:76
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:1
double NekDouble
bool operator()(const PointsKey &lhs, const PointsKey &rhs) const