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

Throw a comprehensive exception when a terminal ref of a busbar section on is written in bus-breaker or bus-branch (#295) #323

Merged
merged 2 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions src/iidm/converter/xml/TerminalRefXml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <powsybl/AssertionError.hpp>
#include <powsybl/iidm/Branch.hpp>
#include <powsybl/iidm/BusbarSection.hpp>
#include <powsybl/iidm/Enum.hpp>
#include <powsybl/iidm/Network.hpp>
#include <powsybl/iidm/PhaseTapChanger.hpp>
Expand All @@ -18,6 +19,7 @@
#include <powsybl/iidm/converter/Anonymizer.hpp>
#include <powsybl/iidm/converter/Constants.hpp>
#include <powsybl/iidm/converter/xml/NetworkXmlWriterContext.hpp>
#include <powsybl/stdcxx/instanceof.hpp>
#include <powsybl/xml/XmlStreamWriter.hpp>

namespace powsybl {
Expand Down Expand Up @@ -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<BusbarSection>(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) {
Expand Down
24 changes: 24 additions & 0 deletions test/iidm/NodeBreakerVoltageLevelTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
#include <powsybl/iidm/Network.hpp>
#include <powsybl/iidm/Substation.hpp>
#include <powsybl/iidm/Switch.hpp>
#include <powsybl/iidm/TwoWindingsTransformer.hpp>
#include <powsybl/iidm/VoltageLevel.hpp>
#include <powsybl/iidm/VoltageLevelAdder.hpp>
#include <powsybl/network/FourSubstationsNodeBreakerFactory.hpp>

#include <powsybl/test/AssertionUtils.hpp>

Expand Down Expand Up @@ -1220,6 +1222,28 @@ 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");

std::stringstream ss;

// make sure no error is thrown while exporting to NODE_BREAKER topology
BOOST_CHECK_NO_THROW({
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
Expand Down