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

Add missing invalidateCache in N/B Voltage Level (#318) #319

Merged
merged 2 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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