From 15a0fcc2053ff155e194a2027633f7ba92aea7f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20LAIGRE?= Date: Fri, 3 Jul 2020 18:01:18 +0200 Subject: [PATCH 1/4] Removed duplicates in VoltageLevel::getConnectables (#46) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sébastien LAIGRE --- include/powsybl/iidm/VoltageLevel.hxx | 5 ++- test/iidm/VoltageLevelTest.cpp | 54 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/include/powsybl/iidm/VoltageLevel.hxx b/include/powsybl/iidm/VoltageLevel.hxx index a5651db41..c7fe85c2a 100644 --- a/include/powsybl/iidm/VoltageLevel.hxx +++ b/include/powsybl/iidm/VoltageLevel.hxx @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -78,12 +79,12 @@ unsigned long VoltageLevel::getConnectableCount() const { template stdcxx::const_range VoltageLevel::getConnectables() const { - return getTerminals() | boost::adaptors::filtered(Terminal::isInstanceOf) | boost::adaptors::transformed(Terminal::map); + return getTerminals() | boost::adaptors::filtered(Terminal::isInstanceOf) | boost::adaptors::transformed(Terminal::map) | boost::adaptors::filtered(DistinctPredicate()); } template stdcxx::range VoltageLevel::getConnectables() { - return getTerminals() | boost::adaptors::filtered(Terminal::isInstanceOf) | boost::adaptors::transformed(Terminal::map); + return getTerminals() | boost::adaptors::filtered(Terminal::isInstanceOf) | boost::adaptors::transformed(Terminal::map) | boost::adaptors::filtered(DistinctPredicate()); } } // namespace iidm diff --git a/test/iidm/VoltageLevelTest.cpp b/test/iidm/VoltageLevelTest.cpp index 4994d3bb9..4264783d6 100644 --- a/test/iidm/VoltageLevelTest.cpp +++ b/test/iidm/VoltageLevelTest.cpp @@ -7,8 +7,11 @@ #include +#include #include #include +#include +#include #include #include #include @@ -26,6 +29,51 @@ namespace powsybl { namespace iidm { +Network createLineTestNetwork2() { + Network network("test", "test"); + Substation& substation = network.newSubstation() + .setId("S1") + .setName("S1_NAME") + .setCountry(Country::FR) + .setTso("TSO") + .add(); + + VoltageLevel& vl1 = substation.newVoltageLevel() + .setId("VL1") + .setName("VL1_NAME") + .setTopologyKind(TopologyKind::BUS_BREAKER) + .setNominalVoltage(380.0) + .setLowVoltageLimit(340.0) + .setHighVoltageLimit(420.0) + .add(); + + Bus& vl1Bus1 = vl1.getBusBreakerView().newBus() + .setId("VL1_BUS1") + .add(); + + Bus& vl1Bus2 = vl1.getBusBreakerView().newBus() + .setId("VL1_BUS2") + .add(); + + network.newLine() + .setId("VL1_VL3") + .setVoltageLevel1(vl1.getId()) + .setBus1(vl1Bus1.getId()) + .setConnectableBus1(vl1Bus1.getId()) + .setVoltageLevel2(vl1.getId()) + .setBus2(vl1Bus2.getId()) + .setConnectableBus2(vl1Bus2.getId()) + .setR(3.0) + .setX(33.0) + .setG1(1.0) + .setB1(0.2) + .setG2(2.0) + .setB2(0.4) + .add(); + + return network; +} + BOOST_AUTO_TEST_SUITE(VoltageLevelTestSuite) BOOST_AUTO_TEST_CASE(constructor) { @@ -145,6 +193,12 @@ BOOST_AUTO_TEST_CASE(integrity) { POWSYBL_ASSERT_REF_FALSE(vl.getConnectable("LOAD1")); } +BOOST_AUTO_TEST_CASE(getConnectablesCheckUnique) { + const Network network = createLineTestNetwork2(); + const VoltageLevel& vl = network.getVoltageLevel("VL1"); + BOOST_CHECK_EQUAL(1UL, boost::size(vl.getConnectables())); +} + BOOST_AUTO_TEST_SUITE_END() } // namespace iidm From 03133fda27ab390a06119afcef64ba9e58efb3dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20LAIGRE?= Date: Tue, 21 Jul 2020 10:24:16 +0200 Subject: [PATCH 2/4] Add test with VoltageLevel::getConnectableCount MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sébastien LAIGRE --- test/iidm/VoltageLevelTest.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/iidm/VoltageLevelTest.cpp b/test/iidm/VoltageLevelTest.cpp index 4264783d6..7d441d16c 100644 --- a/test/iidm/VoltageLevelTest.cpp +++ b/test/iidm/VoltageLevelTest.cpp @@ -197,6 +197,7 @@ BOOST_AUTO_TEST_CASE(getConnectablesCheckUnique) { const Network network = createLineTestNetwork2(); const VoltageLevel& vl = network.getVoltageLevel("VL1"); BOOST_CHECK_EQUAL(1UL, boost::size(vl.getConnectables())); + BOOST_CHECK_EQUAL(1UL, vl.getConnectableCount()); } BOOST_AUTO_TEST_SUITE_END() From 9d05f886059f68894976ef5630dec2d8608ae4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20LAIGRE?= Date: Thu, 30 Jul 2020 07:58:46 +0200 Subject: [PATCH 3/4] Call to boost::size to get the number of 2WT, 3WT and Connectables from a VL/substation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sébastien LAIGRE --- include/powsybl/iidm/VoltageLevel.hxx | 5 +---- src/iidm/Substation.cpp | 12 ++---------- src/iidm/VoltageLevel.cpp | 5 +---- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/include/powsybl/iidm/VoltageLevel.hxx b/include/powsybl/iidm/VoltageLevel.hxx index c7fe85c2a..c322fd072 100644 --- a/include/powsybl/iidm/VoltageLevel.hxx +++ b/include/powsybl/iidm/VoltageLevel.hxx @@ -71,10 +71,7 @@ stdcxx::Reference VoltageLevel::getConnectable(const std::string& id) { template unsigned long VoltageLevel::getConnectableCount() const { - const auto& terminals = getTerminals(); - return std::count_if(std::begin(terminals), std::end(terminals), [](const Terminal& terminal) { - return Terminal::isInstanceOf(terminal); - }); + return boost::size(getConnectables()); } template diff --git a/src/iidm/Substation.cpp b/src/iidm/Substation.cpp index a74c8ffe7..889fbccdf 100644 --- a/src/iidm/Substation.cpp +++ b/src/iidm/Substation.cpp @@ -54,11 +54,7 @@ Network& Substation::getNetwork() { } unsigned long Substation::getThreeWindingsTransformerCount() const { - unsigned long res = 0UL; - for (const auto& it : m_voltageLevels) { - res += it.get().getConnectableCount(); - } - return res / 3UL; + return boost::size(getThreeWindingsTransformers()); } stdcxx::const_range Substation::getThreeWindingsTransformers() const { @@ -86,11 +82,7 @@ const std::string& Substation::getTso() const { } unsigned long Substation::getTwoWindingsTransformerCount() const { - unsigned long res = 0UL; - for (const auto& it : m_voltageLevels) { - res += it.get().getConnectableCount(); - } - return res / 2UL; + return boost::size(getTwoWindingsTransformers()); } stdcxx::const_range Substation::getTwoWindingsTransformers() const { diff --git a/src/iidm/VoltageLevel.cpp b/src/iidm/VoltageLevel.cpp index 7e56edffe..8f8e2bfda 100644 --- a/src/iidm/VoltageLevel.cpp +++ b/src/iidm/VoltageLevel.cpp @@ -54,10 +54,7 @@ stdcxx::range VoltageLevel::getBatteries() { } unsigned long VoltageLevel::getConnectableCount() const { - const auto& terminals = getTerminals(); - return std::count_if(std::begin(terminals), std::end(terminals), [](const Terminal& terminal) { - return terminal.getConnectable(); - }); + return boost::size(getConnectables()); } unsigned long VoltageLevel::getDanglingLineCount() const { From 6d11427bbb524120b87a58acc6159a7466641601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20LAIGRE?= Date: Fri, 7 Aug 2020 12:29:08 +0200 Subject: [PATCH 4/4] Use default template argument for VoltageLevel::getConnectable*() and add tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sébastien LAIGRE --- include/powsybl/iidm/VoltageLevel.hpp | 8 +++----- src/iidm/VoltageLevel.cpp | 4 ---- test/iidm/VoltageLevelTest.cpp | 3 +++ 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/include/powsybl/iidm/VoltageLevel.hpp b/include/powsybl/iidm/VoltageLevel.hpp index ec8de3e36..5d6792307 100644 --- a/include/powsybl/iidm/VoltageLevel.hpp +++ b/include/powsybl/iidm/VoltageLevel.hpp @@ -85,15 +85,13 @@ class VoltageLevel : public Container, public MultiVariantObject { template ::value>::type> stdcxx::Reference getConnectable(const std::string& id); - template ::value>::type> - unsigned long getConnectableCount() const; - + template ::value>::type> unsigned long getConnectableCount() const; - template ::value>::type> + template ::value>::type> stdcxx::const_range getConnectables() const; - template ::value>::type> + template ::value>::type> stdcxx::range getConnectables(); unsigned long getDanglingLineCount() const; diff --git a/src/iidm/VoltageLevel.cpp b/src/iidm/VoltageLevel.cpp index 8f8e2bfda..56aa64e34 100644 --- a/src/iidm/VoltageLevel.cpp +++ b/src/iidm/VoltageLevel.cpp @@ -53,10 +53,6 @@ stdcxx::range VoltageLevel::getBatteries() { return getConnectables(); } -unsigned long VoltageLevel::getConnectableCount() const { - return boost::size(getConnectables()); -} - unsigned long VoltageLevel::getDanglingLineCount() const { return getConnectableCount(); } diff --git a/test/iidm/VoltageLevelTest.cpp b/test/iidm/VoltageLevelTest.cpp index 7d441d16c..0b334c4ff 100644 --- a/test/iidm/VoltageLevelTest.cpp +++ b/test/iidm/VoltageLevelTest.cpp @@ -198,6 +198,9 @@ BOOST_AUTO_TEST_CASE(getConnectablesCheckUnique) { const VoltageLevel& vl = network.getVoltageLevel("VL1"); BOOST_CHECK_EQUAL(1UL, boost::size(vl.getConnectables())); BOOST_CHECK_EQUAL(1UL, vl.getConnectableCount()); + + BOOST_CHECK_EQUAL(1UL, boost::size(vl.getConnectables())); + BOOST_CHECK_EQUAL(1UL, vl.getConnectableCount()); } BOOST_AUTO_TEST_SUITE_END()