Skip to content

Commit 979b9f8

Browse files
committed
address comments
Signed-off-by: Santiago Figueroa Manrique <santiago.figueroa.manrique@alliander.com>
1 parent acf5c96 commit 979b9f8

File tree

2 files changed

+36
-37
lines changed

2 files changed

+36
-37
lines changed

power_grid_model_c/power_grid_model/include/power_grid_model/main_core/update.hpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ namespace power_grid_model::main_core::update {
1717

1818
constexpr Idx invalid_index{-1};
1919

20-
// main core utils
21-
template <class CompType, class... ComponentTypes>
22-
constexpr auto index_of_component = main_core::utils::index_of_component<CompType, ComponentTypes...>;
23-
template <class... ComponentTypes> using SequenceIdx = main_core::utils::SequenceIdx<ComponentTypes...>;
24-
template <class... ComponentTypes> using ComponentFlags = main_core::utils::ComponentFlags<ComponentTypes...>;
25-
2620
namespace detail {
2721
template <component_c Component, forward_iterator_like<typename Component::UpdateType> ForwardIterator, typename Func>
2822
requires std::invocable<std::remove_cvref_t<Func>, typename Component::UpdateType, Idx2D const&>
@@ -98,7 +92,7 @@ template <typename CompType> void process_buffer_span(auto const& all_spans, Upd
9892
}
9993
// Remember the begin iterator of the first scenario, then loop over the remaining scenarios and
10094
// check the ids
101-
auto const first_span = all_spans[0];
95+
auto const first_span = all_spans.front();
10296
// check the subsequent scenarios
10397
// only return true if ids of all scenarios match the ids of the first batch
10498

@@ -157,9 +151,9 @@ inline void validate_update_data_independence(UpdateCompProperties const& comp)
157151
}
158152

159153
template <class... ComponentTypes>
160-
ComponentFlags<ComponentTypes...> is_update_independent(ConstDataset const& update_data,
161-
std::span<Idx const> relevant_component_count) {
162-
ComponentFlags<ComponentTypes...> result{};
154+
main_core::utils::ComponentFlags<ComponentTypes...>
155+
is_update_independent(ConstDataset const& update_data, std::span<Idx const> relevant_component_count) {
156+
main_core::utils::ComponentFlags<ComponentTypes...> result{};
163157
size_t comp_idx{};
164158
utils::run_functor_with_all_types_return_void<ComponentTypes...>(
165159
[&result, &relevant_component_count, &update_data, &comp_idx]<typename CompType>() {
@@ -227,12 +221,13 @@ std::vector<Idx2D> get_component_sequence(MainModelState<ComponentContainer> con
227221
} // namespace detail
228222

229223
template <class... ComponentTypes, class ComponentContainer>
230-
SequenceIdx<ComponentTypes...> get_all_sequence_idx_map(MainModelState<ComponentContainer> const& state,
231-
ConstDataset const& update_data, Idx scenario_idx,
232-
ComponentFlags<ComponentTypes...> const& components_to_store) {
224+
main_core::utils::SequenceIdx<ComponentTypes...>
225+
get_all_sequence_idx_map(MainModelState<ComponentContainer> const& state, ConstDataset const& update_data,
226+
Idx scenario_idx,
227+
main_core::utils::ComponentFlags<ComponentTypes...> const& components_to_store) {
233228
return utils::run_functor_with_all_types_return_array<ComponentTypes...>(
234229
[&update_data, &components_to_store, &state, scenario_idx]<typename CompType>() {
235-
if (!std::get<index_of_component<CompType, ComponentTypes...>>(components_to_store)) {
230+
if (!std::get<main_core::utils::index_of_component<CompType, ComponentTypes...>>(components_to_store)) {
236231
return std::vector<Idx2D>{};
237232
}
238233
auto const n_components = state.components.template size<CompType>();
@@ -245,12 +240,14 @@ SequenceIdx<ComponentTypes...> get_all_sequence_idx_map(MainModelState<Component
245240
// The sequence idx map of the batch is the same as that of the first scenario in the batch (assuming homogeneity)
246241
// This is the entry point for permanent updates.
247242
template <class... ComponentTypes, class ComponentContainer>
248-
SequenceIdx<ComponentTypes...> get_all_sequence_idx_map(MainModelState<ComponentContainer> const& state,
249-
ConstDataset const& update_data) {
250-
ComponentFlags<ComponentTypes...> components_to_store{};
243+
main_core::utils::SequenceIdx<ComponentTypes...>
244+
get_all_sequence_idx_map(MainModelState<ComponentContainer> const& state, ConstDataset const& update_data) {
245+
main_core::utils::ComponentFlags<ComponentTypes...> components_to_store{};
251246
Idx comp_idx{};
252247
utils::run_functor_with_all_types_return_void<ComponentTypes...>(
253248
[&update_data, &components_to_store, &comp_idx]<typename CompType>() {
249+
// In a permanent update, all components that are present are independent (because only one scenario is
250+
// considered) hence all present components are labeled are marked true (independent), the rest are false.
254251
components_to_store[comp_idx] = (update_data.find_component(CompType::name, false) != invalid_index);
255252
++comp_idx;
256253
});

power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@
4545

4646
namespace power_grid_model {
4747

48+
namespace detail {
49+
template <calculation_input_type CalcInputType>
50+
static auto calculate_param(auto const& c, auto const&... extra_args)
51+
requires requires {
52+
{ c.calc_param(extra_args...) };
53+
}
54+
{
55+
return c.calc_param(extra_args...);
56+
}
57+
58+
template <calculation_input_type CalcInputType>
59+
static auto calculate_param(auto const& c, auto const&... extra_args)
60+
requires requires {
61+
{ c.template calc_param<typename CalcInputType::sym>(extra_args...) };
62+
}
63+
{
64+
return c.template calc_param<typename CalcInputType::sym>(extra_args...);
65+
}
66+
} // namespace detail
67+
4868
// solver output type to output type getter meta function
4969

5070
template <solver_output_type SolverOutputType> struct output_type_getter;
@@ -1065,7 +1085,7 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
10651085
auto const& component = get_component_by_sequence<ComponentIn>(state, i);
10661086
CalcStructOut& math_model_input = calc_input[math_idx.group];
10671087
std::vector<CalcParamOut>& math_model_input_vect = math_model_input.*comp_vect;
1068-
math_model_input_vect[math_idx.pos] = calculate_param<CalcStructOut>(component);
1088+
math_model_input_vect[math_idx.pos] = detail::calculate_param<CalcStructOut>(component);
10691089
}
10701090
}
10711091
}
@@ -1086,7 +1106,7 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
10861106
CalcStructOut& math_model_input = calc_input[math_idx.group];
10871107
std::vector<CalcParamOut>& math_model_input_vect = math_model_input.*comp_vect;
10881108
math_model_input_vect[math_idx.pos] =
1089-
calculate_param<CalcStructOut>(component, extra_args(component));
1109+
detail::calculate_param<CalcStructOut>(component, extra_args(component));
10901110
}
10911111
}
10921112
}
@@ -1306,22 +1326,4 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
13061326
}
13071327
};
13081328

1309-
template <calculation_input_type CalcInputType>
1310-
static auto calculate_param(auto const& c, auto const&... extra_args)
1311-
requires requires {
1312-
{ c.calc_param(extra_args...) };
1313-
}
1314-
{
1315-
return c.calc_param(extra_args...);
1316-
}
1317-
1318-
template <calculation_input_type CalcInputType>
1319-
static auto calculate_param(auto const& c, auto const&... extra_args)
1320-
requires requires {
1321-
{ c.template calc_param<typename CalcInputType::sym>(extra_args...) };
1322-
}
1323-
{
1324-
return c.template calc_param<typename CalcInputType::sym>(extra_args...);
1325-
}
1326-
13271329
} // namespace power_grid_model

0 commit comments

Comments
 (0)