Skip to content

Commit 421066b

Browse files
authored
Add contingency branch filter to network crac creator (#1660)
1 parent 015cdcd commit 421066b

4 files changed

Lines changed: 30 additions & 2 deletions

File tree

data/crac/crac-io/crac-io-network/src/main/java/com/powsybl/openrao/data/crac/io/network/NetworkCracCreator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ private static void addInstants(Crac crac, SortedMap<InstantKind, List<String>>
7272

7373
private static void addContingencies(Crac crac, Network network, Contingencies parameters) {
7474
network.getBranchStream().filter(b ->
75-
Utils.branchIsInCountries(b, parameters.getCountries().orElse(null))
76-
&& Utils.branchIsInVRange(b, parameters.getMinV(), parameters.getMaxV()))
75+
parameters.isBranchFiltered(b)
76+
&& Utils.branchIsInCountries(b, parameters.getCountries().orElse(null))
77+
&& Utils.branchIsInVRange(b, parameters.getMinV(), parameters.getMaxV()))
7778
.forEach(
7879
branch -> crac.newContingency()
7980
.withId("CO_" + branch.getNameOrId())

data/crac/crac-io/crac-io-network/src/main/java/com/powsybl/openrao/data/crac/io/network/parameters/Contingencies.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77

88
package com.powsybl.openrao.data.crac.io.network.parameters;
99

10+
import com.powsybl.iidm.network.Branch;
11+
1012
import javax.annotation.Nullable;
13+
import java.util.Objects;
1114
import java.util.Optional;
15+
import java.util.function.Predicate;
1216

1317
/**
1418
* Indicates what elements to simulate as contingencies (N-1).
@@ -17,6 +21,7 @@
1721
*/
1822
public class Contingencies extends AbstractCountriesFilter {
1923
private MinAndMax<Double> minAndMaxV = new MinAndMax<>(null, null);
24+
private Predicate<Branch<?>> branchFilter = branch -> true;
2025

2126
Contingencies() {
2227
}
@@ -37,4 +42,12 @@ public Optional<Double> getMaxV() {
3742
public void setMinAndMaxV(@Nullable Double minV, @Nullable Double maxV) {
3843
this.minAndMaxV = new MinAndMax<>(minV, maxV);
3944
}
45+
46+
public void setBranchFilter(Predicate<Branch<?>> branchFilter) {
47+
this.branchFilter = Objects.requireNonNull(branchFilter);
48+
}
49+
50+
public boolean isBranchFiltered(Branch<?> branch) {
51+
return branchFilter.test(branch);
52+
}
4053
}

data/crac/crac-io/crac-io-network/src/test/java/com/powsybl/openrao/data/crac/io/network/NetworkCracCreatorTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ void testUcteCnecsFiltered() {
152152
assertNull(crac.getFlowCnec("BBE2AA1 FFR3AA1 1_CO_NNL1AA1 NNL2AA1 1_outage"));
153153
}
154154

155+
@Test
156+
void testImportUcteContingencyBranchFiltered() {
157+
parameters.getContingencies().setBranchFilter(b -> b.getId().startsWith("F"));
158+
importCracFrom("TestCase12Nodes.uct");
159+
assertTrue(creationContext.isCreationSuccessful());
160+
assertNotNull(crac);
161+
assertEquals(4, crac.getContingencies().size());
162+
assertEquals(136, crac.getFlowCnecs().size());
163+
assertEquals(2, crac.getPstRangeActions().size());
164+
assertEquals(24, crac.getInjectionRangeActions().size());
165+
}
166+
155167
@Test
156168
void testUctePstsFiltered1() {
157169
parameters.getPstRangeActions().setCountryFilter(Set.of(Country.FR));

docs/input-data/crac/crac-generator.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ By default, all branches of the network are declared as contingencies. Only N-1
4646
You can set the following extra filters:
4747
- countries: an optional set of countries to choose the branches in. If left empty, all branches in the network are considered. If set to an empty set, no country will be considered.
4848
- minAndMaxV: the nominal voltage range in which the branches will be considered as contingency elements. If min and or max is left empty, it will be ignored.
49+
- branchFilter: a predicate to filter branches based on their properties. If left empty, all branches are considered as contingency elements.
4950

5051
::::{tabs}
5152
:::{group-tab} JAVA creation API
5253
~~~java
5354
networkCracCreationParameters.getContingencies().setCountries(Set.of(Country.FR, Country.BE)); // only branches in France & Belgium are considered as contingency elements
5455
networkCracCreationParameters.getContingencies().setMinAndMaxV(150, null); // only branches above 150kV are considered ad contingency elements
56+
networkCracCreationParameters.getContingencies().setBranchFilter(branch -> branch.getId().startsWith("A")); // only branches starting with A are considered as contingency elements
5557
~~~
5658
:::
5759
::::

0 commit comments

Comments
 (0)