Skip to content

Commit

Permalink
new tests + refactor tests
Browse files Browse the repository at this point in the history
Signed-off-by: vmouradian <[email protected]>
  • Loading branch information
vmouradian committed Dec 18, 2024
1 parent c8bfff1 commit b59bda3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.powsybl.openloadflow.network.impl.Networks;
import com.powsybl.openloadflow.network.impl.OlfBranchResult;
import com.powsybl.openloadflow.network.impl.OlfThreeWindingsTransformerResult;
import com.powsybl.openloadflow.sa.extensions.ContingencyLoadFlowParameters;
import com.powsybl.openloadflow.util.LoadFlowAssert;
import com.powsybl.security.*;
import com.powsybl.security.condition.TrueCondition;
Expand Down Expand Up @@ -4034,4 +4035,56 @@ void testNoCc0Sc0() {
assertEquals(LoadFlowResult.ComponentResult.Status.CONVERGED, saResultAll.getPreContingencyResult().getStatus());
assertEquals(6, saResultAll.getPreContingencyResult().getNetworkResult().getBusResults().size()); // 6 buses in total
}

@ParameterizedTest(name = "DC = {0}")
@ValueSource(booleans = {false, true})
void testContingencyParameters(boolean isDc) {
Network network = MultiAreaNetworkFactory.createTwoAreasWithTieLine();

// Create 3 times the same contingency
Contingency cont1 = new Contingency("load3_aic_load", new LoadContingency("load3"));
Contingency cont2 = new Contingency("load3_no_ext", new LoadContingency("load3"));
Contingency cont3 = new Contingency("load3_slack_gen_p", new LoadContingency("load3"));
List<Contingency> contingencies = List.of(cont1, cont2, cont3);

// Default LF parameters
LoadFlowParameters parameters = new LoadFlowParameters()
.setDc(isDc)
.setDistributedSlack(true)
.setBalanceType(LoadFlowParameters.BalanceType.PROPORTIONAL_TO_GENERATION_P_MAX);

// Add contingency LF parameters to contingencies 1 and 3
ContingencyLoadFlowParameters contLfParams1 = new ContingencyLoadFlowParameters(false, true, LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD);
cont1.addExtension(ContingencyLoadFlowParameters.class, contLfParams1);
ContingencyLoadFlowParameters contLfParams3 = new ContingencyLoadFlowParameters(true, false, LoadFlowParameters.BalanceType.PROPORTIONAL_TO_GENERATION_P);
cont3.addExtension(ContingencyLoadFlowParameters.class, contLfParams3);

// Run security analysis
List<StateMonitor> monitors = createAllBranchesMonitors(network);
SecurityAnalysisParameters securityAnalysisParameters = new SecurityAnalysisParameters();
securityAnalysisParameters.setLoadFlowParameters(parameters);
SecurityAnalysisResult resultAc = runSecurityAnalysis(network, contingencies, monitors, securityAnalysisParameters);

// Pre-contingency results -> distributed slack on gens, proportional to Pmax
PreContingencyResult preContingencyResult = resultAc.getPreContingencyResult();
assertEquals(25, preContingencyResult.getNetworkResult().getBranchResult("tl1").getP1(), LoadFlowAssert.DELTA_POWER);
assertEquals(30, preContingencyResult.getNetworkResult().getBranchResult("l34").getP1(), LoadFlowAssert.DELTA_POWER);

// Post-contingency results
// Contingency 1: AIC, proportional to load
PostContingencyResult postContingencyResult1 = getPostContingencyResult(resultAc, "load3_aic_load");
assertEquals(50, postContingencyResult1.getNetworkResult().getBranchResult("tl1").getP1(), LoadFlowAssert.DELTA_POWER);
assertEquals(75, postContingencyResult1.getNetworkResult().getBranchResult("l34").getP1(), LoadFlowAssert.DELTA_POWER);

// Contingency 2: no extension, distributed slack proportional to gen Pmax
PostContingencyResult postContingencyResult2 = getPostContingencyResult(resultAc, "load3_no_ext");
assertEquals(15, postContingencyResult2.getNetworkResult().getBranchResult("tl1").getP1(), LoadFlowAssert.DELTA_POWER);
assertEquals(30, postContingencyResult2.getNetworkResult().getBranchResult("l34").getP1(), LoadFlowAssert.DELTA_POWER);

// Contingency 3: distributed slack, proportional to gen P
PostContingencyResult postContingencyResult3 = getPostContingencyResult(resultAc, "load3_slack_gen_p");
assertEquals(9.545, postContingencyResult3.getNetworkResult().getBranchResult("tl1").getP1(), LoadFlowAssert.DELTA_POWER);
assertEquals(30, postContingencyResult3.getNetworkResult().getBranchResult("l34").getP1(), LoadFlowAssert.DELTA_POWER);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1673,9 +1673,12 @@ void testOperatorStrategyNoMoreBusVoltageControlled() throws IOException {
assertReportEquals("/saReportOperatorStrategyNoVoltageControl.txt", reportNode);
}

@Test
void testContingencyParameters() {
@ParameterizedTest(name = "DC = {0}")
@ValueSource(booleans = {false, true})
void testContingencyParameters(boolean isDc) {
Network network = MultiAreaNetworkFactory.createTwoAreasWithTieLine();

// create a contingency with ContingencyLoadFlowParameters extension
Contingency contingency1 = new Contingency("load3", new LoadContingency("load3"));
ContingencyLoadFlowParameters contingencyParameters1 = new ContingencyLoadFlowParameters(false, true, LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD);
contingency1.addExtension(ContingencyLoadFlowParameters.class, contingencyParameters1);
Expand All @@ -1688,22 +1691,25 @@ void testContingencyParameters() {
List<Action> actions = List.of(action1);
List<OperatorStrategy> operatorStrategies = List.of(operatorStrategy1);

LoadFlowParameters parameters = new LoadFlowParameters();
parameters.setDistributedSlack(true);
// run the security analysis
LoadFlowParameters parameters = new LoadFlowParameters().setDc(isDc);
parameters.setConnectedComponentMode(LoadFlowParameters.ConnectedComponentMode.ALL);
SecurityAnalysisParameters securityAnalysisParameters = new SecurityAnalysisParameters();
securityAnalysisParameters.setLoadFlowParameters(parameters);
SecurityAnalysisResult resultAc = runSecurityAnalysis(network, contingencies, monitors, securityAnalysisParameters,
operatorStrategies, actions, ReportNode.NO_OP);

// Pre-contingency results
PreContingencyResult preContingencyResult = resultAc.getPreContingencyResult();
assertEquals(25, preContingencyResult.getNetworkResult().getBranchResult("tl1").getP1(), LoadFlowAssert.DELTA_POWER);
assertEquals(30, preContingencyResult.getNetworkResult().getBranchResult("l34").getP1(), LoadFlowAssert.DELTA_POWER);

// Post-contingency results : AIC on loads
PostContingencyResult postContingencyResult = getPostContingencyResult(resultAc, "load3");
assertEquals(50, postContingencyResult.getNetworkResult().getBranchResult("tl1").getP1(), LoadFlowAssert.DELTA_POWER);
assertEquals(75, postContingencyResult.getNetworkResult().getBranchResult("l34").getP1(), LoadFlowAssert.DELTA_POWER);

// Operator strategy results : AIC on loads
OperatorStrategyResult acStrategyResult = getOperatorStrategyResult(resultAc, "strategy1");
assertEquals(50, acStrategyResult.getNetworkResult().getBranchResult("tl1").getP1(), LoadFlowAssert.DELTA_POWER);
assertEquals(95, acStrategyResult.getNetworkResult().getBranchResult("l34").getP1(), LoadFlowAssert.DELTA_POWER);
Expand Down

0 comments on commit b59bda3

Please sign in to comment.