diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/PhaseTapChangerAdder.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/PhaseTapChangerAdder.java index 88fbee6361e..3cc3024bc3a 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/PhaseTapChangerAdder.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/PhaseTapChangerAdder.java @@ -7,45 +7,11 @@ package com.powsybl.iidm.network; /** - * * @author Geoffroy Jamgotchian {@literal } */ -public interface PhaseTapChangerAdder { - - interface StepAdder { - - StepAdder setAlpha(double alpha); - - StepAdder setRho(double rho); - - StepAdder setR(double r); - - StepAdder setX(double x); - - StepAdder setG(double g); - - StepAdder setB(double b); - - PhaseTapChangerAdder endStep(); - } - - PhaseTapChangerAdder setLowTapPosition(int lowTapPosition); - - PhaseTapChangerAdder setTapPosition(int tapPosition); - - PhaseTapChangerAdder setRegulating(boolean regulating); +public interface PhaseTapChangerAdder extends TapChangerAdder { PhaseTapChangerAdder setRegulationMode(PhaseTapChanger.RegulationMode regulationMode); PhaseTapChangerAdder setRegulationValue(double regulationValue); - - PhaseTapChangerAdder setRegulationTerminal(Terminal regulationTerminal); - - default PhaseTapChangerAdder setTargetDeadband(double targetDeadband) { - throw new UnsupportedOperationException(); - } - - StepAdder beginStep(); - - PhaseTapChanger add(); } diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/PhaseTapChangerStepAdder.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/PhaseTapChangerStepAdder.java new file mode 100644 index 00000000000..8d17f2dfd20 --- /dev/null +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/PhaseTapChangerStepAdder.java @@ -0,0 +1,16 @@ +/** + * Copyright (c) 2024, 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.iidm.network; + +/** + * @author Florent MILLOT {@literal } + */ +public interface PhaseTapChangerStepAdder extends TapChangerStepAdder { + PhaseTapChangerStepAdder setAlpha(double alpha); +} diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/RatioTapChangerAdder.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/RatioTapChangerAdder.java index b6eec20091b..a11bfe04a96 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/RatioTapChangerAdder.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/RatioTapChangerAdder.java @@ -7,48 +7,15 @@ package com.powsybl.iidm.network; /** - * * @author Geoffroy Jamgotchian {@literal } */ -public interface RatioTapChangerAdder { - - public interface StepAdder { - - StepAdder setRho(double rho); - - StepAdder setR(double r); - - StepAdder setX(double x); - - StepAdder setG(double g); - - StepAdder setB(double b); - - RatioTapChangerAdder endStep(); - } - - RatioTapChangerAdder setLowTapPosition(int lowTapPosition); - - RatioTapChangerAdder setTapPosition(int tapPosition); - - RatioTapChangerAdder setLoadTapChangingCapabilities(boolean loadTapChangingCapabilities); - - RatioTapChangerAdder setRegulating(boolean regulating); +public interface RatioTapChangerAdder extends TapChangerAdder { RatioTapChangerAdder setRegulationMode(RatioTapChanger.RegulationMode regulationMode); RatioTapChangerAdder setRegulationValue(double regulationValue); - RatioTapChangerAdder setTargetV(double targetV); - - RatioTapChangerAdder setRegulationTerminal(Terminal regulationTerminal); - - default RatioTapChangerAdder setTargetDeadband(double targetDeadband) { - throw new UnsupportedOperationException(); - } - - StepAdder beginStep(); - - RatioTapChanger add(); + RatioTapChangerAdder setLoadTapChangingCapabilities(boolean loadTapChangingCapabilities); + RatioTapChangerAdder setTargetV(double targetV); } diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/RatioTapChangerStepAdder.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/RatioTapChangerStepAdder.java new file mode 100644 index 00000000000..b93f186ddd4 --- /dev/null +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/RatioTapChangerStepAdder.java @@ -0,0 +1,14 @@ +/** + * Copyright (c) 2024, 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.iidm.network; + +/** + * @author Florent MILLOT {@literal } + */ +public interface RatioTapChangerStepAdder extends TapChangerStepAdder { +} diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/TapChangerAdder.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/TapChangerAdder.java new file mode 100644 index 00000000000..1235e1b873d --- /dev/null +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/TapChangerAdder.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2024, 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.iidm.network; + +/** + * @author Florent MILLOT {@literal } + */ +public interface TapChangerAdder, A extends TapChangerStepAdder, C extends TapChanger> { + + S setLowTapPosition(int lowTapPosition); + + S setTapPosition(int tapPosition); + + S setRegulating(boolean regulating); + + S setRegulationTerminal(Terminal regulationTerminal); + + default S setTargetDeadband(double targetDeadband) { + throw new UnsupportedOperationException(); + } + + A beginStep(); + + C add(); + +} diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/TapChangerStepAdder.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/TapChangerStepAdder.java new file mode 100644 index 00000000000..a7e084477dd --- /dev/null +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/TapChangerStepAdder.java @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2024, 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.iidm.network; + +/** + * @author Florent MILLOT {@literal } + */ +public interface TapChangerStepAdder, A extends TapChangerAdder> { + S setRho(double rho); + + S setR(double r); + + S setX(double x); + + S setG(double g); + + S setB(double b); + + A endStep(); +} diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/PhaseTapChangerAdderImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/PhaseTapChangerAdderImpl.java index dbfbf488da1..7d2634f0d70 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/PhaseTapChangerAdderImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/PhaseTapChangerAdderImpl.java @@ -44,7 +44,7 @@ class PhaseTapChangerAdderImpl implements PhaseTapChangerAdder { private TerminalExt regulationTerminal; - class StepAdderImpl implements StepAdder { + class StepAdderImpl implements PhaseTapChangerStepAdder { private double alpha = Double.NaN; @@ -59,37 +59,37 @@ class StepAdderImpl implements StepAdder { private double b = 0.0; @Override - public StepAdder setAlpha(double alpha) { + public PhaseTapChangerStepAdder setAlpha(double alpha) { this.alpha = alpha; return this; } @Override - public StepAdder setRho(double rho) { + public PhaseTapChangerStepAdder setRho(double rho) { this.rho = rho; return this; } @Override - public StepAdder setR(double r) { + public PhaseTapChangerStepAdder setR(double r) { this.r = r; return this; } @Override - public StepAdder setX(double x) { + public PhaseTapChangerStepAdder setX(double x) { this.x = x; return this; } @Override - public StepAdder setG(double g) { + public PhaseTapChangerStepAdder setG(double g) { this.g = g; return this; } @Override - public StepAdder setB(double b) { + public PhaseTapChangerStepAdder setB(double b) { this.b = b; return this; } @@ -172,7 +172,7 @@ public PhaseTapChangerAdder setRegulationTerminal(Terminal regulationTerminal) { } @Override - public StepAdder beginStep() { + public PhaseTapChangerStepAdder beginStep() { return new StepAdderImpl(); } diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/RatioTapChangerAdderImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/RatioTapChangerAdderImpl.java index 6f8d709b333..2093fc7b63d 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/RatioTapChangerAdderImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/RatioTapChangerAdderImpl.java @@ -43,7 +43,7 @@ class RatioTapChangerAdderImpl implements RatioTapChangerAdder { private TerminalExt regulationTerminal; - class StepAdderImpl implements StepAdder { + class StepAdderImpl implements RatioTapChangerStepAdder { private double rho = Double.NaN; @@ -56,31 +56,31 @@ class StepAdderImpl implements StepAdder { private double b = 0.0; @Override - public StepAdder setRho(double rho) { + public RatioTapChangerStepAdder setRho(double rho) { this.rho = rho; return this; } @Override - public StepAdder setR(double r) { + public RatioTapChangerStepAdder setR(double r) { this.r = r; return this; } @Override - public StepAdder setX(double x) { + public RatioTapChangerStepAdder setX(double x) { this.x = x; return this; } @Override - public StepAdder setG(double g) { + public RatioTapChangerStepAdder setG(double g) { this.g = g; return this; } @Override - public StepAdder setB(double b) { + public RatioTapChangerStepAdder setB(double b) { this.b = b; return this; } @@ -175,7 +175,7 @@ public RatioTapChangerAdder setRegulationTerminal(Terminal regulationTerminal) { } @Override - public StepAdder beginStep() { + public RatioTapChangerStepAdder beginStep() { return new StepAdderImpl(); } diff --git a/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/AbstractTransformerSerDe.java b/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/AbstractTransformerSerDe.java index 988c4da371c..074adbea8be 100644 --- a/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/AbstractTransformerSerDe.java +++ b/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/AbstractTransformerSerDe.java @@ -18,11 +18,6 @@ */ abstract class AbstractTransformerSerDe, A extends IdentifiableAdder> extends AbstractSimpleIdentifiableSerDe { - private interface StepConsumer { - - void accept(double r, double x, double g, double b, double rho); - } - private static final String ATTR_LOW_TAP_POSITION = "lowTapPosition"; private static final String ATTR_TAP_POSITION = "tapPosition"; private static final String ATTR_REGULATING = "regulating"; @@ -103,11 +98,10 @@ protected static void writeRatioTapChanger(String name, RatioTapChanger rtc, Net } protected static void readRatioTapChanger(String elementName, RatioTapChangerAdder adder, Terminal terminal, NetworkDeserializerContext context) { - boolean regulating = context.getReader().readBooleanAttribute(ATTR_REGULATING, false); - int lowTapPosition = context.getReader().readIntAttribute(ATTR_LOW_TAP_POSITION); - Integer tapPosition = context.getReader().readIntAttribute(ATTR_TAP_POSITION); - double targetDeadband = readTargetDeadband(context, regulating); + readTapChangerAttributes(adder, context); + boolean loadTapChangingCapabilities = context.getReader().readBooleanAttribute("loadTapChangingCapabilities"); + adder.setLoadTapChangingCapabilities(loadTapChangingCapabilities); IidmSerDeUtil.runUntilMaximumVersion(IidmVersion.V_1_11, context, () -> { double targetV = context.getReader().readDoubleAttribute("targetV"); @@ -123,32 +117,17 @@ protected static void readRatioTapChanger(String elementName, RatioTapChangerAdd .setRegulationValue(regulationValue); }); - adder.setLowTapPosition(lowTapPosition) - .setTargetDeadband(targetDeadband) - .setLoadTapChangingCapabilities(loadTapChangingCapabilities) - .setRegulating(regulating); - if (tapPosition != null) { - adder.setTapPosition(tapPosition); - } - boolean[] hasTerminalRef = new boolean[1]; context.getReader().readChildNodes(subElementName -> { switch (subElementName) { case ELEM_TERMINAL_REF -> { hasTerminalRef[0] = true; - TerminalRefSerDe.readTerminalRef(context, terminal.getVoltageLevel().getNetwork(), tRef -> { - adder.setRegulationTerminal(tRef); - adder.add(); - }); + readTapChangerTerminalRef(adder, terminal, context); } case STEP_ROOT_ELEMENT_NAME -> { - readSteps(context, (r, x, g, b, rho) -> adder.beginStep() - .setR(r) - .setX(x) - .setG(g) - .setB(b) - .setRho(rho) - .endStep()); + RatioTapChangerStepAdder stepAdder = adder.beginStep(); + readSteps(context, stepAdder); + stepAdder.endStep(); context.getReader().readEndNode(); } default -> throw new PowsyblException("Unknown element name '" + subElementName + "' in '" + elementName + "'"); @@ -197,43 +176,27 @@ protected static void writePhaseTapChanger(String name, PhaseTapChanger ptc, Net } protected static void readPhaseTapChanger(String name, PhaseTapChangerAdder adder, Terminal terminal, NetworkDeserializerContext context) { - boolean regulating = context.getReader().readBooleanAttribute(ATTR_REGULATING, false); - int lowTapPosition = context.getReader().readIntAttribute(ATTR_LOW_TAP_POSITION); - Integer tapPosition = context.getReader().readIntAttribute(ATTR_TAP_POSITION); - double targetDeadband = readTargetDeadband(context, regulating); + readTapChangerAttributes(adder, context); + PhaseTapChanger.RegulationMode regulationMode = context.getReader().readEnumAttribute(ATTR_REGULATION_MODE, PhaseTapChanger.RegulationMode.class); double regulationValue = context.getReader().readDoubleAttribute(ATTR_REGULATION_VALUE); - - adder.setLowTapPosition(lowTapPosition) - .setTargetDeadband(targetDeadband) - .setRegulationMode(regulationMode) - .setRegulationValue(regulationValue) - .setRegulating(regulating); - if (tapPosition != null) { - adder.setTapPosition(tapPosition); - } + adder.setRegulationMode(regulationMode) + .setRegulationValue(regulationValue); boolean[] hasTerminalRef = new boolean[1]; context.getReader().readChildNodes(elementName -> { switch (elementName) { case ELEM_TERMINAL_REF -> { hasTerminalRef[0] = true; - TerminalRefSerDe.readTerminalRef(context, terminal.getVoltageLevel().getNetwork(), tRef -> { - adder.setRegulationTerminal(tRef); - adder.add(); - }); + readTapChangerTerminalRef(adder, terminal, context); } case STEP_ROOT_ELEMENT_NAME -> { - PhaseTapChangerAdder.StepAdder stepAdder = adder.beginStep(); - readSteps(context, (r, x, g, b, rho) -> stepAdder.setR(r) - .setX(x) - .setG(g) - .setB(b) - .setRho(rho)); + PhaseTapChangerStepAdder stepAdder = adder.beginStep(); + readSteps(context, stepAdder); double alpha = context.getReader().readDoubleAttribute("alpha"); - context.getReader().readEndNode(); stepAdder.setAlpha(alpha) .endStep(); + context.getReader().readEndNode(); } default -> throw new PowsyblException("Unknown element name '" + elementName + "' in '" + name + "'"); } @@ -243,6 +206,26 @@ protected static void readPhaseTapChanger(String name, PhaseTapChangerAdder adde } } + private static void readTapChangerTerminalRef(TapChangerAdder adder, Terminal terminal, NetworkDeserializerContext context) { + TerminalRefSerDe.readTerminalRef(context, terminal.getVoltageLevel().getNetwork(), tRef -> { + adder.setRegulationTerminal(tRef); + adder.add(); + }); + } + + private static void readTapChangerAttributes(TapChangerAdder adder, NetworkDeserializerContext context) { + boolean regulating = context.getReader().readBooleanAttribute(ATTR_REGULATING, false); + int lowTapPosition = context.getReader().readIntAttribute(ATTR_LOW_TAP_POSITION); + Integer tapPosition = context.getReader().readIntAttribute(ATTR_TAP_POSITION); + double targetDeadband = readTargetDeadband(context, regulating); + adder.setLowTapPosition(lowTapPosition) + .setTargetDeadband(targetDeadband) + .setRegulating(regulating); + if (tapPosition != null) { + adder.setTapPosition(tapPosition); + } + } + protected static void readPhaseTapChanger(TwoWindingsTransformer twt, NetworkDeserializerContext context) { readPhaseTapChanger(PHASE_TAP_CHANGER, twt.newPhaseTapChanger(), twt.getTerminal1(), context); } @@ -251,13 +234,13 @@ protected static void readPhaseTapChanger(int leg, ThreeWindingsTransformer.Leg readPhaseTapChanger(PHASE_TAP_CHANGER + leg, twl.newPhaseTapChanger(), twl.getTerminal(), context); } - private static void readSteps(NetworkDeserializerContext context, StepConsumer consumer) { + private static void readSteps(NetworkDeserializerContext context, TapChangerStepAdder adder) { double r = context.getReader().readDoubleAttribute("r"); double x = context.getReader().readDoubleAttribute("x"); double g = context.getReader().readDoubleAttribute("g"); double b = context.getReader().readDoubleAttribute("b"); double rho = context.getReader().readDoubleAttribute("rho"); - consumer.accept(r, x, g, b, rho); + adder.setR(r).setX(x).setG(g).setB(b).setRho(rho); } /**