13#include <basix/finite-element.h>
14#include <basix/maps.h>
19#include <dolfinx/mesh/cell_types.h>
20#include <dolfinx/mesh/permutationcomputation.h>
40template <std::
floating_po
int T>
77std::vector<std::size_t>
79 std::span<const std::size_t> reference_value_shape,
84template <std::
floating_po
int T>
87 std::reference_wrapper<const basix::FiniteElement<T>>
93 std::optional<std::vector<std::size_t>>
value_shape = std::nullopt;
99template <
typename U,
typename V,
typename W>
200template <std::
floating_po
int T>
219 const std::optional<std::vector<std::size_t>>&
value_shape
267 std::array<std::size_t, 2> pshape,
311 const std::
string&
signature() const noexcept;
426 const std::vector<std::vector<std::vector<
int>>>&
431 const std::vector<std::vector<std::vector<
int>>>&
456 std::array<std::
size_t, 2> shape,
int order) const;
468 std::pair<std::vector<
geometry_type>, std::array<std::
size_t, 4>>
524 std::pair<std::vector<
geometry_type>, std::array<std::
size_t, 2>>
536 std::pair<std::vector<
geometry_type>, std::array<std::
size_t, 2>>
551 std::pair<std::vector<
geometry_type>, std::array<std::
size_t, 2>>
639 template <typename U>
640 std::function<
void(std::span<U>, std::span<const std::uint32_t>, std::int32_t,
647 if (!_sub_elements.empty())
649 if (!_reference_value_shape)
651 std::vector<std::function<void(
652 std::span<U>, std::span<const std::uint32_t>, std::int32_t, int)>>
654 std::vector<int> dims;
655 sub_element_fns.reserve(_sub_elements.size());
656 dims.reserve(_sub_elements.size());
657 for (std::size_t i = 0; i < _sub_elements.size(); ++i)
659 sub_element_fns.push_back(
660 _sub_elements[i]->template dof_transformation_fn<U>(ttype));
661 dims.push_back(_sub_elements[i]->space_dimension());
664 return [dims = std::move(dims),
665 sub_element_fns = std::move(sub_element_fns)](
666 std::span<U> data, std::span<const std::uint32_t> cell_info,
667 std::int32_t cell, int block_size)
669 std::size_t offset = 0;
670 for (std::size_t e = 0; e < sub_element_fns.size(); ++e)
672 const std::size_t width = dims[e] * block_size;
673 if (sub_element_fns[e])
675 sub_element_fns[e](data.subspan(offset, width), cell_info, cell,
682 else if (!scalar_element)
685 std::function<void(std::span<U>, std::span<const std::uint32_t>,
691 return [ebs, sub_fn = std::move(sub_fn)](
692 std::span<U> data, std::span<const std::uint32_t> cell_info,
693 std::int32_t
cell,
int data_block_size)
694 { sub_fn(data, cell_info,
cell, ebs * data_block_size); };
701 return [
this](std::span<U> data, std::span<const std::uint32_t> cell_info,
705 return [
this](std::span<U> data, std::span<const std::uint32_t> cell_info,
709 return [
this](std::span<U> data, std::span<const std::uint32_t> cell_info,
713 return [
this](std::span<U> data, std::span<const std::uint32_t> cell_info,
717 throw std::invalid_argument(
"Unknown transformation type");
744 template <
typename U>
745 std::function<void(std::span<U>, std::span<const std::uint32_t>, std::int32_t,
748 bool scalar_element =
false)
const
752 else if (!_sub_elements.empty())
754 if (!_reference_value_shape)
756 std::vector<std::function<void(
757 std::span<U>, std::span<const std::uint32_t>, std::int32_t,
int)>>
759 std::vector<int> dims;
760 sub_element_fns.reserve(_sub_elements.size());
761 dims.reserve(_sub_elements.size());
762 for (std::size_t i = 0; i < _sub_elements.size(); ++i)
764 sub_element_fns.push_back(
769 return [dims = std::move(dims),
770 sub_element_fns = std::move(sub_element_fns)](
771 std::span<U> data, std::span<const std::uint32_t> cell_info,
777 const std::size_t ndofs = data.size() /
block_size;
778 std::size_t offset = 0;
779 for (std::size_t e = 0; e < sub_element_fns.size(); ++e)
781 if (sub_element_fns[e])
785 sub_element_fns[e](data.subspan(i * ndofs + offset, dims[e]),
793 else if (!scalar_element)
800 std::function<void(std::span<U>, std::span<const std::uint32_t>,
805 return [
this, sub_fn = std::move(sub_fn)](
806 std::span<U> data, std::span<const std::uint32_t> cell_info,
807 std::int32_t
cell,
int data_block_size)
810 const std::size_t dof_count = data.size() / data_block_size;
811 for (
int block = 0; block < data_block_size; ++block)
813 sub_fn(data.subspan(block * dof_count, dof_count), cell_info,
cell,
823 return [
this](std::span<U> data, std::span<const std::uint32_t> cell_info,
824 std::int32_t
cell,
int n)
827 return [
this](std::span<U> data, std::span<const std::uint32_t> cell_info,
828 std::int32_t
cell,
int n)
831 return [
this](std::span<U> data, std::span<const std::uint32_t> cell_info,
832 std::int32_t
cell,
int n)
835 return [
this](std::span<U> data, std::span<const std::uint32_t> cell_info,
836 std::int32_t
cell,
int n)
839 throw std::invalid_argument(
"Unknown transformation type");
879 template <
typename U>
880 void T_apply(std::span<U> data, std::uint32_t cell_permutation,
int n)
const
883 _element->T_apply(data, n, cell_permutation & ~_orientation_mask);
884 flip_reversed<false>(data, cell_permutation, n);
896 template <
typename U>
901 _element->Tt_inv_apply(data, n, cell_permutation & ~_orientation_mask);
902 flip_reversed<false>(data, cell_permutation, n);
914 template <
typename U>
915 void Tt_apply(std::span<U> data, std::uint32_t cell_permutation,
int n)
const
918 _element->Tt_apply(data, n, cell_permutation & ~_orientation_mask);
919 flip_reversed<false>(data, cell_permutation, n);
930 template <
typename U>
931 void Tinv_apply(std::span<U> data, std::uint32_t cell_permutation,
935 _element->Tinv_apply(data, n, cell_permutation & ~_orientation_mask);
936 flip_reversed<false>(data, cell_permutation, n);
947 template <
typename U>
952 _element->T_apply_right(data, n, cell_permutation & ~_orientation_mask);
953 flip_reversed<true>(data, cell_permutation, n);
965 template <
typename U>
970 _element->Tinv_apply_right(data, n, cell_permutation & ~_orientation_mask);
971 flip_reversed<true>(data, cell_permutation, n);
983 template <
typename U>
988 _element->Tt_apply_right(data, n, cell_permutation & ~_orientation_mask);
989 flip_reversed<true>(data, cell_permutation, n);
1001 template <
typename U>
1006 _element->Tt_inv_apply_right(data, n,
1007 cell_permutation & ~_orientation_mask);
1008 flip_reversed<true>(data, cell_permutation, n);
1027 void permute(std::span<std::int32_t> doflist,
1028 std::uint32_t cell_permutation)
const;
1046 void permute_inv(std::span<std::int32_t> doflist,
1047 std::uint32_t cell_permutation)
const;
1063 std::function<void(std::span<std::int32_t>, std::uint32_t)>
1064 dof_permutation_fn(
bool inverse =
false,
bool scalar_element =
false)
const;
1075 template <
bool post,
typename U>
1076 void flip_reversed(std::span<U> data, std::uint32_t cell_permutation,
1079 if (!_depends_on_facet_orientations
1080 or !(cell_permutation & _orientation_mask)) [[likely]]
1087 assert(
mesh::cell_dim(_cell_type) == 2 and _entity_dofs.size() > 1);
1088 const std::vector<std::vector<int>>& facet_dofs = _entity_dofs[1];
1090 assert(n > 0 and data.size() % n == 0);
1091 const std::size_t num_dofs = data.size() / n;
1092 for (std::size_t f = 0; f < facet_dofs.size(); ++f)
1096 for (
int dof : facet_dofs[f])
1098 for (
int j = 0; j < n; ++j)
1100 U& value = post ? data[j * num_dofs + dof] : data[dof * n + j];
1112 std::optional<std::vector<std::size_t>> _value_shape;
1122 std::string _signature;
1128 std::vector<std::shared_ptr<const FiniteElement<geometry_type>>>
1135 std::optional<std::vector<std::size_t>> _reference_value_shape;
1138 std::unique_ptr<basix::FiniteElement<geometry_type>> _element;
1144 bool _needs_dof_permutations;
1145 bool _needs_dof_transformations;
1148 bool _depends_on_facet_orientations;
1152 std::uint32_t _orientation_mask = 0;
1154 std::vector<std::vector<std::vector<int>>> _entity_dofs;
1155 std::vector<std::vector<std::vector<int>>> _entity_closure_dofs;
1159 std::pair<std::vector<geometry_type>, std::array<std::size_t, 2>> _points;
Definition CoordinateElement.h:27
bool symmetric() const
Does the element represent a symmetric 2-tensor?
Definition FiniteElement.cpp:445
FiniteElement & operator=(const FiniteElement &element)=delete
Copy assignment.
const std::vector< std::shared_ptr< const FiniteElement< geometry_type > > > & sub_elements() const noexcept
Get subelements (if any).
Definition FiniteElement.cpp:491
void Tinv_apply(std::span< U > data, std::uint32_t cell_permutation, int n) const
Apply the inverse of the operator applied by T_apply().
Definition FiniteElement.h:931
std::span< const std::size_t > value_shape() const
Value shape of the finite element field in physical space.
Definition FiniteElement.cpp:383
std::pair< std::vector< geometry_type >, 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).
Definition FiniteElement.cpp:592
void T_apply(std::span< U > data, std::uint32_t cell_permutation, int n) const
Transform basis functions from the reference element ordering and orientation to the globally consist...
Definition FiniteElement.h:880
basix::maps::type map_type() const
Get the map type used by the element.
Definition FiniteElement.cpp:520
int space_dimension() const noexcept
Dimension of the finite element function space (the number of degrees-of-freedom for the element).
Definition FiniteElement.cpp:365
void tabulate(std::span< geometry_type > values, std::span< const geometry_type > 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.
Definition FiniteElement.cpp:457
void Tt_inv_apply_right(std::span< U > data, std::uint32_t cell_permutation, int n) const
Right(post)-apply the transpose inverse of the operator applied by T_apply().
Definition FiniteElement.h:1002
FiniteElement & operator=(FiniteElement &&element)=default
Move assignment.
bool needs_dof_transformations() const noexcept
Check if DOF transformations are needed for this element.
Definition FiniteElement.cpp:637
FiniteElement(const FiniteElement &element)=delete
Copy constructor.
void Tt_inv_apply(std::span< U > data, std::uint32_t cell_permutation, int n) const
Apply the inverse transpose of the operator applied by T_apply().
Definition FiniteElement.h:897
std::pair< std::vector< geometry_type >, 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...
Definition FiniteElement.cpp:560
std::shared_ptr< const FiniteElement< geometry_type > > extract_sub_element(const std::vector< int > &component) const
Extract sub finite element for component.
Definition FiniteElement.cpp:498
void T_apply_right(std::span< U > data, std::uint32_t cell_permutation, int n) const
Right(post)-apply the operator applied by T_apply().
Definition FiniteElement.h:948
bool needs_dof_permutations() const noexcept
Check if DOF permutations are needed for this element.
Definition FiniteElement.cpp:649
const std::string & signature() const noexcept
String identifying the finite element.
Definition FiniteElement.cpp:359
const std::vector< std::vector< std::vector< int > > > & entity_dofs() const noexcept
Local DOFs associated with each sub-entity of the cell.
Definition FiniteElement.cpp:432
bool is_mixed() const noexcept
Check if element is a mixed element.
Definition FiniteElement.cpp:484
FiniteElement(const basix::FiniteElement< geometry_type > &element, std::size_t gdim, const std::optional< std::vector< std::size_t > > &value_shape=std::nullopt, bool symmetric=false)
Create a finite element from a Basix finite element.
Definition FiniteElement.cpp:160
int reference_value_size() const
Value size of the base (non-blocked) finite element field on the reference cell.
Definition FiniteElement.cpp:410
int value_size() const
Value size of the finite element field in physical space.
Definition FiniteElement.cpp:371
std::function< void(std::span< U >, std::span< const std::uint32_t >, std::int32_t, int)> dof_transformation_fn(doftransform ttype, bool scalar_element=false) const
Return a function that applies a DOF transformation operator to some data (see T_apply()).
Definition FiniteElement.h:642
bool operator!=(const FiniteElement &e) const
Check if two elements are not equivalent.
Definition FiniteElement.cpp:347
~FiniteElement()=default
Destructor.
T geometry_type
Geometry type of the Mesh that the FunctionSpace is defined on.
Definition FiniteElement.h:205
bool depends_on_facet_orientations() const noexcept
Check if the basis changes sign on the facets whose two cells disagree on the normal (see mesh::Topol...
Definition FiniteElement.cpp:643
int physical_base_value_size() const
Number of physical components in one block of the finite element field.
Definition FiniteElement.cpp:392
const basix::FiniteElement< geometry_type > & basix_element() const
Return underlying Basix element (if it exists).
Definition FiniteElement.cpp:508
FiniteElement(FiniteElement &&element)=default
Move constructor.
int num_sub_elements() const noexcept
Number of sub elements (for a mixed or blocked element).
Definition FiniteElement.cpp:478
void Tt_apply(std::span< U > data, std::uint32_t cell_permutation, int n) const
Apply the transpose of the operator applied by T_apply().
Definition FiniteElement.h:915
const std::vector< std::vector< std::vector< int > > > & entity_closure_dofs() const noexcept
Local DOFs associated with the closure of each sub-entity of the cell.
Definition FiniteElement.cpp:439
std::pair< std::vector< geometry_type >, std::array< std::size_t, 2 > > interpolation_operator() const
Definition FiniteElement.cpp:579
int block_size() const noexcept
Block size of the finite element function space.
Definition FiniteElement.cpp:451
std::span< const std::size_t > reference_value_shape() const
Value shape of the base (non-blocked) finite element field on the reference cell.
Definition FiniteElement.cpp:422
void Tt_apply_right(std::span< U > data, std::uint32_t cell_permutation, int n) const
Right(post)-apply the transpose of the operator applied by T_apply().
Definition FiniteElement.h:984
std::function< void(std::span< U >, std::span< const std::uint32_t >, std::int32_t, int)> dof_transformation_right_fn(doftransform ttype, bool scalar_element=false) const
Return a function that applies DOF transformation to some transposed data (see T_apply_right()).
Definition FiniteElement.h:747
mesh::CellType cell_type() const noexcept
Cell shape that the element is defined on.
Definition FiniteElement.cpp:353
bool interpolation_ident() const noexcept
Definition FiniteElement.cpp:547
void Tinv_apply_right(std::span< U > data, std::uint32_t cell_permutation, int n) const
Right(post)-apply the inverse of the operator applied by T_apply().
Definition FiniteElement.h:966
bool operator==(const FiniteElement &e) const
Check if two elements are equivalent.
Definition FiniteElement.cpp:329
bool map_ident() const noexcept
Definition FiniteElement.cpp:533
Finite element method functionality.
Definition assemble_expression_impl.h:28
doftransform
DOF transformation type.
Definition FiniteElement.h:33
@ transpose
Transpose.
Definition FiniteElement.h:35
@ inverse_transpose
Transpose inverse.
Definition FiniteElement.h:37
@ inverse
Inverse.
Definition FiniteElement.h:36
@ standard
Standard.
Definition FiniteElement.h:34
std::vector< std::size_t > compute_value_shape(basix::maps::type map_type, std::span< const std::size_t > reference_value_shape, std::size_t gdim)
Value shape of a finite element field in physical space.
Definition FiniteElement.cpp:119
@ cell
Cell.
Definition Form.h:42
int cell_dim(CellType type)
Return topological dimension of cell type.
Definition cell_types.h:47
CellType
Cell type identifier.
Definition cell_types.h:24
constexpr std::uint32_t reversed_facet_bit(int f)
Bit of the cell permutation info that negates the degrees-of-freedom on facet f of a cell (see Topolo...
Definition permutationcomputation.h:28
Basix element holder.
Definition FiniteElement.h:86
std::optional< std::vector< std::size_t > > value_shape
Definition FiniteElement.h:93
bool symmetry
Definition FiniteElement.h:94
std::reference_wrapper< const basix::FiniteElement< T > > element
Definition FiniteElement.h:88