Skip to content

Commit

Permalink
Simplification following subnetworks within its own identifiables
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
  • Loading branch information
flo-dup committed Sep 19, 2023
1 parent c7f1fce commit 379487d
Showing 1 changed file with 2 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,7 @@ private static void writeVoltageAngleLimits(Network n, NetworkXmlWriterContext c
}

private static void writeExtensions(Network n, NetworkXmlWriterContext context) throws XMLStreamException {
Collection<Identifiable<?>> identifiables = n.getIdentifiables();
if (supportSubnetworksExport(context)) {
identifiables = new LinkedHashSet<>(identifiables);
if (n.getParentNetwork() == n) {
// the subnetworks hold their extensions
identifiables.removeAll(n.getSubnetworks());
} else {
// Subnetworks are not in their own identifiables.
identifiables.add(n);
}
}

for (Identifiable<?> identifiable : IidmXmlUtil.sorted(identifiables, context.getOptions())) {
for (Identifiable<?> identifiable : IidmXmlUtil.sorted(n.getIdentifiables(), context.getOptions())) {
if (!context.isExportedEquipment(identifiable) || !retainElement(identifiable, n, context)) {
continue;
}
Expand Down Expand Up @@ -391,7 +379,7 @@ public static Anonymizer write(Network n, ExportOptions options, OutputStream os
private static boolean retainElement(Identifiable<?> element, Network n, NetworkXmlWriterContext context) {
return !supportSubnetworksExport(context)
|| n.getId().equals(element.getId()) // the element is the network
|| element.getParentNetwork() == n; // the element is directly in the network (not in one of its subnetworks)
|| element.getParentNetwork() == n && element.getType() != IdentifiableType.NETWORK; // the element is directly in the network (not in one of its subnetworks)
}

private static boolean supportSubnetworksExport(NetworkXmlWriterContext context) {
Expand Down

0 comments on commit 379487d

Please sign in to comment.