Flow123d
JS_before_hm-2072-g4aad0192b
|
Go to the documentation of this file.
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>
199 template<
int spacedim,
class Value,
typename CALLABLE,
typename FIELD_TUPLE,
int INDEX >
204 template<
typename... Vs >
206 const auto &single_field =
std::get < INDEX - 1 > (std::forward<decltype(fields)>(fields));
208 p, elm, f, std::forward<decltype(fields)>(fields),
209 single_field.value(p, elm), std::forward<Vs>(args)...);
215 template<
int spacedim,
class Value,
typename CALLABLE,
typename FIELD_TUPLE >
220 template<
typename... Vs >
222 Vs&&... args) -> decltype(
auto)
224 return f(std::forward<Vs>(args)...);
229 template<
typename Function,
typename Tuple>
276 template<
int spacedim,
class Value,
typename Fn,
class ... InputFields>
304 for(
unsigned int i_cache=reg_chunk_begin; i_cache<reg_chunk_end; ++i_cache) {
305 data_cache.
set(i_cache) =
327 for (
uint i=0; i<point_list.
size(); ++i)
328 value_list[i] = this->
value(point_list.template mat<Value::NRows_, Value::NCols_>(i), elm);
337 template<
int spacedim,
class Value>
346 template<
typename Fn,
class ... InputFields>
348 static auto create(Fn fn, InputFields&&... inputs) -> decltype(
auto)
350 return std::make_shared<
FieldModel<spacedim,
Value, Fn, InputFields...>>(fn, std::forward<InputFields>(inputs)...);
355 template<
typename Function,
typename Tuple,
size_t ... I>
356 static auto call_create(Function f, Tuple t, std::index_sequence<I ...>)
358 return create(f, std::get<I>(t) ...);
364 template<
typename Fn,
class ... InputFields>
366 static auto create_multi(Fn fn, InputFields&&... inputs) -> decltype(
auto)
368 typedef std::tuple<InputFields...> FieldTuple;
369 FieldTuple field_tuple = std::forward_as_tuple((inputs)...);
370 constexpr
uint n_inputs =
sizeof...(InputFields);
374 for(
uint i=0; i<n_comp; i++) {
380 result_components.push_back(component_field);
383 return result_components;
base case for building up arguments for the function call
static auto eval(FMT_UNUSED int i_cache, CALLABLE f, FMT_UNUSED FIELD_TUPLE fields, Vs &&... args) -> decltype(auto)
auto field_component(const MultiField< spacedim, Value > &f, uint i_comp) -> decltype(auto)
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
Directing class of FieldValueCache.
auto call(Function f, Tuple t)
static constexpr bool value
#define ASSERT_EQ_DBG(a, b)
Definition of comparative assert macro (EQual) only for debug mode.
const Value::return_type & value(const Point &p, const ElementAccessor< spacedim > &elm) override
Implementation of virtual method.
std::tuple< InputFields... > FieldsTuple
Space< spacedim >::Point Point
static uint eval(FMT_UNUSED FIELD_TUPLE fields, uint n_comp)
FieldAlgorithmBase< spacedim, Value >::Point Point
static auto create_multi(Fn fn, InputFields &&... inputs) -> decltype(auto)
unsigned int region_chunk_end(unsigned int region_patch_idx) const
Return end position of region chunk in FieldValueCache.
FieldAlgorithmBase< spacedim, Value >::Point Point
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.
static auto eval(FMT_UNUSED const Point &p, FMT_UNUSED const ElementAccessor< spacedim > &elm, CALLABLE f, FMT_UNUSED FIELD_TUPLE fields, Vs &&... args) -> decltype(auto)
static auto eval(const Point &p, const ElementAccessor< spacedim > &elm, CALLABLE f, FIELD_TUPLE fields, Vs &&... args) -> decltype(auto)
Container for various descendants of FieldCommonBase.
ArrayMatSet set(uint index)
std::shared_ptr< FieldBaseType > FieldBasePtr
unsigned int size() const
void cache_update(FieldValueCache< typename Value::element_type > &data_cache, ElementCacheMap &cache_map, unsigned int region_patch_idx) override
Implements FieldAlgoBase::cache_update.
unsigned int region_chunk_begin(unsigned int region_patch_idx) const
Return begin position of region chunk in FieldValueCache.
static std::vector< const FieldCommon * > eval(FIELD_TUPLE fields)
FieldAlgorithmBase< spacedim, Value >::Point Point
Class for representation of a vector of fields of the same physical quantity.
static std::vector< const FieldCommon * > eval(FMT_UNUSED FIELD_TUPLE fields)
FieldModel(Fn func, InputFields... args)
static auto eval(FMT_UNUSED FIELD_TUPLE fields, FMT_UNUSED uint n_comp) -> decltype(auto)
static uint eval(FIELD_TUPLE fields, uint n_comp)
static auto call_create(Function f, Tuple t, std::index_sequence< I ... >)
Value::return_type r_value_
static auto create(Fn fn, InputFields &&... inputs) -> decltype(auto)
static auto eval(FIELD_TUPLE fields, uint i_comp) -> decltype(auto)
Class template representing a field with values dependent on: point, element, and region.
std::vector< const FieldCommon * > set_dependency(FMT_UNUSED FieldSet &field_set)
Implements FieldAlgoBase::set_dependency.
FieldAlgorithmBase< spacedim, Value > FieldBaseType
static auto eval(int i_cache, CALLABLE f, FIELD_TUPLE fields, Vs &&... args) -> decltype(auto)