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 network corruption when second node already used #1978

Merged
merged 1 commit into from
Feb 18, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,14 @@ private void checkTerminal(TerminalExt terminal) {
"voltage level " + NodeBreakerVoltageLevel.this.id + " has a node/breaker topology"
+ ", a node connection should be specified instead of a bus connection");
}
int node = ((NodeTerminal) terminal).getNode();
graph.addVertexIfNotPresent(node);
if (graph.getVertexObject(node) != null) {
throw new ValidationException(terminal.getConnectable(),
"an equipment (" + graph.getVertexObject(node).getConnectable().getId()
+ ") is already connected to node " + node + " of voltage level "
+ NodeBreakerVoltageLevel.this.id);
}
}

@Override
Expand All @@ -962,13 +970,6 @@ public void attach(TerminalExt terminal, boolean test) {
return;
}
int node = ((NodeTerminal) terminal).getNode();
graph.addVertexIfNotPresent(node);
if (graph.getVertexObject(node) != null) {
throw new ValidationException(terminal.getConnectable(),
"an equipment (" + graph.getVertexObject(node).getConnectable().getId()
+ ") is already connected to node " + node + " of voltage level "
+ NodeBreakerVoltageLevel.this.id);
}

// create the link terminal <-> voltage level
terminal.setVoltageLevel(NodeBreakerVoltageLevel.this);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright (c) 2022, 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/.
*/
package com.powsybl.iidm.network.impl.tck;

import com.powsybl.iidm.network.tck.AbstractCorruptedNetworkWhenSecondNodeAlreadyUsed;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class CorruptedNetworkWhenSecondNodeAlreadyUsed extends AbstractCorruptedNetworkWhenSecondNodeAlreadyUsed {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Copyright (c) 2022, 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/.
*/
package com.powsybl.iidm.network.tck;

import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.*;
import org.junit.Test;

import static org.junit.Assert.*;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public abstract class AbstractCorruptedNetworkWhenSecondNodeAlreadyUsed {

@Test
public void shouldNotInsertTheTransformer() {
Network network = Network.create("test", "");
Substation s = network.newSubstation()
.setId("S1")
.add();
s.newVoltageLevel()
.setId("VL1")
.setNominalV(1)
.setTopologyKind(TopologyKind.NODE_BREAKER)
.add();
VoltageLevel vl2 = s.newVoltageLevel()
.setId("VL2")
.setNominalV(1)
.setTopologyKind(TopologyKind.NODE_BREAKER)
.add();
vl2.getNodeBreakerView().newBusbarSection()
.setId("BBS")
.setNode(0)
.add();
try {
s.newTwoWindingsTransformer()
.setId("TR")
.setVoltageLevel1("VL1")
.setNode1(0)
.setVoltageLevel2("VL2")
.setNode2(0) // already taken by BBS
.setR(0)
.setX(1)
.setB(1)
.setG(0)
.setRatedU1(1)
.setRatedU2(1)
.add();
} catch (PowsyblException ignored) {
}

TwoWindingsTransformer twt = network.getTwoWindingsTransformer("TR");
assertNull(twt);
assertEquals(0, s.getTwoWindingsTransformerCount());
}
}