Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
vulpes::monomial Namespace Reference

Namespaces

namespace  internal

Classes

class  Monomial
 Class representing a (possibly scaled) monomial. More...

Functions

template<typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
std::array< T, 2 > getMonomial2D (std::size_t n)
 Computes the 2D monomial exponents for a given linear index.
template<typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
std::array< T, 3 > getMonomial3D (std::size_t n)
 Computes the 3D monomial exponents for a given linear index.
template<std::size_t Dim, typename T>
std::array< T, Dim > getMonomial (std::size_t n)
 Computes the Dim-D monomial exponents for a given linear index.
template<std::size_t Dim, typename T>
T getLinearIndex (const std::array< T, Dim > &monomial)
 Computes the linear index given the exponents of the monomial.

Function Documentation

◆ getLinearIndex()

template<std::size_t Dim, typename T>
T vulpes::monomial::getLinearIndex ( const std::array< T, Dim > & monomial)
inline

Computes the linear index given the exponents of the monomial.

Note
The linear index is not upcasted, you may experience overflow errors if T is not wide enough (in terms of bits)

◆ getMonomial()

template<std::size_t Dim, typename T>
std::array< T, Dim > vulpes::monomial::getMonomial ( std::size_t n)
inline

Computes the Dim-D monomial exponents for a given linear index.

◆ getMonomial2D()

template<typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
std::array< T, 2 > vulpes::monomial::getMonomial2D ( std::size_t n)
inline

Computes the 2D monomial exponents for a given linear index.

Template Parameters
TThe integral type used for the return array elements.
DummyA dummy template parameter used for SFINAE (Substitution Failure Is Not An Error).
Parameters
nThe linear index for which the 2D monomial exponents are to be computed.
Returns
A std::array<T, 2> containing the monomial exponents \((i, j)\) corresponding to the input index \(n\).

This function calculates the exponents \(i\) and \(j\) for the monomial \(x^i y^j\) that corresponds to the linear index \(n\) in a 2D monomial ordering scheme. The function assumes the index \(n\) is non-negative and within the range where the floating-point precision of float is sufficient to handle the calculations. It uses a quadratic formula to determine the level of the monomial and then computes the specific exponents within that level. The triangle up to the \(s\)-th level contains \(s(s+1)/2\) elements

Example

  • For \(n = 0\), the result will be \((0, 0)\).
  • For \(n = 1\), the result will be \((1, 0)\).
  • For \(n = 2\), the result will be \((0, 1)\).

◆ getMonomial3D()

template<typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
std::array< T, 3 > vulpes::monomial::getMonomial3D ( std::size_t n)
inline

Computes the 3D monomial exponents for a given linear index.

Template Parameters
TThe integral type used for the return array elements.
DummyA dummy template parameter used for SFINAE (Substitution Failure Is Not An Error).
Parameters
nThe linear index for which the 3D monomial exponents are to be computed.
Returns
A std::array<T, 3> containing the monomial exponents \((i, j, k)\) corresponding to the input index \(n\).

This function calculates the exponents \(i\), \(j\), and \(k\) for the monomial \(x^i y^j z^k\) that corresponds to the linear index \(n\) in a 3D monomial ordering scheme. The function handles the case when \(n = 0\) by returning \((0, 0, 0)\), and for \(n > 0\), it uses a cubic root approximation and Newton's method to determine the pyramid level. Namely, the pyramid up to the \(s\)-th level contains \(s(s+1)(s+2)/6\) elements The specific exponents within that level are then computed using the getMonomial2D function for the residual index.

Example

  • For \(n = 0\), the result will be \((0, 0, 0)\).
  • For \(n = 1\), the result will be \((1, 0, 0)\).
  • For \(n = 2\), the result will be \((0, 1, 0)\).
  • For \(n = 3\), the result will be \((0, 0, 1)\).