-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support of static var compensator action (#2654)
* add static var compensator action * review * remove regulating Terminal * Fix typo. * Fix again. --------- Signed-off-by: Etienne LESOT <etienne.lesot@rte-france.com> Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com> Co-authored-by: Anne Tilloy <48123713+annetill@users.noreply.github.com> Co-authored-by: Anne Tilloy <anne.tilloy@rte-france.com>
- Loading branch information
1 parent
b9875d2
commit 94fe8c0
Showing
8 changed files
with
287 additions
and
3 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...ty-analysis-api/src/main/java/com/powsybl/security/action/StaticVarCompensatorAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Copyright (c) 2023, 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/. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
package com.powsybl.security.action; | ||
|
||
import com.powsybl.iidm.network.StaticVarCompensator; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.OptionalDouble; | ||
|
||
/** | ||
* An action to: | ||
* <ul> | ||
* <li>change the regulationMode of a static var compensator, three options are available VOLTAGE, REACTIVE_POWER or OFF</li> | ||
* <li>change voltageSetPoint to change the voltage setpoint if the regulation mode is set to VOLTAGE (kV) </li> | ||
* <li>change reactivePowerSetpoint to change the reactive power setpoint if the regulation mode is set to REACTIVE_POWER (MVAR)</li> | ||
* </ul> | ||
* @author Etienne Lesot <etienne.lesot@rte-france.com> | ||
*/ | ||
public class StaticVarCompensatorAction extends AbstractAction { | ||
|
||
public static final String NAME = "STATIC_VAR_COMPENSATOR"; | ||
private final String staticVarCompensatorId; | ||
private final StaticVarCompensator.RegulationMode regulationMode; | ||
private final Double voltageSetpoint; | ||
private final Double reactivePowerSetpoint; | ||
|
||
protected StaticVarCompensatorAction(String id, String staticVarCompensatorId, | ||
StaticVarCompensator.RegulationMode regulationMode, | ||
Double voltageSetpoint, Double reactivePowerSetpoint) { | ||
super(id); | ||
this.staticVarCompensatorId = Objects.requireNonNull(staticVarCompensatorId); | ||
this.regulationMode = regulationMode; | ||
this.voltageSetpoint = voltageSetpoint; | ||
this.reactivePowerSetpoint = reactivePowerSetpoint; | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return NAME; | ||
} | ||
|
||
public String getStaticVarCompensatorId() { | ||
return staticVarCompensatorId; | ||
} | ||
|
||
public Optional<StaticVarCompensator.RegulationMode> getRegulationMode() { | ||
return Optional.ofNullable(regulationMode); | ||
} | ||
|
||
public OptionalDouble getVoltageSetpoint() { | ||
return voltageSetpoint == null ? OptionalDouble.empty() : OptionalDouble.of(voltageSetpoint); | ||
} | ||
|
||
public OptionalDouble getReactivePowerSetpoint() { | ||
return reactivePowerSetpoint == null ? OptionalDouble.empty() : OptionalDouble.of(reactivePowerSetpoint); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...ysis-api/src/main/java/com/powsybl/security/action/StaticVarCompensatorActionBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright (c) 2023, 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/. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
package com.powsybl.security.action; | ||
|
||
import com.powsybl.iidm.network.StaticVarCompensator; | ||
|
||
/** | ||
* @author Etienne Lesot <etienne.lesot@rte-france.com> | ||
*/ | ||
public class StaticVarCompensatorActionBuilder { | ||
|
||
private String id; | ||
private String staticVarCompensatorId; | ||
private StaticVarCompensator.RegulationMode regulationMode; | ||
private Double voltageSetpoint; | ||
private Double reactivePowerSetpoint; | ||
|
||
public StaticVarCompensatorAction build() { | ||
return new StaticVarCompensatorAction(id, staticVarCompensatorId, regulationMode, voltageSetpoint, reactivePowerSetpoint); | ||
} | ||
|
||
public StaticVarCompensatorActionBuilder withId(String id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
public StaticVarCompensatorActionBuilder withStaticVarCompensatorId(String staticVarCompensatorId) { | ||
this.staticVarCompensatorId = staticVarCompensatorId; | ||
return this; | ||
} | ||
|
||
public StaticVarCompensatorActionBuilder withRegulationMode(StaticVarCompensator.RegulationMode regulationMode) { | ||
this.regulationMode = regulationMode; | ||
return this; | ||
} | ||
|
||
public StaticVarCompensatorActionBuilder withVoltageSetpoint(Double voltageSetpoint) { | ||
this.voltageSetpoint = voltageSetpoint; | ||
return this; | ||
} | ||
|
||
public StaticVarCompensatorActionBuilder withReactivePowerSetpoint(Double reactivePowerSetpoint) { | ||
this.reactivePowerSetpoint = reactivePowerSetpoint; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...rc/main/java/com/powsybl/security/json/action/StaticVarCompensatorActionDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* Copyright (c) 2023, 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/. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
package com.powsybl.security.json.action; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
import com.powsybl.commons.json.JsonUtil; | ||
import com.powsybl.iidm.network.StaticVarCompensator; | ||
import com.powsybl.security.action.StaticVarCompensatorAction; | ||
import com.powsybl.security.action.StaticVarCompensatorActionBuilder; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* @author Etienne Lesot <etienne.lesot at rte-france.com> | ||
*/ | ||
public class StaticVarCompensatorActionDeserializer extends StdDeserializer<StaticVarCompensatorAction> { | ||
|
||
public StaticVarCompensatorActionDeserializer() { | ||
super(StaticVarCompensatorAction.class); | ||
} | ||
|
||
private static class ParsingContext { | ||
String id; | ||
String staticVarCompensatorId; | ||
String regulationMode; | ||
Double voltageSetpoint; | ||
Double reactivePowerSetpoint; | ||
} | ||
|
||
@Override | ||
public StaticVarCompensatorAction deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { | ||
ParsingContext context = new ParsingContext(); | ||
JsonUtil.parsePolymorphicObject(jsonParser, name -> { | ||
switch (name) { | ||
case "type": | ||
if (!StaticVarCompensatorAction.NAME.equals(jsonParser.nextTextValue())) { | ||
throw JsonMappingException.from(jsonParser, "Expected type " + StaticVarCompensatorAction.NAME); | ||
} | ||
return true; | ||
case "id": | ||
context.id = jsonParser.nextTextValue(); | ||
return true; | ||
case "staticVarCompensatorId": | ||
context.staticVarCompensatorId = jsonParser.nextTextValue(); | ||
return true; | ||
case "regulationMode": | ||
context.regulationMode = jsonParser.nextTextValue(); | ||
return true; | ||
case "voltageSetpoint": | ||
jsonParser.nextToken(); | ||
context.voltageSetpoint = jsonParser.getValueAsDouble(); | ||
return true; | ||
case "reactivePowerSetpoint": | ||
jsonParser.nextToken(); | ||
context.reactivePowerSetpoint = jsonParser.getValueAsDouble(); | ||
return true; | ||
default: | ||
return false; | ||
} | ||
}); | ||
StaticVarCompensatorActionBuilder builder = new StaticVarCompensatorActionBuilder(); | ||
builder.withId(context.id) | ||
.withStaticVarCompensatorId(context.staticVarCompensatorId); | ||
if (context.regulationMode != null) { | ||
builder.withRegulationMode(StaticVarCompensator.RegulationMode.valueOf(context.regulationMode)); | ||
} | ||
if (context.voltageSetpoint != null) { | ||
builder.withVoltageSetpoint(context.voltageSetpoint); | ||
} | ||
if (context.reactivePowerSetpoint != null) { | ||
builder.withReactivePowerSetpoint(context.reactivePowerSetpoint); | ||
} | ||
return builder.build(); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
.../src/main/java/com/powsybl/security/json/action/StaticVarCompensatorActionSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright (c) 2023, 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/. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
package com.powsybl.security.json.action; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.ser.std.StdSerializer; | ||
import com.powsybl.security.action.StaticVarCompensatorAction; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
|
||
/** | ||
* @author Etienne Lesot <etienne.lesot at rte-france.com> | ||
*/ | ||
public class StaticVarCompensatorActionSerializer extends StdSerializer<StaticVarCompensatorAction> { | ||
|
||
public StaticVarCompensatorActionSerializer() { | ||
super(StaticVarCompensatorAction.class); | ||
} | ||
|
||
@Override | ||
public void serialize(StaticVarCompensatorAction action, JsonGenerator jsonGenerator, | ||
SerializerProvider serializerProvider) throws IOException { | ||
jsonGenerator.writeStartObject(); | ||
jsonGenerator.writeStringField("type", action.getType()); | ||
jsonGenerator.writeStringField("id", action.getId()); | ||
jsonGenerator.writeStringField("staticVarCompensatorId", action.getStaticVarCompensatorId()); | ||
action.getRegulationMode().ifPresent(regulationMode -> { | ||
try { | ||
jsonGenerator.writeStringField("regulationMode", String.valueOf(regulationMode)); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
}); | ||
action.getReactivePowerSetpoint().ifPresent(reactivePowerSetpoint -> { | ||
try { | ||
jsonGenerator.writeNumberField("reactivePowerSetpoint", reactivePowerSetpoint); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
}); | ||
action.getVoltageSetpoint().ifPresent(voltageSetpoint -> { | ||
try { | ||
jsonGenerator.writeNumberField("voltageSetpoint", voltageSetpoint); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
}); | ||
jsonGenerator.writeEndObject(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters