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 
240  static const PointsKey NullPointsKey(0, eNoPointsType);
241 
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();
263  CalculateWeights();
264  CalculateDerivMatrix();
265  }
266 
267  inline unsigned int GetPointsDim() const
268  {
269  return m_pointsKey.GetPointsDim();
270  }
271 
272  inline unsigned int GetNumPoints() const
273  {
274  return m_pointsKey.GetNumPoints();
275  }
276 
277  inline unsigned int GetTotNumPoints() const
278  {
279  return m_pointsKey.GetTotNumPoints();
280  }
281 
282  inline PointsType GetPointsType() const
283  {
284  return m_pointsKey.GetPointsType();
285  }
286 
287  inline const Array<OneD, const DataType>& GetZ() const
288  {
289  return m_points[0];
290  }
291 
292  inline const Array<OneD, const DataType>& GetW() const
293  {
294  return m_weights;
295  }
296 
299  {
300  z = m_points[0];
301  w = m_weights;
302  }
303 
305  {
306  x = m_points[0];
307  }
308 
311  {
312  x = m_points[0];
313  y = m_points[1];
314  }
315 
319  {
320  x = m_points[0];
321  y = m_points[1];
322  z = m_points[2];
323  }
324 
325  inline const MatrixSharedPtrType& GetD(Direction dir = xDir) const
326  {
327  return m_derivmatrix[(int)dir];
328  }
329 
330  virtual const MatrixSharedPtrType GetI(const PointsKey &key)
331  {
332  boost::ignore_unused(key);
333  NEKERROR(ErrorUtil::efatal, "Method not implemented ");
334  std::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
335  return returnval;
336  }
337 
338  virtual const MatrixSharedPtrType GetI(const Array<OneD, const DataType>& x)
339  {
340  boost::ignore_unused(x);
341  NEKERROR(ErrorUtil::efatal, "Method not implemented");
342  std::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
343  return returnval;
344  }
345 
346  virtual const MatrixSharedPtrType GetI(unsigned int, const Array<OneD, const DataType>& x)
347  {
348  boost::ignore_unused(x);
349  NEKERROR(ErrorUtil::efatal, "Method not implemented");
350  std::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
351  return returnval;
352  }
353 
354  virtual const MatrixSharedPtrType GetI(const Array<OneD, const DataType>& x, const Array<OneD, const DataType>& y)
355  {
356  boost::ignore_unused(x, y);
357  NEKERROR(ErrorUtil::efatal, "Method not implemented");
358  std::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
359  return returnval;
360  }
361 
362  virtual const MatrixSharedPtrType GetI(const Array<OneD, const DataType>& x, const Array<OneD, const DataType>& y,
364  {
365  boost::ignore_unused(x, y, z);
366  NEKERROR(ErrorUtil::efatal, "Method not implemented");
367  std::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
368  return returnval;
369  }
370 
371  virtual const MatrixSharedPtrType GetGalerkinProjection(const PointsKey &pkey)
372  {
373  boost::ignore_unused(pkey);
374  NEKERROR(ErrorUtil::efatal, "Method not implemented ");
375  std::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
376  return returnval;
377  }
378 
379  protected:
383  MatrixSharedPtrType m_derivmatrix[3];
386 
387  virtual void CalculatePoints()
388  {
389  unsigned int pointsDim = GetPointsDim();
390  unsigned int totNumPoints = GetTotNumPoints();
391 
392  for (unsigned int i=0; i<pointsDim; ++i)
393  {
394  m_points[i] = Array<OneD, DataType>(totNumPoints);
395  }
396  }
397 
398  virtual void CalculateWeights()
399  {
400  m_weights = Array<OneD, DataType>(GetTotNumPoints());
401  }
402 
403  virtual void CalculateDerivMatrix()
404  {
405  int totNumPoints = GetTotNumPoints();
406  for(unsigned int i = 0; i < m_pointsKey.GetPointsDim(); ++i)
407  {
408  m_derivmatrix[i] = MemoryManager<NekMatrix<DataType> >::AllocateSharedPtr(totNumPoints,totNumPoints);
409  }
410  }
411 
412  Points(const PointsKey &key):m_pointsKey(key)
413  {
414  }
415 
416  private:
417  // These should never be called
418  Points(const Points &pts)
419  {
420  boost::ignore_unused(pts);
422  "Copy Constructor for Points should not be called");
423  }
425  {
427  "Default Constructor for Points should not be called");
428  }
429  };
430 
431  } // end of namespace
432 } // end of namespace
433 
434 #endif //NEKTAR_LIB_UTILITIES_FOUNDATIONS_POINTS_H
bool operator!=(const PointsKey &y)
Definition: Points.h:139
virtual const MatrixSharedPtrType GetI(const PointsKey &key)
Definition: Points.h:330
static const PointsKey NullPointsKey(0, eNoPointsType)
virtual void Initialize(void)
Definition: Points.h:260
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
Definition: ErrorUtil.hpp:209
Array< OneD, DataType > m_weights
Definition: Points.h:382
PointsType GetPointsType() const
Definition: Points.h:112
std::vector< PointsKey > PointsKeyVector
Definition: Points.h:246
const Array< OneD, const DataType > & GetW() const
Definition: Points.h:292
Points(const PointsKey &key)
Definition: Points.h:412
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
PointsKey(const PointsKey &key)
Copy constructor.
Definition: Points.h:93
PointsType GetPointsType() const
Definition: Points.h:282
NekDouble m_factor
optional factor
Definition: Points.h:236
NekDouble GetFactor() const
Definition: Points.h:117
PointsType m_pointstype
Type of Points.
Definition: Points.h:235
virtual const MatrixSharedPtrType GetI(const Array< OneD, const DataType > &x)
Definition: Points.h:338
unsigned int GetPointsDim() const
Definition: Points.h:150
unsigned int m_numpoints
number of the points (as appropriately defined for PointsType)
Definition: Points.h:234
void GetPoints(Array< OneD, const DataType > &x, Array< OneD, const DataType > &y) const
Definition: Points.h:309
virtual void CalculatePoints()
Definition: Points.h:387
Stores a set of points of datatype DataT, defined by a PointKey.
3D Nodal Symmetric positive internal tet (Whitherden, Vincent)
Definition: PointsType.h:77
void GetZW(Array< OneD, const DataType > &z, Array< OneD, const DataType > &w) const
Definition: Points.h:297
StandardMatrixTag & lhs
std::ostream & operator<<(std::ostream &os, const BasisKey &rhs)
const Array< OneD, const DataType > & GetZ() const
Definition: Points.h:287
static const NekDouble kNekZeroTol
PointsKey & operator=(const PointsKey &key)
Definition: Points.h:98
std::shared_ptr< NekMatrix< DataType > > MatrixSharedPtrType
Definition: Points.h:254
#define LIB_UTILITIES_EXPORT
NekManager< PointsKey, NekMatrix< DataType >, PointsKey::opLess > m_InterpManager
Definition: Points.h:384
virtual const MatrixSharedPtrType GetGalerkinProjection(const PointsKey &pkey)
Definition: Points.h:371
3D Nodal Electrostatic Points on a Tetrahedron
Definition: PointsType.h:73
unsigned int GetPointsDim() const
Definition: Points.h:267
unsigned int GetTotNumPoints() const
Definition: Points.h:180
Defines a specification for a set of points.
Definition: Points.h:59
double NekDouble
bool operator==(const PointsKey &key)
Definition: Points.h:122
NekManager< PointsKey, NekMatrix< DataType >, PointsKey::opLess > m_GalerkinProjectionManager
Definition: Points.h:385
static const NekDouble kNekUnsetDouble
3D Evenly-spaced points on a Tetrahedron
Definition: PointsType.h:72
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:362
virtual void CalculateDerivMatrix()
Definition: Points.h:403
2D Nodal Fekete Points on a Triangle
Definition: PointsType.h:70
const MatrixSharedPtrType & GetD(Direction dir=xDir) const
Definition: Points.h:325
virtual const MatrixSharedPtrType GetI(unsigned int, const Array< OneD, const DataType > &x)
Definition: Points.h:346
virtual ~PointsKey()
Destructor.
Definition: Points.h:88
PointsKey(void)
Default constructor.
Definition: Points.h:71
Points(const Points &pts)
Definition: Points.h:418
virtual const MatrixSharedPtrType GetI(const Array< OneD, const DataType > &x, const Array< OneD, const DataType > &y)
Definition: Points.h:354
unsigned int GetTotNumPoints() const
Definition: Points.h:277
friend bool operator<(const PointsKey &lhs, const PointsKey &rhs)
PointsKey(const int &numpoints, const PointsType &pointstype, const NekDouble factor=NekConstants::kNekUnsetDouble)
Constructor defining the number and distribution of points.
Definition: Points.h:79
3D Evenly-spaced points on a Prism
Definition: PointsType.h:74
void GetPoints(Array< OneD, const DataType > &x) const
Definition: Points.h:304
virtual void CalculateWeights()
Definition: Points.h:398
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs
void GetPoints(Array< OneD, const DataType > &x, Array< OneD, const DataType > &y, Array< OneD, const DataType > &z) const
Definition: Points.h:316
2D Evenly-spaced points on a Triangle
Definition: PointsType.h:71
bool operator()(const PointsKey &lhs, const PointsKey &rhs) const
unsigned int GetNumPoints() const
Definition: Points.h:107
unsigned int GetNumPoints() const
Definition: Points.h:272
1D Array of constant elements with garbage collection and bounds checking.
Definition: SharedArray.hpp:57
2D Nodal Electrostatic Points on a Triangle
Definition: PointsType.h:69
3D electrostatically spaced points on a Prism
Definition: PointsType.h:75
2D Nodal Symmetric positive internal triangle (Whitherden, Vincent)
Definition: PointsType.h:76