DOLFINx
0.2.0
DOLFINx C++ interface
|
9 #include <basix/finite-element.h>
10 #include <dolfinx/common/types.h>
11 #include <dolfinx/mesh/cell_types.h>
16 #include <xtl/xspan.hpp>
18 struct ufc_finite_element;
29 explicit FiniteElement(
const ufc_finite_element& ufc_element);
82 std::string
family()
const noexcept;
93 void tabulate(xt::xtensor<double, 4>& values,
const xt::xtensor<double, 2>& X,
98 const xt::xtensor<double, 3>& reference_values,
99 const xt::xtensor<double, 3>& J,
100 const xtl::span<const double>& detJ,
101 const xt::xtensor<double, 3>& K)
const;
108 const std::vector<std::shared_ptr<const FiniteElement>>&
112 std::size_t
hash()
const noexcept;
115 std::shared_ptr<const FiniteElement>
151 template <
typename T>
153 xtl::span<T> dofs)
const
157 throw std::runtime_error(
"No underlying element for interpolation. "
158 "Cannot interpolate mixed elements directly.");
161 const std::size_t rows = _space_dim / _bs;
162 assert(_space_dim % _bs == 0);
163 assert(dofs.size() == rows);
166 const xt::xtensor<double, 2>& Pi = _element->interpolation_matrix();
167 assert(Pi.size() % rows == 0);
168 const std::size_t cols = Pi.size() / rows;
169 for (std::size_t i = 0; i < rows; ++i)
173 dofs[i] = std::inner_product(std::next(Pi.data(), i * cols),
174 std::next(Pi.data(), i * cols + cols),
175 values.data(), T(0.0));
223 template <typename T>
224 std::function<
void(const xtl::span<T>&, const xtl::span<const std::uint32_t>&,
227 bool scalar_element = false)
const
232 return [](
const xtl::span<T>&,
const xtl::span<const std::uint32_t>&,
239 if (_sub_elements.size() != 0)
244 std::vector<std::function<void(
const xtl::span<T>&,
245 const xtl::span<const std::uint32_t>&,
247 sub_element_functions;
248 std::vector<int> dims;
249 for (std::size_t i = 0; i < _sub_elements.size(); ++i)
251 sub_element_functions.push_back(
252 _sub_elements[i]->get_dof_transformation_function<T>(inverse,
257 return [dims, sub_element_functions](
258 const xtl::span<T>& data,
259 const xtl::span<const std::uint32_t>& cell_info,
262 std::size_t start = 0;
263 for (std::size_t e = 0; e < sub_element_functions.size(); ++e)
265 const std::size_t width = dims[e] *
block_size;
266 sub_element_functions[e](data.subspan(start, width), cell_info,
272 else if (!scalar_element)
275 const std::function<void(
const xtl::span<T>&,
276 const xtl::span<const std::uint32_t>&,
278 sub_function = _sub_elements[0]->get_dof_transformation_function<T>(
282 [ebs, sub_function](
const xtl::span<T>& data,
283 const xtl::span<const std::uint32_t>& cell_info,
284 std::int32_t cell,
int data_block_size)
285 { sub_function(data, cell_info, cell, ebs * data_block_size); };
292 return [
this](
const xtl::span<T>& data,
293 const xtl::span<const std::uint32_t>& cell_info,
302 return [
this](
const xtl::span<T>& data,
303 const xtl::span<const std::uint32_t>& cell_info,
313 return [
this](
const xtl::span<T>& data,
314 const xtl::span<const std::uint32_t>& cell_info,
321 return [
this](
const xtl::span<T>& data,
322 const xtl::span<const std::uint32_t>& cell_info,
344 template <
typename T>
345 std::function<void(
const xtl::span<T>&,
const xtl::span<const std::uint32_t>&,
348 bool transpose =
false,
355 return [](
const xtl::span<T>&,
const xtl::span<const std::uint32_t>&,
361 else if (_sub_elements.size() != 0)
366 std::vector<std::function<void(
const xtl::span<T>&,
367 const xtl::span<const std::uint32_t>&,
369 sub_element_functions;
370 for (std::size_t i = 0; i < _sub_elements.size(); ++i)
372 sub_element_functions.push_back(
373 _sub_elements[i]->get_dof_transformation_to_transpose_function<T>(
374 inverse, transpose));
377 return [
this, sub_element_functions](
378 const xtl::span<T>& data,
379 const xtl::span<const std::uint32_t>& cell_info,
382 std::size_t start = 0;
383 for (std::size_t e = 0; e < sub_element_functions.size(); ++e)
385 const std::size_t width
386 = _sub_elements[e]->space_dimension() *
block_size;
387 sub_element_functions[e](data.subspan(start, width), cell_info,
393 else if (!scalar_element)
396 const std::function<void(
const xtl::span<T>&,
397 const xtl::span<const std::uint32_t>&,
399 sub_function = _sub_elements[0]->get_dof_transformation_function<T>(
402 sub_function](
const xtl::span<T>& data,
403 const xtl::span<const std::uint32_t>& cell_info,
404 std::int32_t cell,
int data_block_size)
407 const std::size_t dof_count = data.size() / data_block_size;
408 for (
int block = 0; block < data_block_size; ++block)
410 sub_function(data.subspan(block * dof_count, dof_count), cell_info,
421 return [
this](
const xtl::span<T>& data,
422 const xtl::span<const std::uint32_t>& cell_info,
431 return [
this](
const xtl::span<T>& data,
432 const xtl::span<const std::uint32_t>& cell_info,
444 return [
this](
const xtl::span<T>& data,
445 const xtl::span<const std::uint32_t>& cell_info,
454 return [
this](
const xtl::span<T>& data,
455 const xtl::span<const std::uint32_t>& cell_info,
469 template <
typename T>
471 std::uint32_t cell_permutation,
475 _element->apply_dof_transformation(data,
block_size, cell_permutation);
485 template <
typename T>
488 std::uint32_t cell_permutation,
492 _element->apply_inverse_transpose_dof_transformation(data,
block_size,
502 template <
typename T>
504 std::uint32_t cell_permutation,
508 _element->apply_transpose_dof_transformation(data,
block_size,
518 template <
typename T>
520 std::uint32_t cell_permutation,
524 _element->apply_inverse_dof_transformation(data,
block_size,
533 template <
typename T>
535 std::uint32_t cell_permutation,
539 _element->apply_dof_transformation_to_transpose(data,
block_size,
548 template <
typename T>
551 std::uint32_t cell_permutation,
555 _element->apply_inverse_dof_transformation_to_transpose(data,
block_size,
564 template <
typename T>
566 const xtl::span<T>& data, std::uint32_t cell_permutation,
570 _element->apply_transpose_dof_transformation_to_transpose(data,
block_size,
579 template <
typename T>
581 const xtl::span<T>& data, std::uint32_t cell_permutation,
585 _element->apply_inverse_transpose_dof_transformation_to_transpose(
607 template <
typename O,
typename P,
typename Q,
typename T,
typename S>
612 _element->map_pull_back_m(u, J, detJ, K, U);
619 void permute_dofs(
const xtl::span<std::int32_t>& doflist,
620 std::uint32_t cell_permutation)
const;
627 std::uint32_t cell_permutation)
const;
640 std::function<void(
const xtl::span<std::int32_t>&, std::uint32_t)>
642 bool scalar_element =
false)
const;
645 std::string _signature, _family;
649 int _tdim, _space_dim, _value_size, _reference_value_size;
652 std::vector<std::shared_ptr<const FiniteElement>> _sub_elements;
658 std::vector<int> _value_dimension;
665 bool _needs_dof_permutations;
666 bool _needs_dof_transformations;
669 std::unique_ptr<basix::FiniteElement> _element;
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:263
FiniteElement(const ufc_finite_element &ufc_element)
Create finite element from UFC finite element.
Definition: FiniteElement.cpp:80
int block_size() const noexcept
Block size of the finite element function space. For VectorElements and TensorElements,...
Definition: FiniteElement.cpp:181
bool interpolation_ident() const noexcept
Check if interpolation into the finite element space is an identity operation given the evaluation on...
Definition: FiniteElement.cpp:235
std::shared_ptr< const FiniteElement > extract_sub_element(const std::vector< int > &component) const
Extract sub finite element for component.
Definition: FiniteElement.cpp:225
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:269
int value_dimension(int i) const
Return the dimension of the value space for axis i.
Definition: FiniteElement.cpp:183
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:580
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:241
void transform_reference_basis(xt::xtensor< double, 3 > &values, const xt::xtensor< double, 3 > &reference_values, const xt::xtensor< double, 3 > &J, const xtl::span< const double > &detJ, const xt::xtensor< double, 3 > &K) const
Push basis functions forward to physical element.
Definition: FiniteElement.cpp:200
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 transformation to some data.
Definition: FiniteElement.cpp:276
CellType
Cell type identifier.
Definition: cell_types.h:21
int reference_value_size() const noexcept
The value size, e.g. 1 for a scalar function, 2 for a 2D vector for the reference element.
Definition: FiniteElement.cpp:171
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:470
int num_sub_elements() const noexcept
Get the number of sub elements (for a mixed element)
Definition: FiniteElement.cpp:210
Finite Element, containing the dof layout on a reference element, and various methods for evaluating ...
Definition: FiniteElement.h:24
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:503
bool needs_dof_permutations() const noexcept
Check if DOF permutations are needed for this element.
Definition: FiniteElement.cpp:258
std::size_t hash() const noexcept
Return simple hash of the signature string.
Definition: FiniteElement.cpp:222
int value_size() const noexcept
The value size, e.g. 1 for a scalar function, 2 for a 2D vector.
Definition: FiniteElement.cpp:169
int space_dimension() const noexcept
Dimension of the finite element function space.
Definition: FiniteElement.cpp:167
std::string family() const noexcept
The finite element family.
Definition: FiniteElement.cpp:191
constexpr void interpolate(const xt::xtensor< T, 2 > &values, xtl::span< T > dofs) const
Definition: FiniteElement.h:152
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:550
FiniteElement & operator=(const FiniteElement &element)=delete
Copy assignment.
virtual ~FiniteElement()=default
Destructor.
int value_rank() const noexcept
Rank of the value space.
Definition: FiniteElement.cpp:176
mesh::CellType cell_shape() const noexcept
Cell shape.
Definition: FiniteElement.cpp:162
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:487
std::string signature() const noexcept
String identifying the finite element.
Definition: FiniteElement.cpp:160
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:193
const std::vector< std::shared_ptr< const FiniteElement > > & sub_elements() const noexcept
Subelements (if any)
Definition: FiniteElement.cpp:216
bool needs_dof_transformations() const noexcept
Check if DOF transformations are needed for this element.
Definition: FiniteElement.cpp:253
Finite element method functionality.
Definition: assemble_matrix_impl.h:22
void map_pull_back(const O &u, const P &J, const Q &detJ, const T &K, S &&U) const
Pull back data from the physical element to the reference element. It can process batches of points t...
Definition: FiniteElement.h:608
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:226
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:347
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:565
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 tranposed data.
Definition: FiniteElement.h:534
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:519