countriesToCheck) {
diff --git a/iidm/iidm-criteria/src/main/java/com/powsybl/iidm/criteria/AtLeastOneNominalVoltageCriterion.java b/iidm/iidm-criteria/src/main/java/com/powsybl/iidm/criteria/AtLeastOneNominalVoltageCriterion.java
index 5d75d0892fb..e7fb50f37e7 100644
--- a/iidm/iidm-criteria/src/main/java/com/powsybl/iidm/criteria/AtLeastOneNominalVoltageCriterion.java
+++ b/iidm/iidm-criteria/src/main/java/com/powsybl/iidm/criteria/AtLeastOneNominalVoltageCriterion.java
@@ -11,6 +11,7 @@
import com.powsybl.iidm.criteria.translation.NetworkElement;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.IdentifiableType;
+import com.powsybl.iidm.network.ThreeSides;
import java.util.Arrays;
import java.util.Collections;
@@ -18,8 +19,10 @@
import java.util.Objects;
/**
- * Criterion checking that one of the nominal voltages of the network element, on whichever side,
+ *
Criterion checking that one of the nominal voltages of the network element
* is inside a {@link VoltageInterval}.
+ * When filter
is called with a non-null side
, the voltage level on this particular side
+ * should be inside the {@link VoltageInterval}. Else, the validation is performed on whichever side.
* @author Olivier Perrin {@literal }
*/
public class AtLeastOneNominalVoltageCriterion implements Criterion {
@@ -43,7 +46,12 @@ public boolean filter(Identifiable> identifiable, IdentifiableType type) {
@Override
public boolean filter(NetworkElement networkElement) {
- return filterNominalVoltages(getNominalVoltagesToCheck(networkElement));
+ return filter(networkElement, null);
+ }
+
+ @Override
+ public boolean filter(NetworkElement networkElement, ThreeSides side) {
+ return filterNominalVoltages(getNominalVoltagesToCheck(networkElement, side));
}
private List getNominalVoltagesToCheck(Identifiable> identifiable, IdentifiableType type) {
@@ -56,10 +64,12 @@ private List getNominalVoltagesToCheck(Identifiable> identifiable, Ide
};
}
- private List getNominalVoltagesToCheck(NetworkElement networkElement) {
- return Arrays.asList(networkElement.getNominalVoltage1().orElse(null),
- networkElement.getNominalVoltage2().orElse(null),
- networkElement.getNominalVoltage3().orElse(null));
+ private List getNominalVoltagesToCheck(NetworkElement networkElement, ThreeSides side) {
+ return side != null ?
+ Collections.singletonList(networkElement.getNominalVoltage(side).orElse(null)) :
+ Arrays.asList(networkElement.getNominalVoltage1().orElse(null),
+ networkElement.getNominalVoltage2().orElse(null),
+ networkElement.getNominalVoltage3().orElse(null));
}
private boolean filterNominalVoltages(List nominalVoltagesToCheck) {
diff --git a/iidm/iidm-criteria/src/main/java/com/powsybl/iidm/criteria/Criterion.java b/iidm/iidm-criteria/src/main/java/com/powsybl/iidm/criteria/Criterion.java
index d7e0d3153b7..93a28b2a387 100644
--- a/iidm/iidm-criteria/src/main/java/com/powsybl/iidm/criteria/Criterion.java
+++ b/iidm/iidm-criteria/src/main/java/com/powsybl/iidm/criteria/Criterion.java
@@ -10,6 +10,7 @@
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.IdentifiableType;
import com.powsybl.iidm.criteria.translation.NetworkElement;
+import com.powsybl.iidm.network.ThreeSides;
/**
* the purpose of these class is to filter contingencies in a criterion contingency list
@@ -45,4 +46,8 @@ default boolean filter(Identifiable> identifiable, IdentifiableType type) {
default boolean filter(NetworkElement networkElement) {
return false;
}
+
+ default boolean filter(NetworkElement networkElement, ThreeSides side) {
+ return filter(networkElement);
+ }
}
diff --git a/iidm/iidm-criteria/src/main/java/com/powsybl/iidm/criteria/NetworkElementVisitor.java b/iidm/iidm-criteria/src/main/java/com/powsybl/iidm/criteria/NetworkElementVisitor.java
index 3463343398f..d7297be8c6f 100644
--- a/iidm/iidm-criteria/src/main/java/com/powsybl/iidm/criteria/NetworkElementVisitor.java
+++ b/iidm/iidm-criteria/src/main/java/com/powsybl/iidm/criteria/NetworkElementVisitor.java
@@ -8,6 +8,7 @@
package com.powsybl.iidm.criteria;
import com.powsybl.iidm.criteria.translation.NetworkElement;
+import com.powsybl.iidm.network.ThreeSides;
/**
* Visitor used to detect if a given {@link NetworkElement} validates criteria.
@@ -16,22 +17,28 @@
public class NetworkElementVisitor {
private final NetworkElement networkElement;
+ private final ThreeSides side;
public NetworkElementVisitor(NetworkElement networkElement) {
+ this(networkElement, null);
+ }
+
+ public NetworkElementVisitor(NetworkElement networkElement, ThreeSides side) {
this.networkElement = networkElement;
+ this.side = side;
}
public boolean visit(AbstractNetworkElementEquipmentCriterion c) {
return networkElement.isValidFor(c.getNetworkElementCriterionType())
- && doRespectCriterion(networkElement, c.getCountryCriterion())
- && doRespectCriterion(networkElement, c.getNominalVoltageCriterion());
+ && doRespectCriterion(c.getCountryCriterion())
+ && doRespectCriterion(c.getNominalVoltageCriterion());
}
public boolean visit(NetworkElementIdListCriterion c) {
return c.getNetworkElementIds().contains(networkElement.getId());
}
- private boolean doRespectCriterion(NetworkElement networkElement, Criterion criterion) {
- return criterion == null || criterion.filter(networkElement);
+ private boolean doRespectCriterion(Criterion criterion) {
+ return criterion == null || criterion.filter(networkElement, side);
}
}
diff --git a/iidm/iidm-criteria/src/main/java/com/powsybl/iidm/criteria/translation/DefaultNetworkElementAdapter.java b/iidm/iidm-criteria/src/main/java/com/powsybl/iidm/criteria/translation/DefaultNetworkElementAdapter.java
index ed00fb4c5e8..351baae10ec 100644
--- a/iidm/iidm-criteria/src/main/java/com/powsybl/iidm/criteria/translation/DefaultNetworkElementAdapter.java
+++ b/iidm/iidm-criteria/src/main/java/com/powsybl/iidm/criteria/translation/DefaultNetworkElementAdapter.java
@@ -47,12 +47,17 @@ public String getId() {
@Override
public Optional getCountry1() {
- return getCountry(TwoSides.ONE);
+ return getCountry(ThreeSides.ONE);
}
@Override
public Optional getCountry2() {
- return getCountry(TwoSides.TWO);
+ return getCountry(ThreeSides.TWO);
+ }
+
+ @Override
+ public Optional getCountry3() {
+ return getCountry(ThreeSides.THREE);
}
@Override
@@ -60,16 +65,17 @@ public Optional getCountry() {
return getCountry1();
}
- private Optional getCountry(TwoSides side) {
+ @Override
+ public Optional getCountry(ThreeSides side) {
return switch (identifiable.getType()) {
- case LINE, TIE_LINE -> getCountryFromTerminal(((Branch>) identifiable).getTerminal(side));
- case HVDC_LINE -> getCountryFromTerminal(((HvdcLine) identifiable).getConverterStation(side).getTerminal());
+ case LINE, TIE_LINE -> side != ThreeSides.THREE ?
+ getCountryFromTerminal(((Branch>) identifiable).getTerminal(side.toTwoSides())) : Optional.empty();
+ case HVDC_LINE -> side != ThreeSides.THREE ?
+ getCountryFromTerminal(((HvdcLine) identifiable).getConverterStation(side.toTwoSides()).getTerminal()) : Optional.empty();
case DANGLING_LINE, GENERATOR, LOAD, BATTERY, SHUNT_COMPENSATOR, STATIC_VAR_COMPENSATOR, BUSBAR_SECTION, HVDC_CONVERTER_STATION ->
- side != TwoSides.ONE ? Optional.empty() : getCountryFromTerminal(((Injection>) identifiable).getTerminal());
- case TWO_WINDINGS_TRANSFORMER -> side != TwoSides.ONE ? Optional.empty() :
- ((TwoWindingsTransformer) identifiable).getSubstation().map(Substation::getNullableCountry);
- case THREE_WINDINGS_TRANSFORMER -> side != TwoSides.ONE ? Optional.empty() :
- ((ThreeWindingsTransformer) identifiable).getSubstation().map(Substation::getNullableCountry);
+ side != ThreeSides.ONE ? Optional.empty() : getCountryFromTerminal(((Injection>) identifiable).getTerminal());
+ case TWO_WINDINGS_TRANSFORMER -> ((TwoWindingsTransformer) identifiable).getSubstation().map(Substation::getNullableCountry);
+ case THREE_WINDINGS_TRANSFORMER -> ((ThreeWindingsTransformer) identifiable).getSubstation().map(Substation::getNullableCountry);
default -> Optional.empty();
};
}
@@ -99,7 +105,8 @@ public Optional getNominalVoltage() {
return getNominalVoltage1();
}
- private Optional getNominalVoltage(ThreeSides side) {
+ @Override
+ public Optional getNominalVoltage(ThreeSides side) {
return switch (identifiable.getType()) {
case DANGLING_LINE, GENERATOR, LOAD, BATTERY, SHUNT_COMPENSATOR, STATIC_VAR_COMPENSATOR, BUSBAR_SECTION, HVDC_CONVERTER_STATION ->
side != ThreeSides.ONE ? Optional.empty() :
diff --git a/iidm/iidm-criteria/src/main/java/com/powsybl/iidm/criteria/translation/NetworkElement.java b/iidm/iidm-criteria/src/main/java/com/powsybl/iidm/criteria/translation/NetworkElement.java
index a6d542f8a9e..35a297c7502 100644
--- a/iidm/iidm-criteria/src/main/java/com/powsybl/iidm/criteria/translation/NetworkElement.java
+++ b/iidm/iidm-criteria/src/main/java/com/powsybl/iidm/criteria/translation/NetworkElement.java
@@ -9,6 +9,7 @@
import com.powsybl.iidm.criteria.NetworkElementCriterion;
import com.powsybl.iidm.network.Country;
+import com.powsybl.iidm.network.ThreeSides;
import java.util.Optional;
@@ -25,14 +26,32 @@ public interface NetworkElement {
Optional getCountry2();
+ Optional getCountry3();
+
Optional getCountry();
+ default Optional getCountry(ThreeSides side) {
+ return switch (side) {
+ case ONE -> getCountry1();
+ case TWO -> getCountry2();
+ case THREE -> getCountry3();
+ };
+ }
+
Optional getNominalVoltage1();
Optional getNominalVoltage2();
Optional getNominalVoltage3();
+ default Optional getNominalVoltage(ThreeSides side) {
+ return switch (side) {
+ case ONE -> getNominalVoltage1();
+ case TWO -> getNominalVoltage2();
+ case THREE -> getNominalVoltage3();
+ };
+ }
+
Optional getNominalVoltage();
boolean isValidFor(NetworkElementCriterion.NetworkElementCriterionType networkElementCriterionType);
diff --git a/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/DanglingLineCriterionTest.java b/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/DanglingLineCriterionTest.java
index 73caf4c5df8..ab94633fb77 100644
--- a/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/DanglingLineCriterionTest.java
+++ b/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/DanglingLineCriterionTest.java
@@ -7,18 +7,19 @@
*/
package com.powsybl.iidm.criteria;
+import com.powsybl.iidm.criteria.translation.DefaultNetworkElementAdapter;
import com.powsybl.iidm.criteria.translation.NetworkElement;
import com.powsybl.iidm.network.Country;
+import com.powsybl.iidm.network.DanglingLine;
+import com.powsybl.iidm.network.ThreeSides;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.util.List;
-import java.util.Optional;
+import static com.powsybl.iidm.criteria.translation.DefaultNetworkElementAdapterTest.mockDanglingLine;
import static org.junit.jupiter.api.Assertions.*;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.mockito.Mockito.when;
/**
* @author Olivier Perrin {@literal }
@@ -46,10 +47,10 @@ void typeTest() {
@Test
void emptyCriterionTest() {
DanglingLineCriterion criterion = new DanglingLineCriterion(null, null);
- assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine1)));
- assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine2)));
- assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine3)));
- assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine4)));
+ assertCriterionTrue(criterion, danglingLine1);
+ assertCriterionTrue(criterion, danglingLine2);
+ assertCriterionTrue(criterion, danglingLine3);
+ assertCriterionTrue(criterion, danglingLine4);
NetworkElement anotherTypeElement = Mockito.mock(NetworkElement.class);
assertFalse(criterion.accept(new NetworkElementVisitor(anotherTypeElement)));
@@ -59,25 +60,25 @@ void emptyCriterionTest() {
void nominalVoltageTest() {
DanglingLineCriterion criterion = new DanglingLineCriterion(null, new SingleNominalVoltageCriterion(
VoltageInterval.between(40., 100., true, true)));
- assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine1)));
- assertFalse(criterion.accept(new NetworkElementVisitor(danglingLine2)));
- assertFalse(criterion.accept(new NetworkElementVisitor(danglingLine3)));
- assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine4)));
+ assertCriterionTrue(criterion, danglingLine1);
+ assertCriterionFalse(criterion, danglingLine2);
+ assertCriterionFalse(criterion, danglingLine3);
+ assertCriterionTrue(criterion, danglingLine4);
}
@Test
void countryTest() {
DanglingLineCriterion criterion = new DanglingLineCriterion(new SingleCountryCriterion(List.of(Country.BE)), null);
- assertFalse(criterion.accept(new NetworkElementVisitor(danglingLine1)));
- assertFalse(criterion.accept(new NetworkElementVisitor(danglingLine2)));
- assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine3)));
- assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine4)));
+ assertCriterionFalse(criterion, danglingLine1);
+ assertCriterionFalse(criterion, danglingLine2);
+ assertCriterionTrue(criterion, danglingLine3);
+ assertCriterionTrue(criterion, danglingLine4);
criterion = new DanglingLineCriterion(new SingleCountryCriterion(List.of(Country.FR, Country.BE)), null);
- assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine1)));
- assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine2)));
- assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine3)));
- assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine4)));
+ assertCriterionTrue(criterion, danglingLine1);
+ assertCriterionTrue(criterion, danglingLine2);
+ assertCriterionTrue(criterion, danglingLine3);
+ assertCriterionTrue(criterion, danglingLine4);
}
@Test
@@ -85,25 +86,25 @@ void mixedCriteriaTest() {
DanglingLineCriterion criterion = new DanglingLineCriterion(new SingleCountryCriterion(List.of(Country.FR)),
new SingleNominalVoltageCriterion(
VoltageInterval.between(350., 450., true, true)));
- assertFalse(criterion.accept(new NetworkElementVisitor(danglingLine1)));
- assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine2)));
- assertFalse(criterion.accept(new NetworkElementVisitor(danglingLine3)));
- assertFalse(criterion.accept(new NetworkElementVisitor(danglingLine4)));
+ assertCriterionFalse(criterion, danglingLine1);
+ assertCriterionTrue(criterion, danglingLine2);
+ assertCriterionFalse(criterion, danglingLine3);
+ assertCriterionFalse(criterion, danglingLine4);
+ }
+
+ private void assertCriterionTrue(DanglingLineCriterion criterion, NetworkElement danglingLine) {
+ assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine, ThreeSides.ONE)));
+ }
+
+ private void assertCriterionFalse(DanglingLineCriterion criterion, NetworkElement danglingLine) {
+ assertFalse(criterion.accept(new NetworkElementVisitor(danglingLine)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(danglingLine, ThreeSides.ONE)));
}
protected static NetworkElement createDanglingLine(String id, Country country, double nominalVoltage) {
- NetworkElement n = Mockito.mock(NetworkElement.class);
- when(n.getId()).thenReturn(id);
- when(n.getCountry()).thenReturn(Optional.of(country));
- when(n.getCountry1()).thenReturn(Optional.of(country));
- when(n.getCountry2()).thenReturn(Optional.empty());
- when(n.getNominalVoltage()).thenReturn(Optional.of(nominalVoltage));
- when(n.getNominalVoltage1()).thenReturn(Optional.of(nominalVoltage));
- when(n.getNominalVoltage2()).thenReturn(Optional.empty());
- when(n.getNominalVoltage3()).thenReturn(Optional.empty());
- when(n.isValidFor(NetworkElementCriterion.NetworkElementCriterionType.DANGLING_LINE)).thenReturn(true);
- when(n.isValidFor(NetworkElementCriterion.NetworkElementCriterionType.IDENTIFIABLE)).thenReturn(true);
- return n;
+ DanglingLine danglingLine = mockDanglingLine(id, country, nominalVoltage);
+ return new DefaultNetworkElementAdapter(danglingLine);
}
}
diff --git a/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/IdentifiableCriterionTest.java b/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/IdentifiableCriterionTest.java
index 7c549f46a37..6c46bffd98f 100644
--- a/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/IdentifiableCriterionTest.java
+++ b/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/IdentifiableCriterionTest.java
@@ -9,6 +9,7 @@
import com.powsybl.iidm.criteria.translation.NetworkElement;
import com.powsybl.iidm.network.Country;
+import com.powsybl.iidm.network.ThreeSides;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -75,46 +76,125 @@ void creationErrorsTest() {
}
@Test
- void nominalVoltageTest() {
+ void linesNominalVoltageTest() {
IdentifiableCriterion criterion = new IdentifiableCriterion(new AtLeastOneNominalVoltageCriterion(
- VoltageInterval.between(40., 100., true, true)));
+ VoltageInterval.between(80., 100., true, true)));
assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine1)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine1, ThreeSides.ONE)));
assertFalse(criterion.accept(new NetworkElementVisitor(danglingLine2)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(danglingLine2, ThreeSides.ONE)));
assertTrue(criterion.accept(new NetworkElementVisitor(line1)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(line1, ThreeSides.ONE)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(line1, ThreeSides.TWO)));
assertFalse(criterion.accept(new NetworkElementVisitor(line2)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(line2, ThreeSides.ONE)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(line2, ThreeSides.TWO)));
assertTrue(criterion.accept(new NetworkElementVisitor(tieLine1)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(tieLine1, ThreeSides.ONE)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(tieLine1, ThreeSides.TWO)));
assertFalse(criterion.accept(new NetworkElementVisitor(tieLine2)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(tieLine2, ThreeSides.ONE)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(tieLine2, ThreeSides.TWO)));
+ }
+
+ @Test
+ void transformersNominalVoltageTest() {
+ IdentifiableCriterion criterion = new IdentifiableCriterion(new AtLeastOneNominalVoltageCriterion(
+ VoltageInterval.between(80., 100., true, true)));
assertTrue(criterion.accept(new NetworkElementVisitor(twoWt1)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(twoWt1, ThreeSides.ONE)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(twoWt1, ThreeSides.TWO)));
assertFalse(criterion.accept(new NetworkElementVisitor(twoWt2)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(twoWt2, ThreeSides.ONE)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(twoWt2, ThreeSides.TWO)));
assertTrue(criterion.accept(new NetworkElementVisitor(threeWt1)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(threeWt1, ThreeSides.ONE)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(threeWt1, ThreeSides.TWO)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(threeWt1, ThreeSides.THREE)));
assertFalse(criterion.accept(new NetworkElementVisitor(threeWt2)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(threeWt2, ThreeSides.ONE)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(threeWt2, ThreeSides.TWO)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(threeWt2, ThreeSides.THREE)));
}
@Test
- void countriesTest() {
+ void lineOneCountryTest() {
IdentifiableCriterion criterion = new IdentifiableCriterion(new AtLeastOneCountryCriterion(List.of(Country.FR)));
assertFalse(criterion.accept(new NetworkElementVisitor(danglingLine1)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(danglingLine1, ThreeSides.ONE)));
assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine2)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine2, ThreeSides.ONE)));
assertFalse(criterion.accept(new NetworkElementVisitor(line1)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(line1, ThreeSides.ONE)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(line1, ThreeSides.TWO)));
assertTrue(criterion.accept(new NetworkElementVisitor(line2)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(line2, ThreeSides.ONE)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(line2, ThreeSides.TWO)));
assertFalse(criterion.accept(new NetworkElementVisitor(tieLine1)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(tieLine1, ThreeSides.ONE)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(tieLine1, ThreeSides.TWO)));
assertTrue(criterion.accept(new NetworkElementVisitor(tieLine2)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(tieLine2, ThreeSides.ONE)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(tieLine2, ThreeSides.TWO)));
+ }
+
+ @Test
+ void transformersOneCountryTest() {
+ IdentifiableCriterion criterion = new IdentifiableCriterion(new AtLeastOneCountryCriterion(List.of(Country.FR)));
assertFalse(criterion.accept(new NetworkElementVisitor(twoWt1)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(twoWt1, ThreeSides.ONE)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(twoWt1, ThreeSides.TWO)));
assertTrue(criterion.accept(new NetworkElementVisitor(twoWt2)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(twoWt2, ThreeSides.ONE)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(twoWt2, ThreeSides.TWO)));
assertFalse(criterion.accept(new NetworkElementVisitor(threeWt1)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(threeWt1, ThreeSides.ONE)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(threeWt1, ThreeSides.TWO)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(threeWt1, ThreeSides.THREE)));
assertTrue(criterion.accept(new NetworkElementVisitor(threeWt2)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(threeWt2, ThreeSides.ONE)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(threeWt2, ThreeSides.TWO)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(threeWt2, ThreeSides.THREE)));
+ }
- criterion = new IdentifiableCriterion(new AtLeastOneCountryCriterion(List.of(Country.FR, Country.BE)));
+ @Test
+ void linesTwoCountriesTest() {
+ IdentifiableCriterion criterion = new IdentifiableCriterion(new AtLeastOneCountryCriterion(List.of(Country.FR, Country.BE)));
assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine1)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine1, ThreeSides.ONE)));
assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine2)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(danglingLine2, ThreeSides.ONE)));
assertTrue(criterion.accept(new NetworkElementVisitor(line1)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(line1, ThreeSides.ONE)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(line1, ThreeSides.TWO)));
assertTrue(criterion.accept(new NetworkElementVisitor(line2)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(line2, ThreeSides.ONE)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(line2, ThreeSides.TWO)));
assertTrue(criterion.accept(new NetworkElementVisitor(tieLine1)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(tieLine1, ThreeSides.ONE)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(tieLine1, ThreeSides.TWO)));
assertTrue(criterion.accept(new NetworkElementVisitor(tieLine2)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(tieLine2, ThreeSides.ONE)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(tieLine2, ThreeSides.TWO)));
+ }
+
+ @Test
+ void transformersTwoCountriesTest() {
+ IdentifiableCriterion criterion = new IdentifiableCriterion(new AtLeastOneCountryCriterion(List.of(Country.FR, Country.BE)));
assertTrue(criterion.accept(new NetworkElementVisitor(twoWt1)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(twoWt1, ThreeSides.ONE)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(twoWt1, ThreeSides.TWO)));
assertTrue(criterion.accept(new NetworkElementVisitor(twoWt2)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(twoWt2, ThreeSides.ONE)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(twoWt2, ThreeSides.TWO)));
assertTrue(criterion.accept(new NetworkElementVisitor(threeWt1)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(threeWt1, ThreeSides.ONE)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(threeWt1, ThreeSides.TWO)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(threeWt1, ThreeSides.THREE)));
assertTrue(criterion.accept(new NetworkElementVisitor(threeWt2)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(threeWt2, ThreeSides.ONE)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(threeWt2, ThreeSides.TWO)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(threeWt2, ThreeSides.THREE)));
}
@Test
@@ -129,8 +209,12 @@ void mixedCriteriaTest() {
assertFalse(criterion.accept(new NetworkElementVisitor(tieLine2)));
assertFalse(criterion.accept(new NetworkElementVisitor(twoWt1)));
assertTrue(criterion.accept(new NetworkElementVisitor(twoWt2)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(twoWt2, ThreeSides.ONE)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(twoWt2, ThreeSides.TWO)));
assertFalse(criterion.accept(new NetworkElementVisitor(threeWt1)));
assertTrue(criterion.accept(new NetworkElementVisitor(threeWt2)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(threeWt2, ThreeSides.ONE)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(threeWt2, ThreeSides.TWO)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(threeWt2, ThreeSides.THREE)));
}
-
}
diff --git a/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/LineCriterionTest.java b/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/LineCriterionTest.java
index 8ac572c87ee..6fef4b3756b 100644
--- a/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/LineCriterionTest.java
+++ b/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/LineCriterionTest.java
@@ -7,17 +7,19 @@
*/
package com.powsybl.iidm.criteria;
-import com.powsybl.iidm.network.Country;
+import com.powsybl.iidm.criteria.translation.DefaultNetworkElementAdapter;
import com.powsybl.iidm.criteria.translation.NetworkElement;
+import com.powsybl.iidm.network.Country;
+import com.powsybl.iidm.network.Line;
+import com.powsybl.iidm.network.ThreeSides;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.util.List;
-import java.util.Optional;
+import static com.powsybl.iidm.criteria.translation.DefaultNetworkElementAdapterTest.mockLine;
import static org.junit.jupiter.api.Assertions.*;
-import static org.mockito.Mockito.when;
/**
* @author Olivier Perrin {@literal }
@@ -45,13 +47,13 @@ void typeTest() {
@Test
void emptyCriterionTest() {
LineCriterion criterion = new LineCriterion(null, null);
- assertTrue(criterion.accept(new NetworkElementVisitor(line1)));
- assertTrue(criterion.accept(new NetworkElementVisitor(line2)));
- assertTrue(criterion.accept(new NetworkElementVisitor(line3)));
- assertTrue(criterion.accept(new NetworkElementVisitor(line4)));
+ assertCriterionTrue(criterion, line1);
+ assertCriterionTrue(criterion, line2);
+ assertCriterionTrue(criterion, line3);
+ assertCriterionTrue(criterion, line4);
NetworkElement anotherTypeElement = Mockito.mock(NetworkElement.class);
- assertFalse(criterion.accept(new NetworkElementVisitor(anotherTypeElement)));
+ assertCriterionFalse(criterion, anotherTypeElement);
}
@Test
@@ -59,25 +61,25 @@ void nominalVoltageTest() {
LineCriterion criterion = new LineCriterion(null, new TwoNominalVoltageCriterion(
VoltageInterval.between(40., 100., true, true),
null));
- assertTrue(criterion.accept(new NetworkElementVisitor(line1)));
- assertFalse(criterion.accept(new NetworkElementVisitor(line2)));
- assertFalse(criterion.accept(new NetworkElementVisitor(line3)));
- assertTrue(criterion.accept(new NetworkElementVisitor(line4)));
+ assertCriterionTrue(criterion, line1);
+ assertCriterionFalse(criterion, line2);
+ assertCriterionFalse(criterion, line3);
+ assertCriterionTrue(criterion, line4);
}
@Test
void countriesTest() {
LineCriterion criterion = new LineCriterion(new TwoCountriesCriterion(List.of(Country.FR), List.of(Country.BE)), null);
- assertFalse(criterion.accept(new NetworkElementVisitor(line1)));
- assertFalse(criterion.accept(new NetworkElementVisitor(line2)));
- assertTrue(criterion.accept(new NetworkElementVisitor(line3)));
- assertFalse(criterion.accept(new NetworkElementVisitor(line4)));
+ assertCriterionFalse(criterion, line1);
+ assertCriterionFalse(criterion, line2);
+ assertCriterionTrue(criterion, line3);
+ assertCriterionFalse(criterion, line4);
criterion = new LineCriterion(new TwoCountriesCriterion(List.of(Country.FR, Country.BE), List.of(Country.BE)), null);
- assertFalse(criterion.accept(new NetworkElementVisitor(line1)));
- assertFalse(criterion.accept(new NetworkElementVisitor(line2)));
- assertTrue(criterion.accept(new NetworkElementVisitor(line3)));
- assertTrue(criterion.accept(new NetworkElementVisitor(line4)));
+ assertCriterionFalse(criterion, line1);
+ assertCriterionFalse(criterion, line2);
+ assertCriterionTrue(criterion, line3);
+ assertCriterionTrue(criterion, line4);
}
@Test
@@ -86,25 +88,27 @@ void mixedCriteriaTest() {
new TwoNominalVoltageCriterion(
VoltageInterval.between(350., 450., true, true),
null));
- assertFalse(criterion.accept(new NetworkElementVisitor(line1)));
- assertTrue(criterion.accept(new NetworkElementVisitor(line2)));
- assertFalse(criterion.accept(new NetworkElementVisitor(line3)));
- assertFalse(criterion.accept(new NetworkElementVisitor(line4)));
+ assertCriterionFalse(criterion, line1);
+ assertCriterionTrue(criterion, line2);
+ assertCriterionFalse(criterion, line3);
+ assertCriterionFalse(criterion, line4);
+ }
+
+ private void assertCriterionTrue(LineCriterion criterion, NetworkElement line) {
+ assertTrue(criterion.accept(new NetworkElementVisitor(line)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(line, ThreeSides.ONE)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(line, ThreeSides.TWO)));
+ }
+
+ private void assertCriterionFalse(LineCriterion criterion, NetworkElement line) {
+ assertFalse(criterion.accept(new NetworkElementVisitor(line)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(line, ThreeSides.ONE)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(line, ThreeSides.TWO)));
}
protected static NetworkElement createLine(String id, Country country1, Country country2, double nominalVoltage) {
- NetworkElement n = Mockito.mock(NetworkElement.class);
- when(n.getId()).thenReturn(id);
- when(n.getCountry()).thenReturn(Optional.of(country1));
- when(n.getCountry1()).thenReturn(Optional.of(country1));
- when(n.getCountry2()).thenReturn(Optional.of(country2));
- when(n.getNominalVoltage()).thenReturn(Optional.of(nominalVoltage));
- when(n.getNominalVoltage1()).thenReturn(Optional.of(nominalVoltage));
- when(n.getNominalVoltage2()).thenReturn(Optional.empty());
- when(n.getNominalVoltage3()).thenReturn(Optional.empty());
- when(n.isValidFor(NetworkElementCriterion.NetworkElementCriterionType.LINE)).thenReturn(true);
- when(n.isValidFor(NetworkElementCriterion.NetworkElementCriterionType.IDENTIFIABLE)).thenReturn(true);
- return n;
+ Line l = mockLine(id, country1, country2, nominalVoltage, nominalVoltage);
+ return new DefaultNetworkElementAdapter(l);
}
}
diff --git a/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/ThreeWindingsTransformerCriterionTest.java b/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/ThreeWindingsTransformerCriterionTest.java
index 487d5c2df16..8783ca87fee 100644
--- a/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/ThreeWindingsTransformerCriterionTest.java
+++ b/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/ThreeWindingsTransformerCriterionTest.java
@@ -7,17 +7,19 @@
*/
package com.powsybl.iidm.criteria;
-import com.powsybl.iidm.network.Country;
+import com.powsybl.iidm.criteria.translation.DefaultNetworkElementAdapter;
import com.powsybl.iidm.criteria.translation.NetworkElement;
+import com.powsybl.iidm.network.Country;
+import com.powsybl.iidm.network.ThreeSides;
+import com.powsybl.iidm.network.ThreeWindingsTransformer;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.util.List;
-import java.util.Optional;
+import static com.powsybl.iidm.criteria.translation.DefaultNetworkElementAdapterTest.mockThreeWindingsTransformer;
import static org.junit.jupiter.api.Assertions.*;
-import static org.mockito.Mockito.when;
/**
* @author Olivier Perrin {@literal }
@@ -43,12 +45,12 @@ void typeTest() {
@Test
void emptyCriterionTest() {
ThreeWindingsTransformerCriterion criterion = new ThreeWindingsTransformerCriterion(null, null);
- assertTrue(criterion.accept(new NetworkElementVisitor(twt1)));
- assertTrue(criterion.accept(new NetworkElementVisitor(twt2)));
- assertTrue(criterion.accept(new NetworkElementVisitor(twt3)));
+ assertCriterionTrue(criterion, twt1);
+ assertCriterionTrue(criterion, twt2);
+ assertCriterionTrue(criterion, twt3);
NetworkElement anotherTypeElement = Mockito.mock(NetworkElement.class);
- assertFalse(criterion.accept(new NetworkElementVisitor(anotherTypeElement)));
+ assertCriterionFalse(criterion, anotherTypeElement);
}
@Test
@@ -58,22 +60,22 @@ void nominalVoltagesTest() {
VoltageInterval.between(80., 100., true, true),
VoltageInterval.between(350., 550., true, true),
VoltageInterval.between(40., 70., true, true)));
- assertTrue(criterion.accept(new NetworkElementVisitor(twt1)));
- assertFalse(criterion.accept(new NetworkElementVisitor(twt2)));
- assertTrue(criterion.accept(new NetworkElementVisitor(twt3)));
+ assertCriterionTrue(criterion, twt1);
+ assertCriterionFalse(criterion, twt2);
+ assertCriterionTrue(criterion, twt3);
}
@Test
void countryTest() {
ThreeWindingsTransformerCriterion criterion = new ThreeWindingsTransformerCriterion(new SingleCountryCriterion(List.of(Country.BE)), null);
- assertFalse(criterion.accept(new NetworkElementVisitor(twt1)));
- assertFalse(criterion.accept(new NetworkElementVisitor(twt2)));
- assertTrue(criterion.accept(new NetworkElementVisitor(twt3)));
+ assertCriterionFalse(criterion, twt1);
+ assertCriterionFalse(criterion, twt2);
+ assertCriterionTrue(criterion, twt3);
criterion = new ThreeWindingsTransformerCriterion(new SingleCountryCriterion(List.of(Country.FR, Country.BE)), null);
- assertTrue(criterion.accept(new NetworkElementVisitor(twt1)));
- assertTrue(criterion.accept(new NetworkElementVisitor(twt2)));
- assertTrue(criterion.accept(new NetworkElementVisitor(twt3)));
+ assertCriterionTrue(criterion, twt1);
+ assertCriterionTrue(criterion, twt2);
+ assertCriterionTrue(criterion, twt3);
}
@Test
@@ -84,25 +86,29 @@ void mixedCriteriaTest() {
VoltageInterval.between(80., 100., true, true),
VoltageInterval.between(350., 550., true, true),
VoltageInterval.between(40., 70., true, true)));
- assertTrue(criterion.accept(new NetworkElementVisitor(twt1)));
- assertFalse(criterion.accept(new NetworkElementVisitor(twt2)));
- assertFalse(criterion.accept(new NetworkElementVisitor(twt3)));
+ assertCriterionTrue(criterion, twt1);
+ assertCriterionFalse(criterion, twt2);
+ assertCriterionFalse(criterion, twt3);
+ }
+
+ private void assertCriterionTrue(ThreeWindingsTransformerCriterion criterion, NetworkElement twt) {
+ assertTrue(criterion.accept(new NetworkElementVisitor(twt)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(twt, ThreeSides.ONE)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(twt, ThreeSides.TWO)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(twt, ThreeSides.THREE)));
+ }
+
+ private void assertCriterionFalse(ThreeWindingsTransformerCriterion criterion, NetworkElement twt) {
+ assertFalse(criterion.accept(new NetworkElementVisitor(twt)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(twt, ThreeSides.ONE)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(twt, ThreeSides.TWO)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(twt, ThreeSides.THREE)));
}
protected static NetworkElement createThreeWindingsTransformer(String id, Country country, double nominalVoltage1,
double nominalVoltage2, double nominalVoltage3) {
- NetworkElement n = Mockito.mock(NetworkElement.class);
- when(n.getId()).thenReturn(id);
- when(n.getCountry()).thenReturn(Optional.of(country));
- when(n.getCountry1()).thenReturn(Optional.of(country));
- when(n.getCountry2()).thenReturn(Optional.empty());
- when(n.getNominalVoltage()).thenReturn(Optional.of(nominalVoltage1));
- when(n.getNominalVoltage1()).thenReturn(Optional.of(nominalVoltage1));
- when(n.getNominalVoltage2()).thenReturn(Optional.of(nominalVoltage2));
- when(n.getNominalVoltage3()).thenReturn(Optional.of(nominalVoltage3));
- when(n.isValidFor(NetworkElementCriterion.NetworkElementCriterionType.THREE_WINDINGS_TRANSFORMER)).thenReturn(true);
- when(n.isValidFor(NetworkElementCriterion.NetworkElementCriterionType.IDENTIFIABLE)).thenReturn(true);
- return n;
+ ThreeWindingsTransformer twt = mockThreeWindingsTransformer(id, country, nominalVoltage1, nominalVoltage2, nominalVoltage3);
+ return new DefaultNetworkElementAdapter(twt);
}
}
diff --git a/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/TieLineCriterionTest.java b/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/TieLineCriterionTest.java
index f7472c023c7..b40553f8419 100644
--- a/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/TieLineCriterionTest.java
+++ b/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/TieLineCriterionTest.java
@@ -7,17 +7,19 @@
*/
package com.powsybl.iidm.criteria;
+import com.powsybl.iidm.criteria.translation.DefaultNetworkElementAdapter;
import com.powsybl.iidm.criteria.translation.NetworkElement;
import com.powsybl.iidm.network.Country;
+import com.powsybl.iidm.network.ThreeSides;
+import com.powsybl.iidm.network.TieLine;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.util.List;
-import java.util.Optional;
+import static com.powsybl.iidm.criteria.translation.DefaultNetworkElementAdapterTest.mockTieLine;
import static org.junit.jupiter.api.Assertions.*;
-import static org.mockito.Mockito.when;
/**
* @author Olivier Perrin {@literal }
@@ -45,13 +47,13 @@ void typeTest() {
@Test
void emptyCriterionTest() {
TieLineCriterion criterion = new TieLineCriterion(null, null);
- assertTrue(criterion.accept(new NetworkElementVisitor(tieLine1)));
- assertTrue(criterion.accept(new NetworkElementVisitor(tieLine2)));
- assertTrue(criterion.accept(new NetworkElementVisitor(tieLine3)));
- assertTrue(criterion.accept(new NetworkElementVisitor(tieLine4)));
+ assertCriterionTrue(criterion, tieLine1);
+ assertCriterionTrue(criterion, tieLine2);
+ assertCriterionTrue(criterion, tieLine3);
+ assertCriterionTrue(criterion, tieLine4);
NetworkElement anotherTypeElement = Mockito.mock(NetworkElement.class);
- assertFalse(criterion.accept(new NetworkElementVisitor(anotherTypeElement)));
+ assertCriterionFalse(criterion, anotherTypeElement);
}
@Test
@@ -59,25 +61,25 @@ void nominalVoltageTest() {
TieLineCriterion criterion = new TieLineCriterion(null, new TwoNominalVoltageCriterion(
VoltageInterval.between(40., 100., true, true),
null));
- assertTrue(criterion.accept(new NetworkElementVisitor(tieLine1)));
- assertFalse(criterion.accept(new NetworkElementVisitor(tieLine2)));
- assertFalse(criterion.accept(new NetworkElementVisitor(tieLine3)));
- assertTrue(criterion.accept(new NetworkElementVisitor(tieLine4)));
+ assertCriterionTrue(criterion, tieLine1);
+ assertCriterionFalse(criterion, tieLine2);
+ assertCriterionFalse(criterion, tieLine3);
+ assertCriterionTrue(criterion, tieLine4);
}
@Test
void countriesTest() {
TieLineCriterion criterion = new TieLineCriterion(new TwoCountriesCriterion(List.of(Country.FR), List.of(Country.BE)), null);
- assertFalse(criterion.accept(new NetworkElementVisitor(tieLine1)));
- assertFalse(criterion.accept(new NetworkElementVisitor(tieLine2)));
- assertTrue(criterion.accept(new NetworkElementVisitor(tieLine3)));
- assertFalse(criterion.accept(new NetworkElementVisitor(tieLine4)));
+ assertCriterionFalse(criterion, tieLine1);
+ assertCriterionFalse(criterion, tieLine2);
+ assertCriterionTrue(criterion, tieLine3);
+ assertCriterionFalse(criterion, tieLine4);
criterion = new TieLineCriterion(new TwoCountriesCriterion(List.of(Country.FR, Country.BE), List.of(Country.BE)), null);
- assertFalse(criterion.accept(new NetworkElementVisitor(tieLine1)));
- assertFalse(criterion.accept(new NetworkElementVisitor(tieLine2)));
- assertTrue(criterion.accept(new NetworkElementVisitor(tieLine3)));
- assertTrue(criterion.accept(new NetworkElementVisitor(tieLine4)));
+ assertCriterionFalse(criterion, tieLine1);
+ assertCriterionFalse(criterion, tieLine2);
+ assertCriterionTrue(criterion, tieLine3);
+ assertCriterionTrue(criterion, tieLine4);
}
@Test
@@ -86,25 +88,27 @@ void mixedCriteriaTest() {
new TwoNominalVoltageCriterion(
VoltageInterval.between(350., 450., true, true),
null));
- assertFalse(criterion.accept(new NetworkElementVisitor(tieLine1)));
- assertTrue(criterion.accept(new NetworkElementVisitor(tieLine2)));
- assertFalse(criterion.accept(new NetworkElementVisitor(tieLine3)));
- assertFalse(criterion.accept(new NetworkElementVisitor(tieLine4)));
+ assertCriterionFalse(criterion, tieLine1);
+ assertCriterionTrue(criterion, tieLine2);
+ assertCriterionFalse(criterion, tieLine3);
+ assertCriterionFalse(criterion, tieLine4);
+ }
+
+ private void assertCriterionTrue(TieLineCriterion criterion, NetworkElement tieLine) {
+ assertTrue(criterion.accept(new NetworkElementVisitor(tieLine)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(tieLine, ThreeSides.ONE)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(tieLine, ThreeSides.TWO)));
+ }
+
+ private void assertCriterionFalse(TieLineCriterion criterion, NetworkElement tieLine) {
+ assertFalse(criterion.accept(new NetworkElementVisitor(tieLine)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(tieLine, ThreeSides.ONE)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(tieLine, ThreeSides.TWO)));
}
protected static NetworkElement createTieLine(String id, Country country1, Country country2, double nominalVoltage) {
- NetworkElement n = Mockito.mock(NetworkElement.class);
- when(n.getId()).thenReturn(id);
- when(n.getCountry()).thenReturn(Optional.of(country1));
- when(n.getCountry1()).thenReturn(Optional.of(country1));
- when(n.getCountry2()).thenReturn(Optional.of(country2));
- when(n.getNominalVoltage()).thenReturn(Optional.of(nominalVoltage));
- when(n.getNominalVoltage1()).thenReturn(Optional.of(nominalVoltage));
- when(n.getNominalVoltage2()).thenReturn(Optional.empty());
- when(n.getNominalVoltage3()).thenReturn(Optional.empty());
- when(n.isValidFor(NetworkElementCriterion.NetworkElementCriterionType.TIE_LINE)).thenReturn(true);
- when(n.isValidFor(NetworkElementCriterion.NetworkElementCriterionType.IDENTIFIABLE)).thenReturn(true);
- return n;
+ TieLine tieLine = mockTieLine(id, country1, country2, nominalVoltage, nominalVoltage);
+ return new DefaultNetworkElementAdapter(tieLine);
}
}
diff --git a/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/TwoWindingsTransformerCriterionTest.java b/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/TwoWindingsTransformerCriterionTest.java
index 8ae2175cdb4..3e0e377bdce 100644
--- a/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/TwoWindingsTransformerCriterionTest.java
+++ b/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/TwoWindingsTransformerCriterionTest.java
@@ -7,17 +7,19 @@
*/
package com.powsybl.iidm.criteria;
-import com.powsybl.iidm.network.Country;
+import com.powsybl.iidm.criteria.translation.DefaultNetworkElementAdapter;
import com.powsybl.iidm.criteria.translation.NetworkElement;
+import com.powsybl.iidm.network.Country;
+import com.powsybl.iidm.network.ThreeSides;
+import com.powsybl.iidm.network.TwoWindingsTransformer;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.util.List;
-import java.util.Optional;
+import static com.powsybl.iidm.criteria.translation.DefaultNetworkElementAdapterTest.mockTwoWindingsTransformer;
import static org.junit.jupiter.api.Assertions.*;
-import static org.mockito.Mockito.when;
/**
* @author Olivier Perrin {@literal }
@@ -43,12 +45,12 @@ void typeTest() {
@Test
void emptyCriterionTest() {
TwoWindingsTransformerCriterion criterion = new TwoWindingsTransformerCriterion(null, null);
- assertTrue(criterion.accept(new NetworkElementVisitor(twt1)));
- assertTrue(criterion.accept(new NetworkElementVisitor(twt2)));
- assertTrue(criterion.accept(new NetworkElementVisitor(twt3)));
+ assertCriterionTrue(criterion, twt1);
+ assertCriterionTrue(criterion, twt2);
+ assertCriterionTrue(criterion, twt3);
NetworkElement anotherTypeElement = Mockito.mock(NetworkElement.class);
- assertFalse(criterion.accept(new NetworkElementVisitor(anotherTypeElement)));
+ assertCriterionFalse(criterion, anotherTypeElement);
}
@Test
@@ -57,22 +59,22 @@ void nominalVoltagesTest() {
new TwoNominalVoltageCriterion(
VoltageInterval.between(80., 100., true, true),
VoltageInterval.between(40., 70., true, true)));
- assertTrue(criterion.accept(new NetworkElementVisitor(twt1)));
- assertFalse(criterion.accept(new NetworkElementVisitor(twt2)));
- assertTrue(criterion.accept(new NetworkElementVisitor(twt3)));
+ assertCriterionTrue(criterion, twt1);
+ assertCriterionFalse(criterion, twt2);
+ assertCriterionTrue(criterion, twt3);
}
@Test
void countryTest() {
TwoWindingsTransformerCriterion criterion = new TwoWindingsTransformerCriterion(new SingleCountryCriterion(List.of(Country.BE)), null);
- assertFalse(criterion.accept(new NetworkElementVisitor(twt1)));
- assertFalse(criterion.accept(new NetworkElementVisitor(twt2)));
- assertTrue(criterion.accept(new NetworkElementVisitor(twt3)));
+ assertCriterionFalse(criterion, twt1);
+ assertCriterionFalse(criterion, twt2);
+ assertCriterionTrue(criterion, twt3);
criterion = new TwoWindingsTransformerCriterion(new SingleCountryCriterion(List.of(Country.FR, Country.BE)), null);
- assertTrue(criterion.accept(new NetworkElementVisitor(twt1)));
- assertTrue(criterion.accept(new NetworkElementVisitor(twt2)));
- assertTrue(criterion.accept(new NetworkElementVisitor(twt3)));
+ assertCriterionTrue(criterion, twt1);
+ assertCriterionTrue(criterion, twt2);
+ assertCriterionTrue(criterion, twt3);
}
@Test
@@ -82,23 +84,26 @@ void mixedCriteriaTest() {
new TwoNominalVoltageCriterion(
VoltageInterval.between(80., 100., true, true),
VoltageInterval.between(40., 70., true, true)));
- assertTrue(criterion.accept(new NetworkElementVisitor(twt1)));
- assertFalse(criterion.accept(new NetworkElementVisitor(twt2)));
- assertFalse(criterion.accept(new NetworkElementVisitor(twt3)));
+ assertCriterionTrue(criterion, twt1);
+ assertCriterionFalse(criterion, twt2);
+ assertCriterionFalse(criterion, twt3);
+ }
+
+ private void assertCriterionTrue(TwoWindingsTransformerCriterion criterion, NetworkElement twt) {
+ assertTrue(criterion.accept(new NetworkElementVisitor(twt)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(twt, ThreeSides.ONE)));
+ assertTrue(criterion.accept(new NetworkElementVisitor(twt, ThreeSides.TWO)));
+ }
+
+ private void assertCriterionFalse(TwoWindingsTransformerCriterion criterion, NetworkElement twt) {
+ assertFalse(criterion.accept(new NetworkElementVisitor(twt)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(twt, ThreeSides.ONE)));
+ assertFalse(criterion.accept(new NetworkElementVisitor(twt, ThreeSides.TWO)));
}
protected static NetworkElement createTwoWindingsTransformer(String id, Country country, double nominalVoltage1, double nominalVoltage2) {
- NetworkElement n = Mockito.mock(NetworkElement.class);
- when(n.getId()).thenReturn(id);
- when(n.getCountry()).thenReturn(Optional.of(country));
- when(n.getCountry1()).thenReturn(Optional.of(country));
- when(n.getCountry2()).thenReturn(Optional.empty());
- when(n.getNominalVoltage1()).thenReturn(Optional.of(nominalVoltage1));
- when(n.getNominalVoltage2()).thenReturn(Optional.of(nominalVoltage2));
- when(n.getNominalVoltage3()).thenReturn(Optional.empty());
- when(n.isValidFor(NetworkElementCriterion.NetworkElementCriterionType.TWO_WINDINGS_TRANSFORMER)).thenReturn(true);
- when(n.isValidFor(NetworkElementCriterion.NetworkElementCriterionType.IDENTIFIABLE)).thenReturn(true);
- return n;
+ TwoWindingsTransformer twt = mockTwoWindingsTransformer(id, country, nominalVoltage1, nominalVoltage2);
+ return new DefaultNetworkElementAdapter(twt);
}
}
diff --git a/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/translation/DefaultNetworkElementAdapterTest.java b/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/translation/DefaultNetworkElementAdapterTest.java
index 4a3fa3e140b..60e458a4ed1 100644
--- a/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/translation/DefaultNetworkElementAdapterTest.java
+++ b/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/translation/DefaultNetworkElementAdapterTest.java
@@ -19,33 +19,11 @@
/**
* @author Olivier Perrin {@literal }
*/
-class DefaultNetworkElementAdapterTest {
+public class DefaultNetworkElementAdapterTest {
@Test
void testLine() {
- Substation substation1 = Mockito.mock(Substation.class);
- Mockito.when(substation1.getNullableCountry()).thenReturn(Country.FR);
- Substation substation2 = Mockito.mock(Substation.class);
- Mockito.when(substation2.getNullableCountry()).thenReturn(Country.DE);
-
- VoltageLevel voltageLevel1 = Mockito.mock(VoltageLevel.class);
- Mockito.when(voltageLevel1.getSubstation()).thenReturn(Optional.of(substation1));
- Mockito.when(voltageLevel1.getNominalV()).thenReturn(225.);
- VoltageLevel voltageLevel2 = Mockito.mock(VoltageLevel.class);
- Mockito.when(voltageLevel2.getSubstation()).thenReturn(Optional.of(substation2));
- Mockito.when(voltageLevel2.getNominalV()).thenReturn(226.);
-
- Terminal terminal1 = Mockito.mock(Terminal.class);
- Mockito.when(terminal1.getVoltageLevel()).thenReturn(voltageLevel1);
- Terminal terminal2 = Mockito.mock(Terminal.class);
- Mockito.when(terminal2.getVoltageLevel()).thenReturn(voltageLevel2);
-
- Line line = Mockito.mock(Line.class);
- Mockito.when(line.getType()).thenReturn(IdentifiableType.LINE);
- Mockito.when(line.getId()).thenReturn("testLine");
- Mockito.when(line.getTerminal(TwoSides.ONE)).thenReturn(terminal1);
- Mockito.when(line.getTerminal(TwoSides.TWO)).thenReturn(terminal2);
-
+ Line line = mockLine("testLine", Country.FR, Country.DE, 225., 226.);
DefaultNetworkElementAdapter networkElement = new DefaultNetworkElementAdapter(line);
assertEquals("testLine", networkElement.getId());
assertEquals(Country.FR, networkElement.getCountry().orElseThrow());
@@ -68,28 +46,7 @@ void testLine() {
@Test
void testTieLine() {
- Substation substation1 = Mockito.mock(Substation.class);
- Mockito.when(substation1.getNullableCountry()).thenReturn(Country.FR);
- Substation substation2 = Mockito.mock(Substation.class);
- Mockito.when(substation2.getNullableCountry()).thenReturn(Country.DE);
-
- VoltageLevel voltageLevel1 = Mockito.mock(VoltageLevel.class);
- Mockito.when(voltageLevel1.getSubstation()).thenReturn(Optional.of(substation1));
- Mockito.when(voltageLevel1.getNominalV()).thenReturn(225.);
- VoltageLevel voltageLevel2 = Mockito.mock(VoltageLevel.class);
- Mockito.when(voltageLevel2.getSubstation()).thenReturn(Optional.of(substation2));
- Mockito.when(voltageLevel2.getNominalV()).thenReturn(226.);
-
- Terminal terminal1 = Mockito.mock(Terminal.class);
- Mockito.when(terminal1.getVoltageLevel()).thenReturn(voltageLevel1);
- Terminal terminal2 = Mockito.mock(Terminal.class);
- Mockito.when(terminal2.getVoltageLevel()).thenReturn(voltageLevel2);
-
- TieLine tieLine = Mockito.mock(TieLine.class);
- Mockito.when(tieLine.getType()).thenReturn(IdentifiableType.TIE_LINE);
- Mockito.when(tieLine.getId()).thenReturn("testTieLine");
- Mockito.when(tieLine.getTerminal(TwoSides.ONE)).thenReturn(terminal1);
- Mockito.when(tieLine.getTerminal(TwoSides.TWO)).thenReturn(terminal2);
+ TieLine tieLine = mockTieLine("testTieLine", Country.FR, Country.DE, 225., 226.);
DefaultNetworkElementAdapter networkElement = new DefaultNetworkElementAdapter(tieLine);
assertEquals("testTieLine", networkElement.getId());
@@ -113,21 +70,7 @@ void testTieLine() {
@Test
void testDanglingLine() {
- Substation substation1 = Mockito.mock(Substation.class);
- Mockito.when(substation1.getNullableCountry()).thenReturn(Country.FR);
-
- VoltageLevel voltageLevel = Mockito.mock(VoltageLevel.class);
- Mockito.when(voltageLevel.getSubstation()).thenReturn(Optional.of(substation1));
- Mockito.when(voltageLevel.getNominalV()).thenReturn(225.);
-
- Terminal terminal = Mockito.mock(Terminal.class);
- Mockito.when(terminal.getVoltageLevel()).thenReturn(voltageLevel);
-
- DanglingLine danglingLine = Mockito.mock(DanglingLine.class);
- Mockito.when(danglingLine.getType()).thenReturn(IdentifiableType.DANGLING_LINE);
- Mockito.when(danglingLine.getId()).thenReturn("testDanglingLine");
- Mockito.when(danglingLine.getTerminal()).thenReturn(terminal);
-
+ DanglingLine danglingLine = mockDanglingLine("testDanglingLine", Country.FR, 225.);
DefaultNetworkElementAdapter networkElement = new DefaultNetworkElementAdapter(danglingLine);
assertEquals("testDanglingLine", networkElement.getId());
assertEquals(Country.FR, networkElement.getCountry().orElseThrow());
@@ -150,27 +93,7 @@ void testDanglingLine() {
@Test
void testTwoWindingsTransformer() {
- Substation substation = Mockito.mock(Substation.class);
- Mockito.when(substation.getNullableCountry()).thenReturn(Country.FR);
-
- VoltageLevel voltageLevel1 = Mockito.mock(VoltageLevel.class);
- Mockito.when(voltageLevel1.getSubstation()).thenReturn(Optional.of(substation));
- Mockito.when(voltageLevel1.getNominalV()).thenReturn(225.);
- VoltageLevel voltageLevel2 = Mockito.mock(VoltageLevel.class);
- Mockito.when(voltageLevel2.getSubstation()).thenReturn(Optional.of(substation));
- Mockito.when(voltageLevel2.getNominalV()).thenReturn(90.);
-
- Terminal terminal1 = Mockito.mock(Terminal.class);
- Mockito.when(terminal1.getVoltageLevel()).thenReturn(voltageLevel1);
- Terminal terminal2 = Mockito.mock(Terminal.class);
- Mockito.when(terminal2.getVoltageLevel()).thenReturn(voltageLevel2);
-
- TwoWindingsTransformer twt = Mockito.mock(TwoWindingsTransformer.class);
- Mockito.when(twt.getType()).thenReturn(IdentifiableType.TWO_WINDINGS_TRANSFORMER);
- Mockito.when(twt.getId()).thenReturn("testTwoWindingsTransformer");
- Mockito.when(twt.getSubstation()).thenReturn(Optional.of(substation));
- Mockito.when(twt.getTerminal(TwoSides.ONE)).thenReturn(terminal1);
- Mockito.when(twt.getTerminal(TwoSides.TWO)).thenReturn(terminal2);
+ TwoWindingsTransformer twt = mockTwoWindingsTransformer("testTwoWindingsTransformer", Country.FR, 225., 90.);
DefaultNetworkElementAdapter networkElement = new DefaultNetworkElementAdapter(twt);
assertEquals("testTwoWindingsTransformer", networkElement.getId());
@@ -192,18 +115,138 @@ void testTwoWindingsTransformer() {
@Test
void testThreeWindingsTransformer() {
+ ThreeWindingsTransformer twt = mockThreeWindingsTransformer("testThreeWindingsTransformer", Country.FR, 400., 225., 90.);
+ DefaultNetworkElementAdapter networkElement = new DefaultNetworkElementAdapter(twt);
+ assertEquals("testThreeWindingsTransformer", networkElement.getId());
+ assertEquals(Country.FR, networkElement.getCountry().orElseThrow());
+ assertEquals(400., networkElement.getNominalVoltage().orElseThrow(), 0.01);
+ assertEquals(400., networkElement.getNominalVoltage1().orElseThrow(), 0.01);
+ assertEquals(225., networkElement.getNominalVoltage2().orElseThrow(), 0.01);
+ assertEquals(90., networkElement.getNominalVoltage3().orElseThrow(), 0.01);
+
+ assertFalse(networkElement.isValidFor(NetworkElementCriterionType.LINE));
+ assertFalse(networkElement.isValidFor(NetworkElementCriterionType.TIE_LINE));
+ assertFalse(networkElement.isValidFor(NetworkElementCriterionType.DANGLING_LINE));
+ assertFalse(networkElement.isValidFor(NetworkElementCriterionType.TWO_WINDINGS_TRANSFORMER));
+ assertTrue(networkElement.isValidFor(NetworkElementCriterionType.THREE_WINDINGS_TRANSFORMER));
+ assertTrue(networkElement.isValidFor(NetworkElementCriterionType.IDENTIFIABLE));
+ assertTrue(networkElement.isValidFor(NetworkElementCriterionType.IDENTIFIER));
+ assertEquals(twt, networkElement.getIdentifiable());
+ }
+
+ public static Line mockLine(String id, Country country1, Country country2,
+ double nominalVoltage1, double nominalVoltage2) {
+ Substation substation1 = Mockito.mock(Substation.class);
+ Mockito.when(substation1.getNullableCountry()).thenReturn(country1);
+ Substation substation2 = Mockito.mock(Substation.class);
+ Mockito.when(substation2.getNullableCountry()).thenReturn(country2);
+
+ VoltageLevel voltageLevel1 = Mockito.mock(VoltageLevel.class);
+ Mockito.when(voltageLevel1.getSubstation()).thenReturn(Optional.of(substation1));
+ Mockito.when(voltageLevel1.getNominalV()).thenReturn(nominalVoltage1);
+ VoltageLevel voltageLevel2 = Mockito.mock(VoltageLevel.class);
+ Mockito.when(voltageLevel2.getSubstation()).thenReturn(Optional.of(substation2));
+ Mockito.when(voltageLevel2.getNominalV()).thenReturn(nominalVoltage2);
+
+ Terminal terminal1 = Mockito.mock(Terminal.class);
+ Mockito.when(terminal1.getVoltageLevel()).thenReturn(voltageLevel1);
+ Terminal terminal2 = Mockito.mock(Terminal.class);
+ Mockito.when(terminal2.getVoltageLevel()).thenReturn(voltageLevel2);
+
+ Line line = Mockito.mock(Line.class);
+ Mockito.when(line.getType()).thenReturn(IdentifiableType.LINE);
+ Mockito.when(line.getId()).thenReturn(id);
+ Mockito.when(line.getTerminal(TwoSides.ONE)).thenReturn(terminal1);
+ Mockito.when(line.getTerminal(TwoSides.TWO)).thenReturn(terminal2);
+ return line;
+ }
+
+ public static TieLine mockTieLine(String id, Country country1, Country country2,
+ double nominalVoltage1, double nominalVoltage2) {
+ Substation substation1 = Mockito.mock(Substation.class);
+ Mockito.when(substation1.getNullableCountry()).thenReturn(country1);
+ Substation substation2 = Mockito.mock(Substation.class);
+ Mockito.when(substation2.getNullableCountry()).thenReturn(country2);
+
+ VoltageLevel voltageLevel1 = Mockito.mock(VoltageLevel.class);
+ Mockito.when(voltageLevel1.getSubstation()).thenReturn(Optional.of(substation1));
+ Mockito.when(voltageLevel1.getNominalV()).thenReturn(nominalVoltage1);
+ VoltageLevel voltageLevel2 = Mockito.mock(VoltageLevel.class);
+ Mockito.when(voltageLevel2.getSubstation()).thenReturn(Optional.of(substation2));
+ Mockito.when(voltageLevel2.getNominalV()).thenReturn(nominalVoltage2);
+
+ Terminal terminal1 = Mockito.mock(Terminal.class);
+ Mockito.when(terminal1.getVoltageLevel()).thenReturn(voltageLevel1);
+ Terminal terminal2 = Mockito.mock(Terminal.class);
+ Mockito.when(terminal2.getVoltageLevel()).thenReturn(voltageLevel2);
+
+ TieLine tieLine = Mockito.mock(TieLine.class);
+ Mockito.when(tieLine.getType()).thenReturn(IdentifiableType.TIE_LINE);
+ Mockito.when(tieLine.getId()).thenReturn(id);
+ Mockito.when(tieLine.getTerminal(TwoSides.ONE)).thenReturn(terminal1);
+ Mockito.when(tieLine.getTerminal(TwoSides.TWO)).thenReturn(terminal2);
+ return tieLine;
+ }
+
+ public static DanglingLine mockDanglingLine(String id, Country country, double nominalVoltage) {
+ Substation substation1 = Mockito.mock(Substation.class);
+ Mockito.when(substation1.getNullableCountry()).thenReturn(country);
+
+ VoltageLevel voltageLevel = Mockito.mock(VoltageLevel.class);
+ Mockito.when(voltageLevel.getSubstation()).thenReturn(Optional.of(substation1));
+ Mockito.when(voltageLevel.getNominalV()).thenReturn(nominalVoltage);
+
+ Terminal terminal = Mockito.mock(Terminal.class);
+ Mockito.when(terminal.getVoltageLevel()).thenReturn(voltageLevel);
+
+ DanglingLine danglingLine = Mockito.mock(DanglingLine.class);
+ Mockito.when(danglingLine.getType()).thenReturn(IdentifiableType.DANGLING_LINE);
+ Mockito.when(danglingLine.getId()).thenReturn(id);
+ Mockito.when(danglingLine.getTerminal()).thenReturn(terminal);
+ return danglingLine;
+ }
+
+ public static TwoWindingsTransformer mockTwoWindingsTransformer(String id, Country country,
+ double nominalVoltage1, double nominalVoltage2) {
+ Substation substation = Mockito.mock(Substation.class);
+ Mockito.when(substation.getNullableCountry()).thenReturn(country);
+
+ VoltageLevel voltageLevel1 = Mockito.mock(VoltageLevel.class);
+ Mockito.when(voltageLevel1.getSubstation()).thenReturn(Optional.of(substation));
+ Mockito.when(voltageLevel1.getNominalV()).thenReturn(nominalVoltage1);
+ VoltageLevel voltageLevel2 = Mockito.mock(VoltageLevel.class);
+ Mockito.when(voltageLevel2.getSubstation()).thenReturn(Optional.of(substation));
+ Mockito.when(voltageLevel2.getNominalV()).thenReturn(nominalVoltage2);
+
+ Terminal terminal1 = Mockito.mock(Terminal.class);
+ Mockito.when(terminal1.getVoltageLevel()).thenReturn(voltageLevel1);
+ Terminal terminal2 = Mockito.mock(Terminal.class);
+ Mockito.when(terminal2.getVoltageLevel()).thenReturn(voltageLevel2);
+
+ TwoWindingsTransformer twt = Mockito.mock(TwoWindingsTransformer.class);
+ Mockito.when(twt.getType()).thenReturn(IdentifiableType.TWO_WINDINGS_TRANSFORMER);
+ Mockito.when(twt.getId()).thenReturn(id);
+ Mockito.when(twt.getSubstation()).thenReturn(Optional.of(substation));
+ Mockito.when(twt.getTerminal(TwoSides.ONE)).thenReturn(terminal1);
+ Mockito.when(twt.getTerminal(TwoSides.TWO)).thenReturn(terminal2);
+ return twt;
+ }
+
+ public static ThreeWindingsTransformer mockThreeWindingsTransformer(String id, Country country,
+ double nominalVoltage1, double nominalVoltage2,
+ double nominalVoltage3) {
Substation substation = Mockito.mock(Substation.class);
- Mockito.when(substation.getNullableCountry()).thenReturn(Country.FR);
+ Mockito.when(substation.getNullableCountry()).thenReturn(country);
VoltageLevel voltageLevel1 = Mockito.mock(VoltageLevel.class);
Mockito.when(voltageLevel1.getSubstation()).thenReturn(Optional.of(substation));
- Mockito.when(voltageLevel1.getNominalV()).thenReturn(400.);
+ Mockito.when(voltageLevel1.getNominalV()).thenReturn(nominalVoltage1);
VoltageLevel voltageLevel2 = Mockito.mock(VoltageLevel.class);
Mockito.when(voltageLevel2.getSubstation()).thenReturn(Optional.of(substation));
- Mockito.when(voltageLevel2.getNominalV()).thenReturn(225.);
+ Mockito.when(voltageLevel2.getNominalV()).thenReturn(nominalVoltage2);
VoltageLevel voltageLevel3 = Mockito.mock(VoltageLevel.class);
Mockito.when(voltageLevel3.getSubstation()).thenReturn(Optional.of(substation));
- Mockito.when(voltageLevel3.getNominalV()).thenReturn(90.);
+ Mockito.when(voltageLevel3.getNominalV()).thenReturn(nominalVoltage3);
Terminal terminal1 = Mockito.mock(Terminal.class);
Mockito.when(terminal1.getVoltageLevel()).thenReturn(voltageLevel1);
@@ -214,27 +257,11 @@ void testThreeWindingsTransformer() {
ThreeWindingsTransformer twt = Mockito.mock(ThreeWindingsTransformer.class);
Mockito.when(twt.getType()).thenReturn(IdentifiableType.THREE_WINDINGS_TRANSFORMER);
- Mockito.when(twt.getId()).thenReturn("testThreeWindingsTransformer");
+ Mockito.when(twt.getId()).thenReturn(id);
Mockito.when(twt.getSubstation()).thenReturn(Optional.of(substation));
Mockito.when(twt.getTerminal(ThreeSides.ONE)).thenReturn(terminal1);
Mockito.when(twt.getTerminal(ThreeSides.TWO)).thenReturn(terminal2);
Mockito.when(twt.getTerminal(ThreeSides.THREE)).thenReturn(terminal3);
-
- DefaultNetworkElementAdapter networkElement = new DefaultNetworkElementAdapter(twt);
- assertEquals("testThreeWindingsTransformer", networkElement.getId());
- assertEquals(Country.FR, networkElement.getCountry().orElseThrow());
- assertEquals(400., networkElement.getNominalVoltage().orElseThrow(), 0.01);
- assertEquals(400., networkElement.getNominalVoltage1().orElseThrow(), 0.01);
- assertEquals(225., networkElement.getNominalVoltage2().orElseThrow(), 0.01);
- assertEquals(90., networkElement.getNominalVoltage3().orElseThrow(), 0.01);
-
- assertFalse(networkElement.isValidFor(NetworkElementCriterionType.LINE));
- assertFalse(networkElement.isValidFor(NetworkElementCriterionType.TIE_LINE));
- assertFalse(networkElement.isValidFor(NetworkElementCriterionType.DANGLING_LINE));
- assertFalse(networkElement.isValidFor(NetworkElementCriterionType.TWO_WINDINGS_TRANSFORMER));
- assertTrue(networkElement.isValidFor(NetworkElementCriterionType.THREE_WINDINGS_TRANSFORMER));
- assertTrue(networkElement.isValidFor(NetworkElementCriterionType.IDENTIFIABLE));
- assertTrue(networkElement.isValidFor(NetworkElementCriterionType.IDENTIFIER));
- assertEquals(twt, networkElement.getIdentifiable());
+ return twt;
}
}
diff --git a/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/translation/NetworkElementTest.java b/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/translation/NetworkElementTest.java
new file mode 100644
index 00000000000..e245b81106f
--- /dev/null
+++ b/iidm/iidm-criteria/src/test/java/com/powsybl/iidm/criteria/translation/NetworkElementTest.java
@@ -0,0 +1,95 @@
+/**
+ * Copyright (c) 2024, 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/.
+ * SPDX-License-Identifier: MPL-2.0
+ */
+package com.powsybl.iidm.criteria.translation;
+
+import com.powsybl.iidm.criteria.NetworkElementCriterion;
+import com.powsybl.iidm.network.Country;
+import com.powsybl.iidm.network.ThreeSides;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * @author Olivier Perrin {@literal }
+ */
+class NetworkElementTest {
+
+ private static NetworkElement networkElement;
+
+ @BeforeAll
+ public static void init() {
+ networkElement = new NetworkElement() {
+ @Override
+ public String getId() {
+ return "id";
+ }
+
+ @Override
+ public Optional getCountry1() {
+ return Optional.of(Country.DE);
+ }
+
+ @Override
+ public Optional getCountry2() {
+ return Optional.of(Country.ES);
+ }
+
+ @Override
+ public Optional getCountry3() {
+ return Optional.of(Country.BE);
+ }
+
+ @Override
+ public Optional getCountry() {
+ return getCountry1();
+ }
+
+ @Override
+ public Optional getNominalVoltage1() {
+ return Optional.of(400.);
+ }
+
+ @Override
+ public Optional getNominalVoltage2() {
+ return Optional.of(225.);
+ }
+
+ @Override
+ public Optional getNominalVoltage3() {
+ return Optional.of(90.);
+ }
+
+ @Override
+ public Optional getNominalVoltage() {
+ return getNominalVoltage1();
+ }
+
+ @Override
+ public boolean isValidFor(NetworkElementCriterion.NetworkElementCriterionType networkElementCriterionType) {
+ return false;
+ }
+ };
+ }
+
+ @Test
+ void testCountries() {
+ assertEquals(Country.DE, networkElement.getCountry(ThreeSides.ONE).orElse(null));
+ assertEquals(Country.ES, networkElement.getCountry(ThreeSides.TWO).orElse(null));
+ assertEquals(Country.BE, networkElement.getCountry(ThreeSides.THREE).orElse(null));
+ }
+
+ @Test
+ void testVoltageLevels() {
+ assertEquals(400., networkElement.getNominalVoltage(ThreeSides.ONE).orElse(Double.NaN), 0.01);
+ assertEquals(225., networkElement.getNominalVoltage(ThreeSides.TWO).orElse(Double.NaN), 0.01);
+ assertEquals(90., networkElement.getNominalVoltage(ThreeSides.THREE).orElse(Double.NaN), 0.01);
+ }
+}
diff --git a/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/ActivePowerControl.java b/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/ActivePowerControl.java
index 0dd18ffb477..af9dc407473 100644
--- a/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/ActivePowerControl.java
+++ b/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/ActivePowerControl.java
@@ -10,6 +10,8 @@
import com.powsybl.commons.extensions.Extension;
import com.powsybl.iidm.network.Injection;
+import java.util.OptionalDouble;
+
/**
* @author Ghiles Abdellah {@literal }
*/
@@ -54,4 +56,25 @@ default String getName() {
*/
void setParticipationFactor(double participationFactor);
+ /**
+ * @return if present, provides the overridden value of minP to be used for active power control operations.
+ */
+ OptionalDouble getMinPOverride();
+
+ /**
+ * Sets the overridden minimal active power.
+ * @param pMinOverride The overridden value of minP. A Nan value removes the override.
+ */
+ void setMinPOverride(double pMinOverride);
+
+ /**
+ * @return if present, provides the overridden value of maxP to be used for active power control operations.
+ */
+ OptionalDouble getMaxPOverride();
+
+ /**
+ * Sets the overridden maximal active power.
+ * @param pMaxOverride The overridden value of maxP. A Nan value removes the override.
+ */
+ void setMaxPOverride(double pMaxOverride);
}
diff --git a/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/ActivePowerControlAdder.java b/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/ActivePowerControlAdder.java
index 22f64c6200f..b4d6e500b2f 100644
--- a/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/ActivePowerControlAdder.java
+++ b/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/ActivePowerControlAdder.java
@@ -23,4 +23,8 @@ default Class getExtensionClass() {
ActivePowerControlAdder withDroop(double droop);
ActivePowerControlAdder withParticipationFactor(double participationFactor);
+
+ ActivePowerControlAdder withMinPOverride(double minPOverride);
+
+ ActivePowerControlAdder withMaxPOverride(double maxPOverride);
}
diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/ActivePowerControlAdderImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/ActivePowerControlAdderImpl.java
index e0fae2e5f70..69235972c9e 100644
--- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/ActivePowerControlAdderImpl.java
+++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/ActivePowerControlAdderImpl.java
@@ -20,6 +20,8 @@ public class ActivePowerControlAdderImpl>
private double droop = Double.NaN;
private double participationFactor = Double.NaN;
+ private double minPOverride = Double.NaN;
+ private double maxPOverride = Double.NaN;
protected ActivePowerControlAdderImpl(I extendable) {
super(extendable);
@@ -27,7 +29,7 @@ protected ActivePowerControlAdderImpl(I extendable) {
@Override
protected ActivePowerControlImpl createExtension(I extendable) {
- return new ActivePowerControlImpl<>(extendable, participate, droop, participationFactor);
+ return new ActivePowerControlImpl<>(extendable, participate, droop, participationFactor, minPOverride, maxPOverride);
}
@Override
@@ -48,4 +50,16 @@ public ActivePowerControlAdder withParticipationFactor(double participationFa
return this;
}
+ @Override
+ public ActivePowerControlAdder withMinPOverride(double minPOverride) {
+ this.minPOverride = minPOverride;
+ return this;
+ }
+
+ @Override
+ public ActivePowerControlAdder withMaxPOverride(double maxPOverride) {
+ this.maxPOverride = maxPOverride;
+ return this;
+ }
+
}
diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/ActivePowerControlImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/ActivePowerControlImpl.java
index cd085d0b9dc..c890aabe86e 100644
--- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/ActivePowerControlImpl.java
+++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/ActivePowerControlImpl.java
@@ -14,6 +14,7 @@
import gnu.trove.list.array.TDoubleArrayList;
import java.util.List;
+import java.util.OptionalDouble;
/**
* @author Ghiles Abdellah {@literal }
@@ -26,22 +27,38 @@ public class ActivePowerControlImpl> extends AbstractMult
private final TDoubleArrayList droop;
private final TDoubleArrayList participationFactor;
+ private final TDoubleArrayList minPOverride;
+ private final TDoubleArrayList maxPOverride;
+
private final List allTDoubleArrayLists;
public ActivePowerControlImpl(T component,
boolean participate,
double droop,
double participationFactor) {
+ this(component, participate, droop, participationFactor, Double.NaN, Double.NaN);
+ }
+
+ public ActivePowerControlImpl(T component,
+ boolean participate,
+ double droop,
+ double participationFactor,
+ double minPOverride,
+ double maxPOverride) {
super(component);
int variantArraySize = getVariantManagerHolder().getVariantManager().getVariantArraySize();
this.participate = new TBooleanArrayList(variantArraySize);
this.droop = new TDoubleArrayList(variantArraySize);
this.participationFactor = new TDoubleArrayList(variantArraySize);
- this.allTDoubleArrayLists = List.of(this.droop, this.participationFactor);
+ this.minPOverride = new TDoubleArrayList(variantArraySize);
+ this.maxPOverride = new TDoubleArrayList(variantArraySize);
+ this.allTDoubleArrayLists = List.of(this.droop, this.participationFactor, this.minPOverride, this.maxPOverride);
for (int i = 0; i < variantArraySize; i++) {
this.participate.add(participate);
this.droop.add(droop);
this.participationFactor.add(participationFactor);
+ this.minPOverride.add(minPOverride);
+ this.maxPOverride.add(maxPOverride);
}
}
@@ -94,8 +111,29 @@ public void deleteVariantArrayElement(int index) {
public void allocateVariantArrayElement(int[] indexes, int sourceIndex) {
for (int index : indexes) {
participate.set(index, participate.get(sourceIndex));
- droop.set(index, droop.get(sourceIndex));
allTDoubleArrayLists.forEach(dl -> dl.set(index, dl.get(sourceIndex)));
}
}
+
+ @Override
+ public OptionalDouble getMinPOverride() {
+ double result = minPOverride.get(getVariantIndex());
+ return Double.isNaN(result) ? OptionalDouble.empty() : OptionalDouble.of(result);
+ }
+
+ @Override
+ public void setMinPOverride(double minPOverride) {
+ this.minPOverride.set(getVariantIndex(), minPOverride);
+ }
+
+ @Override
+ public OptionalDouble getMaxPOverride() {
+ double result = maxPOverride.get(getVariantIndex());
+ return Double.isNaN(result) ? OptionalDouble.empty() : OptionalDouble.of(result);
+ }
+
+ @Override
+ public void setMaxPOverride(double maxPOverride) {
+ this.maxPOverride.set(getVariantIndex(), maxPOverride);
+ }
}
diff --git a/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/extensions/ActivePowerControlSerDe.java b/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/extensions/ActivePowerControlSerDe.java
index d70fad28cee..fc1507962ae 100644
--- a/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/extensions/ActivePowerControlSerDe.java
+++ b/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/extensions/ActivePowerControlSerDe.java
@@ -45,11 +45,12 @@ public ActivePowerControlSerDe() {
.put(IidmVersion.V_1_9, ImmutableSortedSet.of("1.0", "1.1"))
.put(IidmVersion.V_1_10, ImmutableSortedSet.of("1.0", "1.1"))
.put(IidmVersion.V_1_11, ImmutableSortedSet.of("1.0", "1.1"))
- .put(IidmVersion.V_1_12, ImmutableSortedSet.of("1.0", "1.1"))
+ .put(IidmVersion.V_1_12, ImmutableSortedSet.of("1.0", "1.1", "1.2"))
.build(),
new ImmutableMap.Builder()
.put("1.0", "http://www.itesla_project.eu/schema/iidm/ext/active_power_control/1_0")
.put("1.1", "http://www.powsybl.org/schema/iidm/ext/active_power_control/1_1")
+ .put("1.2", "http://www.powsybl.org/schema/iidm/ext/active_power_control/1_2")
.build());
}
@@ -63,16 +64,22 @@ public void write(ActivePowerControl activePowerControl, SerializerContext co
if ("1.1".compareTo(extVersionStr) <= 0) {
context.getWriter().writeDoubleAttribute("participationFactor", activePowerControl.getParticipationFactor());
}
+ if ("1.2".compareTo(extVersionStr) <= 0) {
+ // not using writeOptionalDouble and trusting implementation convention: : writeDoubleAttribute does not write NaN values in human-readable formats JSON/XML
+ context.getWriter().writeDoubleAttribute("maxPOverride", activePowerControl.getMaxPOverride().orElse(Double.NaN));
+ context.getWriter().writeDoubleAttribute("minPOverride", activePowerControl.getMinPOverride().orElse(Double.NaN));
+ }
}
@Override
public InputStream getXsdAsStream() {
- return getClass().getResourceAsStream("/xsd/activePowerControl_V1_1.xsd");
+ return getClass().getResourceAsStream("/xsd/activePowerControl_V1_2.xsd");
}
@Override
public List getXsdAsStreamList() {
- return List.of(getClass().getResourceAsStream("/xsd/activePowerControl_V1_1.xsd"),
+ return List.of(getClass().getResourceAsStream("/xsd/activePowerControl_V1_2.xsd"),
+ getClass().getResourceAsStream("/xsd/activePowerControl_V1_1.xsd"),
getClass().getResourceAsStream("/xsd/activePowerControl_V1_0.xsd"));
}
@@ -81,16 +88,25 @@ public ActivePowerControl read(T identifiable, DeserializerContext context) {
boolean participate = context.getReader().readBooleanAttribute("participate");
double droop = context.getReader().readDoubleAttribute("droop");
double participationFactor = Double.NaN;
+ double minPOverride = Double.NaN;
+ double maxPOverride = Double.NaN;
NetworkDeserializerContext networkContext = (NetworkDeserializerContext) context;
String extVersionStr = networkContext.getExtensionVersion(this).orElseThrow(IllegalStateException::new);
if ("1.1".compareTo(extVersionStr) <= 0) {
participationFactor = context.getReader().readDoubleAttribute("participationFactor");
}
+ if ("1.2".compareTo(extVersionStr) <= 0) {
+ // not using readOptionalDouble and trusting implementation convention: readDoubleAttribute returns Nan if attribute is absent in human-readable formats (JSON / XML)
+ maxPOverride = context.getReader().readDoubleAttribute("maxPOverride");
+ minPOverride = context.getReader().readDoubleAttribute("minPOverride");
+ }
context.getReader().readEndNode();
ActivePowerControlAdder activePowerControlAdder = identifiable.newExtension(ActivePowerControlAdder.class);
return activePowerControlAdder.withParticipate(participate)
.withDroop(droop)
.withParticipationFactor(participationFactor)
+ .withMinPOverride(minPOverride)
+ .withMaxPOverride(maxPOverride)
.add();
}
}
diff --git a/iidm/iidm-serde/src/main/resources/xsd/activePowerControl_V1_2.xsd b/iidm/iidm-serde/src/main/resources/xsd/activePowerControl_V1_2.xsd
new file mode 100644
index 00000000000..d53fa4a9ca9
--- /dev/null
+++ b/iidm/iidm-serde/src/main/resources/xsd/activePowerControl_V1_2.xsd
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/EurostagBinaryTest.java b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/EurostagBinaryTest.java
index 6e24236fe07..3206071a35b 100644
--- a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/EurostagBinaryTest.java
+++ b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/EurostagBinaryTest.java
@@ -10,9 +10,6 @@
import com.powsybl.commons.io.TreeDataFormat;
import com.powsybl.commons.test.ComparisonUtils;
import com.powsybl.iidm.network.Network;
-import com.powsybl.iidm.network.extensions.ActivePowerControlAdder;
-import com.powsybl.iidm.network.extensions.ConnectablePosition;
-import com.powsybl.iidm.network.extensions.ConnectablePositionAdder;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import org.junit.jupiter.api.Test;
@@ -47,20 +44,4 @@ void roundTripTest() throws IOException {
roundTripVersionedJsonFromMinToCurrentVersionTest(fileName, IidmVersion.V_1_12);
}
- @Test
- void roundTripTestWithExtension() throws IOException {
- ExportOptions exportOptions = new ExportOptions().setFormat(TreeDataFormat.BIN);
- ImportOptions importOptions = new ImportOptions().setFormat(TreeDataFormat.BIN);
- Network network = EurostagTutorialExample1Factory.createWithLFResults();
- network.getGeneratorStream().findFirst().ifPresent(g -> g.newExtension(ActivePowerControlAdder.class).withDroop(2).withParticipate(true).add());
- network.getLoadStream().forEach(l -> l.newExtension(ConnectablePositionAdder.class).newFeeder().withDirection(ConnectablePosition.Direction.BOTTOM).add().add());
- roundTripTest(network,
- (n, binFile) -> NetworkSerDe.write(n, exportOptions, binFile),
- binFile -> NetworkSerDe.read(binFile, importOptions),
- ComparisonUtils::assertBytesEquals,
- getVersionedNetworkPath("eurostag-tutorial1-lf-extensions.bin", CURRENT_IIDM_VERSION));
-
- //backward compatibility
- roundTripVersionedJsonFromMinToCurrentVersionTest("eurostag-tutorial1-lf-extensions.bin", IidmVersion.V_1_12);
- }
}
diff --git a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/extensions/ActivePowerControlXmlTest.java b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/extensions/ActivePowerControlXmlTest.java
index 919deb63a95..613e0a6b5f9 100644
--- a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/extensions/ActivePowerControlXmlTest.java
+++ b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/extensions/ActivePowerControlXmlTest.java
@@ -19,9 +19,12 @@
import org.junit.jupiter.api.Test;
import java.io.IOException;
+import java.util.OptionalDouble;
import static com.powsybl.iidm.serde.IidmSerDeConstants.CURRENT_IIDM_VERSION;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Ghiles Abdellah {@literal }
@@ -44,13 +47,36 @@ public void setUp() throws IOException {
}
@Test
- void test() throws IOException {
- Network network2 = allFormatsRoundTripTest(network, "/activePowerControlRoundTripRef.xml", CURRENT_IIDM_VERSION);
+ void testPLimitOverride() throws IOException {
+ network.getGenerator("GEN").getExtension(ActivePowerControl.class).setMaxPOverride(100.);
+ network.getBattery("BAT").getExtension(ActivePowerControl.class).setMinPOverride(10.);
+ Network network2 = allFormatsRoundTripTest(network, "/activePowerControlWithLimitRoundTripRef.xml", CURRENT_IIDM_VERSION);
+
+ Generator gen2 = network2.getGenerator("GEN");
+ assertNotNull(gen2);
+ ActivePowerControl activePowerControl1 = gen2.getExtension(ActivePowerControl.class);
+ assertNotNull(activePowerControl1);
+ assertEquals(OptionalDouble.of(100), activePowerControl1.getMaxPOverride());
+ assertTrue(activePowerControl1.getMinPOverride().isEmpty());
+
+ Battery bat2 = network2.getBattery("BAT");
+ assertNotNull(bat2);
+ ActivePowerControl activePowerControl2 = bat2.getExtension(ActivePowerControl.class);
+ assertNotNull(activePowerControl2);
+ assertTrue(activePowerControl2.getMaxPOverride().isEmpty());
+ assertEquals(OptionalDouble.of(10), activePowerControl2.getMinPOverride());
+ }
+
+ @Test
+ void testIidmV11() throws IOException {
+ Network network2 = allFormatsRoundTripTest(network, "/activePowerControlRoundTripRef.xml", IidmVersion.V_1_11);
Battery bat2 = network2.getBattery("BAT");
assertNotNull(bat2);
ActivePowerControl activePowerControl2 = bat2.getExtension(ActivePowerControl.class);
assertNotNull(activePowerControl2);
+ assertTrue(activePowerControl2.getMaxPOverride().isEmpty());
+ assertTrue(activePowerControl2.getMinPOverride().isEmpty());
}
@Test
diff --git a/iidm/iidm-serde/src/test/resources/V1_12/activePowerControlWithLimitRoundTripRef.xml b/iidm/iidm-serde/src/test/resources/V1_12/activePowerControlWithLimitRoundTripRef.xml
new file mode 100644
index 00000000000..469356d8c44
--- /dev/null
+++ b/iidm/iidm-serde/src/test/resources/V1_12/activePowerControlWithLimitRoundTripRef.xml
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/iidm/iidm-serde/src/test/resources/V1_12/eurostag-tutorial1-lf-extensions.bin b/iidm/iidm-serde/src/test/resources/V1_12/eurostag-tutorial1-lf-extensions.bin
deleted file mode 100644
index 192b1c97131..00000000000
Binary files a/iidm/iidm-serde/src/test/resources/V1_12/eurostag-tutorial1-lf-extensions.bin and /dev/null differ
diff --git a/iidm/iidm-serde/src/test/resources/V1_12/eurostag-tutorial1-lf-extensions.json b/iidm/iidm-serde/src/test/resources/V1_12/eurostag-tutorial1-lf-extensions.json
index e517fec6c07..7fa2484b7ec 100644
--- a/iidm/iidm-serde/src/test/resources/V1_12/eurostag-tutorial1-lf-extensions.json
+++ b/iidm/iidm-serde/src/test/resources/V1_12/eurostag-tutorial1-lf-extensions.json
@@ -5,7 +5,7 @@
"version" : "1.1"
}, {
"extensionName" : "activePowerControl",
- "version" : "1.1"
+ "version" : "1.2"
} ],
"id" : "sim1",
"caseDate" : "2013-01-15T18:45:00.000+01:00",
diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractActivePowerControlTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractActivePowerControlTest.java
index d5b3e28ae5a..32f2b1e213f 100644
--- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractActivePowerControlTest.java
+++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractActivePowerControlTest.java
@@ -100,15 +100,103 @@ public void variantsCloneTest() {
}
}
+ @Test
+ public void variantsCloneTestWithOverride() {
+ String variant1 = "variant1";
+ String variant2 = "variant2";
+ String variant3 = "variant3";
+
+ Network network = BatteryNetworkFactory.create();
+ Battery bat = network.getBattery("BAT");
+ assertNotNull(bat);
+ bat.newExtension(ActivePowerControlAdder.class)
+ .withDroop(4.0)
+ .withParticipate(true)
+ .withParticipationFactor(1.2)
+ .withMinPOverride(10)
+ .withMaxPOverride(100)
+ .add();
+ ActivePowerControl activePowerControl = bat.getExtension(ActivePowerControl.class);
+ assertNotNull(activePowerControl);
+
+ // Testing variant cloning
+ VariantManager variantManager = network.getVariantManager();
+ variantManager.cloneVariant(INITIAL_VARIANT_ID, variant1);
+ variantManager.cloneVariant(variant1, variant2);
+ variantManager.setWorkingVariant(variant1);
+ checkValues3(activePowerControl);
+
+ // Testing setting different values in the cloned variant and going back to the initial one
+ activePowerControl.setDroop(6.0);
+ activePowerControl.setParticipate(false);
+ activePowerControl.setParticipationFactor(3.0);
+ activePowerControl.setMaxPOverride(110.);
+ activePowerControl.setMinPOverride(Double.NaN);
+ checkValues4(activePowerControl);
+
+ activePowerControl.setMinPOverride(11.);
+ activePowerControl.setMaxPOverride(Double.NaN);
+ checkValues5(activePowerControl);
+
+ variantManager.setWorkingVariant(INITIAL_VARIANT_ID);
+ checkValues3(activePowerControl);
+
+ // Removes a variant then adds another variant to test variant recycling (hence calling allocateVariantArrayElement)
+ variantManager.removeVariant(variant1);
+ List targetVariantIds = Arrays.asList(variant1, variant3);
+ variantManager.cloneVariant(INITIAL_VARIANT_ID, targetVariantIds);
+ variantManager.setWorkingVariant(variant1);
+ checkValues3(activePowerControl);
+ variantManager.setWorkingVariant(variant3);
+ checkValues3(activePowerControl);
+
+ // Test removing current variant
+ variantManager.removeVariant(variant3);
+ try {
+ activePowerControl.getDroop();
+ fail();
+ } catch (PowsyblException e) {
+ assertEquals("Variant index not set", e.getMessage());
+ }
+ }
+
private static void checkValues1(ActivePowerControl activePowerControl) {
assertTrue(activePowerControl.isParticipate());
assertEquals(4.0, activePowerControl.getDroop(), 0.0);
assertEquals(1.2, activePowerControl.getParticipationFactor(), 0.0);
+ assertTrue(activePowerControl.getMaxPOverride().isEmpty());
+ assertTrue(activePowerControl.getMinPOverride().isEmpty());
}
private static void checkValues2(ActivePowerControl activePowerControl) {
assertFalse(activePowerControl.isParticipate());
assertEquals(6.0, activePowerControl.getDroop(), 0.0);
assertEquals(3.0, activePowerControl.getParticipationFactor(), 0.0);
+ assertTrue(activePowerControl.getMaxPOverride().isEmpty());
+ assertTrue(activePowerControl.getMinPOverride().isEmpty());
+ }
+
+ private static void checkValues3(ActivePowerControl activePowerControl) {
+ assertTrue(activePowerControl.isParticipate());
+ assertEquals(4.0, activePowerControl.getDroop(), 0.0);
+ assertEquals(1.2, activePowerControl.getParticipationFactor(), 0.0);
+ assertEquals(10, activePowerControl.getMinPOverride().getAsDouble());
+ assertEquals(100, activePowerControl.getMaxPOverride().getAsDouble());
+ }
+
+ private static void checkValues4(ActivePowerControl activePowerControl) {
+ assertFalse(activePowerControl.isParticipate());
+ assertEquals(6.0, activePowerControl.getDroop(), 0.0);
+ assertEquals(3.0, activePowerControl.getParticipationFactor(), 0.0);
+ assertTrue(activePowerControl.getMinPOverride().isEmpty());
+ assertEquals(110, activePowerControl.getMaxPOverride().getAsDouble());
+ }
+
+ private static void checkValues5(ActivePowerControl activePowerControl) {
+ assertFalse(activePowerControl.isParticipate());
+ assertEquals(6.0, activePowerControl.getDroop(), 0.0);
+ assertEquals(3.0, activePowerControl.getParticipationFactor(), 0.0);
+ assertTrue(activePowerControl.getMaxPOverride().isEmpty());
+ assertEquals(11, activePowerControl.getMinPOverride().getAsDouble());
}
}
diff --git a/security-analysis/security-analysis-api/src/main/java/com/powsybl/security/limitreduction/AbstractLimitReductionsApplier.java b/security-analysis/security-analysis-api/src/main/java/com/powsybl/security/limitreduction/AbstractLimitReductionsApplier.java
index fafccf451ed..b6b583e80ba 100644
--- a/security-analysis/security-analysis-api/src/main/java/com/powsybl/security/limitreduction/AbstractLimitReductionsApplier.java
+++ b/security-analysis/security-analysis-api/src/main/java/com/powsybl/security/limitreduction/AbstractLimitReductionsApplier.java
@@ -61,7 +61,7 @@ protected Optional> computeUncachedLimits(P processable, Limi
AbstractLimitsReducerCreator> limitsReducerCreator = Objects.requireNonNull(getLimitsReducerCreator());
NetworkElement networkElement = Objects.requireNonNull(asNetworkElement(processable));
AbstractLimitsReducer limitsReducer = limitsReducerCreator.create(networkElement.getId(), originalLimits.get());
- updateLimitReducer(limitsReducer, networkElement, limitType, monitoringOnly);
+ updateLimitReducer(limitsReducer, networkElement, limitType, side, monitoringOnly);
LimitsContainer limitsContainer = limitsReducer.getLimits();
// Cache the value to avoid recomputing it
@@ -91,11 +91,11 @@ protected Optional> computeUncachedLimits(P processable, Limi
protected abstract NetworkElement asNetworkElement(P processable);
private void updateLimitReducer(AbstractLimitsReducer> limitsReducer, NetworkElement networkElement,
- LimitType limitType, boolean monitoringOnly) {
+ LimitType limitType, ThreeSides side, boolean monitoringOnly) {
for (LimitReduction limitReduction : reductionsForThisContingency) {
if (limitReduction.getLimitType() == limitType
&& limitReduction.isMonitoringOnly() == monitoringOnly
- && isNetworkElementAffectedByLimitReduction(networkElement, limitReduction)) {
+ && isNetworkElementAffectedByLimitReduction(networkElement, side, limitReduction)) {
setLimitReductionsToLimitReducer(limitsReducer, limitReduction);
}
}
@@ -138,8 +138,8 @@ protected static boolean isContingencyInContingencyContext(ContingencyContext co
|| contingencyContext.getContextType() == SPECIFIC && contingencyContext.getContingencyId().equals(contingencyId);
}
- protected static boolean isNetworkElementAffectedByLimitReduction(NetworkElement networkElement, LimitReduction limitReduction) {
- NetworkElementVisitor networkElementVisitor = new NetworkElementVisitor(networkElement);
+ protected static boolean isNetworkElementAffectedByLimitReduction(NetworkElement networkElement, ThreeSides side, LimitReduction limitReduction) {
+ NetworkElementVisitor networkElementVisitor = new NetworkElementVisitor(networkElement, side);
List networkElementCriteria = limitReduction.getNetworkElementCriteria();
return networkElementCriteria.isEmpty()
|| networkElementCriteria.stream().anyMatch(networkElementCriterion -> networkElementCriterion.accept(networkElementVisitor));
diff --git a/security-analysis/security-analysis-api/src/test/java/com/powsybl/security/limitreduction/DefaultLimitReductionsApplierTest.java b/security-analysis/security-analysis-api/src/test/java/com/powsybl/security/limitreduction/DefaultLimitReductionsApplierTest.java
index dfce0cf8a2a..eb3f8e0438c 100644
--- a/security-analysis/security-analysis-api/src/test/java/com/powsybl/security/limitreduction/DefaultLimitReductionsApplierTest.java
+++ b/security-analysis/security-analysis-api/src/test/java/com/powsybl/security/limitreduction/DefaultLimitReductionsApplierTest.java
@@ -8,13 +8,13 @@
package com.powsybl.security.limitreduction;
import com.powsybl.contingency.ContingencyContext;
+import com.powsybl.iidm.criteria.AtLeastOneNominalVoltageCriterion;
+import com.powsybl.iidm.criteria.IdentifiableCriterion;
import com.powsybl.iidm.criteria.NetworkElementIdListCriterion;
+import com.powsybl.iidm.criteria.VoltageInterval;
import com.powsybl.iidm.criteria.duration.EqualityTemporaryDurationCriterion;
import com.powsybl.iidm.criteria.duration.PermanentDurationCriterion;
-import com.powsybl.iidm.network.LimitType;
-import com.powsybl.iidm.network.LoadingLimits;
-import com.powsybl.iidm.network.Network;
-import com.powsybl.iidm.network.ThreeSides;
+import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.limitmodification.result.LimitsContainer;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import org.junit.jupiter.api.BeforeAll;
@@ -63,10 +63,17 @@ static void init() {
.withNetworkElementCriteria(new NetworkElementIdListCriterion(Set.of("NHV1_NHV2_1")))
.withLimitDurationCriteria(new EqualityTemporaryDurationCriterion(60))
.build();
- LimitReduction reduction5 = LimitReduction.builder(LimitType.CURRENT, 0.2)
+ LimitReduction reduction5 = LimitReduction.builder(LimitType.CURRENT, 0.1)
+ .withMonitoringOnly(false)
+ .withContingencyContext(ContingencyContext.specificContingency("contingency5"))
+ // Applicable only for the 2 winding transformer NHV2_NLOAD on Side 2
+ .withNetworkElementCriteria(new IdentifiableCriterion(new AtLeastOneNominalVoltageCriterion(
+ VoltageInterval.between(150., 160., true, true))))
+ .build();
+ LimitReduction reduction6 = LimitReduction.builder(LimitType.CURRENT, 0.2)
.withMonitoringOnly(true)
.build();
- applier = new DefaultLimitReductionsApplier(List.of(reduction1, reduction2, reduction3, reduction4, reduction5));
+ applier = new DefaultLimitReductionsApplier(List.of(reduction1, reduction2, reduction3, reduction4, reduction5, reduction6));
}
@Test
@@ -176,6 +183,44 @@ void noLimitsToReduceTest() {
assertTrue(optLimits.isEmpty());
}
+ @Test
+ void reduceOnOneSideOnlyTest() {
+ applier.setWorkingContingency("contingency5");
+ TwoWindingsTransformer nhv2Nload = network.getTwoWindingsTransformer("NHV2_NLOAD");
+ nhv2Nload.newCurrentLimits1()
+ .setPermanentLimit(1000.)
+ .beginTemporaryLimit()
+ .setValue(1200.)
+ .setAcceptableDuration(60)
+ .setName("60'")
+ .endTemporaryLimit()
+ .add();
+ nhv2Nload.newCurrentLimits2()
+ .setPermanentLimit(1000.)
+ .beginTemporaryLimit()
+ .setValue(1200.)
+ .setAcceptableDuration(60)
+ .setName("60'")
+ .endTemporaryLimit()
+ .add();
+ // The reduction only applies on side 2 for NHV2_NLOAD
+ Optional> optLimits = applier.computeLimits(nhv2Nload,
+ LimitType.CURRENT, ThreeSides.ONE, false);
+ assertTrue(optLimits.isPresent());
+ assertEquals(1000., optLimits.get().getLimits().getPermanentLimit(), 0.01);
+ assertEquals(1200., optLimits.get().getLimits().getTemporaryLimitValue(60), 0.01);
+ assertFalse(optLimits.get().isDistinct());
+
+ // The reduction only applies on side 1 for NHV2_NLOAD
+ optLimits = applier.computeLimits(nhv2Nload, LimitType.CURRENT, ThreeSides.TWO, false);
+ assertTrue(optLimits.isPresent());
+ assertEquals(1000., optLimits.get().getOriginalLimits().getPermanentLimit(), 0.01);
+ assertEquals(100., optLimits.get().getLimits().getPermanentLimit(), 0.01);
+ assertEquals(1200., optLimits.get().getOriginalLimits().getTemporaryLimitValue(60), 0.01);
+ assertEquals(120., optLimits.get().getLimits().getTemporaryLimitValue(60), 0.01);
+ assertTrue(optLimits.get().isDistinct());
+ }
+
@ParameterizedTest(name = "{0}")
@MethodSource("getNoChangesComputers")
void noChangesTest(String desc, DefaultLimitReductionsApplier noChangesComputer) {