From f5a3e3739f03699c8d3de6ad7161ea9f91d3e5f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20LAIGRE?= Date: Thu, 6 May 2021 15:09:50 +0200 Subject: [PATCH 1/2] Throw a comprehensive exception when a terminal ref of a busbar section is written in bus-breaker or bus-branch (#295) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sébastien LAIGRE --- src/iidm/converter/xml/TerminalRefXml.cpp | 7 +++++++ test/iidm/NodeBreakerVoltageLevelTest.cpp | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/iidm/converter/xml/TerminalRefXml.cpp b/src/iidm/converter/xml/TerminalRefXml.cpp index c8777a177..3a7ecad22 100644 --- a/src/iidm/converter/xml/TerminalRefXml.cpp +++ b/src/iidm/converter/xml/TerminalRefXml.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -18,6 +19,7 @@ #include #include #include +#include #include namespace powsybl { @@ -57,6 +59,11 @@ void TerminalRefXml::writeTerminalRef(const Terminal& terminal, NetworkXmlWriter if (!context.getFilter().test(c)) { throw PowsyblException(stdcxx::format("Oups, terminal ref point to a filtered equipment %1%", c.get().getId())); } + if (terminal.getVoltageLevel().getTopologyKind() == TopologyKind::NODE_BREAKER + && context.getOptions().getTopologyLevel() != TopologyLevel::NODE_BREAKER + && stdcxx::isInstanceOf(terminal.getConnectable())) { + throw PowsyblException(stdcxx::format("Terminal ref should not point to a busbar section (here %1%). Try to export in node-breaker or delete this terminal ref.", terminal.getConnectable().get().getId())); + } writer.writeStartElement(nsPrefix, elementName); writer.writeAttribute(ID, context.getAnonymizer().anonymizeString(c.get().getId())); if (c.get().getTerminals().size() > 1) { diff --git a/test/iidm/NodeBreakerVoltageLevelTest.cpp b/test/iidm/NodeBreakerVoltageLevelTest.cpp index 947065dc6..2f9f13364 100644 --- a/test/iidm/NodeBreakerVoltageLevelTest.cpp +++ b/test/iidm/NodeBreakerVoltageLevelTest.cpp @@ -19,8 +19,10 @@ #include #include #include +#include #include #include +#include #include @@ -1220,6 +1222,27 @@ BOOST_AUTO_TEST_CASE(issue318_invalidateCache) { BOOST_CHECK(!bbs2.getTerminal().getBusView().getBus()); } +BOOST_AUTO_TEST_CASE(NbkComprehensiveErrorMessage) { + Network network = powsybl::network::FourSubstationsNodeBreakerFactory::create(); + BusbarSection& busbarSection = network.getBusbarSection("S1VL2_BBS1"); + TwoWindingsTransformer& twt = network.getTwoWindingsTransformer("TWT"); + twt.getPhaseTapChanger().setRegulationTerminal(stdcxx::ref(busbarSection.getTerminal())); + + stdcxx::Properties properties; + properties.set(converter::ExportOptions::TOPOLOGY_LEVEL, "NODE_BREAKER"); + + // make sure no error is thrown while exporting to NODE_BREAKER topology + BOOST_CHECK_NO_THROW({ + std::stringstream ss; + Network::writeXml("network.xiidm", ss, network, converter::ExportOptions(properties)); + Network::readXml("network.xiidm", ss); + }); + + // make sure an error is thrown when exporting to BUS_BREAKER topology (see #295) + properties.set(converter::ExportOptions::TOPOLOGY_LEVEL, "BUS_BREAKER"); + POWSYBL_ASSERT_THROW(Network::writeXml("network.xiidm", ss, network, converter::ExportOptions(properties)), PowsyblException, "Terminal ref should not point to a busbar section (here S1VL2_BBS1). Try to export in node-breaker or delete this terminal ref."); +} + BOOST_AUTO_TEST_SUITE_END() } // namespace iidm From 725d8fc8abdacbbe4a30f44fd3c10106dab7aac0 Mon Sep 17 00:00:00 2001 From: Mathieu BAGUE Date: Mon, 31 May 2021 23:03:11 +0200 Subject: [PATCH 2/2] Small fixes Signed-off-by: Mathieu BAGUE --- src/iidm/converter/xml/TerminalRefXml.cpp | 6 +++--- test/iidm/NodeBreakerVoltageLevelTest.cpp | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/iidm/converter/xml/TerminalRefXml.cpp b/src/iidm/converter/xml/TerminalRefXml.cpp index 3a7ecad22..1b149dac8 100644 --- a/src/iidm/converter/xml/TerminalRefXml.cpp +++ b/src/iidm/converter/xml/TerminalRefXml.cpp @@ -59,9 +59,9 @@ void TerminalRefXml::writeTerminalRef(const Terminal& terminal, NetworkXmlWriter if (!context.getFilter().test(c)) { throw PowsyblException(stdcxx::format("Oups, terminal ref point to a filtered equipment %1%", c.get().getId())); } - if (terminal.getVoltageLevel().getTopologyKind() == TopologyKind::NODE_BREAKER - && context.getOptions().getTopologyLevel() != TopologyLevel::NODE_BREAKER - && stdcxx::isInstanceOf(terminal.getConnectable())) { + if (terminal.getVoltageLevel().getTopologyKind() == TopologyKind::NODE_BREAKER && + context.getOptions().getTopologyLevel() != TopologyLevel::NODE_BREAKER && + stdcxx::isInstanceOf(terminal.getConnectable())) { throw PowsyblException(stdcxx::format("Terminal ref should not point to a busbar section (here %1%). Try to export in node-breaker or delete this terminal ref.", terminal.getConnectable().get().getId())); } writer.writeStartElement(nsPrefix, elementName); diff --git a/test/iidm/NodeBreakerVoltageLevelTest.cpp b/test/iidm/NodeBreakerVoltageLevelTest.cpp index 2f9f13364..1f848dfe1 100644 --- a/test/iidm/NodeBreakerVoltageLevelTest.cpp +++ b/test/iidm/NodeBreakerVoltageLevelTest.cpp @@ -1231,9 +1231,10 @@ BOOST_AUTO_TEST_CASE(NbkComprehensiveErrorMessage) { stdcxx::Properties properties; properties.set(converter::ExportOptions::TOPOLOGY_LEVEL, "NODE_BREAKER"); + std::stringstream ss; + // make sure no error is thrown while exporting to NODE_BREAKER topology BOOST_CHECK_NO_THROW({ - std::stringstream ss; Network::writeXml("network.xiidm", ss, network, converter::ExportOptions(properties)); Network::readXml("network.xiidm", ss); });