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

Switch contingency support #501

Merged
merged 9 commits into from
Apr 19, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ private static PropagatedContingency create(Network network, Contingency conting
}
shuntsToLose.add(shuntCompensator);
break;
case SWITCH:
Switch aSwitch = network.getSwitch(element.getId());
if (aSwitch == null) {
throw new PowsyblException("Switch '" + element.getId() + "' not found in the network");
}
switchesToOpen.add(aSwitch);
break;
default:
throw new UnsupportedOperationException("Unsupported contingency element type: " + element.getType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1336,4 +1336,32 @@ void testDivergenceStatus() {
SecurityAnalysisResult result = runSecurityAnalysis(network);
assertFalse(result.getPreContingencyResult().getLimitViolationsResult().isComputationOk());
}

@Test
void testSwitchContingency() {
Network network = createNodeBreakerNetwork();

List<Contingency> contingencies = List.of(new Contingency("C", new SwitchContingency("C")));

List<StateMonitor> monitors = createAllBranchesMonitors(network);

SecurityAnalysisResult result = runSecurityAnalysis(network, contingencies, monitors);

assertTrue(result.getPreContingencyResult().getLimitViolationsResult().isComputationOk());
assertTrue(result.getPostContingencyResults().get(0).getLimitViolationsResult().isComputationOk());

// pre-contingency tests
PreContingencyResult preContingencyResult = result.getPreContingencyResult();
assertEquals(301.884, preContingencyResult.getPreContingencyBranchResult("L1").getP1(), LoadFlowAssert.DELTA_POWER);
assertEquals(-300, preContingencyResult.getPreContingencyBranchResult("L1").getP2(), LoadFlowAssert.DELTA_POWER);
assertEquals(301.884, preContingencyResult.getPreContingencyBranchResult("L2").getP1(), LoadFlowAssert.DELTA_POWER);
assertEquals(-300, preContingencyResult.getPreContingencyBranchResult("L2").getP2(), LoadFlowAssert.DELTA_POWER);

// post-contingency tests
PostContingencyResult postContingencyResult = getPostContingencyResult(result, "C");
assertEquals(3.912, postContingencyResult.getBranchResult("L1").getP1(), LoadFlowAssert.DELTA_POWER);
assertEquals(-3.895, postContingencyResult.getBranchResult("L1").getP2(), LoadFlowAssert.DELTA_POWER);
assertEquals(603.769, postContingencyResult.getBranchResult("L2").getP1(), LoadFlowAssert.DELTA_POWER);
assertEquals(-596.104, postContingencyResult.getBranchResult("L2").getP2(), LoadFlowAssert.DELTA_POWER);
}
}