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();
106 template<
typename FIELD_TUPLE>
131 template<
int spacedim,
class Value>
134 ASSERT(f.is_multifield());
141 template<
int spacedim,
class Value>
144 ASSERT(!f.is_multifield());
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>
200 template<
typename Function,
typename Tuple>
247 template<
int spacedim,
class Value,
typename Fn,
class ... InputFields>
259 : fn(func), input_fields(
std::forward_as_tuple((args)...) )
265 decltype(input_fields),
275 for(
unsigned int i_cache=reg_chunk_begin; i_cache<reg_chunk_end; ++i_cache) {
276 data_cache.
set(i_cache) =
279 decltype(input_fields),
281 >
::eval(i_cache, fn, input_fields);
287 ASSERT(
false).error(
"Forbidden method!\n");
288 return this->r_value_;
294 ASSERT(
false).error(
"Forbidden method!\n");
303 template<
int spacedim,
class Value>
312 template<
typename Fn,
class ... InputFields>
314 static auto create(Fn fn, InputFields&&... inputs) -> decltype(
auto)
316 return std::make_shared<
FieldModel<spacedim,
Value, Fn, InputFields...>>(fn, std::forward<InputFields>(inputs)...);
321 template<
typename Function,
typename Tuple,
size_t ... I>
322 static auto call_create(Function f, Tuple t, std::index_sequence<I ...>)
324 return create(f, std::get<I>(t) ...);
330 template<
typename Fn,
class ... InputFields>
332 static auto create_multi(Fn fn, InputFields&&... inputs) -> decltype(
auto)
334 typedef std::tuple<InputFields...> FieldTuple;
335 FieldTuple field_tuple = std::forward_as_tuple((inputs)...);
336 constexpr
uint n_inputs =
sizeof...(InputFields);
340 for(
uint i=0; i<n_comp; i++) {
345 FieldBasePtr component_field = call_create(fn, component_of_inputs, std::make_index_sequence<n_inputs>{});
346 result_components.push_back(component_field);
349 return result_components;
static auto eval(FMT_UNUSED int i_cache, CALLABLE f, FMT_UNUSED FIELD_TUPLE fields, Vs &&...args) -> decltype(auto)
static auto eval(int i_cache, CALLABLE f, FIELD_TUPLE fields, Vs &&...args) -> decltype(auto)
unsigned int region_chunk_begin(unsigned int region_patch_idx) const
Return begin position of region chunk in FieldValueCache.
Container for various descendants of FieldCommonBase.
static auto create_multi(Fn fn, InputFields &&...inputs) -> decltype(auto)
auto field_component(const MultiField< spacedim, Value > &f, uint i_comp) -> decltype(auto)
static uint eval(FIELD_TUPLE fields, uint n_comp)
Class template representing a field with values dependent on: point, element, and region...
void cache_update(FieldValueCache< typename Value::element_type > &data_cache, ElementCacheMap &cache_map, unsigned int region_patch_idx) override
Implements FieldAlgoBase::cache_update.
Directing class of FieldValueCache.
static auto call_create(Function f, Tuple t, std::index_sequence< I... >)
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
void value_list(FMT_UNUSED const Armor::array &point_list, FMT_UNUSED const ElementAccessor< spacedim > &elm, FMT_UNUSED std::vector< typename Value::return_type > &value_list) override
Implementation of virtual method.
static uint eval(FMT_UNUSED FIELD_TUPLE fields, uint n_comp)
static auto create(Fn fn, InputFields &&...inputs) -> decltype(auto)
std::shared_ptr< FieldBaseType > FieldBasePtr
static constexpr bool value
std::vector< const FieldCommon * > set_dependency(FMT_UNUSED FieldSet &field_set)
Implements FieldAlgoBase::set_dependency.
static std::vector< const FieldCommon * > eval(FMT_UNUSED FIELD_TUPLE fields)
Value::return_type const & value(FMT_UNUSED const Point &p, FMT_UNUSED const ElementAccessor< spacedim > &elm) override
Implementation of virtual method.
FieldModel(Fn func, InputFields...args)
unsigned int region_chunk_end(unsigned int region_patch_idx) const
Return end position of region chunk in FieldValueCache.
ArrayMatSet set(uint index)
Space< spacedim >::Point Point
base case for building up arguments for the function call
static auto eval(FMT_UNUSED FIELD_TUPLE fields, FMT_UNUSED uint n_comp) -> decltype(auto)
FieldAlgorithmBase< spacedim, Value > FieldBaseType
static auto eval(FIELD_TUPLE fields, uint i_comp) -> decltype(auto)
std::tuple< InputFields... > FieldsTuple
static std::vector< const FieldCommon * > eval(FIELD_TUPLE fields)
auto call(Function f, Tuple t)
Class for representation of a vector of fields of the same physical quantity.
FieldAlgorithmBase< spacedim, Value >::Point Point