Skip to content

Commit 2a9bc41

Browse files
committed
removed redundant usings
Signed-off-by: Santiago Figueroa Manrique <santiago.figueroa.manrique@alliander.com>
1 parent f5134f9 commit 2a9bc41

File tree

2 files changed

+39
-40
lines changed

2 files changed

+39
-40
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,6 @@ get_all_sequence_idx_map(MainModelState<ComponentContainer> const& state, ConstD
246246
Idx comp_idx{};
247247
utils::run_functor_with_all_types_return_void<ComponentTypes...>(
248248
[&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.
251249
components_to_store[comp_idx] = (update_data.find_component(CompType::name, false) != invalid_index);
252250
++comp_idx;
253251
});

power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,7 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
149149
using MainModelState = main_core::MainModelState<ComponentContainer>;
150150
using MathState = main_core::MathState;
151151

152-
// main core utils
153-
static constexpr auto n_types = main_core::utils::n_types<ComponentType...>;
154-
template <class CompType>
155-
static constexpr auto index_of_component = main_core::utils::index_of_component<CompType, ComponentType...>;
156-
using SequenceIdx = main_core::utils::SequenceIdx<ComponentType...>;
157-
using ComponentFlags = main_core::utils::ComponentFlags<ComponentType...>;
158-
159-
using SequenceIdxView = std::array<std::span<Idx2D const>, n_types>;
160-
152+
using SequenceIdxView = std::array<std::span<Idx2D const>, main_core::utils::n_types<ComponentType...>>;
161153
using OwnedUpdateDataset = std::tuple<std::vector<typename ComponentType::UpdateType>...>;
162154

163155
static constexpr Idx ignore_output{-1};
@@ -187,8 +179,8 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
187179
}
188180

189181
// helper function to get the number of components per type
190-
std::array<Idx, n_types> get_n_components_per_type() const {
191-
std::array<Idx, n_types> result{};
182+
std::array<Idx, main_core::utils::n_types<ComponentType...>> get_n_components_per_type() const {
183+
std::array<Idx, main_core::utils::n_types<ComponentType...>> result{};
192184
size_t idx{};
193185
main_core::utils::run_functor_with_all_types_return_void<ComponentType...>(
194186
[&result, this, &idx]<typename CompType>() {
@@ -237,7 +229,7 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
237229
template <class CompType, cache_type_c CacheType,
238230
forward_iterator_like<typename CompType::UpdateType> ForwardIterator>
239231
void update_component(ForwardIterator begin, ForwardIterator end, std::span<Idx2D const> sequence_idx) {
240-
constexpr auto comp_index = index_of_component<CompType>;
232+
constexpr auto comp_index = main_core::utils::index_of_component<CompType, ComponentType...>;
241233

242234
assert(construction_complete_);
243235
assert(static_cast<ptrdiff_t>(sequence_idx.size()) == std::distance(begin, end));
@@ -297,12 +289,14 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
297289

298290
// overload to update all components across all scenarios
299291
template <cache_type_c CacheType, typename SequenceIdxMap>
300-
requires(std::same_as<SequenceIdxMap, SequenceIdx> || std::same_as<SequenceIdxMap, SequenceIdxView>)
292+
requires(std::same_as<SequenceIdxMap, main_core::utils::SequenceIdx<ComponentType...>> ||
293+
std::same_as<SequenceIdxMap, SequenceIdxView>)
301294
void update_components(ConstDataset const& update_data, Idx pos, SequenceIdxMap const& sequence_idx_map) {
302295
main_core::utils::run_functor_with_all_types_return_void<ComponentType...>(
303296
[this, pos, &update_data, &sequence_idx_map]<typename CT>() {
304-
this->update_component_row_col<CT, CacheType>(update_data, pos,
305-
std::get<index_of_component<CT>>(sequence_idx_map));
297+
this->update_component_row_col<CT, CacheType>(
298+
update_data, pos,
299+
std::get<main_core::utils::index_of_component<CT, ComponentType...>>(sequence_idx_map));
306300
});
307301
}
308302
// overload to update all components in the first scenario (e.g. permanent update)
@@ -313,7 +307,7 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
313307
}
314308

315309
template <typename CompType> void restore_component(SequenceIdxView const& sequence_idx) {
316-
constexpr auto component_index = index_of_component<CompType>;
310+
constexpr auto component_index = main_core::utils::index_of_component<CompType, ComponentType...>;
317311

318312
auto& cached_inverse_update = std::get<component_index>(cached_inverse_update_);
319313
auto const& component_sequence = std::get<component_index>(sequence_idx);
@@ -331,13 +325,14 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
331325
update_state(cached_state_changes_);
332326
cached_state_changes_ = {};
333327
}
334-
void restore_components(std::array<std::reference_wrapper<std::vector<Idx2D> const>, n_types> const& sequence_idx) {
335-
restore_components(
336-
std::array{std::span<Idx2D const>{std::get<index_of_component<ComponentType>>(sequence_idx).get()}...});
328+
void restore_components(std::array<std::reference_wrapper<std::vector<Idx2D> const>,
329+
main_core::utils::n_types<ComponentType...>> const& sequence_idx) {
330+
restore_components(std::array{std::span<Idx2D const>{
331+
std::get<main_core::utils::index_of_component<ComponentType, ComponentType...>>(sequence_idx).get()}...});
337332
}
338-
void restore_components(SequenceIdx const& sequence_idx) {
339-
restore_components(
340-
std::array{std::span<Idx2D const>{std::get<index_of_component<ComponentType>>(sequence_idx)}...});
333+
void restore_components(main_core::utils::SequenceIdx<ComponentType...> const& sequence_idx) {
334+
restore_components(std::array{std::span<Idx2D const>{
335+
std::get<main_core::utils::index_of_component<ComponentType, ComponentType...>>(sequence_idx)}...});
341336
}
342337

343338
// set complete construction
@@ -393,7 +388,8 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
393388
}
394389

395390
// Entry point for main_model.hpp
396-
template <class... ComponentTypes> SequenceIdx get_all_sequence_idx_map(ConstDataset const& update_data) {
391+
template <class... ComponentTypes>
392+
main_core::utils::SequenceIdx<ComponentType...> get_all_sequence_idx_map(ConstDataset const& update_data) {
397393
return main_core::update::get_all_sequence_idx_map<ComponentType...>(state_, update_data);
398394
}
399395

@@ -534,7 +530,7 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
534530
std::vector<CalculationInfo> infos(n_scenarios);
535531

536532
// lambda for sub batch calculation
537-
SequenceIdx all_scenarios_sequence;
533+
main_core::utils::SequenceIdx<ComponentType...> all_scenarios_sequence;
538534
auto sub_batch =
539535
sub_batch_calculation_(calculation_fn, result_data, update_data, all_scenarios_sequence, exceptions, infos);
540536

@@ -549,7 +545,8 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
549545
template <typename Calculate>
550546
requires std::invocable<std::remove_cvref_t<Calculate>, MainModelImpl&, MutableDataset const&, Idx>
551547
auto sub_batch_calculation_(Calculate&& calculation_fn, MutableDataset const& result_data,
552-
ConstDataset const& update_data, SequenceIdx& all_scenarios_sequence,
548+
ConstDataset const& update_data,
549+
main_core::utils::SequenceIdx<ComponentType...>& all_scenarios_sequence,
553550
std::vector<std::string>& exceptions, std::vector<CalculationInfo>& infos) {
554551
// const ref of current instance
555552
MainModelImpl const& base_model = *this;
@@ -576,7 +573,7 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
576573
};
577574
auto model = copy_model_functor(start);
578575

579-
SequenceIdx current_scenario_sequence_cache = SequenceIdx{};
576+
auto current_scenario_sequence_cache = main_core::utils::SequenceIdx<ComponentType...>{};
580577
auto [setup, winddown] = scenario_update_restore(model, update_data, is_independent, all_scenarios_sequence,
581578
current_scenario_sequence_cache, infos);
582579

@@ -650,13 +647,14 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
650647
};
651648
}
652649

653-
static auto scenario_update_restore(MainModelImpl& model, ConstDataset const& update_data,
654-
ComponentFlags const& independence_flags,
655-
SequenceIdx const& all_scenario_sequence,
656-
SequenceIdx& current_scenario_sequence_cache,
657-
std::vector<CalculationInfo>& infos) noexcept {
650+
static auto
651+
scenario_update_restore(MainModelImpl& model, ConstDataset const& update_data,
652+
main_core::utils::ComponentFlags<ComponentType...> const& independence_flags,
653+
main_core::utils::SequenceIdx<ComponentType...> const& all_scenario_sequence,
654+
main_core::utils::SequenceIdx<ComponentType...>& current_scenario_sequence_cache,
655+
std::vector<CalculationInfo>& infos) noexcept {
658656
auto do_update_cache = [&independence_flags] {
659-
ComponentFlags result;
657+
main_core::utils::ComponentFlags<ComponentType...> result;
660658
std::ranges::transform(independence_flags, result.begin(), std::logical_not<>{});
661659
return result;
662660
}();
@@ -665,7 +663,7 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
665663
&independence_flags]() -> SequenceIdxView {
666664
return main_core::utils::run_functor_with_all_types_return_array<ComponentType...>(
667665
[&all_scenario_sequence, &current_scenario_sequence_cache, &independence_flags]<typename CT>() {
668-
constexpr auto comp_idx = index_of_component<CT>;
666+
constexpr auto comp_idx = main_core::utils::index_of_component<CT, ComponentType...>;
669667
if (std::get<comp_idx>(independence_flags)) {
670668
return std::span<Idx2D const>{std::get<comp_idx>(all_scenario_sequence)};
671669
}
@@ -845,7 +843,7 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
845843

846844
OwnedUpdateDataset cached_inverse_update_{};
847845
UpdateChange cached_state_changes_{};
848-
std::array<std::vector<Idx2D>, n_types> parameter_changed_components_{};
846+
std::array<std::vector<Idx2D>, main_core::utils::n_types<ComponentType...>> parameter_changed_components_{};
849847
#ifndef NDEBUG
850848
// construction_complete is used for debug assertions only
851849
bool construction_complete_{false};
@@ -970,7 +968,7 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
970968
template <symmetry_tag sym> std::vector<MathModelParamIncrement> get_math_param_increment() {
971969
using AddToIncrement = void (*)(std::vector<MathModelParamIncrement>&, MainModelState const&, Idx2D const&);
972970

973-
static constexpr std::array<AddToIncrement, n_types> add_to_increments{
971+
static constexpr std::array<AddToIncrement, main_core::utils::n_types<ComponentType...>> add_to_increments{
974972
[](std::vector<MathModelParamIncrement>& increments, MainModelState const& state,
975973
Idx2D const& changed_component_idx) {
976974
if constexpr (std::derived_from<ComponentType, Branch>) {
@@ -1009,7 +1007,7 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
10091007

10101008
std::vector<MathModelParamIncrement> math_param_increment(n_math_solvers_);
10111009

1012-
for (size_t i = 0; i < n_types; ++i) {
1010+
for (size_t i = 0; i < main_core::utils::n_types<ComponentType...>; ++i) {
10131011
auto const& changed_type_components = parameter_changed_components_[i];
10141012
auto const& add_type_to_increment = add_to_increments[i];
10151013
for (auto const& changed_component : changed_type_components) {
@@ -1267,8 +1265,11 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
12671265

12681266
// Check the branch and shunt indices
12691267
constexpr auto branch_param_in_seq_map =
1270-
std::array{index_of_component<Line>, index_of_component<Link>, index_of_component<Transformer>};
1271-
constexpr auto shunt_param_in_seq_map = std::array{index_of_component<Shunt>};
1268+
std::array{main_core::utils::index_of_component<Line, ComponentType...>,
1269+
main_core::utils::index_of_component<Link, ComponentType...>,
1270+
main_core::utils::index_of_component<Transformer, ComponentType...>};
1271+
constexpr auto shunt_param_in_seq_map =
1272+
std::array{main_core::utils::index_of_component<Shunt, ComponentType...>};
12721273

12731274
for (Idx i = 0; i != n_math_solvers_; ++i) {
12741275
// construct from existing Y_bus structure if possible

0 commit comments

Comments
 (0)