Skip to content

Commit

Permalink
Dynamic Simulation - Curve Configuration - Add some expert filter's c…
Browse files Browse the repository at this point in the history
…riteria for Load and Generator
  • Loading branch information
thangqp committed Nov 17, 2023
1 parent b543040 commit 807207c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,36 @@ public static <I extends Identifiable<I>> String getFieldValue(FieldType field,
};
}

private static String getInjectionFieldValue(FieldType field, Injection<?> injection) {
return switch (field) {
case ID -> injection.getId();
case NAME -> injection.getNameOrId();
case COUNTRY -> {
Optional<Country> country = injection.getTerminal().getVoltageLevel().getSubstation().flatMap(Substation::getCountry);
yield country.isPresent() ? String.valueOf(country.get()) : "";
}
case NOMINAL_VOLTAGE -> String.valueOf(injection.getTerminal().getVoltageLevel().getNominalV());
case VOLTAGE_LEVEL_ID -> injection.getTerminal().getVoltageLevel().getId();
default -> throw new PowsyblException("Field " + field + " with " + injection.getType() + " injection type is not implemented with expert filter");
};
}

private static String getLoadFieldValue(FieldType field, Load load) {
return switch (field) {
case ID -> load.getId();
default -> throw new PowsyblException("Field " + field + " with " + load.getType() + " injection type is not implemented with expert filter");
default -> getInjectionFieldValue(field, load);
};
}

private static String getGeneratorFieldValue(FieldType field, Generator generator) {
return switch (field) {
case ID -> generator.getId();
case NAME -> generator.getNameOrId();
case NOMINAL_VOLTAGE -> String.valueOf(generator.getTerminal().getVoltageLevel().getNominalV());
case COUNTRY -> {
Optional<Country> country = generator.getTerminal().getVoltageLevel().getSubstation().flatMap(Substation::getCountry);
yield country.isPresent() ? String.valueOf(country.get()) : "";
}
case ENERGY_SOURCE -> String.valueOf(generator.getEnergySource());
case MIN_P -> String.valueOf(generator.getMinP());
case MAX_P -> String.valueOf(generator.getMaxP());
case TARGET_V -> String.valueOf(generator.getTargetV());
case TARGET_P -> String.valueOf(generator.getTargetP());
case TARGET_Q -> String.valueOf(generator.getTargetQ());
case VOLTAGE_REGULATOR_ON -> String.valueOf(generator.isVoltageRegulatorOn());
default -> getInjectionFieldValue(field, generator);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ public enum FieldType {
TARGET_Q,
ENERGY_SOURCE,
COUNTRY,
VOLTAGE_REGULATOR_ON
VOLTAGE_REGULATOR_ON,
VOLTAGE_LEVEL_ID
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
*/
package org.gridsuite.filter.server;

import com.powsybl.iidm.network.EnergySource;
import com.powsybl.iidm.network.Generator;
import com.powsybl.iidm.network.IdentifiableType;
import com.powsybl.iidm.network.*;
import org.gridsuite.filter.server.dto.expertfilter.expertrule.*;
import org.gridsuite.filter.server.utils.expertfilter.CombinatorType;
import org.gridsuite.filter.server.utils.expertfilter.FieldType;
Expand All @@ -29,6 +27,12 @@ public class ExpertFilterUtilsTest {

@Before
public void setUp() {
VoltageLevel voltageLevel = Mockito.mock(VoltageLevel.class);
Mockito.when(voltageLevel.getId()).thenReturn("GEN_01");

Terminal terminal = Mockito.mock(Terminal.class);
Mockito.when(terminal.getVoltageLevel()).thenReturn(voltageLevel);

gen = Mockito.mock(Generator.class);
Mockito.when(gen.getType()).thenReturn(IdentifiableType.GENERATOR);
Mockito.when(gen.getMinP()).thenReturn(-500.0);
Expand All @@ -38,6 +42,7 @@ public void setUp() {
Mockito.when(gen.getNameOrId()).thenReturn("NAME");
Mockito.when(gen.getEnergySource()).thenReturn(EnergySource.HYDRO);
Mockito.when(gen.isVoltageRegulatorOn()).thenReturn(true);
Mockito.when(gen.getTerminal()).thenReturn(terminal);
}

@Test
Expand Down Expand Up @@ -74,6 +79,9 @@ public void testEvaluateExpertFilterWithANDCombination() {
BooleanExpertRule booleanRule7 = BooleanExpertRule.builder().value(false)
.field(FieldType.VOLTAGE_REGULATOR_ON).operator(OperatorType.NOT_EQUALS).build();
andRules2.add(booleanRule7);
StringExpertRule stringRule8 = StringExpertRule.builder().value("GEN_01")
.field(FieldType.VOLTAGE_LEVEL_ID).operator(OperatorType.IS).build();
andRules2.add(stringRule8);

CombinatorExpertRule andFilter = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(andRules2).build();

Expand Down

0 comments on commit 807207c

Please sign in to comment.