Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BugFix / Handle access violation to unconnected-regulated transformers #703

Merged
merged 6 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ constexpr void add_edge(main_core::MainModelState<ComponentContainer> const& sta
}
auto const& from_node = transformer.from_node();
auto const& to_node = transformer.to_node();

if (regulated_objects.transformers.contains(transformer.id())) {
auto const tap_at_from_side = transformer.tap_side() == BranchSide::from;
auto const& tap_side_node = tap_at_from_side ? from_node : to_node;
Expand Down Expand Up @@ -542,6 +541,15 @@ inline auto u_pu_controlled_node(TapRegulatorRef<RegulatedTypes...> const& regul
regulator.regulator.get().control_side());
}

template <component_c ComponentType, typename... RegulatedTypes, typename State>
requires main_core::component_container_c<typename State::ComponentContainer, ComponentType>
inline bool is_regulated_transformer_connected(TapRegulatorRef<RegulatedTypes...> const& regulator,
State const& state) {
auto const controlled_node_idx = get_topo_node<ComponentType>(state, regulator.transformer.topology_index(),
regulator.regulator.get().control_side());
return get_math_id<Node>(state, controlled_node_idx) != Idx2D{-1, -1};
}

struct VoltageBand {
double u_set{};
double u_band{};
Expand Down Expand Up @@ -935,6 +943,9 @@ class TapPositionOptimizerImpl<std::tuple<TransformerTypes...>, StateCalculator,

regulator.transformer.apply([&](transformer_c auto const& transformer) {
using TransformerType = std::remove_cvref_t<decltype(transformer)>;
if (!is_regulated_transformer_connected<TransformerType>(regulator, state)) {
return;
}

auto [node_state, param] = compute_node_state_and_param<TransformerType>(regulator, state, solver_output);

Expand Down Expand Up @@ -967,6 +978,9 @@ class TapPositionOptimizerImpl<std::tuple<TransformerTypes...>, StateCalculator,

regulator.transformer.apply([&](transformer_c auto const& transformer) { // NOSONAR
using TransformerType = std::remove_cvref_t<decltype(transformer)>;
if (!is_regulated_transformer_connected<TransformerType>(regulator, state)) {
mgovers marked this conversation as resolved.
Show resolved Hide resolved
return;
}

auto [node_state, param] = compute_node_state_and_param<TransformerType>(regulator, state, solver_output);

Expand Down
10 changes: 10 additions & 0 deletions tests/cpp_unit_tests/test_tap_position_optimizer.cpp
mgovers marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,16 @@ inline auto u_pu(State const& state, std::vector<SolverOutputType> const& /* sol
return main_core::get_component_by_sequence<MockTransformer>(state, topology_index).state.u_pu(side);
}

template <std::derived_from<MockTransformer> ComponentType, typename State>
inline auto get_topo_node(State const& /*state*/, Idx /*topology_index*/, ControlSide /*control_side*/) {
return 0;
}

template <typename ComponentType, typename State>
inline auto get_math_id(State const& /*state*/, Idx /*topology_index*/) {
return Idx2D{0, 0};
}

template <typename ContainerType>
std::vector<MockSolverOutput<ContainerType>>
mock_state_calculator(main_core::MainModelState<ContainerType> const& state, CalculationMethod method) {
Expand Down
Loading