polynomials_on_simplices.polynomial.polynomials_simplex_lagrange_basis module

Polynomials on an m-dimensional simplex T with values in \(\mathbb{R}^n\), expressed using the Lagrange basis.

\[\begin{split}l(x) = \sum_{\substack{\nu \in \mathbb{N}_0^m \\ |\nu| \leq r}} a_{\nu} l_{\nu, r}(x) = \sum_{\nu} a_{\nu} (\bar{l}_{\nu, r} \circ \Phi^{-1})(x),\end{split}\]

where \(a_{\nu} \in \mathbb{R}^n, \bar{l}_{\nu, r}\) is the Lagrange basis on the unit simplex and \(\Phi\) is the unique affine map which maps the unit simplex onto the simplex T (the i:th vertex of the unit simplex is mapped to the i:th vertex of the simplex T).

The basis polynomials \(l_{\nu, r} = \bar{l}_{\nu, r} \circ \Phi^{-1}\) satisfies

\[l_{\nu, r}(\Phi(x_{\mu}) = \delta_{\mu, \nu},\]

where \(x_{\mu}\) are the Lagrange points on the unit simplex.

The set \(\{ l_{\nu, r} \}_{\substack{\nu \in \mathbb{N}_0^m \\ |\nu| \leq r}}\) is a basis for the space of all polynomials of degree less than or equal to r on the simplex T, \(\mathcal{P}_r (T)\).

class PolynomialLagrangeSimplex(coeff, vertices, r=None)[source]

Bases: polynomials_on_simplices.polynomial.polynomials_simplex_base.PolynomialSimplexBase

Implementation of the abstract polynomial base class for a polynomial on an m-dimensional simplex T, expressed in the Lagrange basis.

\[l(x) = \sum_{i = 0}^{\dim(\mathcal{P}_r(\mathbb{R}^m)) - 1} a_{\nu_i} l_{\nu_i, r}(x).\]
Parameters:
  • coeff – Coefficients for the polynomial in the Lagrange basis for \(\mathcal{P}_r (T, \mathbb{R}^n). \text{coeff}[i] = a_{\nu_i}\), where \(\nu_i\) is the i:th multi-index in the sequence of all multi-indices of dimension m with norm \(\leq r\) (see polynomials_on_simplices.algebra.multiindex.generate() function). Array of scalars for a scalar valued polynomial (n = 1) and array of n-dimensional vectors for a vector valued polynomial (\(n \geq 2\)).
  • vertices – Vertices of the simplex T ((m + 1) x m matrix where row i contains the i:th vertex of the simplex).
  • r (int) – Degree of the polynomial space. Optional, will be inferred from the number of polynomial coefficients if not specified.
basis()[source]

Get basis for the space \(\mathcal{P}_r (\mathbb{R}^m)\) used to express this polynomial.

Returns:Unique identifier for the basis used.
Return type:str
code_str(fn_name)[source]

Generate a function code string for evaluating this polynomial.

Parameters:fn_name (str) – Name for the function in the generated code.
Returns:Code string for evaluating this polynomial.
Return type:str
degree_elevate(s)[source]

Express the polynomial using a higher degree basis.

Let \(p(x) = \sum_{\substack{\nu \in \mathbb{N}_0^m \\ |\nu| \leq r}} a_{\nu} l_{\nu, r}(x)\) be this polynomial, where \(\{ l_{\nu, r} \}_{\substack{\nu \in \mathbb{N}_0^m \\ |\nu| \leq r}}\) is the Lagrange basis for \(\mathcal{P}_r (T)\). Let \(\{ l_{\nu, s} \}_{\substack{\nu \in \mathbb{N}_0^m \\ |\nu| \leq s}}, s \geq r\) be the Lagrange basis for \(\mathcal{P}_s (T)\). Then this function returns a polynomial \(q(x)\)

\[\begin{split}q(x) = \sum_{\substack{\nu \in \mathbb{N}_0^m \\ |\nu| \leq s}} \tilde{a}_{\nu} l_{\nu, s}(x),\end{split}\]

such that \(p(x) = q(x) \, \forall x \in T\).

Parameters:s (int) – New degree for the polynomial basis the polynomial should be expressed in.
Returns:Elevation of this polynomial to the higher degree basis.
Return type:PolynomialLagrangeSimplex.
latex_str()[source]

Generate a Latex string for this polynomial.

Returns:Latex string for this polynomial.
Return type:str
latex_str_expanded()[source]

Generate a Latex string for this polynomial, where each basis function has been expanded in the monomial basis.

Returns:Latex string for this polynomial.
Return type:str
partial_derivative(i=0)[source]

Compute the i:th partial derivative of the polynomial.

Parameters:i (int) – Index of partial derivative.
Returns:i:th partial derivative of this polynomial.
Return type:PolynomialLagrangeSimplex.
to_monomial_basis()[source]

Compute the monomial representation of this polynomial.

Returns:This polynomial expressed in the monomial basis.
Return type:Polynomial.
dual_lagrange_basis_fn_simplex(mu, r, vertices)[source]

Generate a dual basis function to the Lagrange polynomial basis, i.e. the linear map \(q_{\mu, r} : \mathcal{P}_r(T) \to \mathbb{R}\) that satisfies

\[q_{\mu, r}(l_{\nu, r}) = \delta_{\mu, \nu},\]

where \(l_{\nu, r}\) is the degree r Lagrange basis polynomial on T indexed by the multi-index \(\nu\) (see lagrange_basis_fn_simplex()) and

\[\begin{split}\delta_{\mu, \nu} = \begin{cases} 1 & \mu = \nu \\ 0 & \text{else} \end{cases}.\end{split}\]
Parameters:
  • mu (int or MultiIndex or Tuple[int, …].) – Multi-index indicating which dual Lagrange basis function should be generated.
  • r (int) – Degree of polynomial space.
  • vertices – Vertices of the simplex T ((n + 1) x n matrix where row i contains the i:th vertex of the simplex).
Returns:

The dual Lagrange basis function as specified by mu and r.

Return type:

Callable \(q_{\mu, r}(l)\).

dual_lagrange_basis_simplex(r, vertices)[source]

Generate all dual Lagrange base functions for the space \(\mathcal{P}_r(T)\), where T is an n-dimensional simplex (i.e. the Lagrange basis for \(\mathcal{P}_r(T)^*\)).

See dual_lagrange_basis_fn_simplex().

Parameters:
  • r (int) – Degree of the polynomial space.
  • vertices – Vertices of the simplex T ((n + 1) x n matrix where row i contains the i:th vertex of the simplex).
Returns:

List of dual base functions.

Return type:

List[callable q(l)].

dual_vector_valued_lagrange_basis_fn_simplex(mu, r, i, vertices, n)[source]

Generate a dual basis function to the vector valued Lagrange polynomial basis, i.e. the linear map \(q_{\mu, r, i} : \mathcal{P}_r(T, \mathbb{R}^n) \to \mathbb{R}\) that satisfies

\[q_{\mu, r, i}(l_{\nu, r, j}) = \delta_{\mu, \nu} \delta_{i, j},\]

where \(l_{\nu, r, j}\) is the degree r vector valued Lagrange basis polynomial indexed by the multi-index \(\nu\) with a non-zero i:th component (see vector_valued_lagrange_basis_fn_simplex()) and

\[\begin{split}\delta_{\mu, \nu} = \begin{cases} 1 & \mu = \nu \\ 0 & \text{else} \end{cases}.\end{split}\]
Parameters:
  • mu (int or MultiIndex or Tuple[int, …].) – Multi-index indicating which dual Lagrange basis function should be generated.
  • r (int) – Degree of polynomial space.
  • i (int) – Integer indicating which dual Lagrange basis function should be generated.
  • vertices – Vertices of the simplex T ((m + 1) x m matrix where row i contains the i:th vertex of the simplex).
  • n (int) – Dimension of the target.
Returns:

The dual Lagrange basis function as specified by mu, r and i.

Return type:

Callable \(q_{\mu, r, i}(l)\).

dual_vector_valued_lagrange_basis_simplex(r, vertices, n, ordering='interleaved')[source]

Generate all dual Lagrange base functions for the space \(\mathcal{P}_r(T, \mathbb{R}^n)\), where T is an m-dimensional simplex (i.e. the Lagrange basis for \(\mathcal{P}_r(T, \mathbb{R}^n)^*\)).

See dual_vector_valued_lagrange_basis_fn_simplex().

Parameters:
  • r (int) – Degree of the polynomial space.
  • vertices – Vertices of the simplex T ((m + 1) x m matrix where row i contains the i:th vertex of the simplex).
  • n (int) – Dimension of the target.
  • ordering (str) – How the vector valued basis functions are ordered. Can be “sequential” or “interleaved”. For sequential, sorting is first done on the index of the component that is non-zero, and then the non-zero component is sorted in the same way as the scalar valued basis functions. For “interleaved” basis functions are first sorted on their non-zero component in the same way as scalar valued basis functions, and then they are sorted on the index of the component that is non-zero.
Returns:

List of dual base functions.

Return type:

List[callable q(l)].

generate_lagrange_point_simplex(vertices, r, nu)[source]

Generate a Lagrange point indexed by a multi-index on an n-dimensional simplex T from the set \(\{ \bar{x}_nu \}\) of evenly spaced Lagrange points on the m-dimensional unit simplex (\(\Delta_c^n\)) (Lagrange basis points are constructed so that each basis function has the value 1 at one of the points, and 0 at all the other points).

\[\bar{x}_{\nu} = \frac{\nu}{r},\]
\[x_{\nu} = \Phi(\bar{x}_{\nu},\]

where \(\Phi\) is the unique affine map which maps the unit simplex to the simplex T.

Parameters:
  • vertices – Vertices of the simplex T ((n + 1) x n matrix where row i contains the i:th vertex of the simplex).
  • r (int) – Degree of the polynomial.
  • nu – Multi-index \(\nu\) indexing the Lagrange point, where \(\frac{\nu_i}{r}\) gives the i:th coordinate of the corresponding Lagrange point in the unit simplex.
Returns:

Point in the n-dimensional simplex T.

Return type:

Numpy array

generate_lagrange_points_simplex(vertices, r)[source]

Generate evenly spaced Lagrange points on an n-dimensional simplex T (Lagrange basis points are constructed so that each basis function has the value 1 at one of the points, and 0 at all the other points).

\[\begin{split}\{ x_{\nu} \}_{\substack{\nu \in \mathbb{N}_0^n \\ |\nu| \leq r}}, x_{\nu} = x_{\nu} = \Phi(\bar{x}_{\nu},\end{split}\]

where \(\{ \bar{x}_{\nu} \}\) is the set of evenly spaced Lagrange points on the unit simplex, and \(\Phi\) is the unique affine map which maps the unit simplex to the simplex T.

Parameters:
  • vertices – Vertices of the simplex T ((n + 1) x n matrix where row i contains the i:th vertex of the simplex).
  • r (int) – Degree of the polynomial.
Returns:

List of points in the n-dimensional simplex T.

Return type:

Numpy array

lagrange_basis_fn_simplex(nu, r, vertices)[source]

Generate a Lagrange basis polynomial on an n-dimensional simplex T, where n is equal to the length of nu.

\[l_{\nu, r}(x) = (\bar{l}_{\nu, r} \circ \Phi^{-1})(x),\]

where \(\bar{l}_{\nu, r}\) is the corresponding Lagrange basis polynomial on the (n-dimensional) unit simplex, and \(\Phi\) is the unique affine map which maps the unit simplex to the simplex T.

Parameters:
  • nu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating which Lagrange basis polynomial should be generated. The polynomial will have the value 1 at the point associated with the multi-index, and value 0 at all other points.
  • r (int) – Degree of polynomial.
  • vertices – Vertices of the simplex T ((n + 1) x n matrix where row i contains the i:th vertex of the simplex).
Returns:

The Lagrange base polynomial on the simplex T, as specified by nu and r.

Return type:

PolynomialLagrangeSimplex.

lagrange_basis_fn_simplex_latex(nu, r, vertices)[source]

Generate Latex string for a Lagrange basis polynomial on an n-dimensional simplex T, where n is equal to the length of nu.

Parameters:
  • nu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating which Lagrange basis polynomial we should generate Latex string for.
  • r (int) – Degree of polynomial.
  • vertices – Vertices of the simplex T ((n + 1) x n matrix where row i contains the i:th vertex of the simplex).
Returns:

Latex string for the Lagrange base polynomial on T, as specified by nu and r.

Return type:

str

lagrange_basis_fn_simplex_monomial(nu, r, vertices)[source]

Generate a Lagrange basis polynomial on an n-dimensional simplex T, where n is equal to the length of nu, expanded in the monomial basis.

This is the same polynomial as given by the lagrange_basis_fn_simplex() function, but expressed in the monomial basis.

Parameters:
  • nu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating which Lagrange basis polynomial should be generated The polynomial will have the value 1 at the point associated with the multi-index, and value 0 at all other points.
  • r (int) – Degree of polynomial.
  • vertices – Vertices of the simplex T ((n + 1) x n matrix where row i contains the i:th vertex of the simplex).
Returns:

The Lagrange base polynomial on the simplex T, as specified by nu and r.

Return type:

Polynomial.

lagrange_basis_simplex(r, vertices)[source]

Generate all Lagrange base polynomials for the space \(\mathcal{P}_r(T)\) where T is an n-dimensional simplex.

Parameters:
  • r (int) – Degree of the polynomial space.
  • vertices – Vertices of the simplex T ((n + 1) x n matrix where row i contains the i:th vertex of the simplex).
Returns:

List of base polynomials.

Return type:

List[PolynomialLagrangeSimplex].

lagrange_basis_simplex_latex(r, vertices)[source]

Generate Latex strings for all Lagrange base polynomials for the space \(\mathcal{P}_r(T)\) where T is an n-dimensional simplex.

Parameters:
  • r (int) – Degree of the polynomial space.
  • vertices – Vertices of the simplex T ((n + 1) x n matrix where row i contains the i:th vertex of the simplex).
Returns:

List of Latex strings for each Lagrange base polynomial.

Return type:

List[str]

lagrange_basis_simplex_monomial(r, vertices)[source]

Generate all Lagrange base polynomials for the space \(\mathcal{P}_r(T)\) where T is an n-dimensional simplex, expanded in the monomial basis.

This is the same set of polynomials as given by the lagrange_basis_simplex() function, but expressed in the monomial basis.

Parameters:
  • r (int) – Degree of the polynomial space.
  • vertices – Vertices of the simplex T ((n + 1) x n matrix where row i contains the i:th vertex of the simplex).
Returns:

List of base polynomials.

Return type:

List[Polynomial].

unique_identifier_lagrange_basis_simplex(vertices)[source]

Get unique identifier for the Lagrange polynomial basis on a simplex T.

Parameters:vertices – Vertices of the simplex T ((m + 1) x m matrix where row i contains the i:th vertex of the simplex).
Returns:Unique identifier.
Return type:str
unit_polynomial_simplex(vertices, r=0, n=1)[source]

Get the Lagrange polynomial \(l \in \mathcal{P}(T, \mathbb{R}^n)\) which is identically one, where T is an m-dimensional simplex.

Parameters:
  • vertices – Vertices of the simplex T ((m + 1) x m matrix where row i contains the i:th vertex of the simplex).
  • r (int) – The unit polynomial will be expressed in the Lagrange basis for \(\mathcal{P}_r(T, \mathbb{R}^n)\).
  • n (int) – Dimension of the polynomial target.
Returns:

The unit polynomial.

Return type:

PolynomialLagrangeSimplex.

vector_valued_lagrange_basis_fn_simplex(nu, r, i, vertices, n)[source]

Generate a vector valued Lagrange basis polynomial on an m-dimensional simplex T, \(l_{\nu, r, i} : T \to \mathbb{R}^n\).

The vector valued basis polynomial is generated by specifying a scalar valued basis polynomial and the component of the vector valued basis polynomial that should be equal to the scalar valued basis polynomial. All other components of the vector valued basis polynomial will be zero, i.e.

\[\begin{split}l_{\nu, r, i}^j (x) = \begin{cases} l_{\nu, r} (x), & i = j \\ 0, & \text{else} \end{cases},\end{split}\]

where m is equal to the length of nu.

Parameters:
  • nu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating which scalar valued Lagrange basis polynomial should be generated for the non-zero component.
  • r (int) – Degree of polynomial.
  • i (int) – Index of the vector component that is non-zero.
  • vertices – Vertices of the simplex T ((m + 1) x m matrix where row i contains the i:th vertex of the simplex).
  • n (int) – Dimension of the target.
Returns:

The Lagrange base polynomial on the simplex T as specified by nu, r, i and n.

Return type:

PolynomialLagrangeSimplex.

vector_valued_lagrange_basis_simplex(r, vertices, n, ordering='interleaved')[source]

Generate all Lagrange base polynomials for the space \(\mathcal{P}_r(T, \mathbb{R}^n)\), where T is an m-dimensional simplex.

Parameters:
  • r (int) – Degree of the polynomial space.
  • vertices – Vertices of the simplex T ((m + 1) x m matrix where row i contains the i:th vertex of the simplex).
  • n (int) – Dimension of the target.
  • ordering (str) – How the vector valued basis functions are ordered. Can be “sequential” or “interleaved”. For sequential, sorting is first done on the index of the component that is non-zero, and then the non-zero component is sorted in the same way as the scalar valued basis functions. For “interleaved” basis functions are first sorted on their non-zero component in the same way as scalar valued basis functions, and then they are sorted on the index of the component that is non-zero.
Returns:

List of base polynomials.

Return type:

List[PolynomialLagrangeSimplex].

zero_polynomial_simplex(vertices, r=0, n=1)[source]

Get the Lagrange polynomial \(l \in \mathcal{P}(T, \mathbb{R}^n)\) which is identically zero, where T is an m-dimensional simplex.

Parameters:
  • vertices – Vertices of the simplex T ((m + 1) x m matrix where row i contains the i:th vertex of the simplex).
  • r (int) – The zero polynomial will be expressed in the Lagrange basis for \(\mathcal{P}_r(T, \mathbb{R}^n)\).
  • n (int) – Dimension of the polynomial target.
Returns:

The zero polynomial.

Return type:

PolynomialLagrangeSimplex.