9 #include <basix/finite-element.h>
10 #include <dolfinx/mesh/cell_types.h>
14 #include <xtensor/xtensor.hpp>
15 #include <xtl/xspan.hpp>
17 struct ufcx_finite_element;
104 std::
string family() const noexcept;
116 void tabulate(xt::xtensor<
double, 4>& values, const xt::xtensor<
double, 2>& X,
153 template <typename O, typename P, typename Q, typename R>
154 std::function<
void(O&, const P&, const Q&,
double, const R&)>
map_fn()
const
157 return _element->map_fn<O, P, Q, R>();
222 xt::xtensor<
double, 2>
273 template <typename T>
274 std::function<
void(const xtl::span<T>&, const xtl::span<const std::uint32_t>&,
277 bool scalar_element = false)
const
282 return [](
const xtl::span<T>&,
const xtl::span<const std::uint32_t>&,
289 if (_sub_elements.size() != 0)
294 std::vector<std::function<void(
const xtl::span<T>&,
295 const xtl::span<const std::uint32_t>&,
297 sub_element_functions;
298 std::vector<int> dims;
299 for (std::size_t i = 0; i < _sub_elements.size(); ++i)
301 sub_element_functions.push_back(
302 _sub_elements[i]->get_dof_transformation_function<T>(inverse,
307 return [dims, sub_element_functions](
308 const xtl::span<T>& data,
309 const xtl::span<const std::uint32_t>& cell_info,
312 std::size_t offset = 0;
313 for (std::size_t e = 0; e < sub_element_functions.size(); ++e)
315 const std::size_t width = dims[e] *
block_size;
316 sub_element_functions[e](data.subspan(offset, width), cell_info,
322 else if (!scalar_element)
325 const std::function<void(
const xtl::span<T>&,
326 const xtl::span<const std::uint32_t>&,
328 sub_function = _sub_elements[0]->get_dof_transformation_function<T>(
332 [ebs, sub_function](
const xtl::span<T>& data,
333 const xtl::span<const std::uint32_t>& cell_info,
334 std::int32_t
cell,
int data_block_size)
335 { sub_function(data, cell_info,
cell, ebs * data_block_size); };
342 return [
this](
const xtl::span<T>& data,
343 const xtl::span<const std::uint32_t>& cell_info,
352 return [
this](
const xtl::span<T>& data,
353 const xtl::span<const std::uint32_t>& cell_info,
363 return [
this](
const xtl::span<T>& data,
364 const xtl::span<const std::uint32_t>& cell_info,
371 return [
this](
const xtl::span<T>& data,
372 const xtl::span<const std::uint32_t>& cell_info,
397 template <
typename T>
398 std::function<void(
const xtl::span<T>&,
const xtl::span<const std::uint32_t>&,
401 bool transpose =
false,
408 return [](
const xtl::span<T>&,
const xtl::span<const std::uint32_t>&,
414 else if (_sub_elements.size() != 0)
419 std::vector<std::function<void(
const xtl::span<T>&,
420 const xtl::span<const std::uint32_t>&,
422 sub_element_functions;
423 for (std::size_t i = 0; i < _sub_elements.size(); ++i)
425 sub_element_functions.push_back(
426 _sub_elements[i]->get_dof_transformation_to_transpose_function<T>(
427 inverse, transpose));
430 return [
this, sub_element_functions](
431 const xtl::span<T>& data,
432 const xtl::span<const std::uint32_t>& cell_info,
435 std::size_t offset = 0;
436 for (std::size_t e = 0; e < sub_element_functions.size(); ++e)
438 sub_element_functions[e](data.subspan(offset, data.size() - offset),
440 offset += _sub_elements[e]->space_dimension();
444 else if (!scalar_element)
447 const std::function<void(
const xtl::span<T>&,
448 const xtl::span<const std::uint32_t>&,
450 sub_function = _sub_elements[0]->get_dof_transformation_function<T>(
453 sub_function](
const xtl::span<T>& data,
454 const xtl::span<const std::uint32_t>& cell_info,
455 std::int32_t
cell,
int data_block_size)
458 const std::size_t dof_count = data.size() / data_block_size;
459 for (
int block = 0; block < data_block_size; ++block)
461 sub_function(data.subspan(block * dof_count, dof_count), cell_info,
472 return [
this](
const xtl::span<T>& data,
473 const xtl::span<const std::uint32_t>& cell_info,
482 return [
this](
const xtl::span<T>& data,
483 const xtl::span<const std::uint32_t>& cell_info,
495 return [
this](
const xtl::span<T>& data,
496 const xtl::span<const std::uint32_t>& cell_info,
505 return [
this](
const xtl::span<T>& data,
506 const xtl::span<const std::uint32_t>& cell_info,
521 template <
typename T>
523 std::uint32_t cell_permutation,
527 _element->apply_dof_transformation(data,
block_size, cell_permutation);
538 template <
typename T>
541 std::uint32_t cell_permutation,
545 _element->apply_inverse_transpose_dof_transformation(data,
block_size,
556 template <
typename T>
558 std::uint32_t cell_permutation,
562 _element->apply_transpose_dof_transformation(data,
block_size,
573 template <
typename T>
575 std::uint32_t cell_permutation,
579 _element->apply_inverse_dof_transformation(data,
block_size,
589 template <
typename T>
591 std::uint32_t cell_permutation,
595 _element->apply_dof_transformation_to_transpose(data,
block_size,
605 template <
typename T>
608 std::uint32_t cell_permutation,
612 _element->apply_inverse_dof_transformation_to_transpose(data,
block_size,
622 template <
typename T>
624 const xtl::span<T>& data, std::uint32_t cell_permutation,
628 _element->apply_transpose_dof_transformation_to_transpose(data,
block_size,
638 template <
typename T>
640 const xtl::span<T>& data, std::uint32_t cell_permutation,
644 _element->apply_inverse_transpose_dof_transformation_to_transpose(
652 void permute_dofs(
const xtl::span<std::int32_t>& doflist,
653 std::uint32_t cell_permutation)
const;
660 std::uint32_t cell_permutation)
const;
673 std::function<void(
const xtl::span<std::int32_t>&, std::uint32_t)>
675 bool scalar_element =
false)
const;
678 std::string _signature, _family;
685 std::vector<std::shared_ptr<const FiniteElement>> _sub_elements;
688 std::vector<int> _value_shape;
695 bool _needs_dof_permutations;
696 bool _needs_dof_transformations;
699 std::unique_ptr<basix::FiniteElement> _element;
Finite Element, containing the dof layout on a reference element, and various methods for evaluating ...
Definition: FiniteElement.h:24
std::function< void(const xtl::span< T > &, const xtl::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.
Definition: FiniteElement.h:400
const xt::xtensor< double, 2 > & interpolation_points() const
Points on the reference cell at which an expression need to be evaluated in order to interpolate the ...
Definition: FiniteElement.cpp:382
std::string family() const noexcept
The finite element family.
Definition: FiniteElement.cpp:323
basix::maps::type map_type() const
Get the map type used by the element.
Definition: FiniteElement.cpp:359
int space_dimension() const noexcept
Dimension of the finite element function space (the number of degrees-of-freedom for the element)
Definition: FiniteElement.cpp:302
xtl::span< const int > value_shape() const noexcept
Shape of the value space. The rank is the size of the value_shape.
Definition: FiniteElement.cpp:318
void apply_transpose_dof_transformation_to_transpose(const xtl::span< T > &data, std::uint32_t cell_permutation, int block_size) const
Apply transpose of transformation to some transposed data.
Definition: FiniteElement.h:623
bool needs_dof_transformations() const noexcept
Check if DOF transformations are needed for this element.
Definition: FiniteElement.cpp:447
FiniteElement(const FiniteElement &element)=delete
Copy constructor.
FiniteElement(const ufcx_finite_element &e)
Create finite element from UFC finite element.
Definition: FiniteElement.cpp:99
void apply_inverse_dof_transformation_to_transpose(const xtl::span< T > &data, std::uint32_t cell_permutation, int block_size) const
Apply inverse of DOF transformation to some transposed data.
Definition: FiniteElement.h:607
void apply_inverse_transpose_dof_transformation(const xtl::span< T > &data, std::uint32_t cell_permutation, int block_size) const
Apply inverse transpose transformation to some data. For VectorElements, this applies the transformat...
Definition: FiniteElement.h:540
std::string signature() const noexcept
String identifying the finite element.
Definition: FiniteElement.cpp:295
void permute_dofs(const xtl::span< std::int32_t > &doflist, std::uint32_t cell_permutation) const
Permute the DOFs of the element.
Definition: FiniteElement.cpp:457
bool needs_dof_permutations() const noexcept
Check if DOF permutations are needed for this element.
Definition: FiniteElement.cpp:452
const xt::xtensor< double, 2 > & interpolation_operator() const
Interpolation operator (matrix) Pi that maps a function evaluated at the points provided by FiniteEle...
Definition: FiniteElement.cpp:394
void apply_inverse_transpose_dof_transformation_to_transpose(const xtl::span< T > &data, std::uint32_t cell_permutation, int block_size) const
Apply inverse transpose transformation to some transposed data.
Definition: FiniteElement.h:639
std::function< void(const xtl::span< T > &, const xtl::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.
Definition: FiniteElement.h:276
bool is_mixed() const noexcept
Check if element is a mixed element, i.e. composed of two or more elements of different types....
Definition: FiniteElement.cpp:337
void apply_dof_transformation(const xtl::span< T > &data, std::uint32_t cell_permutation, int block_size) const
Apply DOF transformation to some data.
Definition: FiniteElement.h:522
std::shared_ptr< const FiniteElement > extract_sub_element(const std::vector< int > &component) const
Extract sub finite element for component.
Definition: FiniteElement.cpp:349
FiniteElement & operator=(FiniteElement &&element)=default
Move assignment.
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,...
Definition: FiniteElement.cpp:310
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.
Definition: FiniteElement.cpp:304
virtual ~FiniteElement()=default
Destructor.
void apply_dof_transformation_to_transpose(const xtl::span< T > &data, std::uint32_t cell_permutation, int block_size) const
Apply DOF transformation to some transposed data.
Definition: FiniteElement.h:590
bool operator!=(const FiniteElement &e) const
Check if two elements are not equivalent.
Definition: FiniteElement.cpp:290
std::function< void(O &, const P &, const Q &, double, const R &)> map_fn() const
Return a function that performs the appropriate push-forward (pull-back) for the element type.
Definition: FiniteElement.h:154
xt::xtensor< double, 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:406
void apply_inverse_dof_transformation(const xtl::span< T > &data, std::uint32_t cell_permutation, int block_size) const
Apply inverse transformation to some data. For VectorElements, this applies the transformations for t...
Definition: FiniteElement.h:574
std::function< void(const xtl::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.
Definition: FiniteElement.cpp:470
FiniteElement(FiniteElement &&element)=default
Move constructor.
int num_sub_elements() const noexcept
Get the number of sub elements (for a mixed or blocked element)
Definition: FiniteElement.cpp:332
void apply_transpose_dof_transformation(const xtl::span< T > &data, std::uint32_t cell_permutation, int block_size) const
Apply transpose transformation to some data. For VectorElements, this applies the transformations for...
Definition: FiniteElement.h:557
void unpermute_dofs(const xtl::span< std::int32_t > &doflist, std::uint32_t cell_permutation) const
Unpermute the DOFs of the element.
Definition: FiniteElement.cpp:463
FiniteElement & operator=(const FiniteElement &element)=delete
Copy assignment.
int block_size() const noexcept
Block size of the finite element function space. For VectorElements and TensorElements,...
Definition: FiniteElement.cpp:316
const std::vector< std::shared_ptr< const FiniteElement > > & sub_elements() const noexcept
Subelements (if any)
Definition: FiniteElement.cpp:343
void tabulate(xt::xtensor< double, 4 > &values, const xt::xtensor< double, 2 > &X, int order) const
Evaluate all derivatives of the basis functions up to given order at given points in reference cell.
Definition: FiniteElement.cpp:325
bool interpolation_ident() const noexcept
Check if interpolation into the finite element space is an identity operation given the evaluation on...
Definition: FiniteElement.cpp:376
bool operator==(const FiniteElement &e) const
Check if two elements are equivalent.
Definition: FiniteElement.cpp:280
mesh::CellType cell_shape() const noexcept
Cell shape.
Definition: FiniteElement.cpp:297
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...
Definition: FiniteElement.cpp:370
Finite element method functionality.
Definition: assemble_matrix_impl.h:24
CellType
Cell type identifier.
Definition: cell_types.h:22