Skip to content

Commit 68ebe00

Browse files
committed
move concepts to container_fwd
Signed-off-by: Nitish Bharambe <[email protected]>
1 parent 3d29f46 commit 68ebe00

File tree

7 files changed

+50
-36
lines changed

7 files changed

+50
-36
lines changed

power_grid_model_c/power_grid_model/include/power_grid_model/container.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "common/common.hpp"
1010
#include "common/exception.hpp"
1111
#include "common/iterator_facade.hpp"
12+
#include "container_fwd.hpp"
1213

1314
#include <boost/range.hpp>
1415

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
2+
//
3+
// SPDX-License-Identifier: MPL-2.0
4+
5+
#pragma once
6+
7+
#include "common/common.hpp"
8+
9+
#include <concepts>
10+
11+
namespace power_grid_model {
12+
13+
template <typename ContainerType, typename ComponentType>
14+
concept component_container_c = requires(ContainerType const& c, ID id) {
15+
{ c.template citer<ComponentType>().begin() } -> std::forward_iterator;
16+
{ c.template citer<ComponentType>().end() } -> std::forward_iterator;
17+
{ *(c.template citer<ComponentType>().begin()) } -> std::same_as<ComponentType const&>;
18+
{ *(c.template citer<ComponentType>().end()) } -> std::same_as<ComponentType const&>;
19+
{ c.template get_item<ComponentType>(id) } -> std::convertible_to<ComponentType const&>;
20+
};
21+
22+
template <typename ContainerType, typename ComponentType>
23+
concept extended_component_container_c =
24+
component_container_c<ContainerType, ComponentType> && requires(ContainerType const& c, Idx2D const& idx2d) {
25+
{ c.template size<ComponentType>() } -> std::same_as<Idx>;
26+
{ c.template get_seq<ComponentType>(idx2d) } -> std::same_as<Idx>;
27+
};
28+
29+
template <typename ContainerType, typename... ComponentType>
30+
concept multi_extended_component_container_c = (extended_component_container_c<ContainerType, ComponentType> && ...);
31+
32+
} // namespace power_grid_model

power_grid_model_c/power_grid_model/include/power_grid_model/main_core/state.hpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,6 @@ template <class CompContainer> struct MainModelState {
2828
template <class StateType>
2929
concept main_model_state_c = std::same_as<StateType, MainModelState<typename StateType::ComponentContainer>>;
3030

31-
template <typename ContainerType, typename ComponentType>
32-
concept component_container_c = requires(ContainerType const& c, ID id) {
33-
{ c.template citer<ComponentType>().begin() } -> std::forward_iterator;
34-
{ c.template citer<ComponentType>().end() } -> std::forward_iterator;
35-
{ *(c.template citer<ComponentType>().begin()) } -> std::same_as<ComponentType const&>;
36-
{ *(c.template citer<ComponentType>().end()) } -> std::same_as<ComponentType const&>;
37-
{ c.template get_item<ComponentType>(id) } -> std::convertible_to<ComponentType const&>;
38-
};
39-
40-
template <typename ContainerType, typename ComponentType>
41-
concept extended_component_container_c =
42-
component_container_c<ContainerType, ComponentType> && requires(ContainerType const& c, Idx2D const& idx2d) {
43-
{ c.template size<ComponentType>() } -> std::same_as<Idx>;
44-
{ c.template get_seq<ComponentType>(idx2d) } -> std::same_as<Idx>;
45-
};
46-
47-
template <typename ContainerType, typename... ComponentType>
48-
concept multi_extended_component_container_c = (extended_component_container_c<ContainerType, ComponentType> && ...);
49-
5031
template <template <typename T> class StateType, typename ContainerType, typename ComponentType>
5132
concept model_component_state_c =
5233
component_container_c<typename StateType<ContainerType>::ComponentContainer, ComponentType> &&

power_grid_model_c/power_grid_model/include/power_grid_model/optimizer/optimizer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ constexpr auto get_optimizer(OptimizerType optimizer_type, OptimizerStrategy str
2929
case automatic_tap_adjustment:
3030
if constexpr (detail::steady_state_calculator_c<StateCalculator, State> &&
3131
std::invocable<std::remove_cvref_t<StateUpdater>, ConstDataset const&> &&
32-
main_core::component_container_c<typename State::ComponentContainer, TransformerTapRegulator>) {
32+
component_container_c<typename State::ComponentContainer, TransformerTapRegulator>) {
3333
return BaseOptimizer::template make_shared<TapPositionOptimizer<StateCalculator, StateUpdater, State>>(
3434
std::move(calculator), std::move(updater), strategy, meta_data, search);
3535
}

power_grid_model_c/power_grid_model/include/power_grid_model/optimizer/tap_position_optimizer.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ template <transformer_c... TransformerTypes> struct TapRegulatorRef {
471471
};
472472

473473
template <typename State>
474-
requires main_core::component_container_c<typename State::ComponentContainer, TransformerTapRegulator>
474+
requires component_container_c<typename State::ComponentContainer, TransformerTapRegulator>
475475
TransformerTapRegulator const& find_regulator(State const& state, ID regulated_object) {
476476
auto const regulators = get_component_citer<TransformerTapRegulator>(state);
477477

@@ -503,7 +503,7 @@ template <typename... Ts> struct transformer_types_s<std::tuple<std::tuple<Ts...
503503
template <typename... Ts> using transformer_types_t = typename transformer_types_s<std::tuple<Ts...>>::type;
504504

505505
template <transformer_c... TransformerTypes, typename State>
506-
requires(main_core::component_container_c<typename State::ComponentContainer, TransformerTypes> && ...)
506+
requires(component_container_c<typename State::ComponentContainer, TransformerTypes> && ...)
507507
inline TapRegulatorRef<TransformerTypes...> regulator_mapping(State const& state, Idx2D const& transformer_index) {
508508
using ResultType = TapRegulatorRef<TransformerTypes...>;
509509
using IsType = bool (*)(Idx2D const&);
@@ -536,7 +536,7 @@ inline TapRegulatorRef<TransformerTypes...> regulator_mapping(State const& state
536536
}
537537

538538
template <transformer_c... TransformerTypes, typename State>
539-
requires(main_core::component_container_c<typename State::ComponentContainer, TransformerTypes> && ...)
539+
requires(component_container_c<typename State::ComponentContainer, TransformerTypes> && ...)
540540
inline auto regulator_mapping(State const& state, std::vector<Idx2D> const& order) {
541541
std::vector<TapRegulatorRef<TransformerTypes...>> result;
542542
result.reserve(order.size());
@@ -549,7 +549,7 @@ inline auto regulator_mapping(State const& state, std::vector<Idx2D> const& orde
549549
}
550550

551551
template <transformer_c... TransformerTypes, typename State>
552-
requires(main_core::component_container_c<typename State::ComponentContainer, TransformerTypes> && ...)
552+
requires(component_container_c<typename State::ComponentContainer, TransformerTypes> && ...)
553553
inline auto regulator_mapping(State const& state, RankedTransformerGroups const& order) {
554554
std::vector<std::vector<TapRegulatorRef<TransformerTypes...>>> result;
555555
result.reserve(order.size());
@@ -598,15 +598,15 @@ inline auto i_pu(std::vector<SolverOutputType> const& solver_output, Idx2DBranch
598598

599599
template <component_c ComponentType, typename... RegulatedTypes, typename State,
600600
steady_state_solver_output_type SolverOutputType>
601-
requires main_core::component_container_c<typename State::ComponentContainer, ComponentType>
601+
requires component_container_c<typename State::ComponentContainer, ComponentType>
602602
inline auto i_pu_controlled_node(TapRegulatorRef<RegulatedTypes...> const& regulator, State const& state,
603603
std::vector<SolverOutputType> const& solver_output) {
604604
auto const& branch_math_id = get_math_id<ComponentType>(state, regulator.transformer.topology_index());
605605
return i_pu<ComponentType>(solver_output, branch_math_id, regulator.regulator.get().control_side());
606606
}
607607

608608
template <transformer_c ComponentType, typename State, steady_state_solver_output_type SolverOutputType>
609-
requires main_core::component_container_c<typename State::ComponentContainer, ComponentType> &&
609+
requires component_container_c<typename State::ComponentContainer, ComponentType> &&
610610
requires(State const& state, Idx const i) {
611611
{ get_branch_nodes<ComponentType>(state, i)[i] } -> std::convertible_to<Idx>;
612612
}
@@ -619,15 +619,15 @@ inline auto u_pu(State const& state, std::vector<SolverOutputType> const& solver
619619

620620
template <component_c ComponentType, typename... RegulatedTypes, typename State,
621621
steady_state_solver_output_type SolverOutputType>
622-
requires main_core::component_container_c<typename State::ComponentContainer, ComponentType>
622+
requires component_container_c<typename State::ComponentContainer, ComponentType>
623623
inline auto u_pu_controlled_node(TapRegulatorRef<RegulatedTypes...> const& regulator, State const& state,
624624
std::vector<SolverOutputType> const& solver_output) {
625625
return u_pu<ComponentType>(state, solver_output, regulator.transformer.topology_index(),
626626
regulator.regulator.get().control_side());
627627
}
628628

629629
template <component_c ComponentType, typename... RegulatedTypes, typename State>
630-
requires main_core::component_container_c<typename State::ComponentContainer, ComponentType>
630+
requires component_container_c<typename State::ComponentContainer, ComponentType>
631631
inline bool is_regulated_transformer_connected(TapRegulatorRef<RegulatedTypes...> const& regulator,
632632
State const& state) {
633633
auto const controlled_node_idx = get_topo_node<ComponentType>(state, regulator.transformer.topology_index(),
@@ -702,7 +702,7 @@ class RankIteration {
702702
template <typename... T> class TapPositionOptimizerImpl;
703703
template <transformer_c... TransformerTypes, typename StateCalculator, typename StateUpdater_, typename State_,
704704
typename TransformerRanker_>
705-
requires(main_core::component_container_c<typename State_::ComponentContainer, TransformerTypes> && ...) &&
705+
requires(component_container_c<typename State_::ComponentContainer, TransformerTypes> && ...) &&
706706
detail::steady_state_calculator_c<StateCalculator, State_> &&
707707
std::invocable<std::remove_cvref_t<StateUpdater_>, ConstDataset const&> &&
708708
requires(TransformerRanker_ const& ranker, State_ const& state) {

tests/cpp_unit_tests/test_optimizer.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ static_assert(transformer_c<StubTransformerA>);
5454
static_assert(transformer_c<StubTransformerB>);
5555

5656
template <std::derived_from<StubTransformer> ComponentType, typename State>
57-
requires main_core::component_container_c<typename State::ComponentContainer, ComponentType>
57+
requires component_container_c<typename State::ComponentContainer, ComponentType>
5858
constexpr auto get_topology_index(State const& /* state */, auto const& /* id_or_index */) {
5959
return Idx{};
6060
}
6161

6262
template <std::derived_from<StubTransformer> ComponentType, typename State>
63-
requires main_core::component_container_c<typename State::ComponentContainer, ComponentType>
63+
requires component_container_c<typename State::ComponentContainer, ComponentType>
6464
constexpr auto get_math_id(State const& /* state */, Idx /* topology_sequence_idx */) {
6565
return StubTransformerMathIdType{};
6666
}
@@ -73,7 +73,7 @@ inline auto i_pu(std::vector<SolverOutputType> const& /* solver_output */,
7373

7474
template <std::derived_from<StubTransformer> ComponentType, typename State,
7575
steady_state_solver_output_type SolverOutputType>
76-
requires main_core::component_container_c<typename State::ComponentContainer, ComponentType>
76+
requires component_container_c<typename State::ComponentContainer, ComponentType>
7777
inline auto u_pu(State const& /* state */, std::vector<SolverOutputType> const& /* solver_output */,
7878
Idx /* topology_index */, ControlSide /* control_side */) {
7979
return ComplexValue<typename SolverOutputType::sym>{};

tests/cpp_unit_tests/test_tap_position_optimizer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ class MockSolverOutput : public SolverOutput<symmetric_t> {
624624
template <typename... T> struct AddTapPositions;
625625
template <typename T> struct AddTapPositions<T> {
626626
void operator()(main_core::MainModelState<ContainerType> const& state, std::map<ID, IntS>& target) {
627-
if constexpr (transformer_c<T> && main_core::component_container_c<ContainerType, T>) {
627+
if constexpr (transformer_c<T> && component_container_c<ContainerType, T>) {
628628
for (auto const& component : state.components.template citer<T>()) {
629629
target[component.id()] = component.tap_pos();
630630
}
@@ -732,14 +732,14 @@ struct MockTransformer {
732732
static_assert(transformer_c<MockTransformer>);
733733

734734
template <std::derived_from<MockTransformer> ComponentType, typename State>
735-
requires main_core::component_container_c<typename State::ComponentContainer, ComponentType>
735+
requires component_container_c<typename State::ComponentContainer, ComponentType>
736736
constexpr auto get_topology_index(State const& state, auto const& id_or_index) {
737737
auto const& transformer = main_core::get_component<ComponentType>(state, id_or_index);
738738
return transformer.state.math_id.pos;
739739
}
740740

741741
template <std::derived_from<MockTransformer> ComponentType, typename State>
742-
requires main_core::component_container_c<typename State::ComponentContainer, ComponentType>
742+
requires component_container_c<typename State::ComponentContainer, ComponentType>
743743
constexpr auto get_math_id(State const& state, Idx topology_index) {
744744
return main_core::get_component_by_sequence<MockTransformer>(state, topology_index).state.math_id;
745745
}
@@ -763,7 +763,7 @@ inline DoubleComplex i_pu(std::vector<MockSolverOutput<ContainerType>> const& so
763763

764764
template <std::derived_from<MockTransformer> ComponentType, typename State,
765765
steady_state_solver_output_type SolverOutputType>
766-
requires main_core::component_container_c<typename State::ComponentContainer, ComponentType>
766+
requires component_container_c<typename State::ComponentContainer, ComponentType>
767767
inline auto u_pu(State const& state, std::vector<SolverOutputType> const& /* solver_output */, Idx topology_index,
768768
ControlSide side) {
769769
return main_core::get_component_by_sequence<MockTransformer>(state, topology_index).state.u_pu(side);

0 commit comments

Comments
 (0)