From f27a89ad8dfad2fcfa107b0a72f13891e721282c Mon Sep 17 00:00:00 2001 From: miovd Date: Fri, 3 Jun 2022 13:30:27 +0200 Subject: [PATCH] Use targetP/targetQ instead of p0/q0 for IIDM Battery (#2153) Signed-off-by: VEDELAGO MIORA --- .../ampl/converter/AmplNetworkReader.java | 8 +-- .../ampl/converter/AmplNetworkWriter.java | 8 +-- .../ampl/converter/AmplNetworkReaderTest.java | 8 +-- .../com/powsybl/iidm/network/Battery.java | 48 ++++++++++++++--- .../powsybl/iidm/network/BatteryAdder.java | 24 +++++++-- .../powsybl/iidm/network/ValidationUtil.java | 4 +- .../iidm/network/impl/BatteryAdderImpl.java | 18 +++---- .../iidm/network/impl/BatteryImpl.java | 54 +++++++++---------- .../iidm/mergingview/BatteryAdapter.java | 16 +++--- .../iidm/mergingview/BatteryAdderAdapter.java | 8 +-- .../iidm/mergingview/BatteryAdapterTest.java | 16 +++--- .../mergingview/VoltageLevelAdapterTest.java | 4 +- .../scripting/BatteryAdderExtension.groovy | 22 ++++++++ .../network/scripting/BatteryExtension.groovy | 30 +++++++++++ ...rg.codehaus.groovy.runtime.ExtensionModule | 2 +- .../scripting/BatteryExtensionTest.groovy | 47 ++++++++++++++++ .../iidm/network/tck/AbstractBatteryTest.java | 44 +++++++-------- .../iidm/network/tck/AbstractNetworkTest.java | 8 +-- .../network/test/BatteryNetworkFactory.java | 8 +-- .../java/com/powsybl/iidm/xml/BatteryXml.java | 17 +++--- .../powsybl/iidm/xml/util/IidmXmlUtil.java | 12 +++++ .../src/main/resources/xsd/iidm_V1_8.xsd | 4 +- .../resources/xsd/iidm_equipment_V1_8.xsd | 4 +- .../V1_8/activePowerControlRoundTripRef.xml | 4 +- .../resources/V1_8/batteryRoundTripRef.xml | 4 +- .../V1_8/branchObservabilityRoundTripRef.xml | 4 +- ...branchObservabilityRoundTripRefInvalid.xml | 4 +- .../injectionObservabilityRoundTripRef.xml | 4 +- ...ectionObservabilityRoundTripRefInvalid.xml | 4 +- 29 files changed, 301 insertions(+), 137 deletions(-) create mode 100644 iidm/iidm-scripting/src/main/groovy/com/powsybl/iidm/network/scripting/BatteryAdderExtension.groovy create mode 100644 iidm/iidm-scripting/src/main/groovy/com/powsybl/iidm/network/scripting/BatteryExtension.groovy create mode 100644 iidm/iidm-scripting/src/test/groovy/com/powsybl/iidm/network/scripting/BatteryExtensionTest.groovy diff --git a/ampl-converter/src/main/java/com/powsybl/ampl/converter/AmplNetworkReader.java b/ampl-converter/src/main/java/com/powsybl/ampl/converter/AmplNetworkReader.java index ebb7c7d6d52..66c733a7770 100644 --- a/ampl-converter/src/main/java/com/powsybl/ampl/converter/AmplNetworkReader.java +++ b/ampl-converter/src/main/java/com/powsybl/ampl/converter/AmplNetworkReader.java @@ -148,8 +148,8 @@ public AmplNetworkReader readBatteries() throws IOException { private Void readBattery(String[] tokens) { int num = Integer.parseInt(tokens[1]); int busNum = Integer.parseInt(tokens[2]); - double p0 = readDouble(tokens[3]); - double q0 = readDouble(tokens[4]); + double targetP = readDouble(tokens[3]); + double targetQ = readDouble(tokens[4]); double p = readDouble(tokens[5]); double q = readDouble(tokens[6]); @@ -158,8 +158,8 @@ private Void readBattery(String[] tokens) { if (b == null) { throw new AmplException("Invalid battery id '" + id + "'"); } - b.setP0(p0); - b.setQ0(q0); + b.setTargetP(targetP); + b.setTargetQ(targetQ); Terminal t = b.getTerminal(); t.setP(p).setQ(q); diff --git a/ampl-converter/src/main/java/com/powsybl/ampl/converter/AmplNetworkWriter.java b/ampl-converter/src/main/java/com/powsybl/ampl/converter/AmplNetworkWriter.java index af4d74d1dc0..d2d5f9d0d37 100644 --- a/ampl-converter/src/main/java/com/powsybl/ampl/converter/AmplNetworkWriter.java +++ b/ampl-converter/src/main/java/com/powsybl/ampl/converter/AmplNetworkWriter.java @@ -1603,8 +1603,8 @@ private void writeBatteries(AmplExportContext context) throws IOException { context.batteryIdsToExport.add(id); int num = mapper.getInt(AmplSubset.BATTERY, id); int vlNum = mapper.getInt(AmplSubset.VOLTAGE_LEVEL, t.getVoltageLevel().getId()); - double p0 = b.getP0(); - double q0 = b.getQ0(); + double targetP = b.getTargetP(); + double targetQ = b.getTargetQ(); double minP = b.getMinP(); double maxP = b.getMaxP(); @@ -1613,8 +1613,8 @@ private void writeBatteries(AmplExportContext context) throws IOException { .writeCell(busNum) .writeCell(conBusNum != -1 ? conBusNum : busNum) .writeCell(vlNum) - .writeCell(p0) - .writeCell(q0) + .writeCell(targetP) + .writeCell(targetQ) .writeCell(minP) .writeCell(maxP) .writeCell(b.getReactiveLimits().getMinQ(maxP)) diff --git a/ampl-converter/src/test/java/com/powsybl/ampl/converter/AmplNetworkReaderTest.java b/ampl-converter/src/test/java/com/powsybl/ampl/converter/AmplNetworkReaderTest.java index 7b4569332ef..cb1bc15184c 100644 --- a/ampl-converter/src/test/java/com/powsybl/ampl/converter/AmplNetworkReaderTest.java +++ b/ampl-converter/src/test/java/com/powsybl/ampl/converter/AmplNetworkReaderTest.java @@ -256,8 +256,8 @@ private void testGenerators(Network network, AmplNetworkReader reader) throws IO private void testBatteries(Network network, AmplNetworkReader reader) throws IOException { Battery battery = network.getBattery("BAT"); - assertEquals(9999.99, battery.getP0(), 0.0); - assertEquals(9999.99, battery.getQ0(), 0.0); + assertEquals(9999.99, battery.getTargetP(), 0.0); + assertEquals(9999.99, battery.getTargetQ(), 0.0); assertEquals(-9999.99, battery.getMinP(), 0.0); assertEquals(9999.99, battery.getMaxP(), 0.0); assertEquals(-605.0, battery.getTerminal().getP(), 0.0); @@ -265,8 +265,8 @@ private void testBatteries(Network network, AmplNetworkReader reader) throws IOE reader.readBatteries(); - assertEquals(12.0, battery.getP0(), 0.0); - assertEquals(13.0, battery.getQ0(), 0.0); + assertEquals(12.0, battery.getTargetP(), 0.0); + assertEquals(13.0, battery.getTargetQ(), 0.0); assertEquals(300.0, battery.getTerminal().getP(), 0.0); assertEquals(150.0, battery.getTerminal().getQ(), 0.0); } diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Battery.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Battery.java index 54dcf5e69aa..994fb69db8a 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Battery.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Battery.java @@ -87,32 +87,64 @@ public interface Battery extends Injection, ReactiveLimitsHolder { /** - * Get the constant active power in MW. + * @deprecated Use {@link #getTargetP()} instead. + */ + @Deprecated(since = "4.9.0") + default double getP0() { + return getTargetP(); + } + + /** + * Get the target active power in MW. *

Depends on the working variant. * @see VariantManager */ - double getP0(); + double getTargetP(); + + /** + * @deprecated Use {@link #setTargetP(double)} instead. + */ + @Deprecated(since = "4.9.0") + default Battery setP0(double p0) { + return setTargetP(p0); + } /** - * Set the constant active power in MW. + * Set the target active power in MW. *

Depends on the working variant. * @see VariantManager */ - Battery setP0(double p0); + Battery setTargetP(double targetP); /** - * Get the constant reactive power in MVar. + * @deprecated Use {@link #getTargetQ()} instead. + */ + @Deprecated(since = "4.9.0") + default double getQ0() { + return getTargetQ(); + } + + /** + * Get the target reactive power in MVar. *

Depends on the working variant. * @see VariantManager */ - double getQ0(); + double getTargetQ(); + + /** + * @deprecated Use {@link #setTargetP(double)} instead. + */ + @Deprecated(since = "4.9.0") + default Battery setQ0(double q0) { + return setTargetQ(q0); + } /** - * Set the constant reactive power in MVar. + * Set the target reactive power in MVar. *

Depends on the working variant. * @see VariantManager */ - Battery setQ0(double q0); + Battery setTargetQ(double targetQ); /** * Get the minimal active power in MW. diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/BatteryAdder.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/BatteryAdder.java index 0c93bf91c9c..0ac192dd6ed 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/BatteryAdder.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/BatteryAdder.java @@ -27,18 +27,34 @@ public interface BatteryAdder extends InjectionAdder { /** - * Set the constant active power in MW. + * @deprecated Use {@link #setTargetP(double)} instead. + */ + @Deprecated(since = "4.9.0") + default BatteryAdder setP0(double p0) { + return setTargetP(p0); + } + + /** + * Set the target active power in MW. *

Depends on the working variant. * @see VariantManager */ - BatteryAdder setP0(double p0); + BatteryAdder setTargetP(double targetP); + + /** + * @deprecated Use {@link #setTargetQ(double)} instead. + */ + @Deprecated(since = "4.9.0") + default BatteryAdder setQ0(double q0) { + return setTargetQ(q0); + } /** - * Set the constant reactive power in MVar. + * Set the target reactive power in MVar. *

Depends on the working variant. * @see VariantManager */ - BatteryAdder setQ0(double q0); + BatteryAdder setTargetQ(double targetQ); /** * Set the minimal active power in MW. diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ValidationUtil.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ValidationUtil.java index b2571592eab..b7f3a0c3df0 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ValidationUtil.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ValidationUtil.java @@ -694,8 +694,8 @@ private static ValidationLevel checkIdentifiable(Identifiable identifiable, V Validable validable = (Validable) identifiable; if (identifiable instanceof Battery) { Battery battery = (Battery) identifiable; - validationLevel = ValidationLevel.min(validationLevel, checkP0(validable, battery.getP0(), throwException, reporter)); - validationLevel = ValidationLevel.min(validationLevel, checkQ0(validable, battery.getQ0(), throwException, reporter)); + validationLevel = ValidationLevel.min(validationLevel, checkP0(validable, battery.getTargetP(), throwException, reporter)); + validationLevel = ValidationLevel.min(validationLevel, checkQ0(validable, battery.getTargetQ(), throwException, reporter)); } else if (identifiable instanceof DanglingLine) { DanglingLine danglingLine = (DanglingLine) identifiable; validationLevel = ValidationLevel.min(validationLevel, checkP0(validable, danglingLine.getP0(), throwException, reporter)); diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BatteryAdderImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BatteryAdderImpl.java index ea0104844a7..8d4f6f61dd6 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BatteryAdderImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BatteryAdderImpl.java @@ -20,9 +20,9 @@ public class BatteryAdderImpl extends AbstractInjectionAdder i private final VoltageLevelExt voltageLevel; - private double p0 = Double.NaN; + private double targetP = Double.NaN; - private double q0 = Double.NaN; + private double targetQ = Double.NaN; private double minP = Double.NaN; @@ -52,8 +52,8 @@ protected String getTypeDescription() { * {@inheritDoc} */ @Override - public BatteryAdderImpl setP0(double p0) { - this.p0 = p0; + public BatteryAdderImpl setTargetP(double targetP) { + this.targetP = targetP; return this; } @@ -61,8 +61,8 @@ public BatteryAdderImpl setP0(double p0) { * {@inheritDoc} */ @Override - public BatteryAdderImpl setQ0(double q0) { - this.q0 = q0; + public BatteryAdderImpl setTargetQ(double targetQ) { + this.targetQ = targetQ; return this; } @@ -92,13 +92,13 @@ public BatteryImpl add() { NetworkImpl network = getNetwork(); String id = checkAndGetUniqueId(); TerminalExt terminal = checkAndGetTerminal(); - network.setValidationLevelIfGreaterThan(ValidationUtil.checkP0(this, p0, network.getMinValidationLevel())); - network.setValidationLevelIfGreaterThan(ValidationUtil.checkQ0(this, q0, network.getMinValidationLevel())); + network.setValidationLevelIfGreaterThan(ValidationUtil.checkP0(this, targetP, network.getMinValidationLevel())); + network.setValidationLevelIfGreaterThan(ValidationUtil.checkQ0(this, targetQ, network.getMinValidationLevel())); ValidationUtil.checkMinP(this, minP); ValidationUtil.checkMaxP(this, maxP); ValidationUtil.checkActivePowerLimits(this, minP, maxP); - BatteryImpl battery = new BatteryImpl(network.getRef(), id, getName(), isFictitious(), p0, q0, minP, maxP); + BatteryImpl battery = new BatteryImpl(network.getRef(), id, getName(), isFictitious(), targetP, targetQ, minP, maxP); battery.addTerminal(terminal); voltageLevel.attach(terminal, false); diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BatteryImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BatteryImpl.java index 008b2223df2..6f67f5d05bb 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BatteryImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BatteryImpl.java @@ -19,26 +19,26 @@ public class BatteryImpl extends AbstractConnectable implements Battery private final ReactiveLimitsHolderImpl reactiveLimits; - private TDoubleArrayList p0; + private final TDoubleArrayList targetP; - private TDoubleArrayList q0; + private final TDoubleArrayList targetQ; private double minP; private double maxP; - BatteryImpl(Ref ref, String id, String name, boolean fictitious, double p0, double q0, double minP, double maxP) { + BatteryImpl(Ref ref, String id, String name, boolean fictitious, double targetP, double targetQ, double minP, double maxP) { super(ref, id, name, fictitious); this.minP = minP; this.maxP = maxP; this.reactiveLimits = new ReactiveLimitsHolderImpl(this, new MinMaxReactiveLimitsImpl(-Double.MAX_VALUE, Double.MAX_VALUE)); int variantArraySize = ref.get().getVariantManager().getVariantArraySize(); - this.p0 = new TDoubleArrayList(variantArraySize); - this.q0 = new TDoubleArrayList(variantArraySize); + this.targetP = new TDoubleArrayList(variantArraySize); + this.targetQ = new TDoubleArrayList(variantArraySize); for (int i = 0; i < variantArraySize; i++) { - this.p0.add(p0); - this.q0.add(q0); + this.targetP.add(targetP); + this.targetQ.add(targetQ); } } @@ -54,22 +54,22 @@ protected String getTypeDescription() { * {@inheritDoc} */ @Override - public double getP0() { - return p0.get(getNetwork().getVariantIndex()); + public double getTargetP() { + return targetP.get(getNetwork().getVariantIndex()); } /** * {@inheritDoc} */ @Override - public Battery setP0(double p0) { + public Battery setTargetP(double targetP) { NetworkImpl network = getNetwork(); - ValidationUtil.checkP0(this, p0, network.getMinValidationLevel()); + ValidationUtil.checkP0(this, targetP, network.getMinValidationLevel()); int variantIndex = network.getVariantIndex(); - double oldValue = this.p0.set(variantIndex, p0); + double oldValue = this.targetP.set(variantIndex, targetP); String variantId = network.getVariantManager().getVariantId(variantIndex); network.invalidateValidationLevel(); - notifyUpdate("p0", variantId, oldValue, p0); + notifyUpdate("targetP", variantId, oldValue, targetP); return this; } @@ -77,22 +77,22 @@ public Battery setP0(double p0) { * {@inheritDoc} */ @Override - public double getQ0() { - return q0.get(getNetwork().getVariantIndex()); + public double getTargetQ() { + return targetQ.get(getNetwork().getVariantIndex()); } /** * {@inheritDoc} */ @Override - public Battery setQ0(double q0) { + public Battery setTargetQ(double targetQ) { NetworkImpl network = getNetwork(); - ValidationUtil.checkQ0(this, q0, network.getMinValidationLevel()); + ValidationUtil.checkQ0(this, targetQ, network.getMinValidationLevel()); int variantIndex = network.getVariantIndex(); - double oldValue = this.q0.set(variantIndex, q0); + double oldValue = this.targetQ.set(variantIndex, targetQ); String variantId = network.getVariantManager().getVariantId(variantIndex); network.invalidateValidationLevel(); - notifyUpdate("q0", variantId, oldValue, q0); + notifyUpdate("targetQ", variantId, oldValue, targetQ); return this; } @@ -192,11 +192,11 @@ public MinMaxReactiveLimitsAdder newMinMaxReactiveLimits() { @Override public void extendVariantArraySize(int initVariantArraySize, int number, int sourceIndex) { super.extendVariantArraySize(initVariantArraySize, number, sourceIndex); - p0.ensureCapacity(p0.size() + number); - q0.ensureCapacity(q0.size() + number); + targetP.ensureCapacity(targetP.size() + number); + targetQ.ensureCapacity(targetQ.size() + number); for (int i = 0; i < number; i++) { - p0.add(p0.get(sourceIndex)); - q0.add(q0.get(sourceIndex)); + targetP.add(targetP.get(sourceIndex)); + targetQ.add(targetQ.get(sourceIndex)); } } @@ -206,8 +206,8 @@ public void extendVariantArraySize(int initVariantArraySize, int number, int sou @Override public void reduceVariantArraySize(int number) { super.reduceVariantArraySize(number); - p0.remove(p0.size() - number, number); - q0.remove(q0.size() - number, number); + targetP.remove(targetP.size() - number, number); + targetQ.remove(targetQ.size() - number, number); } /** @@ -217,8 +217,8 @@ public void reduceVariantArraySize(int number) { public void allocateVariantArrayElement(int[] indexes, int sourceIndex) { super.allocateVariantArrayElement(indexes, sourceIndex); for (int index : indexes) { - p0.set(index, p0.get(sourceIndex)); - q0.set(index, q0.get(sourceIndex)); + targetP.set(index, targetP.get(sourceIndex)); + targetQ.set(index, targetQ.get(sourceIndex)); } } } diff --git a/iidm/iidm-mergingview/src/main/java/com/powsybl/iidm/mergingview/BatteryAdapter.java b/iidm/iidm-mergingview/src/main/java/com/powsybl/iidm/mergingview/BatteryAdapter.java index aff6c5095d7..cc6030d7734 100644 --- a/iidm/iidm-mergingview/src/main/java/com/powsybl/iidm/mergingview/BatteryAdapter.java +++ b/iidm/iidm-mergingview/src/main/java/com/powsybl/iidm/mergingview/BatteryAdapter.java @@ -41,24 +41,24 @@ public MinMaxReactiveLimitsAdder newMinMaxReactiveLimits() { } @Override - public double getP0() { - return getDelegate().getP0(); + public double getTargetP() { + return getDelegate().getTargetP(); } @Override - public BatteryAdapter setP0(final double p0) { - getDelegate().setP0(p0); + public BatteryAdapter setTargetP(final double targetP) { + getDelegate().setTargetP(targetP); return this; } @Override - public double getQ0() { - return getDelegate().getQ0(); + public double getTargetQ() { + return getDelegate().getTargetQ(); } @Override - public BatteryAdapter setQ0(final double q0) { - getDelegate().setQ0(q0); + public BatteryAdapter setTargetQ(final double targetQ) { + getDelegate().setTargetQ(targetQ); return this; } diff --git a/iidm/iidm-mergingview/src/main/java/com/powsybl/iidm/mergingview/BatteryAdderAdapter.java b/iidm/iidm-mergingview/src/main/java/com/powsybl/iidm/mergingview/BatteryAdderAdapter.java index f11ea9892de..f39d1280488 100644 --- a/iidm/iidm-mergingview/src/main/java/com/powsybl/iidm/mergingview/BatteryAdderAdapter.java +++ b/iidm/iidm-mergingview/src/main/java/com/powsybl/iidm/mergingview/BatteryAdderAdapter.java @@ -28,14 +28,14 @@ public Battery add() { // Simple delegated methods ------ // ------------------------------- @Override - public BatteryAdder setP0(final double p0) { - getDelegate().setP0(p0); + public BatteryAdder setTargetP(final double targetP) { + getDelegate().setTargetP(targetP); return this; } @Override - public BatteryAdder setQ0(final double q0) { - getDelegate().setQ0(q0); + public BatteryAdder setTargetQ(final double targetQ) { + getDelegate().setTargetQ(targetQ); return this; } diff --git a/iidm/iidm-mergingview/src/test/java/com/powsybl/iidm/mergingview/BatteryAdapterTest.java b/iidm/iidm-mergingview/src/test/java/com/powsybl/iidm/mergingview/BatteryAdapterTest.java index bee92b6104a..068cc4ed39d 100644 --- a/iidm/iidm-mergingview/src/test/java/com/powsybl/iidm/mergingview/BatteryAdapterTest.java +++ b/iidm/iidm-mergingview/src/test/java/com/powsybl/iidm/mergingview/BatteryAdapterTest.java @@ -36,8 +36,8 @@ public void testSetterGetter() { .setBus("busA") .setMaxP(9999.99d) .setMinP(-9999.99d) - .setP0(15.0d) - .setQ0(-15.0d) + .setTargetP(15.0d) + .setTargetQ(-15.0d) .setEnsureIdUnicity(true) .add(); @@ -47,12 +47,12 @@ public void testSetterGetter() { assertSame(mergingView, battery.getNetwork()); assertEquals("BATEST", battery.getId()); assertTrue(battery.isFictitious()); - assertEquals(15.0d, battery.getP0(), delta); - assertNotNull(battery.setP0(0.0d)); - assertEquals(0.0d, battery.getP0(), delta); - assertEquals(-15.0d, battery.getQ0(), delta); - assertNotNull(battery.setQ0(0.0d)); - assertEquals(0.0d, battery.getQ0(), delta); + assertEquals(15.0d, battery.getTargetP(), delta); + assertNotNull(battery.setTargetP(0.0d)); + assertEquals(0.0d, battery.getTargetP(), delta); + assertEquals(-15.0d, battery.getTargetQ(), delta); + assertNotNull(battery.setTargetQ(0.0d)); + assertEquals(0.0d, battery.getTargetQ(), delta); assertEquals(-9999.99d, battery.getMinP(), delta); assertNotNull(battery.setMinP(-9999.95d)); assertEquals(-9999.95d, battery.getMinP(), delta); diff --git a/iidm/iidm-mergingview/src/test/java/com/powsybl/iidm/mergingview/VoltageLevelAdapterTest.java b/iidm/iidm-mergingview/src/test/java/com/powsybl/iidm/mergingview/VoltageLevelAdapterTest.java index 85ab6577ec1..135d4e2f9bb 100644 --- a/iidm/iidm-mergingview/src/test/java/com/powsybl/iidm/mergingview/VoltageLevelAdapterTest.java +++ b/iidm/iidm-mergingview/src/test/java/com/powsybl/iidm/mergingview/VoltageLevelAdapterTest.java @@ -85,8 +85,8 @@ public void baseTests() { .setBus("busA") .setMaxP(9999.99) .setMinP(-9999.99) - .setP0(15) - .setQ0(-15) + .setTargetP(15) + .setTargetQ(-15) .add(); vlActual.getBatteries().forEach(b -> { assertTrue(b instanceof BatteryAdapter); diff --git a/iidm/iidm-scripting/src/main/groovy/com/powsybl/iidm/network/scripting/BatteryAdderExtension.groovy b/iidm/iidm-scripting/src/main/groovy/com/powsybl/iidm/network/scripting/BatteryAdderExtension.groovy new file mode 100644 index 00000000000..a6c313f2086 --- /dev/null +++ b/iidm/iidm-scripting/src/main/groovy/com/powsybl/iidm/network/scripting/BatteryAdderExtension.groovy @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2022, 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.iidm.network.scripting + +import com.powsybl.iidm.network.BatteryAdder + +/** + * @author Miora VEDELAGO + */ +class BatteryAdderExtension { + static BatteryAdder setP0(BatteryAdder self, double p0) { + self.setTargetP(p0) + } + + static BatteryAdder setQ0(BatteryAdder self, double q0) { + self.setTargetQ(q0) + } +} diff --git a/iidm/iidm-scripting/src/main/groovy/com/powsybl/iidm/network/scripting/BatteryExtension.groovy b/iidm/iidm-scripting/src/main/groovy/com/powsybl/iidm/network/scripting/BatteryExtension.groovy new file mode 100644 index 00000000000..928082aa306 --- /dev/null +++ b/iidm/iidm-scripting/src/main/groovy/com/powsybl/iidm/network/scripting/BatteryExtension.groovy @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2022, 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.iidm.network.scripting + +import com.powsybl.iidm.network.Battery + +/** + * @author Miora VEDELAGO + */ +class BatteryExtension { + static double getP0(Battery self) { + self.getTargetP() + } + + static Battery setP0(Battery self, double p0) { + self.setTargetP(p0) + } + + static double getQ0(Battery self) { + self.getTargetQ() + } + + static Battery setQ0(Battery self, double q0) { + self.setTargetQ(q0) + } +} diff --git a/iidm/iidm-scripting/src/main/resources/META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule b/iidm/iidm-scripting/src/main/resources/META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule index 21e0386d7ca..815d85e8c46 100644 --- a/iidm/iidm-scripting/src/main/resources/META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule +++ b/iidm/iidm-scripting/src/main/resources/META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule @@ -1,3 +1,3 @@ moduleName = powsybl-iidm-scripting-module moduleVersion = 1.0 -extensionClasses = com.powsybl.iidm.network.scripting.IdentifiableExtension com.powsybl.iidm.network.scripting.NetworkExtension com.powsybl.iidm.network.scripting.SubstationExtension com.powsybl.iidm.network.scripting.ShuntCompensatorExtension com.powsybl.iidm.network.scripting.VoltageLevelExtension com.powsybl.iidm.network.scripting.TwoWindingsTransformerExtension com.powsybl.iidm.network.scripting.ThreeWindingsTransformerExtension +extensionClasses = com.powsybl.iidm.network.scripting.IdentifiableExtension com.powsybl.iidm.network.scripting.NetworkExtension com.powsybl.iidm.network.scripting.SubstationExtension com.powsybl.iidm.network.scripting.ShuntCompensatorExtension com.powsybl.iidm.network.scripting.VoltageLevelExtension com.powsybl.iidm.network.scripting.TwoWindingsTransformerExtension com.powsybl.iidm.network.scripting.ThreeWindingsTransformerExtension com.powsybl.iidm.network.scripting.BatteryAdderExtension com.powsybl.iidm.network.scripting.BatteryExtension diff --git a/iidm/iidm-scripting/src/test/groovy/com/powsybl/iidm/network/scripting/BatteryExtensionTest.groovy b/iidm/iidm-scripting/src/test/groovy/com/powsybl/iidm/network/scripting/BatteryExtensionTest.groovy new file mode 100644 index 00000000000..28888fdf9d9 --- /dev/null +++ b/iidm/iidm-scripting/src/test/groovy/com/powsybl/iidm/network/scripting/BatteryExtensionTest.groovy @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2022, 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.iidm.network.scripting + +import com.powsybl.iidm.network.* +import org.junit.Test + +import static org.junit.Assert.assertEquals +import static org.junit.Assert.assertNotNull + +/** + * @author Miora VEDELAGO + */ +class BatteryExtensionTest { + + @Test + void test() { + Network network = Network.create("test", "test") + Substation substation = network.newSubstation() + .setCountry(Country.AF) + .setTso("tso") + .setName("sub") + .setId("subId") + .add(); + VoltageLevel voltageLevel = substation.newVoltageLevel() + .setTopologyKind(TopologyKind.BUS_BREAKER) + .setId("bbVL") + .setName("bbVL_name") + .setNominalV(200.0f) + .add() + Bus bus = voltageLevel.getBusBreakerView() + .newBus() + .setName("Bus1") + .setId("Bus1") + .add() + Battery b = voltageLevel.newBattery().setP0(10.0).setQ0(5.0).setId("B").setBus("Bus1").setMinP(-Double.MAX_VALUE).setMaxP(Double.MAX_VALUE).add() + assertNotNull(b) + assertEquals(10.0, b.p0, 0.0) + assertEquals(10.0, b.getP0(), 0.0) + assertEquals(5.0, b.q0, 0.0) + assertEquals(5.0, b.getQ0(), 0.0) + } +} diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractBatteryTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractBatteryTest.java index 6da7b197a35..73cd2fbb38a 100644 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractBatteryTest.java +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractBatteryTest.java @@ -48,12 +48,12 @@ public void testSetterGetter() { Battery battery = network.getBattery("BAT"); assertNotNull(battery); - double p0 = 11.0; - battery.setP0(p0); - assertEquals(p0, battery.getP0(), 0.0); - double q0 = 12.0; - battery.setQ0(q0); - assertEquals(q0, battery.getQ0(), 0.0); + double targetP = 11.0; + battery.setTargetP(targetP); + assertEquals(targetP, battery.getTargetP(), 0.0); + double targetQ = 12.0; + battery.setTargetQ(targetQ); + assertEquals(targetQ, battery.getTargetQ(), 0.0); double minP = 10.0; battery.setMinP(minP); assertEquals(minP, battery.getMinP(), 0.0); @@ -122,8 +122,8 @@ public void testAdder() { .setId(BAT_ID) .setMaxP(20.0) .setMinP(10.0) - .setP0(15.0) - .setQ0(10.0) + .setTargetP(15.0) + .setTargetQ(10.0) .setBus("NBAT") .add(); Battery battery = network.getBattery(BAT_ID); @@ -131,8 +131,8 @@ public void testAdder() { assertEquals(BAT_ID, battery.getId()); assertEquals(20.0, battery.getMaxP(), 0.0); assertEquals(10.0, battery.getMinP(), 0.0); - assertEquals(15.0, battery.getP0(), 0.0); - assertEquals(10.0, battery.getQ0(), 0.0); + assertEquals(15.0, battery.getTargetP(), 0.0); + assertEquals(10.0, battery.getTargetQ(), 0.0); } @Test @@ -242,11 +242,11 @@ public void testSetterGetterInMultiVariants() { variantManager.setWorkingVariant("s4"); // check values cloned by extend - assertEquals(11.0, battery.getP0(), 0.0); - assertEquals(12.0, battery.getQ0(), 0.0); + assertEquals(11.0, battery.getTargetP(), 0.0); + assertEquals(12.0, battery.getTargetQ(), 0.0); // change values in s4 - battery.setP0(11.1); - battery.setQ0(12.2); + battery.setTargetP(11.1); + battery.setTargetQ(12.2); // remove s2 variantManager.removeVariant("s2"); @@ -254,30 +254,30 @@ public void testSetterGetterInMultiVariants() { variantManager.cloneVariant("s4", "s2b"); variantManager.setWorkingVariant("s2b"); // check values cloned by allocate - assertEquals(11.1, battery.getP0(), 0.0); - assertEquals(12.2, battery.getQ0(), 0.0); + assertEquals(11.1, battery.getTargetP(), 0.0); + assertEquals(12.2, battery.getTargetQ(), 0.0); // recheck initial variant value variantManager.setWorkingVariant(VariantManagerConstants.INITIAL_VARIANT_ID); - assertEquals(11.0, battery.getP0(), 0.0); - assertEquals(12.0, battery.getQ0(), 0.0); + assertEquals(11.0, battery.getTargetP(), 0.0); + assertEquals(12.0, battery.getTargetQ(), 0.0); // remove working variant s4 variantManager.setWorkingVariant("s4"); variantManager.removeVariant("s4"); try { - battery.getP0(); + battery.getTargetP(); fail(); } catch (Exception ignored) { // ignore } } - private void createBattery(String id, double p0, double q0, double minP, double maxP) { + private void createBattery(String id, double targetP, double targetQ, double minP, double maxP) { voltageLevel.newBattery() .setId(id) - .setP0(p0) - .setQ0(q0) + .setTargetP(targetP) + .setTargetQ(targetQ) .setMinP(minP) .setMaxP(maxP) .setBus("NBAT") diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractNetworkTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractNetworkTest.java index d68d4fcd862..c9086620069 100644 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractNetworkTest.java +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractNetworkTest.java @@ -323,8 +323,8 @@ public void testNetworkWithBattery() { Battery battery1 = network.getBattery("BAT"); assertNotNull(battery1); assertEquals("BAT", battery1.getId()); - assertEquals(9999.99, battery1.getP0(), 0.0); - assertEquals(9999.99, battery1.getQ0(), 0.0); + assertEquals(9999.99, battery1.getTargetP(), 0.0); + assertEquals(9999.99, battery1.getTargetQ(), 0.0); assertEquals(-9999.99, battery1.getMinP(), 0.0); assertEquals(9999.99, battery1.getMaxP(), 0.0); assertEquals(bus2.getId(), battery1.getTerminal().getBusBreakerView().getBus().getId()); @@ -332,8 +332,8 @@ public void testNetworkWithBattery() { Battery battery2 = network.getBattery("BAT2"); assertNotNull(battery2); assertEquals("BAT2", battery2.getId()); - assertEquals(100, battery2.getP0(), 0.0); - assertEquals(200, battery2.getQ0(), 0.0); + assertEquals(100, battery2.getTargetP(), 0.0); + assertEquals(200, battery2.getTargetQ(), 0.0); assertEquals(-200, battery2.getMinP(), 0.0); assertEquals(200, battery2.getMaxP(), 0.0); assertEquals(bus2.getId(), battery2.getTerminal().getBusBreakerView().getBus().getId()); diff --git a/iidm/iidm-test/src/main/java/com/powsybl/iidm/network/test/BatteryNetworkFactory.java b/iidm/iidm-test/src/main/java/com/powsybl/iidm/network/test/BatteryNetworkFactory.java index 4b5e47976ce..6b99a1865c6 100644 --- a/iidm/iidm-test/src/main/java/com/powsybl/iidm/network/test/BatteryNetworkFactory.java +++ b/iidm/iidm-test/src/main/java/com/powsybl/iidm/network/test/BatteryNetworkFactory.java @@ -122,8 +122,8 @@ public static Network create(NetworkFactory networkFactory) { .setId("BAT") .setBus(nbat.getId()) .setConnectableBus(nbat.getId()) - .setP0(9999.99) - .setQ0(9999.99) + .setTargetP(9999.99) + .setTargetQ(9999.99) .setMinP(-9999.99) .setMaxP(9999.99) .add(); @@ -137,8 +137,8 @@ public static Network create(NetworkFactory networkFactory) { .setId("BAT2") .setBus(nbat.getId()) .setConnectableBus(nbat.getId()) - .setP0(100) - .setQ0(200) + .setTargetP(100) + .setTargetQ(200) .setMinP(-200) .setMaxP(200) .add(); diff --git a/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/BatteryXml.java b/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/BatteryXml.java index e24879b1aa3..3b32df90e0c 100644 --- a/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/BatteryXml.java +++ b/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/BatteryXml.java @@ -10,6 +10,7 @@ import com.powsybl.iidm.network.Battery; import com.powsybl.iidm.network.BatteryAdder; import com.powsybl.iidm.network.VoltageLevel; +import com.powsybl.iidm.xml.util.IidmXmlUtil; import javax.xml.stream.XMLStreamException; @@ -34,8 +35,10 @@ protected boolean hasSubElements(Battery b) { @Override protected void writeRootElementAttributes(Battery b, VoltageLevel vl, NetworkXmlWriterContext context) throws XMLStreamException { - XmlUtil.writeDouble("p0", b.getP0(), context.getWriter()); - XmlUtil.writeDouble("q0", b.getQ0(), context.getWriter()); + XmlUtil.writeDouble(IidmXmlUtil.getAttributeName("p0", "targetP", context.getVersion(), IidmXmlVersion.V_1_8), + b.getTargetP(), context.getWriter()); + XmlUtil.writeDouble(IidmXmlUtil.getAttributeName("q0", "targetQ", context.getVersion(), IidmXmlVersion.V_1_8), + b.getTargetQ(), context.getWriter()); XmlUtil.writeDouble("minP", b.getMinP(), context.getWriter()); XmlUtil.writeDouble("maxP", b.getMaxP(), context.getWriter()); writeNodeOrBus(null, b.getTerminal(), context); @@ -54,13 +57,15 @@ protected BatteryAdder createAdder(VoltageLevel vl) { @Override protected Battery readRootElementAttributes(BatteryAdder adder, NetworkXmlReaderContext context) { - double p0 = XmlUtil.readOptionalDoubleAttribute(context.getReader(), "p0"); - double q0 = XmlUtil.readOptionalDoubleAttribute(context.getReader(), "q0"); + double targetP = XmlUtil.readOptionalDoubleAttribute(context.getReader(), + IidmXmlUtil.getAttributeName("p0", "targetP", context.getVersion(), IidmXmlVersion.V_1_8)); + double targetQ = XmlUtil.readOptionalDoubleAttribute(context.getReader(), + IidmXmlUtil.getAttributeName("q0", "targetQ", context.getVersion(), IidmXmlVersion.V_1_8)); double minP = XmlUtil.readDoubleAttribute(context.getReader(), "minP"); double maxP = XmlUtil.readDoubleAttribute(context.getReader(), "maxP"); readNodeOrBus(adder, context); - Battery b = adder.setP0(p0) - .setQ0(q0) + Battery b = adder.setTargetP(targetP) + .setTargetQ(targetQ) .setMinP(minP) .setMaxP(maxP) .add(); diff --git a/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/util/IidmXmlUtil.java b/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/util/IidmXmlUtil.java index 44bcee08580..eaa3987f13f 100644 --- a/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/util/IidmXmlUtil.java +++ b/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/util/IidmXmlUtil.java @@ -350,6 +350,18 @@ public static void writeIntAttributeUntilMaximumVersion(String attributeName, in } } + /** + * Get an attribute name depending on IIDM-XML version. + * @return oldName if version strictly older than comparisonVersion, else newName. + */ + public static String getAttributeName(String oldName, String newName, IidmXmlVersion version, IidmXmlVersion comparisonVersion) { + if (version.compareTo(comparisonVersion) < 0) { + return oldName; + } else { + return newName; + } + } + /** * Sort identifiables by their ids. */ diff --git a/iidm/iidm-xml-converter/src/main/resources/xsd/iidm_V1_8.xsd b/iidm/iidm-xml-converter/src/main/resources/xsd/iidm_V1_8.xsd index 2ec29c77fcf..aa94f459dfc 100644 --- a/iidm/iidm-xml-converter/src/main/resources/xsd/iidm_V1_8.xsd +++ b/iidm/iidm-xml-converter/src/main/resources/xsd/iidm_V1_8.xsd @@ -260,8 +260,8 @@ - - + + diff --git a/iidm/iidm-xml-converter/src/main/resources/xsd/iidm_equipment_V1_8.xsd b/iidm/iidm-xml-converter/src/main/resources/xsd/iidm_equipment_V1_8.xsd index 9f76811f269..9b898353961 100644 --- a/iidm/iidm-xml-converter/src/main/resources/xsd/iidm_equipment_V1_8.xsd +++ b/iidm/iidm-xml-converter/src/main/resources/xsd/iidm_equipment_V1_8.xsd @@ -260,8 +260,8 @@ - - + + diff --git a/iidm/iidm-xml-converter/src/test/resources/V1_8/activePowerControlRoundTripRef.xml b/iidm/iidm-xml-converter/src/test/resources/V1_8/activePowerControlRoundTripRef.xml index ae5f64aa586..18128f16b94 100644 --- a/iidm/iidm-xml-converter/src/test/resources/V1_8/activePowerControlRoundTripRef.xml +++ b/iidm/iidm-xml-converter/src/test/resources/V1_8/activePowerControlRoundTripRef.xml @@ -15,10 +15,10 @@ - + - + diff --git a/iidm/iidm-xml-converter/src/test/resources/V1_8/batteryRoundTripRef.xml b/iidm/iidm-xml-converter/src/test/resources/V1_8/batteryRoundTripRef.xml index ff1835dd797..b1a5829d9d5 100644 --- a/iidm/iidm-xml-converter/src/test/resources/V1_8/batteryRoundTripRef.xml +++ b/iidm/iidm-xml-converter/src/test/resources/V1_8/batteryRoundTripRef.xml @@ -15,10 +15,10 @@ - + - + diff --git a/iidm/iidm-xml-converter/src/test/resources/V1_8/branchObservabilityRoundTripRef.xml b/iidm/iidm-xml-converter/src/test/resources/V1_8/branchObservabilityRoundTripRef.xml index 4a381f874f0..adbeb55386c 100644 --- a/iidm/iidm-xml-converter/src/test/resources/V1_8/branchObservabilityRoundTripRef.xml +++ b/iidm/iidm-xml-converter/src/test/resources/V1_8/branchObservabilityRoundTripRef.xml @@ -15,10 +15,10 @@ - + - + diff --git a/iidm/iidm-xml-converter/src/test/resources/V1_8/branchObservabilityRoundTripRefInvalid.xml b/iidm/iidm-xml-converter/src/test/resources/V1_8/branchObservabilityRoundTripRefInvalid.xml index e7f5740a818..53467d2326b 100644 --- a/iidm/iidm-xml-converter/src/test/resources/V1_8/branchObservabilityRoundTripRefInvalid.xml +++ b/iidm/iidm-xml-converter/src/test/resources/V1_8/branchObservabilityRoundTripRefInvalid.xml @@ -15,10 +15,10 @@ - + - + diff --git a/iidm/iidm-xml-converter/src/test/resources/V1_8/injectionObservabilityRoundTripRef.xml b/iidm/iidm-xml-converter/src/test/resources/V1_8/injectionObservabilityRoundTripRef.xml index 45a5fe2dcc8..86ef8a67931 100644 --- a/iidm/iidm-xml-converter/src/test/resources/V1_8/injectionObservabilityRoundTripRef.xml +++ b/iidm/iidm-xml-converter/src/test/resources/V1_8/injectionObservabilityRoundTripRef.xml @@ -15,10 +15,10 @@ - + - + diff --git a/iidm/iidm-xml-converter/src/test/resources/V1_8/injectionObservabilityRoundTripRefInvalid.xml b/iidm/iidm-xml-converter/src/test/resources/V1_8/injectionObservabilityRoundTripRefInvalid.xml index bf5a2ddbc94..70440663a39 100644 --- a/iidm/iidm-xml-converter/src/test/resources/V1_8/injectionObservabilityRoundTripRefInvalid.xml +++ b/iidm/iidm-xml-converter/src/test/resources/V1_8/injectionObservabilityRoundTripRefInvalid.xml @@ -15,10 +15,10 @@ - + - +