Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -211,13 +213,20 @@ public void update(Network network, ReadOnlyDataSource ds, Properties p, ReportN

static class FilteredReadOnlyDataSource implements ReadOnlyDataSource {
private final ReadOnlyDataSource ds;
// The modeling authority or IGM name that this subnetwork was separated by, used to sort subnetworks deterministically.
private final String key;
private final Predicate<String> filter;

FilteredReadOnlyDataSource(ReadOnlyDataSource ds, Predicate<String> filter) {
FilteredReadOnlyDataSource(ReadOnlyDataSource ds, String key, Predicate<String> filter) {
this.ds = ds;
this.key = key;
this.filter = filter;
}

String getKey() {
return key;
}

@Override
public String getBaseName() {
return ds.getBaseName();
Expand Down Expand Up @@ -261,6 +270,11 @@ public Set<String> listNames(String regex) throws IOException {
}

static class MultipleGridModelChecker {
// Subnetworks are sorted by their key (modeling authority or IGM name) so that import order,
// and the resulting report, are deterministic and do not depend on hash-based Set iteration order.
private static final Comparator<ReadOnlyDataSource> SUBNETWORK_ORDER =
Comparator.comparing(ds -> ((FilteredReadOnlyDataSource) ds).getKey());

private final ReadOnlyDataSource dataSource;
private XMLInputFactory xmlInputFactory;

Expand Down Expand Up @@ -335,9 +349,9 @@ private Set<ReadOnlyDataSource> separateByModelingAuthority() {
}
}
return igmNames.keySet().stream()
.map(ma -> new FilteredReadOnlyDataSource(dataSource,
.<ReadOnlyDataSource>map(ma -> new FilteredReadOnlyDataSource(dataSource, ma,
name -> isBoundary(name) || igmNames.get(ma).contains(name) || shared.contains(name)))
.collect(Collectors.toSet());
.collect(Collectors.toCollection(() -> new TreeSet<>(SUBNETWORK_ORDER)));
}

private Optional<String> readModelingAuthority(String name) {
Expand Down Expand Up @@ -426,10 +440,10 @@ private Set<ReadOnlyDataSource> separateByIgmName() {
.map(name -> name.split("_")[2])
.collect(Collectors.toSet());
return igmNames.stream()
.map(igmName -> new FilteredReadOnlyDataSource(dataSource, name -> name.contains(igmName)
.<ReadOnlyDataSource>map(igmName -> new FilteredReadOnlyDataSource(dataSource, igmName, name -> name.contains(igmName)
|| isBoundary(name)
|| isShared(name, igmNames)))
.collect(Collectors.toSet());
.collect(Collectors.toCollection(() -> new TreeSet<>(SUBNETWORK_ORDER)));
}

private static boolean isBoundary(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,8 @@ void microGridBaseCaseAssembledSeparatingByFilename() {
params.put(CgmesImport.IMPORT_CGM_WITH_SUBNETWORKS_DEFINED_BY, CgmesImport.SubnetworkDefinedBy.FILENAME.name());
Network n = Network.read(CgmesConformity3Catalog.microGridBaseCaseAssembled().dataSource(), params);
assertEquals(2, n.getSubnetworks().size());
assertEquals(List.of("BE", "NL"),
n.getSubnetworks().stream()
.map(n1 -> n1.getSubstations().iterator().next().getCountry().map(Objects::toString).orElse(""))
.sorted()
.toList());
// Subnetworks are sorted by IGM name ("BE" < "NL")
assertEquals(List.of("BE", "NL"), subnetworksCountries(n));
checkExportSvTerminals(n);
}

Expand All @@ -96,14 +93,17 @@ void microGridBaseCaseAssembledSeparatingByModelingAuthority() {
params.put(CgmesImport.IMPORT_CGM_WITH_SUBNETWORKS_DEFINED_BY, CgmesImport.SubnetworkDefinedBy.MODELING_AUTHORITY.name());
Network n = Network.read(CgmesConformity3Catalog.microGridBaseCaseAssembled().dataSource(), params);
assertEquals(2, n.getSubnetworks().size());
assertEquals(List.of("BE", "NL"),
n.getSubnetworks().stream()
.map(n1 -> n1.getSubstations().iterator().next().getCountry().map(Objects::toString).orElse(""))
.sorted()
.toList());
// Subnetworks are sorted by modeling authority ("http://elia.be/CGMES" < "http://tennet.nl/CGMES")
assertEquals(List.of("BE", "NL"), subnetworksCountries(n));
checkExportSvTerminals(n);
}

private List<String> subnetworksCountries(Network n) {
return n.getSubnetworks().stream()
.map(n1 -> n1.getSubstations().iterator().next().getCountry().map(Objects::toString).orElse(""))
.toList();
}

private void checkExportSvTerminals(Network network) {
CgmesExportContext context = new CgmesExportContext(network);
context.setExportBoundaryPowerFlows(true);
Expand Down
Loading