Skip to content

Commit

Permalink
add hvdc category for expert filters (#41)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: Etienne LESOT <[email protected]>
Co-authored-by: Thang PHAM <[email protected]>
  • Loading branch information
EtienneLt and thangqp authored Jul 19, 2024
1 parent 635848b commit 025b4b1
Show file tree
Hide file tree
Showing 10 changed files with 715 additions and 19 deletions.
10 changes: 8 additions & 2 deletions src/main/java/org/gridsuite/filter/utils/FiltersUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ private static List<Identifiable<?>> get3WTransformerList(Network network, Abstr
}
}

private static List<Identifiable<?>> getHvdcList(Network network, AbstractFilter filter) {
private static List<Identifiable<?>> getHvdcList(Network network, AbstractFilter filter, FilterLoader filterLoader) {
if (filter instanceof CriteriaFilter criteriaFilter) {
HvdcLineFilter hvdcLineFilter = (HvdcLineFilter) criteriaFilter.getEquipmentFilterForm();
Stream<HvdcLine> stream = network.getHvdcLineStream()
Expand All @@ -397,6 +397,12 @@ private static List<Identifiable<?>> getHvdcList(Network network, AbstractFilter
Stream<HvdcLine> stream = network.getHvdcLineStream()
.filter(hvdcLine -> equipmentsIds.contains(hvdcLine.getId()));
return new ArrayList<>(stream.toList());
} else if (filter instanceof ExpertFilter expertFilter) {
var rule = expertFilter.getRules();
Map<UUID, FilterEquipments> cachedUuidFilters = new HashMap<>();
Stream<HvdcLine> stream = network.getHvdcLineStream()
.filter(ident -> rule.evaluateRule(ident, filterLoader, cachedUuidFilters));
return new ArrayList<>(stream.toList());
} else {
return List.of();
}
Expand Down Expand Up @@ -463,7 +469,7 @@ public static List<Identifiable<?>> getIdentifiables(AbstractFilter filter, Netw
case SHUNT_COMPENSATOR -> getShuntCompensatorList(network, filter, filterLoader);
case LCC_CONVERTER_STATION -> getLccConverterStationList(network, filter, filterLoader);
case VSC_CONVERTER_STATION -> getVscConverterStationList(network, filter, filterLoader);
case HVDC_LINE -> getHvdcList(network, filter);
case HVDC_LINE -> getHvdcList(network, filter, filterLoader);
case DANGLING_LINE -> getDanglingLineList(network, filter, filterLoader);
case LINE -> getLineList(network, filter, filterLoader);
case TWO_WINDINGS_TRANSFORMER -> get2WTransformerList(network, filter, filterLoader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,39 @@ public static <I extends Identifiable<I>> String getFieldValue(FieldType field,
case SUBSTATION -> getSubstationFieldValue(field, (Substation) identifiable);
case TWO_WINDINGS_TRANSFORMER -> getTwoWindingsTransformerFieldValue(field, propertyName, (TwoWindingsTransformer) identifiable);
case STATIC_VAR_COMPENSATOR -> getStaticVarCompensatorFieldValue(field, propertyName, (StaticVarCompensator) identifiable);
case HVDC_LINE -> getHvdcLineFieldValue(field, propertyName, (HvdcLine) identifiable);
default -> throw new PowsyblException(TYPE_NOT_IMPLEMENTED + " [" + identifiable.getType() + "]");
};
};
}

private static String getHvdcLineFieldValue(FieldType field, String propertyName, HvdcLine hvdcLine) {
return switch (field) {
case CONNECTED_1 -> getTerminalFieldValue(field, hvdcLine.getConverterStation1().getTerminal());
case CONNECTED_2 -> getTerminalFieldValue(field, hvdcLine.getConverterStation2().getTerminal());
case CONVERTERS_MODE -> hvdcLine.getConvertersMode() != null ? hvdcLine.getConvertersMode().name() : null;
case ACTIVE_POWER_SET_POINT -> String.valueOf(hvdcLine.getActivePowerSetpoint());
case MAX_P -> String.valueOf(hvdcLine.getMaxP());
case DC_NOMINAL_VOLTAGE -> String.valueOf(hvdcLine.getNominalV());
case CONVERTER_STATION_ID_1 -> hvdcLine.getConverterStation1().getId();
case CONVERTER_STATION_NOMINAL_VOLTAGE_1 ->
String.valueOf(hvdcLine.getConverterStation1().getTerminal().getVoltageLevel().getNominalV());
case CONVERTER_STATION_ID_2 -> hvdcLine.getConverterStation2().getId();
case CONVERTER_STATION_NOMINAL_VOLTAGE_2 ->
String.valueOf(hvdcLine.getConverterStation2().getTerminal().getVoltageLevel().getNominalV());
case COUNTRY_1, VOLTAGE_LEVEL_ID_1 ->
getVoltageLevelFieldValue(field, null, hvdcLine.getConverterStation1().getTerminal().getVoltageLevel());
case COUNTRY_2, VOLTAGE_LEVEL_ID_2 ->
getVoltageLevelFieldValue(field, null, hvdcLine.getConverterStation2().getTerminal().getVoltageLevel());
case SERIE_RESISTANCE -> String.valueOf(hvdcLine.getR());
case SUBSTATION_PROPERTIES_1 -> hvdcLine.getConverterStation1().getTerminal().getVoltageLevel().getNullableSubstation().getProperty(propertyName);
case SUBSTATION_PROPERTIES_2 -> hvdcLine.getConverterStation2().getTerminal().getVoltageLevel().getNullableSubstation().getProperty(propertyName);
case VOLTAGE_LEVEL_PROPERTIES_1 -> hvdcLine.getConverterStation1().getTerminal().getVoltageLevel().getProperty(propertyName);
case VOLTAGE_LEVEL_PROPERTIES_2 -> hvdcLine.getConverterStation2().getTerminal().getVoltageLevel().getProperty(propertyName);
default -> throw new PowsyblException(FIELD_AND_TYPE_NOT_IMPLEMENTED + " [" + field + "," + hvdcLine.getType() + "]");
};
}

private static String getVoltageLevelFieldValue(FieldType field, String propertyName, VoltageLevel voltageLevel) {
return switch (field) {
case COUNTRY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public enum FieldType {
SVAR_REGULATION_MODE,
VOLTAGE_SET_POINT,
REACTIVE_POWER_SET_POINT,
ACTIVE_POWER_SET_POINT,
REMOTE_REGULATED_TERMINAL, // group criteria of REGULATING_TERMINAL_VL_ID and/or REGULATING_TERMINAL_CONNECTABLE_ID
REGULATING_TERMINAL_VL_ID,
REGULATING_TERMINAL_CONNECTABLE_ID,
Expand All @@ -88,4 +89,10 @@ public enum FieldType {
LOW_VOLTAGE_THRESHOLD,
HIGH_VOLTAGE_THRESHOLD,
SUSCEPTANCE_FIX,
CONVERTERS_MODE,
CONVERTER_STATION_ID_1,
CONVERTER_STATION_NOMINAL_VOLTAGE_1,
CONVERTER_STATION_ID_2,
CONVERTER_STATION_NOMINAL_VOLTAGE_2,
DC_NOMINAL_VOLTAGE,
}
10 changes: 5 additions & 5 deletions src/test/java/org/gridsuite/filter/FiltersUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.gridsuite.filter;

import com.powsybl.iidm.network.HvdcLine;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.IdentifiableType;
import com.powsybl.iidm.network.Network;
Expand Down Expand Up @@ -57,10 +58,7 @@
import java.util.TreeSet;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
Expand Down Expand Up @@ -866,7 +864,9 @@ void testHvdcLineFilter() {
StringExpertRule.builder().combinator(CombinatorType.AND).field(FieldType.ID).operator(OperatorType.IS).value("L").build());

identifiables = FiltersUtils.getIdentifiables(expertFilter, network2, filterLoader);
assertEquals(0, identifiables.size()); // expert filter for HVDC line not yet implemented
assertEquals(1, identifiables.size()); // expert filter for HVDC line is now implemented
assertEquals("L", identifiables.get(0).getId());
assertInstanceOf(HvdcLine.class, identifiables.get(0));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ static Stream<Arguments> provideArgumentsForTestWithException() {
StaticVarCompensator svar = Mockito.mock(StaticVarCompensator.class);
Mockito.when(svar.getType()).thenReturn(IdentifiableType.STATIC_VAR_COMPENSATOR);

HvdcLine hvdcLine = Mockito.mock(HvdcLine.class);
Mockito.when(hvdcLine.getType()).thenReturn(IdentifiableType.HVDC_LINE);

return Stream.of(
// --- Test an unsupported field for each equipment --- //
Arguments.of(EQUALS, FieldType.RATED_S, network, PowsyblException.class),
Expand All @@ -74,6 +77,7 @@ static Stream<Arguments> provideArgumentsForTestWithException() {
Arguments.of(EQUALS, FieldType.RATED_S, bus, PowsyblException.class),
Arguments.of(EQUALS, FieldType.RATED_S, busbarSection, PowsyblException.class),
Arguments.of(EQUALS, FieldType.RATED_S, svar, PowsyblException.class),
Arguments.of(EQUALS, FieldType.RATED_S, hvdcLine, PowsyblException.class),

// --- Test an unsupported operator for this rule type --- //
Arguments.of(IS, FieldType.VOLTAGE_REGULATOR_ON, generator, PowsyblException.class)
Expand All @@ -89,6 +93,7 @@ static Stream<Arguments> provideArgumentsForTestWithException() {
"provideArgumentsForLoadTest",
"provideArgumentsForTwoWindingTransformerTest",
"provideArgumentsForStaticVarCompensatorTest",
"provideArgumentsForHvdcLinesTest",
})
void testEvaluateRule(OperatorType operator, FieldType field, Boolean value, Identifiable<?> equipment, boolean expected) {
BooleanExpertRule rule = BooleanExpertRule.builder().operator(operator).field(field).value(value).build();
Expand Down Expand Up @@ -221,6 +226,40 @@ private static Stream<Arguments> provideArgumentsForLinesTest() {
);
}

private static Stream<Arguments> provideArgumentsForHvdcLinesTest() {

HvdcLine hvdcLine = Mockito.mock(HvdcLine.class);
Mockito.when(hvdcLine.getType()).thenReturn(IdentifiableType.HVDC_LINE);
// Terminal fields
Terminal terminal1 = Mockito.mock(Terminal.class);
Mockito.when(terminal1.isConnected()).thenReturn(true);
HvdcConverterStation converterStation1 = Mockito.mock(HvdcConverterStation.class);
Mockito.when(converterStation1.getTerminal()).thenReturn(terminal1);
Mockito.when(hvdcLine.getConverterStation1()).thenReturn(converterStation1);

Terminal terminal2 = Mockito.mock(Terminal.class);
Mockito.when(terminal2.isConnected()).thenReturn(true);
HvdcConverterStation converterStation2 = Mockito.mock(HvdcConverterStation.class);
Mockito.when(converterStation2.getTerminal()).thenReturn(terminal2);
Mockito.when(hvdcLine.getConverterStation2()).thenReturn(converterStation2);

return Stream.of(
// --- EQUALS--- //
// Terminal fields
Arguments.of(EQUALS, FieldType.CONNECTED_1, true, hvdcLine, true),
Arguments.of(EQUALS, FieldType.CONNECTED_1, false, hvdcLine, false),
Arguments.of(EQUALS, FieldType.CONNECTED_2, true, hvdcLine, true),
Arguments.of(EQUALS, FieldType.CONNECTED_2, false, hvdcLine, false),

// --- NOT_EQUALS--- //
// Terminal fields
Arguments.of(NOT_EQUALS, FieldType.CONNECTED_1, false, hvdcLine, true),
Arguments.of(NOT_EQUALS, FieldType.CONNECTED_1, true, hvdcLine, false),
Arguments.of(NOT_EQUALS, FieldType.CONNECTED_2, false, hvdcLine, true),
Arguments.of(NOT_EQUALS, FieldType.CONNECTED_2, true, hvdcLine, false)
);
}

private static Stream<Arguments> provideArgumentsForTwoWindingTransformerTest() {

TwoWindingsTransformer twoWindingsTransformer = Mockito.mock(TwoWindingsTransformer.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ static Stream<Arguments> provideArgumentsForTestWithException() {
StaticVarCompensator svar = Mockito.mock(StaticVarCompensator.class);
Mockito.when(svar.getType()).thenReturn(IdentifiableType.STATIC_VAR_COMPENSATOR);

HvdcLine hvdcLine = Mockito.mock(HvdcLine.class);
Mockito.when(hvdcLine.getType()).thenReturn(IdentifiableType.HVDC_LINE);

return Stream.of(
// --- Test an unsupported field for each equipment --- //
Arguments.of(EQUALS, FieldType.RATED_S, network, null, null, PowsyblException.class),
Expand All @@ -97,6 +100,7 @@ static Stream<Arguments> provideArgumentsForTestWithException() {
Arguments.of(EQUALS, FieldType.RATED_S, substation, null, null, PowsyblException.class),
Arguments.of(EQUALS, FieldType.P0, twoWindingsTransformer, null, null, PowsyblException.class),
Arguments.of(EQUALS, FieldType.RATED_S, svar, null, null, PowsyblException.class),
Arguments.of(EQUALS, FieldType.RATED_S, hvdcLine, null, null, PowsyblException.class),

// --- Test an unsupported operator for this rule type --- //
Arguments.of(IS, FieldType.ENERGY_SOURCE, generator, null, null, PowsyblException.class),
Expand Down Expand Up @@ -124,6 +128,7 @@ static Stream<Arguments> provideArgumentsForTestWithException() {
"provideArgumentsForLinesTest",
"provideArgumentsForTwoWindingTransformerTest",
"provideArgumentsForStaticVarCompensatorTest",
"provideArgumentsForHvdcLineTest",
})
void testEvaluateRule(OperatorType operator, FieldType field, String value, Set<String> values, Identifiable<?> equipment, boolean expected) {
EnumExpertRule rule = EnumExpertRule.builder().operator(operator).field(field).value(value).values(values).build();
Expand Down Expand Up @@ -690,4 +695,73 @@ private static Stream<Arguments> provideArgumentsForStaticVarCompensatorTest() {
Arguments.of(NOT_IN, FieldType.REGULATION_TYPE, null, Set.of(RegulationType.DISTANT.name()), svar, false)
);
}

private static Stream<Arguments> provideArgumentsForHvdcLineTest() {

HvdcLine hvdcLine = Mockito.mock(HvdcLine.class);
Mockito.when(hvdcLine.getType()).thenReturn(IdentifiableType.HVDC_LINE);

// VoltageLevel fields
Substation substation1 = Mockito.mock(Substation.class);
Substation substation2 = Mockito.mock(Substation.class);
VoltageLevel voltageLevel1 = Mockito.mock(VoltageLevel.class);
VoltageLevel voltageLevel2 = Mockito.mock(VoltageLevel.class);
Terminal terminal1 = Mockito.mock(Terminal.class);
Terminal terminal2 = Mockito.mock(Terminal.class);
HvdcConverterStation converterStation1 = Mockito.mock(HvdcConverterStation.class);
HvdcConverterStation converterStation2 = Mockito.mock(HvdcConverterStation.class);

Mockito.when(voltageLevel1.getSubstation()).thenReturn(Optional.of(substation1));
Mockito.when(voltageLevel2.getSubstation()).thenReturn(Optional.of(substation2));

Mockito.when(terminal1.getVoltageLevel()).thenReturn(voltageLevel1);
Mockito.when(converterStation1.getTerminal()).thenReturn(terminal1);
Mockito.when(substation1.getCountry()).thenReturn(Optional.of(Country.FR));
Mockito.when(hvdcLine.getConverterStation1()).thenReturn(converterStation1);

Mockito.when(terminal2.getVoltageLevel()).thenReturn(voltageLevel2);
Mockito.when(converterStation2.getTerminal()).thenReturn(terminal2);
Mockito.when(substation2.getCountry()).thenReturn(Optional.of(Country.SM));
Mockito.when(hvdcLine.getConverterStation2()).thenReturn(converterStation2);

Mockito.when(hvdcLine.getConvertersMode()).thenReturn(HvdcLine.ConvertersMode.SIDE_1_INVERTER_SIDE_2_RECTIFIER);

return Stream.of(
// --- EQUALS --- //
// VoltageLevel fields
Arguments.of(EQUALS, FieldType.COUNTRY_1, Country.FR.name(), null, hvdcLine, true),
Arguments.of(EQUALS, FieldType.COUNTRY_1, Country.DE.name(), null, hvdcLine, false),
Arguments.of(EQUALS, FieldType.COUNTRY_2, Country.SM.name(), null, hvdcLine, true),
Arguments.of(EQUALS, FieldType.COUNTRY_2, Country.LI.name(), null, hvdcLine, false),
Arguments.of(EQUALS, FieldType.CONVERTERS_MODE, HvdcLine.ConvertersMode.SIDE_1_INVERTER_SIDE_2_RECTIFIER.name(), null, hvdcLine, true),
Arguments.of(EQUALS, FieldType.CONVERTERS_MODE, HvdcLine.ConvertersMode.SIDE_1_RECTIFIER_SIDE_2_INVERTER.name(), null, hvdcLine, false),

// --- NOT_EQUALS --- //
// VoltageLevel fields
Arguments.of(NOT_EQUALS, FieldType.COUNTRY_1, Country.DE.name(), null, hvdcLine, true),
Arguments.of(NOT_EQUALS, FieldType.COUNTRY_1, Country.FR.name(), null, hvdcLine, false),
Arguments.of(NOT_EQUALS, FieldType.COUNTRY_2, Country.LI.name(), null, hvdcLine, true),
Arguments.of(NOT_EQUALS, FieldType.COUNTRY_2, Country.SM.name(), null, hvdcLine, false),
Arguments.of(NOT_EQUALS, FieldType.CONVERTERS_MODE, HvdcLine.ConvertersMode.SIDE_1_INVERTER_SIDE_2_RECTIFIER.name(), null, hvdcLine, false),
Arguments.of(NOT_EQUALS, FieldType.CONVERTERS_MODE, HvdcLine.ConvertersMode.SIDE_1_RECTIFIER_SIDE_2_INVERTER.name(), null, hvdcLine, true),

// --- IN --- //
// VoltageLevel fields
Arguments.of(IN, FieldType.COUNTRY_1, null, Set.of(Country.FR.name(), Country.DE.name()), hvdcLine, true),
Arguments.of(IN, FieldType.COUNTRY_1, null, Set.of(Country.BE.name(), Country.DE.name()), hvdcLine, false),
Arguments.of(IN, FieldType.COUNTRY_2, null, Set.of(Country.SM.name(), Country.FO.name()), hvdcLine, true),
Arguments.of(IN, FieldType.COUNTRY_2, null, Set.of(Country.LI.name(), Country.MC.name()), hvdcLine, false),
Arguments.of(IN, FieldType.CONVERTERS_MODE, null, Set.of(HvdcLine.ConvertersMode.SIDE_1_INVERTER_SIDE_2_RECTIFIER.name()), hvdcLine, true),
Arguments.of(IN, FieldType.CONVERTERS_MODE, null, Set.of(HvdcLine.ConvertersMode.SIDE_1_RECTIFIER_SIDE_2_INVERTER.name()), hvdcLine, false),

// --- NOT_IN --- //
// VoltageLevel fields
Arguments.of(NOT_IN, FieldType.COUNTRY_1, null, Set.of(Country.BE.name(), Country.DE.name()), hvdcLine, true),
Arguments.of(NOT_IN, FieldType.COUNTRY_1, null, Set.of(Country.FR.name(), Country.DE.name()), hvdcLine, false),
Arguments.of(NOT_IN, FieldType.COUNTRY_2, null, Set.of(Country.LI.name(), Country.MC.name()), hvdcLine, true),
Arguments.of(NOT_IN, FieldType.COUNTRY_2, null, Set.of(Country.SM.name(), Country.FO.name()), hvdcLine, false),
Arguments.of(NOT_IN, FieldType.CONVERTERS_MODE, null, Set.of(HvdcLine.ConvertersMode.SIDE_1_INVERTER_SIDE_2_RECTIFIER.name()), hvdcLine, false),
Arguments.of(NOT_IN, FieldType.CONVERTERS_MODE, null, Set.of(HvdcLine.ConvertersMode.SIDE_1_RECTIFIER_SIDE_2_INVERTER.name()), hvdcLine, true)
);
}
}
Loading

0 comments on commit 025b4b1

Please sign in to comment.