Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // 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 Points definition
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef NEKTAR_LIB_UTILITIES_FOUNDATIONS_POINTS_H
37 #define NEKTAR_LIB_UTILITIES_FOUNDATIONS_POINTS_H
38 
43 
44 //#include <LibUtilities/BasicUtils/BasicUtilsFwd.hpp> // for NekManager
47 
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  {
66  LIB_UTILITIES_EXPORT bool operator()(const PointsKey &lhs, const PointsKey &rhs) const;
67  };
68 
69  /// Default constructor.
70  PointsKey(void):
71  m_numpoints(0),
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),
81  m_pointstype(pointstype),
82  m_factor(factor)
83  {
84  }
85 
86  /// Destructor.
87  virtual ~PointsKey()
88  {
89  }
90 
91  /// Copy constructor.
92  PointsKey(const PointsKey &key)
93  {
94  *this = key; // defer to assignment operator
95  }
96 
98  {
101  m_factor = key.m_factor;
102 
103  return *this;
104  }
105 
106  inline unsigned int GetNumPoints() const
107  {
108  return m_numpoints;
109  }
110 
111  inline PointsType GetPointsType() const
112  {
113  return m_pointstype;
114  }
115 
116  inline NekDouble GetFactor() const
117  {
118  return m_factor;
119  }
120 
121  inline bool operator==(const PointsKey &key)
122  {
123 
125  {
126  return (m_numpoints == key.m_numpoints &&
127  m_pointstype == key.m_pointstype);
128  }
129 
130  return false;
131  }
132 
133  inline bool operator== (const PointsKey *y)
134  {
135  return (*this == *y);
136  }
137 
138  inline bool operator != (const PointsKey& y)
139  {
140  return (!(*this == y));
141  }
142 
143  inline bool operator != (const PointsKey *y)
144  {
145  return (!(*this == *y));
146  }
147 
148  // If new points are added, this function must be modified
149  inline unsigned int GetPointsDim() const
150  {
151  int dimpoints = 1;
152 
153  switch(m_pointstype)
154  {
155  case eNodalTriElec:
156  case eNodalTriFekete:
158  dimpoints = 2;
159  break;
160 
161  case eNodalTetElec:
164  dimpoints = 3;
165  break;
166 
167  default:
168  break;
169  }
170 
171  return dimpoints;
172  }
173 
174  // If new points are added, this function must be modified
175  inline unsigned int GetTotNumPoints() const
176  {
177  int totpoints = m_numpoints;
178 
179  switch(m_pointstype)
180  {
181  case eNodalTriElec:
182  case eNodalTriFekete:
184  totpoints = m_numpoints*(m_numpoints+1)/2;
185  break;
186 
187  case eNodalTetElec:
189  totpoints = m_numpoints*(m_numpoints+1)*(m_numpoints+2)/6;
190  break;
191 
193  totpoints = m_numpoints*m_numpoints*(m_numpoints+1)/2;
194  break;
195 
196  default:
197  break;
198  }
199 
200  return totpoints;
201  }
202 
203  LIB_UTILITIES_EXPORT friend bool operator==(const PointsKey &lhs, const PointsKey &rhs);
204  LIB_UTILITIES_EXPORT friend bool operator<(const PointsKey &lhs, const PointsKey &rhs);
205  LIB_UTILITIES_EXPORT friend bool opLess::operator()(const PointsKey &lhs, const PointsKey &rhs) const;
206 
207  protected:
208  unsigned int m_numpoints; //!< number of the points (as appropriately defined for PointsType)
209  PointsType m_pointstype; //!< Type of Points
210  NekDouble m_factor; //!< optional factor
211  private:
212  };
213 
214  static const PointsKey NullPointsKey(0, eNoPointsType);
215 
216  LIB_UTILITIES_EXPORT bool operator==(const PointsKey &lhs, const PointsKey &rhs);
217  LIB_UTILITIES_EXPORT bool operator<(const PointsKey &lhs, const PointsKey &rhs);
218  LIB_UTILITIES_EXPORT std::ostream& operator<<(std::ostream& os, const PointsKey& rhs);
219 
220  typedef std::vector<PointsKey> PointsKeyVector;
221 
222  /// Stores a set of points of datatype DataT, defined by a PointKey.
223  template<typename DataT>
224  class Points
225  {
226  public:
227  typedef DataT DataType;
228  typedef boost::shared_ptr<NekMatrix<DataType> > MatrixSharedPtrType;
229 
230  virtual ~Points()
231  {
232  }
233 
234  virtual void Initialize(void)
235  {
236  CalculatePoints();
239  }
240 
241  inline unsigned int GetPointsDim() const
242  {
243  return m_pointsKey.GetPointsDim();
244  }
245 
246  inline unsigned int GetNumPoints() const
247  {
248  return m_pointsKey.GetNumPoints();
249  }
250 
251  inline unsigned int GetTotNumPoints() const
252  {
253  return m_pointsKey.GetTotNumPoints();
254  }
255 
256  inline PointsType GetPointsType() const
257  {
258  return m_pointsKey.GetPointsType();
259  }
260 
261  inline const Array<OneD, const DataType>& GetZ() const
262  {
263  return m_points[0];
264  }
265 
266  inline const Array<OneD, const DataType>& GetW() const
267  {
268  return m_weights;
269  }
270 
272  Array<OneD, const DataType> &w) const
273  {
274  z = m_points[0];
275  w = m_weights;
276  }
277 
279  {
280  x = m_points[0];
281  }
282 
285  {
286  x = m_points[0];
287  y = m_points[1];
288  }
289 
293  {
294  x = m_points[0];
295  y = m_points[1];
296  z = m_points[2];
297  }
298 
299  inline const MatrixSharedPtrType& GetD(Direction dir = xDir) const
300  {
301  return m_derivmatrix[(int)dir];
302  }
303 
304  virtual const MatrixSharedPtrType GetI(const PointsKey &pkey)
305  {
306  ASSERTL0(false, "Method not implemented ");
307  boost::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
308  return returnval;
309  }
310 
311  virtual const MatrixSharedPtrType GetI(const Array<OneD, const DataType>& x)
312  {
313  ASSERTL0(false, "Method not implemented");
314  boost::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
315  return returnval;
316  }
317 
318  virtual const MatrixSharedPtrType GetI(unsigned int numpoints, const Array<OneD, const DataType>& x)
319  {
320  ASSERTL0(false, "Method not implemented");
321  boost::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
322  return returnval;
323  }
324 
325  virtual const MatrixSharedPtrType GetI(const Array<OneD, const DataType>& x, const Array<OneD, const DataType>& y)
326  {
327  ASSERTL0(false, "Method not implemented");
328  boost::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
329  return returnval;
330  }
331 
332  virtual const MatrixSharedPtrType GetI(const Array<OneD, const DataType>& x, const Array<OneD, const DataType>& y,
334  {
335  ASSERTL0(false, "Method not implemented");
336  boost::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
337  return returnval;
338  }
339 
340  virtual const MatrixSharedPtrType GetGalerkinProjection(const PointsKey &pkey)
341  {
342  ASSERTL0(false, "Method not implemented ");
343  boost::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
344  return returnval;
345  }
346 
347  protected:
351  MatrixSharedPtrType m_derivmatrix[3];
354 
355  virtual void CalculatePoints()
356  {
357  unsigned int pointsDim = GetPointsDim();
358  unsigned int totNumPoints = GetTotNumPoints();
359 
360  for (unsigned int i=0; i<pointsDim; ++i)
361  {
362  m_points[i] = Array<OneD, DataType>(totNumPoints);
363  }
364  }
365 
366  virtual void CalculateWeights()
367  {
368  m_weights = Array<OneD, DataType>(GetTotNumPoints());
369  }
370 
371  virtual void CalculateDerivMatrix()
372  {
373  int totNumPoints = GetTotNumPoints();
374  for(unsigned int i = 0; i < m_pointsKey.GetPointsDim(); ++i)
375  {
376  m_derivmatrix[i] = MemoryManager<NekMatrix<DataType> >::AllocateSharedPtr(totNumPoints,totNumPoints);
377  }
378  }
379 
380  Points(const PointsKey &key):m_pointsKey(key)
381  {
382  }
383 
384  private:
385  // These should never be called
386  Points(const Points &pts)
387  {
388  NEKERROR(ErrorUtil::efatal,"Copy Constructor for Points should not be called");
389  }
391  {
392  NEKERROR(ErrorUtil::efatal,"Default Constructor for Points should not be called");
393  }
394  };
395 
396  }; // end of namespace
397 } // end of namespace
398 
399 #endif //NEKTAR_LIB_UTILITIES_FOUNDATIONS_POINTS_H
const MatrixSharedPtrType & GetD(Direction dir=xDir) const
Definition: Points.h:299
bool operator!=(const PointsKey &y)
Definition: Points.h:138
NekManager< PointsKey, NekMatrix< DataType >, PointsKey::opLess > m_GalerkinProjectionManager
Definition: Points.h:353
static const PointsKey NullPointsKey(0, eNoPointsType)
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
Points(const Points &pts)
Definition: Points.h:386
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
Definition: ErrorUtil.hpp:158
virtual const MatrixSharedPtrType GetI(const Array< OneD, const DataType > &x)
Definition: Points.h:311
std::vector< PointsKey > PointsKeyVector
Definition: Points.h:220
virtual void CalculatePoints()
Definition: Points.h:355
NekDouble GetFactor() const
Definition: Points.h:116
virtual const MatrixSharedPtrType GetI(const Array< OneD, const DataType > &x, const Array< OneD, const DataType > &y)
Definition: Points.h:325
PointsType GetPointsType() const
Definition: Points.h:256
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
PointsKey(const PointsKey &key)
Copy constructor.
Definition: Points.h:92
NekDouble m_factor
optional factor
Definition: Points.h:210
void GetPoints(Array< OneD, const DataType > &x, Array< OneD, const DataType > &y) const
Definition: Points.h:283
MatrixSharedPtrType m_derivmatrix[3]
Definition: Points.h:351
Array< OneD, DataType > m_points[3]
Definition: Points.h:349
PointsType m_pointstype
Type of Points.
Definition: Points.h:209
unsigned int m_numpoints
number of the points (as appropriately defined for PointsType)
Definition: Points.h:208
StandardMatrixTag & lhs
bool operator==(const BasisKey &x, const BasisKey &y)
Definition: Basis.cpp:703
const Array< OneD, const DataType > & GetW() const
Definition: Points.h:266
unsigned int GetPointsDim() const
Definition: Points.h:241
std::ostream & operator<<(std::ostream &os, const BasisKey &rhs)
Definition: Basis.cpp:85
virtual const MatrixSharedPtrType GetI(const PointsKey &pkey)
Definition: Points.h:304
boost::shared_ptr< NekMatrix< DataType > > MatrixSharedPtrType
Definition: Points.h:228
bool operator()(const PointsKey &lhs, const PointsKey &rhs) const
Definition: Points.cpp:90
const Array< OneD, const DataType > & GetZ() const
Definition: Points.h:261
static const NekDouble kNekZeroTol
virtual const MatrixSharedPtrType GetI(unsigned int numpoints, const Array< OneD, const DataType > &x)
Definition: Points.h:318
PointsKey & operator=(const PointsKey &key)
Definition: Points.h:97
virtual const MatrixSharedPtrType GetGalerkinProjection(const PointsKey &pkey)
Definition: Points.h:340
unsigned int GetNumPoints() const
Definition: Points.h:246
#define LIB_UTILITIES_EXPORT
Points(const PointsKey &key)
Definition: Points.h:380
3D Nodal Electrostatic Points on a Tetrahedron
Definition: PointsType.h:72
unsigned int GetTotNumPoints() const
Definition: Points.h:175
unsigned int GetPointsDim() const
Definition: Points.h:149
Array< OneD, DataType > m_weights
Definition: Points.h:350
Defines a specification for a set of points.
Definition: Points.h:58
double NekDouble
void GetPoints(Array< OneD, const DataType > &x) const
Definition: Points.h:278
bool operator==(const PointsKey &key)
Definition: Points.h:121
virtual void CalculateDerivMatrix()
Definition: Points.h:371
static const NekDouble kNekUnsetDouble
bool operator<(const BasisKey &lhs, const BasisKey &rhs)
Definition: Basis.cpp:49
3D Evenly-spaced points on a Tetrahedron
Definition: PointsType.h:71
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:332
2D Nodal Fekete Points on a Triangle
Definition: PointsType.h:69
void GetPoints(Array< OneD, const DataType > &x, Array< OneD, const DataType > &y, Array< OneD, const DataType > &z) const
Definition: Points.h:290
virtual ~PointsKey()
Destructor.
Definition: Points.h:87
PointsKey(void)
Default constructor.
Definition: Points.h:70
void GetZW(Array< OneD, const DataType > &z, Array< OneD, const DataType > &w) const
Definition: Points.h:271
friend bool operator<(const PointsKey &lhs, const PointsKey &rhs)
Definition: Points.cpp:55
unsigned int GetNumPoints() const
Definition: Points.h:106
PointsKey(const int &numpoints, const PointsType &pointstype, const NekDouble factor=NekConstants::kNekUnsetDouble)
Constructor defining the number and distribution of points.
Definition: Points.h:78
3D Evenly-spaced points on a Prism
Definition: PointsType.h:73
2D Evenly-spaced points on a Triangle
Definition: PointsType.h:70
virtual void Initialize(void)
Definition: Points.h:234
NekManager< PointsKey, NekMatrix< DataType >, PointsKey::opLess > m_InterpManager
Definition: Points.h:352
unsigned int GetTotNumPoints() const
Definition: Points.h:251
1D Array of constant elements with garbage collection and bounds checking.
Definition: SharedArray.hpp:59
PointsType GetPointsType() const
Definition: Points.h:111
2D Nodal Electrostatic Points on a Triangle
Definition: PointsType.h:68
Stores a set of points of datatype DataT, defined by a PointKey.
virtual void CalculateWeights()
Definition: Points.h:366