42 const ufcx_expression& e,
43 const std::vector<std::shared_ptr<
const Function<T, U>>>& coefficients,
44 const std::vector<std::shared_ptr<
const Constant<T>>>& constants,
45 const std::vector<std::reference_wrapper<const mesh::EntityMap>>&
49 if (e.rank > 0 and !argument_space)
51 throw std::invalid_argument(
"Expression has Argument but no Argument "
52 "function space was provided.");
55 std::vector<U> X(e.points, e.points + e.num_points * e.entity_dimension);
56 std::array<std::size_t, 2> Xshape
57 = {
static_cast<std::size_t
>(e.num_points),
58 static_cast<std::size_t
>(e.entity_dimension)};
59 std::vector<std::size_t> value_shape(e.value_shape,
60 e.value_shape + e.num_components);
62 static_assert(std::is_same_v<U, scalar_value_t<T>>,
63 "UFCx kernels require geometry type U == scalar_value_t<T>.");
65 using kptr_t = void (*)(T*,
const T*,
const T*,
const U*,
const int*,
66 const std::uint8_t*,
void*);
67 std::function<void(T*,
const T*,
const T*,
const U*,
const int*,
68 const std::uint8_t*,
void*)>
69 tabulate_tensor =
nullptr;
70 if constexpr (std::is_same_v<T, float>)
71 tabulate_tensor =
reinterpret_cast<kptr_t
>(e.tabulate_tensor_float32);
72 else if constexpr (std::is_same_v<T, double>)
73 tabulate_tensor =
reinterpret_cast<kptr_t
>(e.tabulate_tensor_float64);
74#ifndef DOLFINX_NO_STDC_COMPLEX_KERNELS
75 else if constexpr (std::is_same_v<T, std::complex<float>>)
76 tabulate_tensor =
reinterpret_cast<kptr_t
>(e.tabulate_tensor_complex64);
77 else if constexpr (std::is_same_v<T, std::complex<double>>)
78 tabulate_tensor =
reinterpret_cast<kptr_t
>(e.tabulate_tensor_complex128);
81 throw std::invalid_argument(
"Type not supported.");
83 assert(tabulate_tensor);
84 std::uint64_t e_hash = e.coordinate_element_hash;
85 return Expression(coefficients, constants, std::span<const U>(X), Xshape,
86 tabulate_tensor, value_shape, entity_maps, e_hash,
94 const ufcx_expression& e,
95 const std::map<std::string, std::shared_ptr<
const Function<T, U>>>&
97 const std::map<std::string, std::shared_ptr<
const Constant<T>>>& constants,
98 const std::vector<std::reference_wrapper<const mesh::EntityMap>>&
103 std::vector<std::shared_ptr<const Function<T, U>>> coeff_map;
104 std::vector<std::string> coefficient_names;
105 coefficient_names.reserve(e.num_coefficients);
106 for (
int i = 0; i < e.num_coefficients; ++i)
107 coefficient_names.push_back(e.coefficient_names[i]);
109 for (
const std::string& name : coefficient_names)
111 if (
auto it = coefficients.find(name); it != coefficients.end())
112 coeff_map.push_back(it->second);
115 throw std::runtime_error(
116 std::format(
"Expression coefficient \"{}\" not provided.", name));
121 std::vector<std::shared_ptr<const Constant<T>>> const_map;
122 std::vector<std::string> constant_names;
123 constant_names.reserve(e.num_constants);
124 for (
int i = 0; i < e.num_constants; ++i)
125 constant_names.push_back(e.constant_names[i]);
127 for (
const std::string& name : constant_names)
129 if (
auto it = constants.find(name); it != constants.end())
130 const_map.push_back(it->second);
133 throw std::runtime_error(
134 std::format(
"Expression constant \"{}\" not provided.", name));
This class represents a finite element function space defined by a mesh, a finite element,...
Definition FunctionSpace.h:35
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, const std::vector< std::reference_wrapper< const mesh::EntityMap > > &entity_maps, std::shared_ptr< const FunctionSpace< U > > argument_space=nullptr)
Create Expression from UFC.
Definition expression_factory.h:41