@@ -21,18 +21,22 @@ template <class MainModel, class... ComponentType>
21
21
class JobDispatchAdapter <MainModel, ComponentList<ComponentType...>>
22
22
: public JobDispatchInterface<JobDispatchAdapter<MainModel, ComponentList<ComponentType...>>> {
23
23
public:
24
- JobDispatchAdapter (std::reference_wrapper<MainModel> model) : model_{std::move (model)} {}
24
+ JobDispatchAdapter (std::reference_wrapper<MainModel> model_reference,
25
+ std::reference_wrapper<MainModelOptions const > options)
26
+ : model_reference_{model_reference}, options_{options} {}
25
27
JobDispatchAdapter (JobDispatchAdapter const & other)
26
- : model_copy_{std::make_unique<MainModel>(other.model_ .get ())},
27
- model_{std::ref (*model_copy_)},
28
+ : model_copy_{std::make_unique<MainModel>(other.model_reference_ .get ())},
29
+ model_reference_{std::ref (*model_copy_)},
30
+ options_{std::ref (other.options_ )},
28
31
components_to_update_{other.components_to_update_ },
29
32
update_independence_{other.update_independence_ },
30
33
independence_flags_{other.independence_flags_ },
31
34
all_scenarios_sequence_{other.all_scenarios_sequence_ } {}
32
35
JobDispatchAdapter& operator =(JobDispatchAdapter const & other) {
33
36
if (this != &other) {
34
- model_copy_ = std::make_unique<MainModel>(other.model_ .get ());
35
- model_ = std::ref (*model_copy_);
37
+ model_copy_ = std::make_unique<MainModel>(other.model_reference_ .get ());
38
+ model_reference_ = std::ref (*model_copy_);
39
+ options_ = std::ref (other.options_ );
36
40
components_to_update_ = other.components_to_update_ ;
37
41
update_independence_ = other.update_independence_ ;
38
42
independence_flags_ = other.independence_flags_ ;
@@ -42,15 +46,17 @@ class JobDispatchAdapter<MainModel, ComponentList<ComponentType...>>
42
46
}
43
47
JobDispatchAdapter (JobDispatchAdapter&& other) noexcept
44
48
: model_copy_{std::move (other.model_copy_ )},
45
- model_{model_copy_ ? std::ref (*model_copy_) : std::move (other.model_ )},
49
+ model_reference_{model_copy_ ? std::ref (*model_copy_) : std::move (other.model_reference_ )},
50
+ options_{other.options_ },
46
51
components_to_update_{std::move (other.components_to_update_ )},
47
52
update_independence_{std::move (other.update_independence_ )},
48
53
independence_flags_{std::move (other.independence_flags_ )},
49
54
all_scenarios_sequence_{std::move (other.all_scenarios_sequence_ )} {}
50
55
JobDispatchAdapter& operator =(JobDispatchAdapter&& other) noexcept {
51
56
if (this != &other) {
52
57
model_copy_ = std::move (other.model_copy_ );
53
- model_ = model_copy_ ? std::ref (*model_copy_) : std::move (other.model_ );
58
+ model_reference_ = model_copy_ ? std::ref (*model_copy_) : std::move (other.model_reference_ );
59
+ options_ = other.options_ ;
54
60
components_to_update_ = std::move (other.components_to_update_ );
55
61
update_independence_ = std::move (other.update_independence_ );
56
62
independence_flags_ = std::move (other.independence_flags_ );
@@ -66,10 +72,9 @@ class JobDispatchAdapter<MainModel, ComponentList<ComponentType...>>
66
72
// to call derived-class implementation details as part of the CRTP pattern.
67
73
friend class JobDispatchInterface <JobDispatchAdapter>;
68
74
69
- static constexpr Idx ignore_output{-1 };
70
-
71
75
std::unique_ptr<MainModel> model_copy_;
72
- std::reference_wrapper<MainModel> model_;
76
+ std::reference_wrapper<MainModel> model_reference_;
77
+ std::reference_wrapper<MainModelOptions const > options_;
73
78
74
79
main_core::utils::ComponentFlags<ComponentType...> components_to_update_{};
75
80
main_core::update::independence::UpdateIndependence<ComponentType...> update_independence_{};
@@ -80,26 +85,22 @@ class JobDispatchAdapter<MainModel, ComponentList<ComponentType...>>
80
85
81
86
std::mutex calculation_info_mutex_;
82
87
83
- // TODO(figueroa1395): Keep calculation_fn at the adapter level only
84
- template <typename Calculate>
85
- requires std::invocable<std::remove_cvref_t <Calculate>, MainModel&, MutableDataset const &, bool >
86
- void calculate_impl (Calculate&& calculation_fn, MutableDataset const & result_data, Idx scenario_idx) const {
87
- std::forward<Calculate>(calculation_fn)(model_.get (), result_data.get_individual_scenario (scenario_idx), false );
88
+ void calculate_impl (MutableDataset const & result_data, Idx scenario_idx) const {
89
+ MainModel::calculator (options_.get (), model_reference_.get (), result_data.get_individual_scenario (scenario_idx),
90
+ false );
88
91
}
89
92
90
- template <typename Calculate>
91
- requires std::invocable<std::remove_cvref_t <Calculate>, MainModel&, MutableDataset const &, Idx>
92
- void cache_calculate_impl (Calculate&& calculation_fn) const {
93
+ void cache_calculate_impl () const {
93
94
// calculate once to cache topology, ignore results, all math solvers are initialized
94
95
try {
95
- std::forward<Calculate>(calculation_fn)(model_ .get (),
96
- {
97
- false ,
98
- 1 ,
99
- " sym_output" ,
100
- model_ .get ().meta_data (),
101
- },
102
- true );
96
+ MainModel::calculator (options_. get (), model_reference_ .get (),
97
+ {
98
+ false ,
99
+ 1 ,
100
+ " sym_output" ,
101
+ model_reference_ .get ().meta_data (),
102
+ },
103
+ true );
103
104
} catch (SparseMatrixError const &) { // NOLINT(bugprone-empty-catch) // NOSONAR
104
105
// missing entries are provided in the update data
105
106
} catch (NotObservableError const &) { // NOLINT(bugprone-empty-catch) // NOSONAR
@@ -110,33 +111,35 @@ class JobDispatchAdapter<MainModel, ComponentList<ComponentType...>>
110
111
void prepare_job_dispatch_impl (ConstDataset const & update_data) {
111
112
// cache component update order where possible.
112
113
// the order for a cacheable (independent) component by definition is the same across all scenarios
113
- components_to_update_ = model_ .get ().get_components_to_update (update_data);
114
+ components_to_update_ = model_reference_ .get ().get_components_to_update (update_data);
114
115
update_independence_ = main_core::update::independence::check_update_independence<ComponentType...>(
115
- model_ .get ().state (), update_data);
116
+ model_reference_ .get ().state (), update_data);
116
117
std::ranges::transform (update_independence_, independence_flags_.begin (),
117
118
[](auto const & comp) { return comp.is_independent (); });
118
119
all_scenarios_sequence_ = std::make_shared<main_core::utils::SequenceIdx<ComponentType...>>(
119
120
main_core::update::get_all_sequence_idx_map<ComponentType...>(
120
- model_ .get ().state (), update_data, 0 , components_to_update_, update_independence_, false ));
121
+ model_reference_ .get ().state (), update_data, 0 , components_to_update_, update_independence_, false ));
121
122
}
122
123
123
124
void setup_impl (ConstDataset const & update_data, Idx scenario_idx) {
124
125
current_scenario_sequence_cache_ = main_core::update::get_all_sequence_idx_map<ComponentType...>(
125
- model_.get ().state (), update_data, scenario_idx, components_to_update_, update_independence_, true );
126
+ model_reference_.get ().state (), update_data, scenario_idx, components_to_update_, update_independence_,
127
+ true );
126
128
auto const current_scenario_sequence = get_current_scenario_sequence_view_ ();
127
- model_.get ().template update_components <cached_update_t >(update_data, scenario_idx, current_scenario_sequence);
129
+ model_reference_.get ().template update_components <cached_update_t >(update_data, scenario_idx,
130
+ current_scenario_sequence);
128
131
}
129
132
130
133
void winddown_impl () {
131
- model_ .get ().restore_components (get_current_scenario_sequence_view_ ());
134
+ model_reference_ .get ().restore_components (get_current_scenario_sequence_view_ ());
132
135
std::ranges::for_each (current_scenario_sequence_cache_, [](auto & comp_seq_idx) { comp_seq_idx.clear (); });
133
136
}
134
137
135
- CalculationInfo get_calculation_info_impl () const { return model_ .get ().calculation_info (); }
138
+ CalculationInfo get_calculation_info_impl () const { return model_reference_ .get ().calculation_info (); }
136
139
137
140
void thread_safe_add_calculation_info_impl (CalculationInfo const & info) {
138
141
std::lock_guard const lock{calculation_info_mutex_};
139
- model_ .get ().merge_calculation_info (info);
142
+ model_reference_ .get ().merge_calculation_info (info);
140
143
}
141
144
142
145
auto get_current_scenario_sequence_view_ () const {
0 commit comments