Skip to content

Commit

Permalink
Test PST TCC export (#2920).
Browse files Browse the repository at this point in the history
Signed-off-by: stojkovicn <nemanja.stojkovic@rte-france.com>
Signed-off-by: nemanja-st <nemanja.stojkovic@redstork-solutions.com>
  • Loading branch information
stojkovicn authored and nemanja-st committed Jul 23, 2024
1 parent 22f0609 commit 3280a7d
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.powsybl.computation.local.LocalComputationManager;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.ThreeSides;
import com.powsybl.iidm.network.test.PhaseShifterTestCaseFactory;
import com.powsybl.iidm.network.test.ThreeWindingsTransformerNetworkFactory;
import com.powsybl.iidm.serde.ExportOptions;
import com.powsybl.iidm.serde.NetworkSerDe;
Expand All @@ -51,9 +52,12 @@
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.FileSystem;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;

import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -1004,6 +1008,63 @@ void synchronousMachineKindExportAndImportTest() throws IOException {
assertEquals(expectedOperatingMode, actualOperatingMode);
}

@Test
void phaseTapChangerTapChangerControlEQTest() throws IOException {
String exportFolder = "/test-pst-tcc";
String baseName = "testPstTcc";
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");

// PST with FIXED_TAP
network = PhaseShifterTestCaseFactory.createWithTargetDeadband();
eq = getEQ(network, baseName, tmpDir, exportParams);
testTcTccWithoutAttribute(eq, "_PS1_PTC_RC", "_PS1_PT_T_2", "activePower");

// PST local with ACTIVE_POWER_CONTROL
network = PhaseShifterTestCaseFactory.createLocalActivePowerWithTargetDeadband();
eq = getEQ(network, baseName, tmpDir, exportParams);
testTcTccWithAttribute(eq, "_PS1_PTC_RC", "_PS1_PT_T_2", "activePower");

// PST local with CURRENT_LIMITER
network = PhaseShifterTestCaseFactory.createLocalCurrentLimiterWithTargetDeadband();
eq = getEQ(network, baseName, tmpDir, exportParams);
testTcTccWithAttribute(eq, "_PS1_PTC_RC", "_PS1_PT_T_2", "currentFlow");

// PST remote with CURRENT_LIMITER
network = PhaseShifterTestCaseFactory.createRemoteCurrentLimiterWithTargetDeadband();
eq = getEQ(network, baseName, tmpDir, exportParams);
testTcTccWithAttribute(eq, "_PS1_PTC_RC", "_LD2_EC_T_1", "currentFlow");

// PST remote with ACTIVE_POWER_CONTROL
network = PhaseShifterTestCaseFactory.createRemoteActivePowerWithTargetDeadband();
eq = getEQ(network, baseName, tmpDir, exportParams);
testTcTccWithAttribute(eq, "_PS1_PTC_RC", "_LD2_EC_T_1", "activePower");
}
}

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 + "\""));
assertFalse(eq.contains("RegulatingControlModeKind." + rcMode));
assertFalse(eq.contains("cim:RegulatingControl.Terminal rdf:resource=\"#" + terID + "\""));
}

private void testTcTccWithAttribute(String eq, String rcID, String terID, String rcMode) {
assertTrue(eq.contains("cim:TapChangerControl rdf:ID=\"" + rcID + "\""));
assertTrue(eq.contains("cim:TapChanger.TapChangerControl 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"));
}

private Network createOneGeneratorNetwork() {
Network network = NetworkFactory.findDefault().createNetwork("network", "test");
Substation substation1 = network.newSubstation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
package com.powsybl.cgmes.conversion.test.export;

import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import com.powsybl.cgmes.conformity.*;
import com.powsybl.cgmes.conversion.CgmesExport;
import com.powsybl.cgmes.conversion.CgmesImport;
Expand All @@ -23,6 +25,7 @@
import com.powsybl.iidm.network.ImportConfig;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.NetworkFactory;
import com.powsybl.iidm.network.test.PhaseShifterTestCaseFactory;
import com.powsybl.iidm.serde.NetworkSerDe;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -33,6 +36,7 @@
import javax.xml.stream.*;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
Expand Down Expand Up @@ -382,6 +386,67 @@ void miniGridCgmesExportPreservingOriginalClasses() throws IOException, XMLStrea
assertTrue(ExportXmlCompare.compareSSH(expectedSsh, new ByteArrayInputStream(actualSsh.getBytes(StandardCharsets.UTF_8)), knownDiffsSsh));
}

@Test
void phaseTapChangerTapChangerControlSSHTest() throws IOException {
String exportFolder = "/test-pst-tcc";
String baseName = "testPstTcc";
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");

// PST with FIXED_TAP
network = PhaseShifterTestCaseFactory.createWithTargetDeadband();
ssh = getSSH(network, baseName, tmpDir, exportParams);
testTcTccWithoutAttribute(ssh, "_PS1_PTC_RC", "true", "false", "10", "200", "M");

// PST local with ACTIVE_POWER_CONTROL
network = PhaseShifterTestCaseFactory.createLocalActivePowerWithTargetDeadband();
ssh = getSSH(network, baseName, tmpDir, exportParams);
testTcTccWithAttribute(ssh, "_PS1_PTC_RC", "true", "false", "10", "200", "M");

// PST local with CURRENT_LIMITER
network = PhaseShifterTestCaseFactory.createLocalCurrentLimiterWithTargetDeadband();
ssh = getSSH(network, baseName, tmpDir, exportParams);
testTcTccWithAttribute(ssh, "_PS1_PTC_RC", "true", "false", "10", "200", "none");

// PST remote with CURRENT_LIMITER
network = PhaseShifterTestCaseFactory.createRemoteCurrentLimiterWithTargetDeadband();
ssh = getSSH(network, baseName, tmpDir, exportParams);
testTcTccWithAttribute(ssh, "_PS1_PTC_RC", "true", "false", "10", "200", "none");

// PST remote with ACTIVE_POWER_CONTROL
network = PhaseShifterTestCaseFactory.createRemoteActivePowerWithTargetDeadband();
ssh = getSSH(network, baseName, tmpDir, exportParams);
testTcTccWithAttribute(ssh, "_PS1_PTC_RC", "true", "false", "10", "200", "M");
}
}

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("<cim:RegulatingControl.discrete>" + discrete + "</cim:RegulatingControl.discrete>"));
assertFalse(ssh.contains("<cim:RegulatingControl.enabled>" + enabled + "</cim:RegulatingControl.enabled>"));
assertFalse(ssh.contains("<cim:RegulatingControl.targetDeadband>" + deadband + "</cim:RegulatingControl.targetDeadband>"));
assertFalse(ssh.contains("<cim:RegulatingControl.targetValue>" + target + "</cim:RegulatingControl.targetValue>"));
assertFalse(ssh.contains("UnitMultiplier." + multiplier + "\""));
}

private void testTcTccWithAttribute(String ssh, String rcID, String discrete, String enabled, String deadband, String target, String multiplier) {
assertTrue(ssh.contains("cim:TapChangerControl rdf:about=\"#" + rcID + "\""));
assertTrue(ssh.contains("<cim:RegulatingControl.discrete>" + discrete + "</cim:RegulatingControl.discrete>"));
assertTrue(ssh.contains("<cim:RegulatingControl.enabled>" + enabled + "</cim:RegulatingControl.enabled>"));
assertTrue(ssh.contains("<cim:RegulatingControl.targetDeadband>" + deadband + "</cim:RegulatingControl.targetDeadband>"));
assertTrue(ssh.contains("<cim:RegulatingControl.targetValue>" + target + "</cim:RegulatingControl.targetValue>"));
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"));
}

private static void copyBoundary(Path outputFolder, String baseName, ReadOnlyDataSource originalDataSource) throws IOException {
String eqbd = originalDataSource.listNames(".*EQ_BD.*").stream().findFirst().orElse(null);
if (eqbd != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,35 @@ public static Network createWithTargetDeadband() {
.setTargetDeadband(10.0);
return network;
}

public static Network createLocalActivePowerWithTargetDeadband() {
Network network = createWithTargetDeadband();
network.getTwoWindingsTransformer("PS1")
.getPhaseTapChanger()
.setRegulationMode(PhaseTapChanger.RegulationMode.ACTIVE_POWER_CONTROL);
return network;
}

public static Network createLocalCurrentLimiterWithTargetDeadband() {
Network network = createWithTargetDeadband();
network.getTwoWindingsTransformer("PS1")
.getPhaseTapChanger()
.setRegulationMode(PhaseTapChanger.RegulationMode.CURRENT_LIMITER);
return network;
}

public static Network createRemoteActivePowerWithTargetDeadband() {
return createRemote(createLocalActivePowerWithTargetDeadband());
}

public static Network createRemoteCurrentLimiterWithTargetDeadband() {
return createRemote(createLocalCurrentLimiterWithTargetDeadband());
}

private static Network createRemote(Network network) {
network.getTwoWindingsTransformer("PS1")
.getPhaseTapChanger()
.setRegulationTerminal(network.getLoad("LD2").getTerminal());
return network;
}
}

0 comments on commit 3280a7d

Please sign in to comment.