22 typename T::tuple_type;
23 typename T::tuple_names;
24 { t.tuple } -> std::same_as<typename T::tuple_type>;
25 { t.names } -> std::same_as<typename T::tuple_names>;
26 { t.size } -> std::same_as<size_t>;
32 constexpr bool strings_equal(
char const *a,
char const *b) {
return std::string_view(a) == b; }
35 static constexpr size_t size =
sizeof...(strs);
36 static constexpr std::array<const char *, size>
names{{strs...}};
40 []<
size_t... I>(std::index_sequence<I...>) {
41 for (
size_t i : {I...})
42 for (
size_t j : {I...})
45 }(std::make_index_sequence<size>{}),
46 "Names of a StringSet must be unique!");
56 template <
typename tuple_type,
typename tuple_names>
struct named_tuple {
57 static_assert(tuple_names::size == std::tuple_size_v<tuple_type>,
58 "Number of names must match number of elements in tuple");
61 constexpr operator tuple_type &() {
return tuple; }
63 static constexpr size_t size = tuple_names::size;
64 static constexpr auto names = tuple_names::names;
68 []<
size_t... I>(std::index_sequence<I...>) {
69 for (
size_t i : {I...})
70 for (
size_t j : {I...})
73 }(std::make_index_sequence<size>{}),
74 "Names of a named_tuple must be unique!");
79 template <
typename... T>
static constexpr auto as(std::tuple<T...> &&tup)
81 return named_tuple<std::tuple<T...>, tuple_names>(tup);
83 template <
typename... T>
static constexpr auto as(std::tuple<T...> &tup)
85 return named_tuple<std::tuple<T...>, tuple_names>(tup);
88 static consteval size_t get_idx(
const char *name)
90 size_t running_sum = 0;
91 for (
size_t i = 0; i <
names.size(); ++i) {
97 return size != running_sum
99 :
throw std::invalid_argument(
"named_tuple::get_idx: Name \"" + std::string(name) +
100 "\" not found. Available names are: " + ((std::string(
"") +
"; ") +
""));
103 template <
size_t idx>
auto &
get() {
return std::get<idx>(
tuple); }
104 template <
size_t idx>
const auto &
get()
const {
return std::get<idx>(
tuple); }
110 template <FixedString name,
typename tuple_type,
typename strSet>
114 return ob.template get<idx>();
116 template <FixedString name,
typename tuple_type,
typename strSet>
120 return ob.template get<idx>();
122 template <FixedString name,
typename tuple_type,
typename strSet>
125 return std::get<named_tuple<tuple_type, strSet>::get_idx(name)>(ob.
tuple);
128 template <
size_t idx,
typename tuple_type,
typename strSet>
constexpr auto &get(named_tuple<tuple_type, strSet> &ob)
130 return ob.template get<idx>();
132 template <
size_t idx,
typename tuple_type,
typename strSet>
constexpr auto &
get(named_tuple<tuple_type, strSet> &&ob)
134 return ob.template get<idx>();
136 template <
size_t idx,
typename tuple_type,
typename strSet>
137 constexpr auto &
get(
const named_tuple<tuple_type, strSet> &ob)
139 return ob.template get<idx>();
175 for (
uint i = 0; i < N * M; ++i)
181 if constexpr (std::is_floating_point_v<NT>) {
182 for (
uint i = 0; i < N * M; ++i)
183 if (!std::isfinite(
data[i]))
return false;
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;
204 template <u
int n,
typename NT,
typename Vector> std::array<NT, n>
vector_to_array(
const Vector &v)
207 for (
uint i = 0; i < n; ++i)
212 template <
typename T, std::size_t... Indices>
215 return std::tie(v[Indices]...);
219 assert(v.size() >= N);
223 template <
typename Head,
typename... Tail>
constexpr auto tuple_tail(
const std::tuple<Head, Tail...> &t)
225 return std::apply([](
auto & ,
auto &...tail) {
return std::tie(tail...); }, t);
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,
typename strSet>
244 return tuple_last<i>(t.
tuple);
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) {
256 return std::tuple_cat(std::tie(head), tuple_first<i - 1>(std::tie(tail...)));
261 template <
int i,
typename tuple_type,
typename strSet>
264 return tuple_first<i>(t.
tuple);
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)>()...};
290 return _jacobian_tuple<T_inner, Model>(std::make_index_sequence<Model::Components::count_fe_subsystems()>{});
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)>,
301 return _jacobian_2_tuple<T_inner, Model>(std::make_index_sequence<Model::Components::count_fe_subsystems()>{});
A simple NxM-matrix class, which is used for cell-wise Jacobians.
Definition tuples.hh:156
const NT & operator()(const uint n, const uint m) const
Access the matrix entry at (n,m).
Definition tuples.hh:168
NT & operator()(const uint n, const uint m)
Access the matrix entry at (n,m).
Definition tuples.hh:163
SimpleMatrix()
Definition tuples.hh:158
std::array< NT, N *M > data
Definition tuples.hh:201
void clear()
Set all entries to zero.
Definition tuples.hh:173
bool is_finite() const
Definition tuples.hh:179
void print() const
Print the matrix to the console.
Definition tuples.hh:191
Concept for a named tuple.
Definition tuples.hh:21
Definition complex_math.hh:10
constexpr auto tuple_tail(const std::tuple< Head, Tail... > &t)
Definition tuples.hh:223
auto _jacobian_tuple(std::index_sequence< IDXs... >)
Definition tuples.hh:283
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 vector_to_tuple_helper(const std::vector< T > &v, std::index_sequence< Indices... >)
Definition tuples.hh:213
auto _local_sol_tuple(const std::array< T, N > &a, std::index_sequence< IDXs... >, uint q_index)
Definition tuples.hh:274
auto vector_to_tuple(const std::vector< T > &v)
Definition tuples.hh:217
unsigned int uint
Definition utils.hh:24
consteval bool strings_equal(FixedString< N1 > s1, FixedString< N2 > s2)
Definition fixed_string.hh:49
auto jacobian_2_tuple()
Definition tuples.hh:299
constexpr auto & get(named_tuple< tuple_type, strSet > &ob)
get a reference to the element with the given name
Definition tuples.hh:111
std::array< NT, n > vector_to_array(const Vector &v)
Definition tuples.hh:204
constexpr auto tuple_last(const std::tuple< Head, Tail... > &t)
Definition tuples.hh:233
A fixed size compile-time string.
Definition fixed_string.hh:12
static constexpr size_t size
Definition tuples.hh:35
static constexpr std::array< const char *, size > names
Definition tuples.hh:36
A class to store a tuple with elements that can be accessed by name. The names are stored as FixedStr...
Definition tuples.hh:56
static constexpr size_t size
Definition tuples.hh:63
static constexpr auto as(std::tuple< T... > &tup)
Definition tuples.hh:83
named_tuple(tuple_type &&t)
Definition tuples.hh:76
static constexpr auto names
Definition tuples.hh:64
const auto & get() const
Definition tuples.hh:104
static constexpr auto as(std::tuple< T... > &&tup)
Definition tuples.hh:79
auto & get()
Definition tuples.hh:103
tuple_type tuple
Definition tuples.hh:59
static consteval size_t get_idx(const char *name)
Definition tuples.hh:88
named_tuple(tuple_type &t)
Definition tuples.hh:77