Skip to content

Commit 4022bac

Browse files
committed
addess comments
Signed-off-by: Santiago Figueroa Manrique <santiago.figueroa.manrique@alliander.com>
1 parent 8cabc92 commit 4022bac

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
#pragma once
66

7+
#include "core_utils.hpp"
78
#include "state.hpp"
8-
#include "utils.hpp"
99

1010
#include "../all_components.hpp"
1111
#include "../common/iterator_like_concepts.hpp"
@@ -100,7 +100,8 @@ template <typename CompType> void process_buffer_span(auto const& all_spans, Upd
100100
// check the ids
101101
auto const first_span = all_spans[0];
102102
// check the subsequent scenarios
103-
// only return true if all scenarios match the ids of the first batch
103+
// only return true if ids of all scenarios match the ids of the first batch
104+
104105
properties.update_ids_match =
105106
std::ranges::all_of(all_spans.cbegin() + 1, all_spans.cend(), [&first_span](auto const& current_span) {
106107
return std::ranges::equal(current_span, first_span,
@@ -198,9 +199,9 @@ inline void get_component_sequence_impl(MainModelState<ComponentContainer> const
198199
template <component_c Component, class ComponentContainer,
199200
forward_iterator_like<typename Component::UpdateType> ForwardIterator>
200201
requires model_component_state_c<MainModelState, ComponentContainer, Component>
201-
inline std::vector<Idx2D> get_component_sequence_by_it(MainModelState<ComponentContainer> const& state,
202-
ForwardIterator begin, ForwardIterator end,
203-
Idx n_comp_elements = na_Idx) {
202+
inline std::vector<Idx2D> get_component_sequence_by_iter(MainModelState<ComponentContainer> const& state,
203+
ForwardIterator begin, ForwardIterator end,
204+
Idx n_comp_elements = na_Idx) {
204205
std::vector<Idx2D> result;
205206
result.reserve(std::distance(begin, end));
206207
get_component_sequence_impl<Component>(state, begin, end, std::back_inserter(result), n_comp_elements);
@@ -213,7 +214,7 @@ std::vector<Idx2D> get_component_sequence(MainModelState<ComponentContainer> con
213214
ConstDataset const& update_data, Idx scenario_idx,
214215
independence::UpdateCompProperties const& comp_independence = {}) {
215216
auto const get_sequence = [&state, n_comp_elements = comp_independence.get_n_elements()](auto const& span) {
216-
return get_component_sequence_by_it<CompType>(state, std::begin(span), std::end(span), n_comp_elements);
217+
return get_component_sequence_by_iter<CompType>(state, std::begin(span), std::end(span), n_comp_elements);
217218
};
218219
if (update_data.is_columnar(CompType::name)) {
219220
auto const buffer_span =
@@ -246,6 +247,8 @@ SequenceIdx<ComponentTypes...> get_all_sequence_idx_map(MainModelState<Component
246247
template <class... ComponentTypes, class ComponentContainer>
247248
SequenceIdx<ComponentTypes...> get_all_sequence_idx_map(MainModelState<ComponentContainer> const& state,
248249
ConstDataset const& update_data) {
250+
// Independence for all components is set to true as permanent updates involve only one scenario.
251+
// Flags for all components (not only the ones present in update_data) are set to avoid more expensive checks.
249252
constexpr ComponentFlags<ComponentTypes...> all_true = [] {
250253
ComponentFlags<ComponentTypes...> result{};
251254
std::ranges::fill(result, true);
@@ -291,7 +294,7 @@ template <component_c Component, class ComponentContainer,
291294
inline UpdateChange update_component(MainModelState<ComponentContainer>& state, ForwardIterator begin,
292295
ForwardIterator end, OutputIterator changed_it) {
293296
return update_component<Component>(state, begin, end, changed_it,
294-
detail::get_component_sequence_by_it<Component>(state, begin, end));
297+
detail::get_component_sequence_by_iter<Component>(state, begin, end));
295298
}
296299

297300
// template to get the inverse update for components
@@ -320,7 +323,7 @@ template <component_c Component, class ComponentContainer,
320323
inline void update_inverse(MainModelState<ComponentContainer> const& state, ForwardIterator begin, ForwardIterator end,
321324
OutputIterator destination) {
322325
return update_inverse<Component>(state, begin, end, destination,
323-
detail::get_component_sequence_by_it<Component>(state, begin, end));
326+
detail::get_component_sequence_by_iter<Component>(state, begin, end));
324327
}
325328

326329
} // namespace power_grid_model::main_core::update

power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131

3232
// main model implementation
3333
#include "main_core/calculation_info.hpp"
34+
#include "main_core/core_utils.hpp"
3435
#include "main_core/input.hpp"
3536
#include "main_core/math_state.hpp"
3637
#include "main_core/output.hpp"
3738
#include "main_core/topology.hpp"
3839
#include "main_core/update.hpp"
39-
#include "main_core/utils.hpp"
4040

4141
// stl library
4242
#include <memory>
@@ -139,7 +139,6 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
139139
using SequenceIdxView = std::array<std::span<Idx2D const>, n_types>;
140140

141141
using OwnedUpdateDataset = std::tuple<std::vector<typename ComponentType::UpdateType>...>;
142-
using ComponentCountInBase = std::pair<std::string, Idx>;
143142

144143
static constexpr Idx ignore_output{-1};
145144
static constexpr Idx isolated_component{-1};
@@ -167,9 +166,10 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
167166
return state_.components.template size<CompType>();
168167
}
169168

169+
// TODO: possibly remove, as well as from main_model.hpp
170170
// all component count
171171
std::map<std::string, Idx, std::less<>> all_component_count() const {
172-
auto const get_comp_count = [this]<typename CT>() -> ComponentCountInBase {
172+
auto const get_comp_count = [this]<typename CT>() {
173173
return make_pair(std::string{CT::name}, this->component_count<CT>());
174174
};
175175
auto const all_count =
@@ -255,7 +255,7 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
255255
}
256256
}
257257

258-
// update all components of a single type across all scenarios
258+
// ovearloads to update all components of a single type across all scenarios
259259
template <class CompType, cache_type_c CacheType>
260260
void update_component(std::vector<typename CompType::UpdateType> const& components,
261261
std::span<Idx2D const> sequence_idx) {
@@ -278,7 +278,7 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
278278
}
279279
}
280280

281-
// helper for row or columnar-based components
281+
// entry point overload to update one row or column based component type
282282
template <class CompType, cache_type_c CacheType>
283283
void update_component_row_col(ConstDataset const& update_data, Idx pos, std::span<Idx2D const> sequence_idx) {
284284
assert(construction_complete_);
@@ -293,7 +293,7 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
293293
}
294294
}
295295

296-
// update all components across all scenarios
296+
// overload to update all components across all scenarios
297297
template <cache_type_c CacheType, typename SequenceIdxMap>
298298
requires(std::same_as<SequenceIdxMap, SequenceIdx> || std::same_as<SequenceIdxMap, SequenceIdxView>)
299299
void update_components(ConstDataset const& update_data, Idx pos, SequenceIdxMap const& sequence_idx_map) {
@@ -303,7 +303,7 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
303303
std::get<index_of_component<CT>>(sequence_idx_map));
304304
});
305305
}
306-
// update all components in the first scenario (e.g. permanent update)
306+
// overload to update all components in the first scenario (e.g. permanent update)
307307
template <cache_type_c CacheType> void update_components(ConstDataset const& update_data) {
308308
auto const sequence_idx_map =
309309
main_core::update::get_all_sequence_idx_map<ComponentType...>(state_, update_data);

0 commit comments

Comments
 (0)