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

apply lockout for non fictional switch #500

Merged
merged 17 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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,13 +15,15 @@
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.extensions.OperatingStatus;
import com.powsybl.iidm.network.extensions.OperatingStatusAdder;
import com.powsybl.iidm.network.util.SwitchPredicates;
import org.gridsuite.modification.server.NetworkModificationException;
import org.gridsuite.modification.server.dto.OperatingStatusModificationInfos;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashSet;
import java.util.Objects;
import java.util.function.Predicate;

import static org.gridsuite.modification.server.NetworkModificationException.Type.EQUIPMENT_NOT_FOUND;
import static org.gridsuite.modification.server.NetworkModificationException.Type.OPERATING_STATUS_MODIFICATION_ERROR;
Expand Down Expand Up @@ -142,7 +144,7 @@ private void applyEnergiseEquipmentEnd(ReportNode subReportNode, Identifiable<?>
}

TwoSides oppositeSide = side == TwoSides.ONE ? TwoSides.TWO : TwoSides.ONE;
if (connectOneTerminal(branch.getTerminal(side)) && disconnectOneTerminal(branch.getTerminal(oppositeSide))) {
if (connectOneTerminal(branch.getTerminal(side)) && disconnectOneTerminal(branch.getTerminal(oppositeSide), SwitchPredicates.IS_CLOSED_BREAKER)) {
branch.newExtension(OperatingStatusAdder.class).withStatus(OperatingStatus.Status.IN_OPERATION).add();
} else {
throw new NetworkModificationException(OPERATING_STATUS_MODIFICATION_ERROR, "Unable to energise equipment end");
Expand All @@ -158,11 +160,11 @@ private void applyEnergiseEquipmentEnd(ReportNode subReportNode, Identifiable<?>
}

private boolean disconnectAllTerminals(Identifiable<?> equipment) {
return ModificationUtils.getInstance().getTerminalsFromIdentifiable(equipment).stream().allMatch(this::disconnectOneTerminal);
return ModificationUtils.getInstance().getTerminalsFromIdentifiable(equipment).stream().allMatch(terminal -> disconnectOneTerminal(terminal, SwitchPredicates.IS_NONFICTIONAL));
}

private boolean disconnectOneTerminal(Terminal terminal) {
return !terminal.isConnected() || terminal.disconnect();
private boolean disconnectOneTerminal(Terminal terminal, Predicate<Switch> switchPredicates) {
return !terminal.isConnected() || terminal.disconnect(switchPredicates);
}

private boolean connectAllTerminals(Identifiable<?> equipment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
package org.gridsuite.modification.server.modifications;

import com.fasterxml.jackson.core.type.TypeReference;
import com.powsybl.iidm.network.Line;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.extensions.OperatingStatus;
import com.powsybl.network.store.iidm.impl.NetworkFactoryImpl;
import lombok.SneakyThrows;
import org.gridsuite.modification.server.NetworkModificationException;
import org.gridsuite.modification.server.dto.OperatingStatusModificationInfos;
Expand Down Expand Up @@ -44,7 +44,7 @@ public class OperatingStatusModificationLockoutLineTest extends AbstractNetworkM

@Override
protected Network createNetwork(UUID networkUuid) {
Network network = NetworkCreation.create(networkUuid, true);
Network network = NetworkCreation.createSwitchNetwork(networkUuid, new NetworkFactoryImpl());
// force a branch status different from the expected one, after testCreate
TestUtils.setOperatingStatus(network, TARGET_LINE_ID, OTHER_BRANCH_STATUS);
return network;
Expand Down Expand Up @@ -79,14 +79,25 @@ protected void assertAfterNetworkModificationDeletion() {
TestUtils.assertOperatingStatus(getNetwork(), TARGET_LINE_ID, OTHER_BRANCH_STATUS);
}

@Test
public void testLockoutModification() throws Exception {
OperatingStatusModificationInfos modificationInfos = (OperatingStatusModificationInfos) buildModification();
modificationInfos.setEquipmentId("line2");
modificationInfos.setAction(OperatingStatusModificationInfos.ActionType.LOCKOUT);
String modificationJson = mapper.writeValueAsString(modificationInfos);
mockMvc.perform(post(getNetworkModificationUri()).content(modificationJson).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
assertAfterNetworkModificationCreation();
}
antoinebhs marked this conversation as resolved.
Show resolved Hide resolved

@Test
public void testCreateWithErrors() throws Exception {
// line not existing
OperatingStatusModificationInfos modificationInfos = (OperatingStatusModificationInfos) buildModification();
modificationInfos.setEquipmentId("notFound");
String modificationJson = mapper.writeValueAsString(modificationInfos);
mockMvc.perform(post(getNetworkModificationUri()).content(modificationJson).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
.andExpect(status().isOk());
assertNull(getNetwork().getLine("notFound"));
assertLogMessage(new NetworkModificationException(EQUIPMENT_NOT_FOUND, "notFound").getMessage(),
modificationInfos.getErrorType().name(), reportService);
Expand All @@ -96,34 +107,24 @@ public void testCreateWithErrors() throws Exception {
modificationInfos.setAction(null);
modificationJson = mapper.writeValueAsString(modificationInfos);
mockMvc.perform(post(getNetworkModificationUri()).content(modificationJson).contentType(MediaType.APPLICATION_JSON))
.andExpectAll(
status().isBadRequest(),
content().string(new NetworkModificationException(OPERATING_ACTION_TYPE_EMPTY).getMessage())
);
antoinebhs marked this conversation as resolved.
Show resolved Hide resolved
.andExpectAll(
status().isBadRequest(),
content().string(new NetworkModificationException(OPERATING_ACTION_TYPE_EMPTY).getMessage()));

// modification action not existing
modificationJson = modificationJson.replace("LOCKOUT", "INVALID_ACTION"); // note: should never happen in real
mockMvc.perform(post(getNetworkModificationUri()).content(modificationJson).contentType(MediaType.APPLICATION_JSON))
.andExpect(
status().is4xxClientError());

// Add a line that can't be disconnected
Line line = getNetwork().newLine()
.setId("cantdisconnect")
.setVoltageLevel1("v1")
.setVoltageLevel2("v3")
.setNode1(0)
.setNode2(0)
.setX(12)
.setR(7)
.add();
assertNotNull(line);
modificationInfos.setEquipmentId("cantdisconnect");
// Add a line that can't be disconnected : with fictitious switches
assertNotNull(getNetwork().getLine("line1"));
modificationInfos.setEquipmentId("line1");
modificationInfos.setAction(OperatingStatusModificationInfos.ActionType.LOCKOUT);
modificationJson = mapper.writeValueAsString(modificationInfos);
mockMvc.perform(post(getNetworkModificationUri()).content(modificationJson).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
assertNull(getNetwork().getLine("cantdisconnect").getExtension(OperatingStatus.class));
antoinebhs marked this conversation as resolved.
Show resolved Hide resolved
assertNull(getNetwork().getLine("line1").getExtension(OperatingStatus.class));
assertLogMessage(new NetworkModificationException(OPERATING_STATUS_MODIFICATION_ERROR, "Unable to disconnect all equipment ends").getMessage(),
modificationInfos.getErrorType().name(), reportService);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,41 @@ public static Network create(UUID uuid, boolean createHvdcLine) {
return create(uuid, createHvdcLine, new NetworkFactoryImpl());
}

public static Network createSwitchNetwork(UUID uuid, NetworkFactory networkFactory) {
antoinebhs marked this conversation as resolved.
Show resolved Hide resolved
Network network = networkFactory.createNetwork(uuid.toString(), "test");

Substation s1 = createSubstation(network, "s1", "s1", Country.FR);
VoltageLevel vl1 = createVoltageLevel(s1, "vl1", "vl1", TopologyKind.NODE_BREAKER, 400.0);
createBusBarSection(vl1, "1.1", "1.1", 0);
createSwitch(vl1, "br1", "br1", SwitchKind.LOAD_BREAK_SWITCH, false, false, false, 0, 1);
createSwitch(vl1, "br2", "br2", SwitchKind.LOAD_BREAK_SWITCH, false, false, false, 1, 2);
createSwitch(vl1, "br3", "br3", SwitchKind.LOAD_BREAK_SWITCH, false, false, false, 1, 3);
Substation s2 = createSubstation(network, "s2", "s2", Country.FR);

VoltageLevel vl2 = createVoltageLevel(s2, "vl2", "vl2", TopologyKind.NODE_BREAKER, 400);
createBusBarSection(vl2, "b2", "b2", 1);
createSwitch(vl2, "br4", "br4", SwitchKind.BREAKER, false, false, true, 1, 0);
createSwitch(vl2, "br5", "br5", SwitchKind.LOAD_BREAK_SWITCH, false, false, false, 1, 2);

Substation s3 = createSubstation(network, "s3", "s3", Country.FR);

VoltageLevel vl3 = createVoltageLevel(s3, "vl3", "vl3", TopologyKind.NODE_BREAKER, 400);
createBusBarSection(vl3, "b3", "b3", 1);
createSwitch(vl3, "br6", "br6", SwitchKind.BREAKER, false, false, false, 0, 1);
createSwitch(vl3, "br7", "br7", SwitchKind.BREAKER, false, false, false, 1, 2);
createSwitch(vl3, "br8", "br8", SwitchKind.BREAKER, false, false, false, 1, 3);
createLoad(vl3, "l1", "l1", 0, 180, 18.0, "cn0", 3, ConnectablePosition.Direction.TOP);

createLine(network, "line1", "line1", "vl1", "vl2", 2, 0, 0.1, 10.0, 0.0, 0.0, 0.0, 0.0, "line1", 1, ConnectablePosition.Direction.TOP, "line1", 1, ConnectablePosition.Direction.TOP);
createLine(network, "line2", "line2", "vl2", "vl3", 2, 2, 0.1, 10.0, 0.0, 0.0, 0.0, 0.0, "line2", 1, ConnectablePosition.Direction.TOP, "line2", 1, ConnectablePosition.Direction.TOP);
createLine(network, "line3", "line3", "vl1", "vl3", 3, 3, 0.1, 10.0, 0.0, 0.0, 0.0, 0.0, "line3", 1, ConnectablePosition.Direction.TOP, "line3", 1, ConnectablePosition.Direction.TOP);

network.getVariantManager().setWorkingVariant(VariantManagerConstants.INITIAL_VARIANT_ID);
network.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, VARIANT_ID);
antoinebhs marked this conversation as resolved.
Show resolved Hide resolved

return network;
}

public static Network create(UUID uuid, boolean createHvdcLine, NetworkFactory networkFactory) {
Network network = networkFactory.createNetwork(uuid.toString(), "test");

Expand Down
Loading