diff --git a/src/main/java/org/gridsuite/modification/server/dto/byfilter/equipmentfield/TwoWindingsTransformerField.java b/src/main/java/org/gridsuite/modification/server/dto/byfilter/equipmentfield/TwoWindingsTransformerField.java index 78d35d9bd..665d4f0aa 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/byfilter/equipmentfield/TwoWindingsTransformerField.java +++ b/src/main/java/org/gridsuite/modification/server/dto/byfilter/equipmentfield/TwoWindingsTransformerField.java @@ -87,7 +87,7 @@ public static void setNewValue(TwoWindingsTransformer transformer, String twoWin case PHASE_TAP_POSITION -> processTapChangerPositionsAndSteps(phaseTapChanger, null, true, null, new AttributeModification<>((int) Double.parseDouble(newValue), OperationType.SET), null, null); case PHASE_TARGET_DEADBAND -> processPhaseTapRegulation( - phaseTapChanger, null, null, true, null, attributeModification, null + phaseTapChanger, null, regulationMode, true, null, attributeModification, null ); } } 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 7f8980fa5..c31e18cb7 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModification.java @@ -17,6 +17,7 @@ import java.util.List; import static org.gridsuite.modification.server.NetworkModificationException.Type.TWO_WINDINGS_TRANSFORMER_NOT_FOUND; +import static org.gridsuite.modification.server.dto.AttributeModification.toAttributeModification; import static org.gridsuite.modification.server.modifications.ModificationUtils.insertReportNode; /** @@ -215,10 +216,8 @@ private void processPhaseTapChanger(Network network, regulationMode = phaseTapChangerInfos.getRegulationMode().getValue(); } - if (!PhaseTapChanger.RegulationMode.FIXED_TAP.equals(regulationMode)) { - processPhaseTapRegulation(phaseTapChanger, phaseTapChangerAdder, regulationMode, isModification, + processPhaseTapRegulation(phaseTapChanger, phaseTapChangerAdder, regulationMode, isModification, phaseTapChangerInfos.getRegulationValue(), phaseTapChangerInfos.getTargetDeadband(), regulationReports); - } processRegulatingTerminal(phaseTapChangerInfos, phaseTapChanger, phaseTapChangerAdder, regulationReports, network, @@ -250,6 +249,14 @@ private void processPhaseTapChanger(Network network, } } + public static String getRegulationValueLabel(PhaseTapChanger.RegulationMode regulationMode) { + return switch (regulationMode) { + case FIXED_TAP -> "Current or Flow set point"; + case CURRENT_LIMITER -> "Current"; + case ACTIVE_POWER_CONTROL -> "Flow set point"; + }; + } + public static void processPhaseTapRegulation(PhaseTapChanger phaseTapChanger, PhaseTapChangerAdder phaseTapChangerAdder, PhaseTapChanger.RegulationMode regulationMode, @@ -258,45 +265,52 @@ public static void processPhaseTapRegulation(PhaseTapChanger phaseTapChanger, AttributeModification modifyTargetDeadband, List regulationReports) { - if (regulationMode != null) { - String fieldName = (regulationMode == PhaseTapChanger.RegulationMode.CURRENT_LIMITER) ? "Value" : "Flow set point"; + if (regulationMode == null) { + return; + } + + if (regulationMode != PhaseTapChanger.RegulationMode.FIXED_TAP) { + // Flow set point or current limiter ReportNode regulationValueReportNode = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport( isModification ? phaseTapChanger::setRegulationValue : phaseTapChangerAdder::setRegulationValue, isModification ? phaseTapChanger::getRegulationValue : () -> null, modifyRegulationValue, - fieldName, + getRegulationValueLabel(regulationMode), 2); if (regulationReports != null && regulationValueReportNode != null) { regulationReports.add(regulationValueReportNode); } + + // Deadband + ReportNode targetDeadbandReportNode = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport( + isModification ? phaseTapChanger::setTargetDeadband + : phaseTapChangerAdder::setTargetDeadband, + isModification ? phaseTapChanger::getTargetDeadband : () -> null, + modifyTargetDeadband, + "Target deadband", + 2); + + if (regulationReports != null && targetDeadbandReportNode != null) { + regulationReports.add(targetDeadbandReportNode); + } } - ReportNode targetDeadbandReportNode = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport( - isModification ? phaseTapChanger::setTargetDeadband - : phaseTapChangerAdder::setTargetDeadband, - isModification ? phaseTapChanger::getTargetDeadband : () -> null, - modifyTargetDeadband, "Target deadband", 2); - - if (regulationReports != null && targetDeadbandReportNode != null) { - regulationReports.add(targetDeadbandReportNode); - } - if (regulationMode != null) { - processRegulating(isModification, phaseTapChanger, phaseTapChangerAdder, - regulationMode != PhaseTapChanger.RegulationMode.FIXED_TAP, regulationReports); - } - } - - private static void processRegulating(boolean isModification, PhaseTapChanger phaseTapChanger, PhaseTapChangerAdder phaseTapChangerAdder, - boolean regulating, List regulationReports) { - ReportNode regulatingReportNode = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport( - isModification ? phaseTapChanger::setRegulating - : phaseTapChangerAdder::setRegulating, - isModification ? phaseTapChanger::isRegulating : () -> null, - AttributeModification.toAttributeModification(regulating, OperationType.SET), - regulating ? "Voltage regulation" : "Phase tap regulating", 1); - if (regulationReports != null && regulatingReportNode != null) { - regulationReports.add(regulatingReportNode); + // regulating + // IF current regulating mode is different to FIXED_TAB, and we switch to FIXED_TAP => SET regulating to false, otherwise true + PhaseTapChanger.RegulationMode oldRegulationMode = isModification ? phaseTapChanger.getRegulationMode() : null; + boolean newRegulating = !(oldRegulationMode != PhaseTapChanger.RegulationMode.FIXED_TAP && regulationMode == PhaseTapChanger.RegulationMode.FIXED_TAP); + + if (oldRegulationMode != PhaseTapChanger.RegulationMode.FIXED_TAP && regulationMode == PhaseTapChanger.RegulationMode.FIXED_TAP) { + ReportNode regulatingReportNode = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport( + isModification ? phaseTapChanger::setRegulating + : phaseTapChangerAdder::setRegulating, + isModification ? phaseTapChanger::isRegulating : () -> null, + toAttributeModification(newRegulating, OperationType.SET), + "Phase tap regulating", 1); + if (regulationReports != null && regulatingReportNode != null) { + regulationReports.add(regulatingReportNode); + } } } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/TwoWindingsTransformerModificationByAssignmentTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/TwoWindingsTransformerModificationByAssignmentTest.java index 0b1cb2f14..32e762553 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/TwoWindingsTransformerModificationByAssignmentTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/TwoWindingsTransformerModificationByAssignmentTest.java @@ -159,7 +159,13 @@ protected void createEquipments() { "trf1", 38, ConnectablePosition.Direction.TOP, "trf1", 49, ConnectablePosition.Direction.BOTTOM); twt6.setRatedS(20); - addPhaseTapChangerSteps(twt6.newPhaseTapChanger().setRegulationValue(47).setLowTapPosition(1).setTapPosition(1).setTargetDeadband(36)); + addPhaseTapChangerSteps(twt6.newPhaseTapChanger() + .setRegulationMode(PhaseTapChanger.RegulationMode.FIXED_TAP) + .setRegulationValue(47) + .setTargetDeadband(36) + .setLowTapPosition(1) + .setTapPosition(1) + ); } @Override @@ -387,7 +393,7 @@ protected void assertAfterNetworkModificationCreation() { TwoWindingsTransformer twt5 = getNetwork().getTwoWindingsTransformer(TWT_ID_5); PhaseTapChanger phaseTapChanger5 = twt5.getPhaseTapChanger(); - assertNotNull(phaseTapChanger4); + assertNotNull(phaseTapChanger5); assertEquals(2, phaseTapChanger5.getLowTapPosition()); assertEquals(2, phaseTapChanger5.getTapPosition()); assertEquals(2, twt5.getR(), 0); @@ -396,9 +402,9 @@ protected void assertAfterNetworkModificationCreation() { TwoWindingsTransformer twt6 = getNetwork().getTwoWindingsTransformer(TWT_ID_6); PhaseTapChanger phaseTapChanger6 = twt6.getPhaseTapChanger(); - assertNotNull(phaseTapChanger4); - assertEquals(2, phaseTapChanger6.getRegulationValue(), 0); - assertEquals(10, phaseTapChanger6.getTargetDeadband(), 0); + assertNotNull(phaseTapChanger6); + assertEquals(47, phaseTapChanger6.getRegulationValue(), 0); + assertEquals(36, phaseTapChanger6.getTargetDeadband(), 0); assertEquals(20, twt6.getX(), 0); assertEquals(25, twt6.getG(), 0); } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/TwoWindingsTransformerByFormulaModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/TwoWindingsTransformerByFormulaModificationTest.java index c6c1a84ec..acfba29dc 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/TwoWindingsTransformerByFormulaModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/TwoWindingsTransformerByFormulaModificationTest.java @@ -1,13 +1,7 @@ package org.gridsuite.modification.server.modifications.byfilter.formula; import com.github.tomakehurst.wiremock.client.WireMock; -import com.powsybl.iidm.network.IdentifiableType; -import com.powsybl.iidm.network.PhaseTapChanger; -import com.powsybl.iidm.network.PhaseTapChangerAdder; -import com.powsybl.iidm.network.RatioTapChanger; -import com.powsybl.iidm.network.RatioTapChangerAdder; -import com.powsybl.iidm.network.Substation; -import com.powsybl.iidm.network.TwoWindingsTransformer; +import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.ConnectablePosition; import org.gridsuite.filter.AbstractFilter; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilter; @@ -15,10 +9,10 @@ import org.gridsuite.filter.utils.EquipmentType; import org.gridsuite.modification.server.dto.ByFormulaModificationInfos; import org.gridsuite.modification.server.dto.NetworkModificationResult; +import org.gridsuite.modification.server.dto.byfilter.equipmentfield.TwoWindingsTransformerField; import org.gridsuite.modification.server.dto.byfilter.formula.FormulaInfos; import org.gridsuite.modification.server.dto.byfilter.formula.Operator; import org.gridsuite.modification.server.dto.byfilter.formula.ReferenceFieldOrValue; -import org.gridsuite.modification.server.dto.byfilter.equipmentfield.TwoWindingsTransformerField; import org.junit.Test; import java.util.Date; @@ -26,9 +20,7 @@ import java.util.UUID; import static org.gridsuite.modification.server.utils.NetworkUtil.createTwoWindingsTransformer; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.*; public class TwoWindingsTransformerByFormulaModificationTest extends AbstractByFormulaModificationTest { private static final String TWT_ID_1 = "twt1"; @@ -173,7 +165,7 @@ protected void createEquipments() { "trf1", 30, ConnectablePosition.Direction.TOP, "trf1", 40, ConnectablePosition.Direction.BOTTOM); twt4.setRatedS(15); - addPhaseTapChangerSteps(twt4.newPhaseTapChanger().setRegulationValue(45).setLowTapPosition(1).setTapPosition(2).setTargetDeadband(34)); + addPhaseTapChangerSteps(twt4.newPhaseTapChanger().setRegulationMode(PhaseTapChanger.RegulationMode.CURRENT_LIMITER).setRegulationValue(45).setLowTapPosition(1).setTapPosition(2).setTargetDeadband(34)); TwoWindingsTransformer twt5 = createTwoWindingsTransformer(s3, TWT_ID_5, TWT_ID_5, 50, 60, 70, 80, 30, 40, 101, 101, @@ -189,7 +181,7 @@ protected void createEquipments() { "trf1", 38, ConnectablePosition.Direction.TOP, "trf1", 49, ConnectablePosition.Direction.BOTTOM); twt6.setRatedS(20); - addPhaseTapChangerSteps(twt6.newPhaseTapChanger().setRegulationValue(47).setLowTapPosition(1).setTapPosition(1).setTargetDeadband(36)); + addPhaseTapChangerSteps(twt6.newPhaseTapChanger().setRegulationMode(PhaseTapChanger.RegulationMode.FIXED_TAP).setRegulationValue(47).setLowTapPosition(1).setTapPosition(1).setTargetDeadband(36)); } @Override @@ -415,7 +407,7 @@ protected void assertAfterNetworkModificationCreation() { TwoWindingsTransformer twt5 = getNetwork().getTwoWindingsTransformer(TWT_ID_5); PhaseTapChanger phaseTapChanger5 = twt5.getPhaseTapChanger(); - assertNotNull(phaseTapChanger4); + assertNotNull(phaseTapChanger5); assertEquals(4, phaseTapChanger5.getLowTapPosition()); assertEquals(4, phaseTapChanger5.getTapPosition()); assertEquals(100, twt5.getR(), 0); @@ -424,9 +416,9 @@ protected void assertAfterNetworkModificationCreation() { TwoWindingsTransformer twt6 = getNetwork().getTwoWindingsTransformer(TWT_ID_6); PhaseTapChanger phaseTapChanger6 = twt6.getPhaseTapChanger(); - assertNotNull(phaseTapChanger4); - assertEquals(94, phaseTapChanger6.getRegulationValue(), 0); - assertEquals(26, phaseTapChanger6.getTargetDeadband(), 0); + assertNotNull(phaseTapChanger6); + assertEquals(47, phaseTapChanger6.getRegulationValue(), 0); + assertEquals(36, phaseTapChanger6.getTargetDeadband(), 0); assertEquals(85, twt6.getX(), 0); assertEquals(100, twt6.getG(), 0); }