Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple connect/disconnect in NodeBreakerVoltageLevel (#285) #324

Merged
merged 2 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/iidm/NodeBreakerVoltageLevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ void NodeBreakerVoltageLevel::clean() {
bool NodeBreakerVoltageLevel::connect(Terminal& terminal) {
auto& nodeTerminal = dynamic_cast<NodeTerminal&>(terminal);

if (terminal.isConnected()) {
return false;
}

unsigned long node = nodeTerminal.getNode();

// find all paths starting from the current terminal to a busbar section that does not contain an open disconnector
Expand Down Expand Up @@ -141,6 +145,10 @@ void NodeBreakerVoltageLevel::detach(Terminal& terminal) {
bool NodeBreakerVoltageLevel::disconnect(Terminal& terminal) {
auto& nodeTerminal = dynamic_cast<NodeTerminal&>(terminal);

if (!terminal.isConnected()) {
return false;
}

unsigned long node = nodeTerminal.getNode();

// find all paths starting from the current terminal to a busbar section that does not contain an open disconnector
Expand Down
1 change: 1 addition & 0 deletions test/iidm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(UNIT_TEST_SOURCES
NetworkFactory.cpp
NetworkIndexTest.cpp
NetworkTest.cpp
NodeBreakerConnectTest.cpp
NodeBreakerVoltageLevelTest.cpp
PhaseTapChangerTest.cpp
RatioTapChangerTest.cpp
Expand Down
182 changes: 182 additions & 0 deletions test/iidm/NodeBreakerConnectTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/**
* 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/.
*/

#include <boost/test/unit_test.hpp>

#include <powsybl/iidm/Generator.hpp>
#include <powsybl/iidm/GeneratorAdder.hpp>
#include <powsybl/iidm/Load.hpp>
#include <powsybl/iidm/LoadAdder.hpp>
#include <powsybl/iidm/Network.hpp>
#include <powsybl/iidm/Substation.hpp>
#include <powsybl/iidm/SubstationAdder.hpp>
#include <powsybl/iidm/Switch.hpp>
#include <powsybl/iidm/SwitchAdder.hpp>
#include <powsybl/iidm/TopologyKind.hpp>
#include <powsybl/iidm/VoltageLevel.hpp>
#include <powsybl/iidm/VoltageLevelAdder.hpp>

namespace powsybl {

namespace iidm {

/**
* <pre>
* LD G
* | B1 |
* |---[+]---|
* B2 [-] [+] B3
* | C |
* BBS1 --------[-]-------- BBS2
* </pre>
*/
Network createNbkNetwork() {
Network network("test", "test");
Substation& s = network.newSubstation()
.setId("S")
.setCountry(Country::FR)
.add();
VoltageLevel& vl = s.newVoltageLevel()
.setId("VL")
.setNominalV(400.0)
.setTopologyKind(TopologyKind::NODE_BREAKER)
.add();
vl.getNodeBreakerView().newBusbarSection()
.setId("BBS1")
.setNode(0)
.add();
vl.getNodeBreakerView().newBusbarSection()
.setId("BBS2")
.setNode(1)
.add();
vl.getNodeBreakerView().newBreaker()
.setId("C")
.setNode1(1)
.setNode2(0)
.setOpen(true)
.add();
vl.getNodeBreakerView().newBreaker()
.setId("B2")
.setNode1(0)
.setNode2(2)
.setOpen(true)
.add();
vl.getNodeBreakerView().newBreaker()
.setId("B1")
.setNode1(2)
.setNode2(3)
.setOpen(false)
.add();
vl.getNodeBreakerView().newBreaker()
.setId("B3")
.setNode1(3)
.setNode2(1)
.setOpen(false)
.add();
vl.newLoad()
.setId("LD")
.setNode(2)
.setP0(1)
.setQ0(1)
.add();
vl.newGenerator()
.setId("G")
.setNode(3)
.setMinP(-9999.99)
.setMaxP(9999.99)
.setVoltageRegulatorOn(true)
.setTargetV(400)
.setTargetP(1)
.setTargetQ(0)
.add();
return network;
}

/**
* <pre>
* L
* |
* ---1---
* | |
* BR1 BR2
* | |
* ---0--- BBS1
* </pre>
*/
Network createDiamondNetwork() {
Network network("test", "test");
Substation& s = network.newSubstation()
.setId("S")
.setCountry(Country::FR)
.add();
VoltageLevel& vl = s.newVoltageLevel()
.setId("VL")
.setNominalV(400.0)
.setTopologyKind(TopologyKind::NODE_BREAKER)
.add();
vl.getNodeBreakerView().newBusbarSection()
.setId("BBS1")
.setNode(0)
.add();
vl.newLoad()
.setId("L")
.setNode(1)
.setP0(1)
.setQ0(1)
.add();
vl.getNodeBreakerView().newBreaker()
.setId("BR1")
.setNode1(1)
.setNode2(0)
.setOpen(false)
.add();
vl.getNodeBreakerView().newBreaker()
.setId("BR2")
.setNode1(1)
.setNode2(0)
.setOpen(false)
.add();
return network;
}

BOOST_AUTO_TEST_SUITE(NetworkTestSuite)

BOOST_AUTO_TEST_CASE(NodeBreakerConnectConnectedLoad) {
Network network = createNbkNetwork();
Load& l = network.getLoad("LD");
BOOST_CHECK(l.getTerminal().isConnected());
BOOST_CHECK(network.getSwitch("B2").isOpen());

l.getTerminal().connect();
BOOST_CHECK(network.getSwitch("B2").isOpen());
BOOST_CHECK(l.getTerminal().isConnected());
}

BOOST_AUTO_TEST_CASE(NodeBreakerDisconnectDisconnectedLoad) {
Network network = createNbkNetwork();
network.getSwitch("B3").setOpen(true);
Load& l = network.getLoad("LD");
BOOST_CHECK(!l.getTerminal().isConnected());

l.getTerminal().disconnect();
BOOST_CHECK(!network.getSwitch("B1").isOpen());
BOOST_CHECK(!l.getTerminal().isConnected());
}

BOOST_AUTO_TEST_CASE(NodeBreakerDisconnectionDiamond) {
Network network = createDiamondNetwork();
Load& l = network.getLoad("L");
BOOST_CHECK(l.getTerminal().isConnected());
l.getTerminal().disconnect();
BOOST_CHECK(!l.getTerminal().isConnected());
}

BOOST_AUTO_TEST_SUITE_END()

} // namespace iidm

} // namespace powsybl