Skip to content

Commit

Permalink
Add NaN net position set
Browse files Browse the repository at this point in the history
Signed-off-by: Hugo SCHINDLER <hugo.schindler@rte-france.com>
  • Loading branch information
OpenSuze committed Jan 29, 2024
1 parent 7c77699 commit 8b7c940
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static void addLeavingFlow(Map<Country, Double> netPositions, HvdcLine h
}

private static void addLeavingFlow(Map<Country, Double> netPositions, DanglingLine danglingLine, Country country) {
Double previousValue = getPreviousValue(netPositions, country);
double previousValue = getPreviousValue(netPositions, country);
netPositions.put(country, previousValue + getLeavingFlow(danglingLine));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,63 +19,75 @@
/**
* @author Sebastien Murgey {@literal <sebastien.murgey at rte-france.com>}
* @author Peter Mitri {@literal <peter.mitri at rte-france.com>}
* @author Hugo Schindler{@literal <hugo.schindler@rte-france.com>}
*/
class NetPositionTest {
private static final double DOUBLE_TOLERANCE = 1e-3;

@Test
void testLines() {
Network network = Network.read("testCase.xiidm", getClass().getResourceAsStream("testCase.xiidm"));
LoadFlow.run(network, new LoadFlowParameters().setDc(true));
private static void assertNetPosition(Network network, double netPositionBe, double netPositionNl, double netPositionDe) {
Map<Country, Double> netPositions = NetPositionComputer.computeNetPositions(network);
assertEquals(1000.0, netPositions.get(Country.FR), DOUBLE_TOLERANCE);
assertEquals(1500.0, netPositions.get(Country.BE), DOUBLE_TOLERANCE);
assertEquals(0.0, netPositions.get(Country.NL), DOUBLE_TOLERANCE);
assertEquals(-2500.0, netPositions.get(Country.DE), DOUBLE_TOLERANCE);
assertEquals(netPositionBe, netPositions.get(Country.BE), DOUBLE_TOLERANCE);
assertEquals(netPositionNl, netPositions.get(Country.NL), DOUBLE_TOLERANCE);
assertEquals(netPositionDe, netPositions.get(Country.DE), DOUBLE_TOLERANCE);
double sumAllNetPositions = netPositions.values().stream().mapToDouble(Double::doubleValue).sum();
assertEquals(0.0, sumAllNetPositions, DOUBLE_TOLERANCE);
}

private static void assertNetPositionForHvdc(Network network, double countryNetPosition) {
Map<Country, Double> netPositions = NetPositionComputer.computeNetPositions(network);
assertEquals(countryNetPosition, netPositions.get(Country.FR), DOUBLE_TOLERANCE);
assertEquals(-countryNetPosition, netPositions.get(Country.DE), DOUBLE_TOLERANCE);
double sumAllNetPositions = netPositions.values().stream().mapToDouble(Double::doubleValue).sum();
assertEquals(0.0, sumAllNetPositions, DOUBLE_TOLERANCE);
}

@Test
void testLines() {
Network network = Network.read("testCase.xiidm", getClass().getResourceAsStream("testCase.xiidm"));
LoadFlow.run(network, new LoadFlowParameters().setDc(true));
assertNetPosition(network, 1500.0, 0.0, -2500.0);
}

@Test
void testLinesDisconnected() {
Network network = Network.read("testCase.xiidm", getClass().getResourceAsStream("testCase.xiidm"));
network.getBranch("BBE1AA1 BBE2AA1 1").getTerminal1().disconnect();
network.getBranch("BBE1AA1 BBE2AA1 1").getTerminal2().disconnect();
network.getBranch("NNL2AA1 BBE3AA1 1").getTerminal1().disconnect();
network.getBranch("NNL2AA1 BBE3AA1 1").getTerminal2().disconnect();
LoadFlow.run(network, new LoadFlowParameters().setDc(true));
Map<Country, Double> netPositions = NetPositionComputer.computeNetPositions(network);
assertEquals(1000.0, netPositions.get(Country.FR), DOUBLE_TOLERANCE);
assertEquals(1500.0, netPositions.get(Country.BE), DOUBLE_TOLERANCE);
assertEquals(0.0, netPositions.get(Country.NL), DOUBLE_TOLERANCE);
assertEquals(-2500.0, netPositions.get(Country.DE), DOUBLE_TOLERANCE);
double sumAllNetPositions = netPositions.values().stream().mapToDouble(Double::doubleValue).sum();
assertEquals(0.0, sumAllNetPositions, DOUBLE_TOLERANCE);
assertNetPosition(network, 1500.0, 0.0, -2500.0);
}

@Test
void testLinesNaN() {
Network network = Network.read("testCase.xiidm", getClass().getResourceAsStream("testCase.xiidm"));
LoadFlow.run(network, new LoadFlowParameters().setDc(true));
network.getBranch("NNL2AA1 BBE3AA1 1").getTerminal1().setP(Double.NaN);
network.getBranch("NNL2AA1 BBE3AA1 1").getTerminal2().setP(Double.NaN);
assertNetPosition(network, 1500.0, 0.0, -2500.0);
}

@Test
void testDanglingLinesBalanced() {
Network network = Network.read("TestCaseDangling.xiidm", getClass().getResourceAsStream("TestCaseDangling.xiidm"));
LoadFlow.run(network, new LoadFlowParameters().setDc(true));
Map<Country, Double> netPositions = NetPositionComputer.computeNetPositions(network);
assertEquals(1000.0, netPositions.get(Country.FR), DOUBLE_TOLERANCE);
assertEquals(2300.0, netPositions.get(Country.BE), DOUBLE_TOLERANCE);
assertEquals(-500.0, netPositions.get(Country.NL), DOUBLE_TOLERANCE);
assertEquals(-2800.0, netPositions.get(Country.DE), DOUBLE_TOLERANCE);
double sumAllNetPositions = netPositions.values().stream().mapToDouble(Double::doubleValue).sum();
assertEquals(0.0, sumAllNetPositions, DOUBLE_TOLERANCE);
assertNetPosition(network, 2300.0, -500.0, -2800.0);
}

@Test
void testDanglingLinesDisconnected() {
Network network = Network.read("TestCaseDangling.xiidm", getClass().getResourceAsStream("TestCaseDangling.xiidm"));
network.getDanglingLine("BBE2AA1 X_BEFR1 1").getTerminal().disconnect();
LoadFlow.run(network, new LoadFlowParameters().setDc(true));
Map<Country, Double> netPositions = NetPositionComputer.computeNetPositions(network);
assertEquals(1000.0, netPositions.get(Country.FR), DOUBLE_TOLERANCE);
assertEquals(2300.0, netPositions.get(Country.BE), DOUBLE_TOLERANCE);
assertEquals(-500.0, netPositions.get(Country.NL), DOUBLE_TOLERANCE);
assertEquals(-2800.0, netPositions.get(Country.DE), DOUBLE_TOLERANCE);
double sumAllNetPositions = netPositions.values().stream().mapToDouble(Double::doubleValue).sum();
assertEquals(0.0, sumAllNetPositions, DOUBLE_TOLERANCE);
assertNetPosition(network, 2300.0, -500.0, -2800.0);
}

@Test
void testDanglingLinesNaN() {
Network network = Network.read("TestCaseDangling.xiidm", getClass().getResourceAsStream("TestCaseDangling.xiidm"));
LoadFlow.run(network, new LoadFlowParameters().setDc(true));
network.getDanglingLine("BBE2AA1 X_BEFR1 1").getTerminal().setP(Double.NaN);
assertNetPosition(network, 2300.0, -500.0, -2800.0);
}

@Test
Expand All @@ -92,22 +104,22 @@ void testDanglingLinesUnbalanced() {
@Test
void testHvdcLines() {
Network network = Network.read("TestCaseHvdc.xiidm", getClass().getResourceAsStream("TestCaseHvdc.xiidm"));
Map<Country, Double> netPositions = NetPositionComputer.computeNetPositions(network);
assertEquals(272.0, netPositions.get(Country.FR), DOUBLE_TOLERANCE);
assertEquals(-272.0, netPositions.get(Country.DE), DOUBLE_TOLERANCE);
double sumAllNetPositions = netPositions.values().stream().mapToDouble(Double::doubleValue).sum();
assertEquals(0.0, sumAllNetPositions, DOUBLE_TOLERANCE);
assertNetPositionForHvdc(network, 272.0);
}

@Test
void testHvdcLinesDisconnected() {
Network network = Network.read("TestCaseHvdc.xiidm", getClass().getResourceAsStream("TestCaseHvdc.xiidm"));
network.getHvdcLine("hvdc_line_FR_1_DE").getConverterStation1().getTerminal().disconnect();
network.getHvdcLine("hvdc_line_FR_1_DE").getConverterStation2().getTerminal().disconnect();
Map<Country, Double> netPositions = NetPositionComputer.computeNetPositions(network);
assertEquals(200.0, netPositions.get(Country.FR), DOUBLE_TOLERANCE);
assertEquals(-200.0, netPositions.get(Country.DE), DOUBLE_TOLERANCE);
double sumAllNetPositions = netPositions.values().stream().mapToDouble(Double::doubleValue).sum();
assertEquals(0.0, sumAllNetPositions, DOUBLE_TOLERANCE);
assertNetPositionForHvdc(network, 200.0);
}

@Test
void testHvdcLinesNaN() {
Network network = Network.read("TestCaseHvdc.xiidm", getClass().getResourceAsStream("TestCaseHvdc.xiidm"));
network.getHvdcLine("hvdc_line_FR_1_DE").getConverterStation1().getTerminal().setP(Double.NaN);
network.getHvdcLine("hvdc_line_FR_1_DE").getConverterStation2().getTerminal().setP(Double.NaN);
assertNetPositionForHvdc(network, 200.0);
}
}

0 comments on commit 8b7c940

Please sign in to comment.