From 80a1fac569d9cce04988e01b80e5a51abe1be233 Mon Sep 17 00:00:00 2001 From: Ghazoua Rehili Date: Fri, 18 Oct 2024 15:27:56 +0200 Subject: [PATCH 1/4] =?UTF-8?q?retreive=20busBarSectionId=20and=20VoltageI?= =?UTF-8?q?d=20not=20set=20in=20modification=20connec=E2=80=A6=20(#546)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: REHILI Ghazwa --- .../BusbarSectionFinderTraverser.java | 49 ++++ .../modifications/ModificationUtils.java | 218 ++++++++++-------- .../GeneratorModificationTest.java | 24 ++ .../modifications/LineModificationTest.java | 18 ++ ...woWindingsTransformerModificationTest.java | 2 +- 5 files changed, 213 insertions(+), 98 deletions(-) create mode 100644 src/main/java/org/gridsuite/modification/server/modifications/BusbarSectionFinderTraverser.java diff --git a/src/main/java/org/gridsuite/modification/server/modifications/BusbarSectionFinderTraverser.java b/src/main/java/org/gridsuite/modification/server/modifications/BusbarSectionFinderTraverser.java new file mode 100644 index 000000000..82efbedcc --- /dev/null +++ b/src/main/java/org/gridsuite/modification/server/modifications/BusbarSectionFinderTraverser.java @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.modification.server.modifications; + +import com.powsybl.iidm.network.IdentifiableType; +import com.powsybl.iidm.network.Switch; +import com.powsybl.iidm.network.Terminal; +import com.powsybl.math.graph.TraverseResult; + +/** + * @author Slimane Amar + */ +// FIXME : to remove when this class is available in network-store +public class BusbarSectionFinderTraverser implements Terminal.TopologyTraverser { + + private final boolean onlyConnectedBbs; + + private String firstTraversedBbsId; + + public BusbarSectionFinderTraverser(boolean onlyConnectedBbs) { + this.onlyConnectedBbs = onlyConnectedBbs; + } + + @Override + public TraverseResult traverse(Terminal terminal, boolean connected) { + if (terminal.getConnectable().getType() == IdentifiableType.BUSBAR_SECTION) { + firstTraversedBbsId = terminal.getConnectable().getId(); + return TraverseResult.TERMINATE_TRAVERSER; + } + return TraverseResult.CONTINUE; + } + + @Override + public TraverseResult traverse(Switch aSwitch) { + if (onlyConnectedBbs && aSwitch.isOpen()) { + return TraverseResult.TERMINATE_PATH; + } + return TraverseResult.CONTINUE; + } + + public String getFirstTraversedBbsId() { + return firstTraversedBbsId; + } +} + diff --git a/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java b/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java index a2f5a4833..05c81b1ec 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java @@ -13,6 +13,7 @@ import com.powsybl.iidm.modification.topology.*; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.*; +import com.powsybl.math.graph.TraversalType; import com.powsybl.network.store.iidm.impl.MinMaxReactiveLimitsImpl; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.*; @@ -57,6 +58,12 @@ public final class ModificationUtils { public static final String CONNECTION_POSITION_FIELD_NAME = "Connection position"; public static final String NOT_EXIST_IN_NETWORK = " does not exist in network"; + public enum FeederSide { + INJECTION_SINGLE_SIDE, + BRANCH_SIDE_ONE, + BRANCH_SIDE_TWO + } + private ModificationUtils() { } @@ -615,10 +622,7 @@ public ReportNode modifyInjectionConnectivityAttributes(ConnectablePosition c InjectionModificationInfos modificationInfos, ReportNode connectivityReports) { List reports = new ArrayList<>(); - if (isVoltageOrBusbarIdMissing(modificationInfos.getVoltageLevelId(), modificationInfos.getBusOrBusbarSectionId(), modificationInfos.getEquipmentId(), reports)) { - return reports.get(0); - } - processConnectivityPosition(connectablePosition, connectablePositionAdder, modificationInfos, injection.getNetwork(), reports, false); + processConnectivityPosition(connectablePosition, connectablePositionAdder, modificationInfos, injection.getNetwork(), reports); modifyConnection(modificationInfos.getTerminalConnected(), injection, injection.getTerminal(), reports); return reportModifications(connectivityReports, reports, "ConnectivityModified", CONNECTIVITY); @@ -630,136 +634,122 @@ public ReportNode modifyBranchConnectivityAttributes(ConnectablePosition conn BranchModificationInfos modificationInfos, ReportNode connectivityReports) { List reports = new ArrayList<>(); - if (isVoltageOrBusbarIdMissing(modificationInfos.getVoltageLevelId1(), modificationInfos.getBusOrBusbarSectionId1(), modificationInfos.getEquipmentId(), reports) || - isVoltageOrBusbarIdMissing(modificationInfos.getVoltageLevelId2(), modificationInfos.getBusOrBusbarSectionId2(), modificationInfos.getEquipmentId(), reports)) { - return reports.get(0); - } - - processConnectivityPosition(connectablePosition, connectablePositionAdder, modificationInfos, branch.getNetwork(), reports, true); + processConnectivityPosition(connectablePosition, connectablePositionAdder, modificationInfos, branch.getNetwork(), reports); modifyConnection(modificationInfos.getTerminal1Connected(), branch, branch.getTerminal1(), reports); modifyConnection(modificationInfos.getTerminal2Connected(), branch, branch.getTerminal2(), reports); return reportModifications(connectivityReports, reports, "ConnectivityModified", CONNECTIVITY); } - private boolean isVoltageOrBusbarIdMissing(AttributeModification voltageLevelId, AttributeModification busbarSectionId, String equipmentId, List reports) { - if (voltageLevelId == null || busbarSectionId == null) { - reports.add(ReportNode.newRootReportNode() - .withMessageTemplate("VoltageLevelOrBusbarSectionNotFound", - "Voltage level id or Bus bar section id of equipment id=${id} not found") - .withUntypedValue("id", equipmentId) - .withSeverity(TypedValue.WARN_SEVERITY) - .build()); - return true; - } - return false; - } - private void processConnectivityPosition(ConnectablePosition connectablePosition, ConnectablePositionAdder connectablePositionAdder, BasicEquipmentModificationInfos modificationInfos, Network network, - List reports, - boolean isBranch) { + List reports) { if (connectablePosition != null) { - modifyExistingConnectivityPosition(connectablePosition, modificationInfos, reports, isBranch); + modifyExistingConnectivityPosition(connectablePosition, modificationInfos, reports); } else { - createNewConnectivityPosition(connectablePositionAdder, modificationInfos, network, reports, isBranch); + createNewConnectivityPosition(connectablePositionAdder, modificationInfos, network, reports); } } private void modifyExistingConnectivityPosition(ConnectablePosition connectablePosition, BasicEquipmentModificationInfos modificationInfos, - List reports, - boolean isBranch) { - if (isBranch) { - modifyConnectablePosition(connectablePosition.getFeeder1(), modificationInfos, reports, 1); - modifyConnectablePosition(connectablePosition.getFeeder2(), modificationInfos, reports, 2); - } else { - modifyConnectablePosition(connectablePosition.getFeeder(), modificationInfos, reports, 0); + List reports) { + if (modificationInfos instanceof BranchModificationInfos) { + modifyConnectablePosition(connectablePosition.getFeeder1(), modificationInfos, reports, FeederSide.BRANCH_SIDE_ONE); + modifyConnectablePosition(connectablePosition.getFeeder2(), modificationInfos, reports, FeederSide.BRANCH_SIDE_TWO); + } else if (modificationInfos instanceof InjectionModificationInfos) { + modifyConnectablePosition(connectablePosition.getFeeder(), modificationInfos, reports, FeederSide.INJECTION_SINGLE_SIDE); } } private void createNewConnectivityPosition(ConnectablePositionAdder adder, BasicEquipmentModificationInfos modificationInfos, Network network, - List reports, - boolean isBranch) { - if (isBranch) { - ConnectablePositionAdder.FeederAdder feederAdder1 = adder.newFeeder1(); - ConnectablePositionAdder.FeederAdder feederAdder2 = adder.newFeeder2(); - addConnectablePosition(adder, feederAdder1, modificationInfos, network, reports, 1); - addConnectablePosition(adder, feederAdder2, modificationInfos, network, reports, 2); - } else { - ConnectablePositionAdder.FeederAdder feederAdder = adder.newFeeder(); - addConnectablePosition(adder, feederAdder, modificationInfos, network, reports, 0); + List reports) { + if (modificationInfos instanceof BranchModificationInfos) { + addConnectablePosition(adder, modificationInfos, network, reports, FeederSide.BRANCH_SIDE_ONE); + addConnectablePosition(adder, modificationInfos, network, reports, FeederSide.BRANCH_SIDE_TWO); + } else if (modificationInfos instanceof InjectionModificationInfos) { + addConnectablePosition(adder, modificationInfos, network, reports, FeederSide.INJECTION_SINGLE_SIDE); } } private void modifyConnectablePosition(ConnectablePosition.Feeder feeder, BasicEquipmentModificationInfos modificationInfos, List reports, - int feederNumber) { - applyModifications(feeder, modificationInfos, reports, feederNumber); + FeederSide feederSide) { + applyModifications(feeder, modificationInfos, reports, feederSide); } private void applyModifications(ConnectablePosition.Feeder feeder, BasicEquipmentModificationInfos modificationInfos, List reports, - int feederNumber) { + FeederSide feederSide) { ReportNode connectionNameReport = applyElementaryModificationsAndReturnReport(feeder::setName, feeder.getName()::get, - getConnectionName(modificationInfos, feederNumber), - getConnectionNameField(feederNumber)); + getConnectionName(modificationInfos, feederSide), + getConnectionNameField(feederSide)); if (connectionNameReport != null) { reports.add(connectionNameReport); } ReportNode connectionDirectionReport = applyElementaryModificationsAndReturnReport(feeder::setDirection, feeder::getDirection, - getConnectionDirection(modificationInfos, feederNumber), - getConnectionDirectionField(feederNumber)); + getConnectionDirection(modificationInfos, feederSide), + getConnectionDirectionField(feederSide)); if (connectionDirectionReport != null) { reports.add(connectionDirectionReport); } ReportNode connectionPositionReport = applyElementaryModificationsAndReturnReport(feeder::setOrder, feeder.getOrder()::get, - getConnectionPosition(modificationInfos, feederNumber), - getConnectionPositionField(feederNumber)); + getConnectionPosition(modificationInfos, feederSide), + getConnectionPositionField(feederSide)); if (connectionPositionReport != null) { reports.add(connectionPositionReport); } } private void addConnectablePosition(ConnectablePositionAdder adder, - ConnectablePositionAdder.FeederAdder feeder, BasicEquipmentModificationInfos modificationInfos, Network network, List reports, - int feederNumber) { - AttributeModification connectionName = getConnectionName(modificationInfos, feederNumber); - AttributeModification connectionDirection = getConnectionDirection(modificationInfos, feederNumber); - AttributeModification connectionPosition = getConnectionPosition(modificationInfos, feederNumber); + FeederSide feederSide) { + AttributeModification connectionName = getConnectionName(modificationInfos, feederSide); + AttributeModification connectionDirection = getConnectionDirection(modificationInfos, feederSide); + AttributeModification connectionPosition = getConnectionPosition(modificationInfos, feederSide); + if (Objects.isNull(connectionName) && Objects.isNull(connectionDirection) && Objects.isNull(connectionPosition)) { + return; + } AttributeModification equipmentId = getEquipmentId(modificationInfos); - AttributeModification voltageLevelId = getVoltageLevelId(modificationInfos, feederNumber); - AttributeModification busOrBusbarSectionId = getBusOrBusbarSectionId(modificationInfos, feederNumber); - int position = getPosition(connectionPosition, busOrBusbarSectionId, network, voltageLevelId); - + AttributeModification voltageLevelId = getVoltageLevelId(modificationInfos, feederSide); + AttributeModification busOrBusbarSectionId = getBusOrBusbarSectionId(modificationInfos, feederSide); + int position = getPosition(connectionPosition, busOrBusbarSectionId, voltageLevelId, equipmentId, feederSide, network); + ConnectablePositionAdder.FeederAdder feeder; + switch (feederSide) { + case INJECTION_SINGLE_SIDE -> feeder = adder.newFeeder(); + case BRANCH_SIDE_ONE -> feeder = adder.newFeeder1(); + case BRANCH_SIDE_TWO -> feeder = adder.newFeeder2(); + default -> { + return; + } + } ReportNode connectionNameReport = applyConnectablePositionAttribute( feeder::withName, connectionName, equipmentId, reports, - getConnectionNameField(feederNumber), connectionDirection, connectionPosition + getConnectionNameField(feederSide), connectionDirection, connectionPosition ); ReportNode connectionDirectionReport = applyConnectablePositionAttribute( feeder::withDirection, connectionDirection, new AttributeModification<>(ConnectablePosition.Direction.UNDEFINED, OperationType.SET), - reports, getConnectionDirectionField(feederNumber), + reports, getConnectionDirectionField(feederSide), connectionName, connectionPosition ); ReportNode connectionPositionReport = applyConnectablePositionAttribute( feeder::withOrder, connectionPosition, new AttributeModification<>(position, OperationType.SET), - reports, getConnectionPositionField(feederNumber), + reports, getConnectionPositionField(feederSide), connectionName, connectionDirection ); @@ -791,35 +781,38 @@ private boolean isAnyAttributesNonNull(AttributeModification... attributes) { return Arrays.stream(attributes).anyMatch(Objects::nonNull); } - private T getConnectionDetail(BasicEquipmentModificationInfos modificationInfos, int feederNumber, + private T getConnectionDetail(BasicEquipmentModificationInfos modificationInfos, FeederSide feederSide, Function branchFunc1, Function branchFunc2, Function injectionFunc) { if (modificationInfos instanceof BranchModificationInfos branchInfo) { - return feederNumber == 1 ? branchFunc1.apply(branchInfo) : branchFunc2.apply(branchInfo); + if (Objects.requireNonNull(feederSide) == FeederSide.BRANCH_SIDE_ONE) { + return branchFunc1.apply(branchInfo); + } else if (feederSide == FeederSide.BRANCH_SIDE_TWO) { + return branchFunc2.apply(branchInfo); + } } else if (modificationInfos instanceof InjectionModificationInfos injectionInfo) { return injectionFunc.apply(injectionInfo); } return null; } - private String getConnectionFieldName(int feederNumber, String baseFieldName) { - return switch (feederNumber) { - case 0 -> baseFieldName; - case 1 -> baseFieldName + " 1"; - case 2 -> baseFieldName + " 2"; - default -> ""; + private String getConnectionFieldName(FeederSide feederSide, String baseFieldName) { + return switch (feederSide) { + case INJECTION_SINGLE_SIDE -> baseFieldName; + case BRANCH_SIDE_ONE -> baseFieldName + " 1"; + case BRANCH_SIDE_TWO -> baseFieldName + " 2"; }; } - private AttributeModification getVoltageLevelId(BasicEquipmentModificationInfos modificationInfos, int feederNumber) { - return getConnectionDetail(modificationInfos, feederNumber, + private AttributeModification getVoltageLevelId(BasicEquipmentModificationInfos modificationInfos, FeederSide feederSide) { + return getConnectionDetail(modificationInfos, feederSide, BranchModificationInfos::getVoltageLevelId1, BranchModificationInfos::getVoltageLevelId2, InjectionModificationInfos::getVoltageLevelId); } - private AttributeModification getBusOrBusbarSectionId(BasicEquipmentModificationInfos modificationInfos, int feederNumber) { - return getConnectionDetail(modificationInfos, feederNumber, + private AttributeModification getBusOrBusbarSectionId(BasicEquipmentModificationInfos modificationInfos, FeederSide feederSide) { + return getConnectionDetail(modificationInfos, feederSide, BranchModificationInfos::getBusOrBusbarSectionId1, BranchModificationInfos::getBusOrBusbarSectionId2, InjectionModificationInfos::getBusOrBusbarSectionId); } @@ -828,46 +821,77 @@ private AttributeModification getEquipmentId(BasicEquipmentModificationI return AttributeModification.toAttributeModification(modificationInfos.getEquipmentId(), OperationType.SET); } - private AttributeModification getConnectionName(BasicEquipmentModificationInfos modificationInfos, int feederNumber) { - return getConnectionDetail(modificationInfos, feederNumber, + private AttributeModification getConnectionName(BasicEquipmentModificationInfos modificationInfos, FeederSide feederSide) { + return getConnectionDetail(modificationInfos, feederSide, BranchModificationInfos::getConnectionName1, BranchModificationInfos::getConnectionName2, InjectionModificationInfos::getConnectionName); } - private String getConnectionNameField(int feederNumber) { - return getConnectionFieldName(feederNumber, CONNECTION_NAME_FIELD_NAME); + private String getConnectionNameField(FeederSide feederSide) { + return getConnectionFieldName(feederSide, CONNECTION_NAME_FIELD_NAME); } - private String getConnectionDirectionField(int feederNumber) { - return getConnectionFieldName(feederNumber, CONNECTION_DIRECTION_FIELD_NAME); + private String getConnectionDirectionField(FeederSide feederSide) { + return getConnectionFieldName(feederSide, CONNECTION_DIRECTION_FIELD_NAME); } - private String getConnectionPositionField(int feederNumber) { - return getConnectionFieldName(feederNumber, CONNECTION_POSITION_FIELD_NAME); + private String getConnectionPositionField(FeederSide feederSide) { + return getConnectionFieldName(feederSide, CONNECTION_POSITION_FIELD_NAME); } - private AttributeModification getConnectionDirection(BasicEquipmentModificationInfos modificationInfos, int feederNumber) { - return getConnectionDetail(modificationInfos, feederNumber, + private AttributeModification getConnectionDirection(BasicEquipmentModificationInfos modificationInfos, FeederSide feederSide) { + return getConnectionDetail(modificationInfos, feederSide, BranchModificationInfos::getConnectionDirection1, BranchModificationInfos::getConnectionDirection2, InjectionModificationInfos::getConnectionDirection); } - private AttributeModification getConnectionPosition(BasicEquipmentModificationInfos modificationInfos, int feederNumber) { - return getConnectionDetail(modificationInfos, feederNumber, + private AttributeModification getConnectionPosition(BasicEquipmentModificationInfos modificationInfos, FeederSide feederSide) { + return getConnectionDetail(modificationInfos, feederSide, BranchModificationInfos::getConnectionPosition1, BranchModificationInfos::getConnectionPosition2, InjectionModificationInfos::getConnectionPosition); } + private String getBusOrBusbarSection(Terminal terminal) { + String busOrBusbarSectionId; + if (terminal.getVoltageLevel().getTopologyKind().equals(TopologyKind.BUS_BREAKER)) { + if (terminal.isConnected()) { + busOrBusbarSectionId = terminal.getBusBreakerView().getBus().getId(); + } else { + busOrBusbarSectionId = terminal.getBusBreakerView().getConnectableBus().getId(); + } + } else { + busOrBusbarSectionId = getBusbarSectionId(terminal); + } + return busOrBusbarSectionId; + } + + private String getBusbarSectionId(Terminal terminal) { + BusbarSectionFinderTraverser connectedBusbarSectionFinder = new BusbarSectionFinderTraverser(terminal.isConnected()); + terminal.traverse(connectedBusbarSectionFinder, TraversalType.BREADTH_FIRST); + return connectedBusbarSectionFinder.getFirstTraversedBbsId(); + } + private int getPosition(AttributeModification connectionPosition, AttributeModification busOrBusbarSectionId, - Network network, - AttributeModification voltageLevelId) { - return getPosition( - connectionPosition == null ? null : connectionPosition.getValue(), - busOrBusbarSectionId == null ? null : busOrBusbarSectionId.getValue(), - network, - getVoltageLevel(network, voltageLevelId == null ? null : voltageLevelId.getValue()) - ); + AttributeModification voltageLevelId, + AttributeModification equipmentId, + FeederSide feederSide, + Network network) { + String equipmentValue = equipmentId.getValue(); + Terminal selectedTerminal = null; + switch (feederSide) { + case INJECTION_SINGLE_SIDE -> selectedTerminal = network.getIdentifiable(equipmentValue) instanceof Injection injection ? injection.getTerminal() : null; + case BRANCH_SIDE_ONE -> selectedTerminal = network.getIdentifiable(equipmentValue) instanceof Branch branch ? branch.getTerminal1() : null; + case BRANCH_SIDE_TWO -> selectedTerminal = network.getIdentifiable(equipmentValue) instanceof Branch branch ? branch.getTerminal2() : null; + } + String voltageLevel = (voltageLevelId != null && voltageLevelId.getValue() != null) + ? voltageLevelId.getValue() + : Optional.ofNullable(selectedTerminal).map(terminal -> terminal.getVoltageLevel().getId()).orElse(null); + String busOrBusbarSection = (busOrBusbarSectionId != null && busOrBusbarSectionId.getValue() != null) + ? busOrBusbarSectionId.getValue() + : Optional.ofNullable(selectedTerminal).map(this::getBusOrBusbarSection).orElse(null); + Integer connectionPositionValue = (connectionPosition != null) ? connectionPosition.getValue() : null; + return getPosition(connectionPositionValue, busOrBusbarSection, network, getVoltageLevel(network, voltageLevel)); } private void modifyConnection(AttributeModification terminalConnected, Identifiable equipment, Terminal terminal, List reports) { diff --git a/src/test/java/org/gridsuite/modification/server/modifications/GeneratorModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/GeneratorModificationTest.java index b9841d3f3..b110a1070 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/GeneratorModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/GeneratorModificationTest.java @@ -10,6 +10,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.ActivePowerControl; +import com.powsybl.iidm.network.extensions.ConnectablePosition; import com.powsybl.iidm.network.extensions.GeneratorShortCircuit; import com.powsybl.iidm.network.extensions.GeneratorStartup; import lombok.SneakyThrows; @@ -24,6 +25,8 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.IntStream; +import static org.gridsuite.modification.server.utils.NetworkUtil.*; +import static org.gridsuite.modification.server.utils.NetworkUtil.createGeneratorOnBus; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; import static org.gridsuite.modification.server.utils.assertions.Assertions.assertThat; import static org.junit.Assert.assertNull; @@ -50,6 +53,9 @@ protected ModificationInfos buildModification() { .equipmentName(new AttributeModification<>("newV1Generator", OperationType.SET)) .voltageLevelId(new AttributeModification<>("v2", OperationType.SET)) .busOrBusbarSectionId(new AttributeModification<>("1B", OperationType.SET)) + .connectionName(new AttributeModification<>("idGenerator", OperationType.SET)) + .connectionPosition(new AttributeModification<>(1, OperationType.SET)) + .connectionDirection(new AttributeModification<>(ConnectablePosition.Direction.TOP, OperationType.SET)) .targetP(new AttributeModification<>(80.0, OperationType.SET)) .targetQ(new AttributeModification<>(40.0, OperationType.SET)) .targetV(new AttributeModification<>(48.0, OperationType.SET)) @@ -445,6 +451,24 @@ public void testUnsetAttributes() throws Exception { } + @Test + public void changeGeneratorOnBusBreakerWithoutBusBarSection() throws Exception { + VoltageLevel v1 = createVoltageLevel(getNetwork().getSubstation("s1"), "v11", "v32", TopologyKind.BUS_BREAKER, 380.0); + createBusBarSection(getNetwork().getVoltageLevel("v1"), "1.7", "1.7", 0); + createBus(v1, "bus111", "bus111"); + createGeneratorOnBus(v1, "idGenerator1", "bus111", 42.1, 1.0); + GeneratorModificationInfos generatorModificationInfos = GeneratorModificationInfos.builder() + .stashed(false) + .equipmentId("idGenerator1") + .connectionPosition(new AttributeModification<>(1, OperationType.SET)) + .build(); + String generatorModificationInfosJson = mapper.writeValueAsString(generatorModificationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(generatorModificationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + generatorModificationInfos = (GeneratorModificationInfos) modificationRepository.getModifications(getGroupId(), false, true).get(0); + assertEquals(1, generatorModificationInfos.getConnectionPosition().getValue()); + } + @Override @SneakyThrows protected void testCreationModificationMessage(ModificationInfos modificationInfos) { diff --git a/src/test/java/org/gridsuite/modification/server/modifications/LineModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/LineModificationTest.java index 109581464..e5288c4f4 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/LineModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/LineModificationTest.java @@ -445,4 +445,22 @@ public void changeLineConnectablePosition() throws Exception { assertEquals(1, createdModification.getConnectionPosition2().getValue()); } + + @Test + public void changeLineConnectablePositionWithoutBusBarSection() throws Exception { + LineModificationInfos lineModificationInfos = LineModificationInfos.builder() + .stashed(false) + .equipmentId("line3") + .equipmentName(new AttributeModification<>("LineModified", OperationType.SET)) + .connectionName1(new AttributeModification<>("line3", OperationType.SET)) + .connectionName2(new AttributeModification<>("line3", OperationType.SET)) + .build(); + String modificationInfosJson = mapper.writeValueAsString(lineModificationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(modificationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + LineModificationInfos createdModification = (LineModificationInfos) modificationRepository.getModifications(getGroupId(), false, true).get(0); + assertEquals("line3", createdModification.getConnectionName1().getValue()); + assertEquals("line3", createdModification.getConnectionName2().getValue()); + + } } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModificationTest.java index efd3a20a0..c395fafd1 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModificationTest.java @@ -602,7 +602,7 @@ public void testChangeConnectionStatus() { changeConnectionState(getNetwork().getTwoWindingsTransformer("trf2"), TwoSides.ONE, true, true, null); changeConnectionState(getNetwork().getTwoWindingsTransformer("trf2"), TwoSides.ONE, true, false, null); changeConnectionState(getNetwork().getTwoWindingsTransformer("trf2"), TwoSides.TWO, true, true, null); - changeConnectionState(getNetwork().getTwoWindingsTransformer("trf2"), TwoSides.TWO, true, false, "Could not disconnect equipment 'trf2' on side TWO"); + changeConnectionState(getNetwork().getTwoWindingsTransformer("trf2"), TwoSides.TWO, true, false, "Could not disconnect equipment 'trf2'"); } @SneakyThrows From c3eae6504af0a6c11d3451053100c318d3ba3405 Mon Sep 17 00:00:00 2001 From: Ghazoua Rehili Date: Fri, 18 Oct 2024 17:07:02 +0200 Subject: [PATCH 2/4] add reporting for limits and setpoints modification cspr (#550) Signed-off-by: REHILI Ghazwa --- .../StaticVarCompensatorCreation.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreation.java b/src/main/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreation.java index bc99bbaa3..105ca92c9 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreation.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreation.java @@ -125,7 +125,7 @@ private void addExtensionsToStaticVarCompensator(StaticVarCompensatorCreationInf } reportInjectionCreationConnectivity(staticVarCompensatorCreationInfos, subReportNode); - createStaticVarCompensatorVoltageRegulation(staticVarCompensatorCreationInfos, staticVarCompensator, voltageLevel, subReportNode); + createStaticVarCompensatorLimitsAndSetpoints(staticVarCompensatorCreationInfos, staticVarCompensator, voltageLevel, subReportNode); reportStaticVarCompensatorStandbyAutomaton(staticVarCompensatorCreationInfos, staticVarCompensator, subReportNode); } @@ -195,13 +195,18 @@ private void createStaticVarCompensatorInBusBreaker(VoltageLevel voltageLevel, S addExtensionsToStaticVarCompensator(staticVarCompensatorCreationInfos, staticVarCompensator, voltageLevel, subReportNode); } - private void createStaticVarCompensatorVoltageRegulation(StaticVarCompensatorCreationInfos staticVarCompensatorCreationInfos, - StaticVarCompensator staticVarCompensator, VoltageLevel voltageLevel, ReportNode subReportNode) { + private void createStaticVarCompensatorLimitsAndSetpoints(StaticVarCompensatorCreationInfos staticVarCompensatorCreationInfos, + StaticVarCompensator staticVarCompensator, VoltageLevel voltageLevel, ReportNode subReportNode) { List voltageReports = new ArrayList<>(); + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getMinSusceptance(), "Susceptance min")); + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getMaxSusceptance(), "Susceptance max")); + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getMinQAtNominalV(), "Q min at nominal voltage")); + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getMaxQAtNominalV(), "Q max at nominal voltage")); + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getVoltageSetpoint(), "Voltage set point")); + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getReactivePowerSetpoint(), "Reactive power set point")); voltageReports.add(ModificationUtils.getInstance() .createEnabledDisabledReport("VoltageRegulationOn", modificationInfos.getVoltageRegulationType() == VoltageRegulationType.DISTANT && modificationInfos.getRegulationMode() == StaticVarCompensator.RegulationMode.VOLTAGE)); - voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getVoltageSetpoint(), "Voltage set point")); if (staticVarCompensatorCreationInfos.getRegulatingTerminalVlId() != null && staticVarCompensatorCreationInfos.getRegulatingTerminalId() != null && staticVarCompensatorCreationInfos.getRegulatingTerminalType() != null) { Terminal terminal = ModificationUtils.getInstance().getTerminalFromIdentifiable(voltageLevel.getNetwork(), @@ -212,7 +217,7 @@ private void createStaticVarCompensatorVoltageRegulation(StaticVarCompensatorCre updateCompensatorRegulatingTerminal(staticVarCompensatorCreationInfos, staticVarCompensator, terminal, voltageReports); } } - ModificationUtils.getInstance().reportModifications(subReportNode, voltageReports, "VoltageRegulationCreated", "Voltage regulation"); + ModificationUtils.getInstance().reportModifications(subReportNode, voltageReports, "LimitsAndSetpointsCreated", "Limits and Setpoints"); } private void updateCompensatorRegulatingTerminal(StaticVarCompensatorCreationInfos staticVarCompensatorCreationInfos, StaticVarCompensator staticVarCompensator, From 8bd3d78cce43114f30d146b6f42426e37feeb9e7 Mon Sep 17 00:00:00 2001 From: Joris Mancini <53527338+TheMaskedTurtle@users.noreply.github.com> Date: Mon, 21 Oct 2024 11:25:40 +0200 Subject: [PATCH 3/4] chore: bump powsybl-network-store to v1.19.0 (#553) Signed-off-by: Joris Mancini --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 222be8f32..b31293589 100644 --- a/pom.xml +++ b/pom.xml @@ -50,7 +50,7 @@ 1.16.2 org.gridsuite.modification.server - 1.18.2 + 1.19.0 From 6a9d23c1d822b9a7d37a0ea9e083d976c0dbff05 Mon Sep 17 00:00:00 2001 From: Ghazoua Rehili Date: Wed, 23 Oct 2024 14:18:25 +0200 Subject: [PATCH 4/4] fix reporting susceptance or rective in cspr creation (#554) Signed-off-by: REHILI Ghazwa --- .../modifications/ModificationUtils.java | 15 ++- .../StaticVarCompensatorCreation.java | 90 +++++++------ ...arCompensatorCreationInBusBreakerTest.java | 6 +- ...rCompensatorCreationInNodeBreakerTest.java | 121 +++++++++++++++--- 4 files changed, 174 insertions(+), 58 deletions(-) diff --git a/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java b/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java index 05c81b1ec..ed69f35ae 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java @@ -1334,10 +1334,12 @@ public void checkReactivePowerLimitsAndSetPointsCreation(StaticVarCompensatorCre if (Objects.isNull(creationInfos.getMaxSusceptance()) && Objects.isNull(creationInfos.getMaxQAtNominalV())) { throw makeEquipmentException(creationInfos.getErrorType(), creationInfos.getEquipmentId(), equipmentName, "maximum susceptance is not set"); } - if (Objects.nonNull(creationInfos.getMaxSusceptance()) && Objects.nonNull(creationInfos.getMinSusceptance()) && creationInfos.getMaxSusceptance() < creationInfos.getMinSusceptance() || - Objects.nonNull(creationInfos.getMaxQAtNominalV()) && Objects.nonNull(creationInfos.getMinQAtNominalV()) && creationInfos.getMaxQAtNominalV() < creationInfos.getMinQAtNominalV()) { + if (Objects.nonNull(creationInfos.getMaxSusceptance()) && Objects.nonNull(creationInfos.getMinSusceptance()) && creationInfos.getMaxSusceptance() < creationInfos.getMinSusceptance()) { throw makeEquipmentException(creationInfos.getErrorType(), creationInfos.getEquipmentId(), equipmentName, "maximum susceptance is expected to be greater than or equal to minimum susceptance"); } + if (Objects.nonNull(creationInfos.getMaxQAtNominalV()) && Objects.nonNull(creationInfos.getMinQAtNominalV()) && creationInfos.getMaxQAtNominalV() < creationInfos.getMinQAtNominalV()) { + throw makeEquipmentException(creationInfos.getErrorType(), creationInfos.getEquipmentId(), equipmentName, "maximum Q at nominal voltage is expected to be greater than or equal to minimum Q"); + } // check set points if (Objects.requireNonNull(creationInfos.getRegulationMode()) == StaticVarCompensator.RegulationMode.VOLTAGE && creationInfos.getVoltageSetpoint() == null) { @@ -1354,11 +1356,14 @@ public void checkStandbyAutomatonCreation(StaticVarCompensatorCreationInfos crea throw makeEquipmentException(creationInfos.getErrorType(), creationInfos.getEquipmentId(), equipmentName, "Standby is only supported in Voltage Regulation mode"); } if (Objects.nonNull(creationInfos.getB0()) && Objects.nonNull(creationInfos.getMinSusceptance()) && Objects.nonNull(creationInfos.getMaxSusceptance()) && - (creationInfos.getB0() < creationInfos.getMinSusceptance() || creationInfos.getB0() > creationInfos.getMaxSusceptance()) - || Objects.nonNull(creationInfos.getQ0()) && Objects.nonNull(creationInfos.getMinQAtNominalV()) && Objects.nonNull(creationInfos.getMaxQAtNominalV()) && + (creationInfos.getB0() < creationInfos.getMinSusceptance() || creationInfos.getB0() > creationInfos.getMaxSusceptance())) { + throw makeEquipmentException(creationInfos.getErrorType(), creationInfos.getEquipmentId(), equipmentName, + "b0 must be within the range of minimum susceptance and maximum susceptance"); + } + if (Objects.nonNull(creationInfos.getQ0()) && Objects.nonNull(creationInfos.getMinQAtNominalV()) && Objects.nonNull(creationInfos.getMaxQAtNominalV()) && (creationInfos.getQ0() < creationInfos.getMinQAtNominalV() || creationInfos.getQ0() > creationInfos.getMaxQAtNominalV())) { throw makeEquipmentException(creationInfos.getErrorType(), creationInfos.getEquipmentId(), equipmentName, - "b0 must be within the range of minimun susceptance and maximum susceptance"); + "q0 must be within the range of minimum Q and maximum Q"); } } diff --git a/src/main/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreation.java b/src/main/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreation.java index 105ca92c9..3916fd326 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreation.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreation.java @@ -13,7 +13,6 @@ import com.powsybl.iidm.network.extensions.StandbyAutomatonAdder; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.StaticVarCompensatorCreationInfos; -import org.gridsuite.modification.server.dto.VoltageRegulationType; import java.util.ArrayList; import java.util.List; @@ -60,16 +59,6 @@ public void check(Network network) throws NetworkModificationException { public void apply(Network network, ReportNode subReportNode) { // create the static var compensator in the network VoltageLevel voltageLevel = ModificationUtils.getInstance().getVoltageLevel(network, modificationInfos.getVoltageLevelId()); - if (Objects.isNull(modificationInfos.getMaxSusceptance()) && Objects.nonNull(modificationInfos.getMaxQAtNominalV())) { - modificationInfos.setMaxSusceptance((modificationInfos.getMaxQAtNominalV()) / Math.pow(voltageLevel.getNominalV(), 2)); - } - if (Objects.isNull(modificationInfos.getMinSusceptance()) && Objects.nonNull(modificationInfos.getMinQAtNominalV())) { - modificationInfos.setMinSusceptance((modificationInfos.getMinQAtNominalV()) / Math.pow(voltageLevel.getNominalV(), 2)); - } - if (Boolean.TRUE.equals(modificationInfos.isStandbyAutomatonOn()) && Objects.isNull(modificationInfos.getB0()) - && Objects.nonNull(modificationInfos.getQ0())) { - modificationInfos.setB0((modificationInfos.getQ0()) / Math.pow(voltageLevel.getNominalV(), 2)); - } if (voltageLevel.getTopologyKind() == TopologyKind.NODE_BREAKER) { createStaticVarCompensatorInNodeBreaker(voltageLevel, modificationInfos, network, subReportNode); } else { @@ -99,12 +88,15 @@ private StaticVarCompensatorAdder createStaticVarCompensatorAdderInNodeBreaker(V staticVarCompensatorCreationInfos.getRegulatingTerminalId(), staticVarCompensatorCreationInfos.getRegulatingTerminalType(), staticVarCompensatorCreationInfos.getRegulatingTerminalVlId()); - + double bMax = Objects.isNull(staticVarCompensatorCreationInfos.getMaxSusceptance()) && Objects.nonNull(staticVarCompensatorCreationInfos.getMaxQAtNominalV()) ? + (staticVarCompensatorCreationInfos.getMaxQAtNominalV()) / Math.pow(voltageLevel.getNominalV(), 2) : staticVarCompensatorCreationInfos.getMaxSusceptance(); + double bMin = Objects.isNull(staticVarCompensatorCreationInfos.getMinSusceptance()) && Objects.nonNull(staticVarCompensatorCreationInfos.getMinQAtNominalV()) ? + (staticVarCompensatorCreationInfos.getMinQAtNominalV()) / Math.pow(voltageLevel.getNominalV(), 2) : staticVarCompensatorCreationInfos.getMinSusceptance(); StaticVarCompensatorAdder staticVarCompensatorAdder = voltageLevel.newStaticVarCompensator() .setId(staticVarCompensatorCreationInfos.getEquipmentId()) .setName(staticVarCompensatorCreationInfos.getEquipmentName()) - .setBmax(nanIfNull(staticVarCompensatorCreationInfos.getMaxSusceptance())) - .setBmin(nanIfNull(staticVarCompensatorCreationInfos.getMinSusceptance())) + .setBmax(bMax) + .setBmin(bMin) .setVoltageSetpoint(nanIfNull(staticVarCompensatorCreationInfos.getVoltageSetpoint())) .setReactivePowerSetpoint(nanIfNull(staticVarCompensatorCreationInfos.getReactivePowerSetpoint())) .setRegulationMode(staticVarCompensatorCreationInfos.getRegulationMode()); @@ -125,18 +117,20 @@ private void addExtensionsToStaticVarCompensator(StaticVarCompensatorCreationInf } reportInjectionCreationConnectivity(staticVarCompensatorCreationInfos, subReportNode); - createStaticVarCompensatorLimitsAndSetpoints(staticVarCompensatorCreationInfos, staticVarCompensator, voltageLevel, subReportNode); - reportStaticVarCompensatorStandbyAutomaton(staticVarCompensatorCreationInfos, staticVarCompensator, subReportNode); + reportStaticVarCompensatorLimitsAndSetpoints(staticVarCompensatorCreationInfos, staticVarCompensator, voltageLevel, subReportNode); + reportStaticVarCompensatorStandbyAutomaton(staticVarCompensatorCreationInfos, staticVarCompensator, voltageLevel, subReportNode); } private void reportStaticVarCompensatorStandbyAutomaton(StaticVarCompensatorCreationInfos staticVarCompensatorCreationInfos, - StaticVarCompensator staticVarCompensator, ReportNode subReportNode) { + StaticVarCompensator staticVarCompensator, VoltageLevel voltageLevel, ReportNode subReportNode) { if (Boolean.TRUE.equals(staticVarCompensatorCreationInfos.isStandbyAutomatonOn())) { List standbyAutomatonReports = new ArrayList<>(); + double b0 = Objects.isNull(staticVarCompensatorCreationInfos.getB0()) && Objects.nonNull(staticVarCompensatorCreationInfos.getQ0()) ? + (staticVarCompensatorCreationInfos.getQ0()) / Math.pow(voltageLevel.getNominalV(), 2) : staticVarCompensatorCreationInfos.getB0(); try { staticVarCompensator.newExtension(StandbyAutomatonAdder.class) .withStandbyStatus(staticVarCompensatorCreationInfos.isStandby()) - .withB0(staticVarCompensatorCreationInfos.getB0()) + .withB0(b0) .withLowVoltageSetpoint(staticVarCompensatorCreationInfos.getLowVoltageSetpoint()) .withHighVoltageSetpoint(staticVarCompensatorCreationInfos.getHighVoltageSetpoint()) .withLowVoltageThreshold(staticVarCompensatorCreationInfos.getLowVoltageThreshold()) @@ -145,9 +139,16 @@ private void reportStaticVarCompensatorStandbyAutomaton(StaticVarCompensatorCrea standbyAutomatonReports.add(ModificationUtils.getInstance().buildCreationReport( staticVarCompensatorCreationInfos.isStandby(), "Standby")); - standbyAutomatonReports.add(ModificationUtils.getInstance().buildCreationReport( - staticVarCompensatorCreationInfos.getB0(), - "Fixed part of susceptance")); + if (Objects.nonNull(staticVarCompensatorCreationInfos.getB0())) { + standbyAutomatonReports.add(ModificationUtils.getInstance().buildCreationReport( + staticVarCompensatorCreationInfos.getB0(), + "Fixed part of susceptance")); + } + if (Objects.nonNull(staticVarCompensatorCreationInfos.getQ0())) { + standbyAutomatonReports.add(ModificationUtils.getInstance().buildCreationReport( + staticVarCompensatorCreationInfos.getQ0(), + "Fixed part of Q at nominal voltage")); + } standbyAutomatonReports.add(ModificationUtils.getInstance().buildCreationReport( staticVarCompensatorCreationInfos.getLowVoltageSetpoint(), "Low voltage set point")); @@ -163,12 +164,10 @@ private void reportStaticVarCompensatorStandbyAutomaton(StaticVarCompensatorCrea } catch (PowsyblException e) { standbyAutomatonReports.add(ReportNode.newRootReportNode() .withMessageTemplate("StandbyAutomatonExtensionAddError", - "Cannot add standby automaton extension on static var compensator with id=${id} : ${message}") - .withUntypedValue("id", staticVarCompensatorCreationInfos.getEquipmentId()) + "Cannot add standby automaton extension on ${message}") .withUntypedValue("message", e.getMessage()) .withSeverity(TypedValue.ERROR_SEVERITY) .build()); - } ModificationUtils.getInstance().reportModifications(subReportNode, standbyAutomatonReports, "StandbyAutomatonCreated", "Standby automaton"); @@ -179,14 +178,18 @@ private void createStaticVarCompensatorInBusBreaker(VoltageLevel voltageLevel, S ReportNode subReportNode) { Bus bus = ModificationUtils.getInstance().getBusBreakerBus(voltageLevel, staticVarCompensatorCreationInfos.getBusOrBusbarSectionId()); + double bMax = Objects.isNull(staticVarCompensatorCreationInfos.getMaxSusceptance()) && Objects.nonNull(staticVarCompensatorCreationInfos.getMaxQAtNominalV()) ? + (staticVarCompensatorCreationInfos.getMaxQAtNominalV()) / Math.pow(voltageLevel.getNominalV(), 2) : staticVarCompensatorCreationInfos.getMaxSusceptance(); + double bMin = Objects.isNull(staticVarCompensatorCreationInfos.getMinSusceptance()) && Objects.nonNull(staticVarCompensatorCreationInfos.getMinQAtNominalV()) ? + (staticVarCompensatorCreationInfos.getMinQAtNominalV()) / Math.pow(voltageLevel.getNominalV(), 2) : staticVarCompensatorCreationInfos.getMinSusceptance(); /* creating the static var compensator */ StaticVarCompensator staticVarCompensator = voltageLevel.newStaticVarCompensator() .setId(staticVarCompensatorCreationInfos.getEquipmentId()) .setName(staticVarCompensatorCreationInfos.getEquipmentName()) .setBus(bus.getId()) .setConnectableBus(bus.getId()) - .setBmax(staticVarCompensatorCreationInfos.getMaxSusceptance()) - .setBmin(staticVarCompensatorCreationInfos.getMinSusceptance()) + .setBmax(bMax) + .setBmin(bMin) .setVoltageSetpoint(staticVarCompensatorCreationInfos.getVoltageSetpoint()) .setReactivePowerSetpoint(staticVarCompensatorCreationInfos.getReactivePowerSetpoint()) .setRegulationMode(staticVarCompensatorCreationInfos.getRegulationMode()) @@ -195,18 +198,33 @@ private void createStaticVarCompensatorInBusBreaker(VoltageLevel voltageLevel, S addExtensionsToStaticVarCompensator(staticVarCompensatorCreationInfos, staticVarCompensator, voltageLevel, subReportNode); } - private void createStaticVarCompensatorLimitsAndSetpoints(StaticVarCompensatorCreationInfos staticVarCompensatorCreationInfos, + private void reportStaticVarCompensatorLimitsAndSetpoints(StaticVarCompensatorCreationInfos staticVarCompensatorCreationInfos, StaticVarCompensator staticVarCompensator, VoltageLevel voltageLevel, ReportNode subReportNode) { List voltageReports = new ArrayList<>(); - voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getMinSusceptance(), "Susceptance min")); - voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getMaxSusceptance(), "Susceptance max")); - voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getMinQAtNominalV(), "Q min at nominal voltage")); - voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getMaxQAtNominalV(), "Q max at nominal voltage")); - voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getVoltageSetpoint(), "Voltage set point")); - voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getReactivePowerSetpoint(), "Reactive power set point")); - voltageReports.add(ModificationUtils.getInstance() - .createEnabledDisabledReport("VoltageRegulationOn", modificationInfos.getVoltageRegulationType() == VoltageRegulationType.DISTANT && - modificationInfos.getRegulationMode() == StaticVarCompensator.RegulationMode.VOLTAGE)); + if (Objects.nonNull(staticVarCompensatorCreationInfos.getMinSusceptance())) { + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getMinSusceptance(), "Susceptance min")); + } + if (Objects.nonNull(staticVarCompensatorCreationInfos.getMaxSusceptance())) { + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getMaxSusceptance(), "Susceptance max")); + } + if (Objects.nonNull(staticVarCompensatorCreationInfos.getMinQAtNominalV())) { + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getMinQAtNominalV(), "Q min at nominal voltage")); + } + if (Objects.nonNull(staticVarCompensatorCreationInfos.getMaxQAtNominalV())) { + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getMaxQAtNominalV(), "Q max at nominal voltage")); + } + if (Objects.nonNull(staticVarCompensatorCreationInfos.getRegulationMode())) { + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getRegulationMode(), "regulation mode")); + } + if (Objects.nonNull(staticVarCompensatorCreationInfos.getVoltageSetpoint())) { + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getVoltageSetpoint(), "Voltage set point")); + } + if (Objects.nonNull(staticVarCompensatorCreationInfos.getReactivePowerSetpoint())) { + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getReactivePowerSetpoint(), "Reactive power set point")); + } + if (Objects.nonNull(staticVarCompensatorCreationInfos.getVoltageRegulationType())) { + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getVoltageRegulationType(), "Voltage Regulation type")); + } if (staticVarCompensatorCreationInfos.getRegulatingTerminalVlId() != null && staticVarCompensatorCreationInfos.getRegulatingTerminalId() != null && staticVarCompensatorCreationInfos.getRegulatingTerminalType() != null) { Terminal terminal = ModificationUtils.getInstance().getTerminalFromIdentifiable(voltageLevel.getNetwork(), diff --git a/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInBusBreakerTest.java b/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInBusBreakerTest.java index d1b9ee08d..3b6829e8f 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInBusBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInBusBreakerTest.java @@ -56,8 +56,10 @@ protected ModificationInfos buildModification() { .busOrBusbarSectionId("bus1") .connectionName("top") .connectionDirection(ConnectablePosition.Direction.TOP) - .maxSusceptance(224.0) - .minSusceptance(200.0) + .maxSusceptance(null) + .minSusceptance(null) + .maxQAtNominalV(224.0) + .minQAtNominalV(200.0) .regulationMode(StaticVarCompensator.RegulationMode.VOLTAGE) .voltageSetpoint(120.0) .reactivePowerSetpoint(300.0) diff --git a/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInNodeBreakerTest.java b/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInNodeBreakerTest.java index eed31aafb..933883f76 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInNodeBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInNodeBreakerTest.java @@ -25,8 +25,8 @@ import java.util.UUID; import static com.powsybl.iidm.network.StaticVarCompensator.RegulationMode.OFF; -import static org.gridsuite.modification.server.NetworkModificationException.Type.BUSBAR_SECTION_NOT_FOUND; -import static org.gridsuite.modification.server.NetworkModificationException.Type.VOLTAGE_LEVEL_NOT_FOUND; +import static com.powsybl.iidm.network.StaticVarCompensator.RegulationMode.VOLTAGE; +import static org.gridsuite.modification.server.NetworkModificationException.Type.*; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -58,6 +58,8 @@ protected ModificationInfos buildModification() { .connectionDirection(ConnectablePosition.Direction.TOP) .maxSusceptance(224.0) .minSusceptance(200.0) + .maxQAtNominalV(null) + .minQAtNominalV(null) .regulationMode(StaticVarCompensator.RegulationMode.VOLTAGE) .voltageSetpoint(120.0) .reactivePowerSetpoint(300.0) @@ -73,17 +75,22 @@ protected ModificationInfos buildModificationUpdate() { .stashed(false) .equipmentId("idStaticVarCompensator1Edited") .equipmentName("staticVarCompensatorNameEdited") + .maxSusceptance(null) + .minSusceptance(null) + .maxQAtNominalV(224.0) + .minQAtNominalV(200.0) .standbyAutomatonOn(true) .standby(true) - .b0(221.0) + .b0(null) + .q0(221.0) .lowVoltageSetpoint(200.0) .highVoltageSetpoint(400.0) .lowVoltageThreshold(250.0) .highVoltageThreshold(300.0) + .regulatingTerminalId("idGenerator1") + .regulatingTerminalType("GENERATOR") + .regulatingTerminalVlId("v1") .voltageRegulationType(VoltageRegulationType.DISTANT) - .regulatingTerminalId("idStaticVarCompensator1") - .regulatingTerminalType("STATIC_VAR_COMPENSATOR") - .regulatingTerminalVlId("v2") .build(); } @@ -112,6 +119,15 @@ public void testCreateWithErrors() throws Exception { .andExpect(status().isOk()); assertLogMessage("Invalid id ''", compensatorCreationInfos.getErrorType().name(), reportService); + // try to create an existing cspr + compensatorCreationInfos = (StaticVarCompensatorCreationInfos) buildModification(); + compensatorCreationInfos.setEquipmentId("v5Compensator"); + compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + assertLogMessage(new NetworkModificationException(STATIC_VAR_COMPENSATOR_ALREADY_EXISTS, "v5Compensator").getMessage(), + compensatorCreationInfos.getErrorType().name(), reportService); + // not found voltage level compensatorCreationInfos.setEquipmentId("idStaticVarCompensator2"); compensatorCreationInfos.setVoltageLevelId("notFoundVoltageLevelId"); @@ -144,6 +160,7 @@ public void testCreateWithErrors() throws Exception { compensatorCreationInfos.setMinSusceptance(200.0); compensatorCreationInfos.setMaxSusceptance(null); compensatorCreationInfos.setMaxQAtNominalV(null); + compensatorCreationInfos.setMinQAtNominalV(null); compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); @@ -161,8 +178,18 @@ public void testCreateWithErrors() throws Exception { assertLogMessage("CREATE_STATIC_VAR_COMPENSATOR_ERROR : " + "StaticVarCompensator 'idStaticVarCompensator2' : maximum susceptance is expected to be greater than or equal to minimum susceptance", compensatorCreationInfos.getErrorType().name(), reportService); - compensatorCreationInfos.setMaxSusceptance(200.0); - compensatorCreationInfos.setMinSusceptance(100.0); + compensatorCreationInfos.setMaxSusceptance(null); + compensatorCreationInfos.setMinSusceptance(null); + compensatorCreationInfos.setMaxQAtNominalV(200.0); + compensatorCreationInfos.setMinQAtNominalV(300.0); + compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + assertLogMessage("CREATE_STATIC_VAR_COMPENSATOR_ERROR : " + + "StaticVarCompensator 'idStaticVarCompensator2' : maximum Q at nominal voltage is expected to be greater than or equal to minimum Q", + compensatorCreationInfos.getErrorType().name(), reportService); + compensatorCreationInfos.setMaxQAtNominalV(200.0); + compensatorCreationInfos.setMinQAtNominalV(100.0); compensatorCreationInfos.setRegulationMode(StaticVarCompensator.RegulationMode.REACTIVE_POWER); compensatorCreationInfos.setReactivePowerSetpoint(null); compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); @@ -191,23 +218,77 @@ public void testCreateWithErrors() throws Exception { }); assertTrue(networkModificationResult.isEmpty()); assertNull(getNetwork().getStaticVarCompensator("idStaticVarCompensator3")); - testNetworkModificationsCount(getGroupId(), 9); + compensatorCreationInfos = StaticVarCompensatorCreationInfos.builder() + .stashed(false) + .equipmentId("idStaticVarCompensator3") + .equipmentName("nameStaticVarCompensator3") + .voltageLevelId("v2") + .busOrBusbarSectionId("1B") + .maxQAtNominalV(224.0) + .minQAtNominalV(200.0) + .lowVoltageSetpoint(200.0) + .highVoltageSetpoint(400.0) + .lowVoltageThreshold(250.0) + .highVoltageThreshold(300.0) + .q0(210.0) + .standbyAutomatonOn(true) + .build(); + compensatorCreationInfos.setEquipmentId("idStaticVarCompensator3"); + compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + testNetworkModificationsCount(getGroupId(), 12); } @Test public void testCreateWithStandbyAutomatonErrors() throws Exception { StaticVarCompensatorCreationInfos compensatorCreationInfos = (StaticVarCompensatorCreationInfos) buildModification(); compensatorCreationInfos.setStandbyAutomatonOn(true); - compensatorCreationInfos.setB0(300.0); - + compensatorCreationInfos.setMaxSusceptance(null); + compensatorCreationInfos.setMinSusceptance(null); + compensatorCreationInfos.setMinQAtNominalV(200.0); + compensatorCreationInfos.setMaxQAtNominalV(300.0); + compensatorCreationInfos.setLowVoltageSetpoint(200.0); + compensatorCreationInfos.setHighVoltageSetpoint(400.0); + compensatorCreationInfos.setLowVoltageThreshold(250.0); + compensatorCreationInfos.setHighVoltageThreshold(300.0); + compensatorCreationInfos.setQ0(Double.NaN); String compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + assertLogMessage("Cannot add standby automaton extension on Static var compensator 'idStaticVarCompensator1': b0 is invalid", + "StandbyAutomatonExtensionAddError", reportService); + compensatorCreationInfos = (StaticVarCompensatorCreationInfos) buildModification(); + compensatorCreationInfos.setEquipmentId("idStaticVarCompensator2"); + compensatorCreationInfos.setStandbyAutomatonOn(true); + compensatorCreationInfos.setMaxSusceptance(null); + compensatorCreationInfos.setMinSusceptance(null); + compensatorCreationInfos.setMinQAtNominalV(200.0); + compensatorCreationInfos.setMaxQAtNominalV(300.0); + compensatorCreationInfos.setLowVoltageSetpoint(200.0); + compensatorCreationInfos.setHighVoltageSetpoint(400.0); + compensatorCreationInfos.setLowVoltageThreshold(250.0); + compensatorCreationInfos.setHighVoltageThreshold(300.0); + compensatorCreationInfos.setQ0(400.0); + + compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); assertLogMessage("CREATE_STATIC_VAR_COMPENSATOR_ERROR : " + - "StaticVarCompensator 'idStaticVarCompensator1' : b0 must be within the range of minimun susceptance and maximum susceptance", + "StaticVarCompensator 'idStaticVarCompensator2' : q0 must be within the range of minimum Q and maximum Q", + compensatorCreationInfos.getErrorType().name(), reportService); + compensatorCreationInfos.setMinQAtNominalV(null); + compensatorCreationInfos.setMaxQAtNominalV(null); + compensatorCreationInfos.setMaxSusceptance(300.0); + compensatorCreationInfos.setMinSusceptance(200.0); + compensatorCreationInfos.setB0(400.0); + compensatorCreationInfos.setQ0(null); + compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + assertLogMessage("CREATE_STATIC_VAR_COMPENSATOR_ERROR : " + + "StaticVarCompensator 'idStaticVarCompensator2' : b0 must be within the range of minimum susceptance and maximum susceptance", compensatorCreationInfos.getErrorType().name(), reportService); - - compensatorCreationInfos.setB0(200.0); compensatorCreationInfos.setRegulationMode(OFF); compensatorCreationInfos.setStandby(true); @@ -215,8 +296,18 @@ public void testCreateWithStandbyAutomatonErrors() throws Exception { mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); assertLogMessage("CREATE_STATIC_VAR_COMPENSATOR_ERROR : " + - "StaticVarCompensator 'idStaticVarCompensator1' : Standby is only supported in Voltage Regulation mode", + "StaticVarCompensator 'idStaticVarCompensator2' : Standby is only supported in Voltage Regulation mode", compensatorCreationInfos.getErrorType().name(), reportService); + compensatorCreationInfos.setRegulationMode(VOLTAGE); + compensatorCreationInfos.setB0(null); + compensatorCreationInfos.setQ0(200.0); + compensatorCreationInfos.setLowVoltageSetpoint(200.0); + compensatorCreationInfos.setHighVoltageSetpoint(400.0); + compensatorCreationInfos.setLowVoltageThreshold(250.0); + compensatorCreationInfos.setHighVoltageThreshold(300.0); + compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); }