diff --git a/include/powsybl/iidm/VoltageLevel.hpp b/include/powsybl/iidm/VoltageLevel.hpp index 558ec5d3..46ff9ed5 100644 --- a/include/powsybl/iidm/VoltageLevel.hpp +++ b/include/powsybl/iidm/VoltageLevel.hpp @@ -122,6 +122,12 @@ class VoltageLevel : public Container { stdcxx::range getLccConverterStations(); + unsigned long getLineCount() const; + + stdcxx::const_range getLines() const; + + stdcxx::range getLines(); + unsigned long getLoadCount() const; stdcxx::const_range getLoads() const; @@ -158,8 +164,20 @@ class VoltageLevel : public Container { virtual stdcxx::range getSwitches() = 0; + unsigned long getThreeWindingsTransformerCount() const; + + stdcxx::const_range getThreeWindingsTransformers() const; + + stdcxx::range getThreeWindingsTransformers(); + virtual const TopologyKind& getTopologyKind() const = 0; + unsigned long getTwoWindingsTransformerCount() const; + + stdcxx::const_range getTwoWindingsTransformers() const; + + stdcxx::range getTwoWindingsTransformers(); + unsigned long getVscConverterStationCount() const; stdcxx::const_range getVscConverterStations() const; diff --git a/src/iidm/VoltageLevel.cpp b/src/iidm/VoltageLevel.cpp index 7a361f3e..bac7c6e6 100644 --- a/src/iidm/VoltageLevel.cpp +++ b/src/iidm/VoltageLevel.cpp @@ -125,6 +125,18 @@ stdcxx::range VoltageLevel::getLccConverterStations() { return getConnectables(); } +unsigned long VoltageLevel::getLineCount() const { + return getConnectableCount(); +} + +stdcxx::const_range VoltageLevel::getLines() const { + return getConnectables(); +} + +stdcxx::range VoltageLevel::getLines() { + return getConnectables(); +} + unsigned long VoltageLevel::getLoadCount() const { return getConnectableCount(); } @@ -191,6 +203,30 @@ stdcxx::Reference VoltageLevel::getSubstation() { return m_substation; } +unsigned long VoltageLevel::getThreeWindingsTransformerCount() const { + return getConnectableCount(); +} + +stdcxx::const_range VoltageLevel::getThreeWindingsTransformers() const { + return getConnectables(); +} + +stdcxx::range VoltageLevel::getThreeWindingsTransformers() { + return getConnectables(); +} + +unsigned long VoltageLevel::getTwoWindingsTransformerCount() const { + return getConnectableCount(); +} + +stdcxx::const_range VoltageLevel::getTwoWindingsTransformers() const { + return getConnectables(); +} + +stdcxx::range VoltageLevel::getTwoWindingsTransformers() { + return getConnectables(); +} + const std::string& VoltageLevel::getTypeDescription() const { static std::string s_typeDescription = "Voltage level"; diff --git a/test/iidm/VoltageLevelTest.cpp b/test/iidm/VoltageLevelTest.cpp index 0964fe6f..cb7e603d 100644 --- a/test/iidm/VoltageLevelTest.cpp +++ b/test/iidm/VoltageLevelTest.cpp @@ -239,6 +239,107 @@ BOOST_AUTO_TEST_CASE(noSubstation) { BOOST_CHECK(stdcxx::areSame(voltageLevel.getNetwork(), network)); } +BOOST_AUTO_TEST_CASE(getLines) { + Network network = createComponentsTestNetworkBB(); + VoltageLevel& voltageLevel = network.getVoltageLevel("VL2"); + const VoltageLevel& cVoltageLevel = voltageLevel; + + const Line& line2 = network.newLine() + .setId("VL2_VL9") + .setVoltageLevel1(voltageLevel.getId()) + .setBus1("VL2_BUS1") + .setVoltageLevel2("VL9") + .setBus2("VL9_BUS1") + .setR(3.0) + .setX(33.0) + .setG1(1.0) + .setB1(0.2) + .setG2(2.0) + .setB2(0.4) + .add(); + + const Line& line = network.getLine("VL2_VL5"); + + BOOST_CHECK_EQUAL(2, cVoltageLevel.getLineCount()); + BOOST_CHECK_EQUAL(2, boost::size(voltageLevel.getLines())); + BOOST_CHECK_EQUAL(2, boost::size(cVoltageLevel.getLines())); + + const std::vector>& expected = {line, line2}; + + const auto& lines = cVoltageLevel.getLines(); + const auto& cLines = voltageLevel.getLines(); + + for (const Line& expectedLine : expected) { + auto it = std::find_if(lines.begin(), lines.end(), [&expectedLine](const Line& line) { + return stdcxx::areSame(expectedLine, line); + }); + BOOST_CHECK(it != lines.end()); + + auto cIt = std::find_if(cLines.begin(), cLines.end(), [&expectedLine](const Line& line) { + return stdcxx::areSame(expectedLine, line); + }); + BOOST_CHECK(cIt != cLines.end()); + } +} + +BOOST_AUTO_TEST_CASE(getThreeWindingsTransformer) { + Network network = createComponentsTestNetworkBB(); + VoltageLevel& voltageLevel = network.getVoltageLevel("VL2"); + const VoltageLevel& cVoltageLevel = voltageLevel; + + const ThreeWindingsTransformer& twt = network.getThreeWindingsTransformer("3WT_VL1_VL2_VL3"); + + BOOST_CHECK_EQUAL(1, cVoltageLevel.getThreeWindingsTransformerCount()); + BOOST_CHECK_EQUAL(1, boost::size(voltageLevel.getThreeWindingsTransformers())); + BOOST_CHECK_EQUAL(1, boost::size(cVoltageLevel.getThreeWindingsTransformers())); + + const std::vector>& expected = {twt}; + + const auto& twts = cVoltageLevel.getThreeWindingsTransformers(); + const auto& cTwts = voltageLevel.getThreeWindingsTransformers(); + + for (const ThreeWindingsTransformer& expectedTwt : expected) { + auto it = std::find_if(twts.begin(), twts.end(), [&expectedTwt](const ThreeWindingsTransformer& returnedTwt) { + return stdcxx::areSame(expectedTwt, returnedTwt); + }); + BOOST_CHECK(it != twts.end()); + + auto cIt = std::find_if(cTwts.begin(), cTwts.end(), [&expectedTwt](const ThreeWindingsTransformer& returnedTwt) { + return stdcxx::areSame(expectedTwt, returnedTwt); + }); + BOOST_CHECK(cIt != cTwts.end()); + } +} + +BOOST_AUTO_TEST_CASE(getTwoWindingsTransformer) { + Network network = createComponentsTestNetworkBB(); + VoltageLevel& voltageLevel = network.getVoltageLevel("VL4"); + const VoltageLevel& cVoltageLevel = voltageLevel; + + const TwoWindingsTransformer& twt = network.getTwoWindingsTransformer("2WT_VL4_VL5"); + + BOOST_CHECK_EQUAL(1, cVoltageLevel.getTwoWindingsTransformerCount()); + BOOST_CHECK_EQUAL(1, boost::size(voltageLevel.getTwoWindingsTransformers())); + BOOST_CHECK_EQUAL(1, boost::size(cVoltageLevel.getTwoWindingsTransformers())); + + const std::vector>& expected = {twt}; + + const auto& twts = cVoltageLevel.getTwoWindingsTransformers(); + const auto& cTwts = voltageLevel.getTwoWindingsTransformers(); + + for (const TwoWindingsTransformer& expectedTwt : expected) { + auto it = std::find_if(twts.begin(), twts.end(), [&expectedTwt](const TwoWindingsTransformer& returnedTwt) { + return stdcxx::areSame(expectedTwt, returnedTwt); + }); + BOOST_CHECK(it != twts.end()); + + auto cIt = std::find_if(cTwts.begin(), cTwts.end(), [&expectedTwt](const TwoWindingsTransformer& returnedTwt) { + return stdcxx::areSame(expectedTwt, returnedTwt); + }); + BOOST_CHECK(cIt != cTwts.end()); + } +} + BOOST_AUTO_TEST_SUITE_END() } // namespace iidm