diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/BufferedNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/BufferedNetworkStoreClient.java index 77625b6d8..fab29bd13 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/BufferedNetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/BufferedNetworkStoreClient.java @@ -128,6 +128,11 @@ public class BufferedNetworkStoreClient extends AbstractForwardingNetworkStoreCl delegate::updateTieLines, delegate::removeTieLines)); + private final NetworkCollectionIndex> subnetworkResourcesToFlush + = new NetworkCollectionIndex<>(() -> new CollectionBuffer<>(delegate::createSubnetworks, + delegate::updateSubnetworks, + delegate::removeSubnetworks)); + private final List>> allBuffers = List.of( networkResourcesToFlush, substationResourcesToFlush, @@ -147,7 +152,8 @@ public class BufferedNetworkStoreClient extends AbstractForwardingNetworkStoreCl threeWindingsTransformerResourcesToFlush, lineResourcesToFlush, busResourcesToFlush, - tieLineResourcesToFlush); + tieLineResourcesToFlush, + subnetworkResourcesToFlush); private final ExecutorService executorService; @@ -532,6 +538,25 @@ public void removeTieLines(UUID networkUuid, int variantNum, List tieLin tieLineResourcesToFlush.getCollection(networkUuid, variantNum).remove(tieLinesId); } + @Override + public void createSubnetworks(UUID networkUuid, List> subNetworkAttributes) { + for (Resource subnetworkResource : subNetworkAttributes) { + subnetworkResourcesToFlush.getCollection(networkUuid, subnetworkResource.getVariantNum()).create(subnetworkResource); + } + } + + @Override + public void updateSubnetworks(UUID networkUuid, List> subnetworkResources, AttributeFilter attributeFilter) { + for (Resource subnetworkResource : subnetworkResources) { + subnetworkResourcesToFlush.getCollection(networkUuid, subnetworkResource.getVariantNum()).update(subnetworkResource, attributeFilter); + } + } + + @Override + public void removeSubnetworks(UUID networkUuid, int variantNum, List subnetworkIds) { + subnetworkResourcesToFlush.getCollection(networkUuid, variantNum).remove(subnetworkIds); + } + @Override public void flush(UUID networkUuid) { Stopwatch stopwatch = Stopwatch.createStarted(); diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingNetworkStoreClient.java index 0c03cf18d..654c91de9 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingNetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingNetworkStoreClient.java @@ -864,4 +864,38 @@ public void removeConfiguredBuses(UUID networkUuid, int variantNum, List ensureCached(ResourceType.CONFIGURED_BUS, networkUuid, variantNum); delegate.removeConfiguredBuses(networkUuid, variantNum, configuredBusesId); } + + @Override + public void createSubnetworks(UUID networkUuid, List> subNetworkAttributes) { + for (Resource subNetworkResource : subNetworkAttributes) { + ensureCached(ResourceType.SUBNETWORK, networkUuid, subNetworkResource.getVariantNum()); + } + delegate.createSubnetworks(networkUuid, subNetworkAttributes); + } + + @Override + public List> getSubnetworks(UUID networkUuid, int variantNum) { + ensureCached(ResourceType.SUBNETWORK, networkUuid, variantNum); + return delegate.getSubnetworks(networkUuid, variantNum); + } + + @Override + public Optional> getSubnetwork(UUID networkUuid, int variantNum, String subnetworkId) { + ensureCached(ResourceType.SUBNETWORK, networkUuid, variantNum); + return delegate.getSubnetwork(networkUuid, variantNum, subnetworkId); + } + + @Override + public void removeSubnetworks(UUID networkUuid, int variantNum, List subnetworkIds) { + ensureCached(ResourceType.SUBNETWORK, networkUuid, variantNum); + delegate.removeTieLines(networkUuid, variantNum, subnetworkIds); + } + + @Override + public void updateSubnetworks(UUID networkUuid, List> subnetworkResources, AttributeFilter attributeFilter) { + for (Resource subnetworkResource : subnetworkResources) { + ensureCached(ResourceType.SUBNETWORK, networkUuid, subnetworkResource.getVariantNum()); + } + delegate.updateSubnetworks(networkUuid, subnetworkResources, attributeFilter); + } } diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java index d838c31ec..8932da1bc 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java @@ -773,6 +773,31 @@ public void updateTieLines(UUID networkUuid, List> t updateAll("tie line", "/networks/{networkUuid}/tie-lines", tieLineResources, attributeFilter, networkUuid); } + @Override + public void createSubnetworks(UUID networkUuid, List> subNetworkAttributes) { + + } + + @Override + public List> getSubnetworks(UUID networkUuid, int variantNum) { + return null; + } + + @Override + public Optional> getSubnetwork(UUID networkUuid, int variantNum, String subnetworkId) { + return Optional.empty(); + } + + @Override + public void removeSubnetworks(UUID networkUuid, int variantNum, List subnetworkIds) { + + } + + @Override + public void updateSubnetworks(UUID networkUuid, List> subnetworkResources, AttributeFilter attributeFilter) { + + } + @Override public Optional> getIdentifiable(UUID networkUuid, int variantNum, String id) { return get("identifiable", "/networks/{networkUuid}/{variantNum}/identifiables/{id}", networkUuid, variantNum, id); diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractBranchAdder.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractBranchAdder.java index b0dc62b82..9c4b640d7 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractBranchAdder.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractBranchAdder.java @@ -31,8 +31,8 @@ abstract class AbstractBranchAdder> extends Abs private String voltageLevelId2; - public AbstractBranchAdder(NetworkObjectIndex index) { - super(index); + public AbstractBranchAdder(NetworkObjectIndex index, String parentNetwork) { + super(index, parentNetwork); } public Integer getNode1() { diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractHvdcConverterStationAdder.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractHvdcConverterStationAdder.java index b9ada3996..b745dcd46 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractHvdcConverterStationAdder.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractHvdcConverterStationAdder.java @@ -17,8 +17,8 @@ public abstract class AbstractHvdcConverterStationAdder voltageLevelResource, NetworkObjectIndex index) { - super(voltageLevelResource, index); + AbstractHvdcConverterStationAdder(Resource voltageLevelResource, NetworkObjectIndex index, String parentNetwork) { + super(voltageLevelResource, index, parentNetwork); } public float getLossFactor() { diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractIdentifiableAdder.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractIdentifiableAdder.java index 85b446d3f..ad119aa04 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractIdentifiableAdder.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractIdentifiableAdder.java @@ -28,8 +28,11 @@ abstract class AbstractIdentifiableAdder> private boolean fictitious = false; - AbstractIdentifiableAdder(NetworkObjectIndex index) { + private String parentNetwork; + + AbstractIdentifiableAdder(NetworkObjectIndex index, String parentNetwork) { this.index = index; + this.parentNetwork = parentNetwork; } protected NetworkImpl getNetwork() { @@ -74,6 +77,15 @@ public T setFictitious(boolean fictitious) { return (T) this; } + protected String getParentNetwork() { + return parentNetwork; + } + + public T setParentNetwork(String parentNetwork) { + this.parentNetwork = parentNetwork; + return (T) this; + } + protected String checkAndGetUniqueId() { if (id == null) { throw new PowsyblException(getTypeDescription() + " id is not set"); diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractIdentifiableImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractIdentifiableImpl.java index 5ba71b6aa..0fccb79e0 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractIdentifiableImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractIdentifiableImpl.java @@ -275,6 +275,16 @@ public NetworkImpl getNetwork() { return index.getNetwork(); } + @Override + public Network getParentNetwork() { + String parentId = getResource().getParentNetwork(); + if (parentId == null || index.getNetwork().getId().equals(parentId)) { + return index.getNetwork(); + } else { + return index.getSubnetwork(parentId).orElse(null); + } + } + protected void invalidateCalculatedBuses(List terminals) { terminals.stream().map(Terminal::getVoltageLevel).filter(Objects::nonNull).map(VoltageLevel::getId) .forEach(id -> index.getVoltageLevel(id).ifPresent(VoltageLevelImpl::invalidateCalculatedBuses)); diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractInjectionAdder.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractInjectionAdder.java index c849177ae..5d030ab4a 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractInjectionAdder.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractInjectionAdder.java @@ -25,8 +25,8 @@ abstract class AbstractInjectionAdder> exten private String connectableBus; - public AbstractInjectionAdder(Resource voltageLevelResource, NetworkObjectIndex index) { - super(index); + public AbstractInjectionAdder(Resource voltageLevelResource, NetworkObjectIndex index, String parentNetwork) { + super(index, parentNetwork); this.voltageLevelResource = voltageLevelResource; } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractNetwork.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractNetwork.java new file mode 100644 index 000000000..21b69a6be --- /dev/null +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractNetwork.java @@ -0,0 +1,168 @@ +package com.powsybl.network.store.iidm.impl; + +import com.google.common.collect.ImmutableList; +import com.powsybl.iidm.network.*; +import com.powsybl.network.store.model.IdentifiableAttributes; +import com.powsybl.network.store.model.Resource; +import org.joda.time.DateTime; + +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static java.util.Comparator.comparingInt; +import static java.util.stream.Collectors.collectingAndThen; +import static java.util.stream.Collectors.toCollection; + +public abstract class AbstractNetwork extends AbstractIdentifiableImpl implements Network, Validable { + + private final BusBreakerView busBreakerView = new BusBreakerViewImpl(); + + private final BusView busView = new BusViewImpl(); + + protected AbstractNetwork(NetworkObjectIndex index, Resource resource) { + super(index, resource); + } + + @Override + public DateTime getCaseDate() { + return index.getNetwork().getCaseDate(); + } + + @Override + public Network setCaseDate(DateTime dateTime) { + return null; + } + + @Override + public int getForecastDistance() { + return 0; + } + + @Override + public Network setForecastDistance(int i) { + return null; + } + + @Override + public String getSourceFormat() { + return null; + } + + @Override + public Iterable getSubstations() { + return getSubstationStream().toList(); + } + + @Override + public int getSubstationCount() { + return (int) getSubstationStream().count(); + } + + @Override + public Iterable getSubstations(Country country, String tsoId, String... geographicalTags) { + return getSubstations(Optional.ofNullable(country).map(Country::getName).orElse(null), tsoId, geographicalTags); + } + + @Override + public Iterable getSubstations(String country, String tsoId, String... geographicalTags) { + return getSubstationStream().filter(substation -> { + if (country != null && !country.equals(substation.getCountry().map(Country::getName).orElse(""))) { + return false; + } + if (tsoId != null && !tsoId.equals(substation.getTso())) { + return false; + } + for (String tag : geographicalTags) { + if (!substation.getGeographicalTags().contains(tag)) { + return false; + } + } + return true; + }).collect(Collectors.toList()); + } + + class BusBreakerViewImpl implements BusBreakerView { + + @Override + public Iterable getBuses() { + return getBusStream().collect(Collectors.toList()); + } + + @Override + public Stream getBusStream() { + return getVoltageLevelStream().flatMap(vl -> vl.getBusBreakerView().getBusStream()); + } + + @Override + public int getBusCount() { + return getVoltageLevelStream().mapToInt(vl -> vl.getBusBreakerView().getBusCount()).sum(); + } + + @Override + public Iterable getSwitches() { + return getSwitchStream().collect(Collectors.toList()); + } + + @Override + public Stream getSwitchStream() { + return getVoltageLevelStream().flatMap(vl -> vl.getBusBreakerView().getSwitchStream()); + } + + @Override + public int getSwitchCount() { + return (int) getSwitchStream().count(); + } + + @Override + public Bus getBus(String id) { + Optional busInBusBreakerTopo = index.getConfiguredBus(id).map(Function.identity()); // start search in BB topo + return busInBusBreakerTopo.or(() -> getVoltageLevelStream().map(vl -> vl.getBusBreakerView().getBus(id)) // fallback to search in NB topo + .filter(Objects::nonNull) + .findFirst()) + .orElse(null); + } + } + + class BusViewImpl implements Network.BusView { + + @Override + public Iterable getBuses() { + return getBusStream().collect(Collectors.toList()); + } + + @Override + public Stream getBusStream() { + return getVoltageLevelStream().flatMap(vl -> vl.getBusView().getBusStream()); + } + + @Override + public Bus getBus(String id) { + return getBusStream().filter(b -> b.getId().equals(id)).findFirst().orElse(null); + } + + @Override + public Collection getConnectedComponents() { + return getBusStream().map(Bus::getConnectedComponent) + .collect(collectingAndThen(toCollection(() -> new TreeSet<>(comparingInt(Component::getNum))), ArrayList::new)); + } + + @Override + public Collection getSynchronousComponents() { + return getBusStream().map(Bus::getSynchronousComponent) + .collect(collectingAndThen(toCollection(() -> new TreeSet<>(comparingInt(Component::getNum))), ArrayList::new)); + } + } + + @Override + public BusBreakerView getBusBreakerView() { + return busBreakerView; + } + + @Override + public BusView getBusView() { + return busView; + } + +} diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractSwitchAdder.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractSwitchAdder.java index 17d67b4d3..4d14d0c04 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractSwitchAdder.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractSwitchAdder.java @@ -20,8 +20,8 @@ abstract class AbstractSwitchAdder> extends Abs private boolean open = false; - AbstractSwitchAdder(Resource voltageLevelResource, NetworkObjectIndex index) { - super(index); + AbstractSwitchAdder(Resource voltageLevelResource, NetworkObjectIndex index, String parentNetwork) { + super(index, parentNetwork); this.voltageLevelResource = voltageLevelResource; } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BatteryAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BatteryAdderImpl.java index 9b3a4b58e..3b341ce89 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BatteryAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BatteryAdderImpl.java @@ -26,7 +26,11 @@ public class BatteryAdderImpl extends AbstractInjectionAdder i private double maxP = Double.NaN; BatteryAdderImpl(Resource voltageLevelResource, NetworkObjectIndex index) { - super(voltageLevelResource, index); + super(voltageLevelResource, index, index.getNetwork().getId()); + } + + BatteryAdderImpl(Resource voltageLevelResource, NetworkObjectIndex index, String parentNetwork) { + super(voltageLevelResource, index, parentNetwork); } @Override @@ -72,6 +76,7 @@ public Battery add() { Resource resource = Resource.batteryBuilder() .id(id) .variantNum(index.getWorkingVariantNum()) + .parentNetwork(getParentNetwork()) .attributes(BatteryAttributes.builder() .voltageLevelId(getVoltageLevelResource().getId()) .name(getName()) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusBreakerViewImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusBreakerViewImpl.java index fc7f9fc9d..d01c12730 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusBreakerViewImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusBreakerViewImpl.java @@ -76,6 +76,11 @@ public Stream getBusStream() { return getBuses().stream(); } + @Override + public int getBusCount() { + return (int) getBusStream().count(); + } + @Override public Bus getBus(String busId) { if (isNodeBeakerTopologyKind()) { diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionAdderImpl.java index a2439079e..6fe1c58c5 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionAdderImpl.java @@ -23,7 +23,7 @@ class BusbarSectionAdderImpl extends AbstractIdentifiableAdder voltageLevelResource, NetworkObjectIndex index) { - super(index); + super(index, voltageLevelResource.getParentNetwork()); this.voltageLevelResource = voltageLevelResource; } @@ -40,6 +40,7 @@ public BusbarSection add() { Resource resource = Resource.busbarSectionBuilder() .id(id) .variantNum(index.getWorkingVariantNum()) + .parentNetwork(getParentNetwork()) .attributes(BusbarSectionAttributes.builder() .voltageLevelId(voltageLevelResource.getId()) .name(getName()) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CachedNetworkStoreClient.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CachedNetworkStoreClient.java index 8fa37f8ff..d2dc077ac 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CachedNetworkStoreClient.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CachedNetworkStoreClient.java @@ -118,6 +118,11 @@ public class CachedNetworkStoreClient extends AbstractForwardingNetworkStoreClie null, delegate::getTieLines)); + private final NetworkCollectionIndex> subnetworkCache = new NetworkCollectionIndex<>(() -> new CollectionCache<>( + delegate::getSubnetwork, + null, + delegate::getSubnetworks)); + private final Map>> voltageLevelContainersCaches = new EnumMap<>(ResourceType.class); private final Map>> networkContainersCaches = new EnumMap<>(ResourceType.class); @@ -144,6 +149,7 @@ public CachedNetworkStoreClient(NetworkStoreClient delegate) { networkContainersCaches.put(ResourceType.SUBSTATION, substationsCache); networkContainersCaches.put(ResourceType.VOLTAGE_LEVEL, voltageLevelsCache); networkContainersCaches.put(ResourceType.TIE_LINE, tieLinesCache); + networkContainersCaches.put(ResourceType.SUBNETWORK, subnetworkCache); } @Override @@ -247,6 +253,7 @@ public void cloneNetwork(UUID networkUuid, int sourceVariantNum, int targetVaria cloneCollection(configuredBusesCache, networkUuid, sourceVariantNum, targetVariantNum, objectMapper); cloneCollection(substationsCache, networkUuid, sourceVariantNum, targetVariantNum, objectMapper); cloneCollection(voltageLevelsCache, networkUuid, sourceVariantNum, targetVariantNum, objectMapper); + cloneCollection(subnetworkCache, networkUuid, sourceVariantNum, targetVariantNum, objectMapper); cloneCollection(networksCache, networkUuid, sourceVariantNum, targetVariantNum, objectMapper, networkResource -> networkResource.getAttributes().setVariantId(targetVariantId)); @@ -918,6 +925,38 @@ public void removeConfiguredBuses(UUID networkUuid, int variantNum, List configuredBusesCache.getCollection(networkUuid, variantNum).removeResources(busesId); } + @Override + public void createSubnetworks(UUID networkUuid, List> subNetworkAttributes) { + delegate.createSubnetworks(networkUuid, subNetworkAttributes); + for (Resource subnetworkResource : subNetworkAttributes) { + subnetworkCache.getCollection(networkUuid, subnetworkResource.getVariantNum()).createResource(subnetworkResource); + } + } + + @Override + public List> getSubnetworks(UUID networkUuid, int variantNum) { + return subnetworkCache.getCollection(networkUuid, variantNum).getResources(networkUuid, variantNum); + } + + @Override + public Optional> getSubnetwork(UUID networkUuid, int variantNum, String subnetworkId) { + return subnetworkCache.getCollection(networkUuid, variantNum).getResource(networkUuid, variantNum, subnetworkId); + } + + @Override + public void removeSubnetworks(UUID networkUuid, int variantNum, List subnetworkIds) { + delegate.removeSubnetworks(networkUuid, variantNum, subnetworkIds); + subnetworkCache.getCollection(networkUuid, variantNum).removeResources(subnetworkIds); + } + + @Override + public void updateSubnetworks(UUID networkUuid, List> subnetworkResources, AttributeFilter attributeFilter) { + delegate.updateSubnetworks(networkUuid, subnetworkResources, attributeFilter); + for (Resource subnetworkResource : subnetworkResources) { + subnetworkCache.getCollection(networkUuid, subnetworkResource.getVariantNum()).updateResource(subnetworkResource); + } + } + @SuppressWarnings("unchecked") @Override public Optional> getIdentifiable(UUID networkUuid, int variantNum, String id) { diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ConfiguredBusAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ConfiguredBusAdderImpl.java index 74a1724cb..3a561f0e2 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ConfiguredBusAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ConfiguredBusAdderImpl.java @@ -21,7 +21,7 @@ public class ConfiguredBusAdderImpl extends AbstractIdentifiableAdder voltageLevelResource; ConfiguredBusAdderImpl(Resource voltageLevelResource, NetworkObjectIndex index) { - super(index); + super(index, voltageLevelResource.getParentNetwork()); this.voltageLevelResource = voltageLevelResource; } @@ -32,6 +32,7 @@ public Bus add() { Resource resource = Resource.configuredBusBuilder() .id(id) .variantNum(index.getWorkingVariantNum()) + .parentNetwork(getParentNetwork()) .attributes(ConfiguredBusAttributes.builder() .name(getName()) .fictitious(isFictitious()) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/DanglingLineAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/DanglingLineAdderImpl.java index bdbc8db03..018afe6e7 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/DanglingLineAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/DanglingLineAdderImpl.java @@ -101,7 +101,11 @@ public DanglingLineAdder add() { private DanglingLineGenerationAttributes generation; DanglingLineAdderImpl(Resource voltageLevelResource, NetworkObjectIndex index) { - super(voltageLevelResource, index); + super(voltageLevelResource, index, index.getNetwork().getId()); + } + + DanglingLineAdderImpl(Resource voltageLevelResource, NetworkObjectIndex index, String parentNetwork) { + super(voltageLevelResource, index, parentNetwork); } @Override @@ -141,7 +145,7 @@ public DanglingLineAdder setB(double b) { } @Override - public DanglingLineAdder setUcteXnodeCode(String ucteXNodeCode) { + public DanglingLineAdder setPairingKey(String ucteXNodeCode) { this.ucteXNodeCode = ucteXNodeCode; return this; } @@ -166,6 +170,7 @@ public DanglingLine add() { Resource resource = Resource.danglingLineBuilder() .id(id) .variantNum(index.getWorkingVariantNum()) + .parentNetwork(getParentNetwork()) .attributes(DanglingLineAttributes.builder() .voltageLevelId(getVoltageLevelResource().getId()) .name(getName()) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/DanglingLineImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/DanglingLineImpl.java index 81ec9d8e7..0ef8f6412 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/DanglingLineImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/DanglingLineImpl.java @@ -328,11 +328,11 @@ public DanglingLine.Generation getGeneration() { } @Override - public String getUcteXnodeCode() { + public String getPairingKey() { return getResource().getAttributes().getUcteXnodeCode(); } - public DanglingLine setUcteXnodeCode(String ucteXnodeCode) { + public DanglingLine setPairingKey(String ucteXnodeCode) { String oldValue = getResource().getAttributes().getUcteXnodeCode(); if (!Objects.equals(ucteXnodeCode, oldValue)) { updateResource(res -> res.getAttributes().setUcteXnodeCode(ucteXnodeCode)); diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/GeneratorAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/GeneratorAdderImpl.java index 2e9ab9a61..670b97b32 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/GeneratorAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/GeneratorAdderImpl.java @@ -32,8 +32,8 @@ class GeneratorAdderImpl extends AbstractInjectionAdder impl private Terminal regulatingTerminal; - GeneratorAdderImpl(Resource voltageLevelResource, NetworkObjectIndex index) { - super(voltageLevelResource, index); + GeneratorAdderImpl(Resource voltageLevelResource, NetworkObjectIndex index, String parentId) { + super(voltageLevelResource, index, parentId); } @Override @@ -126,6 +126,7 @@ public Generator add() { Resource resource = Resource.generatorBuilder() .id(id) .variantNum(index.getWorkingVariantNum()) + .parentNetwork(getParentNetwork()) .attributes(GeneratorAttributes.builder() .voltageLevelId(getVoltageLevelResource().getId()) .name(getName()) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/HvdcLineAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/HvdcLineAdderImpl.java index 2ef4ccb0a..2bbe857b6 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/HvdcLineAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/HvdcLineAdderImpl.java @@ -32,7 +32,11 @@ public class HvdcLineAdderImpl extends AbstractIdentifiableAdder resource = Resource.hvdcLineBuilder() .id(id) .variantNum(index.getWorkingVariantNum()) + .parentNetwork(getParentNetwork()) .attributes(HvdcLineAttributes.builder() .name(getName()) .fictitious(isFictitious()) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/LccConverterStationAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/LccConverterStationAdderImpl.java index 60c8ac53d..7f4833363 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/LccConverterStationAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/LccConverterStationAdderImpl.java @@ -21,8 +21,8 @@ public class LccConverterStationAdderImpl extends AbstractHvdcConverterStationAd private float powerFactor = Float.NaN; - LccConverterStationAdderImpl(Resource voltageLevelResource, NetworkObjectIndex index) { - super(voltageLevelResource, index); + LccConverterStationAdderImpl(Resource voltageLevelResource, NetworkObjectIndex index, String parentNetwork) { + super(voltageLevelResource, index, parentNetwork); } @Override @@ -40,6 +40,7 @@ public LccConverterStation add() { Resource resource = Resource.lccConverterStationBuilder() .id(id) .variantNum(index.getWorkingVariantNum()) + .parentNetwork(getParentNetwork()) .attributes(LccConverterStationAttributes.builder() .voltageLevelId(getVoltageLevelResource().getId()) .name(getName()) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/LineAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/LineAdderImpl.java index 8ccb03718..4b61d576c 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/LineAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/LineAdderImpl.java @@ -8,6 +8,7 @@ import com.powsybl.iidm.network.Line; import com.powsybl.iidm.network.LineAdder; +import com.powsybl.iidm.network.ValidationException; import com.powsybl.iidm.network.ValidationUtil; import com.powsybl.network.store.model.LineAttributes; import com.powsybl.network.store.model.Resource; @@ -31,7 +32,11 @@ class LineAdderImpl extends AbstractBranchAdder implements LineAd private double b2 = 0; LineAdderImpl(NetworkObjectIndex index) { - super(index); + this(index, index.getNetwork().getId()); + } + + LineAdderImpl(NetworkObjectIndex index, String parentNetwork) { + super(index, parentNetwork); } @Override @@ -85,9 +90,25 @@ public Line add() { ValidationUtil.checkB1(this, b1); ValidationUtil.checkB2(this, b2); + VoltageLevelImpl vl1 = index.getVoltageLevel(getVoltageLevelId1()).orElse(null); + VoltageLevelImpl vl2 = index.getVoltageLevel(getVoltageLevelId2()).orElse(null); + SubnetworkImpl subnetwork = index.getSubnetwork(getParentNetwork()).orElse(null); + + if (subnetwork != null && vl1 != null && vl2 != null && (!subnetwork.getId().equals(vl1.getResource().getParentNetwork()) || !subnetwork.getId().equals(vl2.getResource().getParentNetwork()))) { + throw new ValidationException(this, "The involved voltage levels are not in the subnetwork '" + + subnetwork + "'. Create this line from the parent network '" + getNetwork().getId() + "'"); + } + + //TODO for all connectable... + String parent = getParentNetwork(); + if (vl1 != null && vl2 != null && vl1.getResource().getParentNetwork().equals(vl2.getResource().getParentNetwork())) { + parent = vl1.getResource().getParentNetwork(); + } + Resource resource = Resource.lineBuilder() .id(id) .variantNum(index.getWorkingVariantNum()) + .parentNetwork(parent) .attributes(LineAttributes.builder() .voltageLevelId1(getVoltageLevelId1()) .voltageLevelId2(getVoltageLevelId2()) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/LoadAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/LoadAdderImpl.java index c3a03796c..200167ce8 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/LoadAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/LoadAdderImpl.java @@ -23,8 +23,8 @@ class LoadAdderImpl extends AbstractInjectionAdder implements Loa private double q0 = Double.NaN; - LoadAdderImpl(Resource voltageLevelResource, NetworkObjectIndex index) { - super(voltageLevelResource, index); + LoadAdderImpl(Resource voltageLevelResource, NetworkObjectIndex index, String parentNetwork) { + super(voltageLevelResource, index, parentNetwork); } @Override @@ -58,6 +58,7 @@ public Load add() { Resource resource = Resource.loadBuilder() .id(id) .variantNum(index.getWorkingVariantNum()) + .parentNetwork(getParentNetwork()) .attributes(LoadAttributes.builder() .voltageLevelId(getVoltageLevelResource().getId()) .name(getName()) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkFactoryImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkFactoryImpl.java index b94948129..54e08ca08 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkFactoryImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkFactoryImpl.java @@ -13,10 +13,9 @@ import com.powsybl.network.store.model.Resource; import org.joda.time.DateTime; -import java.util.Collections; -import java.util.Objects; -import java.util.UUID; +import java.util.*; import java.util.function.Supplier; +import java.util.stream.Collectors; /** * @author Geoffroy Jamgotchian @@ -42,6 +41,7 @@ public Network createNetwork(String id, String sourceFormat) { .variantNum(Resource.INITIAL_VARIANT_NUM) .attributes(NetworkAttributes.builder() .uuid(networkUuid) + .subNetworksIds(new HashSet<>()) .variantId(VariantManagerConstants.INITIAL_VARIANT_ID) .caseDate(DateTime.now()) .forecastDistance(0) @@ -51,4 +51,17 @@ public Network createNetwork(String id, String sourceFormat) { storeClient.createNetworks(Collections.singletonList(resource)); return NetworkImpl.create(storeClient, resource); } + + @Override + public Network merge(String id, Network... networks) { + return NetworkImpl.merge(id, id, networks); + } + + @Override + public Network merge(Network... networks) { + String id = Arrays.stream(Objects.requireNonNull(networks)) + .map(Network::getId) + .collect(Collectors.joining("+")); + return merge(id, networks); + } } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkImpl.java index 235841f43..5670b4861 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkImpl.java @@ -7,12 +7,15 @@ package com.powsybl.network.store.iidm.impl; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; +import com.google.common.collect.Multimap; import com.google.common.primitives.Ints; import com.powsybl.cgmes.extensions.*; import com.powsybl.commons.PowsyblException; import com.powsybl.commons.extensions.Extension; import com.powsybl.iidm.network.*; import com.powsybl.cgmes.extensions.BaseVoltageMapping; +import com.powsybl.iidm.network.util.Identifiables; import com.powsybl.network.store.iidm.impl.extensions.BaseVoltageMappingImpl; import com.powsybl.network.store.model.BaseVoltageMappingAttributes; import com.powsybl.network.store.iidm.impl.extensions.CgmesControlAreasImpl; @@ -30,6 +33,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import static com.powsybl.iidm.network.util.TieLineUtil.*; import static java.util.Comparator.comparingInt; import static java.util.stream.Collectors.collectingAndThen; import static java.util.stream.Collectors.toCollection; @@ -109,6 +113,11 @@ public Stream getBusStream() { return getVoltageLevelStream().flatMap(vl -> vl.getBusBreakerView().getBusStream()); } + @Override + public int getBusCount() { + return getVoltageLevelStream().mapToInt(vl -> vl.getBusBreakerView().getBusCount()).sum(); + } + @Override public Iterable getSwitches() { return getSwitchStream().collect(Collectors.toList()); @@ -721,35 +730,194 @@ public VoltageLevelAdder newVoltageLevel() { } @Override - public TwoWindingsTransformerAdder newTwoWindingsTransformer() { - return new TwoWindingsTransformerAdderImpl(index, null); + public BusBreakerView getBusBreakerView() { + return busBreakerView; } @Override - public ThreeWindingsTransformerAdder newThreeWindingsTransformer() { - return new ThreeWindingsTransformerAdderImpl(index, null); + public BusView getBusView() { + return busView; } @Override - public BusBreakerView getBusBreakerView() { - return busBreakerView; + public VoltageAngleLimitAdder newVoltageAngleLimit() { + throw new UnsupportedOperationException("Voltage angle limit are not supported in this implementation"); } @Override - public BusView getBusView() { - return busView; + public Iterable getVoltageAngleLimits() { + throw new UnsupportedOperationException("Voltage angle limit are not supported in this implementation"); } @Override - public void merge(Network other) { - throw new UnsupportedOperationException("TODO"); + public Stream getVoltageAngleLimitsStream() { + throw new UnsupportedOperationException("Voltage angle limit are not supported in this implementation"); + } + + @Override + public VoltageAngleLimit getVoltageAngleLimit(String s) { + throw new UnsupportedOperationException("Voltage angle limit are not supported in this implementation"); + } + + @Override + public Collection getSubnetworks() { + return index.getSubnetworks(); } @Override + public Network getSubnetwork(String id) { + return index.getSubnetwork(id).orElse(null); + } + + @Override + public Network createSubnetwork(String subnetworkId, String name, String sourceFormat) { + Resource resourceSubNetwork = Resource.subnetwokBuilder() + .id(subnetworkId) + .parentNetwork(this.getId()) + .attributes(SubnetworkAttributes.builder() + .uuid(UUID.randomUUID()) + .build()) + .build(); + return index.createSubnetwork(resourceSubNetwork); + } + + private static void checkIndependentNetwork(Network network) { + if (network instanceof SubnetworkImpl) { + throw new IllegalArgumentException("The network " + network.getId() + " is already a subnetwork"); + } + if (!network.getSubnetworks().isEmpty()) { + throw new IllegalArgumentException("The network " + network.getId() + " already contains subnetworks: not supported"); + } + } + + class DanglingLinePair { + String id; + String name; + String dl1Id; + String dl2Id; + Map aliases; + Properties properties = new Properties(); + } + + private void pairDanglingLines(List danglingLinePairs, DanglingLine dl1, DanglingLine dl2, Map> dl1byXnodeCode) { + if (dl1 != null) { + if (dl1.getPairingKey() != null) { + dl1byXnodeCode.get(dl1.getPairingKey()).remove(dl1); + } + DanglingLinePair l = new DanglingLinePair(); + l.id = buildMergedId(dl1.getId(), dl2.getId()); + l.name = buildMergedName(dl1.getId(), dl2.getId(), dl1.getOptionalName().orElse(null), dl2.getOptionalName().orElse(null)); + l.dl1Id = dl1.getId(); + l.dl2Id = dl2.getId(); + l.aliases = new HashMap<>(); + // No need to merge properties or aliases because we keep the original dangling lines after merge + danglingLinePairs.add(l); + + /*if (dl1.getId().equals(dl2.getId())) { // if identical IDs, rename dangling lines + ((DanglingLineImpl) dl1).replaceId(l.dl1Id + "_1"); + ((DanglingLineImpl) dl2).replaceId(l.dl2Id + "_2"); + l.dl1Id = dl1.getId(); + l.dl2Id = dl2.getId(); + }*/ + } + } + + private void replaceDanglingLineByTieLine(List lines) { + for (DanglingLinePair danglingLinePair : lines) { + TieLine l = newTieLine() + .setId(danglingLinePair.id) + .setEnsureIdUnicity(true) + .setName(danglingLinePair.name) + .setDanglingLine1(danglingLinePair.dl1Id) + .setDanglingLine2(danglingLinePair.dl2Id) + .add(); + danglingLinePair.properties.forEach((key, val) -> l.setProperty(key.toString(), val.toString())); + danglingLinePair.aliases.forEach((alias, type) -> { + if (type.isEmpty()) { + l.addAlias(alias); + } else { + l.addAlias(alias, type); + } + }); + } + } + + private static void createSubnetwork(NetworkImpl parent, NetworkImpl original) { + // Handles the case of creating a subnetwork for itself without duplicating the id + String idSubNetwork = parent != original ? original.getId() : Identifiables.getUniqueId(original.getId(), parent.getIndex()::contains); + parent.createSubnetwork(idSubNetwork, "", original.getSourceFormat()); + } + + static Network merge(String id, String name, Network... networks) { + if (networks == null || networks.length < 2) { + throw new IllegalArgumentException("At least 2 networks are expected"); + } + NetworkImpl mergedNetwork = (NetworkImpl) Network.create(id, networks[0].getSourceFormat()); + for (Network other : networks) { + mergedNetwork.merge(other); + } + + return mergedNetwork; + } + + private void merge(Network other) { + checkIndependentNetwork(other); + NetworkImpl otherNetwork = (NetworkImpl) other; + + // this check must not be done on the number of variants but on the size + // of the internal variant array because the network can have only + // one variant but an internal array with a size greater than one and + // some re-usable variants + if (getVariantManager().getVariantIds().size() != 1 || otherNetwork.getVariantManager().getVariantIds().size() != 1) { + throw new PowsyblException("Merging of multi-variants network is not supported"); + } + + // try to find dangling lines couples + List lines = new ArrayList<>(); + Map> dl1byXnodeCode = new HashMap<>(); + + for (DanglingLine dl1 : getDanglingLines(DanglingLineFilter.ALL)) { + if (dl1.getPairingKey() != null) { + dl1byXnodeCode.computeIfAbsent(dl1.getPairingKey(), k -> new ArrayList<>()).add(dl1); + } + } + for (DanglingLine dl2 : Lists.newArrayList(other.getDanglingLines(DanglingLineFilter.ALL))) { + findAndAssociateDanglingLines(dl2, dl1byXnodeCode::get, (dll1, dll2) -> pairDanglingLines(lines, dll1, dll2, dl1byXnodeCode)); + } + + // create a subnetwork for the other network + createSubnetwork(this, otherNetwork); + + // merge the indexes + index.merge(otherNetwork.index); + + replaceDanglingLineByTieLine(lines); + } + public void merge(Network... others) { throw new UnsupportedOperationException("TODO"); } + @Override + public Network detach() { + throw new IllegalStateException("This network is already detached."); + } + + @Override + public boolean isDetachable() { + return false; + } + + @Override + public Set> getBoundaryElements() { + return getDanglingLineStream(DanglingLineFilter.UNPAIRED).collect(Collectors.toSet()); + } + + @Override + public boolean isBoundaryElement(Identifiable identifiable) { + return identifiable.getType() == IdentifiableType.DANGLING_LINE && !((DanglingLine) identifiable).isPaired(); + } + @Override public void addListener(NetworkListener listener) { listeners.add(listener); diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkObjectIndex.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkObjectIndex.java index 0b7a3c2d4..f6cd17908 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkObjectIndex.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkObjectIndex.java @@ -272,6 +272,8 @@ boolean isLoaded(String id) { private final ObjectCache configuredBusCache; + private final ObjectCache subnetworkCache; + private final Map objectCachesByResourceType = new EnumMap<>(ResourceType.class); public NetworkObjectIndex(NetworkStoreClient storeClient) { @@ -385,6 +387,13 @@ public NetworkObjectIndex(NetworkStoreClient storeClient) { id -> storeClient.removeTieLines(network.getUuid(), workingVariantNum, Collections.singletonList(id)), resource -> TieLineImpl.create(NetworkObjectIndex.this, resource)); + subnetworkCache = new ObjectCache<>(resource -> storeClient.createSubnetworks(network.getUuid(), Collections.singletonList(resource)), + id -> storeClient.getSubnetwork(network.getUuid(), workingVariantNum, id), + null, + () -> storeClient.getSubnetworks(network.getUuid(), workingVariantNum), + id -> storeClient.removeSubnetworks(network.getUuid(), workingVariantNum, Collections.singletonList(id)), + resource -> SubnetworkImpl.createSubnetwork(NetworkObjectIndex.this, resource)); + objectCachesByResourceType.put(ResourceType.SUBSTATION, substationCache); objectCachesByResourceType.put(ResourceType.VOLTAGE_LEVEL, voltageLevelCache); objectCachesByResourceType.put(ResourceType.GENERATOR, generatorCache); @@ -403,6 +412,7 @@ public NetworkObjectIndex(NetworkStoreClient storeClient) { objectCachesByResourceType.put(ResourceType.DANGLING_LINE, danglingLineCache); objectCachesByResourceType.put(ResourceType.CONFIGURED_BUS, configuredBusCache); objectCachesByResourceType.put(ResourceType.TIE_LINE, tieLineCache); + objectCachesByResourceType.put(ResourceType.SUBNETWORK, subnetworkCache); } public NetworkStoreClient getStoreClient() { @@ -781,6 +791,22 @@ public void removeTieLine(String tieLineId) { tieLineCache.remove(tieLineId); } + Optional getSubnetwork(String id) { + return subnetworkCache.getOne(id); + } + + List getSubnetworks() { + return subnetworkCache.getAll().collect(Collectors.toList()); + } + + SubnetworkImpl createSubnetwork(Resource resource) { + return subnetworkCache.create(resource); + } + + public void removeSubnetwork(String subnetworkId) { + subnetworkCache.remove(subnetworkId); + } + // shunt compensator @@ -933,6 +959,9 @@ public Collection> getIdentifiables() { .addAll(getHvdcLines()) .addAll(getDanglingLines()) .addAll(getConfiguredBuses()) + .addAll(getSubnetworks()) + .addAll(getTieLines()) + .add(getNetwork()) .build(); } @@ -1110,6 +1139,131 @@ void updateResource(Resource resource, Att case TIE_LINE: updateTieLineResource((Resource) resource, attributeFilter); break; + case SUBNETWORK: + updateSubnetworkResource((Resource) resource, attributeFilter); + break; + default: + throw new IllegalStateException("Unknown resource type: " + resource.getType()); + } + } + + void removeResource(Resource resource) { + switch (resource.getType()) { + case SUBSTATION: + removeSubstation(resource.getId()); + break; + case VOLTAGE_LEVEL: + removeVoltageLevel(resource.getId()); + break; + case LOAD: + removeLoad(resource.getId()); + break; + case GENERATOR: + removeGenerator(resource.getId()); + break; + case BATTERY: + removeBattery(resource.getId()); + break; + case SHUNT_COMPENSATOR: + removeShuntCompensator(resource.getId()); + break; + case VSC_CONVERTER_STATION: + removeVscConverterStation(resource.getId()); + break; + case LCC_CONVERTER_STATION: + removeLccConverterStation(resource.getId()); + break; + case STATIC_VAR_COMPENSATOR: + removeStaticVarCompensator(resource.getId()); + break; + case BUSBAR_SECTION: + removeBusBarSection(resource.getId()); + break; + case SWITCH: + removeSwitch(resource.getId()); + break; + case TWO_WINDINGS_TRANSFORMER: + removeTwoWindingsTransformer(resource.getId()); + break; + case THREE_WINDINGS_TRANSFORMER: + removeThreeWindingsTransformer(resource.getId()); + break; + case LINE: + removeLine(resource.getId()); + break; + case HVDC_LINE: + removeHvdcLine(resource.getId()); + break; + case DANGLING_LINE: + removeDanglingLine(resource.getId()); + break; + case CONFIGURED_BUS: + removeConfiguredBus(resource.getId()); + break; + case TIE_LINE: + removeTieLine(resource.getId()); + break; + default: + throw new IllegalStateException("Unknown resource type: " + resource.getType()); + } + } + + void createResource(Resource resource) { + switch (resource.getType()) { + case SUBSTATION: + createSubstation((Resource) resource); + break; + case VOLTAGE_LEVEL: + createVoltageLevel((Resource) resource); + break; + case LOAD: + createLoad((Resource) resource); + break; + case GENERATOR: + createGenerator((Resource) resource); + break; + case BATTERY: + createBattery((Resource) resource); + break; + case SHUNT_COMPENSATOR: + createShuntCompensator((Resource) resource); + break; + case VSC_CONVERTER_STATION: + createVscConverterStation((Resource) resource); + break; + case LCC_CONVERTER_STATION: + createLccConverterStation((Resource) resource); + break; + case STATIC_VAR_COMPENSATOR: + createStaticVarCompensator((Resource) resource); + break; + case BUSBAR_SECTION: + createBusbarSection((Resource) resource); + break; + case SWITCH: + createSwitch((Resource) resource); + break; + case TWO_WINDINGS_TRANSFORMER: + createTwoWindingsTransformer((Resource) resource); + break; + case THREE_WINDINGS_TRANSFORMER: + createThreeWindingsTransformer((Resource) resource); + break; + case LINE: + createLine((Resource) resource); + break; + case HVDC_LINE: + createHvdcLine((Resource) resource); + break; + case DANGLING_LINE: + createDanglingLine((Resource) resource); + break; + case CONFIGURED_BUS: + createConfiguredBus((Resource) resource); + break; + case TIE_LINE: + createTieLine((Resource) resource); + break; default: throw new IllegalStateException("Unknown resource type: " + resource.getType()); } @@ -1198,4 +1352,66 @@ void updateSubstationResource(Resource resource, Attribute void updateBusbarSectionResource(Resource resource, AttributeFilter attributeFilter) { storeClient.updateBusbarSections(network.getUuid(), Collections.singletonList(resource), attributeFilter); } + + void updateSubnetworkResource(Resource resource, AttributeFilter attributeFilter) { + storeClient.updateSubnetworks(network.getUuid(), Collections.singletonList(resource), attributeFilter); + } + + void merge(NetworkObjectIndex other) { + for (var substationResource : other.substationCache.allResourcesGetter.get()) { + this.createSubstation(substationResource); + } + for (var voltageLevelResource : other.voltageLevelCache.allResourcesGetter.get()) { + this.createVoltageLevel(voltageLevelResource); + } + for (var generatorResource : other.generatorCache.allResourcesGetter.get()) { + this.createGenerator(generatorResource); + } + for (var batteryResource: other.batteryCache.allResourcesGetter.get()) { + this.createBattery(batteryResource); + } + for (var shuntResource : other.shuntCompensatorCache.allResourcesGetter.get()) { + this.createShuntCompensator(shuntResource); + } + for (var vscConverterResource : other.vscConverterStationCache.allResourcesGetter.get()) { + this.createVscConverterStation(vscConverterResource); + } + for (var lccConverterResource : other.lccConverterStationCache.allResourcesGetter.get()) { + this.createLccConverterStation(lccConverterResource); + } + for (var staticVarCompensatorResource : other.staticVarCompensatorCache.allResourcesGetter.get()) { + this.createStaticVarCompensator(staticVarCompensatorResource); + } + for (var loadResource : other.loadCache.allResourcesGetter.get()) { + this.createLoad(loadResource); + } + for (var busBarSectionResource : other.busbarSectionCache.allResourcesGetter.get()) { + this.createBusbarSection(busBarSectionResource); + } + for (var switchResource : other.switchCache.allResourcesGetter.get()) { + this.createSwitch(switchResource); + } + for (var twoWindingsTransformerResource : other.twoWindingsTransformerCache.allResourcesGetter.get()) { + this.createTwoWindingsTransformer(twoWindingsTransformerResource); + } + for (var threeWindingsTransformerResource : other.threeWindingsTransformerCache.allResourcesGetter.get()) { + this.createThreeWindingsTransformer(threeWindingsTransformerResource); + } + for (var lineResource : other.lineCache.allResourcesGetter.get()) { + this.createLine(lineResource); + } + for (var tieLineResource : other.tieLineCache.allResourcesGetter.get()) { + this.createTieLine(tieLineResource); + } + for (var hvdcResource : other.hvdcLineCache.allResourcesGetter.get()) { + this.createHvdcLine(hvdcResource); + } + for (var danglingLineResources : other.danglingLineCache.allResourcesGetter.get()) { + this.createDanglingLine(danglingLineResources); + } + for (var configuredBusResource : other.configuredBusCache.allResourcesGetter.get()) { + this.createConfiguredBus(configuredBusResource); + } + + } } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkStoreClient.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkStoreClient.java index a904d81f7..dd327c295 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkStoreClient.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkStoreClient.java @@ -8,6 +8,7 @@ package com.powsybl.network.store.iidm.impl; import com.powsybl.network.store.model.*; +import org.openxmlformats.schemas.drawingml.x2006.chart.STHoleSizeUByte; import java.util.List; import java.util.Optional; @@ -276,7 +277,6 @@ public interface NetworkStoreClient { void removeConfiguredBuses(UUID networkUuid, int variantNum, List busesId); // Tie Lines - void createTieLines(UUID networkUuid, List> tieLineResources); List> getTieLines(UUID networkUuid, int variantNum); @@ -287,6 +287,16 @@ public interface NetworkStoreClient { void updateTieLines(UUID networkUuid, List> tieLineResources, AttributeFilter attributeFilter); + void createSubnetworks(UUID networkUuid, List> subNetworkAttributes); + + List> getSubnetworks(UUID networkUuid, int variantNum); + + Optional> getSubnetwork(UUID networkUuid, int variantNum, String subnetworkId); + + void removeSubnetworks(UUID networkUuid, int variantNum, List subnetworkIds); + + void updateSubnetworks(UUID networkUuid, List> subnetworkResources, AttributeFilter attributeFilter); + Optional> getIdentifiable(UUID networkUuid, int variantNum, String id); void flush(UUID networkUuid); diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/OfflineNetworkStoreClient.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/OfflineNetworkStoreClient.java index 441ea79b2..f85c20edb 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/OfflineNetworkStoreClient.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/OfflineNetworkStoreClient.java @@ -594,6 +594,28 @@ public void updateTieLines(UUID networkUuid, List> t // nothing to do } + @Override + public void createSubnetworks(UUID networkUuid, List> subNetworkAttributes) { + } + + @Override + public List> getSubnetworks(UUID networkUuid, int variantNum) { + return Collections.emptyList(); + } + + @Override + public Optional> getSubnetwork(UUID networkUuid, int variantNum, String subnetworkId) { + return Optional.empty(); + } + + @Override + public void removeSubnetworks(UUID networkUuid, int variantNum, List subnetworkIds) { + } + + @Override + public void updateSubnetworks(UUID networkUuid, List> subnetworkResources, AttributeFilter attributeFilter) { + } + @Override public Optional> getIdentifiable(UUID networkUuid, int variantNum, String id) { return Optional.empty(); diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ShuntCompensatorAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ShuntCompensatorAdderImpl.java index 79ac75bbf..6d9f32ef7 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ShuntCompensatorAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ShuntCompensatorAdderImpl.java @@ -144,8 +144,8 @@ public ShuntCompensatorAdder add() { } } - ShuntCompensatorAdderImpl(Resource voltageLevelResource, NetworkObjectIndex index) { - super(voltageLevelResource, index); + ShuntCompensatorAdderImpl(Resource voltageLevelResource, NetworkObjectIndex index, String parentNetwork) { + super(voltageLevelResource, index, parentNetwork); } @Override @@ -213,6 +213,7 @@ public ShuntCompensator add() { Resource resource = Resource.shuntCompensatorBuilder() .id(id) .variantNum(index.getWorkingVariantNum()) + .parentNetwork(getParentNetwork()) .attributes(ShuntCompensatorAttributes.builder() .voltageLevelId(getVoltageLevelResource().getId()) .name(getName()) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/StaticVarCompensatorAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/StaticVarCompensatorAdderImpl.java index 667947847..8360da198 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/StaticVarCompensatorAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/StaticVarCompensatorAdderImpl.java @@ -26,8 +26,8 @@ public class StaticVarCompensatorAdderImpl extends AbstractInjectionAdder voltageLevelResource, NetworkObjectIndex index) { - super(voltageLevelResource, index); + StaticVarCompensatorAdderImpl(Resource voltageLevelResource, NetworkObjectIndex index, String parentNetwork) { + super(voltageLevelResource, index, parentNetwork); } @Override @@ -80,6 +80,7 @@ public StaticVarCompensator add() { Resource resource = Resource.staticVarCompensatorBuilder() .id(id) .variantNum(index.getWorkingVariantNum()) + .parentNetwork(getParentNetwork()) .attributes(StaticVarCompensatorAttributes.builder() .voltageLevelId(getVoltageLevelResource().getId()) .name(getName()) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SubnetworkImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SubnetworkImpl.java new file mode 100644 index 000000000..9cafb5a92 --- /dev/null +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SubnetworkImpl.java @@ -0,0 +1,794 @@ +package com.powsybl.network.store.iidm.impl; + +import com.google.common.collect.ImmutableList; +import com.google.common.primitives.Ints; +import com.powsybl.commons.PowsyblException; +import com.powsybl.commons.extensions.Extension; +import com.powsybl.iidm.network.*; +import com.powsybl.network.store.model.*; + +import java.util.*; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class SubnetworkImpl extends AbstractNetwork { + + SubnetworkImpl(NetworkObjectIndex index, Resource resource) { + super(index, resource); + } + + private boolean contains(Identifiable identifiable) { + AbstractIdentifiableImpl abstractIdentifiable = (AbstractIdentifiableImpl) identifiable; + if (abstractIdentifiable.getType().equals(IdentifiableType.NETWORK) && abstractIdentifiable != this) { + return false; + } + if (abstractIdentifiable.getResource().getParentNetwork() == null) { + System.out.println("Null parent"); + } + return abstractIdentifiable == this || + abstractIdentifiable != null && abstractIdentifiable.getResource().getParentNetwork().equals(this.getId()); + } + + static SubnetworkImpl createSubnetwork(NetworkObjectIndex index, Resource resource) { + return new SubnetworkImpl(index, resource); + } + + @Override + public SubstationAdder newSubstation() { + return new SubstationAdderImpl(index, this.getId()); + } + + @Override + public Stream getSubstationStream() { + return getNetwork().getSubstationStream().filter(this::contains); + } + + @Override + public Substation getSubstation(String s) { + Substation substation = getNetwork().getSubstation(s); + return contains(substation) ? substation : null; + } + + @Override + public Iterable getVoltageLevels() { + return getVoltageLevelStream().toList(); + } + + @Override + public Stream getVoltageLevelStream() { + return index.getVoltageLevels().stream().filter(this::contains); + } + + @Override + public int getVoltageLevelCount() { + return (int)getVoltageLevelStream().count(); + } + + @Override + public VoltageLevel getVoltageLevel(String id) { + VoltageLevel voltageLevel = getNetwork().getVoltageLevel(id); + return contains(voltageLevel) ? voltageLevel : null; + } + + @Override + public VoltageLevelAdder newVoltageLevel() { + return new VoltageLevelAdderImpl(index, null, this.getId()); + } + + @Override + public LineAdder newLine() { + return new LineAdderImpl(index, this.getId()); + } + + @Override + public Iterable getLines() { + return getLineStream().toList(); + } + + @Override + public Stream getLineStream() { + return index.getLines().stream().filter(this::contains); + } + + @Override + public int getLineCount() { + return (int) getLineStream().count(); + } + + @Override + public Line getLine(String id) { + Line line = getNetwork().getLine(id); + return contains(line) ? line : null; + } + + @Override + public Iterable getTieLines() { + return getTieLineStream().toList(); + } + + @Override + public Stream getTieLineStream() { + return index.getTieLines().stream().filter(this::contains); + } + + @Override + public int getTieLineCount() { + return (int) getTieLineStream().count(); + } + + @Override + public TieLine getTieLine(String id) { + Optional tieLine = index.getTieLine(id); + if (tieLine.isPresent() && contains(tieLine.get())) { + return tieLine.get(); + } else { + return null; + } + } + + @Override + public TieLineAdder newTieLine() { + return new TieLineAdderImpl(index, this.getId()); + } + + @Override + public List getBranches() { + return ImmutableList.builder() + .addAll(getLines()) + .addAll(getTwoWindingsTransformers()) + .addAll(getTieLines()) + .build(); + } + + @Override + public Branch getBranch(String id) { + Branch b = index.getBranch(id); + if (b != null && contains(b)) { + return b; + } else { + return null; + } + } + + @Override + public Stream getBranchStream() { + return getBranches().stream(); + } + + @Override + public int getBranchCount() { + return (int) getBranchStream().count(); + } + + @Override + public Iterable getTwoWindingsTransformers() { + return getTwoWindingsTransformerStream().toList(); + } + + @Override + public Stream getTwoWindingsTransformerStream() { + return index.getTwoWindingsTransformers().stream().filter(this::contains); + } + + @Override + public int getTwoWindingsTransformerCount() { + return (int) getTwoWindingsTransformerStream().count(); + } + + @Override + public TwoWindingsTransformer getTwoWindingsTransformer(String id) { + Optional transformer = index.getTwoWindingsTransformer(id); + if (transformer.isPresent() && contains(transformer.get())) { + return transformer.get(); + } else { + return null; + } + } + + @Override + public Iterable getThreeWindingsTransformers() { + return getThreeWindingsTransformerStream().toList(); + } + + @Override + public Stream getThreeWindingsTransformerStream() { + return index.getThreeWindingsTransformers().stream().filter(this::contains); + } + + @Override + public int getThreeWindingsTransformerCount() { + return (int) getThreeWindingsTransformerStream().count(); + } + + @Override + public ThreeWindingsTransformer getThreeWindingsTransformer(String id) { + Optional transformer = index.getThreeWindingsTransformer(id); + if (transformer.isPresent() && contains(transformer.get())) { + return transformer.get(); + } else { + return null; + } + } + + @Override + public Iterable getGenerators() { + return getGeneratorStream().toList(); + } + + @Override + public Stream getGeneratorStream() { + return index.getGenerators().stream().filter(this::contains); + } + + @Override + public int getGeneratorCount() { + return (int) getGeneratorStream().count(); + } + + @Override + public Generator getGenerator(String id) { + return index.getGenerator(id).filter(this::contains).orElse(null); + } + + @Override + public Iterable getBatteries() { + return getBatteryStream().toList(); + } + + @Override + public Stream getBatteryStream() { + return index.getBatteries().stream().filter(this::contains); + } + + @Override + public int getBatteryCount() { + return (int) getBatteryStream().count(); + } + + @Override + public Battery getBattery(String id) { + return index.getBattery(id).filter(this::contains).orElse(null); + } + + @Override + public Iterable getLoads() { + return getLoadStream().toList(); + } + + @Override + public Stream getLoadStream() { + return index.getLoads().stream().filter(this::contains); + } + + @Override + public int getLoadCount() { + return (int) getLoadStream().count(); + } + + @Override + public Load getLoad(String id) { + return index.getLoad(id).filter(this::contains).orElse(null); + } + + @Override + public Iterable getShuntCompensators() { + return getShuntCompensatorStream().toList(); + } + + @Override + public Stream getShuntCompensatorStream() { + return index.getShuntCompensators().stream().filter(this::contains); + } + + @Override + public int getShuntCompensatorCount() { + return (int) getShuntCompensatorStream().count(); + } + + @Override + public ShuntCompensator getShuntCompensator(String id) { + return index.getShuntCompensator(id).filter(this::contains).orElse(null); + } + + @Override + public Iterable getDanglingLines(DanglingLineFilter danglingLineFilter) { + return getDanglingLineStream(danglingLineFilter).toList(); + } + + @Override + public Stream getDanglingLineStream(DanglingLineFilter danglingLineFilter) { + return index.getDanglingLines().stream().filter(danglingLineFilter.getPredicate()).filter(this::contains); + } + + @Override + public int getDanglingLineCount() { + return (int) index.getDanglingLines().stream().filter(this::contains).count(); + } + + @Override + public DanglingLine getDanglingLine(String id) { + return index.getDanglingLine(id).filter(this::contains).orElse(null); + } + + @Override + public Iterable getStaticVarCompensators() { + return getStaticVarCompensatorStream().toList(); + } + + @Override + public Stream getStaticVarCompensatorStream() { + return index.getStaticVarCompensators().stream().filter(this::contains); + } + + @Override + public int getStaticVarCompensatorCount() { + return (int) getStaticVarCompensatorStream().count(); + } + + @Override + public StaticVarCompensator getStaticVarCompensator(String id) { + return index.getStaticVarCompensator(id).filter(this::contains).orElse(null); + } + + @Override + public Switch getSwitch(String id) { + return index.getSwitch(id).filter(this::contains).orElse(null); + } + + @Override + public Iterable getSwitches() { + return getSwitchStream().toList(); + } + + @Override + public Stream getSwitchStream() { + return index.getSwitches().stream().filter(this::contains); + } + + @Override + public int getSwitchCount() { + return (int) getSwitchStream().count(); + } + + @Override + public BusbarSection getBusbarSection(String id) { + return index.getBusbarSection(id).filter(this::contains).orElse(null); + } + + @Override + public Iterable getBusbarSections() { + return getBusbarSectionStream().toList(); + } + + @Override + public Stream getBusbarSectionStream() { + return index.getBusbarSections().stream().filter(this::contains); + } + + @Override + public int getBusbarSectionCount() { + return (int) getBusbarSectionStream().count(); + } + + @Override + public Iterable> getHvdcConverterStations() { + return getHvdcConverterStationStream().toList(); + } + + @Override + public Stream> getHvdcConverterStationStream() { + List> hvdcConverterStationsList = new ArrayList<>(); + hvdcConverterStationsList.addAll(index.getLccConverterStations()); + hvdcConverterStationsList.addAll(index.getVscConverterStations()); + return hvdcConverterStationsList.stream().filter(this::contains); + } + + @Override + public int getHvdcConverterStationCount() { + return (int) getHvdcConverterStationStream().count(); + } + + @Override + public HvdcConverterStation getHvdcConverterStation(String id) { + return index.getHvdcConverterStation(id).filter(this::contains).orElse(null); + } + + @Override + public Iterable getLccConverterStations() { + return getLccConverterStationStream().toList(); + } + + @Override + public Stream getLccConverterStationStream() { + return index.getLccConverterStations().stream().filter(this::contains); + } + + @Override + public int getLccConverterStationCount() { + return (int) getLccConverterStationStream().count(); + } + + @Override + public LccConverterStation getLccConverterStation(String id) { + return index.getLccConverterStation(id).filter(this::contains).orElse(null); + } + + @Override + public Iterable getVscConverterStations() { + return getVscConverterStationStream().toList(); + } + + @Override + public Stream getVscConverterStationStream() { + return index.getVscConverterStations().stream().filter(this::contains); + } + + @Override + public int getVscConverterStationCount() { + return (int) getVscConverterStationStream().count(); + } + + @Override + public VscConverterStation getVscConverterStation(String id) { + return index.getVscConverterStation(id).filter(this::contains).orElse(null); + } + + @Override + public Iterable getHvdcLines() { + return getHvdcLineStream().toList(); + } + + @Override + public Stream getHvdcLineStream() { + return index.getHvdcLines().stream().filter(this::contains); + } + + @Override + public int getHvdcLineCount() { + return (int) getHvdcLineStream().count(); + } + + @Override + public HvdcLine getHvdcLine(String id) { + return index.getHvdcLine(id).filter(this::contains).orElse(null); + } + + @Override + public HvdcLineAdder newHvdcLine() { + return new HvdcLineAdderImpl(index, this.getId()); + } + + @Override + public HvdcLine getHvdcLine(HvdcConverterStation converterStation) { + return getHvdcLineStream() + .filter(l -> l.getConverterStation1() == converterStation || l.getConverterStation2() == converterStation) + .findFirst() + .orElse(null); + } + + @Override + public Identifiable getIdentifiable(String id) { + Identifiable identifiable = index.getIdentifiable(id); + return contains(identifiable) ? identifiable : null; + } + + @Override + public Collection> getIdentifiables() { + return index.getIdentifiables().stream().filter(this::contains).toList(); + } + + @Override + public VoltageAngleLimitAdder newVoltageAngleLimit() { + return null; + } + + @Override + public Iterable getVoltageAngleLimits() { + return null; + } + + @Override + public Stream getVoltageAngleLimitsStream() { + return null; + } + + @Override + public VoltageAngleLimit getVoltageAngleLimit(String s) { + return null; + } + + @Override + public Network createSubnetwork(String s, String s1, String s2) { + return null; + } + + @Override + public Network detach() { + Set> boundaryElements = getBoundaryElements(); + checkDetachable(boundaryElements, true); + + long start = System.currentTimeMillis(); + + // Remove tie-lines + boundaryElements.stream() + .filter(DanglingLine.class::isInstance) + .map(DanglingLine.class::cast) + .map(DanglingLine::getTieLine) + .filter(Optional::isPresent) + .forEach(t -> t.get().remove(true)); + + // Create a new NetworkImpl and transfer the extensions to it + NetworkImpl detachedNetwork = (NetworkImpl) Network.create(getId(), getSourceFormat()); + + // TODO + //transferExtensions(this, detachedNetwork); + + // Memorize the network identifiables/voltageAngleLimits before moving references (to use them latter) + //Collection> identifiables = getIdentifiables(); + //Iterable vals = getVoltageAngleLimits(); + + // Move the substations and voltageLevels to the new network + //ref.setRef(new RefObj<>(null)); + for(Substation substation : getSubstations()) { + SubstationImpl impl = (SubstationImpl) substation; + Resource< SubstationAttributes> attributes = impl.getResource(); + detachedNetwork.index.createSubstation(attributes); + index.removeSubstation(attributes.getId()); + } + for(VoltageLevel vl : getVoltageLevels()) { + VoltageLevelImpl impl = (VoltageLevelImpl) vl; + Resource attributes = impl.getResource(); + detachedNetwork.index.createVoltageLevel(attributes); + index.removeVoltageLevel(attributes.getId()); + } + + // Remove all the identifiers from the parent's index and add them to the detached network's index + for (Identifiable i : index.getIdentifiables()) { + AbstractIdentifiableImpl impl = (AbstractIdentifiableImpl) i; + if (impl.getResource().getParentNetwork() != null && impl.getResource().getParentNetwork().equals(this.getId())) { + Resource resource = impl.getResource(); + index.removeResource(impl.getResource()); + detachedNetwork.index.createResource(resource); + } + } + /*for (VoltageAngleLimit val : vals) { + previousRootNetwork.getVoltageAngleLimitsIndex().remove(val.getId()); + detachedNetwork.getVoltageAngleLimitsIndex().put(val.getId(), val); + }*/ + + // Remove the old subnetwork from the subnetworks list of the current parent network + index.removeSubnetwork(this.getId()); + + // We don't control that regulating terminals and phase/ratio regulation terminals are in the same subnetwork + // as their network elements (generators, PSTs, ...). It is unlikely that those terminals and their elements + // are in different subnetworks but nothing prevents it. For now, we ignore this case, but it may be necessary + // to handle it later. If so, note that there are 2 possible cases: + // - the element is in the subnetwork to detach and its regulating or phase/ratio regulation terminal is not + // - the terminal is in the subnetwork, but not its element (this is trickier) + + //LOGGER.info("Detaching of {} done in {} ms", id, System.currentTimeMillis() - start); + return detachedNetwork; + } + + /** + * {@inheritDoc} + *

For now, only tie-lines can be split (HVDC lines may be supported later).

+ */ + @Override + public boolean isDetachable() { + return checkDetachable(getBoundaryElements(), false); + } + + private boolean checkDetachable(Set> boundaryElements, boolean throwsException) { + if (getNetwork().getVariantManager().getVariantIds().size() != 1) { + if (throwsException) { + throw new PowsyblException("Detaching from multi-variants network is not supported"); + } + return false; + } + if (boundaryElements.stream().anyMatch(Predicate.not(SubnetworkImpl::isSplittable))) { + if (throwsException) { + throw new PowsyblException("Un-splittable boundary elements prevent the subnetwork to be detached: " + + boundaryElements.stream().filter(Predicate.not(SubnetworkImpl::isSplittable)).map(Identifiable::getId).collect(Collectors.joining(", "))); + } + return false; + } + // TODO implement when voltage angle limit are there + /*if (getNetwork().getVoltageAngleLimitsStream().anyMatch(this::isBoundary)) { + if (throwsException) { + throw new PowsyblException("VoltageAngleLimits prevent the subnetwork to be detached: " + + getNetwork().getVoltageAngleLimitsStream().filter(this::isBoundary).map(VoltageAngleLimit::getId).collect(Collectors.joining(", "))); + } + return false; + }*/ + return true; + } + + private static boolean isSplittable(Identifiable identifiable) { + return identifiable.getType() == IdentifiableType.DANGLING_LINE; + } + + @Override + public Set> getBoundaryElements() { + Stream lines = getNetwork().getLineStream().filter(i -> i.getParentNetwork() == getNetwork()); + Stream danglingLineStream = getDanglingLineStream(); + Stream hvdcLineStream = getNetwork().getHvdcLineStream().filter(i -> i.getParentNetwork() == getNetwork()); + + return Stream.of(lines, danglingLineStream, hvdcLineStream) + .flatMap(Function.identity()) + .map(o -> (Identifiable) o) + .filter(this::isBoundaryElement) + .collect(Collectors.toSet()); + } + + @Override + public boolean isBoundaryElement(Identifiable identifiable) { + return switch (identifiable.getType()) { + case LINE, TIE_LINE -> isBoundary((Branch) identifiable); + case HVDC_LINE -> isBoundary((HvdcLine) identifiable); + case DANGLING_LINE -> isBoundary((DanglingLine) identifiable); + default -> false; + }; + } + + private boolean isBoundary(Branch branch) { + return isBoundary(branch.getTerminal1(), branch.getTerminal2()); + } + + private boolean isBoundary(HvdcLine hvdcLine) { + return isBoundary(hvdcLine.getConverterStation1().getTerminal(), + hvdcLine.getConverterStation2().getTerminal()); + } + + private boolean isBoundary(DanglingLine danglingLine) { + return danglingLine.getTieLine() + .map(this::isBoundary) + .orElse(true); + } + + private boolean isBoundary(VoltageAngleLimit val) { + return isBoundary(val.getTerminalFrom(), val.getTerminalTo()); + } + + private boolean isBoundary(Terminal terminal1, Terminal terminal2) { + boolean containsVoltageLevel1 = contains(terminal1.getVoltageLevel()); + boolean containsVoltageLevel2 = contains(terminal2.getVoltageLevel()); + return containsVoltageLevel1 && !containsVoltageLevel2 || + !containsVoltageLevel1 && containsVoltageLevel2; + } + + @Override + public ContainerType getContainerType() { + return null; + } + + @Override + public boolean hasProperty() { + return false; + } + + @Override + public boolean hasProperty(String s) { + return false; + } + + @Override + public String getProperty(String s) { + return null; + } + + @Override + public String getProperty(String s, String s1) { + return null; + } + + @Override + public String setProperty(String s, String s1) { + return null; + } + + @Override + public boolean removeProperty(String s) { + return false; + } + + @Override + public Set getPropertyNames() { + return null; + } + + @Override + public > void addExtension(Class aClass, E e) { + + } + + @Override + public > E getExtension(Class aClass) { + return null; + } + + @Override + public > E getExtensionByName(String s) { + return null; + } + + @Override + public > boolean removeExtension(Class aClass) { + return false; + } + + @Override + public > Collection getExtensions() { + return null; + } + + @Override + public String getMessageHeader() { + return null; + } + + @Override + public void addListener(NetworkListener listener) { + throw new PowsyblException("Listeners are not managed at subnetwork level." + + " Add this listener to the parent network '" + getNetwork().getId() + "'"); + } + + @Override + public void removeListener(NetworkListener listener) { + throw new PowsyblException("Listeners are not managed at subnetwork level." + + " Remove this listener to the parent network '" + getNetwork().getId() + "'"); + } + + @Override + public VariantManager getVariantManager() { + return getParentNetwork().getVariantManager(); + } + + @Override + public Set getCountries() { + return getCountryStream().collect(Collectors.toSet()); + } + + @Override + public int getCountryCount() { + return (int) getCountryStream().count(); + } + + private Stream getCountryStream() { + return getSubstationStream() + .map(s -> s.getCountry().orElse(null)) + .filter(Objects::nonNull); + } + + @Override + public Stream getConnectableStream(Class clazz) { + return index.getIdentifiables().stream().filter(clazz::isInstance).filter(this::contains).map(clazz::cast); + } + + @Override + public Iterable getConnectables(Class clazz) { + return getConnectableStream(clazz).collect(Collectors.toList()); + } + + @Override + public int getConnectableCount(Class clazz) { + return Ints.checkedCast(getConnectableStream(clazz).count()); + } + + @Override + public Iterable getConnectables() { + return getConnectables(Connectable.class); + } + + @Override + public Stream getConnectableStream() { + return getConnectableStream(Connectable.class); + } + + @Override + public int getConnectableCount() { + return Ints.checkedCast(getConnectableStream().count()); + } +} diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SubstationAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SubstationAdderImpl.java index 526394b8a..09881c517 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SubstationAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SubstationAdderImpl.java @@ -28,7 +28,11 @@ class SubstationAdderImpl extends AbstractIdentifiableAdder private final Set geographicalTags = new LinkedHashSet<>(); SubstationAdderImpl(NetworkObjectIndex index) { - super(index); + super(index, index.getNetwork().getId()); + } + + SubstationAdderImpl(NetworkObjectIndex index, String parentNetwork) { + super(index, parentNetwork); } @Override @@ -60,6 +64,7 @@ public Substation add() { Resource resource = Resource.substationBuilder() .id(id) + .parentNetwork(getParentNetwork()) .variantNum(index.getWorkingVariantNum()) .attributes(SubstationAttributes.builder() .name(getName()) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SubstationImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SubstationImpl.java index e8bc5c96a..368453ab4 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SubstationImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SubstationImpl.java @@ -78,7 +78,7 @@ public Substation setTso(String tso) { @Override public VoltageLevelAdder newVoltageLevel() { - return new VoltageLevelAdderImpl(index, getResource()); + return new VoltageLevelAdderImpl(index, getResource(), getResource().getParentNetwork()); } @Override diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SwitchAdderBusBreakerImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SwitchAdderBusBreakerImpl.java index 028fb577a..1d2222421 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SwitchAdderBusBreakerImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SwitchAdderBusBreakerImpl.java @@ -24,7 +24,7 @@ class SwitchAdderBusBreakerImpl extends AbstractSwitchAdder voltageLevelResource, NetworkObjectIndex index) { - super(voltageLevelResource, index); + super(voltageLevelResource, index, voltageLevelResource.getParentNetwork()); } @Override @@ -52,6 +52,7 @@ public Switch add() { Resource resource = Resource.switchBuilder() .id(id) .variantNum(index.getWorkingVariantNum()) + .parentNetwork(getParentNetwork()) .attributes(SwitchAttributes.builder() .voltageLevelId(getVoltageLevelResource().getId()) .name(getName()) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SwitchAdderNodeBreakerImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SwitchAdderNodeBreakerImpl.java index cbb8edb66..635133a74 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SwitchAdderNodeBreakerImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/SwitchAdderNodeBreakerImpl.java @@ -28,7 +28,7 @@ class SwitchAdderNodeBreakerImpl extends AbstractSwitchAdder voltageLevelResource, NetworkObjectIndex index, SwitchKind kind) { - super(voltageLevelResource, index); + super(voltageLevelResource, index, voltageLevelResource.getParentNetwork()); this.kind = kind; } @@ -77,6 +77,7 @@ public Switch add() { Resource resource = Resource.switchBuilder() .id(id) .variantNum(index.getWorkingVariantNum()) + .parentNetwork(getParentNetwork()) .attributes(SwitchAttributes.builder() .voltageLevelId(getVoltageLevelResource().getId()) .name(getName()) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalImpl.java index 49813ee9d..7da338cb2 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalImpl.java @@ -8,6 +8,7 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.iidm.network.*; +import com.powsybl.math.graph.TraversalType; import com.powsybl.math.graph.TraverseResult; import com.powsybl.network.store.model.*; import org.jgrapht.Graph; @@ -377,6 +378,11 @@ public void traverse(Terminal.TopologyTraverser traverser) { } } + @Override + public void traverse(TopologyTraverser topologyTraverser, TraversalType traversalType) { + throw new UnsupportedOperationException("TODO"); + } + boolean traverse(Terminal.TopologyTraverser traverser, Set traversedTerminals) { if (traversedTerminals.contains(this)) { return true; diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ThreeWindingsTransformerAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ThreeWindingsTransformerAdderImpl.java index 99b57facf..7183aaa20 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ThreeWindingsTransformerAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ThreeWindingsTransformerAdderImpl.java @@ -244,7 +244,7 @@ public String getMessageHeader() { private LegAttributes leg3; ThreeWindingsTransformerAdderImpl(NetworkObjectIndex index, SubstationImpl substation) { - super(index); + super(index, substation.getResource().getParentNetwork()); this.substation = substation; } @@ -315,6 +315,7 @@ public ThreeWindingsTransformer add() { Resource resource = Resource.threeWindingsTransformerBuilder() .id(id) .variantNum(index.getWorkingVariantNum()) + .parentNetwork(getParentNetwork()) .attributes(ThreeWindingsTransformerAttributes.builder() .name(getName()) .fictitious(isFictitious()) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TieLineAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TieLineAdderImpl.java index 2fa257829..4704b43de 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TieLineAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TieLineAdderImpl.java @@ -21,7 +21,11 @@ public class TieLineAdderImpl extends AbstractIdentifiableAdder resource = Resource.tieLineBuilder() .id(id) .variantNum(index.getWorkingVariantNum()) + .parentNetwork(getParentNetwork()) .attributes(TieLineAttributes.builder() .danglingLine1Id(dl1.getId()) .danglingLine2Id(dl2.getId()) + .name(getName()) .build()).build(); getIndex().createTieLine(resource); TieLineImpl tieLine = new TieLineImpl(getIndex(), resource); diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TieLineImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TieLineImpl.java index 1ef6761fb..d5f86f3aa 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TieLineImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TieLineImpl.java @@ -27,8 +27,8 @@ public TieLineImpl(NetworkObjectIndex index, Resource resourc } @Override - public String getUcteXnodeCode() { - return Optional.ofNullable(getDanglingLine1().getUcteXnodeCode()).orElseGet(() -> getDanglingLine2().getUcteXnodeCode()); + public String getPairingKey() { + return Optional.ofNullable(getDanglingLine1().getPairingKey()).orElseGet(() -> getDanglingLine2().getPairingKey()); } @Override @@ -64,10 +64,20 @@ public DanglingLine getDanglingLine(String voltageLevelId) { @Override public void remove() { + remove(false); + } + + @Override + public void remove(boolean updateDanglingLines) { var resource = getResource(); index.notifyBeforeRemoval(this); + if (updateDanglingLines) { + updateDanglingLine(getDanglingLine1()); + updateDanglingLine(getDanglingLine2()); + } + getDanglingLine1().removeTieLine(); getDanglingLine2().removeTieLine(); index.removeTieLine(resource.getId()); @@ -75,6 +85,24 @@ public void remove() { index.notifyAfterRemoval(resource.getId()); } + private static void updateDanglingLine(DanglingLine danglingLine) { + // Only update if we have values + if (!Double.isNaN(danglingLine.getBoundary().getP())) { + danglingLine.setP0(-danglingLine.getBoundary().getP()); + if (danglingLine.getGeneration() != null) { + // We do not reset regulation if we only have computed a dc load flow + danglingLine.getGeneration().setTargetP(0.0); + } + } + if (!Double.isNaN(danglingLine.getBoundary().getQ())) { + danglingLine.setQ0(-danglingLine.getBoundary().getQ()); + if (danglingLine.getGeneration() != null) { + // If q values are available a complete ac load flow has been computed, we reset regulation + danglingLine.getGeneration().setTargetQ(0.0).setVoltageRegulationOn(false).setTargetV(Double.NaN); + } + } + } + @Override public double getR() { DanglingLine dl1 = getDanglingLine1(); diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TwoWindingsTransformerAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TwoWindingsTransformerAdderImpl.java index 790e16177..1d0868637 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TwoWindingsTransformerAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TwoWindingsTransformerAdderImpl.java @@ -33,7 +33,7 @@ class TwoWindingsTransformerAdderImpl extends AbstractBranchAdder resource = Resource.twoWindingsTransformerBuilder() .id(id) .variantNum(index.getWorkingVariantNum()) + .parentNetwork(getParentNetwork()) .attributes(TwoWindingsTransformerAttributes.builder() .voltageLevelId1(getVoltageLevelId1()) .voltageLevelId2(getVoltageLevelId2()) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VoltageLevelAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VoltageLevelAdderImpl.java index dfac4e11e..1b3321716 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VoltageLevelAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VoltageLevelAdderImpl.java @@ -33,10 +33,15 @@ class VoltageLevelAdderImpl extends AbstractIdentifiableAdder substationResource) { - super(index); + this(index, substationResource, index.getNetwork().getId()); + } + + VoltageLevelAdderImpl(NetworkObjectIndex index, Resource substationResource, String parentNetwork) { + super(index, parentNetwork); this.substationResource = substationResource; } + @Override public VoltageLevelAdder setNominalV(double nominalV) { this.nominalV = nominalV; @@ -77,6 +82,7 @@ public VoltageLevel add() { Resource voltageLevelResource = Resource.voltageLevelBuilder() .id(id) .variantNum(index.getWorkingVariantNum()) + .parentNetwork(getParentNetwork()) .attributes(VoltageLevelAttributes.builder() .substationId(substationResource != null ? substationResource.getId() : null) .name(getName()) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VoltageLevelImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VoltageLevelImpl.java index c50a64e97..fe4e68f94 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VoltageLevelImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VoltageLevelImpl.java @@ -176,7 +176,7 @@ public int getSwitchCount() { @Override public LoadAdder newLoad() { - return new LoadAdderImpl(getResource(), index); + return new LoadAdderImpl(getResource(), index, getResource().getParentNetwork()); } @Override @@ -196,7 +196,7 @@ public int getLoadCount() { @Override public GeneratorAdder newGenerator() { - return new GeneratorAdderImpl(getResource(), index); + return new GeneratorAdderImpl(getResource(), index, getResource().getParentNetwork()); } @Override @@ -216,7 +216,7 @@ public int getGeneratorCount() { @Override public BatteryAdder newBattery() { - return new BatteryAdderImpl(getResource(), index); + return new BatteryAdderImpl(getResource(), index, getResource().getParentNetwork()); } @Override @@ -236,7 +236,7 @@ public int getBatteryCount() { @Override public ShuntCompensatorAdder newShuntCompensator() { - return new ShuntCompensatorAdderImpl(getResource(), index); + return new ShuntCompensatorAdderImpl(getResource(), index, getResource().getParentNetwork()); } @Override @@ -256,7 +256,7 @@ public int getShuntCompensatorCount() { @Override public DanglingLineAdder newDanglingLine() { - return new DanglingLineAdderImpl(getResource(), index); + return new DanglingLineAdderImpl(getResource(), index, getResource().getParentNetwork()); } @Override @@ -286,7 +286,7 @@ public Stream getDanglingLineStream(DanglingLineFilter danglingLin @Override public VscConverterStationAdder newVscConverterStation() { - return new VscConverterStationAdderImpl(getResource(), index); + return new VscConverterStationAdderImpl(getResource(), index, getResource().getParentNetwork()); } @Override @@ -306,7 +306,7 @@ public int getVscConverterStationCount() { @Override public LccConverterStationAdder newLccConverterStation() { - return new LccConverterStationAdderImpl(getResource(), index); + return new LccConverterStationAdderImpl(getResource(), index, getResource().getParentNetwork()); } @Override @@ -326,7 +326,7 @@ public int getLccConverterStationCount() { @Override public StaticVarCompensatorAdder newStaticVarCompensator() { - return new StaticVarCompensatorAdderImpl(getResource(), index); + return new StaticVarCompensatorAdderImpl(getResource(), index, getResource().getParentNetwork()); } @Override diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VscConverterStationAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VscConverterStationAdderImpl.java index 1acd59222..6d0a30b39 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VscConverterStationAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VscConverterStationAdderImpl.java @@ -23,8 +23,8 @@ public class VscConverterStationAdderImpl extends AbstractHvdcConverterStationAd private double voltageSetPoint = Double.NaN; - VscConverterStationAdderImpl(Resource voltageLevelResource, NetworkObjectIndex index) { - super(voltageLevelResource, index); + VscConverterStationAdderImpl(Resource voltageLevelResource, NetworkObjectIndex index, String parentNetwork) { + super(voltageLevelResource, index, parentNetwork); } @Override @@ -54,6 +54,7 @@ public VscConverterStation add() { Resource resource = Resource.vscConverterStationBuilder() .id(id) .variantNum(index.getWorkingVariantNum()) + .parentNetwork(getParentNetwork()) .attributes(VscConverterStationAttributes.builder() .voltageLevelId(getVoltageLevelResource().getId()) .name(getName()) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/CgmesSshMetadataAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/CgmesSshMetadataAdderImpl.java index dcb9ce541..f919ba85a 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/CgmesSshMetadataAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/CgmesSshMetadataAdderImpl.java @@ -22,6 +22,7 @@ */ public class CgmesSshMetadataAdderImpl extends AbstractExtensionAdder implements CgmesSshMetadataAdder { + private String id; private String description; private int sshVersion; @@ -34,6 +35,12 @@ public CgmesSshMetadataAdderImpl(Network extendable) { super(extendable); } + @Override + public CgmesSshMetadataAdder setId(String id) { + this.id = id; + return this; + } + @Override protected CgmesSshMetadata createExtension(Network network) { if (description == null) { diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/ConfiguredBusBugTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/ConfiguredBusBugTest.java index 306ec369b..c7d1feb44 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/ConfiguredBusBugTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/ConfiguredBusBugTest.java @@ -28,7 +28,7 @@ public void test() { Network network = EurostagTutorialExample1Factory.create(new NetworkFactoryImpl()); List ids = network.getIdentifiables().stream().map(Identifiable::getId).collect(Collectors.toList()); assertEquals(List.of("P1", "P2", "VLGEN", "VLHV1", "VLHV2", "VLLOAD", "GEN", "LOAD", "NGEN_NHV1", "NHV2_NLOAD", - "NHV1_NHV2_1", "NHV1_NHV2_2", "NGEN", "NHV1", "NHV2", "NLOAD"), ids); + "NHV1_NHV2_1", "NHV1_NHV2_2", "NGEN", "NHV1", "NHV2", "NLOAD", "sim1"), ids); assertNotNull(network.getIdentifiable("NGEN")); ids = network.getIdentifiables().stream().filter(i -> i instanceof Bus).map(Identifiable::getId).collect(Collectors.toList()); diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/CreateNetworksUtil.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/CreateNetworksUtil.java index a401dbe9e..8dbceba7f 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/CreateNetworksUtil.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/CreateNetworksUtil.java @@ -287,7 +287,7 @@ private static Network createNetwokWithMultipleEquipments(TopologyKind topologyK .setX(44) .setG(89) .setB(11) - .setUcteXnodeCode("UCTE_DL1") + .setPairingKey("UCTE_DL1") .newGeneration() .setTargetP(100) .setTargetQ(200) @@ -329,7 +329,7 @@ private static Network createNetwokWithMultipleEquipments(TopologyKind topologyK .setX(44) .setG(89) .setB(11) - .setUcteXnodeCode("UCTE_DL2") + .setPairingKey("UCTE_DL2") .newGeneration() .setTargetP(100) .setTargetQ(200) @@ -594,32 +594,36 @@ static Network createEmptyNodeBreakerNetwork() { } static Network createBusBreakerNetworkWithOneBus() { - Network network = Network.create("test", "test"); + return createBusBreakerNetworkWithOneBus(""); + } + + static Network createBusBreakerNetworkWithOneBus(String networkSuffix) { + Network network = Network.create("test" + networkSuffix, "test"); Substation s = network.newSubstation() - .setId("S") + .setId("S" + networkSuffix) .setCountry(Country.FR) .setCountry(Country.FR) - .setTso("TSO1") - .setGeographicalTags("region1") + .setTso("TSO1" + networkSuffix) + .setGeographicalTags("region1" + networkSuffix) .add(); VoltageLevel vl1 = s.newVoltageLevel() - .setId("VL1") + .setId("VL1" + networkSuffix) .setNominalV(400.0) .setTopologyKind(TopologyKind.BUS_BREAKER) .add(); vl1.getBusBreakerView().newBus() - .setId("B1") + .setId("B1" + networkSuffix) .add(); vl1.newLoad() - .setId("LD1") - .setConnectableBus("B1") - .setBus("B1") + .setId("LD1" + networkSuffix) + .setConnectableBus("B1" + networkSuffix) + .setBus("B1" + networkSuffix) .setP0(1.0) .setQ0(1.0) .add(); vl1.newGenerator() - .setId("G") - .setBus("B1") + .setId("G" + networkSuffix) + .setBus("B1" + networkSuffix) .setMaxP(100.0) .setMinP(50.0) .setTargetP(100.0) @@ -631,21 +635,24 @@ static Network createBusBreakerNetworkWithOneBus() { } static Network createBusBreakerNetworkWithTwoBuses() { - Network network = createBusBreakerNetworkWithOneBus(); - VoltageLevel vl1 = network.getVoltageLevel("VL1"); - network.getVoltageLevel("VL1").getBusBreakerView().newBus() - .setId("B2") + return createBusBreakerNetworkWithTwoBuses(""); + } + static Network createBusBreakerNetworkWithTwoBuses(String networkSuffix) { + Network network = createBusBreakerNetworkWithOneBus(networkSuffix); + VoltageLevel vl1 = network.getVoltageLevel("VL1" + networkSuffix); + network.getVoltageLevel("VL1" + networkSuffix).getBusBreakerView().newBus() + .setId("B2" + networkSuffix) .add(); vl1.getBusBreakerView().newSwitch() - .setId("BR1") - .setBus1("B2") - .setBus2("B1") + .setId("BR1" + networkSuffix) + .setBus1("B2" + networkSuffix) + .setBus2("B1" + networkSuffix) .setOpen(false) .add(); vl1.newLoad() - .setId("LD2") - .setConnectableBus("B2") - .setBus("B2") + .setId("LD2" + networkSuffix) + .setConnectableBus("B2" + networkSuffix) + .setBus("B2" + networkSuffix) .setP0(1.0) .setQ0(1.0) .add(); @@ -653,22 +660,22 @@ static Network createBusBreakerNetworkWithTwoBuses() { return network; } - static Network createBusBreakerNetworkWithMultiBuses() { - Network network = createBusBreakerNetworkWithTwoBuses(); - VoltageLevel vl1 = network.getVoltageLevel("VL1"); - network.getVoltageLevel("VL1").getBusBreakerView().newBus() - .setId("B3") + static Network createBusBreakerNetworkWithMultiBuses(String networkSuffix) { + Network network = createBusBreakerNetworkWithTwoBuses(networkSuffix); + VoltageLevel vl1 = network.getVoltageLevel("VL1" + networkSuffix); + network.getVoltageLevel("VL1" + networkSuffix).getBusBreakerView().newBus() + .setId("B3" + networkSuffix) .add(); vl1.getBusBreakerView().newSwitch() - .setId("BR2") - .setBus1("B3") - .setBus2("B2") + .setId("BR2" + networkSuffix) + .setBus1("B3" + networkSuffix) + .setBus2("B2" + networkSuffix) .setOpen(false) .add(); vl1.newLoad() - .setId("LD3") - .setConnectableBus("B3") - .setBus("B3") + .setId("LD3" + networkSuffix) + .setConnectableBus("B3" + networkSuffix) + .setBus("B3" + networkSuffix) .setP0(1.0) .setQ0(1.0) .add(); @@ -676,8 +683,12 @@ static Network createBusBreakerNetworkWithMultiBuses() { return network; } + static Network createBusBreakerNetworkWithMultiBuses() { + return createBusBreakerNetworkWithMultiBuses(""); + } + static Network createBusBreakerNetworkWithLine() { - Network network = createBusBreakerNetworkWithMultiBuses(); + Network network = createBusBreakerNetworkWithMultiBuses(""); Substation s = network.getSubstation("S"); VoltageLevel vl2 = s.newVoltageLevel() @@ -715,6 +726,45 @@ static Network createBusBreakerNetworkWithLine() { return network; } + static Network createBusBreakerNetworkWithLine(String networkSuffix) { + Network network = createBusBreakerNetworkWithMultiBuses(networkSuffix); + Substation s = network.getSubstation("S" + networkSuffix); + + VoltageLevel vl2 = s.newVoltageLevel() + .setId("VL2" + networkSuffix) + .setNominalV(400.0) + .setTopologyKind(TopologyKind.BUS_BREAKER) + .add(); + vl2.getBusBreakerView().newBus() + .setId("B21" + networkSuffix) + .add(); + vl2.newGenerator() + .setId("G2" + networkSuffix) + .setBus("B21" + networkSuffix) + .setMaxP(100.0) + .setMinP(50.0) + .setTargetP(100.0) + .setTargetV(400.0) + .setVoltageRegulatorOn(true) + .add(); + + network.newLine() + .setId("L1" + networkSuffix) + .setVoltageLevel1("VL1" + networkSuffix) + .setBus1("B1" + networkSuffix) + .setVoltageLevel2("VL2" + networkSuffix) + .setBus2("B21" + networkSuffix) + .setR(1.0) + .setX(1.0) + .setG1(0.0) + .setB1(0.0) + .setG2(0.0) + .setB2(0.0) + .add(); + + return network; + } + static Network createNodeBreakerNetworkWithTwoVoltageLevelsAndBusBarSections() { Network network = Network.create("test", "test"); Substation s1 = network.newSubstation() diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/LineTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/LineTest.java index 7748a7c64..794c100f6 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/LineTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/LineTest.java @@ -152,7 +152,7 @@ public void testTieLine() { Network network = Importer.find("CGMES") .importData(CgmesConformity1Catalog.microGridBaseCaseAssembled().dataSource(), new NetworkFactoryImpl(), null); TieLine tieLine = network.getTieLine("b18cd1aa-7808-49b9-a7cf-605eaf07b006 + e8acf6b6-99cb-45ad-b8dc-16c7866a4ddc"); - assertEquals("TN_Border_GY11", tieLine.getUcteXnodeCode()); + assertEquals("TN_Border_GY11", tieLine.getPairingKey()); DanglingLine dl1 = tieLine.getDanglingLine1(); DanglingLine dl2 = tieLine.getDanglingLine2(); assertNotNull(dl1); @@ -180,7 +180,7 @@ public void testDanglingLines() { Network network = Importer.find("CGMES") .importData(CgmesConformity1Catalog.microGridBaseCaseAssembled().dataSource(), new NetworkFactoryImpl(), null); TieLine tieLine = network.getTieLine("b18cd1aa-7808-49b9-a7cf-605eaf07b006 + e8acf6b6-99cb-45ad-b8dc-16c7866a4ddc"); - assertEquals("TN_Border_GY11", tieLine.getUcteXnodeCode()); + assertEquals("TN_Border_GY11", tieLine.getPairingKey()); assertEquals(10, network.getDanglingLineCount()); VoltageLevel vl1 = network.getVoltageLevel("469df5f7-058f-4451-a998-57a48e8a56fe"); @@ -218,7 +218,7 @@ public void testTieLineTerminals() { Network network = Importer.find("CGMES") .importData(CgmesConformity1Catalog.microGridBaseCaseAssembled().dataSource(), new NetworkFactoryImpl(), null); TieLine tieLine = network.getTieLine("b18cd1aa-7808-49b9-a7cf-605eaf07b006 + e8acf6b6-99cb-45ad-b8dc-16c7866a4ddc"); - assertEquals("TN_Border_GY11", tieLine.getUcteXnodeCode()); + assertEquals("TN_Border_GY11", tieLine.getPairingKey()); DanglingLine dl1 = tieLine.getDanglingLine1(); DanglingLine dl2 = tieLine.getDanglingLine2(); diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/NetworkTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/NetworkTest.java index 21e172445..9a481a938 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/NetworkTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/NetworkTest.java @@ -9,6 +9,7 @@ import com.google.common.collect.Iterables; import com.powsybl.iidm.network.Country; import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.Substation; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -58,4 +59,50 @@ public void testNodeBreakerComponent() { assertNotNull(network.getBusView().getBus("VL1_0")); assertNotNull(network.getBusView().getBus("VL2_0")); } + + @Test + public void testSubnetwork() { + Network network = CreateNetworksUtil.createNodeBreakerNetworkWithLine(); + network.createSubnetwork("subNetwork1", "subNetwork1", ""); + network.createSubnetwork("subNetwork2", "subNetwork2", ""); + Network subNetwork1 = network.getSubnetwork("subNetwork1"); + Substation s3 = subNetwork1.newSubstation() + .setId("S3") + .setCountry(Country.FR) + .add(); + Network subNetwork2 = network.getSubnetwork("subNetwork2"); + Substation s4 = subNetwork2.newSubstation() + .setId("S4") + .setCountry(Country.FR) + .add(); + assertEquals(4, network.getSubstationCount()); + assertEquals(1, subNetwork1.getSubstationCount()); + assertNotNull(subNetwork1.getSubstation("S3")); + assertEquals(1, subNetwork2.getSubstationCount()); + assertNotNull(subNetwork2.getSubstation("S4")); + } + + @Test + public void simpleMergeTest() { + + Network n1 = CreateNetworksUtil.createBusBreakerNetworkWithLine("_n1"); + Network n2 = CreateNetworksUtil.createBusBreakerNetworkWithLine("_n2"); + String n1Id = n1.getId(); + String n2Id = n2.getId(); + assertEquals(1, n1.getLineCount()); + assertEquals(1, n2.getLineCount()); + + Network mergedNetwork = Network.merge(n1, n2); + assertEquals(2, mergedNetwork.getLineCount()); + assertEquals(2, mergedNetwork.getSubnetworks().size()); + + Network subN1 = mergedNetwork.getSubnetwork(n1Id); + Network subN2 = mergedNetwork.getSubnetwork(n2Id); + assertEquals(1, subN1.getLineCount()); + assertEquals(1, subN2.getLineCount()); + + Network detachedN2 = subN2.detach(); + assertEquals(1, detachedN2.getLineCount()); + assertEquals(1, mergedNetwork.getSubnetworks().size()); + } } diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java index 1935d2f56..7e5737752 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java @@ -38,21 +38,11 @@ public void multipleDanglingLinesInMergedNetwork() { // FIXME } - @Override - public void testMergeSameId() { - // FIXME - } - @Override public void test() { // FIXME } - @Override - public void xnodeNonCompatible() { - // FIXME - } - @Override public void mergeThenCloneVariantBug() { // FIXME diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/SubnetworkCreationTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/SubnetworkCreationTest.java new file mode 100644 index 000000000..4c5a50fe4 --- /dev/null +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/SubnetworkCreationTest.java @@ -0,0 +1,10 @@ +package com.powsybl.network.store.iidm.impl.tck; + +import com.powsybl.iidm.network.tck.AbstractSubnetworksCreationTest; + +public class SubnetworkCreationTest extends AbstractSubnetworksCreationTest { + + @Override + public void testValidationWithSubnetworkChanges(String networkId) { + } +} diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/SubnetworkExplorationTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/SubnetworkExplorationTest.java new file mode 100644 index 000000000..cb25edc62 --- /dev/null +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/SubnetworkExplorationTest.java @@ -0,0 +1,10 @@ +package com.powsybl.network.store.iidm.impl.tck; + +import com.powsybl.iidm.network.tck.AbstractSubnetworksExplorationTest; +import org.junit.jupiter.api.Test; + +public class SubnetworkExplorationTest extends AbstractSubnetworksExplorationTest { + @Test + public void testExploreVariantManager() { + } +} diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/NetworkAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/NetworkAttributes.java index 0f6cc963b..0b695cc01 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/NetworkAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/NetworkAttributes.java @@ -29,6 +29,10 @@ public class NetworkAttributes extends AbstractAttributes implements Identifiabl @Schema(description = "Variant ID") private String variantId; + //TODO MAP subnetwork ICI + @Schema(description = "Subnetworks IDs") + private Set subNetworksIds; + @Schema(description = "Network name") private String name; diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/Resource.java b/network-store-model/src/main/java/com/powsybl/network/store/model/Resource.java index a1166c23f..4a9ebaeef 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/Resource.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/Resource.java @@ -43,6 +43,9 @@ public class Resource implements Validable { @Schema(description = "Resource ID", required = true) private String id; + @Schema(description = "Resource Parent Network id", required = true) + private String parentNetwork; + @Schema(description = "Variant number", required = true) private int variantNum; @@ -61,12 +64,12 @@ public String getMessageHeader() { public Resource filterAttributes(AttributeFilter filter) { Objects.requireNonNull(filter); - return new Resource<>(type, id, variantNum, filter, ((IdentifiableAttributes) attributes).filter(filter)); + return new Resource<>(type, id, parentNetwork, variantNum, filter, ((IdentifiableAttributes) attributes).filter(filter)); } - public static Resource create(ResourceType type, String id, int variantNum, AttributeFilter filter, T attributes) { + public static Resource create(ResourceType type, String id, String parentNetwork, int variantNum, AttributeFilter filter, T attributes) { Objects.requireNonNull(attributes); - Resource resource = new Resource<>(type, id, variantNum, filter, attributes); + Resource resource = new Resource<>(type, id, parentNetwork, variantNum, filter, attributes); attributes.setResource(resource); return resource; } @@ -77,6 +80,8 @@ public static class Builder { private String id; + private String parentNetwork; + private int variantNum = INITIAL_VARIANT_NUM; private T attributes; @@ -90,6 +95,11 @@ public Builder id(String id) { return this; } + public Builder parentNetwork(String parentNetwork) { + this.parentNetwork = parentNetwork; + return this; + } + public Builder variantNum(int variantNum) { this.variantNum = variantNum; return this; @@ -110,7 +120,7 @@ public Resource build() { if (attributes == null) { throw new IllegalStateException("attributes is not set"); } - Resource resource = new Resource<>(type, id, variantNum, null, attributes); + Resource resource = new Resource<>(type, id, parentNetwork, variantNum, null, attributes); attributes.setResource(resource); return resource; } @@ -120,6 +130,10 @@ public static Builder networkBuilder() { return new Builder<>(ResourceType.NETWORK); } + public static Builder subnetwokBuilder() { + return new Builder<>(ResourceType.SUBNETWORK); + } + public static Builder substationBuilder() { return new Builder<>(ResourceType.SUBSTATION); } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/ResourceDeserializer.java b/network-store-model/src/main/java/com/powsybl/network/store/model/ResourceDeserializer.java index 1a64162b2..b1fb1489a 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/ResourceDeserializer.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/ResourceDeserializer.java @@ -65,6 +65,8 @@ private static Class getTypeClass(ResourceType type, Attri return ConfiguredBusAttributes.class; case TIE_LINE: return TieLineAttributes.class; + case SUBNETWORK: + return SubnetworkAttributes.class; default: throw new IllegalStateException("Unknown resource type: " + type); } @@ -115,6 +117,7 @@ public Resource deserialize(JsonParser parser, DeserializationContext ctxt) thro int variantNum = -1; Attributes attributes = null; AttributeFilter filter = null; + String parentNetwork = null; JsonToken token; while ((token = parser.nextToken()) != null) { @@ -137,6 +140,8 @@ public Resource deserialize(JsonParser parser, DeserializationContext ctxt) thro parser.nextValue(); attributes = parser.readValueAs(getTypeClass(type, filter)); break; + case "parentNetwork": + parentNetwork = parser.nextTextValue(); default: break; } @@ -145,6 +150,6 @@ public Resource deserialize(JsonParser parser, DeserializationContext ctxt) thro } } - return Resource.create(type, id, variantNum, filter, attributes); + return Resource.create(type, id, parentNetwork, variantNum, filter, attributes); } } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/ResourceType.java b/network-store-model/src/main/java/com/powsybl/network/store/model/ResourceType.java index e72eb2a2a..0cb8003fa 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/ResourceType.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/ResourceType.java @@ -13,6 +13,7 @@ */ public enum ResourceType { NETWORK("Network"), + SUBNETWORK("Subnetwork"), SUBSTATION("Substation"), VOLTAGE_LEVEL("Voltage level"), LOAD("Load"), diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/SubnetworkAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/SubnetworkAttributes.java new file mode 100644 index 000000000..23b7d1467 --- /dev/null +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/SubnetworkAttributes.java @@ -0,0 +1,70 @@ +package com.powsybl.network.store.model; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +@Data +@ToString(callSuper = true) +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Schema(description = "Sub network attributes") +public class SubnetworkAttributes extends AbstractAttributes implements IdentifiableAttributes { + + @Schema(description = "Subnetwork UUID", required = true) + private UUID uuid; + + @Override + public String getName() { + return null; + } + + @Override + public void setName(String name) { + + } + + @Override + public Map getProperties() { + return null; + } + + @Override + public void setProperties(Map properties) { + + } + + @Override + public boolean isFictitious() { + return false; + } + + @Override + public void setFictitious(boolean fictitious) { + + } + + @Override + public Set getAliasesWithoutType() { + return null; + } + + @Override + public void setAliasesWithoutType(Set aliasesWithoutType) { + + } + + @Override + public Map getAliasByType() { + return null; + } + + @Override + public void setAliasByType(Map aliasByType) { + + } +} diff --git a/pom.xml b/pom.xml index 62636f6f4..fcc0d10a7 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ 2.7.3 3.9 - 2023.2.1 + 2023.3.0 1.5.0