polynomials_on_simplices.piecewise_polynomial.continuous_piecewise_polynomial module

Functionality for Lagrange (continuous Galerkin) finite elements (continuous piecewise polynomials) on a simplicial domain (triangulation) \(\mathcal{T}\).

The space of continuous piecewise polynomials of degree r on \(\mathcal{T}, C\mathcal{P}_r (\mathcal{T}) = C\mathcal{P}_r (\mathcal{T}, \mathbb{R}^n) \subset H^1(\mathcal{T}, \mathbb{R}^n)\) is defined as

\[C\mathcal{P}_r (\mathcal{T}) = \{ v \in C(\mathcal{T}, \mathbb{R}^n) \big| v|_T \in \mathcal{P}_r(T, \mathbb{R}^n) \, \forall T \in \mathcal{T} \}.\]

Correspondingly the space of continuous piecewise polynomials of degree r on \(\mathcal{T}\) which are zero on specified set of simplices or subsimplices of \(\mathcal{T}, C\mathcal{P}_{r, 0} (\mathcal{T}))\) is defined as

\[C\mathcal{P}_{r, 0} (\mathcal{T}) = \{ v \in C_0(\mathcal{T}, \mathbb{R}^n) \big| v|_T \in \mathcal{P}_r(T, \mathbb{R}^n) \, \forall T \in \mathcal{T} \}.\]
class ContinuousPiecewisePolynomialBase(coeff, triangles, vertices, r, tau=None, boundary_simplices=None, keep_boundary_dofs_last=False, support=None, bsp_tree=None)[source]

Bases: polynomials_on_simplices.piecewise_polynomial.piecewise_polynomial.PiecewisePolynomialBase, abc.ABC

Abstract base class for a continuous piecewise polynomial function of degree r on a triangulation \(\mathcal{T}\), i.e. an element of \(C\mathcal{P}_r (\mathcal{T})\) or \(C\mathcal{P}_{r, 0} (\mathcal{T})\). The space of continuous piecewise polynomials is a subspace of the space of piecewise polynomials, see polynomials_on_simplices.piecewise_polynomial.piecewise_polynomial and in particular PiecewisePolynomialBase.

Differentiable structure

Besides the basic algebraic structures of the space of piecewise polynomials this class also defines the (weakly) differentiable structure of the space of continuous piecewise polynomials.

i:th partial weak derivative: \(\partial_i : C\mathcal{P}_r (\mathcal{T}) \to D\mathcal{P}_{r - 1} (\mathcal{T})\).

Parameters:
  • coeff (List[Union[Scalar, Vector]]) – Coefficients for the piecewise polynomial in the \(\{ \phi_i \}_{i = 1}^N\) basis derived from the basis for \(\mathcal{P}_r (\Delta_c^m)\) used (see polynomials_on_simplices.piecewise_polynomial.piecewise_polynomial.PiecewisePolynomialBase.basis()) and the local-to-global map \(\tau\).
  • triangles – Triangles (or in general simplices) in the mesh \(\mathcal{T}\) (num_triangles by m + 1 array of indices).
  • vertices – Vertices in the mesh \(\mathcal{T}\) (num_vertices by m array of scalars).
  • r (int) – Degree of each polynomial in the piecewise polynomial.
  • tau (Callable \(\tau(j, \nu)\)) – Local-to-global map for mapping local basis functions to the index of the corresponding global basis function, in a way that makes sure that the piecewise polynomial is continuous. Will be generated if not supplied.
  • boundary_simplices (List[List[int]]) – List of simplices or subsimplices on which the continuous piecewise polynomial function should vanish (for an element of \(C\mathcal{P}_{r, 0} (\mathcal{T})\)) or which should be treated separately (if keep_boundary_dofs_last is set to True). Each simplex or subsimplex is specified as a list of vertex indices of the vertices that form the simplex.
  • keep_boundary_dofs_last (bool) – Whether or not to collect all global basis functions associated with any boundary simplex last in the enumeration of all basis functions. Enumerating basis functions associated with boundary simplices last is useful for handling \(C\mathcal{P}_{r, 0} (\mathcal{T})\) as a subset of \(C\mathcal{P}_r (\mathcal{T})\) in a practical way.
  • support (Optional[Set[int]]) – Indices of the triangles in the triangulation where the continuous piecewise polynomial is supported. Will be generated if not supplied.
  • bsp_tree – Optional implementation detail. A binary space partitioning tree built around the triangulation for quicker lookup of triangle a point lies in. Will be generated if not supplied.
static generate_local_to_global_map(triangles, r, boundary_simplices=None, keep_boundary_dofs_last=False)[source]

Generate a local-to-global map \(\tau\) for the space of continuous piecewise polynomial functions of degree r on a triangulation \(\mathcal{T}, C \mathcal{P}_r (\mathcal{T})\) or \(C \mathcal{P}_{r, 0} (\mathcal{T})\). See generate_local_to_global_map().

weak_partial_derivative(i=0)[source]

Compute the i:th weak partial derivative of the continuous piecewise polynomial.

Parameters:i (int) – Index of partial derivative.
Returns:i:th weak partial derivative of this continuous piecewise polynomial.
generate_local_to_global_map(triangles, r, boundary_simplices=None, keep_boundary_dofs_last=False)[source]

Generate a local-to-global map \(\tau\) for the space of continuous piecewise polynomial functions of degree r on a triangulation \(\mathcal{T}, C \mathcal{P}_r (\mathcal{T})\) or \(C \mathcal{P}_{r, 0} (\mathcal{T})\).

We have \(\tau : \{ 0, 1, \ldots, | \mathcal{T} | - 1 \} \times \mathbb{N}_0^m \to \mathbb{N}_0 \cup \{ -1 \}\).

A local-to-global map maps a local polynomial basis function on a simplex in the triangulation to a global basis index for a basis for the space of continuous piecewise polynomials. The value -1 is used to indicate that a local basis function has no corresponding global basis function (see later).

Let \(d = \dim \mathcal{P}_r (\Delta_c^m)\), and let the triangles in \(\mathcal{T}\) be enumerated so that we have \(\mathcal{T} = \{ T_0, T_1, \ldots, T_{| \mathcal{T} | - 1} \}\). Given a basis \(\{ \bar{\varphi}_{\nu} \}_{\substack{\nu \in \mathbb{N}_0^m \\ | \nu | \leq r}}\) for \(\mathcal{P}_r (\Delta_c^m)\), the functions \(\{ \varphi_{\nu, j} = \bar{\varphi}_{\nu} \circ \Phi_{T_j}^{-1} \}_{\substack{\nu \in \mathbb{N}_0^m \\ | \nu | \leq r}}\) is a basis for \(\mathcal{P}_r(T_j)\), where \(\Phi_{T_j}, j = 0, 1, \ldots, | \mathcal{T} | - 1\) is the unique affine map which maps the unit simplex \(\Delta_c^m\) to the simplex \(T_j\). From these local bases and the local-to-global map \(\tau\) a basis \(\{ \phi_i \}_{i = 1}^N\) for \(C \mathcal{P}_r (\mathcal{T})\) is constructed, with

\[\phi_i(x) = \sum_{(j, \nu) \in \operatorname{preim}_{\tau}(i)} \chi_{T_j}(x) \cdot \varphi_{\nu, j}(x).\]

For each triangle \(T_j\) a basis function \(\phi_i\) either agrees with a basis function \(\varphi_{\nu, j}\) or it’s zero. I.e. the set \(v_j = \{ (k, \nu) \in \operatorname{preim}_{\tau}(i) \big| k = j \}\) either contains zero or one element.

\[\begin{split}\phi_i(x) = \begin{cases} \bar{\varphi}_{\nu} \circ \Phi_{T_j}^{-1}(x), & (\nu, j) \text{ unique element in } v_j \\ 0, & v_j \text{ is empty} \end{cases}.\end{split}\]

Optionally a set of boundary simplices can be prescribed where the piecewise polynomial function should vanish. This is achieved by associating an invalid global index (-1) for all local basis functions supported on any of the boundary simplices). Alternatively local basis functions supported on boundary simplices can be associated with global indices placed last in the enumeration of global basis functions (by setting the keep_boundary_dofs_last to true).

Parameters:
  • triangles – Triangles (or in general simplices) in the mesh (num_triangles by n + 1 list of indices, where n is the dimension of each simplex).
  • r (int) – Polynomial degree for the continuous piecewise polynomial functions.
  • boundary_simplices (List[List[int]]) – List of simplices or subsimplices on which the continuous piecewise polynomial functions should vanish (for an element of \(C\mathcal{P}_{r, 0} (\mathcal{T})\)) or which should be treated separately (if keep_boundary_dofs_last is set to True). Each simplex or subsimplex is specified as a list of vertex indices of the vertices that form the simplex.
  • keep_boundary_dofs_last (bool) – Whether or not to collect all global basis functions associated with any boundary simplex last in the enumeration of all basis functions. Enumerating basis functions associated with boundary simplices last makes \(C\mathcal{P}_{r, 0} (\mathcal{T})\) a subset of \(C\mathcal{P}_r (\mathcal{T})\) in a practical way.
Returns:

Tuple containing the local to global map \(\tau\) and the number of global basis functions. If keep_boundary_dofs_last is true then the number of global basis functions not supported on the boundary is also returned.

Return type:

Tuple[Callable \(\tau(j, \nu)\), int, Optional[int]].

generate_local_to_global_map_as_dictionaries(triangles, r, boundary_simplices=None, keep_boundary_dofs_last=False)[source]

Generate a local-to-global map for the space of continuous piecewise polynomial functions of degree r on a triangulation \(\mathcal{T}, C \mathcal{P}_r (\mathcal{T})\) or \(C \mathcal{P}_{r, 0} (\mathcal{T})\). For details see generate_local_to_global_map(). This function differs from that function in that a list of dictionaries (one for each triangle in the mesh) with multi-indices (second function argument) as keys and global DOF indices (function value) as values is returned instead of a callable, which might be preferable in some cases.

Parameters:
  • triangles – Triangles (or in general simplices) in the mesh (num_triangles by n + 1 list of indices, where n is the dimension of each simplex).
  • r (int) – Polynomial degree for the piecewise polynomial functions.
  • boundary_simplices (List[List[int]]) – List of simplices or subsimplices on which the piecewise polynomial functions should vanish (for an element of \(D\mathcal{P}_{r, 0} (\mathcal{T})\)) or which should be treated separately (if keep_boundary_dofs_last is set to True). Each simplex or subsimplex is specified as a list of vertex indices of the vertices that form the simplex.
  • keep_boundary_dofs_last (bool) – Whether or not to collect all global basis functions associated with any boundary simplex last in the enumeration of all basis functions. Enumerating basis functions associated with boundary simplices last is useful for handling \(D\mathcal{P}_{r, 0} (\mathcal{T})\) as a subset of \(D\mathcal{P}_r (\mathcal{T})\) in a practical way.
Returns:

Tuple containing the local to global map dictionaries, one for each triangle, and the number of global basis functions. If keep_boundary_dofs_last is true then the number of global basis functions not supported on the boundary is also returned.

Return type:

Tuple[List[dict[Tuple[int], int]], int, Optional[int]]

generate_local_to_global_preimage_map(tau, num_triangles, num_dofs, r, m)[source]

Generate the preimage map of a local-to-global map.

Let \(\tau : \{ 0, 1, \ldots, | \mathcal{T} | - 1 \} \times \mathbb{N}_0^m \to \mathbb{N}_0 \cup \{ -1 \}\) be a local-to-global map (see generate_local_to_global_map()). Then the preimage map of \(\tau\) is the map

\[\operatorname{preim}_{\tau} : \mathcal{P} \mathbb{N}_0 \to \mathcal{P} \left( \{ 0, 1, \ldots, |\mathcal{T}| - 1 \} \times \mathbb{N}_0^N \right)\]

such that

\[\tau(j, \nu) = i \quad \forall \, (j, \nu) \in \operatorname{preim}_{\tau}(\{i\}).\]
Parameters:
  • tau (Callable \(\tau(j, \nu)\)) – Local-to-global map that we want to create the preimage for.
  • num_triangles (int) – Number of triangles in the triangulation \(\mathcal{T}\) on which the continuous piecewise polynomials associated with the local-to-global map are defined.
  • num_dofs (int) – Number of degrees of freedom (dimension) for the space of continuous piecewise polynomials.
  • r (int) – Polynomial degree for the continuous piecewise polynomials.
  • m (int) – Dimension of the domain of the continuous piecewise polynomials.
Returns:

Preimage of the local-to-global map.

Return type:

Callable \(\operatorname{preim}_{\tau}(A)\).

generate_vector_valued_local_to_global_map(triangles, r, n, boundary_simplices=None, keep_boundary_dofs_last=False, ordering='interleaved')[source]

Generate a local-to-global map \(\tau\) for the space of vector valued continuous piecewise polynomial functions of degree r on a triangulation \(\mathcal{T}, C \mathcal{P}_r (\mathcal{T}, \mathbb{R}^n)\) or \(C \mathcal{P}_{r, 0} (\mathcal{T}, \mathbb{R}^n)\).

We have \(\tau : \{ 0, 1, \ldots, | \mathcal{T} | - 1 \} \times \mathbb{N}_0^m \times \{ 0, 1, \ldots, n - 1\} \to \mathbb{N}_0 \cup \{ -1 \}\).

A local-to-global map maps a local polynomial basis function on a simplex in the triangulation to a global basis index for a basis for the space of vector valued continuous piecewise polynomials. The value -1 is used to indicate that a local basis function has no corresponding global basis function (see later).

Let \(d = \dim \mathcal{P}_r (\Delta_c^m, \mathbb{R}^n)\), and let the triangles in \(\mathcal{T}\) be enumerated so that we have \(\mathcal{T} = \{ T_0, T_1, \ldots, T_{| \mathcal{T} | - 1} \}\). Given a basis \(\{ \bar{\varphi}_{\nu, i} \}_{\substack{\nu \in \mathbb{N}_0^m \\ | \nu | \leq r \\ i \in \{ 0, 1, \ldots, n - 1 \}}}\) for \(\mathcal{P}_r (\Delta_c^m, \mathbb{R}^n)\), the functions \(\{ \varphi_{\nu, j, i} = \bar{\varphi}_{\nu, i} \circ \Phi_{T_j}^{-1} \}_{\substack{\nu \in \mathbb{N}_0^m \\ | \nu | \leq r \\ i \in \{ 0, 1, \ldots, n - 1 \}}}\) is a basis for \(\mathcal{P}_r(T_j, \mathbb{R}^n)\), where \(\Phi_{T_j}, j = 0, 1, \ldots, | \mathcal{T} | - 1\) is the unique affine map which maps the unit simplex \(\Delta_c^m\) to the simplex \(T_j\). From these local bases and the local-to-global map \(\tau\) a basis \(\{ \phi_i \}_{i = 1}^N\) for \(C \mathcal{P}_r (\mathcal{T}, \mathbb{R}^n)\) is constructed, with

\[\phi_i(x) = \sum_{(j, \nu, k) \in \operatorname{preim}_{\tau}(i)} \chi_{T_j}(x) \cdot \varphi_{\nu, j, k}(x).\]

For each triangle \(T_j\) a basis function \(\phi_i\) either agrees with a basis function \(\varphi_{\nu, j, k}\) or it’s zero. I.e. the set \(v_j = \{ (l, \nu, k) \in \operatorname{preim}_{\tau}(i) \big| l = j \}\) either contains zero or one element.

\[\begin{split}\phi_i(x) = \begin{cases} \bar{\varphi}_{\nu, k} \circ \Phi_{T_j}^{-1}(x), & (j, \nu, k) \text{ unique element in } v_j \\ 0, & v_j \text{ is empty} \end{cases}.\end{split}\]

Optionally a set of boundary simplices can be prescribed where the piecewise polynomial function should vanish. This is achieved by associating an invalid global index (-1) for all local basis functions supported on any of the boundary simplices). Alternatively local basis functions supported on boundary simplices can be associated with global indices placed last in the enumeration of global basis functions (by setting the keep_boundary_dofs_last to true).

Parameters:
  • triangles – Triangles (or in general simplices) in the mesh (num_triangles by n + 1 list of indices, where n is the dimension of each simplex).
  • r (int) – Polynomial degree for the continuous piecewise polynomial functions.
  • n (int) – Dimension of the target.
  • boundary_simplices (List[List[int]]) – List of simplices or subsimplices on which the continuous piecewise polynomial functions should vanish (for an element of \(C\mathcal{P}_{r, 0} (\mathcal{T}, \mathbb{R}^n)\)) or which should be treated separately (if keep_boundary_dofs_last is set to True). Each simplex or subsimplex is specified as a list of vertex indices of the vertices that form the simplex.
  • keep_boundary_dofs_last (bool) – Whether or not to collect all global basis functions associated with any boundary simplex last in the enumeration of all basis functions. Enumerating basis functions associated with boundary simplices last makes \(C\mathcal{P}_{r, 0} (\mathcal{T}, \mathbb{R}^n)\) a subset of \(C\mathcal{P}_r (\mathcal{T}, \mathbb{R}^n)\) in a practical way.
  • 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:

Tuple containing the local to global map \(\tau\) and the number of global basis functions. If keep_boundary_dofs_last is true then the number of global basis functions not supported on the boundary is also returned.

Return type:

Tuple[Callable \(\tau(j, \nu, k)\), int, Optional[int]].

generate_vector_valued_local_to_global_preimage_map(tau, num_triangles, num_dofs, r, m, n)[source]

Generate the preimage map of a local-to-global map.

Let \(\tau : \{ 0, 1, \ldots, | \mathcal{T} | - 1 \} \times \mathbb{N}_0^m \times \{ 0, 1, \ldots, n - 1\} \to \mathbb{N}_0 \cup \{ -1 \}\) be a local-to-global map (see generate_vector_valued_local_to_global_map()). Then the preimage map of \(\tau\) is the map

\[\operatorname{preim}_{\tau} : \mathcal{P} \mathbb{N}_0 \to \mathcal{P} \left( \{ 0, 1, \ldots, |\mathcal{T}| - 1 \} \times \mathbb{N}_0^N \times \{ 0, 1, \ldots, n - 1 \} \right)\]

such that

\[\tau(j, \nu, k) = i \quad \forall \, (j, \nu, k) \in \operatorname{preim}_{\tau}(\{i\}).\]
Parameters:
  • tau (Callable \(\tau(j, \nu, k)\)) – Local-to-global map that we want to create the preimage for.
  • num_triangles (int) – Number of triangles in the triangulation \(\mathcal{T}\) on which the continuous piecewise polynomials associated with the local-to-global map are defined.
  • num_dofs (int) – Number of degrees of freedom (dimension) for the space of continuous piecewise polynomials.
  • r (int) – Polynomial degree for the continuous piecewise polynomials.
  • m (int) – Dimension of the domain of the continuous piecewise polynomials.
  • n (int) – Dimension of the domain of the continuous piecewise polynomials.
Returns:

Preimage of the local-to-global map.

Return type:

Callable \(\operatorname{preim}_{\tau}(A)\).