18 constexpr bool strings_equal(
char const *a,
char const *b) {
return std::string_view(a) == b; }
28 static_assert(
sizeof...(strs) == std::tuple_size_v<tuple_type>,
29 "Number of names must match number of elements in tuple");
32 constexpr operator tuple_type &() {
return tuple; }
34 static constexpr size_t size =
sizeof...(strs);
35 static constexpr std::array<const char *, size>
names{{strs...}};
39 []<
size_t... I>(std::index_sequence<I...>) {
40 for (
size_t i : {I...})
41 for (
size_t j : {I...})
44 }(std::make_index_sequence<size>{}),
45 "Names of a named_tuple must be unique!");
50 template <
typename... T>
static constexpr auto as(std::tuple<T...> &&tup)
54 template <
typename... T>
static constexpr auto as(std::tuple<T...> &tup)
59 static consteval size_t get_idx(
const char *name)
61 size_t running_sum = 0;
62 for (
size_t i = 0; i <
names.size(); ++i) {
68 return size != running_sum ? 0
69 :
throw std::invalid_argument(
70 "named_tuple::get_idx: Name \"" + std::string(name) +
71 "\" not found. Available names are: " + ((std::string(strs) +
"; ") + ...));
96 return std::get<named_tuple<tuple_type, strs...>::get_idx(name)>(ob.
tuple);
99 template <
size_t idx,
typename tuple_type,
FixedString... strs>
100 constexpr auto &
get(named_tuple<tuple_type, strs...> &ob)
104 template <
size_t idx,
typename tuple_type,
FixedString... strs>
105 constexpr auto &
get(named_tuple<tuple_type, strs...> &&ob)
109 template <
size_t idx,
typename tuple_type,
FixedString... strs>
110 constexpr auto &
get(
const named_tuple<tuple_type, strs...> &ob)
136 struct tuple_size<
DiFfRG::named_tuple<tuple_type, strs...>> : std::integral_constant<size_t, sizeof...(strs)> {
172 for (
uint i = 0; i < N * M; ++i)
181 if constexpr (std::is_floating_point_v<NT> || std::is_same_v<NT, autodiff::real>) {
182 for (
uint i = 0; i < N * M; ++i)
193 for (
uint i = 0; i < N; ++i) {
194 for (
uint j = 0; j < M; ++j)
195 std::cout <<
data[i * M + j] <<
" ";
196 std::cout << std::endl;
203 template <u
int n,
typename NT,
typename Vector> std::array<NT, n>
vector_to_array(
const Vector &v)
206 for (
uint i = 0; i < n; ++i)
211 template <
typename T, std::size_t... Indices>
214 return std::tie(v[Indices]...);
218 assert(v.size() >= N);
222 template <
typename Head,
typename... Tail>
constexpr auto tuple_tail(
const std::tuple<Head, Tail...> &t)
224 return std::apply([](
auto & ,
auto &...tail) {
return std::tie(tail...); }, t);
227 template <
typename tuple_type,
FixedString... strs>
233 template <
int i,
typename Head,
typename... Tail>
constexpr auto tuple_last(
const std::tuple<Head, Tail...> &t)
235 if constexpr (
sizeof...(Tail) == i)
236 return std::apply([](
auto & ,
auto &...tail) {
return std::tie(tail...); }, t);
238 return std::apply([](
auto & ,
auto &...tail) {
return tuple_last<i>(std::tie(tail...)); }, t);
241 template <
int i,
typename tuple_type,
FixedString... strs>
247 template <
int i,
typename Head,
typename... Tail>
constexpr auto tuple_first(
const std::tuple<Head, Tail...> &t)
249 if constexpr (i == 0)
251 else if constexpr (i == 1)
252 return std::apply([](
auto &head,
auto &...) {
return std::tie(head); }, t);
255 [](
auto &head,
auto &...tail) {
261 template <
int i,
typename tuple_type,
FixedString... strs>
273 template <
typename T,
size_t N,
size_t... IDXs>
276 return std::tie(a[IDXs][q_index]...);
278 template <
typename T,
size_t N>
auto local_sol_q(
const std::array<T, N> &a,
uint q_index)
283 template <
typename T_inner,
typename Model,
size_t... IDXs>
auto _jacobian_tuple(std::index_sequence<IDXs...>)
285 return std::tuple{
SimpleMatrix<T_inner, Model::Components::count_fe_functions(0),
286 Model::Components::count_fe_functions(IDXs)>()...};
293 template <
typename T_inner,
typename Model,
size_t... IDXs>
auto _jacobian_2_tuple(std::index_sequence<IDXs...>)
295 return std::tuple{std::array<
296 SimpleMatrix<T_inner, Model::Components::count_fe_functions(0), Model::Components::count_fe_functions(IDXs)>,
A simple NxM-matrix class, which is used for cell-wise Jacobians.
Definition tuples.hh:153
const NT & operator()(const uint n, const uint m) const
Access the matrix entry at (n,m).
Definition tuples.hh:165
NT & operator()(const uint n, const uint m)
Access the matrix entry at (n,m).
Definition tuples.hh:160
SimpleMatrix()
Definition tuples.hh:155
std::array< NT, N *M > data
Definition tuples.hh:201
void clear()
Set all entries to zero.
Definition tuples.hh:170
bool is_finite() const
Check whether the matrix contains only finite values.
Definition tuples.hh:179
void print() const
Print the matrix to the console.
Definition tuples.hh:191
Definition complex_math.hh:14
constexpr auto tuple_tail(const std::tuple< Head, Tail... > &t)
Definition tuples.hh:222
auto _jacobian_tuple(std::index_sequence< IDXs... >)
Definition tuples.hh:283
constexpr auto & get(named_tuple< tuple_type, strs... > &ob)
get a reference to the element with the given name
Definition tuples.hh:82
constexpr auto tuple_first(const std::tuple< Head, Tail... > &t)
Definition tuples.hh:247
auto _jacobian_2_tuple(std::index_sequence< IDXs... >)
Definition tuples.hh:293
auto local_sol_q(const std::array< T, N > &a, uint q_index)
Definition tuples.hh:278
auto jacobian_tuple()
Definition tuples.hh:288
auto _local_sol_tuple(const std::array< T, N > &a, std::index_sequence< IDXs... >, uint q_index)
Definition tuples.hh:274
constexpr bool strings_equal(char const *a, char const *b)
Check if two strings are equal at compile time.
Definition tuples.hh:18
auto vectorToTupleHelper(const std::vector< T > &v, std::index_sequence< Indices... >)
Definition tuples.hh:212
auto vector_to_tuple(const std::vector< T > &v)
Definition tuples.hh:216
auto jacobian_2_tuple()
Definition tuples.hh:299
std::array< NT, n > vector_to_array(const Vector &v)
Definition tuples.hh:203
unsigned int uint
Definition utils.hh:22
constexpr auto tuple_last(const std::tuple< Head, Tail... > &t)
Definition tuples.hh:233
FixedString(char const (&)[N]) -> FixedString< N - 1 >
bool isfinite(const autodiff::Real< N, T > &x)
Finite-ness check for autodiff::real.
Definition math.hh:26
constexpr auto & get(DiFfRG::named_tuple< tuple_type, strs... > &ob)
Definition tuples.hh:119
A fixed size compile-time string.
Definition fixed_string.hh:10
A class to store a tuple with elements that can be accessed by name. The names are stored as FixedStr...
Definition tuples.hh:27
named_tuple(tuple_type &&t)
Definition tuples.hh:47
tuple_type tuple
Definition tuples.hh:30
static constexpr auto as(std::tuple< T... > &&tup)
Definition tuples.hh:50
const auto & get() const
Definition tuples.hh:75
static consteval size_t get_idx(const char *name)
Definition tuples.hh:59
static constexpr auto as(std::tuple< T... > &tup)
Definition tuples.hh:54
static constexpr size_t size
Definition tuples.hh:34
auto & get()
Definition tuples.hh:74
static constexpr std::array< const char *, size > names
Definition tuples.hh:35
named_tuple(tuple_type &t)
Definition tuples.hh:48