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 c00bbbcbe63..24e30c1c992 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 @@ -31,6 +31,7 @@ import com.powsybl.iidm.network.ThreeSides; import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; import com.powsybl.iidm.network.test.PhaseShifterTestCaseFactory; +import com.powsybl.iidm.network.test.SvcTestCaseFactory; import com.powsybl.iidm.network.test.ThreeWindingsTransformerNetworkFactory; import com.powsybl.iidm.serde.ExportOptions; import com.powsybl.iidm.serde.NetworkSerDe; @@ -1038,6 +1039,70 @@ void ratioTapChangerTapChangerControlEQTest() throws IOException { } } + @Test + void staticVarCompensatorRegulatingControlEQTest() throws IOException { + String exportFolder = "/test-svc-rc"; + String baseName = "testSvcRc"; + Network network; + String eq; + try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { + Path tmpDir = Files.createDirectory(fs.getPath(exportFolder)); + Properties exportParams = new Properties(); + exportParams.put(CgmesExport.PROFILES, "EQ"); + + // SVC VOLTAGE + // Local + network = SvcTestCaseFactory.createLocalVoltageControl(); + eq = getEQ(network, baseName, tmpDir, exportParams); + testRcEqRcWithAttribute(eq, "_SVC2_RC", "_SVC2_SVC_T_1", "voltage"); + + // Remote + network = SvcTestCaseFactory.createRemoteVoltageControl(); + eq = getEQ(network, baseName, tmpDir, exportParams); + testRcEqRcWithAttribute(eq, "_SVC2_RC", "_L2_EC_T_1", "voltage"); + + // SVC REACTIVE_POWER + // Local + network = SvcTestCaseFactory.createLocalReactiveControl(); + eq = getEQ(network, baseName, tmpDir, exportParams); + testRcEqRCWithoutAttribute(eq, "_SVC2_RC", "_SVC2_SVC_T_1", "reactivePower"); + + // Remote + network = SvcTestCaseFactory.createRemoteReactiveControl(); + eq = getEQ(network, baseName, tmpDir, exportParams); + testRcEqRcWithAttribute(eq, "_SVC2_RC", "_L2_EC_T_1", "reactivePower"); + + // SVC OFF + // Local + network = SvcTestCaseFactory.createLocalOffNoTarget(); + eq = getEQ(network, baseName, tmpDir, exportParams); + 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"); + network = SvcTestCaseFactory.createLocalOffVoltageTarget(); + eq = getEQ(network, baseName, tmpDir, exportParams); + testRcEqRCWithoutAttribute(eq, "_SVC2_RC", "_SVC2_SVC_T_1", "dummy"); + network = SvcTestCaseFactory.createLocalOffBothTarget(); + eq = getEQ(network, baseName, tmpDir, exportParams); + testRcEqRCWithoutAttribute(eq, "_SVC2_RC", "_SVC2_SVC_T_1", "dummy"); + + // Remote + network = SvcTestCaseFactory.createRemoteOffNoTarget(); + eq = getEQ(network, baseName, tmpDir, exportParams); + testRcEqRcWithAttribute(eq, "_SVC2_RC", "_L2_EC_T_1", "voltage"); + network = SvcTestCaseFactory.createRemoteOffReactiveTarget(); + eq = getEQ(network, baseName, tmpDir, exportParams); + testRcEqRcWithAttribute(eq, "_SVC2_RC", "_L2_EC_T_1", "reactivePower"); + network = SvcTestCaseFactory.createRemoteOffVoltageTarget(); + eq = getEQ(network, baseName, tmpDir, exportParams); + 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"); + } + } + private void testTcTccWithoutAttribute(String eq, String rcID, String terID, String rcMode) { assertFalse(eq.contains("cim:TapChangerControl rdf:ID=\"" + rcID + "\"")); assertFalse(eq.contains("cim:TapChanger.TapChangerControl rdf:resource=\"#" + rcID + "\"")); @@ -1052,6 +1117,21 @@ private void testTcTccWithAttribute(String eq, String rcID, String terID, String assertTrue(eq.contains("cim:RegulatingControl.Terminal rdf:resource=\"#" + terID + "\"")); } + private void testRcEqRCWithoutAttribute(String eq, String rcID, String terID, String rcMode) { + assertFalse(eq.contains("cim:RegulatingControl rdf:ID=\"" + rcID + "\"")); + assertFalse(eq.contains("cim:RegulatingCondEq.RegulatingControl rdf:resource=\"#" + rcID + "\"")); + // dummy kind is used when false assertion would trigger because other RCs are present from other equipment + assertFalse(eq.contains("RegulatingControlModeKind." + rcMode)); + assertFalse(eq.contains("cim:RegulatingControl.Terminal rdf:resource=\"#" + terID + "\"")); + } + + private void testRcEqRcWithAttribute(String eq, String rcID, String terID, String rcMode) { + assertTrue(eq.contains("cim:RegulatingControl rdf:ID=\"" + rcID + "\"")); + assertTrue(eq.contains("cim:RegulatingCondEq.RegulatingControl rdf:resource=\"#" + rcID + "\"")); + assertTrue(eq.contains("RegulatingControlModeKind." + rcMode)); + assertTrue(eq.contains("cim:RegulatingControl.Terminal rdf:resource=\"#" + terID + "\"")); + } + private String getEQ(Network network, String baseName, Path tmpDir, Properties exportParams) throws IOException { new CgmesExport().export(network, exportParams, new FileDataSource(tmpDir, baseName)); return Files.readString(tmpDir.resolve(baseName + "_EQ.xml")); 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 fbf83de2a11..bf30f642c09 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 @@ -27,6 +27,7 @@ import com.powsybl.iidm.network.NetworkFactory; import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; import com.powsybl.iidm.network.test.PhaseShifterTestCaseFactory; +import com.powsybl.iidm.network.test.SvcTestCaseFactory; import com.powsybl.iidm.serde.NetworkSerDe; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; @@ -486,6 +487,70 @@ void ratioTapChangerTapChangerControlSSHTest() throws IOException { } } + @Test + void staticVarCompensatorRegulatingControlSSHTest() throws IOException { + String exportFolder = "/test-svc-rc"; + String baseName = "testSvcRc"; + Network network; + String ssh; + try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { + Path tmpDir = Files.createDirectory(fs.getPath(exportFolder)); + Properties exportParams = new Properties(); + exportParams.put(CgmesExport.PROFILES, "SSH"); + + // SVC VOLTAGE + // Local + network = SvcTestCaseFactory.createLocalVoltageControl(); + ssh = getSSH(network, baseName, tmpDir, exportParams); + testRcEqRcWithAttribute(ssh, "_SVC2_RC", "false", "true", "0", "390", "k"); + + // Remote + network = SvcTestCaseFactory.createRemoteVoltageControl(); + ssh = getSSH(network, baseName, tmpDir, exportParams); + testRcEqRcWithAttribute(ssh, "_SVC2_RC", "false", "true", "0", "390", "k"); + + // SVC REACTIVE_POWER + // Local + network = SvcTestCaseFactory.createLocalReactiveControl(); + ssh = getSSH(network, baseName, tmpDir, exportParams); + testRcEqRCWithoutAttribute(ssh, "_SVC2_RC"); + + // Remote + network = SvcTestCaseFactory.createRemoteReactiveControl(); + ssh = getSSH(network, baseName, tmpDir, exportParams); + testRcEqRcWithAttribute(ssh, "_SVC2_RC", "false", "true", "0", "350", "M"); + + // SVC OFF + // Local + network = SvcTestCaseFactory.createLocalOffNoTarget(); + ssh = getSSH(network, baseName, tmpDir, exportParams); + testRcEqRCWithoutAttribute(ssh, "_SVC2_RC"); + network = SvcTestCaseFactory.createLocalOffReactiveTarget(); + ssh = getSSH(network, baseName, tmpDir, exportParams); + testRcEqRCWithoutAttribute(ssh, "_SVC2_RC"); + network = SvcTestCaseFactory.createLocalOffVoltageTarget(); + ssh = getSSH(network, baseName, tmpDir, exportParams); + testRcEqRCWithoutAttribute(ssh, "_SVC2_RC"); + network = SvcTestCaseFactory.createLocalOffBothTarget(); + ssh = getSSH(network, baseName, tmpDir, exportParams); + testRcEqRCWithoutAttribute(ssh, "_SVC2_RC"); + + // Remote + network = SvcTestCaseFactory.createRemoteOffNoTarget(); + ssh = getSSH(network, baseName, tmpDir, exportParams); + testRcEqRcWithAttribute(ssh, "_SVC2_RC", "false", "false", "0", "0", "k"); + network = SvcTestCaseFactory.createRemoteOffReactiveTarget(); + ssh = getSSH(network, baseName, tmpDir, exportParams); + testRcEqRcWithAttribute(ssh, "_SVC2_RC", "false", "false", "0", "350", "M"); + network = SvcTestCaseFactory.createRemoteOffVoltageTarget(); + ssh = getSSH(network, baseName, tmpDir, exportParams); + 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"); + } + } + private void testTcTccWithoutAttribute(String ssh, String rcID, String discrete, String enabled, String deadband, String target, String multiplier) { assertFalse(ssh.contains("cim:TapChangerControl rdf:about=\"#" + rcID + "\"")); assertFalse(ssh.contains("" + discrete + "")); @@ -504,6 +569,19 @@ private void testTcTccWithAttribute(String ssh, String rcID, String discrete, St assertTrue(ssh.contains("UnitMultiplier." + multiplier + "\"")); } + private void testRcEqRCWithoutAttribute(String ssh, String rcID) { + assertFalse(ssh.contains("cim:RegulatingControl rdf:about=\"#" + rcID + "\"")); + } + + private void testRcEqRcWithAttribute(String ssh, String rcID, String discrete, String enabled, String deadband, String target, String multiplier) { + assertTrue(ssh.contains("cim:RegulatingControl rdf:about=\"#" + rcID + "\"")); + assertTrue(ssh.contains("" + discrete + "")); + assertTrue(ssh.contains("" + enabled + "")); + assertTrue(ssh.contains("" + deadband + "")); + assertTrue(ssh.contains("" + target + "")); + assertTrue(ssh.contains("UnitMultiplier." + multiplier + "\"")); + } + private String getSSH(Network network, String baseName, Path tmpDir, Properties exportParams) throws IOException { new CgmesExport().export(network, exportParams, new FileDataSource(tmpDir, baseName)); return Files.readString(tmpDir.resolve(baseName + "_SSH.xml")); diff --git a/iidm/iidm-test/src/main/java/com/powsybl/iidm/network/test/SvcTestCaseFactory.java b/iidm/iidm-test/src/main/java/com/powsybl/iidm/network/test/SvcTestCaseFactory.java index 23c29b1d070..7e1edab8857 100644 --- a/iidm/iidm-test/src/main/java/com/powsybl/iidm/network/test/SvcTestCaseFactory.java +++ b/iidm/iidm-test/src/main/java/com/powsybl/iidm/network/test/SvcTestCaseFactory.java @@ -140,4 +140,125 @@ public static Network createWithRemoteRegulatingTerminal(NetworkFactory networkF return network; } + + private static Network addReactiveTarget(Network network) { + network.getStaticVarCompensator("SVC2") + .setReactivePowerSetpoint(350); + return network; + } + + private static Network addVoltageTarget(Network network) { + network.getStaticVarCompensator("SVC2") + .setVoltageSetpoint(390); + return network; + } + + private static Network addBothTarget(Network network) { + network.getStaticVarCompensator("SVC2") + .setReactivePowerSetpoint(350) + .setVoltageSetpoint(390); + return network; + } + + private static Network createLocalVoltageControl(Network network) { + return addVoltageControl(network); + } + + public static Network createLocalVoltageControl() { + return createLocalVoltageControl(create()); + } + + public static Network createRemoteVoltageControl() { + return createLocalVoltageControl(createWithRemoteRegulatingTerminal()); + } + + private static Network addVoltageControl(Network network) { + addVoltageTarget(network); + network.getStaticVarCompensator("SVC2") + .setRegulationMode(StaticVarCompensator.RegulationMode.VOLTAGE); + return network; + } + + private static Network createReactiveControl(Network network) { + return addReactiveControl(network); + } + + public static Network createLocalReactiveControl() { + return createReactiveControl(create()); + } + + public static Network createRemoteReactiveControl() { + return createReactiveControl(createWithRemoteRegulatingTerminal()); + } + + private static Network addReactiveControl(Network network) { + addReactiveTarget(network); + network.getStaticVarCompensator("SVC2") + .setRegulationMode(StaticVarCompensator.RegulationMode.REACTIVE_POWER); + return network; + } + + public static Network createLocalOffReactiveTarget() { + return createOffReactiveTarget(create()); + } + + public static Network createRemoteOffReactiveTarget() { + return createOffReactiveTarget(createWithRemoteRegulatingTerminal()); + } + + private static Network createOffReactiveTarget(Network network) { + return addOffReactiveTarget(network); + } + + private static Network addOffReactiveTarget(Network network) { + return addReactiveTarget(addOffNoTarget(network)); + } + + public static Network createLocalOffVoltageTarget() { + return createOffVoltageTarget(create()); + } + + public static Network createRemoteOffVoltageTarget() { + return createOffVoltageTarget(createWithRemoteRegulatingTerminal()); + } + + private static Network createOffVoltageTarget(Network network) { + return addOffVoltageTarget(network); + } + + private static Network addOffVoltageTarget(Network network) { + return addVoltageTarget(addOffNoTarget(network)); + } + + public static Network createLocalOffBothTarget() { + return createOffBothTarget(create()); + } + + public static Network createRemoteOffBothTarget() { + return createOffBothTarget(createWithRemoteRegulatingTerminal()); + } + + private static Network createOffBothTarget(Network network) { + return addOffBothTarget(network); + } + + private static Network addOffBothTarget(Network network) { + return addBothTarget(addOffNoTarget(network)); + } + + public static Network createLocalOffNoTarget() { + return addOffNoTarget(create()); + } + + public static Network createRemoteOffNoTarget() { + return addOffNoTarget(createWithRemoteRegulatingTerminal()); + } + + private static Network addOffNoTarget(Network network) { + network.getStaticVarCompensator("SVC2") + .setRegulationMode(StaticVarCompensator.RegulationMode.OFF) + .setVoltageSetpoint(Double.NaN) + .setReactivePowerSetpoint(Double.NaN); + return network; + } }