Skip to content

Commit

Permalink
Add three windings transformer contingency (#1761)
Browse files Browse the repository at this point in the history
Signed-off-by: yichen88 <[email protected]>
  • Loading branch information
yichen88 authored Jun 10, 2021
1 parent f7d1bd3 commit 2a757fb
Show file tree
Hide file tree
Showing 16 changed files with 318 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ boolean isValid(Network network) {
valid = checkTwoWindingsTransformerContingency(this, (TwoWindingsTransformerContingency) element, network);
break;

case THREE_WINDINGS_TRANSFORMER:
valid = checkThreeWindingsTransformerContingency(this, (ThreeWindingsTransformerContingency) element, network);
break;

default:
throw new AssertionError("Unknown contingency element type " + element.getType());
}
Expand Down Expand Up @@ -220,6 +224,14 @@ private static boolean checkDanglingLineContingency(Contingency contingency, Dan
return true;
}

private static boolean checkThreeWindingsTransformerContingency(Contingency contingency, ThreeWindingsTransformerContingency element, Network network) {
if (network.getThreeWindingsTransformer(element.getId()) == null) {
LOGGER.warn("ThreeWindingsTransformer '{}' of contingency '{}' not found", element.getId(), contingency.getId());
return false;
}
return true;
}

public static ContingencyBuilder builder(String id) {
return new ContingencyBuilder(id);
}
Expand Down Expand Up @@ -275,4 +287,8 @@ public static Contingency twoWindingsTransformer(String id, String voltageLevelI
public static Contingency danglingLine(String id) {
return builder(id).addDanglingLine(id).build();
}

public static Contingency threeWindingsTransformer(String id) {
return builder(id).addThreeWindingsTransformer(id).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,9 @@ public ContingencyBuilder addDanglingLine(String id) {
elements.add(new DanglingLineContingency(id));
return this;
}

public ContingencyBuilder addThreeWindingsTransformer(String id) {
elements.add(new ThreeWindingsTransformerContingency(id));
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ public enum ContingencyElementType {
BUSBAR_SECTION,
DANGLING_LINE,
LINE,
TWO_WINDINGS_TRANSFORMER
TWO_WINDINGS_TRANSFORMER,
THREE_WINDINGS_TRANSFORMER
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* 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/.
*/
package com.powsybl.contingency;

import com.powsybl.contingency.tasks.AbstractTrippingTask;
import com.powsybl.contingency.tasks.ThreeWindingsTransformerTripping;

import java.util.Objects;

/**
* @author Yichen TANG <yichen.tang at rte-france.com>
*/
public class ThreeWindingsTransformerContingency implements ContingencyElement {

private final String id;

public ThreeWindingsTransformerContingency(String id) {
this.id = Objects.requireNonNull(id);
}

@Override
public String getId() {
return id;
}

@Override
public ContingencyElementType getType() {
return ContingencyElementType.THREE_WINDINGS_TRANSFORMER;
}

@Override
public AbstractTrippingTask toTask() {
return new ThreeWindingsTransformerTripping(id);
}

@Override
public boolean equals(Object o) {
if (o instanceof ThreeWindingsTransformerContingency) {
ThreeWindingsTransformerContingency that = (ThreeWindingsTransformerContingency) o;
return Objects.equals(id, that.id);
}
return false;
}

@Override
public int hashCode() {
return Objects.hash(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public ContingencyElement deserialize(JsonParser parser, DeserializationContext
case TWO_WINDINGS_TRANSFORMER:
return new TwoWindingsTransformerContingency(id, voltageLevelId);

case THREE_WINDINGS_TRANSFORMER:
return new ThreeWindingsTransformerContingency(id);

default:
throw new AssertionError("Unexpected ContingencyElementType value: " + type);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* 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/.
*/
package com.powsybl.contingency.tasks;

import com.powsybl.commons.PowsyblException;
import com.powsybl.computation.ComputationManager;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.Switch;
import com.powsybl.iidm.network.Terminal;
import com.powsybl.iidm.network.ThreeWindingsTransformer;

import java.util.Objects;
import java.util.Set;

/**
* @author Yichen TANG <yichen.tang at rte-france.com>
*/
public class ThreeWindingsTransformerTripping extends AbstractTrippingTask {

private final String id;

public ThreeWindingsTransformerTripping(String id) {
this.id = Objects.requireNonNull(id);
}

@Override
public void traverse(Network network, ComputationManager computationManager, Set<Switch> switchesToOpen, Set<Terminal> terminalsToDisconnect) {
Objects.requireNonNull(network);

ThreeWindingsTransformer twt3 = network.getThreeWindingsTransformer(id);
if (twt3 == null) {
throw createNotFoundException();
}
ContingencyTopologyTraverser.traverse(twt3.getLeg1().getTerminal(), switchesToOpen, terminalsToDisconnect);
ContingencyTopologyTraverser.traverse(twt3.getLeg2().getTerminal(), switchesToOpen, terminalsToDisconnect);
ContingencyTopologyTraverser.traverse(twt3.getLeg3().getTerminal(), switchesToOpen, terminalsToDisconnect);
}

protected PowsyblException createNotFoundException() {
return new PowsyblException("ThreeWindingsTransformer '" + id + "' not found");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public TwoWindingsTransformerTripping(String lineId, String voltageLevelId) {

@Override
protected PowsyblException createNotFoundException() {
return new PowsyblException("Two windings transformer '" + getBranchId() + "' not found");
return new PowsyblException("Two windings transformer '" + getBranchId() + "' not found");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import com.powsybl.contingency.tasks.CompoundModificationTask;
import com.powsybl.contingency.tasks.ModificationTask;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.test.DanglingLineNetworkFactory;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.iidm.network.test.HvdcTestNetwork;
import com.powsybl.iidm.network.test.SvcTestCaseFactory;
import com.powsybl.iidm.network.test.*;
import org.junit.Test;

import java.util.Arrays;
Expand Down Expand Up @@ -140,4 +137,20 @@ public void validationTestForDL() {
.map(Contingency::getId)
.collect(Collectors.toList()));
}

@Test
public void validationTestForTwt3() {
var network = ThreeWindingsTransformerNetworkFactory.create();
var twt3Contingency = Contingency.builder("Twt3 contingency").addThreeWindingsTransformer("3WT").build();
var invalidContingency = Contingency.builder("Twt3 invalid contingency").addThreeWindingsTransformer("3WT_THAT_DO_NOT_EXIST").build();
var validContingencies = ContingencyList.of(twt3Contingency, invalidContingency).getContingencies(network);
var expectedIds = Collections.singletonList("Twt3 contingency");

assertEquals(expectedIds, validContingencies.stream().map(Contingency::getId).collect(Collectors.toList()));
assertEquals(expectedIds,
ContingencyList.getValidContingencies(Arrays.asList(twt3Contingency, invalidContingency), network)
.stream()
.map(Contingency::getId)
.collect(Collectors.toList()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* 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/.
*/
package com.powsybl.contingency;

import com.google.common.testing.EqualsTester;
import com.powsybl.contingency.tasks.ThreeWindingsTransformerTripping;
import org.junit.Test;

import static org.junit.Assert.*;

/**
* @author Yichen TANG <yichen.tang at rte-france.com>
*/
public class ThreeWindingsTransformerContingencyTest {

@Test
public void test() {
var twt3Contingency = new ThreeWindingsTransformerContingency("twt3");
assertEquals("twt3", twt3Contingency.getId());
assertEquals(ContingencyElementType.THREE_WINDINGS_TRANSFORMER, twt3Contingency.getType());

assertNotNull(twt3Contingency.toTask());
assertTrue(twt3Contingency.toTask() instanceof ThreeWindingsTransformerTripping);

new EqualsTester()
.addEqualityGroup(new ThreeWindingsTransformerContingency("foo"), new ThreeWindingsTransformerContingency("foo"))
.addEqualityGroup(new ThreeWindingsTransformerContingency("bar"), new ThreeWindingsTransformerContingency("bar"))
.testEquals();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private static Contingency create() {
.addDanglingLine("DL1")
.addLine("LINE1")
.addTwoWindingsTransformer("TRANSFO1")
.addThreeWindingsTransformer("TWT3")
.build();

contingency.addExtension(DummyExtension.class, new DummyExtension());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public void lineTrippingTest() {

assertFalse(line.getTerminal1().isConnected());
assertFalse(line.getTerminal2().isConnected());

Exception e1 = assertThrows(PowsyblException.class, () -> Contingency.line("NOT_EXISTS").toTask().modify(network, null));
assertEquals("Line 'NOT_EXISTS' not found", e1.getMessage());

Exception e2 = assertThrows(PowsyblException.class, () -> Contingency.line("NHV1_NHV2_1", "NOT_EXISTS_VL").toTask().modify(network, null));
assertEquals("VoltageLevel 'NOT_EXISTS_VL' not connected to line 'NHV1_NHV2_1'", e2.getMessage());
}

@Test
Expand All @@ -67,6 +73,11 @@ public void transformerTrippingTest() {

assertFalse(transformer.getTerminal1().isConnected());
assertFalse(transformer.getTerminal2().isConnected());

Exception e1 = assertThrows(PowsyblException.class, () -> Contingency.twoWindingsTransformer("NOT_EXISTS").toTask().modify(network, null));
assertEquals("Two windings transformer 'NOT_EXISTS' not found", e1.getMessage());
Exception e2 = assertThrows(PowsyblException.class, () -> Contingency.twoWindingsTransformer("NHV2_NLOAD", "NOT_EXISTS_VL").toTask().modify(network, null));
assertEquals("VoltageLevel 'NOT_EXISTS_VL' not connected to the two windings transformer 'NHV2_NLOAD'", e2.getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void setUp() {
}

@Test
public void generatorTrippingTest() {
public void dlTrippingTest() {
assertTrue(network.getDanglingLine("DL").getTerminal().isConnected());

Contingency contingency = Contingency.danglingLine("DL");
Expand All @@ -41,7 +41,7 @@ public void generatorTrippingTest() {
}

@Test(expected = PowsyblException.class)
public void unknownShuntCompensatorTest() {
public void unknownDlTest() {
DanglingLineTripping tripping = new DanglingLineTripping("DL_THAT_DO_NOT_EXIST");
tripping.modify(network, null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* 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/.
*/
package com.powsybl.contingency.tasks;

import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.ThreeWindingsTransformer;
import com.powsybl.iidm.network.test.ThreeWindingsTransformerNetworkFactory;
import org.junit.Test;

import static org.junit.Assert.*;

/**
* @author Yichen TANG <yichen.tang at rte-france.com>
*/
public class ThreeWindingsTransformerTrippingTest extends AbstractTrippingTest {

@Test
public void test() {
var network = ThreeWindingsTransformerNetworkFactory.create();
ThreeWindingsTransformer twt3 = network.getThreeWindingsTransformer("3WT");
assertTrue(twt3.getLeg1().getTerminal().isConnected());
assertTrue(twt3.getLeg2().getTerminal().isConnected());
assertTrue(twt3.getLeg3().getTerminal().isConnected());
var tripping = new ThreeWindingsTransformerTripping("3WT");
tripping.modify(network, null);
assertFalse(twt3.getLeg1().getTerminal().isConnected());
assertFalse(twt3.getLeg2().getTerminal().isConnected());
assertFalse(twt3.getLeg3().getTerminal().isConnected());

var notExistsTripping = new ThreeWindingsTransformerTripping("NOT_EXISTS");
Exception e = assertThrows(PowsyblException.class, () -> notExistsTripping.modify(network, null));
assertEquals("ThreeWindingsTransformer 'NOT_EXISTS' not found", e.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
}, {
"id" : "TRANSFO1",
"type" : "TWO_WINDINGS_TRANSFORMER"
}, {
"id" : "TWT3",
"type" : "THREE_WINDINGS_TRANSFORMER"
} ],
"extensions" : {
"dummy-extension" : { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,23 @@ class ContingencyDslLoader extends DslLoader {
LOGGER.warn("Equipment '{}' of contingency '{}' not found", equipment, id)
valid = false
} else if (identifiable instanceof Line) {
builder.addLine(equipment);
builder.addLine(equipment)
} else if (identifiable instanceof TwoWindingsTransformer) {
builder.addTwoWindingsTransformer(equipment);
builder.addTwoWindingsTransformer(equipment)
} else if (identifiable instanceof HvdcLine) {
builder.addHvdcLine(equipment);
builder.addHvdcLine(equipment)
} else if (identifiable instanceof Generator) {
builder.addGenerator(equipment);
builder.addGenerator(equipment)
} else if (identifiable instanceof BusbarSection) {
builder.addBusbarSection(equipment);
builder.addBusbarSection(equipment)
} else if (identifiable instanceof ShuntCompensator) {
builder.addShuntCompensator(equipment);
builder.addShuntCompensator(equipment)
} else if (identifiable instanceof StaticVarCompensator) {
builder.addStaticVarCompensator(equipment);
builder.addStaticVarCompensator(equipment)
} else if (identifiable instanceof DanglingLine) {
builder.addDanglingLine(equipment);
builder.addDanglingLine(equipment)
} else if (identifiable instanceof ThreeWindingsTransformer) {
builder.addThreeWindingsTransformer(equipment)
} else {
LOGGER.warn("Equipment type {} not supported in contingencies", identifiable.getClass().name)
valid = false
Expand Down
Loading

0 comments on commit 2a757fb

Please sign in to comment.