From 1035fca3da2204960823d467bf6ccdd9108a8750 Mon Sep 17 00:00:00 2001 From: stojkovicn Date: Wed, 15 May 2024 17:42:05 +0200 Subject: [PATCH] SVC and Shunt export change after review (#2920). Signed-off-by: stojkovicn --- .../conversion/export/CgmesExportContext.java | 9 ++++-- .../conversion/export/EquipmentExport.java | 13 ++------ .../export/SteadyStateHypothesisExport.java | 9 +++--- .../test/export/EquipmentExportTest.java | 31 ++++++++++++++---- .../SteadyStateHypothesisExportTest.java | 32 +++++++++++++++---- .../network/test/ShuntTestCaseFactory.java | 23 +++++++++++++ 6 files changed, 85 insertions(+), 32 deletions(-) diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/CgmesExportContext.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/CgmesExportContext.java index ce2b52d5635..ad68c816ad0 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/CgmesExportContext.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/CgmesExportContext.java @@ -523,7 +523,7 @@ private void addIidmMappingsShuntCompensators(Network network) { continue; } String regulatingControlId = shuntCompensator.getProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + REGULATING_CONTROL); - if (regulatingControlId == null && (shuntCompensator.isVoltageRegulatorOn() || !Objects.equals(shuntCompensator, shuntCompensator.getRegulatingTerminal().getConnectable()))) { + if (regulatingControlId == null && SteadyStateHypothesisExport.isValidVoltageSetpoint(shuntCompensator.getTargetV())) { regulatingControlId = namingStrategy.getCgmesId(ref(shuntCompensator), Part.REGULATING_CONTROL); shuntCompensator.setProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + REGULATING_CONTROL, regulatingControlId); } @@ -533,7 +533,12 @@ private void addIidmMappingsShuntCompensators(Network network) { private void addIidmMappingsStaticVarCompensators(Network network) { for (StaticVarCompensator svc : network.getStaticVarCompensators()) { String regulatingControlId = svc.getProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + REGULATING_CONTROL); - if (regulatingControlId == null && (StaticVarCompensator.RegulationMode.VOLTAGE.equals(svc.getRegulationMode()) || !Objects.equals(svc, svc.getRegulatingTerminal().getConnectable()))) { + boolean validVoltageSetpoint = SteadyStateHypothesisExport.isValidVoltageSetpoint(svc.getVoltageSetpoint()); + boolean validReactiveSetpoint = SteadyStateHypothesisExport.isValidReactivePowerSetpoint(svc.getReactivePowerSetpoint()); + if (regulatingControlId == null && ( + svc.getRegulationMode() == StaticVarCompensator.RegulationMode.VOLTAGE || + svc.getRegulationMode() == StaticVarCompensator.RegulationMode.REACTIVE_POWER || + validVoltageSetpoint && !validReactiveSetpoint || !validVoltageSetpoint && validReactiveSetpoint)) { regulatingControlId = namingStrategy.getCgmesId(ref(svc), Part.REGULATING_CONTROL); svc.setProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + REGULATING_CONTROL, regulatingControlId); } diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/EquipmentExport.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/EquipmentExport.java index 2baf0032b74..071531cc14a 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/EquipmentExport.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/EquipmentExport.java @@ -616,24 +616,15 @@ private static void writeStaticVarCompensators(Network network, Map 0; - } - - private static boolean isValidSvcReactivePowerSetpoint(double q) { - return Double.isFinite(q); - } - private static void writeLines(Network network, Map mapTerminal2Id, String cimNamespace, String euNamespace, String valueAttributeName, String limitTypeAttributeName, String limitKindClassName, boolean writeInfiniteDuration, XMLStreamWriter writer, CgmesExportContext context) throws XMLStreamException { for (Line line : network.getLines()) { String baseVoltage = null; diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/SteadyStateHypothesisExport.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/SteadyStateHypothesisExport.java index e8aeea4fa25..8da215c003d 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/SteadyStateHypothesisExport.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/SteadyStateHypothesisExport.java @@ -389,11 +389,11 @@ private static void addRegulatingControlView(Generator g, Map 0; } - private static boolean isValidSvcReactivePowerSetpoint(double q) { + public static boolean isValidReactivePowerSetpoint(double q) { return Double.isFinite(q); } @@ -418,13 +418,12 @@ private static void writeStaticVarCompensators(Network network, String cimNamesp // Regulating control could be reactive power or voltage double targetValue; String multiplier; - // FIXME: remove RegulationMode.OFF when #2790 is done if (regulationMode == StaticVarCompensator.RegulationMode.VOLTAGE - || regulationMode == StaticVarCompensator.RegulationMode.OFF && isValidSvcVolatgeSetpoint(svc.getVoltageSetpoint()) && !isValidSvcReactivePowerSetpoint(svc.getReactivePowerSetpoint())) { + || regulationMode == StaticVarCompensator.RegulationMode.OFF && isValidVoltageSetpoint(svc.getVoltageSetpoint()) && !isValidReactivePowerSetpoint(svc.getReactivePowerSetpoint())) { targetValue = svc.getVoltageSetpoint(); multiplier = "k"; } else if (regulationMode == StaticVarCompensator.RegulationMode.REACTIVE_POWER - || regulationMode == StaticVarCompensator.RegulationMode.OFF && isValidSvcReactivePowerSetpoint(svc.getReactivePowerSetpoint()) && !isValidSvcVolatgeSetpoint(svc.getVoltageSetpoint())) { + || regulationMode == StaticVarCompensator.RegulationMode.OFF && isValidReactivePowerSetpoint(svc.getReactivePowerSetpoint()) && !isValidVoltageSetpoint(svc.getVoltageSetpoint())) { targetValue = svc.getReactivePowerSetpoint(); multiplier = "M"; } else { diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/EquipmentExportTest.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/EquipmentExportTest.java index 136193e9097..8bcb91b961c 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/EquipmentExportTest.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/EquipmentExportTest.java @@ -1128,7 +1128,7 @@ void staticVarCompensatorRegulatingControlEQTest() throws IOException { // Local network = SvcTestCaseFactory.createLocalReactiveControl(); eq = getEQ(network, baseName, tmpDir, exportParams); - testRcEqRCWithoutAttribute(eq, "_SVC2_RC", "_SVC2_SVC_T_1", "reactivePower"); + testRcEqRcWithAttribute(eq, "_SVC2_RC", "_SVC2_SVC_T_1", "reactivePower"); // Remote network = SvcTestCaseFactory.createRemoteReactiveControl(); @@ -1142,10 +1142,10 @@ void staticVarCompensatorRegulatingControlEQTest() throws IOException { testRcEqRCWithoutAttribute(eq, "_SVC2_RC", "_SVC2_SVC_T_1", "dummy"); network = SvcTestCaseFactory.createLocalOffReactiveTarget(); eq = getEQ(network, baseName, tmpDir, exportParams); - testRcEqRCWithoutAttribute(eq, "_SVC2_RC", "_SVC2_SVC_T_1", "dummy"); + testRcEqRcWithAttribute(eq, "_SVC2_RC", "_SVC2_SVC_T_1", "reactivePower"); network = SvcTestCaseFactory.createLocalOffVoltageTarget(); eq = getEQ(network, baseName, tmpDir, exportParams); - testRcEqRCWithoutAttribute(eq, "_SVC2_RC", "_SVC2_SVC_T_1", "dummy"); + testRcEqRcWithAttribute(eq, "_SVC2_RC", "_SVC2_SVC_T_1", "voltage"); network = SvcTestCaseFactory.createLocalOffBothTarget(); eq = getEQ(network, baseName, tmpDir, exportParams); testRcEqRCWithoutAttribute(eq, "_SVC2_RC", "_SVC2_SVC_T_1", "dummy"); @@ -1153,7 +1153,7 @@ void staticVarCompensatorRegulatingControlEQTest() throws IOException { // Remote network = SvcTestCaseFactory.createRemoteOffNoTarget(); eq = getEQ(network, baseName, tmpDir, exportParams); - testRcEqRcWithAttribute(eq, "_SVC2_RC", "_L2_EC_T_1", "voltage"); + testRcEqRCWithoutAttribute(eq, "_SVC2_RC", "_L2_EC_T_1", "dummy"); network = SvcTestCaseFactory.createRemoteOffReactiveTarget(); eq = getEQ(network, baseName, tmpDir, exportParams); testRcEqRcWithAttribute(eq, "_SVC2_RC", "_L2_EC_T_1", "reactivePower"); @@ -1162,7 +1162,7 @@ void staticVarCompensatorRegulatingControlEQTest() throws IOException { testRcEqRcWithAttribute(eq, "_SVC2_RC", "_L2_EC_T_1", "voltage"); network = SvcTestCaseFactory.createRemoteOffBothTarget(); eq = getEQ(network, baseName, tmpDir, exportParams); - testRcEqRcWithAttribute(eq, "_SVC2_RC", "_L2_EC_T_1", "voltage"); + testRcEqRCWithoutAttribute(eq, "_SVC2_RC", "_L2_EC_T_1", "dummy"); } } @@ -1195,7 +1195,16 @@ void shuntCompensatorRegulatingControlEQTest() throws IOException { network = ShuntTestCaseFactory.createDisabledLocalLinear(); eq = getEQ(network, baseName, tmpDir, exportParams); - testRcEqRCWithoutAttribute(eq, "_SHUNT_RC", "_SHUNT_SC_T_1", "voltage"); + testRcEqRcWithAttribute(eq, "_SHUNT_RC", "_SHUNT_SC_T_1", "voltage"); + testRcEqRCWithoutAttribute(eq, "", "", "reactivePower"); + + network = ShuntTestCaseFactory.createLocalLinearNoTarget(); + eq = getEQ(network, baseName, tmpDir, exportParams); + testRcEqRCWithoutAttribute(eq, "_SHUNT_RC", "", ""); + + network = ShuntTestCaseFactory.createRemoteLinearNoTarget(); + eq = getEQ(network, baseName, tmpDir, exportParams); + testRcEqRCWithoutAttribute(eq, "_SHUNT_RC", "", ""); // SC nonlinear network = ShuntTestCaseFactory.createNonLinear(); @@ -1215,7 +1224,15 @@ void shuntCompensatorRegulatingControlEQTest() throws IOException { network = ShuntTestCaseFactory.createDisabledLocalNonLinear(); eq = getEQ(network, baseName, tmpDir, exportParams); - testRcEqRCWithoutAttribute(eq, "_SHUNT_RC", "_SHUNT_SC_T_1", "voltage"); + testRcEqRcWithAttribute(eq, "_SHUNT_RC", "_SHUNT_SC_T_1", "voltage"); + + network = ShuntTestCaseFactory.createLocalNonLinearNoTarget(); + eq = getEQ(network, baseName, tmpDir, exportParams); + testRcEqRCWithoutAttribute(eq, "_SHUNT_RC", "", ""); + + network = ShuntTestCaseFactory.createRemoteNonLinearNoTarget(); + eq = getEQ(network, baseName, tmpDir, exportParams); + testRcEqRCWithoutAttribute(eq, "_SHUNT_RC", "", ""); } } diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/SteadyStateHypothesisExportTest.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/SteadyStateHypothesisExportTest.java index 8e772d73170..17e3a04e2fb 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/SteadyStateHypothesisExportTest.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/SteadyStateHypothesisExportTest.java @@ -539,7 +539,7 @@ void staticVarCompensatorRegulatingControlSSHTest() throws IOException { // Local network = SvcTestCaseFactory.createLocalReactiveControl(); ssh = getSSH(network, baseName, tmpDir, exportParams); - testRcEqRCWithoutAttribute(ssh, "_SVC2_RC"); + testRcEqRcWithAttribute(ssh, "_SVC2_RC", "false", "true", "0", "350", "M"); // Remote network = SvcTestCaseFactory.createRemoteReactiveControl(); @@ -553,10 +553,10 @@ void staticVarCompensatorRegulatingControlSSHTest() throws IOException { testRcEqRCWithoutAttribute(ssh, "_SVC2_RC"); network = SvcTestCaseFactory.createLocalOffReactiveTarget(); ssh = getSSH(network, baseName, tmpDir, exportParams); - testRcEqRCWithoutAttribute(ssh, "_SVC2_RC"); + testRcEqRcWithAttribute(ssh, "_SVC2_RC", "false", "false", "0", "350", "M"); network = SvcTestCaseFactory.createLocalOffVoltageTarget(); ssh = getSSH(network, baseName, tmpDir, exportParams); - testRcEqRCWithoutAttribute(ssh, "_SVC2_RC"); + testRcEqRcWithAttribute(ssh, "_SVC2_RC", "false", "false", "0", "390", "k"); network = SvcTestCaseFactory.createLocalOffBothTarget(); ssh = getSSH(network, baseName, tmpDir, exportParams); testRcEqRCWithoutAttribute(ssh, "_SVC2_RC"); @@ -564,7 +564,7 @@ void staticVarCompensatorRegulatingControlSSHTest() throws IOException { // Remote network = SvcTestCaseFactory.createRemoteOffNoTarget(); ssh = getSSH(network, baseName, tmpDir, exportParams); - testRcEqRcWithAttribute(ssh, "_SVC2_RC", "false", "false", "0", "0", "k"); + testRcEqRCWithoutAttribute(ssh, "_SVC2_RC"); network = SvcTestCaseFactory.createRemoteOffReactiveTarget(); ssh = getSSH(network, baseName, tmpDir, exportParams); testRcEqRcWithAttribute(ssh, "_SVC2_RC", "false", "false", "0", "350", "M"); @@ -573,7 +573,7 @@ void staticVarCompensatorRegulatingControlSSHTest() throws IOException { testRcEqRcWithAttribute(ssh, "_SVC2_RC", "false", "false", "0", "390", "k"); network = SvcTestCaseFactory.createRemoteOffBothTarget(); ssh = getSSH(network, baseName, tmpDir, exportParams); - testRcEqRcWithAttribute(ssh, "_SVC2_RC", "false", "false", "0", "0", "k"); + testRcEqRCWithoutAttribute(ssh, "_SVC2_RC"); } } @@ -606,7 +606,16 @@ void shuntCompensatorRegulatingControlSSHTest() throws IOException { network = ShuntTestCaseFactory.createDisabledLocalLinear(); ssh = getSSH(network, baseName, tmpDir, exportParams); - testRcEqRCWithoutAttribute(ssh, "_SHUNT_RC"); + testRcEqRcWithAttribute(ssh, "_SHUNT_RC", "true", "false", "5", "200", "k"); + testTcTccWithoutAttribute(ssh, "", "", "", "", "", "M"); + + network = ShuntTestCaseFactory.createLocalLinearNoTarget(); + ssh = getSSH(network, baseName, tmpDir, exportParams); + testTcTccWithoutAttribute(ssh, "_SHUNT_RC", "", "", "", "", ""); + + network = ShuntTestCaseFactory.createRemoteLinearNoTarget(); + ssh = getSSH(network, baseName, tmpDir, exportParams); + testTcTccWithoutAttribute(ssh, "_SHUNT_RC", "", "", "", "", ""); // SC nonlinear network = ShuntTestCaseFactory.createNonLinear(); @@ -626,7 +635,16 @@ void shuntCompensatorRegulatingControlSSHTest() throws IOException { network = ShuntTestCaseFactory.createDisabledLocalNonLinear(); ssh = getSSH(network, baseName, tmpDir, exportParams); - testRcEqRCWithoutAttribute(ssh, "_SHUNT_RC"); + testRcEqRcWithAttribute(ssh, "_SHUNT_RC", "true", "false", "5", "200", "k"); + testTcTccWithoutAttribute(ssh, "", "", "", "", "", "M"); + + network = ShuntTestCaseFactory.createLocalNonLinearNoTarget(); + ssh = getSSH(network, baseName, tmpDir, exportParams); + testTcTccWithoutAttribute(ssh, "_SHUNT_RC", "", "", "", "", ""); + + network = ShuntTestCaseFactory.createRemoteNonLinearNoTarget(); + ssh = getSSH(network, baseName, tmpDir, exportParams); + testTcTccWithoutAttribute(ssh, "_SHUNT_RC", "", "", "", "", ""); } } diff --git a/iidm/iidm-test/src/main/java/com/powsybl/iidm/network/test/ShuntTestCaseFactory.java b/iidm/iidm-test/src/main/java/com/powsybl/iidm/network/test/ShuntTestCaseFactory.java index 067cac9cfee..5793c6e837d 100644 --- a/iidm/iidm-test/src/main/java/com/powsybl/iidm/network/test/ShuntTestCaseFactory.java +++ b/iidm/iidm-test/src/main/java/com/powsybl/iidm/network/test/ShuntTestCaseFactory.java @@ -174,6 +174,29 @@ public static Network createDisabledShunt(Network network) { return network; } + private static Network createShuntWithNoTarget(Network network) { + network.getShuntCompensator(SHUNT) + .setVoltageRegulatorOn(false) + .setTargetV(Double.NaN); + return network; + } + + public static Network createRemoteLinearNoTarget() { + return createShuntWithNoTarget(create()); + } + + public static Network createRemoteNonLinearNoTarget() { + return createShuntWithNoTarget(createNonLinear()); + } + + public static Network createLocalLinearNoTarget() { + return createShuntWithNoTarget(createLocalLinear()); + } + + public static Network createLocalNonLinearNoTarget() { + return createShuntWithNoTarget(createLocalNonLinear()); + } + public static Network createLocalNonLinear() { return createLocalShunt(createNonLinear()); }