diff --git a/src/main/java/com/powsybl/openloadflow/OpenLoadFlowParameters.java b/src/main/java/com/powsybl/openloadflow/OpenLoadFlowParameters.java index efb424d045..ff825e1d2d 100644 --- a/src/main/java/com/powsybl/openloadflow/OpenLoadFlowParameters.java +++ b/src/main/java/com/powsybl/openloadflow/OpenLoadFlowParameters.java @@ -34,7 +34,7 @@ public class OpenLoadFlowParameters extends AbstractExtension 10^-2 in p.u diff --git a/src/test/java/com/powsybl/openloadflow/OpenLoadFlowProviderTest.java b/src/test/java/com/powsybl/openloadflow/OpenLoadFlowProviderTest.java index 16dc3f3f4c..9c4ed4b8e3 100644 --- a/src/test/java/com/powsybl/openloadflow/OpenLoadFlowProviderTest.java +++ b/src/test/java/com/powsybl/openloadflow/OpenLoadFlowProviderTest.java @@ -52,7 +52,7 @@ void testDcParameters() { void testAcParameters() { Network network = Mockito.mock(Network.class); AcLoadFlowParameters acParameters = OpenLoadFlowProvider.createAcParameters(network, new DenseMatrixFactory(), new LoadFlowParameters().setReadSlackBus(true), new OpenLoadFlowParameters(), false, Reporter.NO_OP); - assertEquals("AcLoadFlowParameters(networkParameters=LfNetworkParameters(slackBusSelector=NetworkSlackBusSelector, generatorVoltageRemoteControl=true, minImpedance=false, twtSplitShuntAdmittance=false, breakers=false, plausibleActivePowerLimit=5000.0, addRatioToLinesWithDifferentNominalVoltageAtBothEnds=false, computeMainConnectedComponentOnly=true, countriesToBalance=[], distributedOnConformLoad=false, phaseControl=false, transformerVoltageControl=false, voltagePerReactivePowerControl=false, reactivePowerRemoteControl=false, isDc=false, reactiveLimits=true), equationSystemCreationParameters=AcEquationSystemCreationParameters(forceA1Var=false, branchesWithCurrent=null), newtonRaphsonParameters=NewtonRaphsonParameters(maxIteration=30, voltageInitializer=UniformValueVoltageInitializer, stoppingCriteria=DefaultNewtonRaphsonStoppingCriteria), outerLoops=[DistributedSlackOuterLoop, ReactiveLimitsOuterLoop], matrixFactory=DenseMatrixFactory)", + assertEquals("AcLoadFlowParameters(networkParameters=LfNetworkParameters(slackBusSelector=NetworkSlackBusSelector, generatorVoltageRemoteControl=true, minImpedance=false, twtSplitShuntAdmittance=false, breakers=false, plausibleActivePowerLimit=5000.0, addRatioToLinesWithDifferentNominalVoltageAtBothEnds=true, computeMainConnectedComponentOnly=true, countriesToBalance=[], distributedOnConformLoad=false, phaseControl=false, transformerVoltageControl=false, voltagePerReactivePowerControl=false, reactivePowerRemoteControl=false, isDc=false, reactiveLimits=true), equationSystemCreationParameters=AcEquationSystemCreationParameters(forceA1Var=false, branchesWithCurrent=null), newtonRaphsonParameters=NewtonRaphsonParameters(maxIteration=30, voltageInitializer=UniformValueVoltageInitializer, stoppingCriteria=DefaultNewtonRaphsonStoppingCriteria), outerLoops=[DistributedSlackOuterLoop, ReactiveLimitsOuterLoop], matrixFactory=DenseMatrixFactory)", acParameters.toString()); } diff --git a/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowBoundaryTest.java b/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowBoundaryTest.java new file mode 100644 index 0000000000..f594de7a32 --- /dev/null +++ b/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowBoundaryTest.java @@ -0,0 +1,179 @@ +/** + * Copyright (c) 2019, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package com.powsybl.openloadflow.ac; + +import com.powsybl.iidm.network.*; +import com.powsybl.loadflow.LoadFlow; +import com.powsybl.loadflow.LoadFlowParameters; +import com.powsybl.loadflow.LoadFlowResult; +import com.powsybl.math.matrix.DenseMatrixFactory; +import com.powsybl.openloadflow.OpenLoadFlowParameters; +import com.powsybl.openloadflow.OpenLoadFlowProvider; +import com.powsybl.openloadflow.network.BoundaryFactory; +import com.powsybl.openloadflow.network.SlackBusSelectionMode; +import com.powsybl.openloadflow.network.VoltageControlNetworkFactory; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.powsybl.openloadflow.util.LoadFlowAssert.*; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * @author Geoffroy Jamgotchian + */ +class AcLoadFlowBoundaryTest { + + private Network network; + private Bus bus1; + private Bus bus2; + private DanglingLine dl1; + private Generator g1; + + private LoadFlow.Runner loadFlowRunner; + + private LoadFlowParameters parameters; + + private OpenLoadFlowParameters parametersExt; + + @BeforeEach + void setUp() { + network = BoundaryFactory.create(); + bus1 = network.getBusBreakerView().getBus("b1"); + bus2 = network.getBusBreakerView().getBus("b2"); + dl1 = network.getDanglingLine("dl1"); + g1 = network.getGenerator("g1"); + loadFlowRunner = new LoadFlow.Runner(new OpenLoadFlowProvider(new DenseMatrixFactory())); + parameters = new LoadFlowParameters().setNoGeneratorReactiveLimits(true) + .setDistributedSlack(false); + parametersExt = new OpenLoadFlowParameters() + .setSlackBusSelectionMode(SlackBusSelectionMode.MOST_MESHED); + parameters.addExtension(OpenLoadFlowParameters.class, parametersExt); + } + + @Test + void test() { + LoadFlowResult result = loadFlowRunner.run(network, parameters); + assertTrue(result.isOk()); + + assertVoltageEquals(390, bus1); + assertAngleEquals(0.058104, bus1); + assertVoltageEquals(388.582864, bus2); + assertAngleEquals(0, bus2); + assertActivePowerEquals(101.302, dl1.getTerminal()); + assertReactivePowerEquals(149.764, dl1.getTerminal()); + } + + @Test + void testWithVoltageRegulationOn() { + g1.setTargetQ(0); + g1.setVoltageRegulatorOn(false); + dl1.getGeneration().setVoltageRegulationOn(true); + dl1.getGeneration().setMinP(0); + dl1.getGeneration().setMaxP(10); + dl1.getGeneration().newMinMaxReactiveLimits() + .setMinQ(-100) + .setMaxQ(100) + .add(); + LoadFlowResult result = loadFlowRunner.run(network, parameters); + assertTrue(result.isOk()); + + assertVoltageEquals(390.440, bus1); + assertAngleEquals(0.114371, bus1); + assertVoltageEquals(390.181, bus2); + assertAngleEquals(0, bus2); + assertActivePowerEquals(101.2, dl1.getTerminal()); + assertReactivePowerEquals(-0.202, dl1.getTerminal()); + + parameters.setDistributedSlack(true) + .setNoGeneratorReactiveLimits(false); + LoadFlowResult result2 = loadFlowRunner.run(network, parameters); + assertTrue(result2.isOk()); + + assertVoltageEquals(390.440, bus1); + assertAngleEquals(0.114371, bus1); + assertVoltageEquals(390.181, bus2); + assertAngleEquals(0, bus2); + assertActivePowerEquals(101.2, dl1.getTerminal()); + assertReactivePowerEquals(-0.202, dl1.getTerminal()); + } + + @Test + void testWithXnode() { + Network network = BoundaryFactory.createWithXnode(); + parameters.setNoGeneratorReactiveLimits(false); + parameters.setDistributedSlack(true); + LoadFlowResult result = loadFlowRunner.run(network, parameters); + assertTrue(result.isOk()); + + assertVoltageEquals(400.000, network.getBusBreakerView().getBus("b1")); + assertVoltageEquals(399.999, network.getBusBreakerView().getBus("xnode")); + assertVoltageEquals(399.999, network.getBusBreakerView().getBus("b3")); + assertVoltageEquals(400.000, network.getBusBreakerView().getBus("b4")); + + parametersExt.setAddRatioToLinesWithDifferentNominalVoltageAtBothEnds(false); + LoadFlowResult result2 = loadFlowRunner.run(network, parameters); + assertTrue(result2.isOk()); + + assertVoltageEquals(400.000, network.getBusBreakerView().getBus("b1")); + assertVoltageEquals(398.139, network.getBusBreakerView().getBus("xnode")); + assertVoltageEquals(417.679, network.getBusBreakerView().getBus("b3")); + assertVoltageEquals(400.000, network.getBusBreakerView().getBus("b4")); + } + + @Test + void testWithTieLine() { + Network network = BoundaryFactory.createWithTieLine(); + parameters.setNoGeneratorReactiveLimits(false); + parameters.setDistributedSlack(true); + LoadFlowResult result = loadFlowRunner.run(network, parameters); + assertTrue(result.isOk()); + + assertVoltageEquals(400.000, network.getBusBreakerView().getBus("b1")); + assertVoltageEquals(399.999, network.getBusBreakerView().getBus("b3")); + assertVoltageEquals(400.000, network.getBusBreakerView().getBus("b4")); + + parametersExt.setAddRatioToLinesWithDifferentNominalVoltageAtBothEnds(false); + LoadFlowResult result2 = loadFlowRunner.run(network, parameters); + assertTrue(result2.isOk()); + + assertVoltageEquals(400.000, network.getBusBreakerView().getBus("b1")); + assertVoltageEquals(417.841, network.getBusBreakerView().getBus("b3")); + assertVoltageEquals(400.000, network.getBusBreakerView().getBus("b4")); + } + + @Test + void testEquivalentBranch() { + Network network = VoltageControlNetworkFactory.createNetworkWithT2wt(); + network.newLine() + .setId("LINE_23") + .setVoltageLevel1("VL_2") + .setVoltageLevel2("VL_3") + .setBus1("BUS_2") + .setBus2("BUS_3") + .setR(1.05) + .setX(0.01) + .setG1(0.) + .setG2(0.) + .setB1(0.) + .setB2(0.) + .add(); + + parametersExt.setAddRatioToLinesWithDifferentNominalVoltageAtBothEnds(false); + LoadFlowResult result = loadFlowRunner.run(network, parameters); + assertTrue(result.isOk()); + assertVoltageEquals(135.0, network.getBusBreakerView().getBus("BUS_1")); + assertVoltageEquals(134.25, network.getBusBreakerView().getBus("BUS_2")); + assertVoltageEquals(33.26, network.getBusBreakerView().getBus("BUS_3")); + + parametersExt.setAddRatioToLinesWithDifferentNominalVoltageAtBothEnds(true); + LoadFlowResult result2 = loadFlowRunner.run(network, parameters); + assertTrue(result2.isOk()); + assertVoltageEquals(135.0, network.getBusBreakerView().getBus("BUS_1")); + assertVoltageEquals(121.62, network.getBusBreakerView().getBus("BUS_2")); + assertVoltageEquals(0.04, network.getBusBreakerView().getBus("BUS_3")); + } +} diff --git a/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowDanglingLineTest.java b/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowDanglingLineTest.java deleted file mode 100644 index c1ad1836c5..0000000000 --- a/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowDanglingLineTest.java +++ /dev/null @@ -1,102 +0,0 @@ -/** - * Copyright (c) 2019, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package com.powsybl.openloadflow.ac; - -import com.powsybl.iidm.network.*; -import com.powsybl.loadflow.LoadFlow; -import com.powsybl.loadflow.LoadFlowParameters; -import com.powsybl.loadflow.LoadFlowResult; -import com.powsybl.math.matrix.DenseMatrixFactory; -import com.powsybl.openloadflow.OpenLoadFlowParameters; -import com.powsybl.openloadflow.OpenLoadFlowProvider; -import com.powsybl.openloadflow.network.DanglingLineFactory; -import com.powsybl.openloadflow.network.SlackBusSelectionMode; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static com.powsybl.openloadflow.util.LoadFlowAssert.*; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * @author Geoffroy Jamgotchian - */ -class AcLoadFlowDanglingLineTest { - - private Network network; - private Bus bus1; - private Bus bus2; - private DanglingLine dl1; - private Generator g1; - - private LoadFlow.Runner loadFlowRunner; - - private LoadFlowParameters parameters; - - private OpenLoadFlowParameters parametersExt; - - @BeforeEach - void setUp() { - network = DanglingLineFactory.create(); - bus1 = network.getBusBreakerView().getBus("b1"); - bus2 = network.getBusBreakerView().getBus("b2"); - dl1 = network.getDanglingLine("dl1"); - g1 = network.getGenerator("g1"); - loadFlowRunner = new LoadFlow.Runner(new OpenLoadFlowProvider(new DenseMatrixFactory())); - parameters = new LoadFlowParameters().setNoGeneratorReactiveLimits(true) - .setDistributedSlack(false); - parametersExt = new OpenLoadFlowParameters() - .setSlackBusSelectionMode(SlackBusSelectionMode.MOST_MESHED); - parameters.addExtension(OpenLoadFlowParameters.class, parametersExt); - } - - @Test - void test() { - LoadFlowResult result = loadFlowRunner.run(network, parameters); - assertTrue(result.isOk()); - - assertVoltageEquals(390, bus1); - assertAngleEquals(0.058104, bus1); - assertVoltageEquals(388.582864, bus2); - assertAngleEquals(0, bus2); - assertActivePowerEquals(101.302, dl1.getTerminal()); - assertReactivePowerEquals(149.764, dl1.getTerminal()); - } - - @Test - void testWithVoltageRegulationOn() { - g1.setTargetQ(0); - g1.setVoltageRegulatorOn(false); - dl1.getGeneration().setVoltageRegulationOn(true); - dl1.getGeneration().setMinP(0); - dl1.getGeneration().setMaxP(10); - dl1.getGeneration().newMinMaxReactiveLimits() - .setMinQ(-100) - .setMaxQ(100) - .add(); - LoadFlowResult result = loadFlowRunner.run(network, parameters); - assertTrue(result.isOk()); - - assertVoltageEquals(390.440, bus1); - assertAngleEquals(0.114371, bus1); - assertVoltageEquals(390.181, bus2); - assertAngleEquals(0, bus2); - assertActivePowerEquals(101.2, dl1.getTerminal()); - assertReactivePowerEquals(-0.202, dl1.getTerminal()); - - parameters.setDistributedSlack(true) - .setNoGeneratorReactiveLimits(false); - LoadFlowResult result2 = loadFlowRunner.run(network, parameters); - assertTrue(result2.isOk()); - - assertVoltageEquals(390.440, bus1); - assertAngleEquals(0.114371, bus1); - assertVoltageEquals(390.181, bus2); - assertAngleEquals(0, bus2); - assertActivePowerEquals(101.2, dl1.getTerminal()); - assertReactivePowerEquals(-0.202, dl1.getTerminal()); - } -} diff --git a/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowTransformerControlTest.java b/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowTransformerControlTest.java index 47de2210b2..65dbf623fa 100644 --- a/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowTransformerControlTest.java +++ b/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowTransformerControlTest.java @@ -108,7 +108,7 @@ void remoteVoltageControlT2wtTest() { .add(); VoltageLevel vl4 = substation.newVoltageLevel() .setId("VL_4") - .setNominalV(32.0) + .setNominalV(33.0) .setLowVoltageLimit(0) .setHighVoltageLimit(100) .setTopologyKind(TopologyKind.BUS_BREAKER) @@ -145,7 +145,7 @@ void remoteVoltageControlT2wtTest() { .setTargetV(33.0); LoadFlowResult result = loadFlowRunner.run(network, parameters); - assertVoltageEquals(31.861, bus4); + assertVoltageEquals(32.872, bus4); assertTrue(result.isOk()); assertEquals(3, t2wt.getRatioTapChanger().getTapPosition()); @@ -158,7 +158,7 @@ void remoteVoltageControlT2wtTest() { .setTargetV(33.0); result = loadFlowRunner.run(network, parameters); - assertVoltageEquals(31.862, bus4); //FIXME: should be 31.861 + assertVoltageEquals(32.874, bus4); //FIXME: should be 32.872 assertTrue(result.isOk()); assertEquals(3, t2wt.getRatioTapChanger().getTapPosition()); } @@ -408,7 +408,7 @@ void remoteVoltageControlT3wtTest() { .add(); VoltageLevel vl5 = substation.newVoltageLevel() .setId("VL_5") - .setNominalV(30.0) + .setNominalV(33.0) .setLowVoltageLimit(0) .setHighVoltageLimit(100.0) .setTopologyKind(TopologyKind.BUS_BREAKER) @@ -446,7 +446,7 @@ void remoteVoltageControlT3wtTest() { LoadFlowResult result = loadFlowRunner.run(network, parameters); assertTrue(result.isOk()); - assertVoltageEquals(31.200, bus5); + assertVoltageEquals(34.329, bus5); parameters.setTransformerVoltageControlOn(true); t3wt.getLeg2().getRatioTapChanger() @@ -458,7 +458,7 @@ void remoteVoltageControlT3wtTest() { result = loadFlowRunner.run(network, parameters); assertTrue(result.isOk()); - assertVoltageEquals(31.200, bus5); + assertVoltageEquals(34.329, bus5); } /** diff --git a/src/test/java/com/powsybl/openloadflow/network/BoundaryFactory.java b/src/test/java/com/powsybl/openloadflow/network/BoundaryFactory.java new file mode 100644 index 0000000000..76253d8fca --- /dev/null +++ b/src/test/java/com/powsybl/openloadflow/network/BoundaryFactory.java @@ -0,0 +1,403 @@ +/** + * Copyright (c) 2021, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package com.powsybl.openloadflow.network; + +import com.powsybl.iidm.network.*; + +/** + * @author Anne Tilloy + */ +public class BoundaryFactory extends AbstractLoadFlowNetworkFactory { + + /** + * g1 dl1 + * | | + * b1 ---- b2 + * l1 + */ + public static Network create() { + Network network = Network.create("dl", "test"); + Substation s1 = network.newSubstation() + .setId("S1") + .add(); + Substation s2 = network.newSubstation() + .setId("S2") + .add(); + VoltageLevel vl1 = s1.newVoltageLevel() + .setId("vl1") + .setNominalV(400) + .setTopologyKind(TopologyKind.BUS_BREAKER) + .add(); + vl1.getBusBreakerView().newBus() + .setId("b1") + .add(); + vl1.newGenerator() + .setId("g1") + .setConnectableBus("b1") + .setBus("b1") + .setTargetP(101.3664) + .setTargetV(390) + .setMinP(0) + .setMaxP(150) + .setVoltageRegulatorOn(true) + .add(); + VoltageLevel vl2 = s2.newVoltageLevel() + .setId("vl2") + .setNominalV(400) + .setTopologyKind(TopologyKind.BUS_BREAKER) + .add(); + vl2.getBusBreakerView().newBus() + .setId("b2") + .add(); + vl2.newDanglingLine() + .setId("dl1") + .setConnectableBus("b2") + .setBus("b2") + .setR(0.7) + .setX(1) + .setG(Math.pow(10, -6)) + .setB(3 * Math.pow(10, -6)) + .setP0(101) + .setQ0(150) + .newGeneration() + .setTargetP(0) + .setTargetQ(0) + .setTargetV(390) + .setVoltageRegulationOn(false) + .add() + .add(); + network.newLine() + .setId("l1") + .setVoltageLevel1("vl1") + .setBus1("b1") + .setVoltageLevel2("vl2") + .setBus2("b2") + .setR(1) + .setX(3) + .setG1(0) + .setG2(0) + .setB1(0) + .setB2(0) + .add(); + return network; + } + + /** + * g1 dl1 load3 + * | | | + * b1 ---- b2 ----- b3 + * l1 l13 + */ + public static Network createWithLoad() { + + Network network = create(); + + Substation s3 = network.newSubstation() + .setId("S3") + .add(); + VoltageLevel vl3 = s3.newVoltageLevel() + .setId("vl3") + .setNominalV(400) + .setTopologyKind(TopologyKind.BUS_BREAKER) + .add(); + vl3.getBusBreakerView().newBus() + .setId("b3") + .add(); + vl3.newLoad() + .setId("load3") + .setBus("b3") + .setP0(10.0) + .setQ0(5.0) + .add(); + + network.newLine() + .setId("l13") + .setVoltageLevel1("vl1") + .setBus1("b1") + .setVoltageLevel2("vl3") + .setBus2("b3") + .setR(10) + .setX(3) + .setG1(0) + .setG2(0) + .setB1(0) + .setB2(0) + .add(); + network.newLine() + .setId("l32") + .setVoltageLevel1("vl3") + .setBus1("b3") + .setVoltageLevel2("vl2") + .setBus2("b2") + .setR(10) + .setX(10) + .setG1(0) + .setG2(0) + .setB1(0) + .setB2(0) + .add(); + + network.getDanglingLine("dl1").setP0(91); + + return network; + } + + /** + * g1 + load1 g4 + load4 + * | | + * b1 ----- b2 ----- b3 ----- b4 + * l12 l23 l34 + */ + public static Network createWithXnode() { + + Network network = Network.create("xnode-network", "test"); + + Substation s1 = network.newSubstation() + .setId("S1") + .add(); + VoltageLevel vl1 = s1.newVoltageLevel() + .setId("vl1") + .setNominalV(380) + .setTopologyKind(TopologyKind.BUS_BREAKER) + .add(); + vl1.getBusBreakerView().newBus() + .setId("b1") + .add(); + vl1.newLoad() + .setId("load1") + .setBus("b1") + .setP0(50.0) + .setQ0(50.0) + .add(); + vl1.newGenerator() + .setId("g1") + .setConnectableBus("b1") + .setBus("b1") + .setTargetP(100) + .setTargetV(400) + .setMinP(0) + .setMaxP(150) + .setVoltageRegulatorOn(true) + .add(); + + Substation s2 = network.newSubstation() + .setId("S2") + .add(); + VoltageLevel vl2 = s2.newVoltageLevel() + .setId("vl2") + .setNominalV(380) + .setTopologyKind(TopologyKind.BUS_BREAKER) + .add(); + vl2.getBusBreakerView().newBus() + .setId("xnode") + .add(); + + Substation s3 = network.newSubstation() + .setId("S3") + .add(); + VoltageLevel vl3 = s3.newVoltageLevel() + .setId("vl3") + .setNominalV(400) + .setTopologyKind(TopologyKind.BUS_BREAKER) + .add(); + vl3.getBusBreakerView().newBus() + .setId("b3") + .add(); + + Substation s4 = network.newSubstation() + .setId("S4") + .add(); + VoltageLevel vl4 = s4.newVoltageLevel() + .setId("vl4") + .setNominalV(400) + .setTopologyKind(TopologyKind.BUS_BREAKER) + .add(); + vl4.getBusBreakerView().newBus() + .setId("b4") + .add(); + vl4.newLoad() + .setId("load4") + .setBus("b4") + .setP0(40.0) + .setQ0(40.0) + .add(); + vl4.newGenerator() + .setId("g4") + .setConnectableBus("b4") + .setBus("b4") + .setTargetP(20) + .setTargetV(400) + .setMinP(0) + .setMaxP(150) + .setVoltageRegulatorOn(true) + .add(); + + network.newLine() + .setId("l12") + .setVoltageLevel1("vl1") + .setBus1("b1") + .setVoltageLevel2("vl2") + .setBus2("xnode") + .setR(0.0) + .setX(0.1) + .setG1(0) + .setG2(0) + .setB1(0) + .setB2(0) + .add(); + network.newLine() + .setId("l23") + .setVoltageLevel1("vl2") + .setBus1("xnode") + .setVoltageLevel2("vl3") + .setBus2("b3") + .setR(0) + .setX(0.08) + .setG1(0) + .setG2(0) + .setB1(0) + .setB2(0) + .add(); + network.newLine() + .setId("l34") + .setVoltageLevel1("vl3") + .setBus1("b3") + .setVoltageLevel2("vl4") + .setBus2("b4") + .setR(0) + .setX(1.0) + .setG1(0) + .setG2(0) + .setB1(0) + .setB2(0) + .add(); + + return network; + } + + /** + * g1 + load1 g4 + load4 + * | | + * b1 ----- (xnode) ----- b3 ----- b4 + * t13 l34 + */ + public static Network createWithTieLine() { + + Network network = Network.create("xnode-network", "test"); + + Substation s1 = network.newSubstation() + .setId("S1") + .add(); + VoltageLevel vl1 = s1.newVoltageLevel() + .setId("vl1") + .setNominalV(380) + .setTopologyKind(TopologyKind.BUS_BREAKER) + .add(); + vl1.getBusBreakerView().newBus() + .setId("b1") + .add(); + vl1.newLoad() + .setId("load1") + .setBus("b1") + .setP0(50.0) + .setQ0(50.0) + .add(); + vl1.newGenerator() + .setId("g1") + .setConnectableBus("b1") + .setBus("b1") + .setTargetP(100) + .setTargetV(400) + .setMinP(0) + .setMaxP(150) + .setVoltageRegulatorOn(true) + .add(); + + Substation s3 = network.newSubstation() + .setId("S3") + .add(); + VoltageLevel vl3 = s3.newVoltageLevel() + .setId("vl3") + .setNominalV(400) + .setTopologyKind(TopologyKind.BUS_BREAKER) + .add(); + vl3.getBusBreakerView().newBus() + .setId("b3") + .add(); + + Substation s4 = network.newSubstation() + .setId("S4") + .add(); + VoltageLevel vl4 = s4.newVoltageLevel() + .setId("vl4") + .setNominalV(400) + .setTopologyKind(TopologyKind.BUS_BREAKER) + .add(); + vl4.getBusBreakerView().newBus() + .setId("b4") + .add(); + vl4.newLoad() + .setId("load4") + .setBus("b4") + .setP0(40.0) + .setQ0(40.0) + .add(); + vl4.newGenerator() + .setId("g4") + .setConnectableBus("b4") + .setBus("b4") + .setTargetP(20) + .setTargetV(400) + .setMinP(0) + .setMaxP(150) + .setVoltageRegulatorOn(true) + .add(); + + network.newTieLine() + .setId("t12") + .setUcteXnodeCode("xnode") + .newHalfLine1() + .setId("h1") + .setR(0.0) + .setX(0.1) + .setG1(0) + .setG2(0) + .setB1(0) + .setB2(0) + .add() + .newHalfLine2() + .setId("h2") + .setR(0) + .setX(0.08) + .setG1(0) + .setG2(0) + .setB1(0) + .setB2(0) + .add() + .setBus1("b1") + .setVoltageLevel1("vl1") + .setBus2("b3") + .setVoltageLevel2("vl3") + .add(); + + network.newLine() + .setId("l34") + .setVoltageLevel1("vl3") + .setBus1("b3") + .setVoltageLevel2("vl4") + .setBus2("b4") + .setR(0) + .setX(1.0) + .setG1(0) + .setG2(0) + .setB1(0) + .setB2(0) + .add(); + + return network; + } +} diff --git a/src/test/java/com/powsybl/openloadflow/network/DanglingLineFactory.java b/src/test/java/com/powsybl/openloadflow/network/DanglingLineFactory.java deleted file mode 100644 index 928968b164..0000000000 --- a/src/test/java/com/powsybl/openloadflow/network/DanglingLineFactory.java +++ /dev/null @@ -1,149 +0,0 @@ -/** - * Copyright (c) 2021, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package com.powsybl.openloadflow.network; - -import com.powsybl.iidm.network.*; - -/** - * @author Anne Tilloy - */ -public class DanglingLineFactory extends AbstractLoadFlowNetworkFactory { - - /** - * g1 dl1 - * | | - * b1 ---- b2 - * l1 - */ - public static Network create() { - Network network = Network.create("dl", "test"); - Substation s1 = network.newSubstation() - .setId("S1") - .add(); - Substation s2 = network.newSubstation() - .setId("S2") - .add(); - VoltageLevel vl1 = s1.newVoltageLevel() - .setId("vl1") - .setNominalV(400) - .setTopologyKind(TopologyKind.BUS_BREAKER) - .add(); - vl1.getBusBreakerView().newBus() - .setId("b1") - .add(); - vl1.newGenerator() - .setId("g1") - .setConnectableBus("b1") - .setBus("b1") - .setTargetP(101.3664) - .setTargetV(390) - .setMinP(0) - .setMaxP(150) - .setVoltageRegulatorOn(true) - .add(); - VoltageLevel vl2 = s2.newVoltageLevel() - .setId("vl2") - .setNominalV(400) - .setTopologyKind(TopologyKind.BUS_BREAKER) - .add(); - vl2.getBusBreakerView().newBus() - .setId("b2") - .add(); - vl2.newDanglingLine() - .setId("dl1") - .setConnectableBus("b2") - .setBus("b2") - .setR(0.7) - .setX(1) - .setG(Math.pow(10, -6)) - .setB(3 * Math.pow(10, -6)) - .setP0(101) - .setQ0(150) - .newGeneration() - .setTargetP(0) - .setTargetQ(0) - .setTargetV(390) - .setVoltageRegulationOn(false) - .add() - .add(); - network.newLine() - .setId("l1") - .setVoltageLevel1("vl1") - .setBus1("b1") - .setVoltageLevel2("vl2") - .setBus2("b2") - .setR(1) - .setX(3) - .setG1(0) - .setG2(0) - .setB1(0) - .setB2(0) - .add(); - return network; - } - - /** - * g1 dl1 load3 - * | | | - * b1 ---- b2 ----- b3 - * l1 l13 - */ - public static Network createWithLoad() { - - Network network = create(); - - Substation s3 = network.newSubstation() - .setId("S3") - .add(); - VoltageLevel vl3 = s3.newVoltageLevel() - .setId("vl3") - .setNominalV(400) - .setTopologyKind(TopologyKind.BUS_BREAKER) - .add(); - vl3.getBusBreakerView().newBus() - .setId("b3") - .add(); - vl3.newLoad() - .setId("load3") - .setBus("b3") - .setP0(10.0) - .setQ0(5.0) - .add(); - - network.newLine() - .setId("l13") - .setVoltageLevel1("vl1") - .setBus1("b1") - .setVoltageLevel2("vl3") - .setBus2("b3") - .setR(10) - .setX(3) - .setG1(0) - .setG2(0) - .setB1(0) - .setB2(0) - .add(); - network.newLine() - .setId("l32") - .setVoltageLevel1("vl3") - .setBus1("b3") - .setVoltageLevel2("vl2") - .setBus2("b2") - .setR(10) - .setX(10) - .setG1(0) - .setG2(0) - .setB1(0) - .setB2(0) - .add(); - - network.getDanglingLine("dl1").setP0(91); - - return network; - } - -} diff --git a/src/test/java/com/powsybl/openloadflow/network/HvdcNetworkFactory.java b/src/test/java/com/powsybl/openloadflow/network/HvdcNetworkFactory.java index 963bee0b3b..23008bf7ed 100644 --- a/src/test/java/com/powsybl/openloadflow/network/HvdcNetworkFactory.java +++ b/src/test/java/com/powsybl/openloadflow/network/HvdcNetworkFactory.java @@ -277,9 +277,9 @@ public static Network createLccWithBiggerComponents() { Network network = createLcc(); Bus b1 = network.getBusBreakerView().getBus("b1"); Bus b3 = network.getBusBreakerView().getBus("b3"); - Bus b4 = createBus(network, "test_s", "b4"); - Bus b5 = createBus(network, "test_s", "b5"); - Bus b6 = createBus(network, "b6"); + Bus b4 = createBus(network, "test_s", "b4", 400); + Bus b5 = createBus(network, "test_s", "b5", 400); + Bus b6 = createBus(network, "test_s", "b6", 400); createLine(network, b3, b4, "l34", 0.1f); createLine(network, b5, b6, "l56", 0.1f); TwoWindingsTransformer twt = createTransformer(network, "test_s", b4, b5, "l45", 0.1f, 1d); @@ -297,7 +297,7 @@ public static Network createLccWithBiggerComponents() { createGenerator(b6, "g6", 1); for (int i = 0; i < 10; i++) { - Bus b = createBus(network, "additionnalbus_" + i); + Bus b = createBus(network, "test_s", "additionnalbus_" + i, 400); createLine(network, b1, b, "additionnalline_" + i, 0.1f); } @@ -314,7 +314,7 @@ public static Network createLccWithBiggerComponentsAndAdditionalLine() { public static Network createLccWithBiggerComponentsAndAdditionalLine2() { Network network = createLccWithBiggerComponents(); - createBus(network, "additionnalbus_10"); + createBus(network, "test_s", "additionnalbus_10", 400); createLine(network, network.getBusBreakerView().getBus("additionnalbus_0"), network.getBusBreakerView().getBus("additionnalbus_10"), "additionnalline_10", 0.1f); return network; } diff --git a/src/test/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImplTest.java b/src/test/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImplTest.java index 56eae72816..a1a1ea8439 100644 --- a/src/test/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImplTest.java +++ b/src/test/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImplTest.java @@ -143,7 +143,7 @@ void defaultMethodsTest() { @Test void defaultMethodsTest2() { - network = DanglingLineFactory.create(); + network = BoundaryFactory.create(); List lfNetworks = Networks.load(network, new FirstSlackBusSelector()); assertEquals(1, lfNetworks.size()); diff --git a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java index 4130c8030e..c84b141f08 100644 --- a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java +++ b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java @@ -505,7 +505,7 @@ void testSaWithStateMonitorDisconnectBranch() { @Test void testSaWithStateMonitorDanglingLine() { - Network network = DanglingLineFactory.create(); + Network network = BoundaryFactory.create(); List monitors = new ArrayList<>(); monitors.add(new StateMonitor(ContingencyContext.all(), Collections.singleton("dl1"), Collections.singleton("vl1"), emptySet())); diff --git a/src/test/java/com/powsybl/openloadflow/sensi/ac/AcSensitivityAnalysisContingenciesTest.java b/src/test/java/com/powsybl/openloadflow/sensi/ac/AcSensitivityAnalysisContingenciesTest.java index 76fc756bba..66f1db4c51 100644 --- a/src/test/java/com/powsybl/openloadflow/sensi/ac/AcSensitivityAnalysisContingenciesTest.java +++ b/src/test/java/com/powsybl/openloadflow/sensi/ac/AcSensitivityAnalysisContingenciesTest.java @@ -697,7 +697,7 @@ void testContingencyPropagationLfSwitch() { @Test void testDanglingLineContingencyDistributedSlackOnLoads() { - Network network = DanglingLineFactory.createWithLoad(); + Network network = BoundaryFactory.createWithLoad(); SensitivityAnalysisParameters sensiParameters = createParameters(false, "vl3_0", true); sensiParameters.getLoadFlowParameters().setBalanceType(LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD); SensitivityFactorsProvider factorsProvider = n -> List.of(new BranchFlowPerInjectionIncrease(new BranchFlow("l1", "l1", "l1"), @@ -728,7 +728,7 @@ void testDanglingLineContingencyDistributedSlackOnLoads() { @Test void testDanglingLineContingencyDistributedSlackOnGenerators() { - Network network = DanglingLineFactory.createWithLoad(); + Network network = BoundaryFactory.createWithLoad(); SensitivityAnalysisParameters sensiParameters = createParameters(false, "vl1_0", true); sensiParameters.getLoadFlowParameters().setBalanceType(LoadFlowParameters.BalanceType.PROPORTIONAL_TO_GENERATION_P_MAX); SensitivityFactorsProvider factorsProvider2 = n -> List.of(new BranchFlowPerInjectionIncrease(new BranchFlow("l1", "l1", "l1"), diff --git a/src/test/java/com/powsybl/openloadflow/sensi/ac/AcSensitivityAnalysisTest.java b/src/test/java/com/powsybl/openloadflow/sensi/ac/AcSensitivityAnalysisTest.java index 8c1a94897c..599641930e 100644 --- a/src/test/java/com/powsybl/openloadflow/sensi/ac/AcSensitivityAnalysisTest.java +++ b/src/test/java/com/powsybl/openloadflow/sensi/ac/AcSensitivityAnalysisTest.java @@ -832,7 +832,7 @@ void testEmptyFactors() { @Test void testDanglingLineSensi() { - Network network = DanglingLineFactory.createWithLoad(); + Network network = BoundaryFactory.createWithLoad(); runAcLf(network); SensitivityAnalysisParameters sensiParameters = createParameters(false, "vl1_0"); diff --git a/src/test/java/com/powsybl/openloadflow/sensi/dc/DcSensitivityAnalysisContingenciesTest.java b/src/test/java/com/powsybl/openloadflow/sensi/dc/DcSensitivityAnalysisContingenciesTest.java index 8e1af497d6..28b6cfa03a 100644 --- a/src/test/java/com/powsybl/openloadflow/sensi/dc/DcSensitivityAnalysisContingenciesTest.java +++ b/src/test/java/com/powsybl/openloadflow/sensi/dc/DcSensitivityAnalysisContingenciesTest.java @@ -1783,7 +1783,7 @@ void testDebug() throws IOException { @Test void testDanglingLineContingencyDistributedSlackOnLoads() { - Network network = DanglingLineFactory.createWithLoad(); + Network network = BoundaryFactory.createWithLoad(); SensitivityAnalysisParameters sensiParameters = createParameters(true, "vl3_0", true); sensiParameters.getLoadFlowParameters().setBalanceType(LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD); SensitivityFactorsProvider factorsProvider = n -> List.of(new BranchFlowPerInjectionIncrease(new BranchFlow("l1", "l1", "l1"), @@ -1812,7 +1812,7 @@ void testDanglingLineContingencyDistributedSlackOnLoads() { @Test void testDanglingLineContingencyDistributedSlackOnGenerators() { - Network network = DanglingLineFactory.createWithLoad(); + Network network = BoundaryFactory.createWithLoad(); SensitivityAnalysisParameters sensiParameters = createParameters(true, "vl3_0", true); sensiParameters.getLoadFlowParameters().setBalanceType(LoadFlowParameters.BalanceType.PROPORTIONAL_TO_GENERATION_P_MAX); SensitivityFactorsProvider factorsProvider2 = n -> List.of(new BranchFlowPerInjectionIncrease(new BranchFlow("l1", "l1", "l1"), diff --git a/src/test/java/com/powsybl/openloadflow/sensi/dc/DcSensitivityAnalysisTest.java b/src/test/java/com/powsybl/openloadflow/sensi/dc/DcSensitivityAnalysisTest.java index c0234333be..c20fa18e52 100644 --- a/src/test/java/com/powsybl/openloadflow/sensi/dc/DcSensitivityAnalysisTest.java +++ b/src/test/java/com/powsybl/openloadflow/sensi/dc/DcSensitivityAnalysisTest.java @@ -13,7 +13,7 @@ import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; import com.powsybl.iidm.network.test.PhaseShifterTestCaseFactory; import com.powsybl.loadflow.LoadFlowParameters; -import com.powsybl.openloadflow.network.DanglingLineFactory; +import com.powsybl.openloadflow.network.BoundaryFactory; import com.powsybl.openloadflow.network.FourBusNetworkFactory; import com.powsybl.openloadflow.network.HvdcNetworkFactory; import com.powsybl.openloadflow.network.NodeBreakerNetworkFactory; @@ -754,7 +754,7 @@ void testOldApiAdapter() { @Test void testDanglingLineSensi() { - Network network = DanglingLineFactory.createWithLoad(); + Network network = BoundaryFactory.createWithLoad(); runAcLf(network); SensitivityAnalysisParameters sensiParameters = createParameters(true, "vl1_0"); diff --git a/src/test/resources/debug-parameters.json b/src/test/resources/debug-parameters.json index f93a72710f..1c2606cb90 100644 --- a/src/test/resources/debug-parameters.json +++ b/src/test/resources/debug-parameters.json @@ -24,7 +24,7 @@ "lowImpedanceBranchMode" : "REPLACE_BY_ZERO_IMPEDANCE_LINE", "loadPowerFactorConstant" : false, "plausibleActivePowerLimit" : 5000.0, - "addRatioToLinesWithDifferentNominalVoltageAtBothEnds" : false, + "addRatioToLinesWithDifferentNominalVoltageAtBothEnds" : true, "slackBusPMaxMismatch" : 1.0, "voltagePerReactivePowerControl" : false, "maxIteration" : 30,