-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add three windings transformer contingency (#1761)
Signed-off-by: yichen88 <[email protected]>
- Loading branch information
Showing
16 changed files
with
318 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...ngency-api/src/main/java/com/powsybl/contingency/ThreeWindingsTransformerContingency.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...ncy-api/src/main/java/com/powsybl/contingency/tasks/ThreeWindingsTransformerTripping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...cy-api/src/test/java/com/powsybl/contingency/ThreeWindingsTransformerContingencyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...api/src/test/java/com/powsybl/contingency/tasks/ThreeWindingsTransformerTrippingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.