From a4cf99afcdeba80abf6659d79cffe7c3fac2114f Mon Sep 17 00:00:00 2001 From: CARON Alice Date: Mon, 13 Jan 2025 09:20:20 +0100 Subject: [PATCH] Allow standByAutomaton extension to have inconsistent voltage thresholds if not in stand by Signed-off-by: CARON Alice --- .../impl/extensions/StandbyAutomatonImpl.java | 32 ++++++++++++------- .../AbstractStandbyAutomatonTest.java | 8 +++-- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/StandbyAutomatonImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/StandbyAutomatonImpl.java index c4ecc9f75bb..1eb8ebc897e 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/StandbyAutomatonImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/StandbyAutomatonImpl.java @@ -38,7 +38,7 @@ private static double checkB0(double b0) { private static void checkVoltageConfig(double lowVoltageSetpoint, double highVoltageSetpoint, double lowVoltageThreshold, double highVoltageThreshold, - StaticVarCompensator staticVarCompensator) { + StaticVarCompensator staticVarCompensator, boolean standby) { if (Double.isNaN(lowVoltageSetpoint)) { throw new IllegalArgumentException( String.format("lowVoltageSetpoint (%s) is invalid for StaticVarCompensator %s", @@ -64,11 +64,17 @@ private static void checkVoltageConfig(double lowVoltageSetpoint, double highVol staticVarCompensator.getId())); } if (lowVoltageThreshold >= highVoltageThreshold) { - throw new IllegalArgumentException( - String.format("Inconsistent low (%s) and high (%s) voltage thresholds for StaticVarCompensator %s", - lowVoltageThreshold, - highVoltageThreshold, - staticVarCompensator.getId())); + if (standby) { + throw new IllegalArgumentException( + String.format("Inconsistent low (%s) and high (%s) voltage thresholds for StaticVarCompensator %s", + lowVoltageThreshold, + highVoltageThreshold, + staticVarCompensator.getId())); + } else { + LOGGER.warn("Inconsistent low {} and high ({}) voltage thresholds for StaticVarCompensator {}", + lowVoltageSetpoint, lowVoltageThreshold, + staticVarCompensator.getId()); + } } if (lowVoltageSetpoint < lowVoltageThreshold) { LOGGER.warn("Invalid low voltage setpoint {} < threshold {} for StaticVarCompensator {}", @@ -86,7 +92,7 @@ public StandbyAutomatonImpl(StaticVarCompensator svc, double b0, boolean standby double lowVoltageThreshold, double highVoltageThreshold) { super(svc); int variantArraySize = getVariantManagerHolder().getVariantManager().getVariantArraySize(); - checkVoltageConfig(lowVoltageSetpoint, highVoltageSetpoint, lowVoltageThreshold, highVoltageThreshold, svc); + checkVoltageConfig(lowVoltageSetpoint, highVoltageSetpoint, lowVoltageThreshold, highVoltageThreshold, svc, standby); this.b0 = checkB0(b0); this.standby = new TBooleanArrayList(variantArraySize); this.lowVoltageSetpoint = new TDoubleArrayList(variantArraySize); @@ -109,6 +115,10 @@ public boolean isStandby() { @Override public StandbyAutomatonImpl setStandby(boolean standby) { + checkVoltageConfig( + lowVoltageSetpoint.get(getVariantIndex()), highVoltageSetpoint.get(getVariantIndex()), + lowVoltageThreshold.get(getVariantIndex()), highVoltageThreshold.get(getVariantIndex()), + this.getExtendable(), standby); this.standby.set(getVariantIndex(), standby); return this; } @@ -133,7 +143,7 @@ public double getHighVoltageSetpoint() { public StandbyAutomatonImpl setHighVoltageSetpoint(double highVoltageSetpoint) { checkVoltageConfig(lowVoltageSetpoint.get(getVariantIndex()), highVoltageSetpoint, lowVoltageThreshold.get(getVariantIndex()), highVoltageThreshold.get(getVariantIndex()), - this.getExtendable()); + this.getExtendable(), standby.get(getVariantIndex())); this.highVoltageSetpoint.set(getVariantIndex(), highVoltageSetpoint); return this; } @@ -147,7 +157,7 @@ public double getHighVoltageThreshold() { public StandbyAutomatonImpl setHighVoltageThreshold(double highVoltageThreshold) { checkVoltageConfig(lowVoltageSetpoint.get(getVariantIndex()), highVoltageSetpoint.get(getVariantIndex()), lowVoltageThreshold.get(getVariantIndex()), highVoltageThreshold, - this.getExtendable()); + this.getExtendable(), standby.get(getVariantIndex())); this.highVoltageThreshold.set(getVariantIndex(), highVoltageThreshold); return this; } @@ -161,7 +171,7 @@ public double getLowVoltageSetpoint() { public StandbyAutomatonImpl setLowVoltageSetpoint(double lowVoltageSetpoint) { checkVoltageConfig(lowVoltageSetpoint, highVoltageSetpoint.get(getVariantIndex()), lowVoltageThreshold.get(getVariantIndex()), highVoltageThreshold.get(getVariantIndex()), - this.getExtendable()); + this.getExtendable(), standby.get(getVariantIndex())); this.lowVoltageSetpoint.set(getVariantIndex(), lowVoltageSetpoint); return this; } @@ -175,7 +185,7 @@ public double getLowVoltageThreshold() { public StandbyAutomatonImpl setLowVoltageThreshold(double lowVoltageThreshold) { checkVoltageConfig(lowVoltageSetpoint.get(getVariantIndex()), highVoltageSetpoint.get(getVariantIndex()), lowVoltageThreshold, highVoltageThreshold.get(getVariantIndex()), - this.getExtendable()); + this.getExtendable(), standby.get(getVariantIndex())); this.lowVoltageThreshold.set(getVariantIndex(), lowVoltageThreshold); return this; } diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractStandbyAutomatonTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractStandbyAutomatonTest.java index 8c0d5b86470..a857bab83d1 100644 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractStandbyAutomatonTest.java +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractStandbyAutomatonTest.java @@ -48,8 +48,6 @@ public void test() { assertEquals(405, standbyAutomaton.getHighVoltageThreshold(), 0.0); standbyAutomaton.setB0(0.0002f); assertEquals(0.0002f, standbyAutomaton.getB0(), 0.0); - standbyAutomaton.setStandby(false); - assertFalse(standbyAutomaton.isStandby()); standbyAutomaton.setLowVoltageSetpoint(391f); assertEquals(391, standbyAutomaton.getLowVoltageSetpoint(), 0.0); standbyAutomaton.setHighVoltageSetpoint(401f); @@ -68,6 +66,12 @@ public void test() { fail(); } catch (Exception ignored) { } + + // when standby is false do not throw error on inconsistent low and high voltage thresholds use case + standbyAutomaton.setStandby(false); + assertFalse(standbyAutomaton.isStandby()); + standbyAutomaton.setHighVoltageThreshold(200f); + assertEquals(200f, standbyAutomaton.getHighVoltageThreshold(), 0.0); } @Test