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

[CGMES export] Export boundary TopologicalNodes in the TopologicalIsland #3138

Merged
merged 10 commits into from
Sep 30, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static void write(Network network, XMLStreamWriter writer, CgmesExportCon
if (context.getCimVersion() >= 16) {
CgmesExportUtil.writeModelDescription(network, CgmesSubset.STATE_VARIABLES, writer, model, context);
writeTopologicalIslands(network, context, writer);
// Note: unmapped topological nodes (node breaker) & boundary topological nodes are not written in topological islands
// Note: unmapped topological nodes (node breaker) are not written in topological islands
}

writeVoltagesForTopologicalNodes(network, context, writer);
Expand Down Expand Up @@ -224,8 +224,8 @@ static TopologicalIsland fromSynchronousComponent(String key, CgmesExportContext
return new TopologicalIsland(key, new ArrayList<>(), context);
}

static TopologicalIsland fromTopologicalNode(String topologicalNode, CgmesExportContext context) {
return new TopologicalIsland(topologicalNode, Collections.singletonList(topologicalNode), context);
static TopologicalIsland fromTopologicalNodes(List<String> topologicalNodes, CgmesExportContext context) {
return new TopologicalIsland(topologicalNodes.get(0), topologicalNodes, context);
}

void addNode(String topologicalNode, Bus bus, boolean updateLoadFlowStatus) {
Expand Down Expand Up @@ -292,13 +292,19 @@ boolean isInAccordanceWithKirchhoffsFirstLaw(Bus bus) {
private static List<TopologicalIsland> buildIslands(Network network, CgmesExportContext context) {
Map<String, TopologicalIsland> islands = new HashMap<>();
for (Bus b : network.getBusBreakerView().getBuses()) {
String topologicalNodeId = context.getNamingStrategy().getCgmesId(b);
// Adds the topological node of the bus and of any dangling line connected to this bus (QoCDC 4.0)
List<String> topologicalNodeIds = new ArrayList<>();
String busTnId = context.getNamingStrategy().getCgmesId(b);
topologicalNodeIds.add(busTnId);
b.getDanglingLines().forEach(dl -> topologicalNodeIds.add(dl.getProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + CgmesNames.TOPOLOGICAL_NODE_BOUNDARY)));
if (b.getSynchronousComponent() != null) {
String key = String.valueOf(b.getSynchronousComponent().getNum());
TopologicalIsland island = islands.computeIfAbsent(key, k -> TopologicalIsland.fromSynchronousComponent(k, context));
island.addNode(topologicalNodeId, b, context.isExportLoadFlowStatus());
for (String topologicalNodeId : topologicalNodeIds) {
island.addNode(topologicalNodeId, b, context.isExportLoadFlowStatus());
}
} else {
islands.put(topologicalNodeId, TopologicalIsland.fromTopologicalNode(topologicalNodeId, context));
islands.put(busTnId, TopologicalIsland.fromTopologicalNodes(topologicalNodeIds, context));
}
}
return islands.values().stream().toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,20 @@ void testDisconnectedTerminalForSlack() {
assertFalse(svInjectionPattern.matcher(svDisconnected).find());
}

@Test
void testWriteBoundaryTnInTopologicalIsland() throws XMLStreamException {
Network network = Network.read(CgmesConformity1Catalog.microGridBaseCaseNL().dataSource());
Optional<? extends Terminal> terminal = network.getBusBreakerView().getBus("97d7d14a-7294-458f-a8d7-024700a08717").getConnectedTerminalStream().findFirst();
assertTrue(terminal.isPresent());
ReferenceTerminals.addTerminal(terminal.get());
String sv = exportSvAsString(network, false);
Pattern p = Pattern.compile("<cim:TopologicalIsland.TopologicalNodes rdf:resource=");
assertEquals(10, p.matcher(sv).results().count());
// 10 is the number of topologicalIsland associated to buses + topological nodes associated to dangling lines
olperr1 marked this conversation as resolved.
Show resolved Hide resolved
assertEquals(5, network.getBusBreakerView().getBusStream().count());
assertEquals(5, network.getDanglingLineStream().count());
}

record ExportedContent(String sv, String tp) {
}

Expand Down