Skip to content

Commit

Permalink
Add net position test
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 e743ab4 commit 7dec7d0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ Map<Country, Double> run(Network network) {
static Map<Country, Double> computeNetPositions(Network network) {
Map<Country, Double> netPositions = new EnumMap<>(Country.class);

// TODO insert comment here
// TODO add this
network.getDanglingLineStream().forEach(danglingLine -> {
Country country = NetworkUtil.getTerminalCountry(danglingLine.getTerminal());
addLeavingFlow(netPositions, danglingLine, country);
Expand All @@ -40,17 +38,6 @@ static Map<Country, Double> computeNetPositions(Network network) {
addLeavingFlow(netPositions, line, countrySide2);
});

// TODO remove this
//network.getTieLineStream().forEach(line -> {
// Country countrySide1 = NetworkUtil.getTerminalCountry(line.getTerminal1());
// Country countrySide2 = NetworkUtil.getTerminalCountry(line.getTerminal2());
// if (countrySide1.equals(countrySide2)) {
// return;
// }
// addLeavingFlow(netPositions, line, countrySide1);
// addLeavingFlow(netPositions, line, countrySide2);
//});

network.getHvdcLineStream().forEach(hvdcLine -> {
Country countrySide1 = NetworkUtil.getTerminalCountry(hvdcLine.getConverterStation1().getTerminal());
Country countrySide2 = NetworkUtil.getTerminalCountry(hvdcLine.getConverterStation2().getTerminal());
Expand All @@ -73,11 +60,6 @@ private static void addLeavingFlow(Map<Country, Double> netPositions, Line line,
netPositions.put(country, previousValue + getLeavingFlow(line, country));
}

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

private static void addLeavingFlow(Map<Country, Double> netPositions, HvdcLine hvdcLine, Country country) {
double previousValue = getPreviousValue(netPositions, country);
netPositions.put(country, previousValue + getLeavingFlow(hvdcLine, country));
Expand All @@ -95,13 +77,6 @@ private static double getLeavingFlow(Line line, Country country) {
return country.equals(NetworkUtil.getTerminalCountry(line.getTerminal1())) ? directFlow : -directFlow;
}

private static double getLeavingFlow(TieLine line, Country country) {
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 directFlow = (flowSide1 - flowSide2) / 2;
return country.equals(NetworkUtil.getTerminalCountry(line.getTerminal1())) ? directFlow : -directFlow;
}

private static double getLeavingFlow(HvdcLine hvdcLine, Country country) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.powsybl.iidm.network.Country;
import com.powsybl.iidm.network.Network;
import com.powsybl.loadflow.LoadFlow;
import com.powsybl.loadflow.LoadFlowParameters;
import org.junit.jupiter.api.Test;

import java.util.Map;
Expand Down Expand Up @@ -57,4 +58,14 @@ void testHvdcLines() {
assertEquals(0.0, sumAllNetPositions, DOUBLE_TOLERANCE);
}

@Test
void testUnboundedXnode() {
Network network = Network.read("NETWORK_SINGLE_LOAD_TWO_GENERATORS_WITH_UNBOUNDED_XNODE.uct", getClass().getResourceAsStream("NETWORK_SINGLE_LOAD_TWO_GENERATORS_WITH_UNBOUNDED_XNODE.uct"));
LoadFlow.run(network, new LoadFlowParameters().setDc(true));
Map<Country, Double> netPositions = NetPositionComputer.computeNetPositions(network);
assertEquals(100, netPositions.get(Country.FR), DOUBLE_TOLERANCE);
assertEquals(0, netPositions.get(Country.BE), DOUBLE_TOLERANCE);
double sumAllNetPositions = netPositions.values().stream().mapToDouble(Double::doubleValue).sum();
assertEquals(100, sumAllNetPositions, DOUBLE_TOLERANCE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
##C 2007.05.01
This is a test network with only two branches.
Each branch is linking a generator with a central load.
Used to validate:
- Basic network importer
- XNEC automatic selection
- GLSK automatic generation
- Zone automatic extraction
##N
##ZFR
FGEN1 11 GEN 0 3 400.00 0.00000 0.00000 -100.00 0.00000 1000.00 -1000.0 1000.00 -1000.0
##ZBE
BGEN2 11 GEN 0 2 400.00 0.00000 0.00000 -100.00 0.00000 1000.00 -1000.0 1000.00 -1000.0
BLOAD 11 LOAD 0 0 100.000 0.00000 0.00000 0.00000
##ZXX
X 11 XNODE 0 0 100.000 0.00000 0.00000 0.00000 1000.00 -1000.0 1000.00 -1000.0
##L
FGEN1 11 BLOAD 11 1 0 1.0000 0.0500 0.000000 480 LINE
BLOAD 11 BGEN2 11 1 0 1.0000 0.0500 0.000000 480 LINE
BLOAD 11 X 11 1 0 1.0000 0.0500 0.000000 480 LINE

0 comments on commit 7dec7d0

Please sign in to comment.