Finite element (dolfinx::fem
)
Under development
Finite elements
-
template<std::floating_point T>
class FiniteElement Finite Element, containing the dof layout on a reference element, and various methods for evaluating and transforming the basis.
Public Functions
-
explicit FiniteElement(const ufcx_finite_element &e)
Create finite element from UFC finite element.
- Parameters:
e – [in] UFC finite element.
-
FiniteElement(const basix::FiniteElement<T> &element, const std::vector<std::size_t> &value_shape)
Create finite element from a Basix finite element.
- Parameters:
element – [in] Basix finite element
value_shape – [in] Value shape for ‘blocked’ elements, e.g. vector-valued Lagrange elements where each component for the vector field is a Lagrange element. For example, a vector-valued element in 3D will have
value_shape
equal to{3}
, and for a second-order tensor element in 2Dvalue_shape
equal to{2, 2}
.
-
FiniteElement(const FiniteElement &element) = delete
Copy constructor.
-
FiniteElement(FiniteElement &&element) = default
Move constructor.
-
virtual ~FiniteElement() = default
Destructor.
-
FiniteElement &operator=(const FiniteElement &element) = delete
Copy assignment.
-
FiniteElement &operator=(FiniteElement &&element) = default
Move assignment.
-
bool operator==(const FiniteElement &e) const
Check if two elements are equivalent.
Note
Equality can be checked only for non-mixed elements. For a mixed element, this function will raise an exception.
- Returns:
True is the two elements are the same
-
bool operator!=(const FiniteElement &e) const
Check if two elements are not equivalent.
Note
Equality can be checked only for non-mixed elements. For a mixed element, this function will raise an exception.
- Returns:
True is the two elements are not the same
-
std::string signature() const noexcept
String identifying the finite element.
Warning
The function is provided for convenience, but it should not be relied upon for determining the element type. Use other functions, commonly returning enums, to determine element properties.
- Returns:
Element signature
-
int space_dimension() const noexcept
Dimension of the finite element function space (the number of degrees-of-freedom for the element)
- Returns:
Dimension of the finite element space
-
int block_size() const noexcept
Block size of the finite element function space. For BlockedElements, this is the number of DOFs colocated at each DOF point. For other elements, this is always 1.
- Returns:
Block size of the finite element space
-
int value_size() const
The value size, e.g. 1 for a scalar function, 2 for a 2D vector, 9 for a second-order tensor in 3D.
Note
The return value of this function is equivalent to
std::accumulate(value_shape().begin(), value_shape().end(), 1, std::multiplies{})
.- Returns:
The value size
-
int reference_value_size() const
The value size, e.g. 1 for a scalar function, 2 for a 2D vector, 9 for a second-order tensor in 3D, for the reference element.
- Returns:
The value size for the reference element
-
std::span<const std::size_t> value_shape() const noexcept
Shape of the value space. The rank is the size of the
value_shape
.
-
std::string family() const noexcept
The finite element family.
- Returns:
The string of the finite element family
-
void tabulate(std::span<T> values, std::span<const T> X, std::array<std::size_t, 2> shape, int order) const
Evaluate derivatives of the basis functions up to given order at points in the reference cell.
- Parameters:
values – [inout] Array that will be filled with the tabulated basis values. Must have shape
(num_derivatives, num_points, num_dofs, reference_value_size)
(row-major storage)X – [in] The reference coordinates at which to evaluate the basis functions. Shape is
(num_points, topological dimension)
(row-major storage)shape – [in] The shape of
X
order – [in] The number of derivatives (up to and including this order) to tabulate for
-
std::pair<std::vector<T>, std::array<std::size_t, 4>> tabulate(std::span<const T> X, std::array<std::size_t, 2> shape, int order) const
Evaluate all derivatives of the basis functions up to given order at given points in reference cell.
- Parameters:
X – [in] The reference coordinates at which to evaluate the basis functions. Shape is
(num_points, topological dimension)
(row-major storage)shape – [in] The shape of
X
order – [in] The number of derivatives (up to and including this order) to tabulate for
- Returns:
Basis function values and array shape (row-major storage)
-
int num_sub_elements() const noexcept
Number of sub elements (for a mixed or blocked element)
- Returns:
The number of sub elements
-
bool is_mixed() const noexcept
Check if element is a mixed element, i.e. composed of two or more elements of different types. A block element, e.g. a Lagrange element with block size > 1 is not considered mixed.
- Returns:
True is element is mixed.
-
const std::vector<std::shared_ptr<const FiniteElement<T>>> &sub_elements() const noexcept
Subelements (if any)
-
std::shared_ptr<const FiniteElement<T>> extract_sub_element(const std::vector<int> &component) const
Extract sub finite element for component.
-
const basix::FiniteElement<T> &basix_element() const
Return underlying basix element (if it exists)
-
basix::maps::type map_type() const
Get the map type used by the element.
-
bool interpolation_ident() const noexcept
Check if interpolation into the finite element space is an identity operation given the evaluation on an expression at specific points, i.e. the degree-of-freedom are equal to point evaluations. The function will return
true
for Lagrange elements.- Returns:
True if interpolation is an identity operation
-
bool map_ident() const noexcept
Check if the push forward/pull back map from the values on reference to the values on a physical cell for this element is the identity map.
- Returns:
True if the map is the identity
-
std::pair<std::vector<T>, std::array<std::size_t, 2>> interpolation_points() const
Points on the reference cell at which an expression needs to be evaluated in order to interpolate the expression in the finite element space.
For Lagrange elements the points will just be the nodal positions. For other elements the points will typically be the quadrature points used to evaluate moment degrees of freedom.
- Returns:
Interpolation point coordinates on the reference cell, returning the (0) coordinates data (row-major) storage and (1) the shape
(num_points, tdim)
.
-
std::pair<std::vector<T>, std::array<std::size_t, 2>> interpolation_operator() const
Interpolation operator (matrix)
Pi
that maps a function evaluated at the points provided by FiniteElement::interpolation_points to the element degrees of freedom, i.e. dofs = Pi f_x. See the Basix documentation for basix::FiniteElement::interpolation_matrix for how the data inf_x
should be ordered.- Returns:
The interpolation operator
Pi
, returning the data forPi
(row-major storage) and the shape(num_dofs, num_points * value_size)
-
std::pair<std::vector<T>, std::array<std::size_t, 2>> create_interpolation_operator(const FiniteElement &from) const
Create a matrix that maps degrees of freedom from one element to this element (interpolation).
Note
Does not support mixed elements
- Parameters:
from – [in] The element to interpolate from
- Returns:
Matrix operator that maps the
from
degrees-of-freedom to the degrees-of-freedom of this element. The (0) matrix data (row-major storage) and (1) the shape (num_dofs ofthis
element, num_dofs offrom
) are returned.- Pre:
The two elements must use the same mapping between the reference and physical cells
-
bool needs_dof_transformations() const noexcept
Check if DOF transformations are needed for this element.
DOF transformations will be needed for elements which might not be continuous when two neighbouring cells disagree on the orientation of a shared sub-entity, and when this cannot be corrected for by permuting the DOF numbering in the dofmap.
For example, Raviart-Thomas elements will need DOF transformations, as the neighbouring cells may disagree on the orientation of a basis function, and this orientation cannot be corrected for by permuting the DOF numbers on each cell.
- Returns:
True if DOF transformations are required
-
bool needs_dof_permutations() const noexcept
Check if DOF permutations are needed for this element.
DOF permutations will be needed for elements which might not be continuous when two neighbouring cells disagree on the orientation of a shared subentity, and when this can be corrected for by permuting the DOF numbering in the dofmap.
For example, higher order Lagrange elements will need DOF permutations, as the arrangement of DOFs on a shared sub-entity may be different from the point of view of neighbouring cells, and this can be corrected for by permuting the DOF numbers on each cell.
- Returns:
True if DOF transformations are required
-
template<typename U>
inline std::function<void(const std::span<U>&, const std::span<const std::uint32_t>&, std::int32_t, int)> get_dof_transformation_function(bool inverse = false, bool transpose = false, bool scalar_element = false) const Return a function that applies DOF transformation to some data.
The returned function will take four inputs:
[in,out] data The data to be transformed. This data is flattened with row-major layout, shape=(num_dofs, block_size)
[in] cell_info Permutation data for the cell. The size of this is num_cells. For elements where no transformations are required, an empty span can be passed in.
[in] cell The cell number
[in] block_size The block_size of the input data
- Parameters:
inverse – [in] Indicates whether the inverse transformations should be returned
transpose – [in] Indicates whether the transpose transformations should be returned
scalar_element – [in] Indicates whether the scalar transformations should be returned for a vector element
-
template<typename U>
inline std::function<void(const std::span<U>&, const std::span<const std::uint32_t>&, std::int32_t, int)> get_dof_transformation_to_transpose_function(bool inverse = false, bool transpose = false, bool scalar_element = false) const Return a function that applies DOF transformation to some transposed data.
The returned function will take three inputs:
[in,out] data The data to be transformed. This data is flattened with row-major layout, shape=(num_dofs, block_size)
[in] cell_info Permutation data for the cell. The size of this is num_cells. For elements where no transformations are required, an empty span can be passed in.
[in] cell The cell number
[in] block_size The block_size of the input data
- Parameters:
inverse – [in] Indicates whether the inverse transformations should be returned
transpose – [in] Indicates whether the transpose transformations should be returned
scalar_element – [in] Indicated whether the scalar transformations should be returned for a vector element
-
template<typename U>
inline void apply_dof_transformation(const std::span<U> &data, std::uint32_t cell_permutation, int block_size) const Apply DOF transformation to some data.
- Parameters:
data – [inout] The data to be transformed. This data is flattened with row-major layout, shape=(num_dofs, block_size)
cell_permutation – [in] Permutation data for the cell
block_size – [in] The block_size of the input data
-
template<typename U>
inline void apply_inverse_transpose_dof_transformation(const std::span<U> &data, std::uint32_t cell_permutation, int block_size) const Apply inverse transpose transformation to some data. For VectorElements, this applies the transformations for the scalar subelement.
- Parameters:
data – [inout] The data to be transformed. This data is flattened with row-major layout, shape=(num_dofs, block_size)
cell_permutation – [in] Permutation data for the cell
block_size – [in] The block_size of the input data
-
template<typename U>
inline void apply_transpose_dof_transformation(const std::span<U> &data, std::uint32_t cell_permutation, int block_size) const Apply transpose transformation to some data. For VectorElements, this applies the transformations for the scalar subelement.
- Parameters:
data – [inout] The data to be transformed. This data is flattened with row-major layout, shape=(num_dofs, block_size)
cell_permutation – [in] Permutation data for the cell
block_size – [in] The block_size of the input data
-
template<typename U>
inline void apply_inverse_dof_transformation(const std::span<U> &data, std::uint32_t cell_permutation, int block_size) const Apply inverse transformation to some data. For VectorElements, this applies the transformations for the scalar subelement.
- Parameters:
data – [inout] The data to be transformed. This data is flattened with row-major layout, shape=(num_dofs, block_size)
cell_permutation – [in] Permutation data for the cell
block_size – [in] The block_size of the input data
-
template<typename U>
inline void apply_dof_transformation_to_transpose(const std::span<U> &data, std::uint32_t cell_permutation, int block_size) const Apply DOF transformation to some transposed data.
- Parameters:
data – [inout] The data to be transformed. This data is flattened with row-major layout, shape=(num_dofs, block_size)
cell_permutation – [in] Permutation data for the cell
block_size – [in] The block_size of the input data
-
template<typename U>
inline void apply_inverse_dof_transformation_to_transpose(const std::span<U> &data, std::uint32_t cell_permutation, int block_size) const Apply inverse of DOF transformation to some transposed data.
- Parameters:
data – [inout] The data to be transformed. This data is flattened with row-major layout, shape=(num_dofs, block_size)
cell_permutation – [in] Permutation data for the cell
block_size – [in] The block_size of the input data
-
template<typename U>
inline void apply_transpose_dof_transformation_to_transpose(const std::span<U> &data, std::uint32_t cell_permutation, int block_size) const Apply transpose of transformation to some transposed data.
- Parameters:
data – [inout] The data to be transformed. This data is flattened with row-major layout, shape=(num_dofs, block_size)
cell_permutation – [in] Permutation data for the cell
block_size – [in] The block_size of the input data
-
template<typename U>
inline void apply_inverse_transpose_dof_transformation_to_transpose(const std::span<U> &data, std::uint32_t cell_permutation, int block_size) const Apply inverse transpose transformation to some transposed data.
- Parameters:
data – [inout] The data to be transformed. This data is flattened with row-major layout, shape=(num_dofs, block_size)
cell_permutation – [in] Permutation data for the cell
block_size – [in] The block_size of the input data
-
void permute_dofs(const std::span<std::int32_t> &doflist, std::uint32_t cell_permutation) const
Permute the DOFs of the element.
- Parameters:
doflist – [inout] The numbers of the DOFs, a span of length num_dofs
cell_permutation – [in] Permutation data for the cell
-
void unpermute_dofs(const std::span<std::int32_t> &doflist, std::uint32_t cell_permutation) const
Unpermute the DOFs of the element.
- Parameters:
doflist – [inout] The numbers of the DOFs, a span of length num_dofs
cell_permutation – [in] Permutation data for the cell
-
std::function<void(const std::span<std::int32_t>&, std::uint32_t)> get_dof_permutation_function(bool inverse = false, bool scalar_element = false) const
Return a function that applies DOF permutation to some data.
The returned function will take three inputs:
[in,out] doflist The numbers of the DOFs, a span of length num_dofs
[in] cell_permutation Permutation data for the cell
[in] block_size The block_size of the input data
- Parameters:
inverse – [in] Indicates whether the inverse transformations should be returned
scalar_element – [in] Indicated whether the scalar transformations should be returned for a vector element
-
explicit FiniteElement(const ufcx_finite_element &e)
Function spaces and functions
Finite element functions, expressions and constants
Function spaces
-
template<std::floating_point T>
class FunctionSpace This class represents a finite element function space defined by a mesh, a finite element, and a local-to-global map of the degrees-of-freedom.
- Template Parameters:
T – The floating point (real) type of the mesh geometry and the finite element basis.
Public Functions
Create function space for given mesh, element and dofmap.
- Parameters:
mesh – [in] Mesh that the space is defined on.
element – [in] Finite element for the space.
dofmap – [in] Degree-of-freedom map for the space.
-
FunctionSpace(FunctionSpace &&V) = default
Move constructor.
-
virtual ~FunctionSpace() = default
Destructor.
-
FunctionSpace &operator=(FunctionSpace &&V) = default
Move assignment operator.
-
inline std::shared_ptr<FunctionSpace<T>> sub(const std::vector<int> &component) const
Extract subspace for component.
- Parameters:
component – [in] The subspace component
- Returns:
The subspace
-
inline bool contains(const FunctionSpace &V) const
Check whether V is subspace of this, or this itself.
- Parameters:
V – [in] The space to be tested for inclusion
- Returns:
True if V is contained in or is equal to this FunctionSpace
-
inline std::pair<FunctionSpace<T>, std::vector<std::int32_t>> collapse() const
Collapse a subspace and return a new function space and a map from new to old dofs.
- Returns:
The new function space and a map from new to old dofs
-
inline std::vector<int> component() const
Get the component with respect to the root superspace.
- Returns:
The component with respect to the root superspace, i.e.
W.sub(1).sub(0) == [1, 0]
.
-
inline std::vector<T> tabulate_dof_coordinates(bool transpose) const
Tabulate the physical coordinates of all dofs on this process.
- Todo:
Remove - see function in interpolate.h
- Parameters:
transpose – [in] If false the returned data has shape
(num_points, 3)
, otherwise it is transposed and has shape(3, num_points)
.- Returns:
The dof coordinates
[([x0, y0, z0], [x1, y1, z1], ...)
iftranspose
is false, and otherwise the returned data is transposed. Storage is row-major.
-
inline std::shared_ptr<const FiniteElement<T>> element() const
The finite element.
Functions
-
template<dolfinx::scalar T, std::floating_point U = dolfinx::scalar_value_type_t<T>>
class Function This class represents a function \( u_h \) in a finite element function space \( V_h \), given by.
\[ u_h = \sum_{i=1}^{n} U_i \phi_i, \]where \( \{\phi_i\}_{i=1}^{n} \) is a basis for \( V_h \), and \( U \) is a vector of expansion coefficients for \( u_h \).- Template Parameters:
T – The function scalar type.
U – The mesh geometry scalar type.
Public Types
Public Functions
Create function on given function space.
- Parameters:
V – [in] The function space
Create function on given function space with a given vector.
Warning
This constructor is intended for internal library use only
- Parameters:
V – [in] The function space
x – [in] The vector
-
~Function() = default
Destructor.
-
inline Function sub(int i) const
Extract sub-function (a view into the Function).
- Parameters:
i – [in] Index of subfunction
- Returns:
The sub-function
-
inline Function collapse() const
Collapse a subfunction (view into a Function) to a stand-alone Function.
- Returns:
New collapsed Function.
-
inline std::shared_ptr<const FunctionSpace<U>> function_space() const
Access the function space.
- Returns:
The function space
-
inline void interpolate(const Function<T, U> &v, std::span<const std::int32_t> cells, const std::tuple<std::vector<std::int32_t>, std::vector<std::int32_t>, std::vector<U>, std::vector<std::int32_t>> &nmm_interpolation_data = {})
Interpolate a provided Function.
- Parameters:
v – [in] The function to be interpolated
cells – [in] The cells to interpolate on
nmm_interpolation_data – [in] Auxiliary data to interpolate on nonmatching meshes. This data can be generated with generate_nonmatching_meshes_interpolation_data (optional).
-
inline void interpolate(const Function<T, U> &v, const std::tuple<std::vector<std::int32_t>, std::vector<std::int32_t>, std::vector<U>, std::vector<std::int32_t>> &nmm_interpolation_data = {})
Interpolate a provided Function.
- Parameters:
v – [in] The function to be interpolated
nmm_interpolation_data – [in] Auxiliary data to interpolate on nonmatching meshes. This data can be generated with generate_nonmatching_meshes_interpolation_data (optional).
-
inline void interpolate(const std::function<std::pair<std::vector<T>, std::vector<std::size_t>>(MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<const U, MDSPAN_IMPL_STANDARD_NAMESPACE::extents<std::size_t, 3, MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent>>)> &f, std::span<const std::int32_t> cells)
Interpolate an expression function on a list of cells.
- Parameters:
f – [in] The expression function to be interpolated
cells – [in] The cells to interpolate on
-
inline void interpolate(const std::function<std::pair<std::vector<T>, std::vector<std::size_t>>(MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<const U, MDSPAN_IMPL_STANDARD_NAMESPACE::extents<std::size_t, 3, MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent>>)> &f)
Interpolate an expression function on the whole domain.
- Parameters:
f – [in] Expression to be interpolated
-
inline void interpolate(const Expression<T, U> &e, std::span<const std::int32_t> cells)
Interpolate an Expression (based on UFL)
- Parameters:
e – [in] Expression to be interpolated. The Expression must have been created using the reference coordinates
FiniteElement::interpolation_points()
for the element associated withu
.cells – [in] The cells to interpolate on
-
inline void interpolate(const Expression<T, U> &e)
Interpolate an Expression (based on UFL) on all cells.
- Parameters:
e – [in] The function to be interpolated
-
inline void eval(std::span<const U> x, std::array<std::size_t, 2> xshape, std::span<const std::int32_t> cells, std::span<T> u, std::array<std::size_t, 2> ushape) const
Evaluate the Function at points.
- Parameters:
x – [in] The coordinates of the points. It has shape (num_points, 3) and storage is row-major.
xshape – [in] The shape of
x
.cells – [in] An array of cell indices. cells[i] is the index of the cell that contains the point x(i). Negative cell indices can be passed, and the corresponding point will be ignored.
u – [out] The values at the points. Values are not computed for points with a negative cell index. This argument must be passed with the correct size. Storage is row-major.
ushape – [in] The shape of
u
.
Public Members
-
std::string name = "u"
Name.
Constants
Forms
-
template<dolfinx::scalar T, std::floating_point U = dolfinx::scalar_value_type_t<T>>
class Form A representation of finite element variational forms.
A note on the order of trial and test spaces: FEniCS numbers argument spaces starting with the leading dimension of the corresponding tensor (matrix). In other words, the test space is numbered 0 and the trial space is numbered 1. However, in order to have a notation that agrees with most existing finite element literature, in particular
\[ a = a(u, v) \]the spaces are numbered from right to left
\[ a: V_1 \times V_0 \rightarrow \mathbb{R} \]This is reflected in the ordering of the spaces that should be supplied to generated subclasses. In particular, when a bilinear form is initialized, it should be initialized as
a(V_1, V_0) = ...
, whereV_1
is the trial space andV_0
is the test space. However, when a form is initialized by a list of argument spaces (the variablefunction_spaces
in the constructors below), the list of spaces should start with space number 0 (the test space) and then space number 1 (the trial space).Public Functions
Create a finite element form.
Note
User applications will normally call a builder function rather using this interface directly.
- Parameters:
V – [in] Function spaces for the form arguments
integrals – [in] Integrals in the form. The first key is the domain type. For each key there is a list of tuples (domain id, integration kernel, entities).
coefficients – [in]
constants – [in] Constants in the Form
needs_facet_permutations – [in] Set to true is any of the integration kernels require cell permutation data
mesh – [in] Mesh of the domain. This is required when there are no argument functions from which the mesh can be extracted, e.g. for functionals.
-
virtual ~Form() = default
Destructor.
-
inline int rank() const
Rank of the form (bilinear form = 2, linear form = 1, functional = 0, etc)
- Returns:
The rank of the form
-
inline std::shared_ptr<const mesh::Mesh<U>> mesh() const
Extract common mesh for the form.
- Returns:
The mesh
-
inline const std::vector<std::shared_ptr<const FunctionSpace<U>>> &function_spaces() const
Return function spaces for all arguments.
- Returns:
Function spaces
-
inline std::function<void(T*, const T*, const T*, const scalar_value_type_t<T>*, const int*, const std::uint8_t*)> kernel(IntegralType type, int i) const
Get the kernel function for integral i on given domain type.
- Parameters:
type – [in] Integral type
i – [in] Domain index
- Returns:
Function to call for tabulate_tensor
-
inline std::set<IntegralType> integral_types() const
Get types of integrals in the form.
- Returns:
Integrals types.
-
inline int num_integrals(IntegralType type) const
Number of integrals on given domain type.
- Parameters:
type – [in] Integral type.
- Returns:
Number of integrals.
-
inline std::vector<int> integral_ids(IntegralType type) const
Get the IDs for integrals (kernels) for given integral type. The IDs correspond to the domain IDs which the integrals are defined for in the form. ID=-1 is the default integral over the whole domain.
- Parameters:
type – [in] Integral type
- Returns:
List of IDs for given integral type
-
inline std::span<const std::int32_t> domain(IntegralType type, int i) const
Get the list of cell indices for the ith integral (kernel) for the cell domain type.
For IntegralType::cell, returns a list of cell indices.
For IntegralType::exterior_facet, returns a list of (cell_index, local_facet_index) pairs. Data is flattened with row-major layout,
shape=(num_facets, 2)
.For IntegralType::interior_facet, returns list of tuples of the form
(cell_index_0, local_facet_index_0, cell_index_1, local_facet_index_1)
. Data is flattened with row-major layout,shape=(num_facets, 4)
.- Parameters:
type – [in] Integral domain type
i – [in] Integral ID, i.e. (sub)domain index
- Returns:
List of active cell entities for the given integral (kernel)
-
inline const std::vector<std::shared_ptr<const Function<T, U>>> &coefficients() const
Access coefficients.
-
inline bool needs_facet_permutations() const
Get bool indicating whether permutation data needs to be passed into these integrals.
- Returns:
True if cell permutation data is required
-
inline std::vector<int> coefficient_offsets() const
Offset for each coefficient expansion array on a cell. Used to pack data for multiple coefficients in a flat array. The last entry is the size required to store all coefficients.
Dirichlet boundary conditions
-
template<dolfinx::scalar T, std::floating_point U = dolfinx::scalar_value_type_t<T>>
class DirichletBC Object for setting (strong) Dirichlet boundary conditions.
\(u = g \ \text{on} \ G\),
where \(u\) is the solution to be computed, \(g\) is a function and \(G\) is a sub domain of the mesh.
A DirichletBC is specified by the function \(g\), the function space (trial space) and degrees of freedom to which the boundary condition applies.
Public Functions
Create a representation of a Dirichlet boundary condition constrained by a scalar- or vector-valued constant.
Note
Can be used only with point-evaluation elements.
Note
The indices in
dofs
are for blocks, e.g. a block index corresponds to 3 degrees-of-freedom if the dofmap associated withg
has block size 3.Note
The size of of
g
must be equal to the block size ifV
. Use the Function version if this is not the case, e.g. for some mixed spaces.- Parameters:
g – [in] The boundary condition value (
T
or convertible tostd::span<const T>
)dofs – [in] Degree-of-freedom block indices to be constrained. The indices must be sorted.
V – [in] The function space to be constrained
- Pre:
dofs
must be sorted.
Create a representation of a Dirichlet boundary condition constrained by a fem::Constant.
Note
Can be used only with point-evaluation elements.
Note
The indices in
dofs
are for blocks, e.g. a block index corresponds to 3 degrees-of-freedom if the dofmap associated withg
has block size 3.Note
The size of of
g
must be equal to the block size ifV
. Use the Function version if this is not the case, e.g. for some mixed spaces.- Parameters:
g – [in] The boundary condition value.
dofs – [in] Degree-of-freedom block indices to be constrained.
V – [in] The function space to be constrained
- Pre:
dofs
must be sorted.
Create a representation of a Dirichlet boundary condition where the space being constrained is the same as the function that defines the constraint Function, i.e. share the same fem::FunctionSpace.
Note
The indices in
dofs
are for blocks, e.g. a block index corresponds to 3 degrees-of-freedom if the dofmap associated withg
has block size 3.- Parameters:
g – [in] The boundary condition value.
dofs – [in] Degree-of-freedom block indices to be constrained.
- Pre:
dofs
must be sorted.
Create a representation of a Dirichlet boundary condition where the space being constrained and the function that defines the constraint values do not share the same fem::FunctionSpace.
A typical example is when applying a constraint on a subspace. The (sub)space and the constrain function must have the same finite element.
Note
The indices in
dofs
are unrolled and not for blocks.- Parameters:
g – [in] The boundary condition value
V_g_dofs – [in] Two arrays of degree-of-freedom indices (
std::array<std::vector<std::int32_t>, 2>
). First array are indices in the space where boundary condition is applied (V), second array are indices in the space of the boundary condition value function g. The dof indices are unrolled, i.e. are not by dof block.V – [in] The function (sub)space on which the boundary condition is applied
- Pre:
The two degree-of-freedom arrays in
V_g_dofs
must be sorted by the indices in the first array.
-
DirichletBC(const DirichletBC &bc) = default
Copy constructor.
- Parameters:
bc – [in] The object to be copied
-
DirichletBC(DirichletBC &&bc) = default
Move constructor.
- Parameters:
bc – [in] The object to be moved
-
~DirichletBC() = default
Destructor.
-
DirichletBC &operator=(const DirichletBC &bc) = default
Assignment operator.
- Parameters:
bc – [in] Another DirichletBC object
-
DirichletBC &operator=(DirichletBC &&bc) = default
Move assignment operator.
-
inline std::shared_ptr<const FunctionSpace<U>> function_space() const
The function space to which boundary conditions are applied.
- Returns:
The function space
-
inline std::variant<std::shared_ptr<const Function<T, U>>, std::shared_ptr<const Constant<T>>> value() const
Return boundary value function g.
- Returns:
The boundary values Function
-
inline std::pair<std::span<const std::int32_t>, std::int32_t> dof_indices() const
Access dof indices (local indices, unrolled), including ghosts, to which a Dirichlet condition is applied, and the index to the first non-owned (ghost) index. The array of indices is sorted.
- Returns:
Sorted array of dof indices (unrolled) and index to the first entry in the dof index array that is not owned. Entries
dofs[:pos]
are owned and entriesdofs[pos:]
are ghosts.
-
inline void set(std::span<T> x, T scale = 1) const
Set bc entries in
x
toscale * x_bc
- Parameters:
x – [in] The array in which to set
scale * x_bc[i]
, where x_bc[i] is the boundary value of x[i]. Entries in x that do not have a Dirichlet condition applied to them are unchanged. The length of x must be less than or equal to the index of the greatest boundary dof index. To set values only for degrees-of-freedom that are owned by the calling rank, the length of the arrayx
should be equal to the number of dofs owned by this rank.scale – [in] The scaling value to apply
-
inline void set(std::span<T> x, std::span<const T> x0, T scale = 1) const
Set bc entries in
x
toscale * (x0 - x_bc)
- Parameters:
x – [in] The array in which to set
scale * (x0 - x_bc)
x0 – [in] The array used in compute the value to set
scale – [in] The scaling value to apply
-
inline void dof_values(std::span<T> values) const
- Todo:
Review this function - it is almost identical to the ‘DirichletBC::set’ function
Set boundary condition value for entries with an applied boundary condition. Other entries are not modified.
- Parameters:
values – [out] The array in which to set the dof values. The array must be at least as long as the array associated with V1 (the space of the function that provides the dof values)
-
inline void mark_dofs(std::span<std::int8_t> markers) const
Set markers[i] = true if dof i has a boundary condition applied. Value of markers[i] is not changed otherwise.
- Parameters:
markers – [inout] Entry makers[i] is set to true if dof i in V0 had a boundary condition applied, i.e. dofs which are fixed by a boundary condition. Other entries in
markers
are left unchanged.
Degree-of-freedom maps
-
graph::AdjacencyList<std::int32_t> dolfinx::fem::transpose_dofmap(MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<const std::int32_t, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 2>> dofmap, std::int32_t num_cells)
Create an adjacency list that maps a global index (process-wise) to the ‘unassembled’ cell-wise contributions.
It is built from the usual (cell, local index) -> global index dof map. An ‘unassembled’ vector is the stacked cell contributions, ordered by cell index. If the usual dof map is:
Cell: 0 1 2 3
Global index: [ [0, 3, 5], [3, 2, 4], [4, 3, 2], [2, 1, 0]]
the ‘transpose’ dof map will be:
Global index: 0 1 2 3 4 5
Unassembled index: [ [0, 11], [10], [4, 8, 9], [1, 3, 7], [5, 6], [2] ]
- Parameters:
dofmap – [in] The standard dof map that for each cell (node) gives the global (process-wise) index of each local (cell-wise) index.
num_cells – [in] The number of cells (nodes) in
dofmap
to consider. The firstnum_cells
are used. This is argument is typically used to exclude ghost cell contributions.
- Returns:
Map from global (process-wise) index to positions in an unaassembled array. The links for each node are sorted.
-
class DofMap
Degree-of-freedom map.
This class handles the mapping of degrees of freedom. It builds a dof map based on an ElementDofLayout on a specific mesh topology. It will reorder the dofs when running in parallel. Sub-dofmaps, both views and copies, are supported.
Public Functions
- template<typename E, typename U> inline and std::is_convertible_v< std::remove_cvref_t< U >, std::vector< std::int32_t > > DofMap (E &&element, std::shared_ptr< const common::IndexMap > index_map, int index_map_bs, U &&dofmap, int bs)
Create a DofMap from the layout of dofs on a reference element, an IndexMap defining the distribution of dofs across processes and a vector of indices.
- Parameters:
element – [in] The layout of the degrees of freedom on an element
index_map – [in] The map describing the parallel distribution of the degrees of freedom.
index_map_bs – [in] The block size associated with the
index_map
.dofmap – [in] Adjacency list with the degrees-of-freedom for each cell.
bs – [in] The block size of the
dofmap
.
-
bool operator==(const DofMap &map) const
Equality operator.
- Returns:
Returns true if the data for the two dofmaps is equal
-
inline std::span<const std::int32_t> cell_dofs(std::int32_t c) const
Local-to-global mapping of dofs on a cell.
- Parameters:
c – [in] The cell index
- Returns:
Local-global dof map for the cell (using process-local indices)
-
int bs() const noexcept
Return the block size for the dofmap.
-
DofMap extract_sub_dofmap(std::span<const int> component) const
Extract subdofmap component.
- Parameters:
component – [in] The component indices
- Returns:
The dofmap for the component
-
std::pair<DofMap, std::vector<std::int32_t>> collapse(MPI_Comm comm, const mesh::Topology &topology, const std::function<std::vector<int>(const graph::AdjacencyList<std::int32_t>&)> &reorder_fn =
[](const graph::AdjacencyList< std::int32_t > &g) { return graph::reorder_gps(g);}
) const Create a “collapsed” dofmap (collapses a sub-dofmap)
- Parameters:
comm – [in] MPI Communicator
topology – [in] Mesh topology that the dofmap is defined on
reorder_fn – [in] Graph re-ordering function to apply to the dof data
- Returns:
The collapsed dofmap
-
MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<const std::int32_t, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 2>> map() const
Get dofmap data.
- Returns:
The adjacency list with dof indices for each cell
-
inline const ElementDofLayout &element_dof_layout() const
Layout of dofs on an element.
-
int index_map_bs() const
Block size associated with the index_map.
Assembly
Functions
-
template<dolfinx::scalar T>
std::map<std::pair<IntegralType, int>, std::pair<std::span<const T>, int>> make_coefficients_span(const std::map<std::pair<IntegralType, int>, std::pair<std::vector<T>, int>> &coeffs) Create a map of
std::span
s from a map ofstd::vector
s.
-
template<dolfinx::scalar T, std::floating_point U>
T assemble_scalar(const Form<T, U> &M, std::span<const T> constants, const std::map<std::pair<IntegralType, int>, std::pair<std::span<const T>, int>> &coefficients) Assemble functional into scalar.
The caller supplies the form constants and coefficients for this version, which has efficiency benefits if the data can be re-used for multiple calls.
Note
Caller is responsible for accumulation across processes.
- Parameters:
M – [in] The form (functional) to assemble
constants – [in] The constants that appear in
M
coefficients – [in] The coefficients that appear in
M
- Returns:
The contribution to the form (functional) from the local process
-
template<dolfinx::scalar T, std::floating_point U>
T assemble_scalar(const Form<T, U> &M) Assemble functional into scalar.
Note
Caller is responsible for accumulation across processes.
- Parameters:
M – [in] The form (functional) to assemble
- Returns:
The contribution to the form (functional) from the local process
-
template<dolfinx::scalar T, std::floating_point U>
void assemble_vector(std::span<T> b, const Form<T, U> &L, std::span<const T> constants, const std::map<std::pair<IntegralType, int>, std::pair<std::span<const T>, int>> &coefficients) Assemble linear form into a vector.
The caller supplies the form constants and coefficients for this version, which has efficiency benefits if the data can be re-used for multiple calls.
- Parameters:
b – [inout] The vector to be assembled. It will not be zeroed before assembly.
L – [in] The linear forms to assemble into b
constants – [in] The constants that appear in
L
coefficients – [in] The coefficients that appear in
L
-
template<dolfinx::scalar T, std::floating_point U>
void assemble_vector(std::span<T> b, const Form<T, U> &L) Assemble linear form into a vector.
- Parameters:
b – [inout] The vector to be assembled. It will not be zeroed before assembly.
L – [in] The linear forms to assemble into b
Modify b such that:
b <- b - scale * A_j (g_j - x0_j)
where j is a block (nest) index. For a non-blocked problem j = 0. The boundary conditions bcs1 are on the trial spaces V_j. The forms in [a] must have the same test space as L (from which b was built), but the trial space may differ. If x0 is not supplied, then it is treated as zero.
Ghost contributions are not accumulated (not sent to owner). Caller is responsible for calling VecGhostUpdateBegin/End.
Modify b such that:
b <- b - scale * A_j (g_j - x0_j)
where j is a block (nest) index. For a non-blocked problem j = 0. The boundary conditions bcs1 are on the trial spaces V_j. The forms in [a] must have the same test space as L (from which b was built), but the trial space may differ. If x0 is not supplied, then it is treated as zero.
Ghost contributions are not accumulated (not sent to owner). Caller is responsible for calling VecGhostUpdateBegin/End.
-
template<dolfinx::scalar T, std::floating_point U>
void assemble_matrix(la::MatSet<T> auto mat_add, const Form<T, U> &a, std::span<const T> constants, const std::map<std::pair<IntegralType, int>, std::pair<std::span<const T>, int>> &coefficients, std::span<const std::int8_t> dof_marker0, std::span<const std::int8_t> dof_marker1) Assemble bilinear form into a matrix. Matrix must already be initialised. Does not zero or finalise the matrix.
- Parameters:
mat_add – [in] The function for adding values into the matrix
a – [in] The bilinear form to assemble
constants – [in] Constants that appear in
a
coefficients – [in] Coefficients that appear in
a
dof_marker0 – [in] Boundary condition markers for the rows. If bc[i] is true then rows i in A will be zeroed. The index i is a local index.
dof_marker1 – [in] Boundary condition markers for the columns. If bc[i] is true then rows i in A will be zeroed. The index i is a local index.
Assemble bilinear form into a matrix.
- Parameters:
mat_add – [in] The function for adding values into the matrix
a – [in] The bilinear from to assemble
constants – [in] Constants that appear in
a
coefficients – [in] Coefficients that appear in
a
bcs – [in] Boundary conditions to apply. For boundary condition dofs the row and column are zeroed. The diagonal entry is not set.
Assemble bilinear form into a matrix.
- Parameters:
mat_add – [in] The function for adding values into the matrix
a – [in] The bilinear from to assemble
bcs – [in] Boundary conditions to apply. For boundary condition dofs the row and column are zeroed. The diagonal entry is not set.
-
template<dolfinx::scalar T, std::floating_point U>
void assemble_matrix(auto mat_add, const Form<T, U> &a, std::span<const std::int8_t> dof_marker0, std::span<const std::int8_t> dof_marker1) Assemble bilinear form into a matrix. Matrix must already be initialised. Does not zero or finalise the matrix.
- Parameters:
mat_add – [in] The function for adding values into the matrix
a – [in] The bilinear form to assemble
dof_marker0 – [in] Boundary condition markers for the rows. If bc[i] is true then rows i in A will be zeroed. The index i is a local index.
dof_marker1 – [in] Boundary condition markers for the columns. If bc[i] is true then rows i in A will be zeroed. The index i is a local index.
-
template<dolfinx::scalar T>
void set_diagonal(auto set_fn, std::span<const std::int32_t> rows, T diagonal = 1.0) Sets a value to the diagonal of a matrix for specified rows.
This function is typically called after assembly. The assembly function zeroes Dirichlet rows and columns. For block matrices, this function should normally be called only on the diagonal blocks, i.e. blocks for which the test and trial spaces are the same.
- Parameters:
set_fn – [in] The function for setting values to a matrix
rows – [in] The row blocks, in local indices, for which to add a value to the diagonal
diagonal – [in] The value to add to the diagonal for the specified rows
Sets a value to the diagonal of the matrix for rows with a Dirichlet boundary conditions applied.
This function is typically called after assembly. The assembly function zeroes Dirichlet rows and columns. This function adds the value only to rows that are locally owned, and therefore does not create a need for parallel communication. For block matrices, this function should normally be called only on the diagonal blocks, i.e. blocks for which the test and trial spaces are the same.
- Parameters:
set_fn – [in] The function for setting values to a matrix
V – [in] The function space for the rows and columns of the matrix. It is used to extract only the Dirichlet boundary conditions that are define on V or subspaces of V.
bcs – [in] The Dirichlet boundary conditions
diagonal – [in] The value to add to the diagonal for rows with a boundary condition applied
Set bc values in owned (local) part of the vector, multiplied by ‘scale’. The vectors b and x0 must have the same local size. The bcs should be on (sub-)spaces of the form L that b represents.
Set bc values in owned (local) part of the vector, multiplied by ‘scale’. The bcs should be on (sub-)spaces of the form L that b represents.
Interpolation
-
template<std::floating_point T>
std::vector<T> dolfinx::fem::interpolation_coords(const fem::FiniteElement<T> &element, const mesh::Geometry<T> &geometry, std::span<const std::int32_t> cells) Compute the evaluation points in the physical space at which an expression should be computed to interpolate it in a finite element space.
- Parameters:
element – [in] The element to be interpolated into
geometry – [in] Mesh geometry
cells – [in] Indices of the cells in the mesh to compute interpolation coordinates for
- Returns:
The coordinates in the physical space at which to evaluate an expression. The shape is (3, num_points) and storage is row-major.
Warning
doxygenfunction: Unable to resolve function “dolfinx::fem::interpolate” with arguments (Function<T, U>&, const Function<T, U>&, std::span<const std::int32_t>) in doxygen xml output for project “DOLFINx” from directory: ../xml/. Potential matches:
- template<dolfinx::scalar T, std::floating_point U> void interpolate(Function<T, U> &u, const Function<T, U> &v, std::span<const std::int32_t> cells, const std::tuple<std::vector<std::int32_t>, std::vector<std::int32_t>, std::vector<U>, std::vector<std::int32_t>> &nmm_interpolation_data = {})
- template<dolfinx::scalar T, std::floating_point U> void interpolate(Function<T, U> &u, std::span<const T> f, std::array<std::size_t, 2> fshape, std::span<const std::int32_t> cells)
-
template<dolfinx::scalar T, std::floating_point U>
void dolfinx::fem::interpolate(Function<T, U> &u, std::span<const T> f, std::array<std::size_t, 2> fshape, std::span<const std::int32_t> cells) Interpolate an expression f(x) in a finite element space.
- Parameters:
u – [out] The Function object to interpolate into
f – [in] Evaluation of the function
f(x)
at the physical pointsx
given by fem::interpolation_coords. The element used in fem::interpolation_coords should be the same element as associated withu
. The shape off
should be (value_size, num_points), with row-major storage.fshape – [in] The shape of
f
.cells – [in] Indices of the cells in the mesh on which to interpolate. Should be the same as the list used when calling fem::interpolation_coords.
- Template Parameters:
T – Scalar type
U – Mesh geometry type
Sparsity pattern construction
Warning
doxygenfunction: Unable to resolve function “dolfinx::fem::create_sparsity_pattern” with arguments (const Form<T, double>&) in doxygen xml output for project “DOLFINx” from directory: ../xml/. Potential matches:
- template<dolfinx::scalar T, std::floating_point U> la::SparsityPattern create_sparsity_pattern(const Form<T, U> &a)
PETSc helpers
-
template<std::floating_point T>
Mat dolfinx::fem::petsc::create_matrix(const Form<PetscScalar, T> &a, const std::string &type = std::string()) Create a matrix.
- Parameters:
a – [in] A bilinear form
type – [in] The PETSc matrix type to create
- Returns:
A sparse matrix with a layout and sparsity that matches the bilinear form. The caller is responsible for destroying the Mat object.
-
template<std::floating_point T>
Mat dolfinx::fem::petsc::create_matrix_block(const std::vector<std::vector<const Form<PetscScalar, T>*>> &a, const std::string &type = std::string()) Initialise a monolithic matrix for an array of bilinear forms.
- Parameters:
a – [in] Rectangular array of bilinear forms. The
a(i, j)
form will correspond to the(i, j)
block in the returned matrixtype – [in] The type of PETSc Mat. If empty the PETSc default is used.
- Returns:
A sparse matrix with a layout and sparsity that matches the bilinear forms. The caller is responsible for destroying the Mat object.
-
template<std::floating_point T>
Mat dolfinx::fem::petsc::create_matrix_nest(const std::vector<std::vector<const Form<PetscScalar, T>*>> &a, const std::vector<std::vector<std::string>> &types) Create nested (MatNest) matrix.
Note
The caller is responsible for destroying the Mat object.
-
Vec dolfinx::fem::petsc::create_vector_block(const std::vector<std::pair<std::reference_wrapper<const common::IndexMap>, int>> &maps)
Initialise monolithic vector. Vector is not zeroed.
The caller is responsible for destroying the Mat object
-
Vec dolfinx::fem::petsc::create_vector_nest(const std::vector<std::pair<std::reference_wrapper<const common::IndexMap>, int>> &maps)
Create nested (VecNest) vector. Vector is not zeroed.
-
template<std::floating_point T>
void dolfinx::fem::petsc::assemble_vector(Vec b, const Form<PetscScalar, T> &L, std::span<const PetscScalar> constants, const std::map<std::pair<IntegralType, int>, std::pair<std::span<const PetscScalar>, int>> &coeffs) Assemble linear form into an already allocated PETSc vector.
Ghost contributions are not accumulated (not sent to owner). Caller is responsible for calling
VecGhostUpdateBegin/End
.- Parameters:
b – [inout] The PETsc vector to assemble the form into. The vector must already be initialised with the correct size. The process-local contribution of the form is assembled into this vector. It is not zeroed before assembly.
L – [in] The linear form to assemble
constants – [in] The constants that appear in
L
coeffs – [in] The coefficients that appear in
L
-
template<std::floating_point T>
void dolfinx::fem::petsc::assemble_vector(Vec b, const Form<PetscScalar, T> &L) Assemble linear form into an already allocated PETSc vector. Ghost contributions are not accumulated (not sent to owner). Caller is responsible for calling VecGhostUpdateBegin/End.
- Parameters:
b – [inout] The PETsc vector to assemble the form into. The vector must already be initialised with the correct size. The process-local contribution of the form is assembled into this vector. It is not zeroed before assembly.
L – [in] The linear form to assemble
Modify RHS vector to account for Dirichlet boundary conditions.
Modify b such that:
b <- b - scale * A_j (g_j - x0_j)
where j is a block (nest) index. For a non-blocked problem j = 0. The boundary conditions bcs1 are on the trial spaces V_j. The forms in [a] must have the same test space as L (from which b was built), but the trial space may differ. If x0 is not supplied, then it is treated as zero.
Ghost contributions are not accumulated (not sent to owner). Caller is responsible for calling VecGhostUpdateBegin/End.
Modify b such that:
b <- b - scale * A_j (g_j - x0_j)
where j is a block (nest) index. For a non-blocked problem j = 0. The boundary conditions bcs1 are on the trial spaces V_j. The forms in [a] must have the same test space as L (from which b was built), but the trial space may differ. If x0 is not supplied, then it is treated as zero.
Ghost contributions are not accumulated (not sent to owner). Caller is responsible for calling VecGhostUpdateBegin/End.
Set bc values in owned (local) part of the PETSc vector, multiplied by ‘scale’. The vectors b and x0 must have the same local size. The bcs should be on (sub-)spaces of the form L that b represents.
Misc
Functions
-
template<int num_cells>
std::array<std::int32_t, 2 * num_cells> get_cell_facet_pairs(std::int32_t f, const std::span<const std::int32_t> &cells, const graph::AdjacencyList<std::int32_t> &c_to_f) Helper function to get an array of of (cell, local_facet) pairs corresponding to a given facet index.
- Parameters:
f – [in] Facet index
cells – [in] List of cells incident to the facet
c_to_f – [in] Cell to facet connectivity
- Returns:
Vector of (cell, local_facet) pairs
-
std::vector<std::pair<int, std::vector<std::int32_t>>> compute_integration_domains(IntegralType integral_type, const mesh::Topology &topology, std::span<const std::int32_t> entities, int dim, std::span<const int> values)
Given an integral type and mesh tag data, compute the entities that should be integrated over.
This function returns as list
[(id, entities)]
, whereentities
are the entities inmeshtags
with tag valueid
. For cell integralsentities
are the cell indices. For exterior facet integrals,entities
is a list of(cell_index, local_facet_index)
pairs. For interior facet integrals,entities
is a list of(cell_index0, local_facet_index0, cell_index1, local_facet_index1)
.Note
Owned mesh entities only are returned. Ghost entities are not included.
- Parameters:
integral_type – [in] Integral type
topology – [in] Mesh topology
entities – [in] List of tagged mesh entities
dim – [in] Topological dimension of tagged entities
values – [in] Value associated with each entity
- Returns:
List of
(integral id, entities)
pairs- Pre:
The topological dimension of the integral entity type and the topological dimension of mesh tag data must be equal.
- Pre:
For facet integrals, the topology facet-to-cell and cell-to-facet connectivity must be computed before calling this function.
-
template<dolfinx::scalar T, std::floating_point U>
std::vector<std::vector<std::array<std::shared_ptr<const FunctionSpace<U>>, 2>>> extract_function_spaces(const std::vector<std::vector<const Form<T, U>*>> &a) Extract test (0) and trial (1) function spaces pairs for each bilinear form for a rectangular array of forms.
- Parameters:
a – [in] A rectangular block on bilinear forms
- Returns:
Rectangular array of the same shape as
a
with a pair of function spaces in each array entry. If a form is null, then the returned function space pair is (null, null).
-
template<dolfinx::scalar T, std::floating_point U>
la::SparsityPattern create_sparsity_pattern(const Form<T, U> &a) Create a sparsity pattern for a given form.
Note
The pattern is not finalised, i.e. the caller is responsible for calling SparsityPattern::assemble.
- Parameters:
a – [in] A bilinear form
- Returns:
The corresponding sparsity pattern
-
ElementDofLayout create_element_dof_layout(const ufcx_dofmap &dofmap, const mesh::CellType cell_type, const std::vector<int> &parent_map = {})
Create an ElementDofLayout from a ufcx_dofmap.
-
DofMap create_dofmap(MPI_Comm comm, const ElementDofLayout &layout, mesh::Topology &topology, std::function<void(const std::span<std::int32_t>&, std::uint32_t)> unpermute_dofs, std::function<std::vector<int>(const graph::AdjacencyList<std::int32_t>&)> reorder_fn)
Create a dof map on mesh.
- Parameters:
comm – [in] MPI communicator
layout – [in] Dof layout on an element
topology – [in] Mesh topology
unpermute_dofs – [in] Function to un-permute dofs.
nullptr
when transformation is not required.reorder_fn – [in] Graph reordering function called on the dofmap
- Returns:
A new dof map
-
std::vector<std::string> get_coefficient_names(const ufcx_form &ufcx_form)
Get the name of each coefficient in a UFC form.
- Parameters:
ufcx_form – [in] The UFC form
- Returns:
The name of each coefficient
-
std::vector<std::string> get_constant_names(const ufcx_form &ufcx_form)
Get the name of each constant in a UFC form.
- Parameters:
ufcx_form – [in] The UFC form
- Returns:
The name of each constant
-
template<dolfinx::scalar T, typename U = dolfinx::scalar_value_type_t<T>>
Form<T, U> create_form(const ufcx_form &ufcx_form, const std::vector<std::shared_ptr<const FunctionSpace<U>>> &spaces, const std::vector<std::shared_ptr<const Function<T, U>>> &coefficients, const std::vector<std::shared_ptr<const Constant<T>>> &constants, const std::map<IntegralType, std::vector<std::pair<std::int32_t, std::vector<std::int32_t>>>> &subdomains, std::shared_ptr<const mesh::Mesh<U>> mesh = nullptr) Create a Form from UFC input.
- Parameters:
ufcx_form – [in] The UFC form
spaces – [in] Vector of function spaces
coefficients – [in] Coefficient fields in the form
constants – [in] Spatial constants in the form
subdomains – [in] Subdomain markers
mesh – [in] The mesh of the domain
- Pre:
Each value in
subdomains
must be sorted by domain id
-
template<dolfinx::scalar T, typename U = dolfinx::scalar_value_type_t<T>>
Form<T, U> create_form(const ufcx_form &ufcx_form, const std::vector<std::shared_ptr<const FunctionSpace<U>>> &spaces, const std::map<std::string, std::shared_ptr<const Function<T, U>>> &coefficients, const std::map<std::string, std::shared_ptr<const Constant<T>>> &constants, const std::map<IntegralType, std::vector<std::pair<std::int32_t, std::vector<std::int32_t>>>> &subdomains, std::shared_ptr<const mesh::Mesh<U>> mesh = nullptr) Create a Form from UFC input.
- Parameters:
ufcx_form – [in] UFC form
coefficients – [in] Coefficient fields in the form (by name).
constants – [in] Spatial constants in the form (by name).
subdomains – [in] Subdomain markers.
mesh – [in] Mesh of the domain. This is required if the form has no arguments, e.g. a functional.
- Pre:
Each value in
subdomains
must be sorted by domain id.- Returns:
A Form
-
template<dolfinx::scalar T, typename U = dolfinx::scalar_value_type_t<T>>
Form<T, U> create_form(ufcx_form *(*fptr)(), const std::vector<std::shared_ptr<const FunctionSpace<U>>> &spaces, const std::map<std::string, std::shared_ptr<const Function<T, U>>> &coefficients, const std::map<std::string, std::shared_ptr<const Constant<T>>> &constants, const std::map<IntegralType, std::vector<std::pair<std::int32_t, std::vector<std::int32_t>>>> &subdomains, std::shared_ptr<const mesh::Mesh<U>> mesh = nullptr) Create a Form using a factory function that returns a pointer to a ufcx_form.
- Parameters:
fptr – [in] Pointer to a function returning a pointer to ufcx_form.
coefficients – [in] Coefficient fields in the form (by name),
constants – [in] Spatial constants in the form (by name),
subdomains – [in] Subdomain markers.
mesh – [in] Mesh of the domain. This is required if the form has no arguments, e.g. a functional.
- Pre:
Each value in
subdomains
must be sorted by domain id.- Returns:
A Form
-
template<std::floating_point T>
FunctionSpace<T> create_functionspace(std::shared_ptr<mesh::Mesh<T>> mesh, const basix::FiniteElement<T> &e, const std::vector<std::size_t> &value_shape = {}, std::function<std::vector<int>(const graph::AdjacencyList<std::int32_t>&)> reorder_fn = nullptr) Create a function space from a Basix element.
- Parameters:
mesh – [in] Mesh
e – [in] Basix finite element.
value_shape – [in] Value shape for ‘blocked’ elements, e.g. vector-valued Lagrange elements where each component for the vector field is a Lagrange element. For example, a vector-valued element in 3D will have
value_shape
equal to{3}
, and for a second-order tensor element in 2Dvalue_shape
equal to{2, 2}
.reorder_fn – [in] The graph reordering function to call on the dofmap. If
nullptr
, the default re-ordering is used.
- Returns:
The created function space
-
template<std::floating_point T>
FunctionSpace<T> create_functionspace(ufcx_function_space *(*fptr)(const char*), const std::string &function_name, std::shared_ptr<mesh::Mesh<T>> mesh, std::function<std::vector<int>(const graph::AdjacencyList<std::int32_t>&)> reorder_fn = nullptr) Create a FunctionSpace from UFC data.
- Parameters:
fptr – [in] Pointer to a ufcx_function_space_create function.
function_name – [in] Name of a function whose function space to create. Function name is the name of Python variable for ufl.Coefficient, ufl.TrialFunction or ufl.TestFunction as defined in the UFL file.
mesh – [in] Mesh
reorder_fn – [in] Graph reordering function to call on the dofmap. If
nullptr
, the default re-ordering is used.
- Returns:
The created function space.
-
template<dolfinx::scalar T, std::floating_point U>
std::span<const std::uint32_t> get_cell_orientation_info(const std::vector<std::shared_ptr<const Function<T, U>>> &coefficients)
-
template<dolfinx::scalar T, int _bs>
void pack(std::span<T> coeffs, std::int32_t cell, int bs, std::span<const T> v, std::span<const std::uint32_t> cell_info, const DofMap &dofmap, auto transform) Pack a single coefficient for a single cell.
-
template<dolfinx::scalar T, std::floating_point U>
void pack_coefficient_entity(std::span<T> c, int cstride, const Function<T, U> &u, std::span<const std::uint32_t> cell_info, std::span<const std::int32_t> entities, std::size_t estride, FetchCells auto &&fetch_cells, std::int32_t offset) Pack a single coefficient for a set of active entities.
- Parameters:
c – [out] Coefficient to be packed.
cstride – [in] Total number of coefficient values to pack for each entity.
u – [in] Function to extract coefficient data from.
cell_info – [in] Array of bytes describing which transformation has to be applied on the cell to map it to the reference element.
entities – [in] Set of active entities.
estride – [in] Stride for each entity in active entities.
fetch_cells – [in] Function that fetches the cell index for an entity in active_entities.
offset – [in] The offset for c.
-
template<dolfinx::scalar T, std::floating_point U>
std::pair<std::vector<T>, int> allocate_coefficient_storage(const Form<T, U> &form, IntegralType integral_type, int id) Allocate storage for coefficients of a pair
(integral_type, id)
from a Form.- Parameters:
form – [in] The Form
integral_type – [in] Type of integral
id – [in] The id of the integration domain
- Returns:
A storage container and the column stride
-
template<dolfinx::scalar T, std::floating_point U>
std::map<std::pair<IntegralType, int>, std::pair<std::vector<T>, int>> allocate_coefficient_storage(const Form<T, U> &form) Allocate memory for packed coefficients of a Form.
- Parameters:
form – [in] The Form
- Returns:
Map from a form
(integral_type, domain_id)
pair to a(coeffs, cstride)
pair
-
template<dolfinx::scalar T, std::floating_point U>
void pack_coefficients(const Form<T, U> &form, IntegralType integral_type, int id, std::span<T> c, int cstride) Pack coefficients of a Form for a given integral type and domain id.
- Parameters:
form – [in] The Form
integral_type – [in] Type of integral
id – [in] The id of the integration domain
c – [in] The coefficient array
cstride – [in] The coefficient stride
-
template<dolfinx::scalar T, typename U = dolfinx::scalar_value_type_t<T>>
Expression<T, U> create_expression(const ufcx_expression &e, const std::vector<std::shared_ptr<const Function<T, U>>> &coefficients, const std::vector<std::shared_ptr<const Constant<T>>> &constants, std::shared_ptr<const FunctionSpace<U>> argument_function_space = nullptr) Create Expression from UFC.
-
template<dolfinx::scalar T, typename U = dolfinx::scalar_value_type_t<T>>
Expression<T, U> create_expression(const ufcx_expression &e, const std::map<std::string, std::shared_ptr<const Function<T, U>>> &coefficients, const std::map<std::string, std::shared_ptr<const Constant<T>>> &constants, std::shared_ptr<const FunctionSpace<U>> argument_function_space = nullptr) Create Expression from UFC input (with named coefficients and constants).
-
template<dolfinx::scalar T, std::floating_point U>
void pack_coefficients(const Form<T, U> &form, std::map<std::pair<IntegralType, int>, std::pair<std::vector<T>, int>> &coeffs) Pack coefficients of a Form.
Warning
This is subject to change
- Parameters:
form – [in] The Form
coeffs – [in] A map from a (integral_type, domain_id) pair to a (coeffs, cstride) pair
-
template<dolfinx::scalar T, std::floating_point U>
std::pair<std::vector<T>, int> pack_coefficients(const Expression<T, U> &e, std::span<const std::int32_t> cells) Pack coefficients of a Expression u for a give list of active cells.
- Parameters:
e – [in] The Expression
cells – [in] A list of active cells
- Returns:
A pair of the form (coeffs, cstride)