diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Network.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Network.java index 901520ed455..ff05db300f1 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Network.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Network.java @@ -410,6 +410,14 @@ interface BusBreakerView { */ Stream getBusStream(); + /** + * Get the bus count. + *

+ * Depends on the working variant. + * @see VariantManager + */ + int getBusCount(); + /** * Get all switches */ diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/VoltageLevel.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/VoltageLevel.java index 9f84cb39ddf..faba9b21581 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/VoltageLevel.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/VoltageLevel.java @@ -707,6 +707,15 @@ interface SwitchAdder extends IdentifiableAdder { */ Stream getBusStream(); + /** + * Get the bus count. + *

+ * Depends on the working variant if topology kind is NODE_BREAKER. + * + * @see VariantManager + */ + int getBusCount(); + /** * Get a bus. *

diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BusBreakerVoltageLevel.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BusBreakerVoltageLevel.java index 789ac17090f..0af6f7cc03f 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BusBreakerVoltageLevel.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BusBreakerVoltageLevel.java @@ -599,6 +599,11 @@ public Stream getBusStream() { return graph.getVertexObjectStream().map(Function.identity()); } + @Override + public int getBusCount() { + return graph.getVertexCount(); + } + @Override public ConfiguredBus getBus(String id) { return BusBreakerVoltageLevel.this.getBus(id, false); diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NetworkImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NetworkImpl.java index f8295e00fe4..4d06cb1d6a6 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NetworkImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NetworkImpl.java @@ -66,6 +66,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 FluentIterable.from(getVoltageLevels()) diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NodeBreakerVoltageLevel.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NodeBreakerVoltageLevel.java index 7722bd81791..6969fa9cd2c 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NodeBreakerVoltageLevel.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NodeBreakerVoltageLevel.java @@ -229,6 +229,10 @@ private Collection getBuses() { return id2bus.values(); } + private int getBusCount() { + return id2bus.size(); + } + private CalculatedBus getBus(int node) { return node2bus[node]; } @@ -321,6 +325,11 @@ Collection getBuses() { return busCache.getBuses(); } + int getBusCount() { + updateCache(); + return busCache.getBusCount(); + } + CalculatedBus getBus(int node) { updateCache(); return busCache.getBus(node); @@ -985,6 +994,11 @@ public Stream getBusStream() { return variants.get().calculatedBusBreakerTopology.getBuses().stream().map(Function.identity()); } + @Override + public int getBusCount() { + return variants.get().calculatedBusBreakerTopology.getBusCount(); + } + @Override public CalculatedBus getBus(String id) { return variants.get().calculatedBusBreakerTopology.getBus(id, false); diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractNetworkTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractNetworkTest.java index 5bd01626418..312bd782297 100644 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractNetworkTest.java +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractNetworkTest.java @@ -58,6 +58,7 @@ public void testNetwork1() { assertEquals(1, Iterables.size(network.getSubstations())); assertEquals(1, Iterables.size(network.getSubstations(Country.FR, "TSO1", REGION1))); assertEquals(1, network.getSubstationCount()); + assertEquals(2, network.getBusBreakerView().getBusCount()); Substation substation1 = network.getSubstation(SUBSTATION12); assertNotNull(substation1); @@ -156,6 +157,7 @@ public void testNetwork1() { assertEquals(300.0, rcc1.getMinQ(500), 0.0); assertEquals(2, Iterables.size(voltageLevel1.getBusBreakerView().getBuses())); + assertEquals(2, voltageLevel1.getBusBreakerView().getBusCount()); Bus busCalc1 = voltageLevel1BusbarSection1.getTerminal().getBusBreakerView().getBus(); Bus busCalc2 = voltageLevel1BusbarSection2.getTerminal().getBusBreakerView().getBus(); assertSame(busCalc1, load1.getTerminal().getBusBreakerView().getBus()); @@ -268,6 +270,7 @@ public void testNetworkWithBattery() { assertEquals(2, network.getVoltageLevelCount()); assertEquals(2, Iterables.size(network.getBatteries())); assertEquals(2, network.getBatteryCount()); + assertEquals(2, network.getBusBreakerView().getBusCount()); // Substation A Substation substation1 = network.getSubstation("P1"); @@ -284,6 +287,7 @@ public void testNetworkWithBattery() { assertEquals(400.0, voltageLevel1.getNominalV(), 0.0); assertSame(substation1, voltageLevel1.getSubstation().orElse(null)); assertSame(TopologyKind.BUS_BREAKER, voltageLevel1.getTopologyKind()); + assertEquals(1, voltageLevel1.getBusBreakerView().getBusCount()); Bus bus1 = voltageLevel1.getBusBreakerView().getBus("NGEN"); assertEquals(3, bus1.getConnectedTerminalCount());