Skip to content

Commit

Permalink
Fix: when a switch has a disconnected terminal at its end, a fictitio…
Browse files Browse the repository at this point in the history
…us topological node is created

Signed-off-by: VEDELAGO MIORA <miora.ralambotiana@rte-france.com>
  • Loading branch information
miovd committed Mar 29, 2022
1 parent 5d3a617 commit 59993c0
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private static String cgmesTerminalFromAlias(Identifiable<?> i, String aliasType
}

private static String topologicalNodeFromIidmBus(Bus b, CgmesExportContext context) {
return context.getTopologicalNodesByBusViewBus(b.getId()).stream().findFirst().orElseThrow(PowsyblException::new).getCgmesId();
return b != null ? context.getTopologicalNodesByBusViewBus(b.getId()).stream().findFirst().orElseThrow(PowsyblException::new).getCgmesId() : null;
}

private static void writeSwitchesTerminals(Network network, String cimNamespace, XMLStreamWriter writer, CgmesExportContext context) throws XMLStreamException {
Expand All @@ -102,11 +102,22 @@ private static void writeSwitchesTerminals(Network network, String cimNamespace,
String cgmesTerminal1 = cgmesTerminalFromAlias(sw, CgmesNames.TERMINAL1);
String cgmesTerminal2 = cgmesTerminalFromAlias(sw, CgmesNames.TERMINAL2);

writeTerminal(cgmesTerminal1, topologicalNodeFromIidmBus(bus1, context), cimNamespace, writer);
writeTerminal(cgmesTerminal2, topologicalNodeFromIidmBus(bus2, context), cimNamespace, writer);
writeSwitchTerminal(bus1, sw.getVoltageLevel(), cgmesTerminal1, cimNamespace, writer, context);
writeSwitchTerminal(bus2, sw.getVoltageLevel(), cgmesTerminal2, cimNamespace, writer, context);
}
}

private static void writeSwitchTerminal(Bus bus, VoltageLevel voltageLevel, String cgmesTerminal, String cimNamespace,
XMLStreamWriter writer, CgmesExportContext context) throws XMLStreamException {
String tn = topologicalNodeFromIidmBus(bus, context);
if (tn == null) {
tn = CgmesExportUtil.getUniqueId();
writeTopologicalNode(tn, tn, voltageLevel.getId(),
context.getBaseVoltageByNominalVoltage(voltageLevel.getNominalV()).getId(), cimNamespace, writer);
}
writeTerminal(cgmesTerminal, tn, cimNamespace, writer);
}

private static void writeHvdcTerminals(Network network, String cimNamespace, XMLStreamWriter writer, CgmesExportContext context) throws XMLStreamException {
for (HvdcLine line : network.getHvdcLines()) {
Bus b1 = line.getConverterStation1().getTerminal().getBusView().getBus();
Expand Down

0 comments on commit 59993c0

Please sign in to comment.