-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix LoadsMerger thanks to new unit test
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
- Loading branch information
Showing
3 changed files
with
133 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
commons/src/test/java/com/powsybl/dynawo/commons/LoadsMergerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.powsybl.dynawo.commons; | ||
|
||
import com.powsybl.commons.test.AbstractConverterTest; | ||
import com.powsybl.iidm.network.*; | ||
import com.powsybl.iidm.xml.NetworkXml; | ||
import com.powsybl.sld.SingleLineDiagram; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import static com.powsybl.commons.test.ComparisonUtils.compareTxt; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class LoadsMergerTest extends AbstractConverterTest { | ||
|
||
@Test | ||
public void mergeLoads() throws IOException { | ||
Network network = createTestNetwork(); | ||
Network expectedIidm = Network.read("mergedLoads.xiidm", getClass().getResourceAsStream("/mergedLoads.xiidm")); | ||
compare(expectedIidm, LoadsMerger.mergeLoads(network)); | ||
} | ||
|
||
private static Network createTestNetwork() { | ||
Network network = Network.create("test", "test"); | ||
Substation s = network.newSubstation().setId("substation").add(); | ||
|
||
VoltageLevel vl1 = s.newVoltageLevel().setId("vl1").setNominalV(250).setTopologyKind(TopologyKind.NODE_BREAKER).add(); | ||
vl1.getNodeBreakerView().newBusbarSection().setId("Busbar1").setNode(0).add(); | ||
vl1.getNodeBreakerView().newBusbarSection().setId("Busbar2").setNode(4).add(); | ||
vl1.getNodeBreakerView().newDisconnector().setNode1(0).setNode2(1).setId("d1").add(); | ||
vl1.getNodeBreakerView().newDisconnector().setNode1(0).setNode2(2).setId("d2").add(); | ||
vl1.getNodeBreakerView().newDisconnector().setNode1(0).setNode2(3).setId("d3").add(); | ||
vl1.getNodeBreakerView().newBreaker().setNode1(0).setNode2(4).setId("coupler").setOpen(true).add(); | ||
vl1.getNodeBreakerView().newDisconnector().setNode1(0).setNode2(5).setId("d4").add(); | ||
vl1.getNodeBreakerView().newDisconnector().setNode1(4).setNode2(6).setId("d5").add(); | ||
vl1.newLoad().setId("load1").setP0(10.0).setQ0(5.0).setNode(1).add(); | ||
vl1.newLoad().setId("load2").setP0(12.0).setQ0(1.0).setNode(2).add(); | ||
vl1.newLoad().setId("load3").setP0(22.0).setQ0(3.0).setNode(3).add(); | ||
vl1.newLoad().setId("load4").setP0(-2.0).setQ0(-1.0).setNode(6).add(); | ||
|
||
VoltageLevel vl2 = s.newVoltageLevel().setId("vl2").setNominalV(250).setTopologyKind(TopologyKind.BUS_BREAKER).add(); | ||
Bus b1 = vl2.getBusBreakerView().newBus().setId("b1").add(); | ||
Bus b2 = vl2.getBusBreakerView().newBus().setId("b2").add(); | ||
Bus b3 = vl2.getBusBreakerView().newBus().setId("b3").add(); | ||
vl2.getBusBreakerView().newSwitch().setId("c1").setBus1(b1.getId()).setBus2(b2.getId()).add(); | ||
vl2.getBusBreakerView().newSwitch().setId("c2").setBus1(b2.getId()).setBus2(b3.getId()).add(); | ||
vl2.newGenerator().setId("g1").setBus(b1.getId()).setTargetP(101).setTargetV(390).setMinP(0).setMaxP(150).setVoltageRegulatorOn(true).add(); | ||
vl2.newLoad().setId("load5").setP0(37.0).setQ0(1.0).setBus(b2.getId()).add(); | ||
vl2.newLoad().setId("load6").setP0(13.0).setQ0(6.0).setBus(b2.getId()).add(); | ||
vl2.newLoad().setId("load7").setP0(7.0).setQ0(-4.0).setBus(b3.getId()).add(); | ||
|
||
network.newLine().setId("l1").setVoltageLevel1(vl1.getId()).setNode1(5).setVoltageLevel2(vl2.getId()).setBus2(b1.getId()) | ||
.setR(1).setX(3).setG1(0).setG2(0).setB1(0).setB2(0).add(); | ||
return network; | ||
} | ||
|
||
private void compare(Network expected, Network actual) throws IOException { | ||
Path pexpected = tmpDir.resolve("expected.xiidm"); | ||
assertNotNull(pexpected); | ||
Path pactual = tmpDir.resolve("actual.xiidm"); | ||
assertNotNull(pactual); | ||
NetworkXml.write(expected, pexpected); | ||
actual.setCaseDate(expected.getCaseDate()); | ||
NetworkXml.write(actual, pactual); | ||
compareTxt(Files.newInputStream(pexpected), Files.newInputStream(pactual)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_9" id="test" caseDate="2023-02-17T05:41:11.194+01:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS"> | ||
<iidm:substation id="substation"> | ||
<iidm:voltageLevel id="vl1" nominalV="250.0" topologyKind="NODE_BREAKER"> | ||
<iidm:nodeBreakerTopology> | ||
<iidm:busbarSection id="Busbar1" node="0"/> | ||
<iidm:busbarSection id="Busbar2" node="4"/> | ||
<iidm:switch id="d1" kind="DISCONNECTOR" retained="false" open="false" node1="0" node2="1"/> | ||
<iidm:switch id="d2" kind="DISCONNECTOR" retained="false" open="false" node1="0" node2="2"/> | ||
<iidm:switch id="d3" kind="DISCONNECTOR" retained="false" open="false" node1="0" node2="3"/> | ||
<iidm:switch id="coupler" kind="BREAKER" retained="false" open="true" node1="0" node2="4"/> | ||
<iidm:switch id="d4" kind="DISCONNECTOR" retained="false" open="false" node1="0" node2="5"/> | ||
<iidm:switch id="d5" kind="DISCONNECTOR" retained="false" open="false" node1="4" node2="6"/> | ||
</iidm:nodeBreakerTopology> | ||
<iidm:load id="merged_load_.vl1_0" loadType="UNDEFINED" p0="44.0" q0="9.0" node="1"/> | ||
<iidm:load id="load4" loadType="UNDEFINED" p0="-2.0" q0="-1.0" node="6"/> | ||
</iidm:voltageLevel> | ||
<iidm:voltageLevel id="vl2" nominalV="250.0" topologyKind="BUS_BREAKER"> | ||
<iidm:busBreakerTopology> | ||
<iidm:bus id="b1"/> | ||
<iidm:bus id="b2"/> | ||
<iidm:bus id="b3"/> | ||
<iidm:switch id="c1" kind="BREAKER" retained="true" open="false" bus1="b1" bus2="b2"/> | ||
<iidm:switch id="c2" kind="BREAKER" retained="true" open="false" bus1="b2" bus2="b3"/> | ||
</iidm:busBreakerTopology> | ||
<iidm:generator id="g1" energySource="OTHER" minP="0.0" maxP="150.0" voltageRegulatorOn="true" targetP="101.0" targetV="390.0" bus="b1" connectableBus="b1"> | ||
<iidm:minMaxReactiveLimits minQ="-1.7976931348623157E308" maxQ="1.7976931348623157E308"/> | ||
</iidm:generator> | ||
<iidm:load id="merged_load_.b2" loadType="UNDEFINED" p0="50.0" q0="7.0" bus="b2" connectableBus="b2"/> | ||
<iidm:load id="load7" loadType="UNDEFINED" p0="7.0" q0="-4.0" bus="b3" connectableBus="b3"/> | ||
</iidm:voltageLevel> | ||
</iidm:substation> | ||
<iidm:line id="l1" r="1.0" x="3.0" g1="0.0" b1="0.0" g2="0.0" b2="0.0" node1="5" voltageLevelId1="vl1" bus2="b1" connectableBus2="b1" voltageLevelId2="vl2"/> | ||
</iidm:network> |