Skip to content

Commit

Permalink
add optional on getRegulatedSide (#717)
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne LESOT <[email protected]>
  • Loading branch information
EtienneLt committed Mar 7, 2024
1 parent 408a2f4 commit 0089f49
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.powsybl.iidm.network.TwoSides;

import java.util.Optional;

/**
* @author Yichen TANG <yichen.tang at rte-france.com>
*/
Expand Down Expand Up @@ -88,8 +90,8 @@ int getHighTapPosition() {
return targetV;
}

TwoSides getRegulatedSide() {
return regulatedSide;
Optional<TwoSides> getRegulatedSide() {
return Optional.ofNullable(regulatedSide);
}

double getV() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public static DataframeMapper<List<TwtValidationData>> twtsValidationMapper() {
.ints("low_tap_position", TwtValidationData::getLowTapPosition)
.ints("high_tap_position", TwtValidationData::getHighTapPosition)
.doubles("target_v", TwtValidationData::getTargetV)
.strings("regulated_side", d -> d.getRegulatedSide().name())
.strings("regulated_side", d -> d.getRegulatedSide().map(Enum::name).orElse(""))
.doubles("v", TwtValidationData::getV)
.booleans("connected", TwtValidationData::isConnected)
.booleans("main_component", TwtValidationData::isMainComponent)
Expand Down
63 changes: 63 additions & 0 deletions tests/eurostag-example1_test_regulated_side_null.xiidm
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<iidm:network xmlns:iidm="http://www.itesla_project.eu/schema/iidm/1_0" xmlns:gsc="http://www.itesla_project.eu/schema/iidm/ext/generator_short_circuits/1_0" xmlns:vlsc="http://www.itesla_project.eu/schema/iidm/ext/voltagelevel_short_circuits/1_0" id="sim1" caseDate="2018-02-13T14:02:25.068+01:00" forecastDistance="0" sourceFormat="test">
<iidm:substation id="P1" country="FR" tso="RTE" geographicalTags="A">
<iidm:voltageLevel id="VLGEN" nominalV="24.0" topologyKind="BUS_BREAKER">
<iidm:busBreakerTopology>
<iidm:bus id="NGEN"/>
</iidm:busBreakerTopology>
<iidm:generator id="GEN" energySource="OTHER" minP="0" maxP="1000" voltageRegulatorOn="true" targetP="607.0" targetV="24.5" targetQ="301.0" bus="NGEN" connectableBus="NGEN">
<iidm:minMaxReactiveLimits minQ="-9999.99" maxQ="9999.99"/>
</iidm:generator>
</iidm:voltageLevel>
<iidm:voltageLevel id="VLHV1" nominalV="380.0" topologyKind="BUS_BREAKER">
<iidm:busBreakerTopology>
<iidm:bus id="NHV1"/>
</iidm:busBreakerTopology>
</iidm:voltageLevel>
<iidm:twoWindingsTransformer id="NGEN_NHV1" r="0.2665846" x="11.104493" g="0.0" b="0.0" ratedU1="24.0" ratedU2="400.0" bus1="NGEN" connectableBus1="NGEN" voltageLevelId1="VLGEN" bus2="NHV1" connectableBus2="NHV1" voltageLevelId2="VLHV1"/>
</iidm:substation>
<iidm:substation id="P2" country="FR" tso="RTE" geographicalTags="B">
<iidm:voltageLevel id="VLHV2" nominalV="380.0" topologyKind="BUS_BREAKER">
<iidm:busBreakerTopology>
<iidm:bus id="NHV2"/>
</iidm:busBreakerTopology>
</iidm:voltageLevel>
<iidm:voltageLevel id="VLLOAD" nominalV="150.0" topologyKind="BUS_BREAKER">
<iidm:busBreakerTopology>
<iidm:bus id="NLOAD"/>
</iidm:busBreakerTopology>
<iidm:load id="LOAD" loadType="UNDEFINED" p0="600.0" q0="200.0" bus="NLOAD" connectableBus="NLOAD"/>
</iidm:voltageLevel>
<iidm:twoWindingsTransformer id="NHV2_NLOAD" r="0.04725" x="4.0497246" g="0.0" b="0.0" ratedU1="400.0" ratedU2="158.0" bus1="NHV2" connectableBus1="NHV2" voltageLevelId1="VLHV2" bus2="NLOAD" connectableBus2="NLOAD" voltageLevelId2="VLLOAD">
<iidm:ratioTapChanger lowTapPosition="0" tapPosition="1" loadTapChangingCapabilities="true" regulating="true" targetV="158.0">
<iidm:terminalRef id="NGEN_NHV1"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="0.8505666"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.0006666"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.1507666"/>
</iidm:ratioTapChanger>
</iidm:twoWindingsTransformer>
</iidm:substation>
<iidm:line id="NHV1_NHV2_1" r="3.0" x="33.0" g1="0.0" b1="1.93E-4" g2="0.0" b2="1.93E-4" bus1="NHV1" connectableBus1="NHV1" voltageLevelId1="VLHV1" bus2="NHV2" connectableBus2="NHV2" voltageLevelId2="VLHV2">
<iidm:currentLimits1 permanentLimit="1000"/>
<iidm:currentLimits2 permanentLimit="1000"/>
</iidm:line>
<iidm:line id="NHV1_NHV2_2" r="3.0" x="33.0" g1="0.0" b1="1.93E-4" g2="0.0" b2="1.93E-4" bus1="NHV1" connectableBus1="NHV1" voltageLevelId1="VLHV1" bus2="NHV2" connectableBus2="NHV2" voltageLevelId2="VLHV2">
<iidm:currentLimits1 permanentLimit="500"/>
<iidm:currentLimits2 permanentLimit="500"/>
</iidm:line>
<iidm:extension id="VLGEN">
<vlsc:voltageLevelShortCircuits minShortCircuitsCurrent="2700.0" maxShortCircuitsCurrent="20000.0"/>
</iidm:extension>
<iidm:extension id="VLLOAD">
<vlsc:voltageLevelShortCircuits minShortCircuitsCurrent="2700.0" maxShortCircuitsCurrent="20000.0"/>
</iidm:extension>
<iidm:extension id="VLHV2">
<vlsc:voltageLevelShortCircuits minShortCircuitsCurrent="10000.0" maxShortCircuitsCurrent="40000.0"/>
</iidm:extension>
<iidm:extension id="GEN">
<gsc:generatorShortCircuits transientReactance="0.1728" stepUpTransformerReactance="0.0576"/>
</iidm:extension>
<iidm:extension id="VLHV1">
<vlsc:voltageLevelShortCircuits minShortCircuitsCurrent="10000.0" maxShortCircuitsCurrent="40000.0"/>
</iidm:extension>
</iidm:network>
10 changes: 9 additions & 1 deletion tests/test_loadflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# 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/.
#
import unittest
import pathlib
import json

import pypowsybl as pp
Expand All @@ -14,6 +14,7 @@
import pytest
import pypowsybl.report as rp

TEST_DIR = pathlib.Path(__file__).parent

@pytest.fixture(autouse=True)
def set_up():
Expand Down Expand Up @@ -310,3 +311,10 @@ def test_result_status_as_bool():
n = pp.network.create_ieee14()
r = pp.loadflow.run_ac(n)
assert r[0].status


def test_wrong_regulated_bus_id():
net = pp.network.load(str(TEST_DIR.joinpath('eurostag-example1_test_regulated_side_null.xiidm')))
pp.loadflow.run_ac(net)
parameters = lf.ValidationParameters()
validation = pp.loadflow.run_validation(net, validation_parameters=parameters)

0 comments on commit 0089f49

Please sign in to comment.