ryujin 2.1.1 revision 6dc06e5864abd5d99e5d7ab641dbe621936411d9
convenience_macros.h
Go to the documentation of this file.
1//
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3// Copyright (C) 2020 - 2023 by the ryujin authors
4//
5
6#pragma once
7
8#include <deal.II/base/function.h>
9
14
15namespace ryujin
16{
17#ifndef DOXYGEN
18 namespace
19 {
20 template <int dim, typename Number, typename Callable>
21 class ToFunction : public dealii::Function<dim, Number>
22 {
23 public:
24 ToFunction(const Callable &callable, const unsigned int k)
25 : dealii::Function<dim, Number>(1)
26 , callable_(callable)
27 , k_(k)
28 {
29 }
30
31 Number value(const dealii::Point<dim> &point,
32 unsigned int /*component*/) const override
33 {
34 return callable_(point)[k_];
35 }
36
37 private:
38 const Callable callable_;
39 const unsigned int k_;
40 };
41 } // namespace
42#endif
43
44
68 template <int dim, typename Number, typename Callable>
69 ToFunction<dim, Number, Callable> to_function(const Callable &callable,
70 const unsigned int k)
71 {
72 return {callable, k};
73 }
74
75
79 template <typename FT,
80 int problem_dim = FT::dimension,
81 typename TT = typename FT::value_type,
82 typename T = typename TT::value_type>
83 DEAL_II_ALWAYS_INLINE inline dealii::Tensor<1, problem_dim, T>
84 contract(const FT &flux_ij, const TT &c_ij)
85 {
86 dealii::Tensor<1, problem_dim, T> result;
87 for (unsigned int k = 0; k < problem_dim; ++k)
88 result[k] = flux_ij[k] * c_ij;
89 return result;
90 }
91
92
96 template <typename FT, int problem_dim = FT::dimension>
97 DEAL_II_ALWAYS_INLINE inline FT add(const FT &flux_left_ij,
98 const FT &flux_right_ij)
99 {
100 FT result;
101 for (unsigned int k = 0; k < problem_dim; ++k)
102 result[k] = flux_left_ij[k] + flux_right_ij[k];
103 return result;
104 }
105
106
107} // namespace ryujin
108
109
120#define AssertThrowSIMD(variable, condition, exception) \
121 if constexpr (std::is_same< \
122 typename std::remove_const<decltype(variable)>::type, \
123 double>::value || \
124 std::is_same< \
125 typename std::remove_const<decltype(variable)>::type, \
126 float>::value) { \
127 AssertThrow(condition(variable), exception); \
128 } else { \
129 for (unsigned int k = 0; k < decltype(variable)::size(); ++k) { \
130 AssertThrow(condition((variable)[k]), exception); \
131 } \
132 }
133
134#ifndef DOXYGEN
135namespace
136{
137 template <typename T>
138 class is_dereferenceable
139 {
140 template <typename C>
141 static auto test(...) -> std::false_type;
142
143 template <typename C>
144 static auto test(C *) -> decltype(*std::declval<C>(), std::true_type());
145
146 public:
147 using type = decltype(test<T>(nullptr));
148 static constexpr auto value = type::value;
149 };
150
151 template <typename T, typename>
152 auto dereference(T &t) -> decltype(dereference(*t)) &;
153
154 template <typename T>
155 auto dereference(T &t) -> T &
156 requires(!is_dereferenceable<T>::value)
157 {
158 return t;
159 }
160
161 template <typename T>
162 auto dereference(T &t) -> decltype(*t) &
163 requires is_dereferenceable<T>::value
164 {
165 return *t;
166 }
167} /* anonymous namespace */
168#endif
169
184#define ACCESSOR_READ_ONLY(member) \
185 inline const auto &member() const \
186 { \
187 return dereference(member##_); \
188 }
189
190
196#define ACCESSOR(member) \
197 inline auto &member() \
198 { \
199 return dereference(member##_); \
200 }
201
202
209#define ACCESSOR_READ_ONLY_NO_DEREFERENCE(member) \
210 inline const auto &member() const \
211 { \
212 return member##_; \
213 }
214
215
221#define ASM_LABEL(label) asm("#" label);
222
ToFunction< dim, Number, Callable > to_function(const Callable &callable, const unsigned int k)
DEAL_II_ALWAYS_INLINE FT add(const FT &flux_left_ij, const FT &flux_right_ij)
DEAL_II_ALWAYS_INLINE dealii::Tensor< 1, problem_dim, T > contract(const FT &flux_ij, const TT &c_ij)