8#include <compile_time_options.h>
10#include <deal.II/base/function.h>
11#include <deal.II/lac/vector.h>
18 template <
int dim,
typename Number,
typename Callable>
19 class ToFunction :
public dealii::Function<dim, Number>
22 ToFunction(
const Callable &callable,
const unsigned int k)
23 : dealii::Function<dim, Number>(1)
29 Number value(
const dealii::Point<dim> &point,
30 unsigned int )
const override
32 return callable_(point)[k_];
36 const Callable callable_;
37 const unsigned int k_;
41 template <
int dim,
typename Number,
typename Callable>
42 class ToVectorFunction :
public dealii::Function<dim, Number>
45 ToVectorFunction(
const Callable &callable,
const unsigned int components)
46 : dealii::Function<dim, Number>(components)
51 Number value(
const dealii::Point<dim> &point,
52 unsigned int component)
const override
54 return callable_(point)[component];
57 void vector_value(
const dealii::Point<dim> &point,
58 dealii::Vector<double> &values)
const override
60 AssertDimension(values.size(), this->n_components);
62 const auto temp = callable_(point);
63 for (
unsigned int k = 0; k < this->n_components; ++k)
68 const Callable callable_;
103 template <
int dim,
typename Number,
typename Callable>
104 ToFunction<dim, Number, Callable>
to_function(
const Callable &callable,
105 const unsigned int k)
107 return {callable, k};
132 template <
int dim,
typename Number,
typename Callable>
133 ToVectorFunction<dim, Number, Callable>
136 return {callable, n_components};
143 template <
typename FT,
144 int problem_dim = FT::dimension,
145 typename TT =
typename FT::value_type,
146 typename T =
typename TT::value_type>
147 DEAL_II_HOST_DEVICE_ALWAYS_INLINE dealii::Tensor<1, problem_dim, T>
150 dealii::Tensor<1, problem_dim, T> result;
151 for (
unsigned int k = 0; k < problem_dim; ++k)
152 result[k] = flux_ij[k] * c_ij;
160 template <
typename FT,
int problem_dim = FT::dimension>
161 DEAL_II_HOST_DEVICE_ALWAYS_INLINE FT
add(
const FT &flux_left_ij,
162 const FT &flux_right_ij)
165 for (
unsigned int k = 0; k < problem_dim; ++k)
166 result[k] = flux_left_ij[k] + flux_right_ij[k];
177 template <
typename T>
178 class is_dereferenceable
180 template <
typename C>
181 static auto test(...) -> std::false_type;
183 template <
typename C>
184 static auto test(C *) ->
decltype(*std::declval<C>(), std::true_type());
187 using type =
decltype(test<T>(
nullptr));
188 static constexpr auto value = type::value;
191 template <
typename T,
typename>
192 auto dereference(T &t) ->
decltype(dereference(*t)) &;
194 template <
typename T>
195 auto dereference(T &t) -> T &
196 requires(!is_dereferenceable<T>::value)
201 template <
typename T>
202 auto dereference(T &t) ->
decltype(*t) &
203 requires is_dereferenceable<T>::value
229#define ACCESSOR_READ_ONLY(member) \
230 inline const auto &member() const \
232 return dereference(member##_); \
241#define ACCESSOR(member) \
242 inline auto &member() \
244 return dereference(member##_); \
254#define ACCESSOR_READ_ONLY_NO_DEREFERENCE(member) \
255 inline const auto &member() const \
272#define ACCESSOR_CONTAINER_READ_ONLY(container, member) \
273 inline const auto &member() const \
275 return dereference(dereference(container).member); \
292#if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__) || \
293 defined(__SYCL_DEVICE_ONLY__)
294#define RYUJIN_DEVICE_COMPILATION_PASS
304#define RYUJIN_PRAGMA(x) _Pragma(#x)
321#define RYUJIN_LIKELY(x) (__builtin_expect(!!(x), 1))
338#define RYUJIN_UNLIKELY(x) (__builtin_expect(!!(x), 0))
346#define ASM_LABEL(label) asm("#" label);
ToVectorFunction< dim, Number, Callable > to_vector_function(const Callable &callable, const unsigned int n_components)
DEAL_II_HOST_DEVICE_ALWAYS_INLINE dealii::Tensor< 1, problem_dim, T > contract(const FT &flux_ij, const TT &c_ij)
ToFunction< dim, Number, Callable > to_function(const Callable &callable, const unsigned int k)
DEAL_II_HOST_DEVICE_ALWAYS_INLINE FT add(const FT &flux_left_ij, const FT &flux_right_ij)