From 82515797834658250acdcfb563453853114e10ff Mon Sep 17 00:00:00 2001 From: VEDELAGO MIORA Date: Wed, 30 Mar 2022 15:29:49 +0200 Subject: [PATCH] Fix: fictitious DC topological nodes are created when a DC converter station is disconnected Signed-off-by: VEDELAGO MIORA --- .../conversion/export/CgmesExportContext.java | 7 ++++++- .../cgmes/conversion/export/TopologyExport.java | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/CgmesExportContext.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/CgmesExportContext.java index 2be01030d02..e7020821e17 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/CgmesExportContext.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/CgmesExportContext.java @@ -387,7 +387,7 @@ private static void addIidmMappingsTerminal(Terminal t, Connectable c) { boundaryId = CgmesExportUtil.getUniqueId(); c.addAlias(boundaryId, Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + TERMINAL_BOUNDARY); } - } else if (c instanceof Load && ((Load) c).isFictitious()) { + } else if (c instanceof Load && c.isFictitious()) { // An fictitious load do not need an alias } else { int sequenceNumber = CgmesExportUtil.getTerminalSide(t, c); @@ -602,6 +602,11 @@ public Set getTopologicalNodesByBusViewBu return topologicalNodeByBusViewBusMapping.get(busId); } + public CgmesExportContext putTopologicalNode(String iidmBusId, String cgmesId) { + topologicalNodeByBusViewBusMapping.computeIfAbsent(iidmBusId, k -> new HashSet<>()).add(new CgmesIidmMapping.CgmesTopologicalNode(cgmesId, cgmesId, Source.IGM)); + return this; + } + public Set getUnmappedTopologicalNodes() { return Collections.unmodifiableSet(unmappedTopologicalNodes); } diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/TopologyExport.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/TopologyExport.java index 3d35b9bf8c5..4a9c24cda46 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/TopologyExport.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/TopologyExport.java @@ -129,7 +129,13 @@ private static void writeHvdcTerminals(Network network, String cimNamespace, XML } private static void writeHvdcBusTerminals(HvdcLine line, Bus bus, int side, String cimNamespace, XMLStreamWriter writer, CgmesExportContext context) throws XMLStreamException { - for (CgmesIidmMapping.CgmesTopologicalNode topologicalNode : context.getTopologicalNodesByBusViewBus(bus.getId())) { + String iidmId; + if (bus == null) { + iidmId = line.getId() + side; + } else { + iidmId = bus.getId(); + } + for (CgmesIidmMapping.CgmesTopologicalNode topologicalNode : context.getTopologicalNodesByBusViewBus(iidmId)) { String dcTopologicalNode = topologicalNode.getCgmesId() + "DC"; String dcNode = line.getAliasFromType(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + "DCNode" + side).orElseThrow(PowsyblException::new); writeDCNode(dcNode, dcTopologicalNode, cimNamespace, writer); @@ -223,6 +229,10 @@ private static void writeHvdcTopologicalNodes(Network network, String cimNamespa for (CgmesIidmMapping.CgmesTopologicalNode topologicalNode : context.getTopologicalNodesByBusViewBus(b1.getId())) { writeDCTopologicalNode(topologicalNode.getCgmesId() + "DC", line.getNameOrId() + 1, cimNamespace, writer); } + } else { + String topologicalNode = CgmesExportUtil.getUniqueId(); + context.putTopologicalNode(line.getId() + 1, topologicalNode); + writeDCTopologicalNode(topologicalNode + "DC", line.getNameOrId() + 1, cimNamespace, writer); } Bus b2 = line.getConverterStation2().getTerminal().getBusView().getBus(); @@ -230,7 +240,12 @@ private static void writeHvdcTopologicalNodes(Network network, String cimNamespa for (CgmesIidmMapping.CgmesTopologicalNode topologicalNode : context.getTopologicalNodesByBusViewBus(b2.getId())) { writeDCTopologicalNode(topologicalNode.getCgmesId() + "DC", line.getNameOrId() + 2, cimNamespace, writer); } + } else { + String topologicalNode = CgmesExportUtil.getUniqueId(); + context.putTopologicalNode(line.getId() + 2, topologicalNode); + writeDCTopologicalNode(topologicalNode + "DC", line.getNameOrId() + 2, cimNamespace, writer); } + } }