Nektar++
Loading...
Searching...
No Matches
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
44
46{
47
48/// Defines a specification for a set of points.
50{
51public:
52 // Used for looking up the creator. The creator for number of points
53 // can generate for any number, so we want the same creator called
54 // for all number.
55 struct opLess
56 {
58 const PointsKey &rhs) const;
59 };
60
61 /// Default constructor.
64 m_factor(NekConstants::kNekUnsetDouble)
65 {
66 }
67
68 /// Constructor defining the number and distribution of points.
69 PointsKey(const size_t &numpoints, const PointsType &pointstype,
71 : m_numpoints(numpoints), m_pointstype(pointstype), m_factor(factor)
72 {
73 }
74
75 /// Destructor.
76 virtual ~PointsKey()
77 {
78 }
79
80 /// Copy constructor.
81 PointsKey(const PointsKey &key) = default;
82
83 PointsKey &operator=(const PointsKey &key) = default;
84
85 inline size_t GetNumPoints() const
86 {
87 return m_numpoints;
88 }
89
91 {
92 return m_pointstype;
93 }
94
95 inline NekDouble GetFactor() const
96 {
97 return m_factor;
98 }
99
100 inline bool operator==(const PointsKey &key)
101 {
102
104 {
105 return (m_numpoints == key.m_numpoints &&
107 }
108
109 return false;
110 }
111
112 inline bool operator==(const PointsKey *y)
113 {
114 return (*this == *y);
115 }
116
117 inline bool operator!=(const PointsKey &y)
118 {
119 return (!(*this == y));
120 }
121
122 inline bool operator!=(const PointsKey *y)
123 {
124 return (!(*this == *y));
125 }
126
127 // If new points are added, this function must be modified
128 inline size_t GetPointsDim() const
129 {
130 size_t dimpoints = 1;
131
132 switch (m_pointstype)
133 {
134 case eNodalTriElec:
135 case eNodalTriFekete:
137 case eNodalTriSPI:
138 case eNodalQuadElec:
139 dimpoints = 2;
140 break;
141
142 case eNodalTetElec:
145 case eNodalPrismElec:
146 case eNodalHexElec:
147 dimpoints = 3;
148 break;
149
150 default:
151 break;
152 }
153
154 return dimpoints;
155 }
156
157 // If new points are added, this function must be modified
158 inline size_t GetTotNumPoints() const
159 {
160 size_t totpoints = m_numpoints;
161
162 switch (m_pointstype)
163 {
164 case eNodalTriElec:
165 case eNodalTriFekete:
167 totpoints = m_numpoints * (m_numpoints + 1) / 2;
168 break;
169 case eNodalTriSPI:
171 "This method cannot be implemented");
172 break;
173
174 case eNodalQuadElec:
175 totpoints = m_numpoints * m_numpoints;
176 break;
177
178 case eNodalTetElec:
180 totpoints =
181 m_numpoints * (m_numpoints + 1) * (m_numpoints + 2) / 6;
182 break;
183 case eNodalTetSPI:
185 "This method cannot be implemented");
186 break;
187
189 case eNodalPrismElec:
190 totpoints = m_numpoints * m_numpoints * (m_numpoints + 1) / 2;
191 break;
192 case eNodalPrismSPI:
194 "This method cannot be implemented");
195 break;
196
197 case eNodalHexElec:
198 totpoints = m_numpoints * m_numpoints * m_numpoints;
199 break;
200
201 default:
202 break;
203 }
204
205 return totpoints;
206 }
207
208 LIB_UTILITIES_EXPORT friend bool operator==(const PointsKey &lhs,
209 const PointsKey &rhs);
210 LIB_UTILITIES_EXPORT friend bool operator<(const PointsKey &lhs,
211 const PointsKey &rhs);
213 const PointsKey &lhs, const PointsKey &rhs) const;
214
215 // returns a new pointskey that has same accuracy but different type
217
218 /// offset the m_nq_begin and m_nq_end according to the points type
219 static inline void GetEffectiveQuadRange(
220 const LibUtilities::PointsKey &pkey, int &q_begin, int &q_end)
221 {
222 switch (pkey.GetPointsType())
223 {
225 {
226 q_begin = 1;
227 q_end = pkey.GetNumPoints();
228 }
229 break;
231 {
232 q_begin = 1;
233 q_end = pkey.GetNumPoints() - 1;
234 }
235 break;
236 default:
237 {
238 q_begin = 0;
239 q_end = pkey.GetNumPoints();
240 }
241 }
242 }
243
244 /// Get degree of exactness for quadrature points
245 static inline int GetDegreeOfExactness(const PointsType ptype,
246 const int npt)
247 {
248 switch (ptype)
249 {
252 {
253 return 2 * npt - 1;
254 }
256 {
257 return 2 * (npt - 2) - 1;
258 }
260 {
261 return 2 * (npt - 1) - 1;
262 }
267 case eGaussRadauMAlpha0Beta2:
268 case eGaussRadauMAlpha1Beta0:
269 case eGaussRadauMAlpha2Beta0:
270 {
271 return 2 * npt - 2;
272 }
275 {
276 return 2 * npt - 3;
277 }
278 case eGaussKronrodLegendre:
279 {
280 return 3 * (npt - 1) / 2 + 1;
281 }
284 {
285 return 3 * (npt - 2) / 2; // not for sure
286 }
288 {
289 return 3 * (npt - 3) / 2; // not for sure
290 }
291 default:
292 break; // make it happy
293 }
294 return npt;
295 }
296
297protected:
298 size_t m_numpoints; //!< number of the points (as appropriately
299 //!< defined for PointsType)
300 PointsType m_pointstype; //!< Type of Points
301 NekDouble m_factor; //!< optional factor
302private:
303};
304
306
308 const PointsKey &rhs);
309LIB_UTILITIES_EXPORT bool operator<(const PointsKey &lhs, const PointsKey &rhs);
310LIB_UTILITIES_EXPORT std::ostream &operator<<(std::ostream &os,
311 const PointsKey &rhs);
312
313typedef std::vector<PointsKey> PointsKeyVector;
314
315/// Stores a set of points of datatype DataT, defined by a PointKey.
316template <typename DataT> class Points
317{
318public:
319 typedef DataT DataType;
320 typedef std::shared_ptr<NekMatrix<DataType>> MatrixSharedPtrType;
321
322 virtual ~Points()
323 {
324 }
325
326 inline void Initialize(void)
327 {
328 v_Initialize();
329 }
330
331 inline size_t GetPointsDim() const
332 {
333 return m_pointsKey.GetPointsDim();
334 }
335
336 inline size_t GetNumPoints() const
337 {
338 return m_pointsKey.GetNumPoints();
339 }
340
341 inline size_t GetTotNumPoints() const
342 {
344 }
345
347 {
348 return m_pointsKey.GetPointsType();
349 }
350
351 inline const Array<OneD, const DataType> &GetZ() const
352 {
353 return m_points[0];
354 }
355
356 inline const Array<OneD, const DataType> &GetW() const
357 {
358 return m_weights;
359 }
360
363 {
364 z = m_points[0];
365 w = m_weights;
366 }
367
369 {
370 return m_bcweights;
371 }
372
374 {
375 x = m_points[0];
376 }
377
380 {
381 x = m_points[0];
382 y = m_points[1];
383 }
384
388 {
389 x = m_points[0];
390 y = m_points[1];
391 z = m_points[2];
392 }
393
394 inline const MatrixSharedPtrType &GetD(Direction dir = xDir) const
395 {
396 return m_derivmatrix[(int)dir];
397 }
398
400 {
401 return v_GetI(key);
402 }
403
405 {
406 return v_GetI(x);
407 }
408
409 const MatrixSharedPtrType GetI(size_t uint,
411 {
412 return v_GetI(uint, x);
413 }
414
417 {
418 return v_GetI(x, y);
419 }
420
424 {
425 return v_GetI(x, y, z);
426 }
427
429 {
430 return v_GetGalerkinProjection(pkey);
431 }
432
433protected:
434 /// Points type for this points distributions.
436 /// Storage for the point locations, allowing for up to a 3D points
437 /// storage.
439 /// Quadrature weights for the weights.
441 /// Barycentric weights.
443 /// Derivative matrices.
449
450 virtual void v_Initialize(void)
451 {
454 v_CalculateBaryWeights();
455 v_CalculateDerivMatrix();
456 }
457
458 virtual void v_CalculatePoints()
459 {
460 size_t pointsDim = GetPointsDim();
461 size_t totNumPoints = GetTotNumPoints();
462
463 for (size_t i = 0; i < pointsDim; ++i)
464 {
465 m_points[i] = Array<OneD, DataType>(totNumPoints);
466 }
467 }
468
473
474 /**
475 * @brief This function calculates the barycentric weights used for
476 * enhanced interpolation speed.
477 *
478 * For the points distribution \f$ z_i \f$ with \f% 1\leq z_i \leq N
479 * \f$, the barycentric weights are computed as:
480 *
481 * \f[
482 * b_i=\prod_{\substack{1\leq j\leq N\\ i\neq j}} \frac{1}{z_i-z_j}
483 * \f]
484 */
485 virtual void v_CalculateBaryWeights()
486 {
487 const size_t totNumPoints = m_pointsKey.GetNumPoints();
488 m_bcweights = Array<OneD, DataType>(totNumPoints, 1.0);
489
491
492 for (size_t i = 0; i < totNumPoints; ++i)
493 {
494 for (size_t j = 0; j < totNumPoints; ++j)
495 {
496 if (i == j)
497 {
498 continue;
499 }
500
501 m_bcweights[i] *= (z[i] - z[j]);
502 }
503
504 m_bcweights[i] = 1.0 / m_bcweights[i];
505 }
506 }
507
508 virtual void v_CalculateDerivMatrix()
509 {
510 size_t totNumPoints = GetTotNumPoints();
511 for (size_t i = 0; i < m_pointsKey.GetPointsDim(); ++i)
512 {
513 m_derivmatrix[i] =
514 MemoryManager<NekMatrix<DataType>>::AllocateSharedPtr(
515 totNumPoints, totNumPoints);
516 }
517 }
518
519 Points(const PointsKey &key) : m_pointsKey(key)
520 {
521 }
522
523 virtual const MatrixSharedPtrType v_GetI(
524 [[maybe_unused]] const PointsKey &key)
525 {
526 NEKERROR(ErrorUtil::efatal, "Method not implemented ");
527 std::shared_ptr<NekMatrix<NekDouble>> returnval(
528 MemoryManager<NekMatrix<NekDouble>>::AllocateSharedPtr());
529 return returnval;
530 }
531
532 virtual const MatrixSharedPtrType v_GetI(
533 [[maybe_unused]] const Array<OneD, const DataType> &x)
534 {
535 NEKERROR(ErrorUtil::efatal, "Method not implemented");
536 std::shared_ptr<NekMatrix<NekDouble>> returnval(
537 MemoryManager<NekMatrix<NekDouble>>::AllocateSharedPtr());
538 return returnval;
539 }
540
541 virtual const MatrixSharedPtrType v_GetI(
542 size_t, [[maybe_unused]] const Array<OneD, const DataType> &x)
543 {
544 NEKERROR(ErrorUtil::efatal, "Method not implemented");
545 std::shared_ptr<NekMatrix<NekDouble>> returnval(
546 MemoryManager<NekMatrix<NekDouble>>::AllocateSharedPtr());
547 return returnval;
548 }
549
550 virtual const MatrixSharedPtrType v_GetI(
551 [[maybe_unused]] const Array<OneD, const DataType> &x,
552 [[maybe_unused]] const Array<OneD, const DataType> &y)
553 {
554 NEKERROR(ErrorUtil::efatal, "Method not implemented");
555 std::shared_ptr<NekMatrix<NekDouble>> returnval(
556 MemoryManager<NekMatrix<NekDouble>>::AllocateSharedPtr());
557 return returnval;
558 }
559
560 virtual const MatrixSharedPtrType v_GetI(
561 [[maybe_unused]] const Array<OneD, const DataType> &x,
562 [[maybe_unused]] const Array<OneD, const DataType> &y,
563 [[maybe_unused]] const Array<OneD, const DataType> &z)
564 {
565 NEKERROR(ErrorUtil::efatal, "Method not implemented");
566 std::shared_ptr<NekMatrix<NekDouble>> returnval(
567 MemoryManager<NekMatrix<NekDouble>>::AllocateSharedPtr());
568 return returnval;
569 }
570
571 virtual const MatrixSharedPtrType v_GetGalerkinProjection(
572 [[maybe_unused]] const PointsKey &pkey)
573 {
574 NEKERROR(ErrorUtil::efatal, "Method not implemented ");
575 std::shared_ptr<NekMatrix<NekDouble>> returnval(
576 MemoryManager<NekMatrix<NekDouble>>::AllocateSharedPtr());
577 return returnval;
578 }
579
580private:
581 Points(const Points &pts) = delete;
582 Points() = delete;
583};
584
585} // namespace Nektar::LibUtilities
586
587#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...
#define LIB_UTILITIES_EXPORT
std::shared_ptr< NekMatrix< NekDouble > > MatrixSharedPtrType
Stores a set of points of datatype DataT, defined by a PointKey.
Definition Points.h:317
Array< OneD, DataType > m_points[3]
Storage for the point locations, allowing for up to a 3D points storage.
Definition Points.h:438
MatrixSharedPtrType m_derivmatrix[3]
Derivative matrices.
Definition Points.h:444
NekManager< PointsKey, NekMatrix< DataType >, PointsKey::opLess > m_InterpManager
Definition Points.h:446
size_t GetPointsDim() const
Definition Points.h:331
void GetPoints(Array< OneD, const DataType > &x, Array< OneD, const DataType > &y) const
Definition Points.h:378
NekManager< PointsKey, NekMatrix< DataType >, PointsKey::opLess > m_GalerkinProjectionManager
Definition Points.h:448
virtual void v_CalculatePoints()
Definition Points.h:458
const MatrixSharedPtrType GetI(size_t uint, const Array< OneD, const DataType > &x)
Definition Points.h:409
size_t GetNumPoints() const
Definition Points.h:336
PointsKey m_pointsKey
Points type for this points distributions.
Definition Points.h:435
void GetZW(Array< OneD, const DataType > &z, Array< OneD, const DataType > &w) const
Definition Points.h:361
virtual void v_Initialize(void)
Definition Points.h:450
void GetPoints(Array< OneD, const DataType > &x) const
Definition Points.h:373
void GetPoints(Array< OneD, const DataType > &x, Array< OneD, const DataType > &y, Array< OneD, const DataType > &z) const
Definition Points.h:385
PointsType GetPointsType() const
Definition Points.h:346
const MatrixSharedPtrType GetI(const Array< OneD, const DataType > &x)
Definition Points.h:404
const Array< OneD, const DataType > & GetW() const
Definition Points.h:356
const Array< OneD, const NekDouble > & GetBaryWeights() const
Definition Points.h:368
const MatrixSharedPtrType GetI(const Array< OneD, const DataType > &x, const Array< OneD, const DataType > &y, const Array< OneD, const DataType > &z)
Definition Points.h:421
size_t GetTotNumPoints() const
Definition Points.h:341
std::shared_ptr< NekMatrix< DataType > > MatrixSharedPtrType
Definition Points.h:320
const MatrixSharedPtrType & GetD(Direction dir=xDir) const
Definition Points.h:394
Array< OneD, DataType > m_weights
Quadrature weights for the weights.
Definition Points.h:440
const MatrixSharedPtrType GetI(const Array< OneD, const DataType > &x, const Array< OneD, const DataType > &y)
Definition Points.h:415
const MatrixSharedPtrType GetI(const PointsKey &key)
Definition Points.h:399
const Array< OneD, const DataType > & GetZ() const
Definition Points.h:351
virtual void v_CalculateWeights()
Definition Points.h:469
const MatrixSharedPtrType GetGalerkinProjection(const PointsKey &pkey)
Definition Points.h:428
Array< OneD, DataType > m_bcweights
Barycentric weights.
Definition Points.h:442
Defines a specification for a set of points.
Definition Points.h:50
static void GetEffectiveQuadRange(const LibUtilities::PointsKey &pkey, int &q_begin, int &q_end)
offset the m_nq_begin and m_nq_end according to the points type
Definition Points.h:219
size_t m_numpoints
number of the points (as appropriately defined for PointsType)
Definition Points.h:298
bool operator==(const PointsKey *y)
Definition Points.h:112
PointsKey GetEquivalentPointsKey(const PointsType ptype)
size_t GetPointsDim() const
Definition Points.h:128
PointsKey(const PointsKey &key)=default
Copy constructor.
PointsType GetPointsType() const
Definition Points.h:90
PointsKey & operator=(const PointsKey &key)=default
friend bool opLess::operator()(const PointsKey &lhs, const PointsKey &rhs) const
friend bool operator<(const PointsKey &lhs, const PointsKey &rhs)
PointsType m_pointstype
Type of Points.
Definition Points.h:300
PointsKey(const size_t &numpoints, const PointsType &pointstype, const NekDouble factor=NekConstants::kNekUnsetDouble)
Constructor defining the number and distribution of points.
Definition Points.h:69
size_t GetTotNumPoints() const
Definition Points.h:158
bool operator==(const PointsKey &key)
Definition Points.h:100
size_t GetNumPoints() const
Definition Points.h:85
NekDouble GetFactor() const
Definition Points.h:95
NekDouble m_factor
optional factor
Definition Points.h:301
static int GetDegreeOfExactness(const PointsType ptype, const int npt)
Get degree of exactness for quadrature points.
Definition Points.h:245
friend bool operator==(const PointsKey &lhs, const PointsKey &rhs)
virtual ~PointsKey()
Destructor.
Definition Points.h:76
bool operator!=(const PointsKey &y)
Definition Points.h:117
PointsKey(void)
Default constructor.
Definition Points.h:62
bool operator!=(const PointsKey *y)
Definition Points.h:122
bool operator==(const BasisKey &x, const BasisKey &y)
bool operator<(const BasisKey &lhs, const BasisKey &rhs)
std::vector< PointsKey > PointsKeyVector
Definition Points.h:313
std::ostream & operator<<(std::ostream &os, const BasisKey &rhs)
@ eNodalPrismEvenlySpaced
3D Evenly-spaced points on a Prism
Definition PointsType.h:86
@ eNodalTriFekete
2D Nodal Fekete Points on a Triangle
Definition PointsType.h:82
@ eGaussRadauMLegendre
1D Gauss-Radau-Legendre quadrature points, pinned at x=-1
Definition PointsType.h:47
@ eGaussLegendreWithMP
1D Gauss-Legendre quadrature points with additional x=-1 and x=1 end points
Definition PointsType.h:95
@ eNodalPrismSPI
3D prism SPI
Definition PointsType.h:92
@ eGaussRadauMAlpha0Beta1
Gauss Radau pinned at x=-1,.
Definition PointsType.h:58
@ eGaussRadauKronrodMLegendre
1D Gauss-Radau-Kronrod-Legendre quadrature points, pinned at x=-1
Definition PointsType.h:67
@ eGaussLobattoChebyshev
1D Gauss-Lobatto-Legendre quadrature points
Definition PointsType.h:57
@ eNodalTriElec
2D Nodal Electrostatic Points on a Triangle
Definition PointsType.h:81
@ eNodalTriEvenlySpaced
2D Evenly-spaced points on a Triangle
Definition PointsType.h:83
@ eNodalHexElec
3D GLL for hex
Definition PointsType.h:94
@ eGaussRadauMChebyshev
1D Gauss-Radau-Chebyshev quadrature points, pinned at x=-1
Definition PointsType.h:53
@ eGaussRadauKronrodMAlpha1Beta0
1D Gauss-Radau-Kronrod-Legendre pinned at x=-1,
Definition PointsType.h:69
@ eGaussLobattoLegendre
1D Gauss-Lobatto-Legendre quadrature points
Definition PointsType.h:51
@ eGaussLegendreWithM
1D Gauss-Legendre quadrature points with additional x=-1 point
Definition PointsType.h:97
@ eNodalQuadElec
2D GLL for quad
Definition PointsType.h:93
@ eNodalTetEvenlySpaced
3D Evenly-spaced points on a Tetrahedron
Definition PointsType.h:84
@ eGaussGaussChebyshev
1D Gauss-Gauss-Chebyshev quadrature points
Definition PointsType.h:52
@ eNodalTetSPI
3D Nodal Symmetric positive internal tet (Whitherden, Vincent)
Definition PointsType.h:90
@ eGaussLobattoKronrodLegendre
1D Lobatto Kronrod quadrature points
Definition PointsType.h:72
@ eGaussGaussLegendre
1D Gauss-Gauss-Legendre quadrature points
Definition PointsType.h:46
@ eNodalPrismElec
3D electrostatically spaced points on a Prism
Definition PointsType.h:87
@ eNodalTetElec
3D Nodal Electrostatic Points on a Tetrahedron
Definition PointsType.h:85
@ eGaussRadauPLegendre
1D Gauss-Radau-Legendre quadrature points, pinned at x=1
Definition PointsType.h:49
@ eNodalTriSPI
2D Nodal Symmetric positive internal triangle (Whitherden, Vincent)
Definition PointsType.h:88
static const PointsKey NullPointsKey(0, eNoPointsType)
static const NekDouble kNekUnsetDouble
static const NekDouble kNekZeroTol
bool operator()(const PointsKey &lhs, const PointsKey &rhs) const