Skip to content

Commit

Permalink
Add Line, 2wt, 3wt convenience getters to VoltagelLevel (#380) (#433)
Browse files Browse the repository at this point in the history
Signed-off-by: Sébastien LAIGRE <[email protected]>
  • Loading branch information
sebalaig authored May 23, 2022
1 parent 6e0aa9e commit 61bb7f4
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 0 deletions.
18 changes: 18 additions & 0 deletions include/powsybl/iidm/VoltageLevel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ class VoltageLevel : public Container {

stdcxx::range<LccConverterStation> getLccConverterStations();

unsigned long getLineCount() const;

stdcxx::const_range<Line> getLines() const;

stdcxx::range<Line> getLines();

unsigned long getLoadCount() const;

stdcxx::const_range<Load> getLoads() const;
Expand Down Expand Up @@ -158,8 +164,20 @@ class VoltageLevel : public Container {

virtual stdcxx::range<Switch> getSwitches() = 0;

unsigned long getThreeWindingsTransformerCount() const;

stdcxx::const_range<ThreeWindingsTransformer> getThreeWindingsTransformers() const;

stdcxx::range<ThreeWindingsTransformer> getThreeWindingsTransformers();

virtual const TopologyKind& getTopologyKind() const = 0;

unsigned long getTwoWindingsTransformerCount() const;

stdcxx::const_range<TwoWindingsTransformer> getTwoWindingsTransformers() const;

stdcxx::range<TwoWindingsTransformer> getTwoWindingsTransformers();

unsigned long getVscConverterStationCount() const;

stdcxx::const_range<VscConverterStation> getVscConverterStations() const;
Expand Down
36 changes: 36 additions & 0 deletions src/iidm/VoltageLevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ stdcxx::range<LccConverterStation> VoltageLevel::getLccConverterStations() {
return getConnectables<LccConverterStation>();
}

unsigned long VoltageLevel::getLineCount() const {
return getConnectableCount<Line>();
}

stdcxx::const_range<Line> VoltageLevel::getLines() const {
return getConnectables<Line>();
}

stdcxx::range<Line> VoltageLevel::getLines() {
return getConnectables<Line>();
}

unsigned long VoltageLevel::getLoadCount() const {
return getConnectableCount<Load>();
}
Expand Down Expand Up @@ -191,6 +203,30 @@ stdcxx::Reference<Substation> VoltageLevel::getSubstation() {
return m_substation;
}

unsigned long VoltageLevel::getThreeWindingsTransformerCount() const {
return getConnectableCount<ThreeWindingsTransformer>();
}

stdcxx::const_range<ThreeWindingsTransformer> VoltageLevel::getThreeWindingsTransformers() const {
return getConnectables<ThreeWindingsTransformer>();
}

stdcxx::range<ThreeWindingsTransformer> VoltageLevel::getThreeWindingsTransformers() {
return getConnectables<ThreeWindingsTransformer>();
}

unsigned long VoltageLevel::getTwoWindingsTransformerCount() const {
return getConnectableCount<TwoWindingsTransformer>();
}

stdcxx::const_range<TwoWindingsTransformer> VoltageLevel::getTwoWindingsTransformers() const {
return getConnectables<TwoWindingsTransformer>();
}

stdcxx::range<TwoWindingsTransformer> VoltageLevel::getTwoWindingsTransformers() {
return getConnectables<TwoWindingsTransformer>();
}

const std::string& VoltageLevel::getTypeDescription() const {
static std::string s_typeDescription = "Voltage level";

Expand Down
101 changes: 101 additions & 0 deletions test/iidm/VoltageLevelTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::reference_wrapper<const Line>>& 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<std::reference_wrapper<const ThreeWindingsTransformer>>& 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<std::reference_wrapper<const TwoWindingsTransformer>>& 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
Expand Down

0 comments on commit 61bb7f4

Please sign in to comment.