Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add getBusCount() to network and voltage level busbreakerview for symetry #2660

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,14 @@ interface BusBreakerView {
*/
Stream<Bus> getBusStream();

/**
* Get the bus count.
* <p>
* Depends on the working variant.
* @see VariantManager
*/
int getBusCount();

/**
* Get all switches
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,15 @@ interface SwitchAdder extends IdentifiableAdder<Switch, SwitchAdder> {
*/
Stream<Bus> getBusStream();

/**
* Get the bus count.
* <p>
* Depends on the working variant if topology kind is NODE_BREAKER.
*
* @see VariantManager
*/
int getBusCount();

/**
* Get a bus.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,11 @@ public Stream<Bus> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public Stream<Bus> getBusStream() {
return getVoltageLevelStream().flatMap(vl -> vl.getBusBreakerView().getBusStream());
}

@Override
public int getBusCount() {
return getVoltageLevelStream().mapToInt(vl -> vl.getBusBreakerView().getBusCount()).sum();
}

@Override
public Iterable<Switch> getSwitches() {
return FluentIterable.from(getVoltageLevels())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ private Collection<CalculatedBus> getBuses() {
return id2bus.values();
}

private int getBusCount() {
return id2bus.size();
}

private CalculatedBus getBus(int node) {
return node2bus[node];
}
Expand Down Expand Up @@ -321,6 +325,11 @@ Collection<CalculatedBus> getBuses() {
return busCache.getBuses();
}

int getBusCount() {
updateCache();
return busCache.getBusCount();
}

CalculatedBus getBus(int node) {
updateCache();
return busCache.getBus(node);
Expand Down Expand Up @@ -985,6 +994,11 @@ public Stream<Bus> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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");
Expand All @@ -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());
Expand Down