18 #ifndef FIELD_MODEL_HH_ 19 #define FIELD_MODEL_HH_ 27 #include <type_traits> 52 #define wrap_overload(func) [](auto&&... ps){ return func( std::forward<decltype(ps)>(ps)... ); } 61 template<
typename CALLABLE,
typename FIELD_TUPLE,
int INDEX >
62 struct model_cache_item
64 template<
typename... Vs >
65 static auto eval(
int i_cache, CALLABLE f, FIELD_TUPLE fields, Vs&&... args) -> decltype(
auto) {
66 const auto &single_field =
std::get < INDEX - 1 > (std::forward<decltype(fields)>(fields));
68 i_cache, f, std::forward<decltype(fields)>(fields),
69 single_field[i_cache], std::forward<Vs>(args)...);
75 template<
typename CALLABLE,
typename FIELD_TUPLE >
78 template<
typename... Vs >
79 static auto eval(
int i_cache, CALLABLE f, FIELD_TUPLE fields, Vs&&... args) -> decltype(
auto)
81 return f(std::forward<Vs>(args)...);
91 template<
typename FIELD_TUPLE,
int INDEX >
94 const auto &single_field =
std::get < INDEX - 1 > (std::forward<decltype(fields)>(fields));
95 uint n_comp_new = single_field.n_comp();
105 template<
typename FIELD_TUPLE>
130 template<
int spacedim,
class Value>
133 ASSERT(f.is_multifield());
140 template<
int spacedim,
class Value>
143 ASSERT(!f.is_multifield());
151 template<
typename FIELD_TUPLE,
int INDEX>
153 static auto eval(FIELD_TUPLE fields,
uint i_comp) -> decltype(
auto)
155 const auto &single_field =
std::get < INDEX - 1 > (std::forward<decltype(fields)>(fields));
156 return std::tuple_cat(
159 std::forward<decltype(fields)>(fields), i_comp)
164 template<
typename FIELD_TUPLE>
166 static auto eval(FIELD_TUPLE fields,
uint n_comp) -> decltype(
auto)
168 return std::forward_as_tuple<>();
175 template<
typename Function,
typename Tuple>
222 template<
int spacedim,
class Value,
typename Fn,
class ... InputFields>
234 : fn(func), input_fields(
std::forward_as_tuple((args)...) )
244 unsigned int i_cache_el_begin = update_cache_data.region_value_cache_range_[region_in_cache];
245 unsigned int i_cache_el_end = update_cache_data.region_value_cache_range_[region_in_cache+1];
246 for(
unsigned int i_cache=i_cache_el_begin; i_cache<i_cache_el_end; ++i_cache) {
247 data_cache.
data().
set(i_cache) =
250 decltype(input_fields),
252 >
::eval(i_cache, fn, input_fields);
258 ASSERT(
false).error(
"Forbidden method!\n");
259 return this->r_value_;
265 ASSERT(
false).error(
"Forbidden method!\n");
274 template<
int spacedim,
class Value>
280 template<
typename Fn,
class ... InputFields>
281 static auto create(Fn *fn, InputFields&&... inputs) -> decltype(
auto)
283 return std::make_shared<
FieldModel<spacedim,
Value, Fn, InputFields...>>(fn, std::forward<InputFields>(inputs)...);
288 template<
typename Function,
typename Tuple,
size_t ... I>
289 static auto call_create(Function f, Tuple t, std::index_sequence<I ...>)
291 return create(f, std::get<I>(t) ...);
294 template<
typename Fn,
class ... InputFields>
295 static auto create_multi(Fn *fn, InputFields&&... inputs) -> decltype(
auto)
297 typedef std::tuple<InputFields...> FieldTuple;
298 FieldTuple field_tuple = std::forward_as_tuple((inputs)...);
299 constexpr
uint n_inputs =
sizeof...(InputFields);
303 for(
uint i=0; i<n_comp; i++) {
308 FieldBasePtr component_field = call_create(fn, component_of_inputs, std::make_index_sequence<n_inputs>{});
309 result_components.push_back(component_field);
312 return result_components;
static auto eval(int i_cache, CALLABLE f, FIELD_TUPLE fields, Vs &&...args) -> decltype(auto)
auto field_component(const MultiField< spacedim, Value > &f, uint i_comp) -> decltype(auto)
static uint eval(FIELD_TUPLE fields, uint n_comp)
const UpdateCacheHelper & update_cache_data() const
Return update cache data helper.
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_idx) override
FieldModel(Fn *func, InputFields...args)
Directing class of FieldValueCache.
static auto eval(FIELD_TUPLE fields, uint n_comp) -> decltype(auto)
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...
std::shared_ptr< FieldBaseType > FieldBasePtr
static constexpr bool value
static uint eval(FIELD_TUPLE fields, uint n_comp)
const Armor::Array< elm_type > & data() const
Return data vector.
std::unordered_map< unsigned int, unsigned int > region_cache_indices_range_
Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm) override
Implementation of virtual method.
ArrayMatSet set(uint index)
Space< spacedim >::Point Point
base case for building up arguments for the function call
FieldAlgorithmBase< spacedim, Value > FieldBaseType
static auto create_multi(Fn *fn, InputFields &&...inputs) -> decltype(auto)
static auto eval(int i_cache, CALLABLE f, FIELD_TUPLE fields, Vs &&...args) -> decltype(auto)
static auto eval(FIELD_TUPLE fields, uint i_comp) -> decltype(auto)
std::tuple< InputFields... > FieldsTuple
auto call(Function f, Tuple t)
Class for representation of a vector of fields of the same physical quantity.
static auto create(Fn *fn, InputFields &&...inputs) -> decltype(auto)
void value_list(const Armor::array &point_list, const ElementAccessor< spacedim > &elm, std::vector< typename Value::return_type > &value_list) override
Implementation of virtual method.
FieldAlgorithmBase< spacedim, Value >::Point Point