Skip to content

Commit

Permalink
Add missing invalidateCache in N/B Voltage Level (#318)
Browse files Browse the repository at this point in the history
Signed-off-by: Sébastien LAIGRE <[email protected]>
  • Loading branch information
sebalaig committed May 6, 2021
1 parent fa59a54 commit 539341d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/iidm/NodeBreakerVoltageLevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
}

Expand Down Expand Up @@ -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<NodeTerminal>());
Expand Down
34 changes: 34 additions & 0 deletions test/iidm/NodeBreakerVoltageLevelTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 539341d

Please sign in to comment.