Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dangling lines for expert filter #42

Merged
merged 10 commits into from
Jul 25, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ 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 DANGLING_LINE -> getDanglingLinesFieldValue(field, propertyName, (DanglingLine) identifiable);
case THREE_WINDINGS_TRANSFORMER -> getThreeWindingsTransformerFieldValue(field, propertyName, (ThreeWindingsTransformer) identifiable);
case HVDC_LINE -> getHvdcLineFieldValue(field, propertyName, (HvdcLine) identifiable);
default -> throw new PowsyblException(TYPE_NOT_IMPLEMENTED + " [" + identifiable.getType() + "]");
Expand Down Expand Up @@ -538,6 +539,26 @@ private static String getStaticVarCompensatorFieldValue(FieldType field, String
};
}

private static String getDanglingLinesFieldValue(FieldType field, String propertyName, DanglingLine danglingLine) {
return switch (field) {
case CONNECTED -> getTerminalFieldValue(field, danglingLine.getTerminal());
case COUNTRY,
VOLTAGE_LEVEL_ID,
NOMINAL_VOLTAGE -> getVoltageLevelFieldValue(field, null, danglingLine.getTerminal().getVoltageLevel());
case VOLTAGE_LEVEL_PROPERTIES,
SUBSTATION_PROPERTIES -> getVoltageLevelFieldValue(field, propertyName, danglingLine.getTerminal().getVoltageLevel());
case P0 -> String.valueOf(danglingLine.getP0());
case Q0 -> String.valueOf(danglingLine.getQ0());
case SERIE_RESISTANCE -> String.valueOf(danglingLine.getR());
case SERIE_REACTANCE -> String.valueOf(danglingLine.getX());
case SHUNT_SUSCEPTANCE -> String.valueOf(danglingLine.getB());
case SHUNT_CONDUCTANCE -> String.valueOf(danglingLine.getG());
case PAIRED -> String.valueOf(danglingLine.isPaired());
default ->
throw new PowsyblException(FIELD_AND_TYPE_NOT_IMPLEMENTED + " [" + field + "," + danglingLine.getType() + "]");
};
}

private static String getStandbyAutomatonFieldValue(FieldType field, StaticVarCompensator svar) {
StandbyAutomaton standbyAutomaton = svar.getExtension(StandbyAutomaton.class);
if (standbyAutomaton == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public enum FieldType {
SERIE_RESISTANCE_2,
SERIE_RESISTANCE_3,
SERIE_REACTANCE,
SHUNT_SUSCEPTANCE,
SHUNT_CONDUCTANCE,
SERIE_REACTANCE_1,
SERIE_REACTANCE_2,
SERIE_REACTANCE_3,
Expand Down Expand Up @@ -132,6 +134,7 @@ public enum FieldType {
LOW_VOLTAGE_THRESHOLD,
HIGH_VOLTAGE_THRESHOLD,
SUSCEPTANCE_FIX,
PAIRED,
CONVERTERS_MODE,
CONVERTER_STATION_ID_1,
CONVERTER_STATION_NOMINAL_VOLTAGE_1,
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);

DanglingLine dl = Mockito.mock(DanglingLine.class);
Mockito.when(dl.getType()).thenReturn(IdentifiableType.DANGLING_LINE);

TwoWindingsTransformer twoWindingsTransformer = Mockito.mock(TwoWindingsTransformer.class);
Mockito.when(twoWindingsTransformer.getType()).thenReturn(IdentifiableType.TWO_WINDINGS_TRANSFORMER);

Expand All @@ -86,6 +89,7 @@ static Stream<Arguments> provideArgumentsForTestWithException() {
Arguments.of(EQUALS, FieldType.CONNECTED, twoWindingsTransformer, PowsyblException.class),
Arguments.of(EQUALS, FieldType.RATED_S, threeWindingsTransformer, PowsyblException.class),
Arguments.of(EQUALS, FieldType.RATED_S, hvdcLine, PowsyblException.class),
Arguments.of(EQUALS, FieldType.RATED_S, dl, PowsyblException.class),

// --- Test an unsupported operator for this rule type --- //
Arguments.of(IS, FieldType.VOLTAGE_REGULATOR_ON, generator, PowsyblException.class)
Expand All @@ -101,6 +105,7 @@ static Stream<Arguments> provideArgumentsForTestWithException() {
"provideArgumentsForLoadTest",
"provideArgumentsForTwoWindingTransformerTest",
"provideArgumentsForStaticVarCompensatorTest",
"provideArgumentsForDanglingLineTest",
"provideArgumentsForThreeWindingTransformerTest",
"provideArgumentsForHvdcLinesTest",
})
Expand Down Expand Up @@ -506,4 +511,34 @@ private static Stream<Arguments> provideArgumentsForStaticVarCompensatorTest() {
Arguments.of(NOT_EXISTS, FieldType.AUTOMATE, null, svar1, true)
);
}

private static Stream<Arguments> provideArgumentsForDanglingLineTest() {

DanglingLine danglingLine = Mockito.mock(DanglingLine.class);
Mockito.when(danglingLine.getType()).thenReturn(IdentifiableType.DANGLING_LINE);
//Generator fields
Mockito.when(danglingLine.isPaired()).thenReturn(true);
// Terminal fields
Terminal terminal = Mockito.mock(Terminal.class);
Mockito.when(terminal.isConnected()).thenReturn(true);
Mockito.when(danglingLine.getTerminal()).thenReturn(terminal);

return Stream.of(
// --- EQUALS--- //
//Generator fields
Arguments.of(EQUALS, FieldType.PAIRED, true, danglingLine, true),
Arguments.of(EQUALS, FieldType.PAIRED, false, danglingLine, false),
// Terminal fields
Arguments.of(EQUALS, FieldType.CONNECTED, true, danglingLine, true),
Arguments.of(EQUALS, FieldType.CONNECTED, false, danglingLine, false),

// --- NOT_EQUALS--- //
//Generator fields
Arguments.of(NOT_EQUALS, FieldType.PAIRED, false, danglingLine, true),
Arguments.of(NOT_EQUALS, FieldType.PAIRED, true, danglingLine, false),
// Terminal fields
Arguments.of(NOT_EQUALS, FieldType.CONNECTED, false, danglingLine, true),
Arguments.of(NOT_EQUALS, FieldType.CONNECTED, true, danglingLine, false)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ static Stream<Arguments> provideArgumentsForTestWithException() {
"provideArgumentsForLinesTest",
"provideArgumentsForTwoWindingTransformerTest",
"provideArgumentsForStaticVarCompensatorTest",
"provideArgumentsForDanglingLineTest",
"provideArgumentsForThreeWindingTransformerTest",
"provideArgumentsForHvdcLineTest",
})
Expand Down Expand Up @@ -416,6 +417,42 @@ private static Stream<Arguments> provideArgumentsForBatteryTest() {
);
}

private static Stream<Arguments> provideArgumentsForDanglingLineTest() {

DanglingLine danglingLine = Mockito.mock(DanglingLine.class);
Mockito.when(danglingLine.getType()).thenReturn(IdentifiableType.DANGLING_LINE);
// VoltageLevel fields
Substation substation = Mockito.mock(Substation.class);
VoltageLevel voltageLevel = Mockito.mock(VoltageLevel.class);
Mockito.when(voltageLevel.getSubstation()).thenReturn(Optional.of(substation));
Terminal terminal = Mockito.mock(Terminal.class);
Mockito.when(terminal.getVoltageLevel()).thenReturn(voltageLevel);
Mockito.when(danglingLine.getTerminal()).thenReturn(terminal);
Mockito.when(substation.getCountry()).thenReturn(Optional.of(Country.FR));

return Stream.of(
// --- EQUALS --- //
// VoltageLevel fields
Arguments.of(EQUALS, FieldType.COUNTRY, Country.FR.name(), null, danglingLine, true),
Arguments.of(EQUALS, FieldType.COUNTRY, Country.DE.name(), null, danglingLine, false),

// --- NOT_EQUALS --- //
// VoltageLevel fields
Arguments.of(NOT_EQUALS, FieldType.COUNTRY, Country.DE.name(), null, danglingLine, true),
Arguments.of(NOT_EQUALS, FieldType.COUNTRY, Country.FR.name(), null, danglingLine, false),

// --- IN --- //
// VoltageLevel fields
Arguments.of(IN, FieldType.COUNTRY, null, Set.of(Country.FR.name(), Country.DE.name()), danglingLine, true),
Arguments.of(IN, FieldType.COUNTRY, null, Set.of(Country.BE.name(), Country.DE.name()), danglingLine, false),

// --- NOT_IN --- //
// VoltageLevel fields
Arguments.of(NOT_IN, FieldType.COUNTRY, null, Set.of(Country.BE.name(), Country.DE.name()), danglingLine, true),
Arguments.of(NOT_IN, FieldType.COUNTRY, null, Set.of(Country.FR.name(), Country.DE.name()), danglingLine, false)
);
}

private static Stream<Arguments> provideArgumentsForVoltageLevelTest() {

VoltageLevel voltageLevel = Mockito.mock(VoltageLevel.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class FilterUuidExpertRuleTest {
private static final UUID FILTER_VOLTAGE_LEVEL_1_LINE_2_UUID = UUID.fromString("49281814-7977-4592-ba19-88027e4254e4");
private static final UUID FILTER_VOLTAGE_LEVEL_2_LINE_2_UUID = UUID.fromString("49281815-7977-4592-ba19-88027e4254e4");

private static final UUID FILTER_DANGLING_LINE_1_UUID = UUID.fromString("18273121-7977-4592-ba19-88027e4254e4");
private static final UUID FILTER_DANGLING_LINE_2_UUID = UUID.fromString("18273122-7977-4592-ba19-88027e4254e4");
private static final UUID FILTER_VOLTAGE_LEVEL_DANGLING_LINE_1_UUID = UUID.fromString("18273123-7977-4592-ba19-88027e4254e4");
private static final UUID FILTER_VOLTAGE_LEVEL_DANGLING_LINE_2_UUID = UUID.fromString("18273124-7977-4592-ba19-88027e4254e4");

private static final UUID FILTER_HVDC_LINE_1_UUID = UUID.fromString("65432936-7977-4592-ba19-88027e4254e4");
private static final UUID FILTER_HVDC_LINE_2_UUID = UUID.fromString("65432937-7977-4592-ba19-88027e4254e4");
private static final UUID FILTER_VOLTAGE_LEVEL_1_HVDC_LINE_1_UUID = UUID.fromString("65432938-7977-4592-ba19-88027e4254e4");
Expand Down Expand Up @@ -104,13 +109,17 @@ private static Stream<Arguments> provideArgumentsForTestWithException() {
Line line = Mockito.mock(Line.class);
Mockito.when(line.getType()).thenReturn(IdentifiableType.LINE);

DanglingLine danglingLine = Mockito.mock(DanglingLine.class);
Mockito.when(danglingLine.getType()).thenReturn(IdentifiableType.DANGLING_LINE);

return Stream.of(
// --- Test an unsupported field for each equipment --- //
Arguments.of(IS, FieldType.P0, generator, PowsyblException.class),
Arguments.of(IS, FieldType.RATED_S, load, PowsyblException.class),
Arguments.of(IS, FieldType.MIN_P, shuntCompensator, PowsyblException.class),
Arguments.of(IS, FieldType.HIGH_VOLTAGE_LIMIT, battery, PowsyblException.class),
Arguments.of(IS, FieldType.MARGINAL_COST, line, PowsyblException.class),
Arguments.of(IS, FieldType.MARGINAL_COST, danglingLine, PowsyblException.class),

// --- Test an unsupported operator for this rule type --- //
Arguments.of(EQUALS, FieldType.ID, generator, PowsyblException.class),
Expand Down Expand Up @@ -156,13 +165,25 @@ private void initMockFilters(Network network, MockedStatic<FilterServiceUtils> f
mockGetFilterEquipments(filtersUtilsMock, network, FILTER_VOLTAGE_LEVEL_1_LINE_2_UUID, new IdentifiableAttributes("VL12", IdentifiableType.VOLTAGE_LEVEL, 100D));
mockGetFilterEquipments(filtersUtilsMock, network, FILTER_VOLTAGE_LEVEL_2_LINE_2_UUID, new IdentifiableAttributes("VL22", IdentifiableType.VOLTAGE_LEVEL, 100D));

// Dangling Lines
mockGetFilterEquipments(filtersUtilsMock, network, FILTER_DANGLING_LINE_1_UUID, new IdentifiableAttributes("ID1", IdentifiableType.DANGLING_LINE, 100D));
mockGetFilterEquipments(filtersUtilsMock, network, FILTER_DANGLING_LINE_2_UUID, new IdentifiableAttributes("ID2", IdentifiableType.DANGLING_LINE, 100D));
mockGetFilterEquipments(filtersUtilsMock, network, FILTER_VOLTAGE_LEVEL_DANGLING_LINE_1_UUID, new IdentifiableAttributes("VL1", IdentifiableType.VOLTAGE_LEVEL, 100D));
mockGetFilterEquipments(filtersUtilsMock, network, FILTER_VOLTAGE_LEVEL_DANGLING_LINE_2_UUID, new IdentifiableAttributes("VL2", IdentifiableType.VOLTAGE_LEVEL, 100D));

// Hvdc Line
mockGetFilterEquipments(filtersUtilsMock, network, FILTER_HVDC_LINE_1_UUID, new IdentifiableAttributes("ID1", IdentifiableType.HVDC_LINE, 100D));
mockGetFilterEquipments(filtersUtilsMock, network, FILTER_HVDC_LINE_2_UUID, new IdentifiableAttributes("ID2", IdentifiableType.HVDC_LINE, 100D));
mockGetFilterEquipments(filtersUtilsMock, network, FILTER_VOLTAGE_LEVEL_1_HVDC_LINE_1_UUID, new IdentifiableAttributes("VL11", IdentifiableType.VOLTAGE_LEVEL, 100D));
mockGetFilterEquipments(filtersUtilsMock, network, FILTER_VOLTAGE_LEVEL_2_HVDC_LINE_1_UUID, new IdentifiableAttributes("VL21", IdentifiableType.VOLTAGE_LEVEL, 100D));
mockGetFilterEquipments(filtersUtilsMock, network, FILTER_VOLTAGE_LEVEL_1_HVDC_LINE_2_UUID, new IdentifiableAttributes("VL12", IdentifiableType.VOLTAGE_LEVEL, 100D));
mockGetFilterEquipments(filtersUtilsMock, network, FILTER_VOLTAGE_LEVEL_2_HVDC_LINE_2_UUID, new IdentifiableAttributes("VL22", IdentifiableType.VOLTAGE_LEVEL, 100D));

// Dangling Lines
mockGetFilterEquipments(filtersUtilsMock, network, FILTER_DANGLING_LINE_1_UUID, new IdentifiableAttributes("ID1", IdentifiableType.DANGLING_LINE, 100D));
mockGetFilterEquipments(filtersUtilsMock, network, FILTER_DANGLING_LINE_2_UUID, new IdentifiableAttributes("ID2", IdentifiableType.DANGLING_LINE, 100D));
mockGetFilterEquipments(filtersUtilsMock, network, FILTER_VOLTAGE_LEVEL_DANGLING_LINE_1_UUID, new IdentifiableAttributes("VL1", IdentifiableType.VOLTAGE_LEVEL, 100D));
mockGetFilterEquipments(filtersUtilsMock, network, FILTER_VOLTAGE_LEVEL_DANGLING_LINE_2_UUID, new IdentifiableAttributes("VL2", IdentifiableType.VOLTAGE_LEVEL, 100D));
}

@ParameterizedTest
Expand All @@ -171,8 +192,11 @@ private void initMockFilters(Network network, MockedStatic<FilterServiceUtils> f
"provideArgumentsForLoadTest",
"provideArgumentsForBatteryTest",
"provideArgumentsForShuntCompensatorTest",
"provideArgumentsForDanglingLinesTest",
"provideArgumentsForLineTest",
"provideArgumentsForHvdcTest"
"provideArgumentsForHvdcTest",
"provideArgumentsForLineTest",
"provideArgumentsForDanglingLinesTest",
})
void testEvaluateRule(OperatorType operator, FieldType field, String value, Set<String> values, Identifiable<?> equipment, boolean expected) {
try (MockedStatic<FilterServiceUtils> filterServiceUtilsMockedStatic = Mockito.mockStatic(FilterServiceUtils.class)) {
Expand Down Expand Up @@ -493,4 +517,50 @@ private static Stream<Arguments> provideArgumentsForHvdcTest() {
Arguments.of(IS_NOT_PART_OF, FieldType.VOLTAGE_LEVEL_ID_2, null, Set.of(FILTER_VOLTAGE_LEVEL_2_HVDC_LINE_2_UUID.toString()), hvdcLine1, true)
);
}

private static Stream<Arguments> provideArgumentsForDanglingLinesTest() {
Network network = Mockito.mock(Network.class);

DanglingLine danglingLine1 = Mockito.mock(DanglingLine.class);
Mockito.when(danglingLine1.getType()).thenReturn(IdentifiableType.DANGLING_LINE);
Mockito.when(danglingLine1.getNetwork()).thenReturn(network);
DanglingLine danglingLine2 = Mockito.mock(DanglingLine.class);
Mockito.when(danglingLine2.getType()).thenReturn(IdentifiableType.DANGLING_LINE);
Mockito.when(danglingLine2.getNetwork()).thenReturn(network);

// Common fields
Mockito.when(danglingLine1.getId()).thenReturn("ID1");
Mockito.when(danglingLine2.getId()).thenReturn("ID2");

// VoltageLevel fields
VoltageLevel voltageLevel1 = Mockito.mock(VoltageLevel.class);
Mockito.when(voltageLevel1.getId()).thenReturn("VL1");
Terminal terminal1 = Mockito.mock(Terminal.class);
Mockito.when(terminal1.getVoltageLevel()).thenReturn(voltageLevel1);
Mockito.when(danglingLine1.getTerminal()).thenReturn(terminal1);

VoltageLevel voltageLevel2 = Mockito.mock(VoltageLevel.class);
Mockito.when(voltageLevel2.getId()).thenReturn("VL2");
Terminal terminal2 = Mockito.mock(Terminal.class);
Mockito.when(terminal2.getVoltageLevel()).thenReturn(voltageLevel2);
Mockito.when(danglingLine2.getTerminal()).thenReturn(terminal2);

return Stream.of(
// --- IS_PART_OF --- //
// Common fields
Arguments.of(IS_PART_OF, FieldType.ID, null, Set.of(FILTER_DANGLING_LINE_1_UUID.toString()), danglingLine1, true),
Arguments.of(IS_PART_OF, FieldType.ID, null, Set.of(FILTER_DANGLING_LINE_2_UUID.toString()), danglingLine2, true),
// VoltageLevel fields
Arguments.of(IS_PART_OF, FieldType.VOLTAGE_LEVEL_ID, null, Set.of(FILTER_VOLTAGE_LEVEL_DANGLING_LINE_1_UUID.toString()), danglingLine1, true),
Arguments.of(IS_PART_OF, FieldType.VOLTAGE_LEVEL_ID, null, Set.of(FILTER_VOLTAGE_LEVEL_DANGLING_LINE_2_UUID.toString()), danglingLine2, true),

// --- IS_NOT_PART_OF --- //
// Common fields
Arguments.of(IS_NOT_PART_OF, FieldType.ID, null, Set.of(FILTER_DANGLING_LINE_1_UUID.toString()), danglingLine2, true),
Arguments.of(IS_NOT_PART_OF, FieldType.ID, null, Set.of(FILTER_DANGLING_LINE_2_UUID.toString()), danglingLine1, true),
// VoltageLevel fields
Arguments.of(IS_NOT_PART_OF, FieldType.VOLTAGE_LEVEL_ID, null, Set.of(FILTER_VOLTAGE_LEVEL_1_LINE_2_UUID.toString()), danglingLine1, true),
Arguments.of(IS_NOT_PART_OF, FieldType.VOLTAGE_LEVEL_ID, null, Set.of(FILTER_VOLTAGE_LEVEL_GENERATOR_1_UUID.toString()), danglingLine2, true)
);
}
}
Loading
Loading