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

Fix notifications on terminal connection/disconnection #453

Merged
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 @@ -63,13 +63,9 @@ public String getBus() {
@Override
public void setBus(String bus) {
if (side1) {
String oldValue = attributes.getBus1();
attributes.setBus1(bus);
branch.notifyUpdate("bus1", oldValue, bus, true);
} else {
String oldValue = attributes.getBus2();
attributes.setBus2(bus);
branch.notifyUpdate("bus2", oldValue, bus, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,11 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static com.powsybl.network.store.iidm.impl.ConnectDisconnectUtil.closeSwitches;
import static com.powsybl.network.store.iidm.impl.ConnectDisconnectUtil.openSwitches;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class TerminalImpl<U extends IdentifiableAttributes> implements Terminal, Validable {

private static final Set<IdentifiableType> CONNECTABLE_WITH_SIDES_TYPES = Set.of(IdentifiableType.LINE, IdentifiableType.TWO_WINDINGS_TRANSFORMER, IdentifiableType.THREE_WINDINGS_TRANSFORMER);

private final NetworkObjectIndex index;

private final Connectable<?> connectable;
Expand Down Expand Up @@ -241,6 +236,10 @@ private boolean connectNodeBreaker(Predicate<Switch> isTypeSwitchToOperate) {
// Set of switches that are to be closed
Set<SwitchImpl> switchesToClose = new HashSet<>();

if (isConnected()) {
return false;
}

// Get the list of switches to open
if (getConnectingSwitches(isTypeSwitchToOperate, switchesToClose)) {
// Open the switches
Expand All @@ -249,9 +248,6 @@ private boolean connectNodeBreaker(Predicate<Switch> isTypeSwitchToOperate) {
return false;
}

// The switches are now closed
closeSwitches(index, switchesToClose);

return true;
TheMaskedTurtle marked this conversation as resolved.
Show resolved Hide resolved
}

Expand All @@ -261,12 +257,8 @@ protected void connectBusBreaker() {
a.setBus(a.getConnectableBus());

// Notification to the listeners
index.notifyUpdate(getConnectable(), "connected", index.getNetwork().getVariantManager().getWorkingVariantId(), false, true);

// Notification for branches (with sides) is made in the injection attributes adapters (setBus)
if (!CONNECTABLE_WITH_SIDES_TYPES.contains(getConnectable().getType())) {
index.notifyUpdate(getConnectable(), "bus", null, a.getConnectableBus());
}
String side = Terminal.getConnectableSide(this).map(s -> Integer.toString(s.getNum())).orElse("");
index.notifyUpdate(getConnectable(), "connected" + side, index.getNetwork().getVariantManager().getWorkingVariantId(), false, true);
});
}

Expand All @@ -284,6 +276,8 @@ public boolean connect(Predicate<Switch> isTypeSwitchToOperate) {
try {
Resource<VoltageLevelAttributes> voltageLevelResource = getVoltageLevelResource();
VoltageLevelAttributes voltageLevelAttributes = voltageLevelResource.getAttributes();
boolean connectedBefore = isConnected();
index.notifyUpdate(getConnectable(), "beginConnect", index.getNetwork().getVariantManager().getWorkingVariantId(), connectedBefore, null);
if (isNodeBeakerTopologyKind()) {
if (connectNodeBreaker(isTypeSwitchToOperate)) {
done = true;
Expand All @@ -296,6 +290,9 @@ public boolean connect(Predicate<Switch> isTypeSwitchToOperate) {
}
}

boolean connectedAfter = isConnected();
index.notifyUpdate(getConnectable(), "endConnect", index.getNetwork().getVariantManager().getWorkingVariantId(), null, connectedAfter);

if (done) {
// to invalidate calculated buses
voltageLevelAttributes.setCalculatedBusesValid(false);
Expand Down Expand Up @@ -402,9 +399,6 @@ private boolean disconnectNodeBreaker(Predicate<Switch> isSwitchOpenable) {
return false;
}

// The switches are now opened
openSwitches(index, switchesToOpen);

TheMaskedTurtle marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

Expand All @@ -416,12 +410,8 @@ protected boolean disconnectBusBreaker() {
a.setBus(null);

// Notification to the listeners
index.notifyUpdate(getConnectable(), "connected", index.getNetwork().getVariantManager().getWorkingVariantId(), true, false);

// Notification for branches (with sides) is made in the injection attributes adapters (setBus)
if (!CONNECTABLE_WITH_SIDES_TYPES.contains(getConnectable().getType())) {
index.notifyUpdate(getConnectable(), "bus", a.getConnectableBus(), null);
}
String side = Terminal.getConnectableSide(this).map(s -> Integer.toString(s.getNum())).orElse("");
index.notifyUpdate(getConnectable(), "connected" + side, index.getNetwork().getVariantManager().getWorkingVariantId(), true, false);
});
return true;
}
Expand All @@ -442,6 +432,8 @@ public boolean disconnect(Predicate<Switch> isSwitchOpenable) {
try {
Resource<VoltageLevelAttributes> voltageLevelResource = getVoltageLevelResource();
VoltageLevelAttributes voltageLevelAttributes = voltageLevelResource.getAttributes();
boolean disconnectedBefore = !isConnected();
index.notifyUpdate(getConnectable(), "beginDisconnect", index.getNetwork().getVariantManager().getWorkingVariantId(), disconnectedBefore, null);
if (isNodeBeakerTopologyKind()) {
if (disconnectNodeBreaker(isSwitchOpenable)) {
done = true;
Expand All @@ -452,6 +444,9 @@ public boolean disconnect(Predicate<Switch> isSwitchOpenable) {
}
}

boolean disconnectedAfter = !isConnected();
index.notifyUpdate(getConnectable(), "endDisconnect", index.getNetwork().getVariantManager().getWorkingVariantId(), null, disconnectedAfter);

if (done) {
// to invalidate calculated buses
voltageLevelAttributes.setCalculatedBusesValid(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ public void cancelSelectedOperationalLimitsGroup() {
leg2 = new LegImpl(this, ThreeWindingsTransformerAttributes::getLeg2, index);
leg3 = new LegImpl(this, ThreeWindingsTransformerAttributes::getLeg3, index);

terminal1 = new TerminalImpl<>(index, this, r -> new ThreeWindingsTransformerToInjectionAttributesAdapter(leg1, r.getAttributes(), ThreeSides.ONE));
terminal2 = new TerminalImpl<>(index, this, r -> new ThreeWindingsTransformerToInjectionAttributesAdapter(leg2, r.getAttributes(), ThreeSides.TWO));
terminal3 = new TerminalImpl<>(index, this, r -> new ThreeWindingsTransformerToInjectionAttributesAdapter(leg3, r.getAttributes(), ThreeSides.THREE));
terminal1 = new TerminalImpl<>(index, this, r -> new ThreeWindingsTransformerToInjectionAttributesAdapter(r.getAttributes(), ThreeSides.ONE));
terminal2 = new TerminalImpl<>(index, this, r -> new ThreeWindingsTransformerToInjectionAttributesAdapter(r.getAttributes(), ThreeSides.TWO));
terminal3 = new TerminalImpl<>(index, this, r -> new ThreeWindingsTransformerToInjectionAttributesAdapter(r.getAttributes(), ThreeSides.THREE));
}

static ThreeWindingsTransformerImpl create(NetworkObjectIndex index, Resource<ThreeWindingsTransformerAttributes> resource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,15 @@
import com.powsybl.network.store.model.LegAttributes;
import com.powsybl.network.store.model.ThreeWindingsTransformerAttributes;

import java.util.Objects;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class ThreeWindingsTransformerToInjectionAttributesAdapter extends AbstractIdentifiableToInjectionAttributesAdapter<ThreeWindingsTransformerAttributes> {

private final ThreeWindingsTransformerImpl.LegImpl leg;

private final ThreeSides side;

public ThreeWindingsTransformerToInjectionAttributesAdapter(ThreeWindingsTransformerImpl.LegImpl leg, ThreeWindingsTransformerAttributes attributes, ThreeSides side) {
TheMaskedTurtle marked this conversation as resolved.
Show resolved Hide resolved
public ThreeWindingsTransformerToInjectionAttributesAdapter(ThreeWindingsTransformerAttributes attributes, ThreeSides side) {
super(attributes);
this.leg = Objects.requireNonNull(leg);
this.side = side;
}

Expand All @@ -37,7 +32,6 @@ private LegAttributes getLegAttributes() {
case ONE -> attributes.getLeg1();
case TWO -> attributes.getLeg2();
case THREE -> attributes.getLeg3();
default -> throw createUnknownSideException();
};
}

Expand Down Expand Up @@ -68,9 +62,7 @@ public String getBus() {

@Override
public void setBus(String bus) {
String oldValue = getLegAttributes().getBus();
getLegAttributes().setBus(bus);
leg.notifyUpdate("bus", oldValue, bus);
}

@Override
Expand All @@ -89,7 +81,6 @@ public double getP() {
case ONE -> attributes.getP1();
case TWO -> attributes.getP2();
case THREE -> attributes.getP3();
default -> throw createUnknownSideException();
};
}

Expand All @@ -109,7 +100,6 @@ public double getQ() {
case ONE -> attributes.getQ1();
case TWO -> attributes.getQ2();
case THREE -> attributes.getQ3();
default -> throw createUnknownSideException();
};
}

Expand All @@ -129,7 +119,6 @@ public ConnectablePositionAttributes getPosition() {
case ONE -> attributes.getPosition1();
case TWO -> attributes.getPosition2();
case THREE -> attributes.getPosition3();
default -> throw createUnknownSideException();
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,4 @@
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
public class ConnectionNotificationTest extends AbstractConnectionNotificationTest {
@Override
public void busBreakerTest() {
// FIXME remove this test when we have the same update notifications as the core impl when disconnecting terminals : beginDisconnect and endDisconnect
}

@Override
public void nodeBreakerTest() {
// FIXME remove this test when we have the same update notifications as the core impl when disconnecting terminals : beginDisconnect and endDisconnect
}
}
Loading