Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
func_bundle.hh
Go to the documentation of this file.
1#ifndef UTOPIA_MODELS_ENVIRONMENT_FUNCBUNDLE_HH
2#define UTOPIA_MODELS_ENVIRONMENT_FUNCBUNDLE_HH
3
5namespace FuncBundle {
6
12
16template<typename Func, typename Time>
17struct FuncBundle {
18 std::string name;
22 std::set<Time> times;
23
24 FuncBundle(std::string name, Func func,
25 bool invoke_at_initialization = true, bool invoke_always = true,
26 std::set<Time> times = {})
27 :
28 name(name),
29 func(func),
33 {}
34};
35
37
41template<typename Func, typename Time>
42struct ParamFuncBundle : FuncBundle<Func, Time> {
44 std::string param_name;
45
46 ParamFuncBundle(std::string name, Func func, std::string param_name,
47 bool invoke_at_initialization = true, bool invoke_always = true,
48 std::set<Time> times = {})
49 :
53 {}
54
55 ParamFuncBundle(std::string name, Func func, std::string param_name,
56 std::tuple<bool, bool, std::set<Time>> invoke_times_tuple)
57 :
62 {}
63};
64
66
70template<typename RuleFunc, typename Time, typename CellContainer>
71struct RuleFuncBundle : FuncBundle<RuleFunc, Time> {
74
75 // Select a subset of cells
82
83 RuleFuncBundle(std::string name, RuleFunc func,
85 bool invoke_always = true, std::set<Time> times = {},
86 bool fix_selection = false,
87 const CellContainer& cell_selection = {},
88 const DataIO::Config& select_cfg = {})
89 :
90 FuncBundle<RuleFunc, Time>(name, func, invoke_at_initialization,
96 { }
97
98 RuleFuncBundle(std::string name, RuleFunc func, Update update,
100 std::pair<bool, std::set<Time>> times_pair,
101 std::tuple<bool, CellContainer, DataIO::Config> select_tuple)
102 :
103 RuleFuncBundle<RuleFunc, Time, CellContainer>(name, func, update,
107 std::get<DataIO::Config>(select_tuple))
108 {}
109};
110
111// End group Environment
116} // namespace FuncBundle
117} // namespace Utopia::Models::Environment
118
119#endif
YAML::Node Config
Type of a variadic dictionary-like data structure used throughout Utopia.
Definition types.hh:71
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
Update
Update modes when applying rules.
Definition state.hh:20
@ sync
Synchronous update.
DataIO::Config Config
Configuration node type alias.
Definition env_param_func_collection.hh:13
Definition env_param_func_collection.hh:8
EntityContainer< CellType > CellContainer
Type of the variably sized container for cells.
Definition types.hh:26
Definition parallel.hh:235
A bundle wrapping a (iterative) function with metadata.
Definition func_bundle.hh:17
std::set< Time > times
Whether to invoke in every timestep.
Definition func_bundle.hh:22
bool invoke_always
Whether to invoke at initialization.
Definition func_bundle.hh:21
FuncBundle(std::string name, Func func, bool invoke_at_initialization=true, bool invoke_always=true, std::set< Time > times={})
When to invoke.
Definition func_bundle.hh:24
Func func
The name of the function.
Definition func_bundle.hh:19
std::string name
Definition func_bundle.hh:18
bool invoke_at_initialization
The function.
Definition func_bundle.hh:20
A bundle wrapping a (iterative) function with metadata.
Definition func_bundle.hh:42
std::string param_name
The name of the parameter to which to apply the function.
Definition func_bundle.hh:44
ParamFuncBundle(std::string name, Func func, std::string param_name, std::tuple< bool, bool, std::set< Time > > invoke_times_tuple)
Definition func_bundle.hh:55
ParamFuncBundle(std::string name, Func func, std::string param_name, bool invoke_at_initialization=true, bool invoke_always=true, std::set< Time > times={})
Definition func_bundle.hh:46
A bundle wrapping a (rule-)function with metadata.
Definition func_bundle.hh:71
RuleFuncBundle(std::string name, RuleFunc func, Update update, bool invoke_at_initialization, std::pair< bool, std::set< Time > > times_pair, std::tuple< bool, CellContainer, DataIO::Config > select_tuple)
Definition func_bundle.hh:98
Update update
The update mode of the RuleFunc.
Definition func_bundle.hh:73
DataIO::Config select_cfg
Config node that is passed to the select_cells of the cell manager.
Definition func_bundle.hh:81
bool fix_selection
Whether the selection of cells is fixed.
Definition func_bundle.hh:77
RuleFuncBundle(std::string name, RuleFunc func, Update update=Update::sync, bool invoke_at_initialization=true, bool invoke_always=true, std::set< Time > times={}, bool fix_selection=false, const CellContainer &cell_selection={}, const DataIO::Config &select_cfg={})
Definition func_bundle.hh:83
CellContainer cell_selection
Cell container over which to apply the func, optional.
Definition func_bundle.hh:79