18 #ifndef FIELD_MODEL_HH_
19 #define FIELD_MODEL_HH_
27 #include <type_traits>
53 #define wrap_overload(func) [](auto&&... ps){ return func( std::forward<decltype(ps)>(ps)... ); }
62 template<
typename CALLABLE,
typename FIELD_TUPLE,
int INDEX >
63 struct model_cache_item
65 template<
typename... Vs >
66 static auto eval(
int i_cache, CALLABLE f, FIELD_TUPLE fields, Vs&&... args) -> decltype(
auto) {
67 const auto &single_field =
std::get < INDEX - 1 > (std::forward<decltype(fields)>(fields));
69 i_cache, f, std::forward<decltype(fields)>(fields),
70 single_field[i_cache], std::forward<Vs>(args)...);
76 template<
typename CALLABLE,
typename FIELD_TUPLE >
79 template<
typename... Vs >
82 return f(std::forward<Vs>(args)...);
92 template<
typename FIELD_TUPLE,
int INDEX >
95 const auto &single_field =
std::get < INDEX - 1 > (std::forward<decltype(fields)>(fields));
96 uint n_comp_new = single_field.n_comp();
100 ASSERT(n_comp == n_comp_new);
106 template<
typename FIELD_TUPLE>
131 template<
int spacedim,
class Value>
141 template<
int spacedim,
class Value>
152 template<
typename FIELD_TUPLE,
int INDEX>
154 static auto eval(FIELD_TUPLE fields,
uint i_comp) -> decltype(
auto)
156 const auto &single_field =
std::get < INDEX - 1 > (std::forward<decltype(fields)>(fields));
157 return std::tuple_cat(
159 std::forward<decltype(fields)>(fields), i_comp),
165 template<
typename FIELD_TUPLE>
169 return std::forward_as_tuple<>();
179 template<
typename FIELD_TUPLE,
int INDEX >
182 const auto &single_field =
std::get < INDEX - 1 > (std::forward<decltype(fields)>(fields));
184 vec.push_back(&single_field);
189 template<
typename FIELD_TUPLE>
199 template<
typename Function,
typename Tuple>
246 template<
int spacedim,
class Value,
typename Fn,
class ... InputFields>
274 for(
unsigned int i_cache=reg_chunk_begin; i_cache<reg_chunk_end; ++i_cache) {
275 data_cache.
set(i_cache) =
290 template<
int spacedim,
class Value>
299 template<
typename Fn,
class ... InputFields>
301 static auto create(Fn fn, InputFields&&... inputs) -> decltype(
auto)
303 return std::make_shared<
FieldModel<spacedim,
Value, Fn, InputFields...>>(fn, std::forward<InputFields>(inputs)...);
308 template<
typename Function,
typename Tuple,
size_t ... I>
309 static auto call_create(Function f, Tuple t, std::index_sequence<I ...>)
311 return create(f, std::get<I>(t) ...);
317 template<
typename Fn,
class ... InputFields>
319 static auto create_multi(Fn fn, InputFields&&... inputs) -> decltype(
auto)
321 typedef std::tuple<InputFields...> FieldTuple;
322 FieldTuple field_tuple = std::forward_as_tuple((inputs)...);
323 constexpr
uint n_inputs =
sizeof...(InputFields);
327 for(
uint i=0; i<n_comp; i++) {
333 result_components.push_back(component_field);
336 return result_components;