Skip to content

Commit

Permalink
Add Battery case for getIdentifiable for Propagated Contingency (#1018)
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne LESOT <etienne.lesot@rte-france.com>
  • Loading branch information
EtienneLt authored and caioluke committed Apr 29, 2024
1 parent 6fad576 commit d97c730
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,61 +291,62 @@ private static List<? extends Terminal> getTerminals(Identifiable<?> identifiabl

private static Identifiable<?> getIdentifiable(Network network, ContingencyElement element) {
Identifiable<?> identifiable;
String identifiableType;
switch (element.getType()) {
case BRANCH,
LINE,
TWO_WINDINGS_TRANSFORMER:
String identifiableType = switch (element.getType()) {
case BRANCH, LINE, TWO_WINDINGS_TRANSFORMER -> {
identifiable = network.getBranch(element.getId());
identifiableType = "Branch";
break;
case HVDC_LINE:
yield "Branch";
}
case HVDC_LINE -> {
identifiable = network.getHvdcLine(element.getId());
identifiableType = "HVDC line";
break;
case DANGLING_LINE:
yield "HVDC line";
}
case DANGLING_LINE -> {
identifiable = network.getDanglingLine(element.getId());
identifiableType = "Dangling line";
break;
case GENERATOR:
yield "Dangling line";
}
case GENERATOR -> {
identifiable = network.getGenerator(element.getId());
identifiableType = "Generator";
break;
case STATIC_VAR_COMPENSATOR:
yield "Generator";
}
case STATIC_VAR_COMPENSATOR -> {
identifiable = network.getStaticVarCompensator(element.getId());
identifiableType = "Static var compensator";
break;
case LOAD:
yield "Static var compensator";
}
case LOAD -> {
identifiable = network.getLoad(element.getId());
identifiableType = "Load";
break;
case SHUNT_COMPENSATOR:
yield "Load";
}
case SHUNT_COMPENSATOR -> {
identifiable = network.getShuntCompensator(element.getId());
identifiableType = "Shunt compensator";
break;
case SWITCH:
yield "Shunt compensator";
}
case SWITCH -> {
identifiable = network.getSwitch(element.getId());
identifiableType = "Switch";
break;
case THREE_WINDINGS_TRANSFORMER:
yield "Switch";
}
case THREE_WINDINGS_TRANSFORMER -> {
identifiable = network.getThreeWindingsTransformer(element.getId());
identifiableType = "Three windings transformer";
break;
case BUSBAR_SECTION:
yield "Three windings transformer";
}
case BUSBAR_SECTION -> {
identifiable = network.getBusbarSection(element.getId());
identifiableType = "Busbar section";
break;
case TIE_LINE:
yield "Busbar section";
}
case TIE_LINE -> {
identifiable = network.getTieLine(element.getId());
identifiableType = "Tie line";
break;
case BUS:
yield "Tie line";
}
case BUS -> {
identifiable = network.getBusBreakerView().getBus(element.getId());
identifiableType = "Configured bus";
break;
default:
yield "Configured bus";
}
case BATTERY -> {
identifiable = network.getBattery(element.getId());
yield "Battery";
}
default ->
throw new UnsupportedOperationException("Unsupported contingency element type: " + element.getType());
}
};
if (identifiable == null) {
throw new PowsyblException(identifiableType + " '" + element.getId() + "' not found in the network");
}
Expand Down
29 changes: 20 additions & 9 deletions src/test/java/com/powsybl/openloadflow/sa/LfContingencyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
import com.powsybl.commons.report.ReportNode;
import com.powsybl.commons.test.AbstractSerDeTest;
import com.powsybl.commons.test.ComparisonUtils;
import com.powsybl.contingency.BranchContingency;
import com.powsybl.contingency.Contingency;
import com.powsybl.contingency.GeneratorContingency;
import com.powsybl.contingency.LoadContingency;
import com.powsybl.contingency.*;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.test.BatteryNetworkFactory;
import com.powsybl.iidm.network.test.FourSubstationsNodeBreakerFactory;
import com.powsybl.math.matrix.DenseMatrixFactory;
import com.powsybl.openloadflow.graph.EvenShiloachGraphDecrementalConnectivityFactory;
Expand All @@ -36,8 +34,10 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

import static com.powsybl.openloadflow.network.impl.PropagatedContingency.createList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

Expand Down Expand Up @@ -78,7 +78,7 @@ void test() throws IOException {
.setContingencyPropagation(false)
.setHvdcAcEmulation(false);
List<PropagatedContingency> propagatedContingencies =
PropagatedContingency.createList(network, Collections.singletonList(contingency), new LfTopoConfig(), creationParameters);
createList(network, Collections.singletonList(contingency), new LfTopoConfig(), creationParameters);

List<LfContingency> lfContingencies = propagatedContingencies.stream()
.flatMap(propagatedContingency -> propagatedContingency.toLfContingency(mainNetwork).stream())
Expand All @@ -91,10 +91,21 @@ void test() throws IOException {
}

try (InputStream is = Files.newInputStream(file)) {
ComparisonUtils.compareTxt(getClass().getResourceAsStream("/lfc.json"), is);
ComparisonUtils.compareTxt(Objects.requireNonNull(getClass().getResourceAsStream("/lfc.json")), is);
}
}

@Test
void testBatteryContingencyPropagated() {
Network network = BatteryNetworkFactory.create();
ContingencyElement element = new BatteryContingency("BAT");
Contingency contingency = new Contingency("contingencyId", "contingencyName", List.of(element));
PropagatedContingencyCreationParameters creationParameters = new PropagatedContingencyCreationParameters();
List<PropagatedContingency> propagatedContingencies = createList(network, List.of(contingency), new LfTopoConfig(), creationParameters);
assertEquals(1, propagatedContingencies.size());
assertEquals("contingencyId", propagatedContingencies.get(0).getContingency().getId());
}

@Test
void testGeneratorNotFound() {
Network network = FourSubstationsNodeBreakerFactory.create();
Expand All @@ -109,7 +120,7 @@ void testGeneratorNotFound() {
PropagatedContingencyCreationParameters creationParameters = new PropagatedContingencyCreationParameters()
.setHvdcAcEmulation(false);
assertThrows(PowsyblException.class, () ->
PropagatedContingency.createList(network, Collections.singletonList(contingency), new LfTopoConfig(), creationParameters),
createList(network, Collections.singletonList(contingency), new LfTopoConfig(), creationParameters),
"Generator 'GEN' not found in the network");
}

Expand All @@ -127,7 +138,7 @@ void testLoadNotFound() {
PropagatedContingencyCreationParameters creationParameters = new PropagatedContingencyCreationParameters()
.setHvdcAcEmulation(false);
assertThrows(PowsyblException.class, () ->
PropagatedContingency.createList(network, Collections.singletonList(contingency), new LfTopoConfig(), creationParameters),
createList(network, Collections.singletonList(contingency), new LfTopoConfig(), creationParameters),
"Load 'LOAD' not found in the network");
}

Expand All @@ -136,7 +147,7 @@ void testOpenBranchOutOfMainComponentIssue() {
Network network = VoltageControlNetworkFactory.createNetworkWithT3wt();
LfNetwork lfNetwork = Networks.load(network, new LfNetworkParameters().setBreakers(true)).get(0);
Contingency contingency = Contingency.threeWindingsTransformer("T3wT");
PropagatedContingency propagatedContingency = PropagatedContingency.createList(network, List.of(contingency), new LfTopoConfig(), new PropagatedContingencyCreationParameters()).get(0);
PropagatedContingency propagatedContingency = createList(network, List.of(contingency), new LfTopoConfig(), new PropagatedContingencyCreationParameters()).get(0);
LfContingency lfContingency = propagatedContingency.toLfContingency(lfNetwork).orElseThrow();
assertEquals(Map.of(lfNetwork.getBranchById("T3wT_leg_1"), DisabledBranchStatus.BOTH_SIDES,
lfNetwork.getBranchById("T3wT_leg_2"), DisabledBranchStatus.BOTH_SIDES,
Expand Down

0 comments on commit d97c730

Please sign in to comment.