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

Allow creation of voltage topology in bus/breaker voltage levels #2447

Merged
merged 4 commits into from
Feb 6, 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 @@ -15,11 +15,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import static com.powsybl.iidm.modification.topology.ModificationReports.*;
import static com.powsybl.iidm.modification.topology.TopologyModificationUtils.createNBBreaker;
import static com.powsybl.iidm.modification.topology.TopologyModificationUtils.createNBDisconnector;
import static com.powsybl.iidm.modification.topology.ModificationReports.createdNewSymmetricalTopology;
import static com.powsybl.iidm.modification.topology.ModificationReports.notFoundVoltageLevelReport;
import static com.powsybl.iidm.modification.topology.TopologyModificationUtils.*;

/**
* Creates symmetrical matrix topology in a given voltage level,
Expand All @@ -36,27 +39,27 @@ public class CreateVoltageLevelTopology extends AbstractNetworkModification {

private final String voltageLevelId;

private final int lowBusbarIndex;
private final int busbarCount;
private final int lowBusOrBusbarIndex;
private final int alignedBusesOrBusbarCount;
private final int lowSectionIndex;
private final int sectionCount;

private final String busbarSectionPrefixId;
private final String busOrBusbarSectionPrefixId;
private final String switchPrefixId;

private final List<SwitchKind> switchKinds;

CreateVoltageLevelTopology(String voltageLevelId, int lowBusbarIndex, Integer busbarCount,
CreateVoltageLevelTopology(String voltageLevelId, int lowBusOrBusbarIndex, Integer alignedBusesOrBusbarCount,
int lowSectionIndex, Integer sectionCount,
String busbarSectionPrefixId, String switchPrefixId, List<SwitchKind> switchKinds) {
String busOrBusbarSectionPrefixId, String switchPrefixId, List<SwitchKind> switchKinds) {
this.voltageLevelId = Objects.requireNonNull(voltageLevelId, "Undefined voltage level ID");
this.lowBusbarIndex = checkCount(lowBusbarIndex, "low busbar index", 0);
this.busbarCount = checkCount(busbarCount, "busBar count", 1);
this.lowBusOrBusbarIndex = checkCount(lowBusOrBusbarIndex, "low busbar index", 0);
this.alignedBusesOrBusbarCount = checkCount(alignedBusesOrBusbarCount, "busBar count", 1);
this.lowSectionIndex = checkCount(lowSectionIndex, "low section index", 0);
this.sectionCount = checkCount(sectionCount, "section count", 1);
this.busbarSectionPrefixId = Objects.requireNonNull(busbarSectionPrefixId, "Undefined busbar section prefix ID");
this.busOrBusbarSectionPrefixId = Objects.requireNonNull(busOrBusbarSectionPrefixId, "Undefined busbar section prefix ID");
this.switchPrefixId = Objects.requireNonNull(switchPrefixId, "Undefined switch prefix ID");
this.switchKinds = checkSwitchKinds(switchKinds, sectionCount);
this.switchKinds = switchKinds;
}

private static int checkCount(Integer count, String type, int min) {
Expand Down Expand Up @@ -85,12 +88,12 @@ public String getVoltageLevelId() {
return voltageLevelId;
}

public int getLowBusbarIndex() {
return lowBusbarIndex;
public int getLowBusOrBusbarIndex() {
return lowBusOrBusbarIndex;
}

public int getBusbarCount() {
return busbarCount;
public int getAlignedBusesOrBusbarCount() {
return alignedBusesOrBusbarCount;
}

public int getLowSectionIndex() {
Expand All @@ -117,57 +120,79 @@ public void apply(Network network, boolean throwException, ComputationManager co
}
return;
}
// Check voltage level is NODE_BREAKER
TopologyKind topologyKind = voltageLevel.getTopologyKind();
if (topologyKind != TopologyKind.NODE_BREAKER) {
LOG.error("Voltage Level {} has an unsupported topology {}. Should be {}", voltageLevelId, topologyKind, TopologyKind.NODE_BREAKER);
unsupportedVoltageLevelTopologyKind(reporter, voltageLevelId, TopologyKind.NODE_BREAKER, topologyKind);
if (throwException) {
throw new PowsyblException(String.format("Voltage Level %s has an unsupported topology %s. Should be %s",
voltageLevelId, topologyKind.name(), TopologyKind.NODE_BREAKER.name()));
if (topologyKind == TopologyKind.BUS_BREAKER) {
if (!switchKinds.isEmpty()) {
LOG.warn("Voltage level {} is BUS_BREAKER. Switchkinds is ignored.", voltageLevelId);
}
return;
// Create buses
miovd marked this conversation as resolved.
Show resolved Hide resolved
createBuses(voltageLevel);
// Create switches between buses
createBusBreakerSwitches(voltageLevel);
} else {
// Check switch kinds
checkSwitchKinds(switchKinds, sectionCount);
// Create busbar sections
createBusbarSections(voltageLevel);
// Create switches
createSwitches(voltageLevel);
}
// Create busbar sections
createBusBarSections(voltageLevel);
// Create switches
createSwitches(voltageLevel);
LOG.info("New symmetrical topology in voltage level {}: creation of {} busbar(s) with {} section(s) each.", voltageLevelId, busbarCount, sectionCount);
createdNewSymmetricalTopology(reporter, voltageLevelId, busbarCount, sectionCount);
LOG.info("New symmetrical topology in voltage level {}: creation of {} bus(es) or busbar(s) with {} section(s) each.", voltageLevelId, alignedBusesOrBusbarCount, sectionCount);
createdNewSymmetricalTopology(reporter, voltageLevelId, alignedBusesOrBusbarCount, sectionCount);
}

private void createBusBarSections(VoltageLevel voltageLevel) {
private void createBusbarSections(VoltageLevel voltageLevel) {
int node = 0;
for (int sectionNum = lowSectionIndex; sectionNum < lowSectionIndex + sectionCount; sectionNum++) {
for (int busBarNum = lowBusbarIndex; busBarNum < lowBusbarIndex + busbarCount; busBarNum++) {
for (int busbarNum = lowBusOrBusbarIndex; busbarNum < lowBusOrBusbarIndex + alignedBusesOrBusbarCount; busbarNum++) {
BusbarSection bbs = voltageLevel.getNodeBreakerView().newBusbarSection()
.setId(busbarSectionPrefixId + SEPARATOR + busBarNum + SEPARATOR + sectionNum)
.setId(busOrBusbarSectionPrefixId + SEPARATOR + busbarNum + SEPARATOR + sectionNum)
.setNode(node)
.add();
bbs.newExtension(BusbarSectionPositionAdder.class)
.withBusbarIndex(busBarNum)
.withBusbarIndex(busbarNum)
.withSectionIndex(sectionNum)
.add();
node++;
}
}
}

private void createBuses(VoltageLevel voltageLevel) {
for (int sectionNum = lowSectionIndex; sectionNum < lowSectionIndex + sectionCount; sectionNum++) {
for (int busNum = lowBusOrBusbarIndex; busNum < lowBusOrBusbarIndex + alignedBusesOrBusbarCount; busNum++) {
voltageLevel.getBusBreakerView().newBus()
.setId(busOrBusbarSectionPrefixId + SEPARATOR + busNum + SEPARATOR + sectionNum)
.add();
}
}
}

private void createBusBreakerSwitches(VoltageLevel voltageLevel) {
for (int sectionNum = lowSectionIndex; sectionNum < lowSectionIndex + sectionCount - 1; sectionNum++) {
for (int busNum = lowBusOrBusbarIndex; busNum < lowSectionIndex + alignedBusesOrBusbarCount; busNum++) {
String bus1Id = busOrBusbarSectionPrefixId + SEPARATOR + busNum + SEPARATOR + sectionNum;
String bus2Id = busOrBusbarSectionPrefixId + SEPARATOR + busNum + SEPARATOR + (sectionNum + 1);
createBusBreakerSwitch(bus1Id, bus2Id, switchPrefixId + SEPARATOR, SEPARATOR + busNum + SEPARATOR + sectionNum, voltageLevel.getBusBreakerView());
}
}
}

private void createSwitches(VoltageLevel voltageLevel) {
for (int sectionNum = lowSectionIndex; sectionNum < lowSectionIndex + sectionCount - 1; sectionNum++) {
SwitchKind switchKind = switchKinds.get(sectionNum - 1);
for (int busBarNum = lowBusbarIndex; busBarNum < lowBusbarIndex + busbarCount; busBarNum++) {
for (int busBarNum = lowBusOrBusbarIndex; busBarNum < lowBusOrBusbarIndex + alignedBusesOrBusbarCount; busBarNum++) {
if (switchKind == SwitchKind.BREAKER) {
int node1 = getNode(busBarNum, sectionNum, busbarSectionPrefixId, voltageLevel);
int node1 = getNode(busBarNum, sectionNum, busOrBusbarSectionPrefixId, voltageLevel);
int node2 = voltageLevel.getNodeBreakerView().getMaximumNodeIndex() + 1;
int node3 = node2 + 1;
int node4 = getNode(busBarNum, sectionNum + 1, busbarSectionPrefixId, voltageLevel);
int node4 = getNode(busBarNum, sectionNum + 1, busOrBusbarSectionPrefixId, voltageLevel);
createNBDisconnector(node1, node2, SEPARATOR + busBarNum + SEPARATOR + sectionNum, switchPrefixId, voltageLevel.getNodeBreakerView(), false);
createNBBreaker(node2, node3, SEPARATOR + busBarNum + SEPARATOR + sectionNum, switchPrefixId, voltageLevel.getNodeBreakerView(), false);
createNBDisconnector(node3, node4, SEPARATOR + busBarNum + SEPARATOR + sectionNum, switchPrefixId, voltageLevel.getNodeBreakerView(), false);
} else if (switchKind == SwitchKind.DISCONNECTOR) {
int node1 = getNode(busBarNum, sectionNum, busbarSectionPrefixId, voltageLevel);
int node2 = getNode(busBarNum, sectionNum + 1, busbarSectionPrefixId, voltageLevel);
int node1 = getNode(busBarNum, sectionNum, busOrBusbarSectionPrefixId, voltageLevel);
int node2 = getNode(busBarNum, sectionNum + 1, busOrBusbarSectionPrefixId, voltageLevel);
createNBDisconnector(node1, node2, SEPARATOR + busBarNum + SEPARATOR + sectionNum, switchPrefixId, voltageLevel.getNodeBreakerView(), false);
} // other cases cannot happen (has been checked in the constructor)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public class CreateVoltageLevelTopologyBuilder {

private String voltageLevelId = null;

private int lowBusbarIndex = 1;
private Integer busbarCount = null;
private int lowBusOrBusbarIndex = 1;
private Integer alignedBusesOrBusbarCount = null;
private int lowSectionIndex = 1;
private Integer sectionCount = null;

private String busbarSectionPrefixId = null;
private String busOrBusbarSectionPrefixId = null;
private String switchPrefixId = null;

private List<SwitchKind> switchKinds = Collections.emptyList();
Expand All @@ -38,8 +38,8 @@ public class CreateVoltageLevelTopologyBuilder {
*/
public CreateVoltageLevelTopologyBuilder withVoltageLevelId(String voltageLevelId) {
this.voltageLevelId = voltageLevelId;
if (busbarSectionPrefixId == null) {
busbarSectionPrefixId = voltageLevelId;
if (busOrBusbarSectionPrefixId == null) {
busOrBusbarSectionPrefixId = voltageLevelId;
}
if (switchPrefixId == null) {
switchPrefixId = voltageLevelId;
Expand All @@ -48,22 +48,24 @@ public CreateVoltageLevelTopologyBuilder withVoltageLevelId(String voltageLevelI
}

/**
* Set the lowest index of busbar index that will be created (1 by default).
* Set the lowest index of bus or busbar index that will be created (1 by default).
*
* @param lowBusbarIndex
* @param lowBusOrBusbarIndex
*/
public CreateVoltageLevelTopologyBuilder withLowBusbarIndex(int lowBusbarIndex) {
this.lowBusbarIndex = lowBusbarIndex;
public CreateVoltageLevelTopologyBuilder withLowBusOrBusbarIndex(int lowBusOrBusbarIndex) {
this.lowBusOrBusbarIndex = lowBusOrBusbarIndex;
return this;
}

/**
* Set the number of busbar which will be created.
* Set the number of parallel bus lines or busbar which will be created.
* In case of node/breaker topology, it is the number of busbar sections.
* In case of bus/breaker topology, it is the number of lines of aligned buses.
*
* @param busbarCount
* @param alignedBusesOrBusbarCount
*/
public CreateVoltageLevelTopologyBuilder withBusbarCount(int busbarCount) {
this.busbarCount = busbarCount;
public CreateVoltageLevelTopologyBuilder withAlignedBusesOrBusbarCount(int alignedBusesOrBusbarCount) {
this.alignedBusesOrBusbarCount = alignedBusesOrBusbarCount;
return this;
}

Expand All @@ -78,7 +80,7 @@ public CreateVoltageLevelTopologyBuilder withLowSectionIndex(int lowSectionIndex
}

/**
* Set the number of sections for each created busbar.
* Set the number of sections for each created busbar or the number of switches between the buses in bus/breaker topology.
*
* @param sectionCount
*/
Expand All @@ -88,12 +90,12 @@ public CreateVoltageLevelTopologyBuilder withSectionCount(int sectionCount) {
}

/**
* Set the prefix ID for the created busbar sections. By default, it is equals to the voltage level ID.
* Set the prefix ID for the created buses or busbar sections. By default, it is equals to the voltage level ID.
*
* @param busbarSectionPrefixId
*/
public CreateVoltageLevelTopologyBuilder withBusbarSectionPrefixId(String busbarSectionPrefixId) {
this.busbarSectionPrefixId = busbarSectionPrefixId;
this.busOrBusbarSectionPrefixId = busbarSectionPrefixId;
return this;
}

Expand All @@ -115,6 +117,8 @@ public CreateVoltageLevelTopologyBuilder withSwitchPrefixId(String switchPrefixI
* If it is {@link SwitchKind#DISCONNECTOR}, a closed disconnector is created.
* If it is null, no switch is created: the sections are disconnected.
*
* In bus/breaker topology, all the switching devices are by default breakers.
*
* @param switchKinds
*/
public CreateVoltageLevelTopologyBuilder withSwitchKinds(SwitchKind... switchKinds) {
Expand All @@ -129,6 +133,8 @@ public CreateVoltageLevelTopologyBuilder withSwitchKinds(SwitchKind... switchKin
* If it is {@link SwitchKind#BREAKER}, a closed disconnector, a closed breaker and a closed disconnector are created.
* If it is {@link SwitchKind#DISCONNECTOR}, a closed disconnector is created.
*
* In bus/breaker topology, all the switching devices are by default breakers.
*
* @param switchKinds
*/
public CreateVoltageLevelTopologyBuilder withSwitchKinds(List<SwitchKind> switchKinds) {
Expand All @@ -137,6 +143,6 @@ public CreateVoltageLevelTopologyBuilder withSwitchKinds(List<SwitchKind> switch
}

public CreateVoltageLevelTopology build() {
return new CreateVoltageLevelTopology(voltageLevelId, lowBusbarIndex, busbarCount, lowSectionIndex, sectionCount, busbarSectionPrefixId, switchPrefixId, switchKinds);
return new CreateVoltageLevelTopology(voltageLevelId, lowBusOrBusbarIndex, alignedBusesOrBusbarCount, lowSectionIndex, sectionCount, busOrBusbarSectionPrefixId, switchPrefixId, switchKinds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static void newCouplingDeviceAddedReport(Reporter reporter, String voltageLevelI
static void createdNewSymmetricalTopology(Reporter reporter, String voltageLevelId, int busbarCount, int sectionCount) {
reporter.report(Report.builder()
.withKey("SymmetricalTopologyCreated")
.withDefaultMessage("New symmetrical topology in voltage level ${voltageLevelId}: creation of ${busbarCount} busbar(s) with ${sectionCount} section(s) each.")
.withDefaultMessage("New symmetrical topology in voltage level ${voltageLevelId}: creation of ${busbarCount} bus(es) or busbar(s) with ${sectionCount} section(s) each.")
.withValue(VOLTAGE_LEVEL_ID, voltageLevelId)
.withValue("busbarCount", busbarCount)
.withValue("sectionCount", sectionCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,16 @@ static void createNBDisconnector(int node1, int node2, String suffix, String pre
}

static void createBusBreakerSwitches(String busId1, String middleBusId, String busId2, String lineId, VoltageLevel.BusBreakerView view) {
createBusBreakerSwitch(busId1, middleBusId, lineId + "_", "_1", view);
createBusBreakerSwitch(middleBusId, busId2, lineId + "_", "_2", view);
}

static void createBusBreakerSwitch(String busId1, String busId2, String prefix, String suffix, VoltageLevel.BusBreakerView view) {
view.newSwitch()
.setId(lineId + "_SW_1")
.setId(prefix + "SW" + suffix)
.setEnsureIdUnicity(true)
.setOpen(false)
.setBus1(busId1)
.setBus2(middleBusId)
.add();
view.newSwitch()
.setId(lineId + "_SW_2")
.setEnsureIdUnicity(true)
.setOpen(false)
.setBus1(middleBusId)
.setBus2(busId2)
.add();
}
Expand Down
Loading