From 539341d3728aa12609d21486fbb318e6ea0db544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20LAIGRE?= Date: Thu, 6 May 2021 09:09:12 +0200 Subject: [PATCH] Add missing invalidateCache in N/B Voltage Level (#318) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sébastien LAIGRE --- src/iidm/NodeBreakerVoltageLevel.cpp | 8 +++++- test/iidm/NodeBreakerVoltageLevelTest.cpp | 34 +++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/iidm/NodeBreakerVoltageLevel.cpp b/src/iidm/NodeBreakerVoltageLevel.cpp index 4dd8b8526..85521c91b 100644 --- a/src/iidm/NodeBreakerVoltageLevel.cpp +++ b/src/iidm/NodeBreakerVoltageLevel.cpp @@ -68,6 +68,10 @@ void NodeBreakerVoltageLevel::attach(Terminal& terminal, bool test) { // create the link terminal <-> graph vertex m_graph.setVertexObject(node, stdcxx::ref(nodeTerminal)); + + getNetwork().getVariantManager().forEachVariant([this]() { + invalidateCache(); + }); } } @@ -125,7 +129,9 @@ void NodeBreakerVoltageLevel::detach(Terminal& terminal) { assert(node < m_graph.getVertexCount()); assert(stdcxx::areSame(m_graph.getVertexObject(node).get(), nodeTerminal)); - invalidateCache(); + getNetwork().getVariantManager().forEachVariant([this]() { + invalidateCache(); + }); // remove the link terminal <-> graph vertex m_graph.setVertexObject(node, stdcxx::ref()); diff --git a/test/iidm/NodeBreakerVoltageLevelTest.cpp b/test/iidm/NodeBreakerVoltageLevelTest.cpp index 5b57adcf2..947065dc6 100644 --- a/test/iidm/NodeBreakerVoltageLevelTest.cpp +++ b/test/iidm/NodeBreakerVoltageLevelTest.cpp @@ -1186,6 +1186,40 @@ BOOST_AUTO_TEST_CASE(TestRemoveVoltageLevelWithInternalConnectionsIssue) { POWSYBL_ASSERT_THROW(network.getVoltageLevel("S5 10kV"), PowsyblException, "Unable to find to the identifiable 'S5 10kV'"); } +BOOST_AUTO_TEST_CASE(issue318_invalidateCache) { + Network network("test", "test"); + Substation& substation = network.newSubstation() + .setId("S1") + .setCountry(Country::FR) + .setTso("TSO") + .add(); + VoltageLevel& vl1 = substation.newVoltageLevel() + .setId("VL1") + .setTopologyKind(TopologyKind::NODE_BREAKER) + .setNominalV(90.0) + .setLowVoltageLimit(88.0) + .setHighVoltageLimit(96.0) + .add(); + + BusbarSection& bbs1 = vl1.getNodeBreakerView().newBusbarSection() + .setId("BBS1") + .setName("BBS1_NAME") + .setNode(0) + .add(); + + // In that case, the bus cache is initialized, but there is no bus for node 0 + BOOST_CHECK(!bbs1.getTerminal().getBusView().getBus()); + + BusbarSection& bbs2 = vl1.getNodeBreakerView().newBusbarSection() + .setId("BBS2") + .setName("BBS2_NAME") + .setNode(1) + .add(); + + // Without the fix, this call throws an exception (ArrayIndexOutOfBoundsException), but an invalid reference is expected + BOOST_CHECK(!bbs2.getTerminal().getBusView().getBus()); +} + BOOST_AUTO_TEST_SUITE_END() } // namespace iidm