Skip to content

Commit

Permalink
Update with test case and small refacto
Browse files Browse the repository at this point in the history
Signed-off-by: Sébastien Murgey <sebastien.murgey@rte-france.com>
  • Loading branch information
murgeyseb committed Oct 17, 2023
1 parent 0c195fc commit 7a9a387
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,24 @@ private boolean isAreaBorder(HvdcLine hvdcLine) {
}

private double getLeavingFlow(DanglingLine danglingLine) {
return danglingLine.getTerminal().isConnected() && !Double.isNaN(danglingLine.getBoundary().getP()) ? -danglingLine.getBoundary().getP() : 0;
return danglingLine.getTerminal().isConnected() ? zeroIfNan(-danglingLine.getBoundary().getP()) : 0;
}

private double getLeavingFlow(Line line) {
double flowSide1 = line.getTerminal1().isConnected() && !Double.isNaN(line.getTerminal1().getP()) ? line.getTerminal1().getP() : 0;
double flowSide2 = line.getTerminal2().isConnected() && !Double.isNaN(line.getTerminal2().getP()) ? line.getTerminal2().getP() : 0;
double flowSide1 = line.getTerminal1().isConnected() ? zeroIfNan(line.getTerminal1().getP()) : 0;
double flowSide2 = line.getTerminal2().isConnected() ? zeroIfNan(line.getTerminal2().getP()) : 0;
double directFlow = (flowSide1 - flowSide2) / 2;
return countries.contains(line.getTerminal1().getVoltageLevel().getSubstation().map(Substation::getNullableCountry).orElse(null)) ? directFlow : -directFlow;
}

private double getLeavingFlow(HvdcLine hvdcLine) {
double flowSide1 = hvdcLine.getConverterStation1().getTerminal().isConnected() && !Double.isNaN(hvdcLine.getConverterStation1().getTerminal().getP()) ? hvdcLine.getConverterStation1().getTerminal().getP() : 0;
double flowSide2 = hvdcLine.getConverterStation2().getTerminal().isConnected() && !Double.isNaN(hvdcLine.getConverterStation2().getTerminal().getP()) ? hvdcLine.getConverterStation2().getTerminal().getP() : 0;
double flowSide1 = hvdcLine.getConverterStation1().getTerminal().isConnected() ? zeroIfNan(hvdcLine.getConverterStation1().getTerminal().getP()) : 0;
double flowSide2 = hvdcLine.getConverterStation2().getTerminal().isConnected() ? zeroIfNan(hvdcLine.getConverterStation2().getTerminal().getP()) : 0;
double directFlow = (flowSide1 - flowSide2) / 2;
return countries.contains(hvdcLine.getConverterStation1().getTerminal().getVoltageLevel().getSubstation().map(Substation::getNullableCountry).orElse(null)) ? directFlow : -directFlow;
}

private static double zeroIfNan(double aPossiblyNanValue) {
return Double.isNaN(aPossiblyNanValue) ? 0 : aPossiblyNanValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,13 @@ void testLeavingFlowToCountryWithTieLines() {
assertEquals(0, countryAreaCH.getLeavingFlowToCountry(countryAreaDE), EPSILON);
assertEquals(-699, countryAreaIT.getLeavingFlowToCountry(countryAreaAT), EPSILON);
}

@Test
void testNetPositionIsZeroWhenDanglingLineBorderPIsNaN() {
Network testNetwork = Network.read("testCaseNanInNetPositionComputation.uct", NetworkAreaTest.class.getResourceAsStream("/testCaseNanInNetPositionComputation.uct"));
NetworkAreaFactory countryAreaCH = new CountryAreaFactory(Country.CH);
NetworkAreaFactory countryAreaIT = new CountryAreaFactory(Country.IT);
assertEquals(0, countryAreaCH.create(testNetwork).getNetPosition(), 1e-3);
assertEquals(0, countryAreaIT.create(testNetwork).getNetPosition(), 1e-3);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import com.powsybl.iidm.network.Country;
import com.powsybl.iidm.network.Network;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -18,24 +17,12 @@
*/
class NetworkAreaTest {

private Network testNetwork1;
private NetworkAreaFactory countryAreaFR;

private NetworkAreaFactory voltageLevelsArea1;

@BeforeEach
void setUp() {
testNetwork1 = Network.read("testCase.xiidm", NetworkAreaTest.class.getResourceAsStream("/testCase.xiidm"));

voltageLevelsArea1 = new VoltageLevelsAreaFactory("FFR1AA1", "FFR3AA1");

countryAreaFR = new CountryAreaFactory(Country.FR);

}

@Test
void testGetNetPosition() {
assertEquals(countryAreaFR.create(testNetwork1).getNetPosition(), voltageLevelsArea1.create(testNetwork1).getNetPosition(), 1e-3);
Network testNetwork = Network.read("testCase.xiidm", NetworkAreaTest.class.getResourceAsStream("/testCase.xiidm"));
NetworkAreaFactory voltageLevelsArea = new VoltageLevelsAreaFactory("FFR1AA1", "FFR3AA1");
NetworkAreaFactory countryAreaFR = new CountryAreaFactory(Country.FR);
assertEquals(countryAreaFR.create(testNetwork).getNetPosition(), voltageLevelsArea.create(testNetwork).getNetPosition(), 1e-3);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
##C 2007.05.01
Manually made test case to fix NaN issue in net position computation
##N
##ZCH
S 21 0 0 0.00000 0.00000 0.00000 0.00000
##ZIT
I 22 0 0 0.00000 0.00000 0.00000 0.00000
##ZXX
X_S_I_21 0 0 0.00000 0.00000 0.00000 0.00000
##L
S 21 X_S_I_21 1 8 2.0000 10.000 100.0000 9999
X_S_I_21 I 22 1 0 2.0000 10.000 100.0000 9999

0 comments on commit 7a9a387

Please sign in to comment.