From cf0fc3a3d98c85dceba499e011bdcf8dcc444244 Mon Sep 17 00:00:00 2001 From: Etienne LESOT Date: Tue, 7 Mar 2023 13:07:53 +0100 Subject: [PATCH] fix Signed-off-by: Etienne LESOT --- .../powsybl/security/action/HvdcAction.java | 2 +- .../security/action/HvdcActionBuilder.java | 10 +++++----- .../json/action/HvdcActionDeserializer.java | 13 +++++++++++-- .../JsonActionAndOperatorStrategyTest.java | 19 ++++++++++++++++++- .../src/test/resources/ActionFileTest.json | 18 +++++++++++++++++- .../test/resources/ActionFileTestV1.0.json | 18 +++++++++++++++++- .../resources/OperatorStrategyFileTest.json | 2 +- 7 files changed, 70 insertions(+), 12 deletions(-) diff --git a/security-analysis/security-analysis-api/src/main/java/com/powsybl/security/action/HvdcAction.java b/security-analysis/security-analysis-api/src/main/java/com/powsybl/security/action/HvdcAction.java index 091bf080fbd..b0c2745c54f 100644 --- a/security-analysis/security-analysis-api/src/main/java/com/powsybl/security/action/HvdcAction.java +++ b/security-analysis/security-analysis-api/src/main/java/com/powsybl/security/action/HvdcAction.java @@ -38,7 +38,7 @@ public class HvdcAction extends AbstractAction { private final Double p0; private final Boolean relativeValue; - public HvdcAction(String id, String hvdcId, boolean acEmulationEnabled, Double activePowerSetpoint, HvdcLine.ConvertersMode converterMode, Double droop, Double p0, Boolean relativeValue) { + protected HvdcAction(String id, String hvdcId, boolean acEmulationEnabled, Double activePowerSetpoint, HvdcLine.ConvertersMode converterMode, Double droop, Double p0, Boolean relativeValue) { super(id); this.hvdcId = hvdcId; this.acEmulationEnabled = acEmulationEnabled; diff --git a/security-analysis/security-analysis-api/src/main/java/com/powsybl/security/action/HvdcActionBuilder.java b/security-analysis/security-analysis-api/src/main/java/com/powsybl/security/action/HvdcActionBuilder.java index ca640cfa75e..cb081a6b788 100644 --- a/security-analysis/security-analysis-api/src/main/java/com/powsybl/security/action/HvdcActionBuilder.java +++ b/security-analysis/security-analysis-api/src/main/java/com/powsybl/security/action/HvdcActionBuilder.java @@ -38,27 +38,27 @@ public HvdcActionBuilder withHvdcId(String hvdcId) { return this; } - public HvdcActionBuilder withAcEmulationEnabled(boolean acEmulationEnabled) { + public HvdcActionBuilder withAcEmulationEnabled(Boolean acEmulationEnabled) { this.acEmulationEnabled = acEmulationEnabled; return this; } - public HvdcActionBuilder withActivePowerSetpoint(double activePowerSetpoint) { + public HvdcActionBuilder withActivePowerSetpoint(Double activePowerSetpoint) { this.activePowerSetpoint = activePowerSetpoint; return this; } - public HvdcActionBuilder withDroop(double droop) { + public HvdcActionBuilder withDroop(Double droop) { this.droop = droop; return this; } - public HvdcActionBuilder withP0(double p0) { + public HvdcActionBuilder withP0(Double p0) { this.p0 = p0; return this; } - public HvdcActionBuilder withRelativeValue(boolean relativeValue) { + public HvdcActionBuilder withRelativeValue(Boolean relativeValue) { this.relativeValue = relativeValue; return this; } diff --git a/security-analysis/security-analysis-api/src/main/java/com/powsybl/security/json/action/HvdcActionDeserializer.java b/security-analysis/security-analysis-api/src/main/java/com/powsybl/security/json/action/HvdcActionDeserializer.java index d94deab0c91..c303cd0f81d 100644 --- a/security-analysis/security-analysis-api/src/main/java/com/powsybl/security/json/action/HvdcActionDeserializer.java +++ b/security-analysis/security-analysis-api/src/main/java/com/powsybl/security/json/action/HvdcActionDeserializer.java @@ -14,6 +14,7 @@ import com.powsybl.commons.json.JsonUtil; import com.powsybl.iidm.network.HvdcLine; import com.powsybl.security.action.HvdcAction; +import com.powsybl.security.action.HvdcActionBuilder; import java.io.IOException; @@ -80,7 +81,15 @@ public HvdcAction deserialize(JsonParser jsonParser, DeserializationContext dese return false; } }); - return new HvdcAction(context.id, context.hvdcId, context.acEmulationEnabled, context.activePowerSetpoint, context.converterMode, - context.droop, context.p0, context.relativeValue); + return new HvdcActionBuilder() + .withId(context.id) + .withHvdcId(context.hvdcId) + .withAcEmulationEnabled(context.acEmulationEnabled) + .withActivePowerSetpoint(context.activePowerSetpoint) + .withConverterMode(context.converterMode) + .withDroop(context.droop) + .withP0(context.p0) + .withRelativeValue(context.relativeValue) + .build(); } } diff --git a/security-analysis/security-analysis-api/src/test/java/com/powsybl/security/json/JsonActionAndOperatorStrategyTest.java b/security-analysis/security-analysis-api/src/test/java/com/powsybl/security/json/JsonActionAndOperatorStrategyTest.java index 051b5b3de1a..6a9a97108d4 100644 --- a/security-analysis/security-analysis-api/src/test/java/com/powsybl/security/json/JsonActionAndOperatorStrategyTest.java +++ b/security-analysis/security-analysis-api/src/test/java/com/powsybl/security/json/JsonActionAndOperatorStrategyTest.java @@ -32,6 +32,7 @@ import java.util.Collections; import java.util.List; +import static com.powsybl.iidm.network.HvdcLine.ConvertersMode.SIDE_1_RECTIFIER_SIDE_2_INVERTER; import static org.junit.jupiter.api.Assertions.*; import static com.powsybl.security.LimitViolationType.*; @@ -68,8 +69,24 @@ void actionRoundTrip() throws IOException { PhaseTapChanger.RegulationMode.ACTIVE_POWER_CONTROL, 15.0)); actions.add(RatioTapChangerRegulationAction.activateRegulationAndChangeTargetV("id20", "transformerId5", 90.0)); actions.add(RatioTapChangerRegulationAction.deactivateRegulation("id21", "transformerId5", ThreeWindingsTransformer.Side.THREE)); - actions.add(HvdcAction.activateActivePowerSetpointMode("id22", "hvdc2")); + actions.add(HvdcAction.activateActivePowerSetpointMode("id22", "hvdc1")); actions.add(HvdcAction.activateAcEmulationMode("id23", "hvdc2")); + actions.add(new HvdcActionBuilder() + .withId("id24") + .withHvdcId("hvdc2") + .withAcEmulationEnabled(true) + .withDroop(121.0) + .withP0(42.0) + .withConverterMode(SIDE_1_RECTIFIER_SIDE_2_INVERTER) + .withRelativeValue(false) + .build()); + actions.add(new HvdcActionBuilder() + .withId("id25") + .withHvdcId("hvdc1") + .withAcEmulationEnabled(false) + .withActivePowerSetpoint(12.0) + .withRelativeValue(true) + .build()); ActionList actionList = new ActionList(actions); roundTripTest(actionList, ActionList::writeJsonFile, ActionList::readJsonFile, "/ActionFileTest.json"); } diff --git a/security-analysis/security-analysis-api/src/test/resources/ActionFileTest.json b/security-analysis/security-analysis-api/src/test/resources/ActionFileTest.json index e399325d822..125edf5d8e7 100644 --- a/security-analysis/security-analysis-api/src/test/resources/ActionFileTest.json +++ b/security-analysis/security-analysis-api/src/test/resources/ActionFileTest.json @@ -139,12 +139,28 @@ }, { "type" : "HVDC", "id" : "id22", - "hvdcId" : "hvdc2", + "hvdcId" : "hvdc1", "acEmulationEnabled" : false }, { "type" : "HVDC", "id" : "id23", "hvdcId" : "hvdc2", "acEmulationEnabled" : true + }, { + "type" : "HVDC", + "id" : "id24", + "hvdcId" : "hvdc2", + "acEmulationEnabled" : true, + "converterMode" : "SIDE_1_RECTIFIER_SIDE_2_INVERTER", + "droop" : 121.0, + "p0" : 42.0, + "relativeValue" : false + }, { + "type" : "HVDC", + "id" : "id25", + "hvdcId" : "hvdc1", + "acEmulationEnabled" : false, + "activePowerSetpoint" : 12.0, + "relativeValue" : true } ] } \ No newline at end of file diff --git a/security-analysis/security-analysis-api/src/test/resources/ActionFileTestV1.0.json b/security-analysis/security-analysis-api/src/test/resources/ActionFileTestV1.0.json index f7edaf0580c..37a4755e085 100644 --- a/security-analysis/security-analysis-api/src/test/resources/ActionFileTestV1.0.json +++ b/security-analysis/security-analysis-api/src/test/resources/ActionFileTestV1.0.json @@ -139,12 +139,28 @@ }, { "type" : "HVDC", "id" : "id22", - "hvdcId" : "hvdc2", + "hvdcId" : "hvdc1", "acEmulationEnabled" : false }, { "type" : "HVDC", "id" : "id23", "hvdcId" : "hvdc2", "acEmulationEnabled" : true + }, { + "type" : "HVDC", + "id" : "id24", + "hvdcId" : "hvdc2", + "acEmulationEnabled" : true, + "converterMode" : "SIDE_1_RECTIFIER_SIDE_2_INVERTER", + "droop" : 121.0, + "p0" : 42.0, + "relativeValue" : false + }, { + "type" : "HVDC", + "id" : "id25", + "hvdcId" : "hvdc1", + "acEmulationEnabled" : false, + "activePowerSetpoint" : 12.0, + "relativeValue" : true } ] } \ No newline at end of file diff --git a/security-analysis/security-analysis-api/src/test/resources/OperatorStrategyFileTest.json b/security-analysis/security-analysis-api/src/test/resources/OperatorStrategyFileTest.json index 139f72fdbf3..67d20415766 100644 --- a/security-analysis/security-analysis-api/src/test/resources/OperatorStrategyFileTest.json +++ b/security-analysis/security-analysis-api/src/test/resources/OperatorStrategyFileTest.json @@ -19,7 +19,7 @@ }, { "id" : "id3", "contingencyContextType" : "SPECIFIC", - "contingencyId" : "contingencyId2", + "contingencyId" : "contingencyId1", "condition" : { "type" : "ANY_VIOLATION_CONDITION", "filters" : [ "CURRENT" ]