Nektar++
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | List of all members
Nektar::LibUtilities::NodalUtilTetrahedron Class Reference

Specialisation of the NodalUtil class to support nodal tetrahedral elements. More...

#include <NodalUtil.h>

Inheritance diagram for Nektar::LibUtilities::NodalUtilTetrahedron:
[legend]

Public Member Functions

 NodalUtilTetrahedron (size_t degree, Array< OneD, NekDouble > r, Array< OneD, NekDouble > s, Array< OneD, NekDouble > t)
 Construct the nodal utility class for a tetrahedron.
 
 ~NodalUtilTetrahedron () override
 
- Public Member Functions inherited from Nektar::LibUtilities::NodalUtil
virtual ~NodalUtil ()=default
 
NekVector< NekDouble > GetWeights ()
 Obtain the integration weights for the given nodal distribution.
 
SharedMatrix GetVandermonde ()
 Return the Vandermonde matrix for the nodal distribution.
 
SharedMatrix GetVandermondeForDeriv (size_t dir)
 Return the Vandermonde matrix of the derivative of the basis functions for the nodal distribution.
 
SharedMatrix GetDerivMatrix (size_t dir)
 Return the derivative matrix for the nodal distribution.
 
SharedMatrix GetInterpolationMatrix (Array< OneD, Array< OneD, NekDouble > > &xi)
 Construct the interpolation matrix used to evaluate the basis at the points xi inside the element.
 

Static Public Member Functions

static void CartesianOrdering (const int nq, Array< OneD, int > &sorted)
 

Protected Member Functions

NekVector< NekDouble > v_OrthoBasis (const size_t mode) override
 Return the value of the modal functions for the tetrahedral element at the nodal points m_xi for a given mode.
 
NekVector< NekDouble > v_OrthoBasisDeriv (const size_t dir, const size_t mode) override
 Return the value of the derivative of the modal functions for the tetrahedral element at the nodal points m_xi for a given mode.
 
std::shared_ptr< NodalUtil > v_CreateUtil (Array< OneD, Array< OneD, NekDouble > > &xi) override
 Construct a NodalUtil object of the appropriate element type for a given set of points.
 
NekDouble v_ModeZeroIntegral () override
 Return the value of the integral of the zero-th mode for this element.
 
size_t v_NumModes () override
 Calculate the number of degrees of freedom for this element.
 
- Protected Member Functions inherited from Nektar::LibUtilities::NodalUtil
 NodalUtil (size_t degree, size_t dim)
 Set up the NodalUtil object.
 

Protected Attributes

std::vector< Mode > m_ordering
 Mapping from the \( (i,j,k) \) indexing of the basis to a continuous ordering.
 
Array< OneD, Array< OneD, NekDouble > > m_eta
 Collapsed coordinates \( (\eta_1, \eta_2, \eta_3) \) of the nodal points.
 
- Protected Attributes inherited from Nektar::LibUtilities::NodalUtil
size_t m_dim
 Dimension of the nodal element.
 
size_t m_degree
 Degree of the nodal element.
 
size_t m_numPoints
 Total number of nodal points.
 
Array< OneD, Array< OneD, NekDouble > > m_xi
 Coordinates of the nodal points defining the basis.
 

Private Types

typedef std::tuple< int, int, int > Mode
 

Detailed Description

Specialisation of the NodalUtil class to support nodal tetrahedral elements.

Definition at line 240 of file NodalUtil.h.

Member Typedef Documentation

◆ Mode

typedef std::tuple<int, int, int> Nektar::LibUtilities::NodalUtilTetrahedron::Mode
private

Definition at line 242 of file NodalUtil.h.

Constructor & Destructor Documentation

◆ NodalUtilTetrahedron()

Nektar::LibUtilities::NodalUtilTetrahedron::NodalUtilTetrahedron ( size_t  degree,
Array< OneD, NekDouble >  r,
Array< OneD, NekDouble >  s,
Array< OneD, NekDouble >  t 
)

Construct the nodal utility class for a tetrahedron.

The constructor of this class sets up two member variables used in the evaluation of the orthogonal basis:

  • NodalUtilTetrahedron::m_eta is used to construct the collapsed coordinate locations of the nodal points \( (\eta_1, \eta_2, \eta_3) \) inside the cube \([-1,1]^3\) on which the orthogonal basis functions are defined.
  • NodalUtilTetrahedron::m_ordering constructs a mapping from the index set \( I = \{ (i,j,k)\ |\ 0\leq i,j,k \leq P, i+j \leq P, i+j+k \leq P \}\) to an ordering \( 0 \leq m(ijk) \leq (P+1)(P+2)(P+3)/6 \) that defines the monomials \( \xi_1^i \xi_2^j \xi_3^k \) that span the tetrahedral space. This is then used to calculate which \( (i,j,k) \) triple (represented as a tuple) corresponding to a column of the Vandermonde matrix when calculating the orthogonal polynomials.
Parameters
degreePolynomial order of this nodal tetrahedron
r\( \xi_1 \)-coordinates of nodal points in the standard element.
s\( \xi_2 \)-coordinates of nodal points in the standard element.
t\( \xi_3 \)-coordinates of nodal points in the standard element.

Definition at line 411 of file NodalUtil.cpp.

415 : NodalUtil(degree, 3), m_eta(3)
416{
417 m_numPoints = r.size();
418 m_xi[0] = r;
419 m_xi[1] = s;
420 m_xi[2] = t;
421
422 for (size_t i = 0; i <= m_degree; ++i)
423 {
424 for (size_t j = 0; j <= m_degree - i; ++j)
425 {
426 for (size_t k = 0; k <= m_degree - i - j; ++k)
427 {
428 m_ordering.push_back(Mode(i, j, k));
429 }
430 }
431 }
432
433 // Calculate collapsed coordinates from r/s values
434 m_eta[0] = Array<OneD, NekDouble>(m_numPoints);
435 m_eta[1] = Array<OneD, NekDouble>(m_numPoints);
436 m_eta[2] = Array<OneD, NekDouble>(m_numPoints);
437
438 for (size_t i = 0; i < m_numPoints; ++i)
439 {
440 if (fabs(m_xi[2][i] - 1.0) < NekConstants::kNekZeroTol)
441 {
442 // Very top point of the tetrahedron
443 m_eta[0][i] = -1.0;
444 m_eta[1][i] = -1.0;
445 m_eta[2][i] = m_xi[2][i];
446 }
447 else
448 {
449 if (fabs(m_xi[1][i] - 1.0) < NekConstants::kNekZeroTol)
450 {
451 // Distant diagonal edge shared by all eta_x coordinate planes:
452 // the xi_y == -xi_z line
453 m_eta[0][i] = -1.0;
454 }
455 else if (fabs(m_xi[1][i] + m_xi[2][i]) < NekConstants::kNekZeroTol)
456 {
457 m_eta[0][i] = -1.0;
458 }
459 else
460 {
461 m_eta[0][i] =
462 2.0 * (1.0 + m_xi[0][i]) / (-m_xi[1][i] - m_xi[2][i]) - 1.0;
463 }
464 m_eta[1][i] = 2.0 * (1.0 + m_xi[1][i]) / (1.0 - m_xi[2][i]) - 1.0;
465 m_eta[2][i] = m_xi[2][i];
466 }
467 }
468}
Array< OneD, Array< OneD, NekDouble > > m_xi
Coordinates of the nodal points defining the basis.
Definition NodalUtil.h:107
size_t m_degree
Degree of the nodal element.
Definition NodalUtil.h:103
size_t m_numPoints
Total number of nodal points.
Definition NodalUtil.h:105
NodalUtil(size_t degree, size_t dim)
Set up the NodalUtil object.
Definition NodalUtil.h:95
std::tuple< int, int, int > Mode
Definition NodalUtil.h:242
Array< OneD, Array< OneD, NekDouble > > m_eta
Collapsed coordinates of the nodal points.
Definition NodalUtil.h:319
std::vector< Mode > m_ordering
Mapping from the indexing of the basis to a continuous ordering.
Definition NodalUtil.h:315
static const NekDouble kNekZeroTol

References Nektar::NekConstants::kNekZeroTol, Nektar::LibUtilities::NodalUtil::m_degree, m_eta, Nektar::LibUtilities::NodalUtil::m_numPoints, m_ordering, and Nektar::LibUtilities::NodalUtil::m_xi.

◆ ~NodalUtilTetrahedron()

Nektar::LibUtilities::NodalUtilTetrahedron::~NodalUtilTetrahedron ( )
inlineoverride

Definition at line 250 of file NodalUtil.h.

251 {
252 }

Member Function Documentation

◆ CartesianOrdering()

static void Nektar::LibUtilities::NodalUtilTetrahedron::CartesianOrdering ( const int  nq,
Array< OneD, int > &  sorted 
)
inlinestatic

Definition at line 256 of file NodalUtil.h.

258 {
259 sorted = Array<OneD, int>(nq * (nq + 1) * (nq + 2) / 6, -1);
260 int cnt = 0;
261 sorted[cnt++] = 0; /* vertex 0 */
262 for (int i = 0; i < nq - 2; ++i) // edge 0
263 {
264 sorted[cnt++] = 4 + i;
265 }
266 sorted[cnt++] = 1; // vertex 1
267 int cnt1 = 0;
268 for (int j = 0; j < nq - 2; ++j)
269 {
270 sorted[cnt++] = 4 + 2 * (nq - 2) + j; // edge 2
271 for (int i = 0; i < nq - 3 - j; ++i) // face 0
272 {
273 sorted[cnt++] = 4 + 6 * (nq - 2) + cnt1++;
274 }
275 sorted[cnt++] = 4 + (nq - 2) + j; // edge 1
276 }
277 sorted[cnt++] = 2; /* vertex 2 */
278
279 cnt1 = 0;
280 int cnt2 = 0;
281 int cnt3 = 0;
282 int cint = 0;
283 for (int k = 0; k < nq - 2; ++k)
284 {
285 sorted[cnt++] = 4 + 3 * (nq - 2) + k; // edge 3
286 for (int i = 0; i < nq - 3 - k; ++i) // face 1
287 {
288 sorted[cnt++] =
289 4 + 6 * (nq - 2) + (nq - 3) * (nq - 2) / 2 + cnt1++;
290 }
291 sorted[cnt++] = 4 + 4 * (nq - 2) + k; // edge 4
292
293 for (int j = 0; j < nq - 3 - k; ++j)
294 {
295 sorted[cnt++] = 4 + 6 * (nq - 2) + 3 * (nq - 3) * (nq - 2) / 2 +
296 cnt3++; // face 3
297 for (int i = 0; i < nq - 4 - k - j; ++i) /* int */
298 {
299 sorted[cnt++] =
300 4 + 6 * (nq - 2) + 4 * (nq - 3) * (nq - 2) / 2 + cint++;
301 }
302 sorted[cnt++] = 4 + 6 * (nq - 2) + 2 * (nq - 3) * (nq - 2) / 2 +
303 cnt2++; // face 2
304 }
305 sorted[cnt++] = 4 + 5 * (nq - 2) + k; // edge 5
306 }
307 sorted[cnt++] = 3; /* vertex 3 */
308 ASSERTL1(cnt == nq * (nq + 1) * (nq + 2) / 6,
309 "No of sorted points not the same as number in expansion");
310 }
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....

References ASSERTL1.

Referenced by Nektar::QuadEquiSpaced::BOOST_AUTO_TEST_CASE(), Nektar::QuadEquiSpaced::BOOST_AUTO_TEST_CASE(), and Nektar::StdRegions::StdTetExp::v_GenMatrix().

◆ v_CreateUtil()

std::shared_ptr< NodalUtil > Nektar::LibUtilities::NodalUtilTetrahedron::v_CreateUtil ( Array< OneD, Array< OneD, NekDouble > > &  xi)
inlineoverrideprotectedvirtual

Construct a NodalUtil object of the appropriate element type for a given set of points.

This function is used inside NodalUtil::GetInterpolationMatrix so that the (potentially non-square) Vandermonde matrix can be constructed to create the interpolation matrix at an arbitrary set of points in the domain.

Parameters
xiDistribution of nodal points to create utility with.

Implements Nektar::LibUtilities::NodalUtil.

Definition at line 325 of file NodalUtil.h.

327 {
329 m_degree, xi[0], xi[1], xi[2]);
330 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), and Nektar::LibUtilities::NodalUtil::m_degree.

◆ v_ModeZeroIntegral()

NekDouble Nektar::LibUtilities::NodalUtilTetrahedron::v_ModeZeroIntegral ( )
inlineoverrideprotectedvirtual

Return the value of the integral of the zero-th mode for this element.

Note that for the orthogonal basis under consideration, all modes integrate to zero asides from the zero-th mode. This function is used in NodalUtil::GetWeights to determine integration weights.

Implements Nektar::LibUtilities::NodalUtil.

Definition at line 332 of file NodalUtil.h.

333 {
334 return 8.0 * sqrt(2.0) / 3.0;
335 }
scalarT< T > sqrt(scalarT< T > in)
Definition scalar.hpp:289

References tinysimd::sqrt().

◆ v_NumModes()

size_t Nektar::LibUtilities::NodalUtilTetrahedron::v_NumModes ( )
inlineoverrideprotectedvirtual

Calculate the number of degrees of freedom for this element.

Implements Nektar::LibUtilities::NodalUtil.

Definition at line 337 of file NodalUtil.h.

338 {
339 return (m_degree + 1) * (m_degree + 2) * (m_degree + 3) / 6;
340 }

References Nektar::LibUtilities::NodalUtil::m_degree.

◆ v_OrthoBasis()

NekVector< NekDouble > Nektar::LibUtilities::NodalUtilTetrahedron::v_OrthoBasis ( const size_t  mode)
overrideprotectedvirtual

Return the value of the modal functions for the tetrahedral element at the nodal points m_xi for a given mode.

In a tetrahedron, we use the orthogonal basis

\[ \psi_{m(ijk)} = \sqrt{8} P^{(0,0)}_i(\xi_1) P_j^{(2i+1,0)}(\xi_2) P_k^{(2i+2j+2,0)}(\xi_3) (1-\xi_2)^i (1-\xi_3)^{i+j} \]

where \( m(ijk) \) is the mapping defined in m_ordering and \( J_n^{(\alpha,\beta)}(z) \) denotes the standard Jacobi polynomial.

Parameters
modeThe mode of the orthogonal basis to evaluate.
Returns
Vector containing orthogonal basis evaluated at the points m_xi.

Implements Nektar::LibUtilities::NodalUtil.

Definition at line 486 of file NodalUtil.cpp.

487{
488 std::vector<NekDouble> jacA(m_numPoints), jacB(m_numPoints);
489 std::vector<NekDouble> jacC(m_numPoints);
490
491 size_t I, J, K;
492 std::tie(I, J, K) = m_ordering[mode];
493
494 // Calculate Jacobi polynomials
495 Polylib::jacobfd(m_numPoints, &m_eta[0][0], &jacA[0], nullptr, I, 0.0, 0.0);
496 Polylib::jacobfd(m_numPoints, &m_eta[1][0], &jacB[0], nullptr, J,
497 2.0 * I + 1.0, 0.0);
498 Polylib::jacobfd(m_numPoints, &m_eta[2][0], &jacC[0], nullptr, K,
499 2.0 * (I + J) + 2.0, 0.0);
500
501 NekVector<NekDouble> ret(m_numPoints);
502 NekDouble sqrt8 = sqrt(8.0);
503
504 for (size_t i = 0; i < m_numPoints; ++i)
505 {
506 ret[i] = sqrt8 * jacA[i] * jacB[i] * jacC[i] *
507 pow(1.0 - m_eta[1][i], I) * pow(1.0 - m_eta[2][i], I + J);
508 }
509
510 return ret;
511}
void jacobfd(const int np, const double *z, double *poly_in, double *polyd, const int n, const double alpha, const double beta)
Routine to calculate Jacobi polynomials, , and their first derivative, .
Definition Polylib.cpp:1249

References Polylib::jacobfd(), m_eta, Nektar::LibUtilities::NodalUtil::m_numPoints, m_ordering, and tinysimd::sqrt().

◆ v_OrthoBasisDeriv()

NekVector< NekDouble > Nektar::LibUtilities::NodalUtilTetrahedron::v_OrthoBasisDeriv ( const size_t  dir,
const size_t  mode 
)
overrideprotectedvirtual

Return the value of the derivative of the modal functions for the tetrahedral element at the nodal points m_xi for a given mode.

Note that this routine must use the chain rule combined with the collapsed coordinate derivatives as described in Sherwin & Karniadakis (2nd edition), pg 152.

Parameters
dirCoordinate direction in which to evaluate the derivative.
modeThe mode of the orthogonal basis to evaluate.
Returns
Vector containing the derivative of the orthogonal basis evaluated at the points m_xi.

Implements Nektar::LibUtilities::NodalUtil.

Definition at line 527 of file NodalUtil.cpp.

529{
530 std::vector<NekDouble> jacA(m_numPoints), jacB(m_numPoints);
531 std::vector<NekDouble> jacC(m_numPoints);
532 std::vector<NekDouble> jacDerivA(m_numPoints), jacDerivB(m_numPoints);
533 std::vector<NekDouble> jacDerivC(m_numPoints);
534
535 size_t I, J, K;
536 std::tie(I, J, K) = m_ordering[mode];
537
538 // Calculate Jacobi polynomials
539 Polylib::jacobfd(m_numPoints, &m_eta[0][0], &jacA[0], nullptr, I, 0.0, 0.0);
540 Polylib::jacobfd(m_numPoints, &m_eta[1][0], &jacB[0], nullptr, J,
541 2.0 * I + 1.0, 0.0);
542 Polylib::jacobfd(m_numPoints, &m_eta[2][0], &jacC[0], nullptr, K,
543 2.0 * (I + J) + 2.0, 0.0);
544 Polylib::jacobd(m_numPoints, &m_eta[0][0], &jacDerivA[0], I, 0.0, 0.0);
545 Polylib::jacobd(m_numPoints, &m_eta[1][0], &jacDerivB[0], J, 2.0 * I + 1.0,
546 0.0);
547 Polylib::jacobd(m_numPoints, &m_eta[2][0], &jacDerivC[0], K,
548 2.0 * (I + J) + 2.0, 0.0);
549
550 NekVector<NekDouble> ret(m_numPoints);
551 NekDouble sqrt8 = sqrt(8.0);
552
553 // Always compute x-derivative since this term appears in the latter two
554 // terms.
555 for (size_t i = 0; i < m_numPoints; ++i)
556 {
557 ret[i] = 4.0 * sqrt8 * jacDerivA[i] * jacB[i] * jacC[i];
558
559 if (I > 0)
560 {
561 ret[i] *= pow(1 - m_eta[1][i], I - 1);
562 }
563
564 if (I + J > 0)
565 {
566 ret[i] *= pow(1 - m_eta[2][i], I + J - 1);
567 }
568 }
569
570 if (dir >= 1)
571 {
572 // Multiply by (1+a)/2
573 NekVector<NekDouble> tmp(m_numPoints);
574
575 for (size_t i = 0; i < m_numPoints; ++i)
576 {
577 ret[i] *= 0.5 * (m_eta[0][i] + 1.0);
578
579 tmp[i] = 2.0 * sqrt8 * jacA[i] * jacC[i];
580 if (I + J > 0)
581 {
582 tmp[i] *= pow(1.0 - m_eta[2][i], I + J - 1);
583 }
584
585 NekDouble tmp2 = jacDerivB[i] * pow(1.0 - m_eta[1][i], I);
586 if (I > 0)
587 {
588 tmp2 -= I * jacB[i] * pow(1.0 - m_eta[1][i], I - 1);
589 }
590
591 tmp[i] *= tmp2;
592 }
593
594 if (dir == 1)
595 {
596 ret += tmp;
597 return ret;
598 }
599
600 for (size_t i = 0; i < m_numPoints; ++i)
601 {
602 ret[i] += 0.5 * (1.0 + m_eta[1][i]) * tmp[i];
603
604 NekDouble tmp2 = jacDerivC[i] * pow(1.0 - m_eta[2][i], I + J);
605 if (I + J > 0)
606 {
607 tmp2 -= jacC[i] * (I + J) * pow(1.0 - m_eta[2][i], I + J - 1);
608 }
609
610 ret[i] +=
611 sqrt8 * jacA[i] * jacB[i] * pow(1.0 - m_eta[1][i], I) * tmp2;
612 }
613 }
614
615 return ret;
616}
void jacobd(const int np, const double *z, double *polyd, const int n, const double alpha, const double beta)
Calculate the derivative of Jacobi polynomials.
Definition Polylib.cpp:1379

References Polylib::jacobd(), Polylib::jacobfd(), m_eta, Nektar::LibUtilities::NodalUtil::m_numPoints, m_ordering, and tinysimd::sqrt().

Member Data Documentation

◆ m_eta

Array<OneD, Array<OneD, NekDouble> > Nektar::LibUtilities::NodalUtilTetrahedron::m_eta
protected

Collapsed coordinates \( (\eta_1, \eta_2, \eta_3) \) of the nodal points.

Definition at line 319 of file NodalUtil.h.

Referenced by NodalUtilTetrahedron(), v_OrthoBasis(), and v_OrthoBasisDeriv().

◆ m_ordering

std::vector<Mode> Nektar::LibUtilities::NodalUtilTetrahedron::m_ordering
protected

Mapping from the \( (i,j,k) \) indexing of the basis to a continuous ordering.

Definition at line 315 of file NodalUtil.h.

Referenced by NodalUtilTetrahedron(), v_OrthoBasis(), and v_OrthoBasisDeriv().