-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add ac emulation deactivation action #1538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dbb374a
8ac568b
a7b0b1b
f005a4d
9bc0e3c
4435a4b
76b5993
757c459
11f0757
ea3688c
e68d85a
cef1d8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /* | ||
| * Copyright (c) 2025, RTE (http://www.rte-france.com) | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
|
|
||
| package com.powsybl.openrao.data.crac.api.networkaction; | ||
|
|
||
| /** | ||
| * @author Roxane Chen {@literal <roxane.chen at rte-france.com>} | ||
| */ | ||
| public interface AcEmulationDeactivationActionAdder extends SingleNetworkElementActionAdder<AcEmulationDeactivationActionAdder> { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * Copyright (c) 2025, RTE (http://www.rte-france.com) | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
|
|
||
| package com.powsybl.openrao.data.crac.impl; | ||
|
|
||
| import com.powsybl.action.Action; | ||
| import com.powsybl.action.HvdcActionBuilder; | ||
| import com.powsybl.openrao.data.crac.api.networkaction.AcEmulationDeactivationActionAdder; | ||
|
|
||
| /** | ||
| * @author Roxane Chen {@literal <roxane.chen at rte-france.com>} | ||
| */ | ||
| public class AcEmulationDeactivationActionAdderImpl extends AbstractSingleNetworkElementActionAdderImpl<AcEmulationDeactivationActionAdder> implements AcEmulationDeactivationActionAdder { | ||
|
|
||
| AcEmulationDeactivationActionAdderImpl(NetworkActionAdderImpl ownerAdder) { | ||
| super(ownerAdder); | ||
| } | ||
|
|
||
| protected Action buildAction() { | ||
| return new HvdcActionBuilder() | ||
| .withId(String.format("%s_%s_%s", getActionName(), networkElementId, "DEACTIVATE")) | ||
| .withHvdcId(networkElementId) | ||
| .withAcEmulationEnabled(false) | ||
| .build(); | ||
| } | ||
|
|
||
| protected void assertSpecificAttributes() { | ||
| // Nothing to be done here attributes are always non null | ||
| } | ||
|
|
||
| protected String getActionName() { | ||
| return "AcEmulationDeactivationAction"; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Copyright (c) 2025, RTE (http://www.rte-france.com) | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
|
|
||
| package com.powsybl.openrao.data.crac.impl; | ||
|
|
||
| import com.powsybl.action.HvdcAction; | ||
| import com.powsybl.openrao.commons.OpenRaoException; | ||
| import com.powsybl.openrao.data.crac.api.Crac; | ||
| import com.powsybl.openrao.data.crac.api.networkaction.AcEmulationDeactivationActionAdder; | ||
| import com.powsybl.openrao.data.crac.api.networkaction.NetworkAction; | ||
| import com.powsybl.openrao.data.crac.api.networkaction.NetworkActionAdder; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| /** | ||
| * @author Roxane Chen {@literal <roxane.chen at rte-france.com>} | ||
| */ | ||
| public class AcEmulationDeactivationActionAdderImplTest { | ||
|
Check warning on line 24 in data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/AcEmulationDeactivationActionAdderImplTest.java
|
||
| private Crac crac; | ||
| private NetworkActionAdder networkActionAdder; | ||
|
|
||
| @BeforeEach | ||
| public void setUp() { | ||
|
Check warning on line 29 in data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/AcEmulationDeactivationActionAdderImplTest.java
|
||
| crac = new CracImplFactory().create("cracId"); | ||
| networkActionAdder = crac.newNetworkAction() | ||
| .withId("networkActionId") | ||
| .withName("networkActionName") | ||
| .withOperator("operator"); | ||
| } | ||
|
|
||
| @Test | ||
| void testOk() { | ||
| NetworkAction networkAction = networkActionAdder.newAcEmulationDeactivationAction() | ||
| .withNetworkElement("hvdcLineElementId") | ||
| .add() | ||
| .add(); | ||
|
|
||
| HvdcAction hvdcAction = (HvdcAction) networkAction.getElementaryActions().iterator().next(); | ||
| assertEquals("hvdcLineElementId", hvdcAction.getHvdcId()); | ||
| assertFalse(hvdcAction.isAcEmulationEnabled().get()); | ||
|
|
||
| // check that network element has been added in CracImpl | ||
| assertEquals(1, ((CracImpl) crac).getNetworkElements().size()); | ||
| assertNotNull(((CracImpl) crac).getNetworkElement("hvdcLineElementId")); | ||
| } | ||
|
|
||
| @Test | ||
| void testNoNetworkElement() { | ||
| AcEmulationDeactivationActionAdder acEmulationDeactivationActionAdder = networkActionAdder.newAcEmulationDeactivationAction(); | ||
| assertThrows(OpenRaoException.class, acEmulationDeactivationActionAdder::add); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * Copyright (c) 2021, RTE (http://www.rte-france.com) | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
|
|
||
| package com.powsybl.openrao.data.crac.io.json.deserializers; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonParser; | ||
| import com.fasterxml.jackson.core.JsonToken; | ||
| import com.powsybl.openrao.commons.OpenRaoException; | ||
| import com.powsybl.openrao.data.crac.api.networkaction.AcEmulationDeactivationActionAdder; | ||
| import com.powsybl.openrao.data.crac.api.networkaction.NetworkActionAdder; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
|
|
||
| import static com.powsybl.openrao.data.crac.io.json.JsonSerializationConstants.*; | ||
|
|
||
| /** | ||
| * @author Roxane Chen {@literal <roxane.chen at rte-france.com>} | ||
| */ | ||
| public final class AcEmulationDeactivationActionDeserializer { | ||
| private AcEmulationDeactivationActionDeserializer() { | ||
| } | ||
|
|
||
| public static void deserialize(JsonParser jsonParser, NetworkActionAdder ownerAdder, Map<String, String> networkElementsNamesPerId) throws IOException { | ||
| if (networkElementsNamesPerId == null) { | ||
| throw new OpenRaoException(String.format("Cannot deserialize %s before %s", AC_EMULATION_DEACTIVATION_ACTIONS, NETWORK_ELEMENTS_NAME_PER_ID)); | ||
| } | ||
| while (jsonParser.nextToken() != JsonToken.END_ARRAY) { | ||
| AcEmulationDeactivationActionAdder adder = ownerAdder.newAcEmulationDeactivationAction(); | ||
| while (!jsonParser.nextToken().isStructEnd()) { | ||
| switch (jsonParser.getCurrentName()) { | ||
|
Check warning on line 35 in data/crac/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/crac/io/json/deserializers/AcEmulationDeactivationActionDeserializer.java
|
||
| case NETWORK_ELEMENT_ID: | ||
| deserializeNetworkElement(jsonParser.nextTextValue(), networkElementsNamesPerId, adder); | ||
| break; | ||
| default: | ||
| throw new OpenRaoException("Unexpected field in AcEmulationDeactivationAction: " + jsonParser.getCurrentName()); | ||
|
Check warning on line 40 in data/crac/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/crac/io/json/deserializers/AcEmulationDeactivationActionDeserializer.java
|
||
| } | ||
| } | ||
| adder.add(); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * Copyright (c) 2025, RTE (http://www.rte-france.com) | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
|
|
||
| package com.powsybl.openrao.data.crac.io.json.serializers; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonGenerator; | ||
| import com.fasterxml.jackson.databind.SerializerProvider; | ||
| import com.powsybl.action.HvdcAction; | ||
| import com.powsybl.openrao.data.crac.io.json.JsonSerializationConstants; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * @author Roxane Chen {@literal <roxane.chen at rte-france.com>} | ||
| */ | ||
| public class AcEmulationDeactivationActionSerializer extends AbstractJsonSerializer<HvdcAction> { | ||
| @Override | ||
| public void serialize(HvdcAction value, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException { | ||
| gen.writeStartObject(); | ||
| gen.writeStringField(JsonSerializationConstants.NETWORK_ELEMENT_ID, value.getHvdcId()); | ||
| gen.writeEndObject(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema#", | ||
| "$id": "https://www.powsybl.org?open-rao-crac-schema=ac-emulation-deactivation-action-v2.9.json", | ||
| "type": "object", | ||
| "properties": { | ||
| "networkElementId": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "additionalProperties": false, | ||
| "required": [ | ||
| "networkElementId" | ||
| ] | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.