Skip to content

Commit

Permalink
Connection disconnection notification (#2854)
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
  • Loading branch information
geofjamg authored Jan 17, 2024
1 parent ebe7ae8 commit 3a1881c
Show file tree
Hide file tree
Showing 18 changed files with 229 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,6 @@ static Terminal getTerminal(Identifiable<?> identifiable, ThreeSides side) {
throw new PowsyblException("Unexpected terminal reference identifiable instance: " + identifiable.getClass());
}
}

ThreeSides getSide();
}
5 changes: 5 additions & 0 deletions iidm/iidm-extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package com.powsybl.iidm.network.impl;

import com.powsybl.iidm.network.ThreeSides;
import com.powsybl.iidm.network.ValidationException;

/**
Expand Down Expand Up @@ -52,7 +53,7 @@ public T setVoltageLevel1(String voltageLevelId1) {

protected TerminalExt checkAndGetTerminal1() {
VoltageLevelExt voltageLevel = checkAndGetVoltageLevel1();
return new TerminalBuilder(voltageLevel.getNetworkRef(), this)
return new TerminalBuilder(voltageLevel.getNetworkRef(), this, ThreeSides.ONE)
.setNode(node1)
.setBus(bus1)
.setConnectableBus(connectableBus1)
Expand Down Expand Up @@ -97,7 +98,7 @@ public T setVoltageLevel2(String voltageLevelId2) {

protected TerminalExt checkAndGetTerminal2() {
VoltageLevelExt voltageLevel = checkAndGetVoltageLevel2();
return new TerminalBuilder(voltageLevel.getNetworkRef(), this)
return new TerminalBuilder(voltageLevel.getNetworkRef(), this, ThreeSides.TWO)
.setNode(node2)
.setBus(bus2)
.setConnectableBus(connectableBus2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ protected void move(TerminalExt oldTerminal, TopologyPoint oldTopologyPoint, int
}

// create the new terminal and attach it to the given voltage level and to the connectable
TerminalExt terminalExt = new TerminalBuilder(voltageLevel.getNetworkRef(), this)
TerminalExt terminalExt = new TerminalBuilder(voltageLevel.getNetworkRef(), this, oldTerminal.getSide())
.setNode(node)
.build();

Expand All @@ -170,7 +170,7 @@ protected void move(TerminalExt oldTerminal, TopologyPoint oldTopologyPoint, Str
}

// create the new terminal and attach it to the voltage level of the given bus and links it to the connectable
TerminalExt terminalExt = new TerminalBuilder(((VoltageLevelExt) bus.getVoltageLevel()).getNetworkRef(), this)
TerminalExt terminalExt = new TerminalBuilder(((VoltageLevelExt) bus.getVoltageLevel()).getNetworkRef(), this, oldTerminal.getSide())
.setBus(connected ? bus.getId() : null)
.setConnectableBus(bus.getId())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected Ref<NetworkImpl> getNetworkRef() {
}

protected TerminalExt checkAndGetTerminal() {
return new TerminalBuilder(getNetworkRef(), this)
return new TerminalBuilder(getNetworkRef(), this, null)
.setNode(node)
.setBus(bus)
.setConnectableBus(connectableBus)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ abstract class AbstractTerminal implements TerminalExt {

private Ref<? extends VariantManagerHolder> network;

protected final ThreeSides side;

protected AbstractConnectable connectable;

protected VoltageLevelExt voltageLevel;

protected int num = -1;

protected final List<RegulatingPoint> regulated = new ArrayList<>();

// attributes depending on the variant
Expand All @@ -42,7 +42,8 @@ abstract class AbstractTerminal implements TerminalExt {

protected boolean removed = false;

AbstractTerminal(Ref<? extends VariantManagerHolder> network) {
AbstractTerminal(Ref<? extends VariantManagerHolder> network, ThreeSides side) {
this.side = side;
this.network = network;
int variantArraySize = network.get().getVariantManager().getVariantArraySize();
p = new TDoubleArrayList(variantArraySize);
Expand All @@ -53,6 +54,15 @@ abstract class AbstractTerminal implements TerminalExt {
}
}

@Override
public ThreeSides getSide() {
return side;
}

protected String getAttributeSideSuffix() {
return "" + (side != null ? side.getNum() : "");
}

protected VariantManagerHolder getVariantManagerHolder() {
return network.get();
}
Expand Down Expand Up @@ -83,11 +93,6 @@ public void setVoltageLevel(VoltageLevelExt voltageLevel) {
}
}

@Override
public void setNum(int num) {
this.num = num;
}

@Override
public void removeAsRegulationPoint() {
regulated.forEach(RegulatingPoint::removeRegulatingTerminal);
Expand All @@ -113,7 +118,7 @@ public Terminal setP(double p) {
int variantIndex = network.get().getVariantIndex();
double oldValue = this.p.set(variantIndex, p);
String variantId = network.get().getVariantManager().getVariantId(variantIndex);
getConnectable().notifyUpdate(() -> "p" + (num != -1 ? num : ""), variantId, oldValue, p);
getConnectable().notifyUpdate(() -> "p" + getAttributeSideSuffix(), variantId, oldValue, p);
return this;
}

Expand All @@ -136,7 +141,7 @@ public Terminal setQ(double q) {
int variantIndex = network.get().getVariantIndex();
double oldValue = this.q.set(variantIndex, q);
String variantId = network.get().getVariantManager().getVariantId(variantIndex);
getConnectable().notifyUpdate(() -> "q" + (num != -1 ? num : ""), variantId, oldValue, q);
getConnectable().notifyUpdate(() -> "q" + getAttributeSideSuffix(), variantId, oldValue, q);
return this;
}

Expand Down Expand Up @@ -172,12 +177,13 @@ public boolean connect(Predicate<Switch> isTypeSwitchToOperate) {
if (removed) {
throw new PowsyblException(UNMODIFIABLE_REMOVED_EQUIPMENT + connectable.id);
}
int variantIndex = getVariantManagerHolder().getVariantIndex();
String variantId = getVariantManagerHolder().getVariantManager().getVariantId(variantIndex);
boolean connectedBefore = isConnected();
connectable.notifyUpdate("beginConnect", variantId, connectedBefore, null);
boolean connected = voltageLevel.connect(this, isTypeSwitchToOperate);
if (connected) {
int variantIndex = getVariantManagerHolder().getVariantIndex();
String variantId = getVariantManagerHolder().getVariantManager().getVariantId(variantIndex);
connectable.notifyUpdate("connection", variantId, false, true);
}
boolean connectedAfter = isConnected();
connectable.notifyUpdate("endConnect", variantId, null, connectedAfter);
return connected;
}

Expand All @@ -198,12 +204,13 @@ public boolean disconnect(Predicate<Switch> isSwitchOpenable) {
if (removed) {
throw new PowsyblException(UNMODIFIABLE_REMOVED_EQUIPMENT + connectable.id);
}
int variantIndex = getVariantManagerHolder().getVariantIndex();
String variantId = getVariantManagerHolder().getVariantManager().getVariantId(variantIndex);
boolean disconnectedBefore = !isConnected();
connectable.notifyUpdate("beginDisconnect", variantId, disconnectedBefore, null);
boolean disconnected = voltageLevel.disconnect(this, isSwitchOpenable);
if (disconnected) {
int variantIndex = getVariantManagerHolder().getVariantIndex();
String variantId = getVariantManagerHolder().getVariantManager().getVariantId(variantIndex);
connectable.notifyUpdate("connection", variantId, true, false);
}
boolean disconnectedAfter = !isConnected();
connectable.notifyUpdate("endDisconnect", variantId, null, disconnectedAfter);
return disconnected;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.util.trove.TBooleanArrayList;
import com.powsybl.iidm.network.Terminal;
import com.powsybl.iidm.network.ThreeSides;
import com.powsybl.iidm.network.TopologyPoint;
import com.powsybl.iidm.network.impl.util.Ref;
import com.powsybl.math.graph.TraversalType;
Expand Down Expand Up @@ -118,8 +119,8 @@ public MergedBus getConnectableBus() {

private final ArrayList<String> connectableBusId;

BusTerminal(Ref<? extends VariantManagerHolder> network, String connectableBusId, boolean connected) {
super(network);
BusTerminal(Ref<? extends VariantManagerHolder> network, ThreeSides side, String connectableBusId, boolean connected) {
super(network, side);
Objects.requireNonNull(connectableBusId);
int variantArraySize = network.get().getVariantManager().getVariantArraySize();
this.connected = new TBooleanArrayList(variantArraySize);
Expand Down Expand Up @@ -154,7 +155,7 @@ void setConnected(boolean connected) {
int variantIndex = getVariantManagerHolder().getVariantIndex();
boolean oldValue = this.connected.set(variantIndex, connected);
String variantId = getVariantManagerHolder().getVariantManager().getVariantId(variantIndex);
getConnectable().notifyUpdate("connected", variantId, oldValue, connected);
getConnectable().notifyUpdate("connected" + getAttributeSideSuffix(), variantId, oldValue, connected);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public BusbarSection add() {
if (node == null) {
throw new ValidationException(this, "node is not set");
}
TerminalExt terminal = new NodeTerminal(voltageLevel.getNetworkRef(), node);
TerminalExt terminal = new NodeTerminal(voltageLevel.getNetworkRef(), null, node);
BusbarSectionImpl section = new BusbarSectionImpl(voltageLevel.getNetworkRef(), id, getName(), isFictitious());
section.addTerminal(terminal);
voltageLevel.attach(terminal, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ public LineImpl add() {
Ref<NetworkImpl> networkRef = computeNetworkRef(getNetwork(), voltageLevel1, voltageLevel2);

LineImpl line = new LineImpl(networkRef, id, getName(), isFictitious(), r, x, g1, b1, g2, b2);
terminal1.setNum(1);
terminal2.setNum(2);
line.addTerminal(terminal1);
line.addTerminal(terminal2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.Terminal;
import com.powsybl.iidm.network.ThreeSides;
import com.powsybl.iidm.network.TopologyPoint;
import com.powsybl.iidm.network.ValidationException;
import com.powsybl.iidm.network.impl.util.Ref;
Expand Down Expand Up @@ -113,8 +114,8 @@ public BusExt getConnectableBus() {

};

NodeTerminal(Ref<? extends VariantManagerHolder> network, int node) {
super(network);
NodeTerminal(Ref<? extends VariantManagerHolder> network, ThreeSides side, int node) {
super(network, side);
this.node = node;
int variantArraySize = network.get().getVariantManager().getVariantArraySize();
v = new TDoubleArrayList(variantArraySize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
*/
package com.powsybl.iidm.network.impl;

import com.powsybl.iidm.network.ThreeSides;
import com.powsybl.iidm.network.impl.util.Ref;
import com.powsybl.iidm.network.Validable;
import com.powsybl.iidm.network.ValidationException;

import java.util.Objects;

/**
*
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
Expand All @@ -20,15 +23,18 @@ class TerminalBuilder {

private final Validable validable;

private ThreeSides side;

private Integer node;

private String bus;

private String connectableBus;

TerminalBuilder(Ref<? extends VariantManagerHolder> network, Validable validable) {
this.network = network;
this.validable = validable;
TerminalBuilder(Ref<? extends VariantManagerHolder> network, Validable validable, ThreeSides side) {
this.network = Objects.requireNonNull(network);
this.validable = Objects.requireNonNull(validable);
this.side = side;
}

TerminalBuilder setBus(String bus) {
Expand Down Expand Up @@ -58,9 +64,9 @@ TerminalExt build() {
throw new ValidationException(validable, "connectable bus is not set");
}

return new BusTerminal(network, connectionBus, bus != null);
return new BusTerminal(network, side, connectionBus, bus != null);
} else {
return new NodeTerminal(network, node);
return new NodeTerminal(network, side, node);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ interface BusViewExt extends BusView {

@Override BusViewExt getBusView();

void setNum(int num);

/**
* Traverse from this terminal using the given topology traverser, knowing that the terminals in the given
* set have already been visited.
Expand Down
Loading

0 comments on commit 3a1881c

Please sign in to comment.