8#include <compile_time_options.h>
10#include <deal.II/base/tensor.h>
11#include <deal.II/base/utilities.h>
12#include <deal.II/base/vectorization.h>
35 template <
typename T, std::
size_t w
idth>
51 template <
typename T, std::
size_t w
idth>
52 constexpr unsigned int get_stride_size<dealii::VectorizedArray<T, width>> =
60 template <
typename Functor,
size_t... Is>
61 auto generate_iterators_impl(Functor f, std::index_sequence<Is...>)
62 -> std::array<
decltype(f(0)),
sizeof...(Is)>
81 template <
unsigned int length,
typename Functor>
83 -> std::array<
decltype(f(0)), length>
85 return generate_iterators_impl<>(f, std::make_index_sequence<length>());
97 for (
auto &it : iterators)
112 template <
typename Number>
115 return std::max(Number(0.), number);
124 template <
typename Number>
127 return -std::min(Number(0.), number);
138 template <
int N,
typename T>
141 return dealii::Utilities::fixed_power<N, T>(x);
150 template <
typename T>
151 T
pow(
const T x,
const T b);
159 template <
typename T, std::
size_t w
idth>
160 dealii::VectorizedArray<T, width>
161 pow(
const dealii::VectorizedArray<T, width> x,
const T b);
170 template <
typename T, std::
size_t w
idth>
171 dealii::VectorizedArray<T, width>
172 pow(
const dealii::VectorizedArray<T, width> x,
173 const dealii::VectorizedArray<T, width> b);
204 template <
typename T>
213 template <
typename T, std::
size_t w
idth>
214 dealii::VectorizedArray<T, width>
215 fast_pow(
const dealii::VectorizedArray<T, width> x,
226 template <
typename T, std::
size_t w
idth>
227 dealii::VectorizedArray<T, width>
228 fast_pow(
const dealii::VectorizedArray<T, width> x,
229 const dealii::VectorizedArray<T, width> b,
244 template <
typename T,
typename V>
245 DEAL_II_ALWAYS_INLINE
inline T
get_entry(
const V &vector,
unsigned int i)
247 static_assert(std::is_same_v<typename get_value_type<T>::type,
248 typename V::value_type>,
252 if constexpr (std::is_same_v<T, typename get_value_type<T>::type>) {
254 result = vector.local_element(i);
257 result.load(vector.get_values() + i);
268 template <
typename T,
typename T2>
269 DEAL_II_ALWAYS_INLINE
inline T
get_entry(
const std::vector<T2> &vector,
272 if constexpr (std::is_same_v<typename get_value_type<T>::type, T2>) {
276 if constexpr (std::is_same_v<T, typename get_value_type<T>::type>) {
281 result.load(vector.data() + i);
288 if constexpr (std::is_same_v<T, typename get_value_type<T>::type>) {
292 for (
unsigned int k = 0; k < T::size(); ++k)
293 result[k] = vector[i + k];
306 template <
typename T,
typename V>
307 DEAL_II_ALWAYS_INLINE
inline T
get_entry(
const V &vector,
308 const unsigned int *js)
310 static_assert(std::is_same_v<typename get_value_type<T>::type,
311 typename V::value_type>,
315 if constexpr (std::is_same_v<T, typename get_value_type<T>::type>) {
317 result = vector.local_element(js[0]);
320 result.gather(vector.get_values(), js);
331 template <
typename T,
typename T2>
332 DEAL_II_ALWAYS_INLINE
inline T
get_entry(
const std::vector<T2> &vector,
333 const unsigned int *js)
335 static_assert(std::is_same_v<typename get_value_type<T>::type, T2>,
339 if constexpr (std::is_same_v<T, typename get_value_type<T>::type>) {
341 result = vector[js[0]];
344 result.load(vector.data(), js);
356 template <
typename T,
typename V>
357 DEAL_II_ALWAYS_INLINE
inline void
360 static_assert(std::is_same_v<typename get_value_type<T>::type,
361 typename V::value_type>,
364 if constexpr (std::is_same_v<T, typename get_value_type<T>::type>) {
366 vector.local_element(i) = values;
369 values.store(vector.get_values() + i);
378 template <
typename T,
typename T2>
379 DEAL_II_ALWAYS_INLINE
inline void
380 write_entry(std::vector<T2> &vector,
const T &values,
unsigned int i)
382 if constexpr (std::is_same_v<typename get_value_type<T>::type, T2>) {
385 if constexpr (std::is_same_v<T, typename get_value_type<T>::type>) {
390 values.store(vector.data() + i);
395 if constexpr (std::is_same_v<T, typename get_value_type<T>::type>) {
399 for (
unsigned int k = 0; k < T::size(); ++k)
400 vector[i + k] = values[k];
411 template <
int rank,
int dim, std::
size_t w
idth,
typename Number>
412 DEAL_II_ALWAYS_INLINE
inline dealii::Tensor<rank, dim, Number>
414 const dealii::Tensor<rank, dim, dealii::VectorizedArray<Number, width>>
416 const unsigned int k)
418 Assert(k < width, dealii::ExcMessage(
"Index past VectorizedArray width"));
419 dealii::Tensor<rank, dim, Number> result;
420 if constexpr (rank == 1) {
421 for (
unsigned int d = 0; d < dim; ++d)
422 result[d] = vectorized[d][k];
424 for (
unsigned int d = 0; d < dim; ++d)
437 template <
int rank,
int dim,
typename Number>
438 DEAL_II_ALWAYS_INLINE
inline dealii::Tensor<rank, dim, Number>
440 const unsigned int k [[maybe_unused]])
444 "The given index k must be zero for a serial tensor"));
454 template <
int rank,
int dim, std::
size_t w
idth,
typename Number>
456 dealii::Tensor<rank, dim, dealii::VectorizedArray<Number, width>> &result,
457 const dealii::Tensor<rank, dim, Number> &serial,
458 const unsigned int k)
460 Assert(k < width, dealii::ExcMessage(
"Index past VectorizedArray width"));
461 if constexpr (rank == 1) {
462 for (
unsigned int d = 0; d < dim; ++d)
465 for (
unsigned int d = 0; d < dim; ++d)
477 template <
int rank,
int dim,
typename Number>
478 DEAL_II_ALWAYS_INLINE
inline void
480 const dealii::Tensor<rank, dim, Number> &serial,
481 const unsigned int k [[maybe_unused]])
485 "The given index k must be zero for a serial tensor"));
DEAL_II_ALWAYS_INLINE void assign_serial_tensor(dealii::Tensor< rank, dim, dealii::VectorizedArray< Number, width > > &result, const dealii::Tensor< rank, dim, Number > &serial, const unsigned int k)
DEAL_II_ALWAYS_INLINE auto generate_iterators(Functor f) -> std::array< auto, length >
T pow(const T x, const T b)
constexpr unsigned int get_stride_size
DEAL_II_ALWAYS_INLINE void increment_iterators(T &iterators)
DEAL_II_ALWAYS_INLINE T get_entry(const V &vector, unsigned int i)
DEAL_II_ALWAYS_INLINE Number negative_part(const Number number)
DEAL_II_ALWAYS_INLINE void write_entry(V &vector, const T &values, unsigned int i)
T fast_pow(const T x, const T b, const Bias bias=Bias::none)
DEAL_II_ALWAYS_INLINE Number positive_part(const Number number)
DEAL_II_ALWAYS_INLINE dealii::Tensor< rank, dim, Number > serialize_tensor(const dealii::Tensor< rank, dim, dealii::VectorizedArray< Number, width > > &vectorized, const unsigned int k)