From 41ec5c2c0ded7293448c7d5ae7dc0f648d2dfe72 Mon Sep 17 00:00:00 2001 From: Ghazoua Rehili Date: Thu, 19 Sep 2024 17:11:14 +0200 Subject: [PATCH 1/2] implement connectablePosition modification for branch form (#530) Signed-off-by: Ghazwa Rehili --- .../server/dto/BranchModificationInfos.java | 35 +- .../BranchModificationEntity.java | 95 ++++- .../modification/LineModificationEntity.java | 14 +- ...WindingsTransformerModificationEntity.java | 14 +- .../AbstractBranchModification.java | 19 +- .../modifications/ModificationUtils.java | 327 +++++++++++------- .../changesets/changelog_20240904T211456Z.xml | 127 +++++++ .../db/changelog/db.changelog-master.yaml | 3 + .../modifications/LineModificationTest.java | 15 +- ...woWindingsTransformerModificationTest.java | 15 +- 10 files changed, 526 insertions(+), 138 deletions(-) create mode 100644 src/main/resources/db/changelog/changesets/changelog_20240904T211456Z.xml diff --git a/src/main/java/org/gridsuite/modification/server/dto/BranchModificationInfos.java b/src/main/java/org/gridsuite/modification/server/dto/BranchModificationInfos.java index 97605d817..50a4eae5c 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/BranchModificationInfos.java +++ b/src/main/java/org/gridsuite/modification/server/dto/BranchModificationInfos.java @@ -5,6 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.gridsuite.modification.server.dto; +import com.powsybl.iidm.network.extensions.ConnectablePosition; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.NoArgsConstructor; @@ -35,9 +36,39 @@ public class BranchModificationInfos extends BasicEquipmentModificationInfos { @Schema(description = "Current limits Side 2") private CurrentLimitsModificationInfos currentLimits2; + @Schema(description = "Voltage level id modification 1") + private AttributeModification voltageLevelId1; + + @Schema(description = "Voltage level id modification 2") + private AttributeModification voltageLevelId2; + + @Schema(description = "Bus id modification 1") + private AttributeModification busOrBusbarSectionId1; + + @Schema(description = "Bus id modification 2") + private AttributeModification busOrBusbarSectionId2; + + @Schema(description = "Connection Name 1") + private AttributeModification connectionName1; + + @Schema(description = "Connection Name 2") + private AttributeModification connectionName2; + + @Schema(description = "Connection Direction 1") + private AttributeModification connectionDirection1; + + @Schema(description = "Connection Direction 2") + private AttributeModification connectionDirection2; + + @Schema(description = "Connection Position 1") + private AttributeModification connectionPosition1; + + @Schema(description = "Connection Position 2") + private AttributeModification connectionPosition2; + @Schema(description = "Connected 1") - private AttributeModification connected1; + private AttributeModification terminal1Connected; @Schema(description = "Connected 2") - private AttributeModification connected2; + private AttributeModification terminal2Connected; } diff --git a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/BranchModificationEntity.java b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/BranchModificationEntity.java index 672d4d433..128341b55 100644 --- a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/BranchModificationEntity.java +++ b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/BranchModificationEntity.java @@ -6,14 +6,13 @@ */ package org.gridsuite.modification.server.entities.equipment.modification; +import com.powsybl.iidm.network.extensions.ConnectablePosition; +import jakarta.persistence.*; import lombok.Getter; import lombok.NoArgsConstructor; import org.gridsuite.modification.server.dto.BranchModificationInfos; import org.gridsuite.modification.server.dto.ModificationInfos; -import org.gridsuite.modification.server.entities.equipment.modification.attribute.BooleanModificationEmbedded; -import org.gridsuite.modification.server.entities.equipment.modification.attribute.DoubleModificationEmbedded; - -import jakarta.persistence.*; +import org.gridsuite.modification.server.entities.equipment.modification.attribute.*; /** * @author Ayoub LABIDI @@ -53,19 +52,89 @@ public class BranchModificationEntity extends BasicEquipmentModificationEntity { ), nullable = true) private CurrentLimitsModificationEntity currentLimits2; + @Embedded + @AttributeOverrides(value = { + @AttributeOverride(name = "value", column = @Column(name = "voltageLevelId1")), + @AttributeOverride(name = "opType", column = @Column(name = "voltageLevelId1Op")) + }) + private StringModificationEmbedded voltageLevelId1; + + @Embedded + @AttributeOverrides(value = { + @AttributeOverride(name = "value", column = @Column(name = "voltageLevelId2")), + @AttributeOverride(name = "opType", column = @Column(name = "voltageLevelId2Op")) + }) + private StringModificationEmbedded voltageLevelId2; + + @Embedded + @AttributeOverrides(value = { + @AttributeOverride(name = "value", column = @Column(name = "busOrBusbarSectionId1")), + @AttributeOverride(name = "opType", column = @Column(name = "busOrBusbarSectionId1Op")) + }) + private StringModificationEmbedded busOrBusbarSectionId1; + + @Embedded + @AttributeOverrides(value = { + @AttributeOverride(name = "value", column = @Column(name = "busOrBusbarSectionId2")), + @AttributeOverride(name = "opType", column = @Column(name = "busOrBusbarSectionId2Op")) + }) + private StringModificationEmbedded busOrBusbarSectionId2; + + @Embedded + @AttributeOverrides(value = { + @AttributeOverride(name = "value", column = @Column(name = "connectionName1")), + @AttributeOverride(name = "opType", column = @Column(name = "connectionName1Op")) + }) + private StringModificationEmbedded connectionName1; + + @Embedded + @AttributeOverrides(value = { + @AttributeOverride(name = "value", column = @Column(name = "connectionName2")), + @AttributeOverride(name = "opType", column = @Column(name = "connectionName2Op")) + }) + private StringModificationEmbedded connectionName2; + + @Embedded + @AttributeOverrides(value = { + @AttributeOverride(name = "value", column = @Column(name = "connectionPosition1")), + @AttributeOverride(name = "opType", column = @Column(name = "connectionPosition1Op")) + }) + private IntegerModificationEmbedded connectionPosition1; + + @Embedded + @AttributeOverrides(value = { + @AttributeOverride(name = "value", column = @Column(name = "connectionPosition2")), + @AttributeOverride(name = "opType", column = @Column(name = "connectionPosition2Op")) + }) + private IntegerModificationEmbedded connectionPosition2; + + @Embedded + @AttributeOverrides(value = { + @AttributeOverride(name = "value", column = @Column(name = "connectionDirection1")), + @AttributeOverride(name = "opType", column = @Column(name = "connectionDirection1Op")) + }) + private EnumModificationEmbedded connectionDirection1; + + @Embedded + @AttributeOverrides(value = { + @AttributeOverride(name = "value", column = @Column(name = "connectionDirection2")), + @AttributeOverride(name = "opType", column = @Column(name = "connectionDirection2Op")) + }) + private EnumModificationEmbedded connectionDirection2; + @Embedded @AttributeOverrides(value = { @AttributeOverride(name = "value", column = @Column(name = "connected1")), @AttributeOverride(name = "opType", column = @Column(name = "connected1Op")) }) - private BooleanModificationEmbedded connected1; + private BooleanModificationEmbedded terminal1Connected; @Embedded @AttributeOverrides(value = { @AttributeOverride(name = "value", column = @Column(name = "connected2")), @AttributeOverride(name = "opType", column = @Column(name = "connected2Op")) }) - private BooleanModificationEmbedded connected2; + private BooleanModificationEmbedded terminal2Connected; protected BranchModificationEntity(BranchModificationInfos branchModificationInfos) { super(branchModificationInfos); @@ -92,7 +161,17 @@ private void assignAttributes(BranchModificationInfos branchModificationInfos) { } else { currentLimits2 = branchModificationInfos.getCurrentLimits2().toEntity(); } - this.connected1 = branchModificationInfos.getConnected1() != null ? new BooleanModificationEmbedded(branchModificationInfos.getConnected1()) : null; - this.connected2 = branchModificationInfos.getConnected2() != null ? new BooleanModificationEmbedded(branchModificationInfos.getConnected2()) : null; + this.voltageLevelId1 = branchModificationInfos.getVoltageLevelId1() != null ? new StringModificationEmbedded(branchModificationInfos.getVoltageLevelId1()) : null; + this.voltageLevelId2 = branchModificationInfos.getVoltageLevelId2() != null ? new StringModificationEmbedded(branchModificationInfos.getVoltageLevelId2()) : null; + this.busOrBusbarSectionId1 = branchModificationInfos.getBusOrBusbarSectionId1() != null ? new StringModificationEmbedded(branchModificationInfos.getBusOrBusbarSectionId1()) : null; + this.busOrBusbarSectionId2 = branchModificationInfos.getBusOrBusbarSectionId2() != null ? new StringModificationEmbedded(branchModificationInfos.getBusOrBusbarSectionId2()) : null; + this.connectionName1 = branchModificationInfos.getConnectionName1() != null ? new StringModificationEmbedded(branchModificationInfos.getConnectionName1()) : null; + this.connectionName2 = branchModificationInfos.getConnectionName2() != null ? new StringModificationEmbedded(branchModificationInfos.getConnectionName2()) : null; + this.connectionDirection1 = branchModificationInfos.getConnectionDirection1() != null ? new EnumModificationEmbedded<>(branchModificationInfos.getConnectionDirection1()) : null; + this.connectionDirection2 = branchModificationInfos.getConnectionDirection2() != null ? new EnumModificationEmbedded<>(branchModificationInfos.getConnectionDirection2()) : null; + this.connectionPosition1 = branchModificationInfos.getConnectionPosition1() != null ? new IntegerModificationEmbedded(branchModificationInfos.getConnectionPosition1()) : null; + this.connectionPosition2 = branchModificationInfos.getConnectionPosition2() != null ? new IntegerModificationEmbedded(branchModificationInfos.getConnectionPosition2()) : null; + this.terminal1Connected = branchModificationInfos.getTerminal1Connected() != null ? new BooleanModificationEmbedded(branchModificationInfos.getTerminal1Connected()) : null; + this.terminal2Connected = branchModificationInfos.getTerminal2Connected() != null ? new BooleanModificationEmbedded(branchModificationInfos.getTerminal2Connected()) : null; } } diff --git a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/LineModificationEntity.java b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/LineModificationEntity.java index a7f79a584..da4d92024 100644 --- a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/LineModificationEntity.java +++ b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/LineModificationEntity.java @@ -88,8 +88,18 @@ public LineModificationInfos toModificationInfos() { .activated(getActivated()) .equipmentId(getEquipmentId()) .equipmentName(AttributeModification.toAttributeModification(getEquipmentNameValue(), getEquipmentNameOp())) - .connected1(toAttributeModification(getConnected1())) - .connected2(toAttributeModification(getConnected2())) + .voltageLevelId1(toAttributeModification(getVoltageLevelId1())) + .voltageLevelId2(toAttributeModification(getVoltageLevelId2())) + .busOrBusbarSectionId1(toAttributeModification(getBusOrBusbarSectionId1())) + .busOrBusbarSectionId2(toAttributeModification(getBusOrBusbarSectionId2())) + .connectionName1(toAttributeModification(getConnectionName1())) + .connectionName2(toAttributeModification(getConnectionName2())) + .connectionDirection1(toAttributeModification(getConnectionDirection1())) + .connectionDirection2(toAttributeModification(getConnectionDirection2())) + .connectionPosition1(toAttributeModification(getConnectionPosition1())) + .connectionPosition2(toAttributeModification(getConnectionPosition2())) + .terminal1Connected(toAttributeModification(getTerminal1Connected())) + .terminal2Connected(toAttributeModification(getTerminal2Connected())) .r(toAttributeModification(getR())) .x(toAttributeModification(getX())) .g1(toAttributeModification(getG1())) diff --git a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/TwoWindingsTransformerModificationEntity.java b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/TwoWindingsTransformerModificationEntity.java index 8a96f8b51..95e106e2f 100644 --- a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/TwoWindingsTransformerModificationEntity.java +++ b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/TwoWindingsTransformerModificationEntity.java @@ -355,8 +355,18 @@ public TwoWindingsTransformerModificationInfos toModificationInfos() { .activated(getActivated()) .equipmentId(getEquipmentId()) .equipmentName(AttributeModification.toAttributeModification(getEquipmentNameValue(), getEquipmentNameOp())) - .connected1(toAttributeModification(getConnected1())) - .connected2(toAttributeModification(getConnected2())) + .voltageLevelId1(toAttributeModification(getVoltageLevelId1())) + .voltageLevelId2(toAttributeModification(getVoltageLevelId2())) + .busOrBusbarSectionId1(toAttributeModification(getBusOrBusbarSectionId1())) + .busOrBusbarSectionId2(toAttributeModification(getBusOrBusbarSectionId2())) + .connectionName1(toAttributeModification(getConnectionName1())) + .connectionName2(toAttributeModification(getConnectionName2())) + .connectionDirection1(toAttributeModification(getConnectionDirection1())) + .connectionDirection2(toAttributeModification(getConnectionDirection2())) + .connectionPosition1(toAttributeModification(getConnectionPosition1())) + .connectionPosition2(toAttributeModification(getConnectionPosition2())) + .terminal1Connected(toAttributeModification(getTerminal1Connected())) + .terminal2Connected(toAttributeModification(getTerminal2Connected())) .r(AttributeModification.toAttributeModification(getR())) .x(AttributeModification.toAttributeModification(getX())) .g(AttributeModification.toAttributeModification(getG())) diff --git a/src/main/java/org/gridsuite/modification/server/modifications/AbstractBranchModification.java b/src/main/java/org/gridsuite/modification/server/modifications/AbstractBranchModification.java index 1b69f73ed..a3305ef26 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/AbstractBranchModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/AbstractBranchModification.java @@ -10,6 +10,8 @@ import com.powsybl.commons.report.ReportNode; import com.powsybl.commons.report.TypedValue; import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.extensions.ConnectablePosition; +import com.powsybl.iidm.network.extensions.ConnectablePositionAdder; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.BranchModificationInfos; import org.gridsuite.modification.server.dto.CurrentLimitsModificationInfos; @@ -48,6 +50,8 @@ protected void modifyBranch(Branch branch, BranchModificationInfos branchModi branch.setName(branchModificationInfos.getEquipmentName().getValue()); } + modifyBranchConnectivityAttributes(branchModificationInfos, branch, subReportNode); + if (characteristicsModified(branchModificationInfos)) { modifyCharacteristics(branch, branchModificationInfos, subReportNode); } @@ -78,13 +82,13 @@ protected void modifyBranch(Branch branch, BranchModificationInfos branchModi private void updateConnections(Branch branch, BranchModificationInfos branchModificationInfos) { List errorSides = new ArrayList<>(); List errorTypes = new ArrayList<>(); - if (branchModificationInfos.getConnected1() != null && !updateConnection(branch, TwoSides.ONE, modificationInfos.getConnected1().getValue())) { + if (branchModificationInfos.getTerminal1Connected() != null && !updateConnection(branch, TwoSides.ONE, modificationInfos.getTerminal1Connected().getValue())) { errorSides.add(TwoSides.ONE); - errorTypes.add(Boolean.TRUE.equals(modificationInfos.getConnected1().getValue()) ? "connect" : "disconnect"); + errorTypes.add(Boolean.TRUE.equals(modificationInfos.getTerminal1Connected().getValue()) ? "connect" : "disconnect"); } - if (branchModificationInfos.getConnected2() != null && !updateConnection(branch, TwoSides.TWO, modificationInfos.getConnected2().getValue())) { + if (branchModificationInfos.getTerminal2Connected() != null && !updateConnection(branch, TwoSides.TWO, modificationInfos.getTerminal2Connected().getValue())) { errorSides.add(TwoSides.TWO); - errorTypes.add(Boolean.TRUE.equals(modificationInfos.getConnected2().getValue()) ? "connect" : "disconnect"); + errorTypes.add(Boolean.TRUE.equals(modificationInfos.getTerminal2Connected().getValue()) ? "connect" : "disconnect"); } if (!errorSides.isEmpty()) { throw new NetworkModificationException(BRANCH_MODIFICATION_ERROR, @@ -219,4 +223,11 @@ protected boolean characteristicsModified(BranchModificationInfos branchModifica protected abstract void modifyCharacteristics(Branch branch, BranchModificationInfos branchModificationInfos, ReportNode subReportNode); + + private ReportNode modifyBranchConnectivityAttributes(BranchModificationInfos branchModificationInfos, + Branch branch, ReportNode subReportNode) { + ConnectablePosition connectablePosition = (ConnectablePosition) branch.getExtension(ConnectablePosition.class); + ConnectablePositionAdder connectablePositionAdder = branch.newExtension(ConnectablePositionAdder.class); + return ModificationUtils.getInstance().modifyBranchConnectivityAttributes(connectablePosition, connectablePositionAdder, branch, branchModificationInfos, subReportNode); + } } 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 02a6b04b5..92d4e588a 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java @@ -54,6 +54,7 @@ public final class ModificationUtils { public static final String CONNECTION_NAME_FIELD_NAME = "Connection name"; public static final String CONNECTION_DIRECTION_FIELD_NAME = "Connection direction"; public static final String CONNECTION_POSITION_FIELD_NAME = "Connection position"; + public static final String NOT_EXIST_IN_NETWORK = " does not exist in network"; private ModificationUtils() { } @@ -89,7 +90,7 @@ Line getLine(Network network, String lineId) { Battery getBattery(Network network, String batteryId) { Battery battery = network.getBattery(batteryId); if (battery == null) { - throw new NetworkModificationException(BATTERY_NOT_FOUND, "Battery " + batteryId + " does not exist in network"); + throw new NetworkModificationException(BATTERY_NOT_FOUND, "Battery " + batteryId + NOT_EXIST_IN_NETWORK); } return battery; } @@ -97,7 +98,7 @@ Battery getBattery(Network network, String batteryId) { Generator getGenerator(Network network, String generatorId) { Generator generator = network.getGenerator(generatorId); if (generator == null) { - throw new NetworkModificationException(GENERATOR_NOT_FOUND, "Generator " + generatorId + " does not exist in network"); + throw new NetworkModificationException(GENERATOR_NOT_FOUND, "Generator " + generatorId + NOT_EXIST_IN_NETWORK); } return generator; } @@ -105,7 +106,7 @@ Generator getGenerator(Network network, String generatorId) { VscConverterStation getVscConverterStation(Network network, String converterStationId) { VscConverterStation vscConverterStation = network.getVscConverterStation(converterStationId); if (vscConverterStation == null) { - throw new NetworkModificationException(VSC_CONVERTER_STATION_NOT_FOUND, "Vsc converter station " + converterStationId + " does not exist in network"); + throw new NetworkModificationException(VSC_CONVERTER_STATION_NOT_FOUND, "Vsc converter station " + converterStationId + NOT_EXIST_IN_NETWORK); } return vscConverterStation; } @@ -114,7 +115,7 @@ VscConverterStation getVscConverterStation(Network network, String converterStat HvdcLine getHvdcLine(Network network, String hvdcLineId) { HvdcLine hvdcLine = network.getHvdcLine(hvdcLineId); if (hvdcLine == null) { - throw new NetworkModificationException(HVDC_LINE_NOT_FOUND, "Hvdc line " + hvdcLineId + " does not exist in network"); + throw new NetworkModificationException(HVDC_LINE_NOT_FOUND, "Hvdc line " + hvdcLineId + NOT_EXIST_IN_NETWORK); } return hvdcLine; } @@ -493,10 +494,7 @@ public ReportNode reportModifications(ReportNode reportNode, List re for (Map.Entry valueEntry : report.getValues().entrySet()) { reportNodeAdder.withUntypedValue(valueEntry.getKey(), valueEntry.getValue().toString()); } - TypedValue severity = report.getValue(ReportConstants.SEVERITY_KEY).orElse(null); - if (severity != null) { - reportNodeAdder.withSeverity(severity); - } + report.getValue(ReportConstants.SEVERITY_KEY).ifPresent(reportNodeAdder::withSeverity); reportNodeAdder.add(); } } @@ -601,120 +599,235 @@ public void disconnectCreatedInjection(InjectionCreationInfos modificationInfos, } public ReportNode modifyInjectionConnectivityAttributes(ConnectablePosition connectablePosition, - ConnectablePositionAdder connectablePositionAdder, - Injection injection, - InjectionModificationInfos modificationInfos, - ReportNode connectivityReports) { + ConnectablePositionAdder connectablePositionAdder, + Injection injection, + InjectionModificationInfos modificationInfos, + ReportNode connectivityReports) { List reports = new ArrayList<>(); - if (modificationInfos.getVoltageLevelId() == null || modificationInfos.getBusOrBusbarSectionId() == null) { - return ReportNode.newRootReportNode() + if (isVoltageOrBusbarIdMissing(modificationInfos.getVoltageLevelId(), modificationInfos.getBusOrBusbarSectionId(), modificationInfos.getEquipmentId(), reports)) { + return reports.get(0); + } + processConnectivityPosition(connectablePosition, connectablePositionAdder, modificationInfos, reports, false); + modifyConnection(modificationInfos.getTerminalConnected(), injection, injection.getTerminal(), reports); + + return reportModifications(connectivityReports, reports, "ConnectivityModified", CONNECTIVITY); + } + + public ReportNode modifyBranchConnectivityAttributes(ConnectablePosition connectablePosition, + ConnectablePositionAdder connectablePositionAdder, + Branch branch, + 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, reports, true); + 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", modificationInfos.getEquipmentId()) + .withUntypedValue("id", equipmentId) .withSeverity(TypedValue.WARN_SEVERITY) - .build(); + .build()); + return true; } + return false; + } + + private void processConnectivityPosition(ConnectablePosition connectablePosition, + ConnectablePositionAdder connectablePositionAdder, + Object modificationInfos, + List reports, + boolean isBranch) { if (connectablePosition != null) { - modifyExistingConnectivityPosition(connectablePosition, modificationInfos, reports); + modifyExistingConnectivityPosition(connectablePosition, modificationInfos, reports, isBranch); } else { - createNewConnectivityPosition(connectablePositionAdder, modificationInfos, reports); + createNewConnectivityPosition(connectablePositionAdder, modificationInfos, reports, isBranch); } - modifyInjectionConnection(modificationInfos, injection, reports); - return reportModifications(connectivityReports, reports, "ConnectivityModified", CONNECTIVITY); } private void modifyExistingConnectivityPosition(ConnectablePosition connectablePosition, - InjectionModificationInfos modificationInfos, - List reports) { - ConnectablePosition.Feeder feeder = connectablePosition.getFeeder(); - ReportNode connectionNameReport = applyElementaryModificationsAndReturnReport( - feeder::setName, + Object modificationInfos, + List reports, + boolean isBranch) { + if (isBranch) { + modifyFeeder(connectablePosition.getFeeder1(), modificationInfos, reports, 1); + modifyFeeder(connectablePosition.getFeeder2(), modificationInfos, reports, 2); + } else { + modifyFeeder(connectablePosition.getFeeder(), modificationInfos, reports, 0); + } + } + + private void createNewConnectivityPosition(ConnectablePositionAdder adder, + Object modificationInfos, + List reports, + boolean isBranch) { + if (isBranch) { + ConnectablePositionAdder.FeederAdder feeder1 = adder.newFeeder1(); + ConnectablePositionAdder.FeederAdder feeder2 = adder.newFeeder2(); + modifyFeederAdder(feeder1, modificationInfos, reports, 1); + modifyFeederAdder(feeder2, modificationInfos, reports, 2); + } else { + ConnectablePositionAdder.FeederAdder feeder = adder.newFeeder(); + modifyFeederAdder(feeder, modificationInfos, reports, 0); + } + adder.add(); + } + + private void modifyFeeder(ConnectablePosition.Feeder feeder, + Object modificationInfos, + List reports, + int feederNumber) { + applyModifications(feeder, modificationInfos, reports, feederNumber); + } + + private void applyModifications(ConnectablePosition.Feeder feeder, + Object modificationInfos, + List reports, + int feederNumber) { + ReportNode connectionNameReport = applyElementaryModificationsAndReturnReport(feeder::setName, feeder.getName()::get, - modificationInfos.getConnectionName(), - CONNECTION_NAME_FIELD_NAME); + getConnectionName(modificationInfos, feederNumber), + getConnectionNameField(feederNumber)); if (connectionNameReport != null) { reports.add(connectionNameReport); } - ReportNode connectionDirectionReport = applyElementaryModificationsAndReturnReport( - feeder::setDirection, + ReportNode connectionDirectionReport = applyElementaryModificationsAndReturnReport(feeder::setDirection, feeder::getDirection, - modificationInfos.getConnectionDirection(), - CONNECTION_DIRECTION_FIELD_NAME); + getConnectionDirection(modificationInfos, feederNumber), + getConnectionDirectionField(feederNumber)); if (connectionDirectionReport != null) { reports.add(connectionDirectionReport); } - ReportNode connectionPositionReport = applyElementaryModificationsAndReturnReport( - feeder::setOrder, + ReportNode connectionPositionReport = applyElementaryModificationsAndReturnReport(feeder::setOrder, feeder.getOrder()::get, - modificationInfos.getConnectionPosition(), - CONNECTION_POSITION_FIELD_NAME); + getConnectionPosition(modificationInfos, feederNumber), + getConnectionPositionField(feederNumber)); if (connectionPositionReport != null) { reports.add(connectionPositionReport); } } - private void createNewConnectivityPosition(ConnectablePositionAdder adder, - InjectionModificationInfos modificationInfos, - List reports) { - ConnectablePositionAdder.FeederAdder feeder = adder.newFeeder(); - ReportNode connectionNameReport = applyElementaryModificationsAndReturnReport( - feeder::withName, + private void modifyFeederAdder(ConnectablePositionAdder.FeederAdder feeder, + Object modificationInfos, + List reports, + int feederNumber) { + ReportNode connectionNameReport = applyElementaryModificationsAndReturnReport(feeder::withName, () -> null, - modificationInfos.getConnectionName(), - CONNECTION_NAME_FIELD_NAME); + getConnectionName(modificationInfos, feederNumber), + getConnectionNameField(feederNumber)); if (connectionNameReport != null) { reports.add(connectionNameReport); } - - ReportNode connectionDirectionReport = applyElementaryModificationsAndReturnReport( - feeder::withDirection, + ReportNode connectionDirectionReport = applyElementaryModificationsAndReturnReport(feeder::withDirection, () -> null, - modificationInfos.getConnectionDirection(), - CONNECTION_DIRECTION_FIELD_NAME); + getConnectionDirection(modificationInfos, feederNumber), + getConnectionDirectionField(feederNumber)); if (connectionDirectionReport != null) { reports.add(connectionDirectionReport); } - - ReportNode connectionPositionReport = applyElementaryModificationsAndReturnReport( - feeder::withOrder, + ReportNode connectionPositionReport = applyElementaryModificationsAndReturnReport(feeder::withOrder, () -> null, - modificationInfos.getConnectionPosition(), - CONNECTION_POSITION_FIELD_NAME); + getConnectionPosition(modificationInfos, feederNumber), + getConnectionPositionField(feederNumber)); if (connectionPositionReport != null) { reports.add(connectionPositionReport); } - if (connectionNameReport != null || connectionDirectionReport != null || connectionPositionReport != null) { - adder.add(); + feeder.add(); } } - public void modifyInjectionConnection(InjectionModificationInfos modificationInfos, Injection injection, List subReportNode) { - if (modificationInfos.getTerminalConnected() != null && injection != null) { - if (isInjectionConnected(injection) && Boolean.FALSE.equals(modificationInfos.getTerminalConnected().getValue())) { - injection.getTerminal().disconnect(); - if (isInjectionConnected(injection)) { - throw new NetworkModificationException(INJECTION_MODIFICATION_ERROR, - String.format("Could not disconnect equipment '%s'", injection.getId())); - } - subReportNode.add(ReportNode.newRootReportNode() - .withMessageTemplate("equipmentDisconnected", " Equipment with id=${id} disconnected") - .withUntypedValue("id", modificationInfos.getEquipmentId()) - .withSeverity(TypedValue.INFO_SEVERITY) - .build()); - } else if (!isInjectionConnected(injection) && Boolean.TRUE.equals(modificationInfos.getTerminalConnected().getValue())) { - injection.getTerminal().connect(); - if (!isInjectionConnected(injection)) { - throw new NetworkModificationException(INJECTION_MODIFICATION_ERROR, - String.format("Could not connect equipment '%s'", injection.getId())); - } - subReportNode.add(ReportNode.newRootReportNode() - .withMessageTemplate("equipmentConnected", " Equipment with id=${id} connected") - .withUntypedValue("id", modificationInfos.getEquipmentId()) - .withSeverity(TypedValue.INFO_SEVERITY) - .build()); - } + private T getConnectionDetail(Object modificationInfos, int feederNumber, + Function branchFunc1, + Function branchFunc2, + Function injectionFunc) { + if (modificationInfos instanceof BranchModificationInfos branchInfo) { + return feederNumber == 1 ? branchFunc1.apply(branchInfo) : 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 AttributeModification getConnectionName(Object modificationInfos, int feederNumber) { + return getConnectionDetail(modificationInfos, feederNumber, + BranchModificationInfos::getConnectionName1, BranchModificationInfos::getConnectionName2, + InjectionModificationInfos::getConnectionName); + } + + private String getConnectionNameField(int feederNumber) { + return getConnectionFieldName(feederNumber, CONNECTION_NAME_FIELD_NAME); + } + + private String getConnectionDirectionField(int feederNumber) { + return getConnectionFieldName(feederNumber, CONNECTION_DIRECTION_FIELD_NAME); + } + + private String getConnectionPositionField(int feederNumber) { + return getConnectionFieldName(feederNumber, CONNECTION_POSITION_FIELD_NAME); + } + + private AttributeModification getConnectionDirection(Object modificationInfos, int feederNumber) { + return getConnectionDetail(modificationInfos, feederNumber, + BranchModificationInfos::getConnectionDirection1, BranchModificationInfos::getConnectionDirection2, + InjectionModificationInfos::getConnectionDirection); + } + + private AttributeModification getConnectionPosition(Object modificationInfos, int feederNumber) { + return getConnectionDetail(modificationInfos, feederNumber, + BranchModificationInfos::getConnectionPosition1, BranchModificationInfos::getConnectionPosition2, + InjectionModificationInfos::getConnectionPosition); + } + + private void modifyConnection(AttributeModification terminalConnected, Identifiable equipment, Terminal terminal, List reports) { + if (terminalConnected == null || equipment == null) { + return; + } + + boolean isConnected = terminal.isConnected(); + if (isConnected && Boolean.FALSE.equals(terminalConnected.getValue())) { + terminal.disconnect(); + validateConnectionChange(!terminal.isConnected(), equipment, "disconnect", reports); + } else if (!isConnected && Boolean.TRUE.equals(terminalConnected.getValue())) { + terminal.connect(); + validateConnectionChange(terminal.isConnected(), equipment, "connect", reports); + } + } + + private void validateConnectionChange(boolean success, Identifiable equipment, String action, List reports) { + if (!success) { + throw new NetworkModificationException(equipment instanceof Branch ? BRANCH_MODIFICATION_ERROR : INJECTION_MODIFICATION_ERROR, + String.format("Could not %s equipment '%s'", action, equipment.getId())); + } + reports.add(ReportNode.newRootReportNode() + .withMessageTemplate("equipment" + capitalize(action), String.format("Equipment with id=${id} %sed", action)) + .withUntypedValue("id", equipment.getId()) + .withSeverity(TypedValue.INFO_SEVERITY) + .build()); + } + + private String capitalize(String input) { + return input.substring(0, 1).toUpperCase() + input.substring(1); } public void disconnectBranch(BranchCreationInfos modificationInfos, Branch branch, ReportNode subReportNode) { @@ -742,38 +855,23 @@ public Identifiable getEquipmentByIdentifiableType(Network network, Identifia return null; } - switch (type) { - case HVDC_LINE: - return network.getHvdcLine(equipmentId); - case LINE: - return network.getLine(equipmentId); - case TWO_WINDINGS_TRANSFORMER: - return network.getTwoWindingsTransformer(equipmentId); - case THREE_WINDINGS_TRANSFORMER: - return network.getThreeWindingsTransformer(equipmentId); - case GENERATOR: - return network.getGenerator(equipmentId); - case LOAD: - return network.getLoad(equipmentId); - case BATTERY: - return network.getBattery(equipmentId); - case SHUNT_COMPENSATOR: - return network.getShuntCompensator(equipmentId); - case STATIC_VAR_COMPENSATOR: - return network.getStaticVarCompensator(equipmentId); - case DANGLING_LINE: - return network.getDanglingLine(equipmentId); - case HVDC_CONVERTER_STATION: - return network.getHvdcConverterStation(equipmentId); - case SUBSTATION: - return network.getSubstation(equipmentId); - case VOLTAGE_LEVEL: - return network.getVoltageLevel(equipmentId); - case BUSBAR_SECTION: - return network.getBusbarSection(equipmentId); - default: - return null; - } + return switch (type) { + case HVDC_LINE -> network.getHvdcLine(equipmentId); + case LINE -> network.getLine(equipmentId); + case TWO_WINDINGS_TRANSFORMER -> network.getTwoWindingsTransformer(equipmentId); + case THREE_WINDINGS_TRANSFORMER -> network.getThreeWindingsTransformer(equipmentId); + case GENERATOR -> network.getGenerator(equipmentId); + case LOAD -> network.getLoad(equipmentId); + case BATTERY -> network.getBattery(equipmentId); + case SHUNT_COMPENSATOR -> network.getShuntCompensator(equipmentId); + case STATIC_VAR_COMPENSATOR -> network.getStaticVarCompensator(equipmentId); + case DANGLING_LINE -> network.getDanglingLine(equipmentId); + case HVDC_CONVERTER_STATION -> network.getHvdcConverterStation(equipmentId); + case SUBSTATION -> network.getSubstation(equipmentId); + case VOLTAGE_LEVEL -> network.getVoltageLevel(equipmentId); + case BUSBAR_SECTION -> network.getBusbarSection(equipmentId); + default -> null; + }; } public void setCurrentLimits(CurrentLimitsInfos currentLimitsInfos, CurrentLimitsAdder limitsAdder) { @@ -1266,10 +1364,7 @@ public static void insertReportNode(ReportNode parent, ReportNode child) { for (Map.Entry valueEntry : child.getValues().entrySet()) { adder.withUntypedValue(valueEntry.getKey(), valueEntry.getValue().toString()); } - TypedValue severity = child.getValue(ReportConstants.SEVERITY_KEY).orElse(null); - if (severity != null) { - adder.withSeverity(severity); - } + child.getValue(ReportConstants.SEVERITY_KEY).ifPresent(adder::withSeverity); ReportNode insertedChild = adder.add(); if (child.getChildren() != null) { child.getChildren().forEach(grandChild -> insertReportNode(insertedChild, grandChild)); diff --git a/src/main/resources/db/changelog/changesets/changelog_20240904T211456Z.xml b/src/main/resources/db/changelog/changesets/changelog_20240904T211456Z.xml new file mode 100644 index 000000000..5d6cf56f0 --- /dev/null +++ b/src/main/resources/db/changelog/changesets/changelog_20240904T211456Z.xml @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml index 6f9f44d4e..32b8d57e2 100644 --- a/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -305,4 +305,7 @@ databaseChangeLog: relativeToChangelogFile: true - include: file: changesets/changelog_20240829T071248Z.xml + relativeToChangelogFile: true + - include: + file: changesets/changelog_20240904T211456Z.xml relativeToChangelogFile: true \ No newline at end of file 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 165d082e4..69af786b8 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/LineModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/LineModificationTest.java @@ -11,6 +11,7 @@ import com.powsybl.iidm.network.Line; import com.powsybl.iidm.network.LoadingLimits.TemporaryLimit; import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.extensions.ConnectablePosition; import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.*; @@ -51,6 +52,16 @@ protected ModificationInfos buildModification() { .stashed(false) .equipmentId("line1") .equipmentName(new AttributeModification<>("LineModified", OperationType.SET)) + .voltageLevelId1(new AttributeModification<>("v1", OperationType.SET)) + .voltageLevelId2(new AttributeModification<>("v4", OperationType.SET)) + .busOrBusbarSectionId1(new AttributeModification<>("1B", OperationType.SET)) + .busOrBusbarSectionId2(new AttributeModification<>("2B", OperationType.SET)) + .connectionName1(new AttributeModification<>("cn1Line1", OperationType.SET)) + .connectionName2(new AttributeModification<>("cn2Line1", OperationType.SET)) + .connectionDirection1(new AttributeModification<>(ConnectablePosition.Direction.TOP, OperationType.SET)) + .connectionDirection2(new AttributeModification<>(ConnectablePosition.Direction.TOP, OperationType.SET)) + .connectionPosition1(new AttributeModification<>(1, OperationType.SET)) + .connectionPosition2(new AttributeModification<>(1, OperationType.SET)) .currentLimits1(CurrentLimitsModificationInfos.builder() .permanentLimit(12.0) .temporaryLimits(List.of(CurrentTemporaryLimitModificationInfos.builder() @@ -378,8 +389,8 @@ public void testConnection() throws Exception { private void changeLineConnectionState(Line existingEquipment, boolean expectedState) throws Exception { LineModificationInfos modificationInfos = (LineModificationInfos) buildModification(); - modificationInfos.setConnected1(new AttributeModification<>(expectedState, OperationType.SET)); - modificationInfos.setConnected2(new AttributeModification<>(expectedState, OperationType.SET)); + modificationInfos.setTerminal1Connected(new AttributeModification<>(expectedState, OperationType.SET)); + modificationInfos.setTerminal2Connected(new AttributeModification<>(expectedState, OperationType.SET)); if (expectedState) { if (existingEquipment.getTerminal1().isConnected()) { 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 7ec3a0df4..efd3a20a0 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModificationTest.java @@ -15,6 +15,7 @@ import com.powsybl.iidm.network.TwoSides; import com.powsybl.iidm.network.TwoWindingsTransformer; +import com.powsybl.iidm.network.extensions.ConnectablePosition; import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.*; @@ -79,6 +80,16 @@ protected ModificationInfos buildModification() { .modificationType(TemporaryLimitModificationType.ADDED) .build())) .build()) + .voltageLevelId1(new AttributeModification<>("v1", OperationType.SET)) + .voltageLevelId2(new AttributeModification<>("v2", OperationType.SET)) + .busOrBusbarSectionId1(new AttributeModification<>("1B", OperationType.SET)) + .busOrBusbarSectionId2(new AttributeModification<>("2B", OperationType.SET)) + .connectionName1(new AttributeModification<>("trf1", OperationType.SET)) + .connectionName2(new AttributeModification<>("trf1", OperationType.SET)) + .connectionDirection1(new AttributeModification<>(ConnectablePosition.Direction.TOP, OperationType.SET)) + .connectionDirection2(new AttributeModification<>(ConnectablePosition.Direction.TOP, OperationType.SET)) + .connectionPosition1(new AttributeModification<>(1, OperationType.SET)) + .connectionPosition2(new AttributeModification<>(2, OperationType.SET)) .ratioTapChanger(RatioTapChangerModificationInfos.builder() .enabled(new AttributeModification<>(true, OperationType.SET)) .loadTapChangingCapabilities(new AttributeModification<>(true, OperationType.SET)) @@ -603,8 +614,8 @@ private void changeConnectionState(TwoWindingsTransformer existingEquipment, Two TwoWindingsTransformerModificationInfos.builder() .stashed(false) .equipmentId(existingEquipment.getId()) - .connected1(side == TwoSides.ONE ? new AttributeModification<>(expectedState, OperationType.SET) : null) - .connected2(side == TwoSides.TWO ? new AttributeModification<>(expectedState, OperationType.SET) : null) + .terminal1Connected(side == TwoSides.ONE ? new AttributeModification<>(expectedState, OperationType.SET) : null) + .terminal2Connected(side == TwoSides.TWO ? new AttributeModification<>(expectedState, OperationType.SET) : null) .build(); String modificationInfosJson = mapper.writeValueAsString(modificationInfos); MvcResult mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(modificationInfosJson).contentType(MediaType.APPLICATION_JSON)) From bc457485c4a98a8bb41b05bae4c87c6dafa9e109 Mon Sep 17 00:00:00 2001 From: Mathieu Deharbe <148252167+Mathieu-Deharbe@users.noreply.github.com> Date: Thu, 26 Sep 2024 10:07:05 +0200 Subject: [PATCH 2/2] share code for regular network modifications and network modifications by formula (#524) Signed-off-by: Mathieu DEHARBE --- .../formula/equipmentfield/BatteryField.java | 38 +- .../equipmentfield/GeneratorField.java | 116 ++---- .../dto/formula/equipmentfield/LoadField.java | 9 +- .../equipmentfield/ShuntCompensatorField.java | 28 +- .../TwoWindingsTransformerField.java | 43 ++- .../equipmentfield/VoltageLevelField.java | 30 +- .../modifications/BatteryModification.java | 44 ++- .../modifications/ByFormulaModification.java | 5 +- .../modifications/GeneratorModification.java | 200 +++++++---- .../modifications/LoadModification.java | 13 +- .../modifications/ModificationUtils.java | 38 +- .../ShuntCompensatorModification.java | 94 +++-- .../TwoWindingsTransformerModification.java | 334 +++++++++++------- .../VoltageLevelModification.java | 99 ++++-- .../GeneratorByFormulaModificationTest.java | 4 +- 15 files changed, 666 insertions(+), 429 deletions(-) diff --git a/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/BatteryField.java b/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/BatteryField.java index 079dd8a12..7c82638e7 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/BatteryField.java +++ b/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/BatteryField.java @@ -10,6 +10,14 @@ import com.powsybl.iidm.network.Battery; import com.powsybl.iidm.network.extensions.ActivePowerControl; import com.powsybl.iidm.network.extensions.ActivePowerControlAdder; +import jakarta.validation.constraints.NotNull; +import org.gridsuite.modification.server.dto.AttributeModification; +import org.gridsuite.modification.server.dto.OperationType; +import org.gridsuite.modification.server.modifications.ModificationUtils; + +import static org.gridsuite.modification.server.NetworkModificationException.Type.MODIFY_BATTERY_ERROR; +import static org.gridsuite.modification.server.modifications.BatteryModification.modifyBatteryActiveLimitsAttributes; +import static org.gridsuite.modification.server.modifications.BatteryModification.modifyBatterySetpointsAttributes; /** * @author Seddik Yengui @@ -34,16 +42,30 @@ public static Double getReferenceValue(Battery battery, String batteryField) { }; } - public static void setNewValue(Battery battery, String batteryField, Double newValue) { + public static void setNewValue(Battery battery, String batteryField, @NotNull Double newValue) { BatteryField field = BatteryField.valueOf(batteryField); + final AttributeModification attributeModification = new AttributeModification<>(newValue, OperationType.SET); switch (field) { - case MINIMUM_ACTIVE_POWER -> battery.setMinP(newValue); - case MAXIMUM_ACTIVE_POWER -> battery.setMaxP(newValue); - case ACTIVE_POWER_SET_POINT -> battery.setTargetP(newValue); - case REACTIVE_POWER_SET_POINT -> battery.setTargetQ(newValue); - case DROOP -> battery.newExtension(ActivePowerControlAdder.class) - .withDroop(newValue) - .add(); + case MINIMUM_ACTIVE_POWER -> + modifyBatteryActiveLimitsAttributes(null, attributeModification, battery, null); + case MAXIMUM_ACTIVE_POWER -> + modifyBatteryActiveLimitsAttributes(attributeModification, null, battery, null); + case ACTIVE_POWER_SET_POINT -> { + ModificationUtils.getInstance().checkActivePowerZeroOrBetweenMinAndMaxActivePower( + attributeModification, null, null, battery.getMinP(), + battery.getMaxP(), battery.getTargetP(), MODIFY_BATTERY_ERROR, "Battery '" + battery.getId() + "' : " + ); + modifyBatterySetpointsAttributes(attributeModification, null, null, null, battery, null); + } + case REACTIVE_POWER_SET_POINT -> modifyBatterySetpointsAttributes( + null, attributeModification, null, null, battery, null); + case DROOP -> { + ActivePowerControl activePowerControl = battery.getExtension(ActivePowerControl.class); + ActivePowerControlAdder activePowerControlAdder = battery.newExtension(ActivePowerControlAdder.class); + ModificationUtils.getInstance().modifyActivePowerControlAttributes( + activePowerControl, activePowerControlAdder, null, + new AttributeModification<>(newValue.floatValue(), OperationType.SET), null, null); + } } } } diff --git a/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/GeneratorField.java b/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/GeneratorField.java index 7c864cbfd..d36390c58 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/GeneratorField.java +++ b/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/GeneratorField.java @@ -11,11 +11,15 @@ import com.powsybl.iidm.network.extensions.ActivePowerControl; import com.powsybl.iidm.network.extensions.ActivePowerControlAdder; import com.powsybl.iidm.network.extensions.CoordinatedReactiveControl; -import com.powsybl.iidm.network.extensions.CoordinatedReactiveControlAdder; import com.powsybl.iidm.network.extensions.GeneratorShortCircuit; -import com.powsybl.iidm.network.extensions.GeneratorShortCircuitAdder; import com.powsybl.iidm.network.extensions.GeneratorStartup; -import com.powsybl.iidm.network.extensions.GeneratorStartupAdder; +import com.powsybl.network.store.iidm.impl.extensions.CoordinatedReactiveControlAdderImpl; +import org.gridsuite.modification.server.dto.AttributeModification; +import org.gridsuite.modification.server.dto.OperationType; +import org.gridsuite.modification.server.modifications.ModificationUtils; + +import static org.gridsuite.modification.server.NetworkModificationException.Type.MODIFY_GENERATOR_ERROR; +import static org.gridsuite.modification.server.modifications.GeneratorModification.*; /** * @author Seddik Yengui @@ -61,86 +65,42 @@ public static Double getReferenceValue(Generator generator, String generatorFiel }; } - public static void setNewValue(Generator generator, String generatorField, Double newValue) { + public static void setNewValue(Generator generator, String generatorField, double newValue) { if (!Double.isNaN(newValue)) { - GeneratorStartup generatorStartup = generator.getExtension(GeneratorStartup.class); - GeneratorShortCircuit generatorShortCircuit = generator.getExtension(GeneratorShortCircuit.class); GeneratorField field = GeneratorField.valueOf(generatorField); + final AttributeModification attributeModification = new AttributeModification<>(newValue, OperationType.SET); switch (field) { - case MAXIMUM_ACTIVE_POWER -> generator.setMaxP(newValue); - case MINIMUM_ACTIVE_POWER -> generator.setMinP(newValue); - case ACTIVE_POWER_SET_POINT -> generator.setTargetP(newValue); - case RATED_NOMINAL_POWER -> generator.setRatedS(newValue); - case REACTIVE_POWER_SET_POINT -> generator.setTargetQ(newValue); - case VOLTAGE_SET_POINT -> generator.setTargetV(newValue); - case PLANNED_ACTIVE_POWER_SET_POINT -> { - if (generatorStartup == null) { - generator.newExtension(GeneratorStartupAdder.class) - .withPlannedActivePowerSetpoint(newValue) - .add(); - } else { - generator.newExtension(GeneratorStartupAdder.class) - .withMarginalCost(generatorStartup.getMarginalCost()) - .withPlannedActivePowerSetpoint(newValue) - .withPlannedOutageRate(generatorStartup.getPlannedOutageRate()) - .withForcedOutageRate(generatorStartup.getForcedOutageRate()) - .add(); - } - } - case MARGINAL_COST -> { - if (generatorStartup == null) { - generator.newExtension(GeneratorStartupAdder.class) - .withMarginalCost(newValue) - .add(); - } else { - generator.newExtension(GeneratorStartupAdder.class) - .withMarginalCost(newValue) - .withPlannedActivePowerSetpoint(generatorStartup.getPlannedActivePowerSetpoint()) - .withPlannedOutageRate(generatorStartup.getPlannedOutageRate()) - .withForcedOutageRate(generatorStartup.getForcedOutageRate()) - .add(); - } - } - case PLANNED_OUTAGE_RATE -> { - if (generatorStartup == null) { - generator.newExtension(GeneratorStartupAdder.class) - .withPlannedOutageRate(newValue) - .add(); - } else { - generator.newExtension(GeneratorStartupAdder.class) - .withMarginalCost(generatorStartup.getMarginalCost()) - .withPlannedActivePowerSetpoint(generatorStartup.getPlannedActivePowerSetpoint()) - .withPlannedOutageRate(newValue) - .withForcedOutageRate(generatorStartup.getForcedOutageRate()) - .add(); - } + case MAXIMUM_ACTIVE_POWER -> modifyGeneratorActiveLimitsAttributes( + attributeModification, null, null, generator, null); + case MINIMUM_ACTIVE_POWER -> modifyGeneratorActiveLimitsAttributes(null, attributeModification, null, generator, null); + case ACTIVE_POWER_SET_POINT -> { + ModificationUtils.getInstance().checkActivePowerZeroOrBetweenMinAndMaxActivePower( + attributeModification, null, null, + generator.getMinP(), generator.getMaxP(), generator.getTargetP(), + MODIFY_GENERATOR_ERROR, "Generator '" + generator.getId() + "' : " + ); + generator.setTargetP(newValue); } - case FORCED_OUTAGE_RATE -> { - if (generatorStartup == null) { - generator.newExtension(GeneratorStartupAdder.class) - .withForcedOutageRate(newValue) - .add(); - } else { - generator.newExtension(GeneratorStartupAdder.class) - .withMarginalCost(generatorStartup.getMarginalCost()) - .withPlannedActivePowerSetpoint(generatorStartup.getPlannedActivePowerSetpoint()) - .withPlannedOutageRate(generatorStartup.getForcedOutageRate()) - .withForcedOutageRate(newValue) - .add(); - } + case RATED_NOMINAL_POWER -> modifyGeneratorActiveLimitsAttributes(null, null, attributeModification, generator, null); + case REACTIVE_POWER_SET_POINT -> modifyTargetQ(generator, attributeModification); + case VOLTAGE_SET_POINT -> modifyTargetV(generator, attributeModification); + case PLANNED_ACTIVE_POWER_SET_POINT -> + modifyGeneratorStartUpAttributes(attributeModification, null, null, null, generator, null, null); + case MARGINAL_COST -> + modifyGeneratorStartUpAttributes(null, attributeModification, null, null, generator, null, null); + case PLANNED_OUTAGE_RATE -> + modifyGeneratorStartUpAttributes(null, null, attributeModification, null, generator, null, null); + case FORCED_OUTAGE_RATE -> + modifyGeneratorStartUpAttributes(null, null, null, attributeModification, generator, null, null); + case DROOP -> { + ActivePowerControl activePowerControl = generator.getExtension(ActivePowerControl.class); + ActivePowerControlAdder activePowerControlAdder = generator.newExtension(ActivePowerControlAdder.class); + ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder, null, + new AttributeModification<>((float) newValue, OperationType.SET), null, null); } - case DROOP -> generator.newExtension(ActivePowerControlAdder.class) - .withDroop(newValue) - .add(); - case TRANSIENT_REACTANCE -> generator.newExtension(GeneratorShortCircuitAdder.class) - .withDirectTransX(newValue) - .withStepUpTransformerX(generatorShortCircuit == null ? Double.NaN : generatorShortCircuit.getStepUpTransformerX()) - .add(); - case STEP_UP_TRANSFORMER_REACTANCE -> generator.newExtension(GeneratorShortCircuitAdder.class) - .withDirectTransX(generatorShortCircuit == null ? 0.0D : generatorShortCircuit.getDirectTransX()) - .withStepUpTransformerX(newValue) - .add(); - case Q_PERCENT -> generator.newExtension(CoordinatedReactiveControlAdder.class) + case TRANSIENT_REACTANCE -> modifyGeneratorShortCircuitAttributes(attributeModification, null, generator, null); + case STEP_UP_TRANSFORMER_REACTANCE -> modifyGeneratorShortCircuitAttributes(null, attributeModification, generator, null); + case Q_PERCENT -> generator.newExtension(CoordinatedReactiveControlAdderImpl.class) .withQPercent(newValue) .add(); } diff --git a/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/LoadField.java b/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/LoadField.java index 2743186a6..8c01d3f96 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/LoadField.java +++ b/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/LoadField.java @@ -8,6 +8,11 @@ package org.gridsuite.modification.server.dto.formula.equipmentfield; import com.powsybl.iidm.network.Load; +import org.gridsuite.modification.server.dto.AttributeModification; +import org.gridsuite.modification.server.dto.OperationType; + +import static org.gridsuite.modification.server.modifications.LoadModification.modifyP0; +import static org.gridsuite.modification.server.modifications.LoadModification.modifyQ0; /** * @author Seddik Yengui @@ -28,8 +33,8 @@ public static Double getReferenceValue(Load load, String loadField) { public static void setNewValue(Load load, String loadField, Double newValue) { LoadField field = LoadField.valueOf(loadField); switch (field) { - case ACTIVE_POWER -> load.setP0(newValue); - case REACTIVE_POWER -> load.setQ0(newValue); + case ACTIVE_POWER -> modifyP0(load, new AttributeModification<>(newValue, OperationType.SET), null); + case REACTIVE_POWER -> modifyQ0(load, new AttributeModification<>(newValue, OperationType.SET), null); } } } diff --git a/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/ShuntCompensatorField.java b/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/ShuntCompensatorField.java index e155d4720..87dabb14a 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/ShuntCompensatorField.java +++ b/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/ShuntCompensatorField.java @@ -12,6 +12,11 @@ import com.powsybl.iidm.network.ShuntCompensatorModelType; import com.powsybl.iidm.network.VoltageLevel; import org.gridsuite.modification.server.NetworkModificationException; +import org.gridsuite.modification.server.dto.AttributeModification; +import org.gridsuite.modification.server.dto.OperationType; +import org.gridsuite.modification.server.dto.ShuntCompensatorType; + +import static org.gridsuite.modification.server.modifications.ShuntCompensatorModification.*; /** * @author Seddik Yengui @@ -42,19 +47,18 @@ public static void setNewValue(ShuntCompensator shuntCompensator, String shuntCo ShuntCompensatorLinearModel model = shuntCompensator.getModel(ShuntCompensatorLinearModel.class); ShuntCompensatorField field = ShuntCompensatorField.valueOf(shuntCompensatorField); VoltageLevel voltageLevel = shuntCompensator.getTerminal().getVoltageLevel(); + var shuntCompensatorType = ShuntCompensatorType.REACTOR; + if (model != null && model.getBPerSection() > 0) { + shuntCompensatorType = ShuntCompensatorType.CAPACITOR; + } switch (field) { - case MAXIMUM_SECTION_COUNT -> { - int maximumSectionCount = newValue.intValue(); - model.setBPerSection(model.getBPerSection() * shuntCompensator.getMaximumSectionCount() / maximumSectionCount); - model.setMaximumSectionCount(maximumSectionCount); - } - case SECTION_COUNT -> shuntCompensator.setSectionCount(newValue.intValue()); - case MAXIMUM_SUSCEPTANCE -> model.setBPerSection(newValue / shuntCompensator.getMaximumSectionCount()); - case MAXIMUM_Q_AT_NOMINAL_VOLTAGE -> { - double newQatNominalV = newValue / shuntCompensator.getMaximumSectionCount(); - double newSusceptancePerSection = newQatNominalV / Math.pow(voltageLevel.getNominalV(), 2); - model.setBPerSection(newSusceptancePerSection); - } + case MAXIMUM_SECTION_COUNT -> modifyMaximumSectionCount(new AttributeModification<>(newValue.intValue(), OperationType.SET), + null, null, null, shuntCompensator, model); + case SECTION_COUNT -> modifySectionCount(new AttributeModification<>(newValue.intValue(), OperationType.SET), null, shuntCompensator); + case MAXIMUM_SUSCEPTANCE -> modifyMaxSusceptance(new AttributeModification<>(newValue, OperationType.SET), + shuntCompensator.getMaximumSectionCount(), null, model); + case MAXIMUM_Q_AT_NOMINAL_VOLTAGE -> modifyMaximumQAtNominalVoltage(new AttributeModification<>(newValue, OperationType.SET), + voltageLevel, shuntCompensator.getMaximumSectionCount(), null, model, shuntCompensatorType); } } } diff --git a/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/TwoWindingsTransformerField.java b/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/TwoWindingsTransformerField.java index e0f6d52df..6a13e93d6 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/TwoWindingsTransformerField.java +++ b/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/TwoWindingsTransformerField.java @@ -3,6 +3,9 @@ import com.powsybl.iidm.network.PhaseTapChanger; import com.powsybl.iidm.network.RatioTapChanger; import com.powsybl.iidm.network.TwoWindingsTransformer; +import org.gridsuite.modification.server.dto.AttributeModification; +import org.gridsuite.modification.server.dto.OperationType; +import static org.gridsuite.modification.server.modifications.TwoWindingsTransformerModification.*; public enum TwoWindingsTransformerField { R, @@ -48,23 +51,33 @@ public static void setNewValue(TwoWindingsTransformer transformer, String twoWin TwoWindingsTransformerField field = TwoWindingsTransformerField.valueOf(twoWindingsTransformerField); final PhaseTapChanger phaseTapChanger = transformer.getPhaseTapChanger(); final RatioTapChanger ratioTapChanger = transformer.getRatioTapChanger(); + final PhaseTapChanger.RegulationMode regulationMode = phaseTapChanger != null ? phaseTapChanger.getRegulationMode() : null; + final AttributeModification attributeModification = new AttributeModification<>(newValue, OperationType.SET); switch (field) { - case R -> transformer.setR(newValue); - case X -> transformer.setX(newValue); - case G -> transformer.setG(newValue); - case B -> transformer.setB(newValue); - case RATED_U1 -> transformer.setRatedU1(newValue); - case RATED_U2 -> transformer.setRatedU2(newValue); - case RATED_S -> transformer.setRatedS(newValue); - case TARGET_V -> ratioTapChanger.setTargetV(newValue); - case RATIO_LOW_TAP_POSITION -> ratioTapChanger.setLowTapPosition(newValue.intValue()); - case RATIO_TAP_POSITION -> ratioTapChanger.setTapPosition(newValue.intValue()); - case RATIO_TARGET_DEADBAND -> ratioTapChanger.setTargetDeadband(newValue); - case REGULATION_VALUE -> phaseTapChanger.setRegulationValue(newValue); - case PHASE_LOW_TAP_POSITION -> phaseTapChanger.setLowTapPosition(newValue.intValue()); - case PHASE_TAP_POSITION -> phaseTapChanger.setTapPosition(newValue.intValue()); - case PHASE_TARGET_DEADBAND -> phaseTapChanger.setTargetDeadband(newValue); + case R -> modifyR(transformer, attributeModification, null); + case X -> modifyX(transformer, attributeModification, null); + case G -> modifyG(transformer, attributeModification, null); + case B -> modifyB(transformer, attributeModification, null); + case RATED_U1 -> modifyRatedU1(transformer, attributeModification, null); + case RATED_U2 -> modifyRatedU2(transformer, attributeModification, null); + case RATED_S -> modifyRatedS(transformer, attributeModification, null); + case TARGET_V -> modifyTargets(ratioTapChanger, null, true, attributeModification, null, null); + case RATIO_LOW_TAP_POSITION -> processTapChangerPositionsAndSteps(ratioTapChanger, null, true, + new AttributeModification<>(newValue.intValue(), OperationType.SET), null, null, null); + case RATIO_TAP_POSITION -> processTapChangerPositionsAndSteps(ratioTapChanger, null, true, + null, new AttributeModification<>(newValue.intValue(), OperationType.SET), null, null); + case RATIO_TARGET_DEADBAND -> modifyTargets(ratioTapChanger, null, true, null, attributeModification, null); + case REGULATION_VALUE -> processPhaseTapRegulation( + phaseTapChanger, null, regulationMode, true, attributeModification, null, null + ); + case PHASE_LOW_TAP_POSITION -> processTapChangerPositionsAndSteps(phaseTapChanger, null, true, + new AttributeModification<>(newValue.intValue(), OperationType.SET), null, null, null); + case PHASE_TAP_POSITION -> processTapChangerPositionsAndSteps(phaseTapChanger, null, true, + null, new AttributeModification<>(newValue.intValue(), OperationType.SET), null, null); + case PHASE_TARGET_DEADBAND -> processPhaseTapRegulation( + phaseTapChanger, null, null, true, null, attributeModification, null + ); } } } diff --git a/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/VoltageLevelField.java b/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/VoltageLevelField.java index a1fc1d644..69f366ad4 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/VoltageLevelField.java +++ b/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/VoltageLevelField.java @@ -9,7 +9,10 @@ import com.powsybl.iidm.network.VoltageLevel; import com.powsybl.iidm.network.extensions.IdentifiableShortCircuit; -import com.powsybl.iidm.network.extensions.IdentifiableShortCircuitAdder; +import org.gridsuite.modification.server.dto.AttributeModification; +import org.gridsuite.modification.server.dto.OperationType; + +import static org.gridsuite.modification.server.modifications.VoltageLevelModification.*; /** * @author Seddik Yengui @@ -35,26 +38,15 @@ public static Double getReferenceValue(VoltageLevel voltageLevel, String voltage } public static void setNewValue(VoltageLevel voltageLevel, String voltageLevelField, Double newValue) { - IdentifiableShortCircuit identifiableShortCircuit = voltageLevel.getExtension(IdentifiableShortCircuit.class); VoltageLevelField field = VoltageLevelField.valueOf(voltageLevelField); switch (field) { - case NOMINAL_VOLTAGE -> voltageLevel.setNominalV(newValue); - case LOW_VOLTAGE_LIMIT -> voltageLevel.setLowVoltageLimit(newValue); - case HIGH_VOLTAGE_LIMIT -> voltageLevel.setHighVoltageLimit(newValue); - case LOW_SHORT_CIRCUIT_CURRENT_LIMIT -> { - IdentifiableShortCircuitAdder adder = voltageLevel.newExtension(IdentifiableShortCircuitAdder.class).withIpMin(newValue); - if (identifiableShortCircuit != null) { - adder.withIpMax(identifiableShortCircuit.getIpMax()); - } - adder.add(); - } - case HIGH_SHORT_CIRCUIT_CURRENT_LIMIT -> { - IdentifiableShortCircuitAdder adder = voltageLevel.newExtension(IdentifiableShortCircuitAdder.class).withIpMax(newValue); - if (identifiableShortCircuit != null) { - adder.withIpMin(identifiableShortCircuit.getIpMin()); - } - adder.add(); - } + case NOMINAL_VOLTAGE -> modifyNominalV(voltageLevel, new AttributeModification<>(newValue, OperationType.SET), null); + case LOW_VOLTAGE_LIMIT -> modifLowVoltageLimit(voltageLevel, new AttributeModification<>(newValue, OperationType.SET), null); + case HIGH_VOLTAGE_LIMIT -> modifyHighVoltageLimit(voltageLevel, new AttributeModification<>(newValue, OperationType.SET), null); + case LOW_SHORT_CIRCUIT_CURRENT_LIMIT -> modifyVoltageLevelShortCircuit( + new AttributeModification<>(newValue, OperationType.SET), null, null, voltageLevel); + case HIGH_SHORT_CIRCUIT_CURRENT_LIMIT -> modifyVoltageLevelShortCircuit( + null, new AttributeModification<>(newValue, OperationType.SET), null, voltageLevel); } } } diff --git a/src/main/java/org/gridsuite/modification/server/modifications/BatteryModification.java b/src/main/java/org/gridsuite/modification/server/modifications/BatteryModification.java index 544be215a..15d9bd3ad 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/BatteryModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/BatteryModification.java @@ -18,6 +18,7 @@ import com.powsybl.iidm.network.extensions.ConnectablePosition; import com.powsybl.iidm.network.extensions.ConnectablePositionAdder; import org.gridsuite.modification.server.NetworkModificationException; +import org.gridsuite.modification.server.dto.AttributeModification; import org.gridsuite.modification.server.dto.BatteryModificationInfos; import org.gridsuite.modification.server.dto.ReactiveCapabilityCurveModificationInfos; @@ -86,17 +87,24 @@ private void modifyBattery(Battery battery, BatteryModificationInfos modificatio } modifyBatteryLimitsAttributes(modificationInfos, battery, subReportNode); - modifyBatterySetpointsAttributes(modificationInfos, battery, subReportNode); + modifyBatterySetpointsAttributes( + modificationInfos.getTargetP(), modificationInfos.getTargetQ(), + modificationInfos.getParticipate(), modificationInfos.getDroop(), + battery, subReportNode); modifyBatteryConnectivityAttributes(modificationInfos, battery, subReportNode); PropertiesUtils.applyProperties(battery, subReportNode, modificationInfos.getProperties(), "BatteryProperties"); } - private void modifyBatterySetpointsAttributes(BatteryModificationInfos modificationInfos, - Battery battery, ReportNode subReportNode) { - ReportNode reportActivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(battery::setTargetP, battery::getTargetP, modificationInfos.getTargetP(), "Active power"); - ReportNode reportReactivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(battery::setTargetQ, battery::getTargetQ, modificationInfos.getTargetQ(), "Reactive power"); + public static void modifyBatterySetpointsAttributes(AttributeModification targetP, + AttributeModification targetQ, + AttributeModification participate, + AttributeModification droop, + Battery battery, + ReportNode subReportNode) { + ReportNode reportActivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(battery::setTargetP, battery::getTargetP, targetP, "Active power"); + ReportNode reportReactivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(battery::setTargetQ, battery::getTargetQ, targetQ, "Reactive power"); ReportNode subReporterSetpoints = null; - if (reportActivePower != null || reportReactivePower != null) { + if (subReportNode != null && (reportActivePower != null || reportReactivePower != null)) { subReporterSetpoints = subReportNode.newReportNode().withMessageTemplate(SETPOINTS, SETPOINTS).add(); if (reportActivePower != null) { insertReportNode(subReporterSetpoints, reportActivePower); @@ -105,12 +113,12 @@ private void modifyBatterySetpointsAttributes(BatteryModificationInfos modificat insertReportNode(subReporterSetpoints, reportReactivePower); } } - modifyBatteryActivePowerControlAttributes(modificationInfos, battery, subReportNode, subReporterSetpoints); + modifyBatteryActivePowerControlAttributes(participate, droop, battery, subReportNode, subReporterSetpoints); } private void modifyBatteryLimitsAttributes(BatteryModificationInfos modificationInfos, Battery battery, ReportNode subReportNode) { - ReportNode subReportNodeLimits = modifyBatteryActiveLimitsAttributes(modificationInfos, battery, subReportNode); + ReportNode subReportNodeLimits = modifyBatteryActiveLimitsAttributes(modificationInfos.getMaxP(), modificationInfos.getMinP(), battery, subReportNode); modifyBatteryReactiveLimitsAttributes(modificationInfos, battery, subReportNode, subReportNodeLimits); } @@ -123,12 +131,13 @@ private void modifyBatteryReactiveCapabilityCurvePoints(BatteryModificationInfos ModificationUtils.getInstance().modifyReactiveCapabilityCurvePoints(points, modificationPoints, adder, subReportNode, subReportNodeLimits); } - private ReportNode modifyBatteryActiveLimitsAttributes(BatteryModificationInfos modificationInfos, - Battery battery, ReportNode subReportNode) { + public static ReportNode modifyBatteryActiveLimitsAttributes(AttributeModification maxP, + AttributeModification minP, + Battery battery, ReportNode subReportNode) { ReportNode subReportNodeLimits = null; - ReportNode reportMaxActivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(battery::setMaxP, battery::getMaxP, modificationInfos.getMaxP(), "Max active power"); - ReportNode reportMinActivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(battery::setMinP, battery::getMinP, modificationInfos.getMinP(), "Min active power"); - if (reportMaxActivePower != null || reportMinActivePower != null) { + ReportNode reportMaxActivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(battery::setMaxP, battery::getMaxP, maxP, "Max active power"); + ReportNode reportMinActivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(battery::setMinP, battery::getMinP, minP, "Min active power"); + if (subReportNode != null && (reportMaxActivePower != null || reportMinActivePower != null)) { subReportNodeLimits = subReportNode.newReportNode().withMessageTemplate(LIMITS, LIMITS).add(); ReportNode subReporterActiveLimits = subReportNodeLimits.newReportNode().withMessageTemplate(ACTIVE_LIMITS, ACTIVE_LIMITS).add(); if (reportMaxActivePower != null) { @@ -155,11 +164,14 @@ private void modifyBatteryReactiveLimitsAttributes(BatteryModificationInfos modi } } - private ReportNode modifyBatteryActivePowerControlAttributes(BatteryModificationInfos modificationInfos, - Battery battery, ReportNode subReportNode, ReportNode subReportNodeSetpoints) { + public static ReportNode modifyBatteryActivePowerControlAttributes(AttributeModification participate, + AttributeModification droop, + Battery battery, + ReportNode subReportNode, + ReportNode subReportNodeSetpoints) { ActivePowerControl activePowerControl = battery.getExtension(ActivePowerControl.class); ActivePowerControlAdder activePowerControlAdder = battery.newExtension(ActivePowerControlAdder.class); - return ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder, modificationInfos.getParticipate(), modificationInfos.getDroop(), subReportNode, subReportNodeSetpoints); + return ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder, participate, droop, subReportNode, subReportNodeSetpoints); } private ReportNode modifyBatteryConnectivityAttributes(BatteryModificationInfos modificationInfos, diff --git a/src/main/java/org/gridsuite/modification/server/modifications/ByFormulaModification.java b/src/main/java/org/gridsuite/modification/server/modifications/ByFormulaModification.java index 75616c713..a1f119008 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/ByFormulaModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/ByFormulaModification.java @@ -98,7 +98,6 @@ public void apply(Network network, ReportNode subReportNode) { .withUntypedValue(KEY_VALUE, equipmentCount) .withSeverity(TypedValue.INFO_SEVERITY) .add(); - report(formulaSubReporter, formulaReports); } else { if (equipmentNotModifiedCount == equipmentCount) { createReport(subReportNode, "byFormulaModificationNone", @@ -111,9 +110,9 @@ public void apply(Network network, ReportNode subReportNode) { .withUntypedValue(KEY_NB_UNCHANGED, equipmentNotModifiedCount + equipmentNotFoundCount) .withSeverity(TypedValue.WARN_SEVERITY) .add(); - report(formulaSubReporter, formulaReports); } } + report(formulaSubReporter, formulaReports); } } @@ -267,7 +266,7 @@ private void applyFormula(Identifiable identifiable, try { final Double newValue = applyOperation(formulaInfos.getOperator(), value1, value2); switch (identifiable.getType()) { - case GENERATOR -> GeneratorField.setNewValue((Generator) identifiable, formulaInfos.getEditedField(), newValue); + case GENERATOR -> GeneratorField.setNewValue((Generator) identifiable, formulaInfos.getEditedField(), newValue.doubleValue()); case BATTERY -> BatteryField.setNewValue((Battery) identifiable, formulaInfos.getEditedField(), newValue); case SHUNT_COMPENSATOR -> ShuntCompensatorField.setNewValue((ShuntCompensator) identifiable, formulaInfos.getEditedField(), newValue); case VOLTAGE_LEVEL -> VoltageLevelField.setNewValue((VoltageLevel) identifiable, formulaInfos.getEditedField(), newValue); diff --git a/src/main/java/org/gridsuite/modification/server/modifications/GeneratorModification.java b/src/main/java/org/gridsuite/modification/server/modifications/GeneratorModification.java index 03711328c..71a4508b9 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/GeneratorModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/GeneratorModification.java @@ -92,53 +92,58 @@ private void modifyGenerator(Generator generator, GeneratorModificationInfos mod modifyGeneratorLimitsAttributes(modificationInfos, generator, subReportNode); modifyGeneratorSetpointsAttributes(modificationInfos, generator, subReportNode); - modifyGeneratorShortCircuitAttributes(modificationInfos, generator, subReportNode); + modifyGeneratorShortCircuitAttributes(modificationInfos.getDirectTransX(), modificationInfos.getStepUpTransformerX(), generator, subReportNode); modifyGeneratorStartUpAttributes(modificationInfos, generator, subReportNode); modifyGeneratorConnectivityAttributes(modificationInfos, generator, subReportNode); PropertiesUtils.applyProperties(generator, subReportNode, modificationInfos.getProperties(), "GeneratorProperties"); } - private void modifyGeneratorShortCircuitAttributes(GeneratorModificationInfos modificationInfos, - Generator generator, ReportNode subReportNode) { + public static void modifyGeneratorShortCircuitAttributes(AttributeModification directTransX, + AttributeModification stepUpTransformerX, + Generator generator, + ReportNode subReportNode) { List reports = new ArrayList<>(); GeneratorShortCircuit generatorShortCircuit = generator.getExtension(GeneratorShortCircuit.class); Double oldTransientReactance = generatorShortCircuit != null ? generatorShortCircuit.getDirectTransX() : Double.NaN; Double oldStepUpTransformerReactance = generatorShortCircuit != null ? generatorShortCircuit.getStepUpTransformerX() : Double.NaN; // Either transient reactance or step-up transformer reactance are modified or // both - if (modificationInfos.getDirectTransX() != null - && modificationInfos.getStepUpTransformerX() != null) { + if (directTransX != null && stepUpTransformerX != null) { generator.newExtension(GeneratorShortCircuitAdder.class) - .withDirectTransX(modificationInfos.getDirectTransX().getValue()) - .withStepUpTransformerX(modificationInfos.getStepUpTransformerX().getValue()) + .withDirectTransX(directTransX.getValue()) + .withStepUpTransformerX(stepUpTransformerX.getValue()) .add(); reports.add(ModificationUtils.getInstance().buildModificationReport( oldTransientReactance, - modificationInfos.getDirectTransX().getValue(), + directTransX.getValue(), "Transient reactance")); reports.add(ModificationUtils.getInstance().buildModificationReport( oldStepUpTransformerReactance, - modificationInfos.getStepUpTransformerX().getValue(), + stepUpTransformerX.getValue(), "Transformer reactance")); - } else if (modificationInfos.getDirectTransX() != null) { + } else if (directTransX != null) { generator.newExtension(GeneratorShortCircuitAdder.class) - .withDirectTransX(modificationInfos.getDirectTransX().getValue()) + .withStepUpTransformerX(oldStepUpTransformerReactance) + .withDirectTransX(directTransX.getValue()) .add(); reports.add(ModificationUtils.getInstance().buildModificationReport( oldTransientReactance, - modificationInfos.getDirectTransX().getValue(), + directTransX.getValue(), "Transient reactance")); - } else if (modificationInfos.getStepUpTransformerX() != null) { + } else if (stepUpTransformerX != null) { generator.newExtension(GeneratorShortCircuitAdder.class) - .withStepUpTransformerX(modificationInfos.getStepUpTransformerX().getValue()) + .withStepUpTransformerX(stepUpTransformerX.getValue()) + .withDirectTransX(oldTransientReactance) .add(); reports.add(ModificationUtils.getInstance().buildModificationReport( oldStepUpTransformerReactance, - modificationInfos.getStepUpTransformerX().getValue(), + stepUpTransformerX.getValue(), "Transformer reactance")); } - ModificationUtils.getInstance().reportModifications(subReportNode, reports, "shortCircuitAttributesModified", "Short-circuit"); + if (subReportNode != null) { + ModificationUtils.getInstance().reportModifications(subReportNode, reports, "shortCircuitAttributesModified", "Short-circuit"); + } } private void modifyGeneratorReactiveCapabilityCurvePoints(GeneratorModificationInfos modificationInfos, @@ -149,22 +154,25 @@ private void modifyGeneratorReactiveCapabilityCurvePoints(GeneratorModificationI ModificationUtils.getInstance().modifyReactiveCapabilityCurvePoints(points, modificationPoints, adder, subReportNode, subReportNodeLimits); } - private ReportNode modifyGeneratorActiveLimitsAttributes(GeneratorModificationInfos modificationInfos, - Generator generator, ReportNode subReportNode) { + public static ReportNode modifyGeneratorActiveLimitsAttributes(AttributeModification maxP, + AttributeModification minP, + AttributeModification ratedS, + Generator generator, + ReportNode subReportNode) { ReportNode subReporterLimits = null; ReportNode reportMaxActivePower; ReportNode reportMinActivePower; - if (modificationInfos.getMaxP() != null && modificationInfos.getMaxP().getValue() > generator.getMinP()) { - reportMaxActivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(generator::setMaxP, generator::getMaxP, modificationInfos.getMaxP(), "Max active power"); - reportMinActivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(generator::setMinP, generator::getMinP, modificationInfos.getMinP(), "Min active power"); + if (maxP != null && maxP.getValue() > generator.getMinP()) { + reportMaxActivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(generator::setMaxP, generator::getMaxP, maxP, "Max active power"); + reportMinActivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(generator::setMinP, generator::getMinP, minP, "Min active power"); } else { - reportMinActivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(generator::setMinP, generator::getMinP, modificationInfos.getMinP(), "Min active power"); - reportMaxActivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(generator::setMaxP, generator::getMaxP, modificationInfos.getMaxP(), "Max active power"); + reportMinActivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(generator::setMinP, generator::getMinP, minP, "Min active power"); + reportMaxActivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(generator::setMaxP, generator::getMaxP, maxP, "Max active power"); } - ReportNode reportRatedNominalPower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(generator::setRatedS, generator::getRatedS, modificationInfos.getRatedS(), "Rated nominal power"); - if (reportMaxActivePower != null || reportMinActivePower != null || reportRatedNominalPower != null) { + ReportNode reportRatedNominalPower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(generator::setRatedS, generator::getRatedS, ratedS, "Rated nominal power"); + if (subReportNode != null && (reportMaxActivePower != null || reportMinActivePower != null || reportRatedNominalPower != null)) { subReporterLimits = subReportNode.newReportNode().withMessageTemplate(LIMITS, LIMITS).add(); ReportNode subReporterActiveLimits = subReporterLimits.newReportNode().withMessageTemplate(ACTIVE_LIMITS, ACTIVE_LIMITS).add(); if (reportMaxActivePower != null) { @@ -208,30 +216,53 @@ private ReportNode modifyGeneratorActivePowerControlAttributes(GeneratorModifica private void modifyGeneratorStartUpAttributes(GeneratorModificationInfos modificationInfos, Generator generator, ReportNode subReportNode) { List reports = new ArrayList<>(); - GeneratorStartup generatorStartup = generator.getExtension(GeneratorStartup.class); + modifyGeneratorStartUpAttributes(modificationInfos.getPlannedActivePowerSetPoint(), + modificationInfos.getMarginalCost(), + modificationInfos.getPlannedOutageRate(), + modificationInfos.getForcedOutageRate(), + generator, + subReportNode, + reports); + } + + public static void modifyGeneratorStartUpAttributes(AttributeModification plannedActivePowerSetPoint, + AttributeModification marginalCost, + AttributeModification plannedOutageRate, + AttributeModification forcedOutageRate, + Generator generator, + ReportNode subReportNode, + List reports) { GeneratorStartupAdder generatorStartupAdder = generator.newExtension(GeneratorStartupAdder.class); - boolean plannedActivePowerSetPointUpdated = addPlannedActivePowerSetPoint(modificationInfos, generatorStartupAdder, generatorStartup, reports); - boolean marginalCostUpdated = addMarginalCost(modificationInfos, generatorStartupAdder, generatorStartup, reports); - boolean plannedOutageRateUpdated = addPlannedOutageRate(modificationInfos, generatorStartupAdder, generatorStartup, reports); - boolean forcedOutageRateUpdated = addForcedOutageRate(modificationInfos, generatorStartupAdder, generatorStartup, reports); + GeneratorStartup generatorStartup = generator.getExtension(GeneratorStartup.class); + boolean plannedActivePowerSetPointUpdated = addPlannedActivePowerSetPoint(plannedActivePowerSetPoint, + generatorStartupAdder, + generatorStartup, + reports); + boolean marginalCostUpdated = addMarginalCost(marginalCost, generatorStartupAdder, generatorStartup, reports); + boolean plannedOutageRateUpdated = addPlannedOutageRate(plannedOutageRate, generatorStartupAdder, generatorStartup, reports); + boolean forcedOutageRateUpdated = addForcedOutageRate(forcedOutageRate, generatorStartupAdder, generatorStartup, reports); if (plannedActivePowerSetPointUpdated || marginalCostUpdated || plannedOutageRateUpdated || forcedOutageRateUpdated) { generatorStartupAdder.add(); - ModificationUtils.getInstance().reportModifications(subReportNode, reports, "startUpAttributesModified", "Start up"); + if (subReportNode != null) { + ModificationUtils.getInstance().reportModifications(subReportNode, reports, "startUpAttributesModified", "Start up"); + } } } - private boolean addForcedOutageRate(GeneratorModificationInfos modificationInfos, GeneratorStartupAdder generatorStartupAdder, GeneratorStartup generatorStartup, List reports) { + private static boolean addForcedOutageRate(AttributeModification forcedOutageRate, GeneratorStartupAdder generatorStartupAdder, GeneratorStartup generatorStartup, List reports) { Double oldForcedOutageRate = generatorStartup != null ? generatorStartup.getForcedOutageRate() : Double.NaN; - if (modificationInfos.getForcedOutageRate() != null) { + if (forcedOutageRate != null) { generatorStartupAdder - .withForcedOutageRate(modificationInfos.getForcedOutageRate().getValue()); - reports.add(ModificationUtils.getInstance().buildModificationReport(oldForcedOutageRate, - modificationInfos.getForcedOutageRate().getValue(), - "Forced outage rate")); + .withForcedOutageRate(forcedOutageRate.getValue()); + if (reports != null) { + reports.add(ModificationUtils.getInstance().buildModificationReport(oldForcedOutageRate, + forcedOutageRate.getValue(), + "Forced outage rate")); + } return true; } else { generatorStartupAdder @@ -240,14 +271,16 @@ private boolean addForcedOutageRate(GeneratorModificationInfos modificationInfos return false; } - private boolean addPlannedOutageRate(GeneratorModificationInfos modificationInfos, GeneratorStartupAdder generatorStartupAdder, GeneratorStartup generatorStartup, List reports) { + private static boolean addPlannedOutageRate(AttributeModification plannedOutageRate, GeneratorStartupAdder generatorStartupAdder, GeneratorStartup generatorStartup, List reports) { Double oldPlannedOutageRate = generatorStartup != null ? generatorStartup.getPlannedOutageRate() : Double.NaN; - if (modificationInfos.getPlannedOutageRate() != null) { + if (plannedOutageRate != null) { generatorStartupAdder - .withPlannedOutageRate(modificationInfos.getPlannedOutageRate().getValue()); - reports.add(ModificationUtils.getInstance().buildModificationReport(oldPlannedOutageRate, - modificationInfos.getPlannedOutageRate().getValue(), - "Planning outage rate")); + .withPlannedOutageRate(plannedOutageRate.getValue()); + if (reports != null) { + reports.add(ModificationUtils.getInstance().buildModificationReport(oldPlannedOutageRate, + plannedOutageRate.getValue(), + "Planning outage rate")); + } return true; } else { generatorStartupAdder @@ -256,14 +289,16 @@ private boolean addPlannedOutageRate(GeneratorModificationInfos modificationInfo return false; } - private boolean addMarginalCost(GeneratorModificationInfos modificationInfos, GeneratorStartupAdder generatorStartupAdder, GeneratorStartup generatorStartup, List reports) { + private static boolean addMarginalCost(AttributeModification marginalCost, GeneratorStartupAdder generatorStartupAdder, GeneratorStartup generatorStartup, List reports) { Double oldMarginalCost = generatorStartup != null ? generatorStartup.getMarginalCost() : Double.NaN; - if (modificationInfos.getMarginalCost() != null) { + if (marginalCost != null) { generatorStartupAdder - .withMarginalCost(modificationInfos.getMarginalCost().getValue()); - reports.add(ModificationUtils.getInstance().buildModificationReport(oldMarginalCost, - modificationInfos.getMarginalCost().getValue(), - "Marginal cost")); + .withMarginalCost(marginalCost.getValue()); + if (reports != null) { + reports.add(ModificationUtils.getInstance().buildModificationReport(oldMarginalCost, + marginalCost.getValue(), + "Marginal cost")); + } return true; } else { generatorStartupAdder @@ -272,14 +307,17 @@ private boolean addMarginalCost(GeneratorModificationInfos modificationInfos, Ge return false; } - private boolean addPlannedActivePowerSetPoint(GeneratorModificationInfos modificationInfos, GeneratorStartupAdder generatorStartupAdder, GeneratorStartup generatorStartup, List reports) { + private static boolean addPlannedActivePowerSetPoint(AttributeModification plannedActivePowerSetPoint, GeneratorStartupAdder generatorStartupAdder, + GeneratorStartup generatorStartup, List reports) { Double oldPlannedActivePowerSetPoint = generatorStartup != null ? generatorStartup.getPlannedActivePowerSetpoint() : Double.NaN; - if (modificationInfos.getPlannedActivePowerSetPoint() != null) { + if (plannedActivePowerSetPoint != null) { generatorStartupAdder - .withPlannedActivePowerSetpoint(modificationInfos.getPlannedActivePowerSetPoint().getValue()); - reports.add(ModificationUtils.getInstance().buildModificationReport(oldPlannedActivePowerSetPoint, - modificationInfos.getPlannedActivePowerSetPoint().getValue(), - "Planning active power set point")); + .withPlannedActivePowerSetpoint(plannedActivePowerSetPoint.getValue()); + if (reports != null) { + reports.add(ModificationUtils.getInstance().buildModificationReport(oldPlannedActivePowerSetPoint, + plannedActivePowerSetPoint.getValue(), + "Planning active power set point")); + } return true; } else { generatorStartupAdder @@ -339,15 +377,8 @@ private ReportNode modifyGeneratorVoltageRegulatorAttributes(GeneratorModificati Generator generator, ReportNode subReportNode, ReportNode subReportNodeSetpoints) { List voltageRegulationReports = new ArrayList<>(); - ReportNode reportVoltageSetpoint = null; - if (modificationInfos.getTargetV() != null) { - if (modificationInfos.getTargetV().getOp() == OperationType.SET) { - reportVoltageSetpoint = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(generator::setTargetV, generator::getTargetV, - modificationInfos.getTargetV(), "Voltage"); - } else { - reportVoltageSetpoint = ModificationUtils.getInstance().buildModificationReport(generator.getTargetV(), Double.NaN, "Voltage"); - } - } + ReportNode reportVoltageSetpoint = modifyTargetV(generator, modificationInfos.getTargetV()); + ReportNode voltageRegulationOn = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(generator::setVoltageRegulatorOn, generator::isVoltageRegulatorOn, modificationInfos.getVoltageRegulationOn(), "VoltageRegulationOn"); if (voltageRegulationOn != null) { @@ -392,17 +423,24 @@ private ReportNode modifyGeneratorVoltageRegulatorAttributes(GeneratorModificati return subReportNodeSetpoints2; } - private void modifyGeneratorSetpointsAttributes(GeneratorModificationInfos modificationInfos, - Generator generator, ReportNode subReportNode) { - ReportNode reportActivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(generator::setTargetP, generator::getTargetP, modificationInfos.getTargetP(), "Active power"); - ReportNode reportReactivePower = null; - if (modificationInfos.getTargetQ() != null) { - if (modificationInfos.getTargetQ().getOp() == OperationType.SET) { - reportReactivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(generator::setTargetQ, generator::getTargetQ, modificationInfos.getTargetQ(), "Reactive power"); + public static ReportNode modifyTargetV(Generator generator, AttributeModification modifTargetV) { + ReportNode reportVoltageSetpoint = null; + if (modifTargetV != null) { + if (modifTargetV.getOp() == OperationType.SET) { + reportVoltageSetpoint = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(generator::setTargetV, generator::getTargetV, + modifTargetV, "Voltage"); } else { - reportReactivePower = ModificationUtils.getInstance().buildModificationReport(generator.getTargetQ(), Double.NaN, "Reactive power"); + reportVoltageSetpoint = ModificationUtils.getInstance().buildModificationReport(generator.getTargetV(), Double.NaN, "Voltage"); } } + return reportVoltageSetpoint; + } + + private void modifyGeneratorSetpointsAttributes(GeneratorModificationInfos modificationInfos, + Generator generator, ReportNode subReportNode) { + ReportNode reportActivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(generator::setTargetP, generator::getTargetP, modificationInfos.getTargetP(), "Active power"); + + ReportNode reportReactivePower = modifyTargetQ(generator, modificationInfos.getTargetQ()); ReportNode subReporterSetpoints = null; if (reportActivePower != null || reportReactivePower != null) { @@ -418,9 +456,25 @@ private void modifyGeneratorSetpointsAttributes(GeneratorModificationInfos modif modifyGeneratorActivePowerControlAttributes(modificationInfos, generator, subReportNode, subReporterSetpoints); } + public static ReportNode modifyTargetQ(Generator generator, AttributeModification modifTargetQ) { + ReportNode reportReactivePower = null; + if (modifTargetQ != null) { + if (modifTargetQ.getOp() == OperationType.SET) { + reportReactivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(generator::setTargetQ, generator::getTargetQ, modifTargetQ, "Target reactive power"); + } else { + reportReactivePower = ModificationUtils.getInstance().buildModificationReport(generator.getTargetQ(), Double.NaN, "Target reactive power"); + } + } + return reportReactivePower; + } + private void modifyGeneratorLimitsAttributes(GeneratorModificationInfos modificationInfos, Generator generator, ReportNode subReportNode) { - ReportNode subReportNodeLimits = modifyGeneratorActiveLimitsAttributes(modificationInfos, generator, subReportNode); + ReportNode subReportNodeLimits = modifyGeneratorActiveLimitsAttributes(modificationInfos.getMaxP(), + modificationInfos.getMinP(), + modificationInfos.getRatedS(), + generator, + subReportNode); modifyGeneratorReactiveLimitsAttributes(modificationInfos, generator, subReportNode, subReportNodeLimits); } diff --git a/src/main/java/org/gridsuite/modification/server/modifications/LoadModification.java b/src/main/java/org/gridsuite/modification/server/modifications/LoadModification.java index 019271d8e..3bbbb68c8 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/LoadModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/LoadModification.java @@ -13,6 +13,7 @@ import com.powsybl.iidm.network.extensions.ConnectablePosition; import com.powsybl.iidm.network.extensions.ConnectablePositionAdder; import org.gridsuite.modification.server.NetworkModificationException; +import org.gridsuite.modification.server.dto.AttributeModification; import org.gridsuite.modification.server.dto.LoadModificationInfos; import static org.gridsuite.modification.server.NetworkModificationException.Type.LOAD_NOT_FOUND; @@ -53,13 +54,21 @@ private void modifyLoad(Load load, ReportNode subReportNode) { ModificationUtils.getInstance().applyElementaryModifications(load::setName, () -> load.getOptionalName().orElse("No value"), modificationInfos.getEquipmentName(), subReportNode, "Name"); ModificationUtils.getInstance().applyElementaryModifications(load::setLoadType, load::getLoadType, modificationInfos.getLoadType(), subReportNode, "Type"); - ModificationUtils.getInstance().applyElementaryModifications(load::setP0, load::getP0, modificationInfos.getP0(), subReportNode, "Constant active power"); - ModificationUtils.getInstance().applyElementaryModifications(load::setQ0, load::getQ0, modificationInfos.getQ0(), subReportNode, "Constant reactive power"); + modifyP0(load, modificationInfos.getP0(), subReportNode); + modifyQ0(load, modificationInfos.getQ0(), subReportNode); modifyLoadConnectivityAttributes(modificationInfos, load, subReportNode); // properties PropertiesUtils.applyProperties(load, subReportNode, modificationInfos.getProperties(), "LoadProperties"); } + public static void modifyQ0(Load load, AttributeModification q0, ReportNode subReportNode) { + ModificationUtils.getInstance().applyElementaryModifications(load::setQ0, load::getQ0, q0, subReportNode, "Constant reactive power"); + } + + public static void modifyP0(Load load, AttributeModification p0, ReportNode subReportNode) { + ModificationUtils.getInstance().applyElementaryModifications(load::setP0, load::getP0, p0, subReportNode, "Constant active power"); + } + private ReportNode modifyLoadConnectivityAttributes(LoadModificationInfos modificationInfos, Load load, ReportNode subReportNode) { ConnectablePosition connectablePosition = load.getExtension(ConnectablePosition.class); 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 92d4e588a..c2b94e850 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java @@ -509,7 +509,9 @@ public void applyElementaryModifications(Consumer setter, Supplier get T newValue = modification.applyModification(oldValue); setter.accept(newValue); - insertReportNode(subReportNode, buildModificationReport(oldValue, newValue, fieldName)); + if (subReportNode != null) { + insertReportNode(subReportNode, buildModificationReport(oldValue, newValue, fieldName)); + } } } @@ -1073,12 +1075,16 @@ private void modifyExistingActivePowerControl(ActivePowerControl activePowerC Optional.ofNullable(participateInfo).ifPresent(info -> { activePowerControl.setParticipate(info.getValue()); - reports.add(buildModificationReport(oldParticipate, info.getValue(), "Participate")); + if (reports != null) { + reports.add(buildModificationReport(oldParticipate, info.getValue(), "Participate")); + } }); Optional.ofNullable(droopInfo).ifPresent(info -> { activePowerControl.setDroop(info.getValue()); - reports.add(buildModificationReport(oldDroop, info.getValue(), "Droop")); + if (reports != null) { + reports.add(buildModificationReport(oldDroop, info.getValue(), "Droop")); + } }); } @@ -1088,22 +1094,22 @@ private void createNewActivePowerControl(ActivePowerControlAdder adder, List reports) { boolean participate = participateInfo != null ? participateInfo.getValue() : false; adder.withParticipate(participate); - if (participateInfo != null) { + if (participateInfo != null && reports != null) { reports.add(buildModificationReport(null, participate, "Participate")); } double droop = droopInfo != null ? droopInfo.getValue() : Double.NaN; adder.withDroop(droop); - if (droopInfo != null) { + if (droopInfo != null && reports != null) { reports.add(buildModificationReport(Double.NaN, droop, "Droop")); } adder.add(); } public ReportNode modifyActivePowerControlAttributes(ActivePowerControl activePowerControl, - ActivePowerControlAdder activePowerControlAdder, - AttributeModification participateInfo, - AttributeModification droopInfo, - ReportNode subReportNode, + ActivePowerControlAdder activePowerControlAdder, + AttributeModification participateInfo, + AttributeModification droopInfo, + ReportNode subReportNode, ReportNode subReporterSetpoints) { List reports = new ArrayList<>(); if (activePowerControl != null) { @@ -1111,13 +1117,15 @@ public ReportNode modifyActivePowerControlAttributes(ActivePowerControl activ } else { createNewActivePowerControl(activePowerControlAdder, participateInfo, droopInfo, reports); } - - ReportNode subReportNodeSetpoints2 = subReporterSetpoints; - if (subReporterSetpoints == null && !reports.isEmpty()) { - subReportNodeSetpoints2 = subReportNode.newReportNode().withMessageTemplate(SETPOINTS, SETPOINTS).add(); + if (subReportNode != null) { + ReportNode subReportNodeSetpoints2 = subReporterSetpoints; + if (subReporterSetpoints == null && !reports.isEmpty()) { + subReportNodeSetpoints2 = subReportNode.newReportNode().withMessageTemplate(SETPOINTS, SETPOINTS).add(); + } + reportModifications(subReportNodeSetpoints2, reports, "activePowerRegulationModified", "Active power regulation"); + return subReportNodeSetpoints2; } - reportModifications(subReportNodeSetpoints2, reports, "activePowerRegulationModified", "Active power regulation"); - return subReportNodeSetpoints2; + return null; } public void checkMaxQGreaterThanMinQ( diff --git a/src/main/java/org/gridsuite/modification/server/modifications/ShuntCompensatorModification.java b/src/main/java/org/gridsuite/modification/server/modifications/ShuntCompensatorModification.java index 25aaebe37..899ace841 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/ShuntCompensatorModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/ShuntCompensatorModification.java @@ -13,6 +13,7 @@ import com.powsybl.iidm.network.extensions.ConnectablePosition; import com.powsybl.iidm.network.extensions.ConnectablePositionAdder; import org.gridsuite.modification.server.NetworkModificationException; +import org.gridsuite.modification.server.dto.AttributeModification; import org.gridsuite.modification.server.dto.ShuntCompensatorModificationInfos; import org.gridsuite.modification.server.dto.ShuntCompensatorType; @@ -81,21 +82,30 @@ public void apply(Network network, ReportNode subReportNode) { PropertiesUtils.applyProperties(shuntCompensator, subReportNode, modificationInfos.getProperties(), "ShuntCompensatorProperties"); } - private void modifyMaximumSectionCount(List reports, ShuntCompensator shuntCompensator, ShuntCompensatorLinearModel model) { - if (modificationInfos.getMaximumSectionCount() != null) { - var maximumSectionCount = modificationInfos.getMaximumSectionCount().getValue(); - if (modificationInfos.getMaxSusceptance() == null && modificationInfos.getMaxQAtNominalV() == null) { + public static void modifyMaximumSectionCount(AttributeModification maximumSectionCountModif, + AttributeModification maxSusceptance, + AttributeModification maxQAtNominalV, + List reports, + ShuntCompensator shuntCompensator, + ShuntCompensatorLinearModel model) { + if (maximumSectionCountModif != null) { + var maximumSectionCount = maximumSectionCountModif.getValue(); + if (maxSusceptance == null && maxQAtNominalV == null) { model.setBPerSection(model.getBPerSection() * shuntCompensator.getMaximumSectionCount() / maximumSectionCount); } - reports.add(ModificationUtils.getInstance().buildModificationReport(shuntCompensator.getMaximumSectionCount(), maximumSectionCount, "Maximum section count")); + if (reports != null) { + reports.add(ModificationUtils.getInstance().buildModificationReport(shuntCompensator.getMaximumSectionCount(), maximumSectionCount, "Maximum section count")); + } model.setMaximumSectionCount(maximumSectionCount); } } - private void modifySectionCount(List reports, ShuntCompensator shuntCompensator) { - if (modificationInfos.getSectionCount() != null) { - var newSectionCount = modificationInfos.getSectionCount().getValue(); - reports.add(ModificationUtils.getInstance().buildModificationReport(shuntCompensator.getSectionCount(), newSectionCount, "Section count")); + public static void modifySectionCount(AttributeModification sectionCount, List reports, ShuntCompensator shuntCompensator) { + if (sectionCount != null) { + var newSectionCount = sectionCount.getValue(); + if (reports != null) { + reports.add(ModificationUtils.getInstance().buildModificationReport(shuntCompensator.getSectionCount(), newSectionCount, "Section count")); + } shuntCompensator.setSectionCount(newSectionCount); } } @@ -106,7 +116,6 @@ private void applyModificationOnLinearModel(ReportNode subReportNode, ShuntCompe var shuntCompensatorType = model.getBPerSection() > 0 ? ShuntCompensatorType.CAPACITOR : ShuntCompensatorType.REACTOR; double oldSusceptancePerSection = model.getBPerSection(); double oldQAtNominalV = Math.abs(Math.pow(voltageLevel.getNominalV(), 2) * oldSusceptancePerSection); - double oldMaxSusceptance = oldSusceptancePerSection * shuntCompensator.getMaximumSectionCount(); double oldMaxQAtNominalV = oldQAtNominalV * shuntCompensator.getMaximumSectionCount(); double oldSwitchedOnSusceptance = oldSusceptancePerSection * shuntCompensator.getSectionCount(); double oldSwitchedOnQAtNominalV = oldQAtNominalV * shuntCompensator.getSectionCount(); @@ -118,11 +127,17 @@ private void applyModificationOnLinearModel(ReportNode subReportNode, ShuntCompe // due to cross validation between maximum section count and section count, we need to modify section count first // when maximum section count old value is greater than the new one if (modificationInfos.getMaximumSectionCount() != null && modificationInfos.getMaximumSectionCount().getValue() < shuntCompensator.getMaximumSectionCount()) { - modifySectionCount(reports, shuntCompensator); - modifyMaximumSectionCount(reports, shuntCompensator, model); + modifySectionCount(modificationInfos.getSectionCount(), reports, shuntCompensator); + modifyMaximumSectionCount(modificationInfos.getMaximumSectionCount(), + modificationInfos.getMaxSusceptance(), + modificationInfos.getMaxQAtNominalV(), + reports, shuntCompensator, model); } else { - modifyMaximumSectionCount(reports, shuntCompensator, model); - modifySectionCount(reports, shuntCompensator); + modifyMaximumSectionCount(modificationInfos.getMaximumSectionCount(), + modificationInfos.getMaxSusceptance(), + modificationInfos.getMaxQAtNominalV(), + reports, shuntCompensator, model); + modifySectionCount(modificationInfos.getSectionCount(), reports, shuntCompensator); } int maximumSectionCount = modificationInfos.getMaximumSectionCount() != null ? modificationInfos.getMaximumSectionCount().getValue() : shuntCompensator.getMaximumSectionCount(); @@ -140,22 +155,10 @@ private void applyModificationOnLinearModel(ReportNode subReportNode, ShuntCompe } if (modificationInfos.getMaxQAtNominalV() != null) { - if (modificationInfos.getMaxQAtNominalV().getValue() < 0) { - throw new NetworkModificationException(NetworkModificationException.Type.MODIFY_SHUNT_COMPENSATOR_ERROR, - "Qmax at nominal voltage should be greater or equal to 0"); - } - double newQatNominalV = modificationInfos.getMaxQAtNominalV().getValue() / maximumSectionCount; - double newSusceptancePerSection = newQatNominalV / Math.pow(voltageLevel.getNominalV(), 2); - reports.add(ModificationUtils.getInstance().buildModificationReport(oldMaxQAtNominalV, modificationInfos.getMaxQAtNominalV().getValue(), "Qmax available at nominal voltage")); - - model.setBPerSection(shuntCompensatorType == ShuntCompensatorType.CAPACITOR ? newSusceptancePerSection : -newSusceptancePerSection); + modifyMaximumQAtNominalVoltage(modificationInfos.getMaxQAtNominalV(), voltageLevel, maximumSectionCount, reports, model, shuntCompensatorType); } - if (modificationInfos.getMaxSusceptance() != null) { - double newSusceptancePerSection = modificationInfos.getMaxSusceptance().getValue() / maximumSectionCount; - reports.add(ModificationUtils.getInstance().buildModificationReport(oldMaxSusceptance, modificationInfos.getMaxSusceptance().getValue(), "Maximal susceptance available")); - - model.setBPerSection(newSusceptancePerSection); + modifyMaxSusceptance(modificationInfos.getMaxSusceptance(), maximumSectionCount, reports, model); } reportSwitchedOnAndPerSectionValues(reports, oldQAtNominalV, oldSwitchedOnQAtNominalV, oldSusceptancePerSection, oldSwitchedOnSusceptance, oldMaxQAtNominalV, sectionCount, maximumSectionCount); @@ -163,6 +166,41 @@ private void applyModificationOnLinearModel(ReportNode subReportNode, ShuntCompe reports.forEach(report -> insertReportNode(subReportNode, report)); } + public static void modifyMaxSusceptance(AttributeModification maxSusceptance, + int maximumSectionCount, + List reports, + ShuntCompensatorLinearModel model) { + double newSusceptancePerSection = maxSusceptance.getValue() / maximumSectionCount; + if (reports != null) { + double oldSusceptancePerSection = model.getBPerSection(); + double oldMaxSusceptance = oldSusceptancePerSection * maximumSectionCount; + reports.add(ModificationUtils.getInstance().buildModificationReport(oldMaxSusceptance, maxSusceptance.getValue(), "Maximal susceptance available")); + } + model.setBPerSection(newSusceptancePerSection); + } + + public static void modifyMaximumQAtNominalVoltage(AttributeModification maxQAtNominalV, + VoltageLevel voltageLevel, + int maximumSectionCount, + List reports, + ShuntCompensatorLinearModel model, + ShuntCompensatorType shuntCompensatorType) { + if (maxQAtNominalV.getValue() < 0) { + throw new NetworkModificationException(NetworkModificationException.Type.MODIFY_SHUNT_COMPENSATOR_ERROR, + "Qmax at nominal voltage should be greater or equal to 0"); + } + double newQatNominalV = maxQAtNominalV.getValue() / maximumSectionCount; + double newSusceptancePerSection = newQatNominalV / Math.pow(voltageLevel.getNominalV(), 2); + if (reports != null) { + double oldSusceptancePerSection = model.getBPerSection(); + double oldQAtNominalV = Math.abs(Math.pow(voltageLevel.getNominalV(), 2) * oldSusceptancePerSection); + double oldMaxQAtNominalV = oldQAtNominalV * maximumSectionCount; + reports.add(ModificationUtils.getInstance().buildModificationReport(oldMaxQAtNominalV, maxQAtNominalV.getValue(), "Qmax available at nominal voltage")); + } + + model.setBPerSection(shuntCompensatorType == ShuntCompensatorType.CAPACITOR ? newSusceptancePerSection : -newSusceptancePerSection); + } + private void reportSwitchedOnAndPerSectionValues(List reports, double oldQAtNominalV, double oldSwitchedOnQAtNominalV, double oldSusceptancePerSection, double oldSwitchedOnSusceptance, double oldMaxQAtNominalV, int sectionCount, int maximumSectionCount) { if (modificationInfos.getMaxQAtNominalV() != null) { double newQatNominalV = modificationInfos.getMaxQAtNominalV().getValue() / maximumSectionCount; diff --git a/src/main/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModification.java b/src/main/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModification.java index 4a940d4cc..5fee968aa 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModification.java @@ -26,6 +26,7 @@ public class TwoWindingsTransformerModification extends AbstractBranchModificati private static final String RATIO_TAP_CHANGER_SUBREPORTER_DEFAULT_MESSAGE = "Ratio tap changer"; private static final String PHASE_TAP_CHANGER_SUBREPORTER_DEFAULT_MESSAGE = "Phase tap changer"; + public static final String MAGNETIZING_CONDUCTANCE_FIELD_NAME = "Magnetizing conductance"; public TwoWindingsTransformerModification(TwoWindingsTransformerModificationInfos modificationInfos) { super(modificationInfos); @@ -58,49 +59,111 @@ protected void modifyCharacteristics(Branch branch, BranchModificationInfos b ReportNode characteristicsReporter = subReportNode.newReportNode().withMessageTemplate("characteristics", "Characteristics").add(); // Branch specific fields - if (branchModificationInfos.getR() != null && branchModificationInfos.getR().getValue() != null) { - insertReportNode(characteristicsReporter, ModificationUtils.getInstance().buildModificationReport(twoWindingsTransformer.getR(), - branchModificationInfos.getR().getValue(), "Series resistance", 1)); - twoWindingsTransformer.setR(branchModificationInfos.getR().getValue()); - } - if (branchModificationInfos.getX() != null && branchModificationInfos.getX().getValue() != null) { - insertReportNode(characteristicsReporter, ModificationUtils.getInstance().buildModificationReport(twoWindingsTransformer.getX(), - branchModificationInfos.getX().getValue(), "Series reactance", 1)); - twoWindingsTransformer.setX(branchModificationInfos.getX().getValue()); - } + modifyR(twoWindingsTransformer, branchModificationInfos.getR(), characteristicsReporter); + modifyX(twoWindingsTransformer, branchModificationInfos.getX(), characteristicsReporter); // Transformer specific fields TwoWindingsTransformerModificationInfos twoWindingsTransformerModificationInfos = (TwoWindingsTransformerModificationInfos) branchModificationInfos; - if (twoWindingsTransformerModificationInfos.getG() != null && twoWindingsTransformerModificationInfos.getG().getValue() != null) { - // convert reported value from siemens to microsiemens - double oldMagnetizingConductanceToReport = twoWindingsTransformer.getG() * Math.pow(10, 6); - double newMagnetizingConductanceToReport = twoWindingsTransformerModificationInfos.getG().getValue() * Math.pow(10, 6); - insertReportNode(characteristicsReporter, ModificationUtils.getInstance().buildModificationReport(oldMagnetizingConductanceToReport, - newMagnetizingConductanceToReport, "Magnetizing conductance", 1)); - twoWindingsTransformer.setG(twoWindingsTransformerModificationInfos.getG().getValue()); + modifyTransformerFields(twoWindingsTransformer, + twoWindingsTransformerModificationInfos.getG(), + twoWindingsTransformerModificationInfos.getB(), + twoWindingsTransformerModificationInfos.getRatedS(), + twoWindingsTransformerModificationInfos.getRatedU1(), + twoWindingsTransformerModificationInfos.getRatedU2(), + characteristicsReporter); + } + + public static void modifyTransformerFields(TwoWindingsTransformer transformer, + AttributeModification modifG, + AttributeModification modifB, + AttributeModification modifRatedS, + AttributeModification modifRatedU1, + AttributeModification modifRatedU2, + ReportNode reportNode) { + modifyG(transformer, modifG, reportNode); + modifyB(transformer, modifB, reportNode); + modifyRatedS(transformer, modifRatedS, reportNode); + modifyRatedU1(transformer, modifRatedU1, reportNode); + modifyRatedU2(transformer, modifRatedU2, reportNode); + } + + public static void modifyRatedU2(TwoWindingsTransformer transformer, AttributeModification modifRatedU2, ReportNode reportNode) { + if (modifRatedU2 != null && modifRatedU2.getValue() != null) { + if (reportNode != null) { + insertReportNode(reportNode, ModificationUtils.getInstance().buildModificationReport(transformer.getRatedU2(), + modifRatedU2.getValue(), "Rated Voltage (Side 2)", 1)); + } + transformer.setRatedU2(modifRatedU2.getValue()); } - if (twoWindingsTransformerModificationInfos.getB() != null && twoWindingsTransformerModificationInfos.getB().getValue() != null) { + } + + public static void modifyRatedU1(TwoWindingsTransformer transformer, AttributeModification modifRatedU1, ReportNode reportNode) { + if (modifRatedU1 != null && modifRatedU1.getValue() != null) { + if (reportNode != null) { + insertReportNode(reportNode, ModificationUtils.getInstance().buildModificationReport(transformer.getRatedU1(), + modifRatedU1.getValue(), "Rated Voltage (Side 1)", 1)); + } + transformer.setRatedU1(modifRatedU1.getValue()); + } + } + + public static void modifyRatedS(TwoWindingsTransformer transformer, AttributeModification modifRatedS, ReportNode reportNode) { + if (modifRatedS != null && modifRatedS.getValue() != null) { + if (reportNode != null) { + insertReportNode(reportNode, ModificationUtils.getInstance().buildModificationReport(transformer.getRatedS(), + modifRatedS.getValue(), "Rated nominal power", 1)); + } + transformer.setRatedS(modifRatedS.getValue()); + } + } + + public static void modifyB(TwoWindingsTransformer transformer, AttributeModification modifB, ReportNode reportNode) { + if (modifB != null && modifB.getValue() != null) { // convert reported value from siemens to microsiemens - double oldMagnetizingSusceptanceToReport = twoWindingsTransformer.getB() * Math.pow(10, 6); - double newMagnetizingSusceptanceToReport = twoWindingsTransformerModificationInfos.getB().getValue() * Math.pow(10, 6); - insertReportNode(characteristicsReporter, ModificationUtils.getInstance().buildModificationReport(oldMagnetizingSusceptanceToReport, - newMagnetizingSusceptanceToReport, "Magnetizing susceptance", 1)); - twoWindingsTransformer.setB(twoWindingsTransformerModificationInfos.getB().getValue()); + if (reportNode != null) { + double oldMagnetizingSusceptanceToReport = transformer.getB() * Math.pow(10, 6); + double newMagnetizingSusceptanceToReport = modifB.getValue() * Math.pow(10, 6); + insertReportNode(reportNode, ModificationUtils.getInstance().buildModificationReport(oldMagnetizingSusceptanceToReport, + newMagnetizingSusceptanceToReport, "Magnetizing susceptance", 1)); + } + transformer.setB(modifB.getValue()); } - if (twoWindingsTransformerModificationInfos.getRatedS() != null && twoWindingsTransformerModificationInfos.getRatedS().getValue() != null) { - insertReportNode(characteristicsReporter, ModificationUtils.getInstance().buildModificationReport(twoWindingsTransformer.getRatedS(), - twoWindingsTransformerModificationInfos.getRatedS().getValue(), "Rated nominal power", 1)); - twoWindingsTransformer.setRatedS(twoWindingsTransformerModificationInfos.getRatedS().getValue()); + } + + public static void modifyG(TwoWindingsTransformer transformer, AttributeModification modifG, ReportNode reportNode) { + if (modifG != null && modifG.getValue() != null) { + // convert reported value from siemens to microsiemens + if (reportNode != null) { + double oldMagnetizingConductanceToReport = transformer.getG() * Math.pow(10, 6); + double newMagnetizingConductanceToReport = modifG.getValue() * Math.pow(10, 6); + ReportNode gReportNode = ModificationUtils.getInstance().buildModificationReport( + oldMagnetizingConductanceToReport, + newMagnetizingConductanceToReport, + MAGNETIZING_CONDUCTANCE_FIELD_NAME, + 1); + insertReportNode(reportNode, gReportNode); + } + transformer.setG(modifG.getValue()); } - if (twoWindingsTransformerModificationInfos.getRatedU1() != null && twoWindingsTransformerModificationInfos.getRatedU1().getValue() != null) { - insertReportNode(characteristicsReporter, ModificationUtils.getInstance().buildModificationReport(twoWindingsTransformer.getRatedU1(), - twoWindingsTransformerModificationInfos.getRatedU1().getValue(), "Rated Voltage (Side 1)", 1)); - twoWindingsTransformer.setRatedU1(twoWindingsTransformerModificationInfos.getRatedU1().getValue()); + } + + public static void modifyX(TwoWindingsTransformer twt, AttributeModification modifX, ReportNode reportNode) { + if (modifX != null && modifX.getValue() != null) { + if (reportNode != null) { + insertReportNode(reportNode, ModificationUtils.getInstance().buildModificationReport(twt.getX(), + modifX.getValue(), "Series reactance", 1)); + } + twt.setX(modifX.getValue()); } - if (twoWindingsTransformerModificationInfos.getRatedU2() != null && twoWindingsTransformerModificationInfos.getRatedU2().getValue() != null) { - insertReportNode(characteristicsReporter, ModificationUtils.getInstance().buildModificationReport(twoWindingsTransformer.getRatedU2(), - twoWindingsTransformerModificationInfos.getRatedU2().getValue(), "Rated Voltage (Side 2)", 1)); - twoWindingsTransformer.setRatedU2(twoWindingsTransformerModificationInfos.getRatedU2().getValue()); + } + + public static void modifyR(TwoWindingsTransformer twt, AttributeModification modifR, ReportNode reportNode) { + if (modifR != null && modifR.getValue() != null) { + if (reportNode != null) { + insertReportNode(reportNode, ModificationUtils.getInstance().buildModificationReport(twt.getR(), + modifR.getValue(), "Series resistance", 1)); + } + twt.setR(modifR.getValue()); } } @@ -152,8 +215,8 @@ private void processPhaseTapChanger(Network network, regulationMode = phaseTapChangerInfos.getRegulationMode().getValue(); } if (!PhaseTapChanger.RegulationMode.FIXED_TAP.equals(regulationMode)) { - processPhaseTapRegulation(phaseTapChangerInfos, phaseTapChanger, phaseTapChangerAdder, regulationReports, - regulationMode, isModification); + processPhaseTapRegulation(phaseTapChanger, phaseTapChangerAdder, regulationMode, isModification, phaseTapChangerInfos.getRegulationValue(), phaseTapChangerInfos.getTargetDeadband(), regulationReports + ); } processRegulatingTerminal(phaseTapChangerInfos, phaseTapChanger, phaseTapChangerAdder, regulationReports, @@ -161,8 +224,7 @@ private void processPhaseTapChanger(Network network, twt, isModification); List positionsAndStepsReports = new ArrayList<>(); - processTapChangerPositionsAndSteps(phaseTapChangerInfos, phaseTapChanger, phaseTapChangerAdder, positionsAndStepsReports, - isModification); + processTapChangerPositionsAndSteps(phaseTapChanger, phaseTapChangerAdder, isModification, phaseTapChangerInfos.getLowTapPosition(), phaseTapChangerInfos.getTapPosition(), phaseTapChangerInfos.getSteps(), positionsAndStepsReports); if (!isModification) { phaseTapChangerAdder.add(); @@ -186,33 +248,36 @@ private void processPhaseTapChanger(Network network, } } - private void processPhaseTapRegulation(PhaseTapChangerModificationInfos phaseTapChangerInfos, - PhaseTapChanger phaseTapChanger, - PhaseTapChangerAdder phaseTapChangerAdder, - List regulationReports, - PhaseTapChanger.RegulationMode regulationMode, - boolean isModification) { + public static void processPhaseTapRegulation(PhaseTapChanger phaseTapChanger, + PhaseTapChangerAdder phaseTapChangerAdder, + PhaseTapChanger.RegulationMode regulationMode, + boolean isModification, + AttributeModification modifyRegulationValue, + AttributeModification modifyTargetDeadband, + List regulationReports) { if (regulationMode != null) { - ReportNode regulationReport = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport( + String fieldName = (regulationMode.equals(PhaseTapChanger.RegulationMode.CURRENT_LIMITER)) ? "Value" : "Flow set point"; + ReportNode regulationValueReportNode = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport( isModification ? phaseTapChanger::setRegulationValue : phaseTapChangerAdder::setRegulationValue, isModification ? phaseTapChanger::getRegulationValue : () -> null, - phaseTapChangerInfos.getRegulationValue(), - regulationMode.equals(PhaseTapChanger.RegulationMode.CURRENT_LIMITER) ? "Value" : "Flow set point", + modifyRegulationValue, + fieldName, 2); - if (regulationReport != null) { - regulationReports.add(regulationReport); + if (regulationReports != null && regulationValueReportNode != null) { + regulationReports.add(regulationValueReportNode); } } - ReportNode targetDeadbandReport = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport( + ReportNode targetDeadbandReportNode = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport( isModification ? phaseTapChanger::setTargetDeadband : phaseTapChangerAdder::setTargetDeadband, isModification ? phaseTapChanger::getTargetDeadband : () -> null, - phaseTapChangerInfos.getTargetDeadband(), "Target deadband", 2); - if (targetDeadbandReport != null) { - regulationReports.add(targetDeadbandReport); + modifyTargetDeadband, "Target deadband", 2); + + if (regulationReports != null && targetDeadbandReportNode != null) { + regulationReports.add(targetDeadbandReportNode); } if (isModification) { @@ -246,8 +311,8 @@ private void processRatioTapChanger(Network network, processRatioVoltageRegulation(ratioTapChangerInfos, twt, ratioTapChanger, ratioTapChangerAdder, voltageRegulationReports, network, isModification); List positionsAndStepsReports = new ArrayList<>(); - processTapChangerPositionsAndSteps(ratioTapChangerInfos, ratioTapChanger, ratioTapChangerAdder, positionsAndStepsReports, - isModification); + processTapChangerPositionsAndSteps(ratioTapChanger, ratioTapChangerAdder, isModification, ratioTapChangerInfos.getLowTapPosition(), ratioTapChangerInfos.getTapPosition(), ratioTapChangerInfos.getSteps(), positionsAndStepsReports + ); if (!isModification) { ratioTapChangerAdder.add(); @@ -292,27 +357,33 @@ private void processRatioVoltageRegulation(RatioTapChangerModificationInfos rati List voltageRegulationReports, Network network, boolean isModification) { + modifyTargets(ratioTapChanger, ratioTapChangerAdder, isModification, ratioTapChangerInfos.getTargetV(), ratioTapChangerInfos.getTargetDeadband(), voltageRegulationReports); - ReportNode targetVoltageReport = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport( - isModification ? ratioTapChanger::setTargetV - : ratioTapChangerAdder::setTargetV, - isModification ? ratioTapChanger::getTargetV : () -> null, - ratioTapChangerInfos.getTargetV(), "Target voltage", 2); - if (targetVoltageReport != null) { - voltageRegulationReports.add(targetVoltageReport); - } + processRegulatingTerminal(ratioTapChangerInfos, ratioTapChanger, ratioTapChangerAdder, voltageRegulationReports, + network, twt, isModification); + } + + public static void modifyTargets(RatioTapChanger ratioTapChanger, RatioTapChangerAdder ratioTapChangerAdder, boolean isModification, AttributeModification targetV, AttributeModification targetDeadband, List voltageRegulationReports) { + ReportNode targetVoltageReportNode = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport( + isModification ? ratioTapChanger::setTargetV + : ratioTapChangerAdder::setTargetV, + isModification ? ratioTapChanger::getTargetV : () -> null, + targetV, "Target voltage", 2); - ReportNode targetDeadbandReport = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport( + ReportNode targetDeadbandReportNode = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport( isModification ? ratioTapChanger::setTargetDeadband : ratioTapChangerAdder::setTargetDeadband, isModification ? ratioTapChanger::getTargetDeadband : () -> null, - ratioTapChangerInfos.getTargetDeadband(), "Target deadband", 2); - if (targetDeadbandReport != null) { - voltageRegulationReports.add(targetDeadbandReport); - } + targetDeadband, "Target deadband", 2); - processRegulatingTerminal(ratioTapChangerInfos, ratioTapChanger, ratioTapChangerAdder, voltageRegulationReports, - network, twt, isModification); + if (voltageRegulationReports != null) { + if (targetVoltageReportNode != null) { + voltageRegulationReports.add(targetVoltageReportNode); + } + if (targetDeadbandReportNode != null) { + voltageRegulationReports.add(targetDeadbandReportNode); + } + } } private void processRegulatingTerminal(TapChangerModificationInfos tapChangerModificationInfos, @@ -369,35 +440,25 @@ private void setRegulatingTerminalInfos(TapChangerModificationInfos tapChangerMo tapChangerModificationInfos.setRegulatingTerminalType(new AttributeModification<>(terminal.getConnectable().getType().name(), OperationType.SET)); } - private void processTapchangerSteps(List tapChangerStepsReports, - TapChangerModificationInfos tapChangerModificationInfos, - TapChangerAdder tapChangerAdder, - TapChangerStepsReplacer tapChangerStepReplacer, - boolean isModification) { - tapChangerStepsReports.add(ReportNode.newRootReportNode() - .withMessageTemplate("tapChangerStepsModification", " Taps were replaced by new ones below") - .withSeverity(TypedValue.INFO_SEVERITY) - .build()); - for (TapChangerStepCreationInfos step : tapChangerModificationInfos.getSteps()) { - addStepAttributeReports(tapChangerStepsReports, step); + private static void processTapchangerSteps(List tapChangerStepsReports, + TapChangerAdder tapChangerAdder, + TapChangerStepsReplacer tapChangerStepReplacer, + boolean isModification, + List modifSteps) { + if (tapChangerStepsReports != null) { + tapChangerStepsReports.add(ReportNode.newRootReportNode() + .withMessageTemplate("tapChangerStepsModification", " Taps were replaced by new ones below") + .withSeverity(TypedValue.INFO_SEVERITY) + .build()); + } + for (TapChangerStepCreationInfos step : modifSteps) { + if (tapChangerStepsReports != null) { + addStepAttributeReports(tapChangerStepsReports, step); + } if (tapChangerStepReplacer instanceof RatioTapChangerStepsReplacer || tapChangerAdder instanceof RatioTapChangerAdder) { - if (isModification) { - tapChangerStepReplacer.beginStep().setR(step.getR()).setX(step.getX()).setG(step.getG()) - .setB(step.getB()).setRho(step.getRho()).endStep(); - } else { - tapChangerAdder.beginStep().setR(step.getR()).setX(step.getX()).setG(step.getG()) - .setB(step.getB()).setRho(step.getRho()).endStep(); - } + processRatioTapChangerStep(tapChangerAdder, tapChangerStepReplacer, isModification, step); } else { - addStepAttributeReport(tapChangerStepsReports, "newStepAlpha" + step.getAlpha(), - " Shift angle : ${alpha}", "alpha", String.valueOf(step.getAlpha())); - if (isModification) { - ((PhaseTapChangerStepsReplacer) tapChangerStepReplacer).beginStep().setR(step.getR()).setX(step.getX()).setG(step.getG()) - .setB(step.getB()).setRho(step.getRho()).setAlpha(step.getAlpha()).endStep(); - } else { - ((PhaseTapChangerAdder) tapChangerAdder).beginStep().setR(step.getR()).setX(step.getX()).setG(step.getG()) - .setB(step.getB()).setRho(step.getRho()).setAlpha(step.getAlpha()).endStep(); - } + processPhaseTapChangerStep(tapChangerStepsReports, (PhaseTapChangerAdder) tapChangerAdder, (PhaseTapChangerStepsReplacer) tapChangerStepReplacer, isModification, step); } } if (isModification) { @@ -405,7 +466,31 @@ private void processTapchangerSteps(List tapChangerStepsReports, } } - private void addStepAttributeReports(List tapChangerStepsReports, TapChangerStepCreationInfos step) { + private static void processPhaseTapChangerStep(List tapChangerStepsReports, PhaseTapChangerAdder tapChangerAdder, PhaseTapChangerStepsReplacer tapChangerStepReplacer, boolean isModification, TapChangerStepCreationInfos step) { + if (tapChangerStepsReports != null) { + addStepAttributeReport(tapChangerStepsReports, "newStepAlpha" + step.getAlpha(), + " Shift angle : ${alpha}", "alpha", String.valueOf(step.getAlpha())); + } + if (isModification) { + tapChangerStepReplacer.beginStep().setR(step.getR()).setX(step.getX()).setG(step.getG()) + .setB(step.getB()).setRho(step.getRho()).setAlpha(step.getAlpha()).endStep(); + } else { + tapChangerAdder.beginStep().setR(step.getR()).setX(step.getX()).setG(step.getG()) + .setB(step.getB()).setRho(step.getRho()).setAlpha(step.getAlpha()).endStep(); + } + } + + private static void processRatioTapChangerStep(TapChangerAdder tapChangerAdder, TapChangerStepsReplacer tapChangerStepReplacer, boolean isModification, TapChangerStepCreationInfos step) { + if (isModification) { + tapChangerStepReplacer.beginStep().setR(step.getR()).setX(step.getX()).setG(step.getG()) + .setB(step.getB()).setRho(step.getRho()).endStep(); + } else { + tapChangerAdder.beginStep().setR(step.getR()).setX(step.getX()).setG(step.getG()) + .setB(step.getB()).setRho(step.getRho()).endStep(); + } + } + + private static void addStepAttributeReports(List tapChangerStepsReports, TapChangerStepCreationInfos step) { addStepAttributeReport(tapChangerStepsReports, "newStepIndex" + step.getIndex(), " Tap (${index})", "index", String.valueOf(step.getIndex())); addStepAttributeReport(tapChangerStepsReports, "newStepResistance" + step.getR(), @@ -420,41 +505,48 @@ private void addStepAttributeReports(List tapChangerStepsReports, Ta " Ratio : ${rho}", "rho", String.valueOf(step.getRho())); } - private void processTapChangerPositionsAndSteps(TapChangerModificationInfos tapChangerModificationInfos, - TapChanger tapChanger, - TapChangerAdder tapChangerAdder, - List tapChangerReports, - boolean isModification) { - ReportNode lowTapPositionReport = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport( + public static void processTapChangerPositionsAndSteps(TapChanger tapChanger, + TapChangerAdder tapChangerAdder, + boolean isModification, + AttributeModification modifyLowTapPosition, + AttributeModification modifyTapPosition, + List modifySteps, + List tapChangerReports) { + ReportNode lowTapPositionReportNode = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport( isModification ? tapChanger::setLowTapPosition : tapChangerAdder::setLowTapPosition, isModification ? tapChanger::getLowTapPosition : () -> null, - tapChangerModificationInfos.getLowTapPosition(), "Low tap position", 2); - if (lowTapPositionReport != null) { - tapChangerReports.add(lowTapPositionReport); - } + modifyLowTapPosition, "Low tap position", 2); - ReportNode tapPositionReport = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport( + ReportNode tapPositionReportNode = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport( isModification ? tapChanger::setTapPosition : tapChangerAdder::setTapPosition, isModification ? tapChanger::getTapPosition : () -> null, - tapChangerModificationInfos.getTapPosition(), "Tap position", 2); - if (tapPositionReport != null) { - tapChangerReports.add(tapPositionReport); + modifyTapPosition, "Tap position", 2); + + if (tapChangerReports != null) { + if (lowTapPositionReportNode != null) { + tapChangerReports.add(lowTapPositionReportNode); + } + if (tapPositionReportNode != null) { + tapChangerReports.add(tapPositionReportNode); + } } // Add steps - if (tapChangerModificationInfos.getSteps() != null) { - tapChangerReports.add(ReportNode.newRootReportNode() - .withMessageTemplate("tapsModification", " Taps") - .withSeverity(TypedValue.INFO_SEVERITY) - .build()); - processTapchangerSteps(tapChangerReports, tapChangerModificationInfos, - tapChangerAdder, isModification ? tapChanger.stepsReplacer() : null, isModification); + if (modifySteps != null) { + if (tapChangerReports != null) { + tapChangerReports.add(ReportNode.newRootReportNode() + .withMessageTemplate("tapsModification", " Taps") + .withSeverity(TypedValue.INFO_SEVERITY) + .build()); + } + processTapchangerSteps(tapChangerReports, + tapChangerAdder, isModification ? tapChanger.stepsReplacer() : null, isModification, modifySteps); } } - private void addStepAttributeReport(List tapChangerStepsReports, String key, String defaultMessage, + private static void addStepAttributeReport(List tapChangerStepsReports, String key, String defaultMessage, String valueKey, String value) { tapChangerStepsReports.add(ReportNode.newRootReportNode() .withMessageTemplate(key, defaultMessage) diff --git a/src/main/java/org/gridsuite/modification/server/modifications/VoltageLevelModification.java b/src/main/java/org/gridsuite/modification/server/modifications/VoltageLevelModification.java index 7bbd83e8b..0fb9eebc3 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/VoltageLevelModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/VoltageLevelModification.java @@ -13,7 +13,9 @@ import com.powsybl.iidm.network.extensions.IdentifiableShortCircuit; import com.powsybl.iidm.network.extensions.IdentifiableShortCircuitAdder; import org.gridsuite.modification.server.NetworkModificationException; +import org.gridsuite.modification.server.dto.AttributeModification; import org.gridsuite.modification.server.dto.VoltageLevelModificationInfos; + import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -84,52 +86,79 @@ public void apply(Network network, ReportNode subReportNode) { .add(); ModificationUtils.getInstance().applyElementaryModifications(voltageLevel::setName, () -> voltageLevel.getOptionalName().orElse("No value"), modificationInfos.getEquipmentName(), subReportNode, "Name"); - ModificationUtils.getInstance().applyElementaryModifications(voltageLevel::setNominalV, voltageLevel::getNominalV, modificationInfos.getNominalV(), subReportNode, "Nominal voltage"); - ModificationUtils.getInstance().applyElementaryModifications(voltageLevel::setLowVoltageLimit, voltageLevel::getLowVoltageLimit, modificationInfos.getLowVoltageLimit(), subReportNode, "Low voltage limit"); - ModificationUtils.getInstance().applyElementaryModifications(voltageLevel::setHighVoltageLimit, voltageLevel::getHighVoltageLimit, modificationInfos.getHighVoltageLimit(), subReportNode, "High voltage limit"); + modifyNominalV(voltageLevel, modificationInfos.getNominalV(), subReportNode); + modifLowVoltageLimit(voltageLevel, modificationInfos.getLowVoltageLimit(), subReportNode); + modifyHighVoltageLimit(voltageLevel, modificationInfos.getHighVoltageLimit(), subReportNode); - modifyVoltageLevelShortCircuit(subReportNode, voltageLevel); + modifyVoltageLevelShortCircuit(modificationInfos.getIpMin(), modificationInfos.getIpMax(), subReportNode, voltageLevel); PropertiesUtils.applyProperties(voltageLevel, subReportNode, modificationInfos.getProperties(), "VlProperties"); } - private void modifyVoltageLevelShortCircuit(ReportNode subReportNode, VoltageLevel voltageLevel) { - if (modificationInfos.getIpMin() != null || modificationInfos.getIpMax() != null) { - List reports = new ArrayList<>(); - IdentifiableShortCircuit identifiableShortCircuit = voltageLevel.getExtension(IdentifiableShortCircuit.class); - IdentifiableShortCircuitAdder identifiableShortCircuitAdder = voltageLevel.newExtension(IdentifiableShortCircuitAdder.class); - var oldIpMin = identifiableShortCircuit == null ? null : identifiableShortCircuit.getIpMin(); - var oldIpMax = identifiableShortCircuit == null ? null : identifiableShortCircuit.getIpMax(); + public static void modifyHighVoltageLimit(VoltageLevel voltageLevel, AttributeModification highVoltageLimit, ReportNode subReportNode) { + ModificationUtils.getInstance().applyElementaryModifications(voltageLevel::setHighVoltageLimit, voltageLevel::getHighVoltageLimit, highVoltageLimit, subReportNode, "High voltage limit"); + } - if (modificationInfos.getIpMin() != null) { - var newIpMin = modificationInfos.getIpMin().getValue(); + public static void modifLowVoltageLimit(VoltageLevel voltageLevel, AttributeModification lowVoltageLimit, ReportNode subReportNode) { + ModificationUtils.getInstance().applyElementaryModifications(voltageLevel::setLowVoltageLimit, voltageLevel::getLowVoltageLimit, lowVoltageLimit, subReportNode, "Low voltage limit"); + } - identifiableShortCircuitAdder.withIpMin(newIpMin); + public static void modifyNominalV(VoltageLevel voltageLevel, AttributeModification modifNominalV, ReportNode subReportNode) { + ModificationUtils.getInstance().applyElementaryModifications(voltageLevel::setNominalV, voltageLevel::getNominalV, modifNominalV, subReportNode, "Nominal voltage"); + } - //convert to kA to report it like the user set it. - var oldIpMinToReport = oldIpMin != null ? oldIpMin * 0.001 : null; - var newIpMinToReport = newIpMin * 0.001; + public static void modifyVoltageLevelShortCircuit(AttributeModification ipMin, + AttributeModification ipMax, + ReportNode subReportNode, + VoltageLevel voltageLevel) { + if (ipMin == null && ipMax == null) { + return; + } - reports.add(ModificationUtils.getInstance() - .buildModificationReport(oldIpMinToReport, newIpMinToReport, "Low short circuit current limit")); - } else if (oldIpMin != null) { - identifiableShortCircuitAdder.withIpMin(oldIpMin); - } + List reports = new ArrayList<>(); + IdentifiableShortCircuitAdder identifiableShortCircuitAdder = voltageLevel.newExtension(IdentifiableShortCircuitAdder.class); + Double oldIpMin = null; + Double oldIpMax = null; + IdentifiableShortCircuit identifiableShortCircuit = voltageLevel.getExtension(IdentifiableShortCircuit.class); + if (identifiableShortCircuit != null) { + oldIpMin = identifiableShortCircuit.getIpMin(); + oldIpMax = identifiableShortCircuit.getIpMax(); + } - if (modificationInfos.getIpMax() != null) { - var newIpMax = modificationInfos.getIpMax().getValue(); - identifiableShortCircuitAdder.withIpMax(newIpMax); - - //Convert to kA to report it like the user set it. - var oldIpMaxToReport = oldIpMax != null ? oldIpMax * 0.001 : null; - var newIpMaxToReport = newIpMax * 0.001; - reports.add(ModificationUtils.getInstance() - .buildModificationReport(oldIpMaxToReport, newIpMaxToReport, "High short circuit current limit")); - } else if (oldIpMax != null) { - identifiableShortCircuitAdder.withIpMax(oldIpMax); - } + if (ipMin != null) { + var newIpMin = ipMin.getValue(); - identifiableShortCircuitAdder.add(); + identifiableShortCircuitAdder.withIpMin(newIpMin); + + //convert to kA to report it like the user set it. + var oldIpMinToReport = convertToKiloAmps(oldIpMin); + var newIpMinToReport = convertToKiloAmps(newIpMin); + reports.add(ModificationUtils.getInstance() + .buildModificationReport(oldIpMinToReport, newIpMinToReport, "Low short circuit current limit")); + } else if (oldIpMin != null) { + identifiableShortCircuitAdder.withIpMin(oldIpMin); + } + + if (ipMax != null) { + var newIpMax = ipMax.getValue(); + identifiableShortCircuitAdder.withIpMax(newIpMax); + + //Convert to kA to report it like the user set it. + var oldIpMaxToReport = convertToKiloAmps(oldIpMax); + var newIpMaxToReport = convertToKiloAmps(newIpMax); + reports.add(ModificationUtils.getInstance() + .buildModificationReport(oldIpMaxToReport, newIpMaxToReport, "High short circuit current limit")); + } else if (oldIpMax != null) { + identifiableShortCircuitAdder.withIpMax(oldIpMax); + } + + identifiableShortCircuitAdder.add(); + if (subReportNode != null) { reports.forEach(report -> insertReportNode(subReportNode, report)); } } + + private static Double convertToKiloAmps(Double value) { + return (value != null) ? value * 0.001 : null; + } } + diff --git a/src/test/java/org/gridsuite/modification/server/modifications/GeneratorByFormulaModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/GeneratorByFormulaModificationTest.java index 9c3a4d38a..ae5b98b1b 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/GeneratorByFormulaModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/GeneratorByFormulaModificationTest.java @@ -299,7 +299,7 @@ protected void assertAfterNetworkModificationCreation() { assertNotNull(generatorStartup1); assertEquals(50, generator1.getTargetP(), 0); assertEquals(15, generatorStartup1.getMarginalCost(), 0); - assertEquals(55, generatorStartup1.getPlannedOutageRate(), 0); + assertEquals(2.5, generatorStartup1.getPlannedOutageRate(), 0); assertEquals(1100, generatorStartup1.getForcedOutageRate(), 0); assertEquals(50, generatorStartup1.getPlannedActivePowerSetpoint(), 0); assertEquals(502, generator1.getMaxP(), 0); @@ -310,7 +310,7 @@ protected void assertAfterNetworkModificationCreation() { assertNotNull(generatorStartup2); assertEquals(100, generator2.getTargetP(), 0); assertEquals(15, generatorStartup2.getMarginalCost(), 0); - assertEquals(55, generatorStartup2.getPlannedOutageRate(), 0); + assertEquals(2.5, generatorStartup2.getPlannedOutageRate(), 0); assertEquals(1100, generatorStartup2.getForcedOutageRate(), 0); assertEquals(50, generatorStartup2.getPlannedActivePowerSetpoint(), 0); assertEquals(2002, generator2.getMaxP(), 0);