diff --git a/src/main/java/org/gridsuite/modification/server/modifications/VscModification.java b/src/main/java/org/gridsuite/modification/server/modifications/VscModification.java index 9f6b9c913..c03c84575 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/VscModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/VscModification.java @@ -83,23 +83,26 @@ private void modifyVsc(@NonNull Network network, @NonNull HvdcLine hvdcLine, Vsc "Angle drop power control")); } - if (modificationInfos.getDroop() != null) { - hvdcLine.newExtension(HvdcAngleDroopActivePowerControlAdder.class) - .withDroop(modificationInfos.getDroop().getValue()) - .add(); - reports.add(ModificationUtils.getInstance().buildModificationReport( - "unknown", - modificationInfos.getDroop().getValue(), - "Angle drop power control")); - } - if (modificationInfos.getP0() != null) { - hvdcLine.newExtension(HvdcAngleDroopActivePowerControlAdder.class) - .withP0(modificationInfos.getP0().getValue()) - .add(); - reports.add(ModificationUtils.getInstance().buildModificationReport( - "unknown", - modificationInfos.getP0().getValue(), - "p0")); + if (modificationInfos.getDroop() != null || + modificationInfos.getP0() != null) { + var activePowerControlExtension = hvdcLine.newExtension(HvdcAngleDroopActivePowerControlAdder.class); + activePowerControlExtension.withEnabled(modificationInfos.getAngleDroopActivePowerControl().getValue()); + if (modificationInfos.getDroop() != null) { + activePowerControlExtension.withDroop(modificationInfos.getDroop().getValue()); + reports.add(ModificationUtils.getInstance().buildModificationReport( + "unknown", + modificationInfos.getDroop().getValue(), + "Angle drop power control")); + } + if (modificationInfos.getP0() != null) { + activePowerControlExtension + .withP0(modificationInfos.getP0().getValue()); + reports.add(ModificationUtils.getInstance().buildModificationReport( + "unknown", + modificationInfos.getP0().getValue(), + "p0")); + } + activePowerControlExtension.add(); } if (modificationInfos.getOperatorActivePowerLimitFromSide1ToSide2() != null || diff --git a/src/test/java/org/gridsuite/modification/server/modifications/VscModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/VscModificationTest.java index 59b1a2b8e..4d1eb09e7 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/VscModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/VscModificationTest.java @@ -1,6 +1,5 @@ package org.gridsuite.modification.server.modifications; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.HvdcAngleDroopActivePowerControl; @@ -12,13 +11,11 @@ import org.junit.Test; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; -import org.springframework.test.web.servlet.MvcResult; import org.springframework.util.CollectionUtils; import java.util.*; import java.util.stream.IntStream; -import static org.gridsuite.modification.server.utils.assertions.Assertions.assertThat; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -37,16 +34,16 @@ protected ModificationInfos buildModification() { .equipmentId("hvdcLine") .equipmentName(new AttributeModification<>("hvdcLine", OperationType.SET)) .dcNominalVoltage(new AttributeModification<>(39., OperationType.SET)) - .dcResistance(new AttributeModification<>(4., OperationType.SET)) - .maximumActivePower(new AttributeModification<>(56., OperationType.SET)) - .p0(new AttributeModification<>(5F, OperationType.SET)) - .operatorActivePowerLimitFromSide2ToSide1(new AttributeModification<>(5.6F, OperationType.SET)) - .convertersMode(new AttributeModification<>(HvdcLine.ConvertersMode.SIDE_1_INVERTER_SIDE_2_RECTIFIER, OperationType.SET)) - .activePower(new AttributeModification<>(5., OperationType.SET)) - .operatorActivePowerLimitFromSide1ToSide2(new AttributeModification<>(6.0F, OperationType.SET)) - .operatorActivePowerLimitFromSide2ToSide1(new AttributeModification<>(8F, OperationType.SET)) - .droop(new AttributeModification<>(1F, OperationType.SET)) - .angleDroopActivePowerControl(new AttributeModification<>(false, OperationType.SET)) + .dcResistance(new AttributeModification<>(4., OperationType.SET)) + .maximumActivePower(new AttributeModification<>(56., OperationType.SET)) + .p0(new AttributeModification<>(5F, OperationType.SET)) + .operatorActivePowerLimitFromSide2ToSide1(new AttributeModification<>(5.6F, OperationType.SET)) + .convertersMode(new AttributeModification<>(HvdcLine.ConvertersMode.SIDE_1_INVERTER_SIDE_2_RECTIFIER, OperationType.SET)) + .activePower(new AttributeModification<>(5., OperationType.SET)) + .operatorActivePowerLimitFromSide1ToSide2(new AttributeModification<>(6.0F, OperationType.SET)) + .operatorActivePowerLimitFromSide2ToSide1(new AttributeModification<>(8F, OperationType.SET)) + .droop(new AttributeModification<>(1F, OperationType.SET)) + .angleDroopActivePowerControl(new AttributeModification<>(true, OperationType.SET)) .converterStation1(buildConverterStationWithMinMaxReactiveLimits()) .converterStation2(buildConverterStationWithReactiveCapabilityCurve()) .build(); @@ -67,6 +64,7 @@ private ConverterStationModificationInfos buildConverterStationWithReactiveCapab new ReactiveCapabilityCurveModificationInfos(0.6, 2., 12., 14., 0.8, 0.11))) .build(); } + private ConverterStationModificationInfos buildConverterStationWithMinMaxReactiveLimits() { return ConverterStationModificationInfos.builder() .equipmentId("v2vsc") @@ -115,18 +113,16 @@ protected void assertAfterNetworkModificationCreation() { assertEquals(5., hvdcLine.getActivePowerSetpoint(), 0); assertEquals(56., hvdcLine.getMaxP(), 0); -//TODO(jamal) check p0 and droop HvdcOperatorActivePowerRange hvdcOperatorActivePowerRange = hvdcLine.getExtension(HvdcOperatorActivePowerRange.class); Assert.assertEquals(6, hvdcOperatorActivePowerRange.getOprFromCS1toCS2(), 0); Assert.assertEquals(8, hvdcOperatorActivePowerRange.getOprFromCS2toCS1(), 0); HvdcAngleDroopActivePowerControl activePowerControl = hvdcLine.getExtension(HvdcAngleDroopActivePowerControl.class); Assert.assertEquals(5, activePowerControl.getP0(), 0); - //Assert.assertEquals(1, activePowerControl.getDroop(), 0); //FIXME (jamal) : check droop - + Assert.assertEquals(1, activePowerControl.getDroop(), 0); + Assert.assertTrue(activePowerControl.isEnabled()); Assert.assertEquals(HvdcLine.ConvertersMode.SIDE_1_INVERTER_SIDE_2_RECTIFIER, hvdcLine.getConvertersMode()); - //TODO (jamal) : check converter stations Assert.assertEquals(1, getNetwork().getVoltageLevel("v1").getVscConverterStationStream() .filter(converterStation -> converterStation.getId().equals("v1vsc")).count()); @@ -158,8 +154,6 @@ protected void assertAfterNetworkModificationCreation() { assertEquals(modificationPoint.getP(), point.getP()); }); } - - Assert.assertEquals(0.3, vscConverterStation1.getVoltageSetpoint(), 0); Assert.assertEquals("v1", vscConverterStation1.getTerminal().getVoltageLevel().getId()); } @@ -191,26 +185,17 @@ protected void testCreationModificationMessage(ModificationInfos modificationInf @Override protected void assertAfterNetworkModificationDeletion() { assertNull(getNetwork().getHvdcLine("vsc1")); -// Assert.assertEquals(0, getNetwork().getVoltageLevel("v1").getVscConverterStationStream() -// .filter(converterStation -> converterStation.getId().equals("stationId1")).count()); -// -// Assert.assertEquals(0, getNetwork().getVoltageLevel("v2").getVscConverterStationStream() -// .filter(converterStation -> converterStation.getId().equals("stationId2")).count()); + Assert.assertEquals(0, getNetwork().getVoltageLevel("v1").getVscConverterStationStream() + .filter(converterStation -> converterStation.getId().equals("stationId1")).count()); + + Assert.assertEquals(0, getNetwork().getVoltageLevel("v2").getVscConverterStationStream() + .filter(converterStation -> converterStation.getId().equals("stationId2")).count()); } + @Test - public void testVscModification() throws JsonProcessingException { - MvcResult mvcResult; - Optional networkModificationResult; - ModificationInfos modificationToRead = buildModification(); - - UUID modificationUuid = saveModification(modificationToRead); - //convert modification to json - String resultAsString = mapper.writeValueAsString(modificationToRead); - ModificationInfos receivedModification = mapper.readValue(resultAsString, new TypeReference<>() { - }); + public void testDroopUnchanged() throws Exception { - assertThat(receivedModification).recursivelyEquals(modificationToRead); } @Override