4545
4646import java .util .*;
4747import java .util .function .Function ;
48+ import java .util .function .Predicate ;
4849import java .util .function .Supplier ;
4950import java .util .stream .Collectors ;
5051
@@ -206,7 +207,8 @@ private void filterActions(List<Action> actions) {
206207 private PostContingencyResult computePostContingencyResultFromPostContingencyStates (DcLoadFlowContext loadFlowContext , Contingency contingency , LfContingency lfContingency ,
207208 LimitViolationManager preContingencyLimitViolationManager , PreContingencyNetworkResult preContingencyNetworkResult ,
208209 boolean createResultExtension , SecurityAnalysisParameters .IncreasedViolationsParameters violationsParameters ,
209- double [] postContingencyStates , List <LimitReduction > limitReductions ) {
210+ double [] postContingencyStates , Predicate <LfBranch > isBranchDisabledDueToContingency ,
211+ List <LimitReduction > limitReductions ) {
210212
211213 // update network state with post contingency states
212214 LfNetwork lfNetwork = loadFlowContext .getNetwork ();
@@ -217,11 +219,11 @@ private PostContingencyResult computePostContingencyResultFromPostContingencySta
217219
218220 // update post contingency network result
219221 var postContingencyNetworkResult = new PostContingencyNetworkResult (lfNetwork , monitorIndex , createResultExtension , preContingencyNetworkResult , contingency );
220- postContingencyNetworkResult .update ();
222+ postContingencyNetworkResult .update (isBranchDisabledDueToContingency );
221223
222224 // detect violations
223225 var postContingencyLimitViolationManager = new LimitViolationManager (preContingencyLimitViolationManager , limitReductions , violationsParameters );
224- postContingencyLimitViolationManager .detectViolations (lfNetwork );
226+ postContingencyLimitViolationManager .detectViolations (lfNetwork , isBranchDisabledDueToContingency );
225227
226228 // connectivity result due to the application of the lf contingency
227229 var connectivityResult = new ConnectivityResult (
@@ -244,15 +246,16 @@ private PostContingencyResult computePostContingencyResultFromPostContingencySta
244246 */
245247 private PostContingencyResult processPostContingencyResult (DcLoadFlowContext context , PropagatedContingency contingency , LfContingency lfContingency , Supplier <double []> postContingencyStatesSupplier ,
246248 LimitViolationManager preContingencyLimitViolationManager , PreContingencyNetworkResult preContingencyNetworkResult ,
247- boolean createResultExtension , SecurityAnalysisParameters .IncreasedViolationsParameters violationsParameters ,
249+ Predicate <LfBranch > isBranchDisabledDueToContingency , boolean createResultExtension ,
250+ SecurityAnalysisParameters .IncreasedViolationsParameters violationsParameters ,
248251 List <LimitReduction > limitReductions ) {
249252 logPostContingencyStart (context .getNetwork (), lfContingency );
250253 Stopwatch stopwatch = Stopwatch .createStarted ();
251254
252255 double [] postContingencyStates = postContingencyStatesSupplier .get ();
253256 PostContingencyResult postContingencyResult = computePostContingencyResultFromPostContingencyStates (context , contingency .getContingency (),
254257 lfContingency , preContingencyLimitViolationManager , preContingencyNetworkResult , createResultExtension ,
255- violationsParameters , postContingencyStates , limitReductions );
258+ violationsParameters , postContingencyStates , isBranchDisabledDueToContingency , limitReductions );
256259
257260 stopwatch .stop ();
258261 logPostContingencyEnd (context .getNetwork (), lfContingency , stopwatch );
@@ -266,7 +269,7 @@ private PostContingencyResult processPostContingencyResult(DcLoadFlowContext con
266269 private OperatorStrategyResult computeOperatorStrategyResultFromPostContingencyAndOperatorStrategyStates (DcLoadFlowContext loadFlowContext , LfContingency lfContingency , OperatorStrategy operatorStrategy ,
267270 List <LfAction > operatorStrategyLfActions , LimitViolationManager preContingencyLimitViolationManager ,
268271 boolean createResultExtension , SecurityAnalysisParameters .IncreasedViolationsParameters violationsParameters ,
269- double [] postContingencyAndOperatorStrategyStates , List <LimitReduction > limitReductions ) {
272+ double [] postContingencyAndOperatorStrategyStates , Predicate < LfBranch > isBranchDisabledDueToContingency , List <LimitReduction > limitReductions ) {
270273 // update network state with post contingency and post operator strategy states
271274 LfNetwork lfNetwork = loadFlowContext .getNetwork ();
272275 loadFlowContext .getEquationSystem ().getStateVector ().set (postContingencyAndOperatorStrategyStates );
@@ -278,11 +281,11 @@ private OperatorStrategyResult computeOperatorStrategyResultFromPostContingencyA
278281
279282 // update network result
280283 var postActionsNetworkResult = new PreContingencyNetworkResult (lfNetwork , monitorIndex , createResultExtension );
281- postActionsNetworkResult .update ();
284+ postActionsNetworkResult .update (isBranchDisabledDueToContingency );
282285
283286 // detect violations
284287 var postActionsViolationManager = new LimitViolationManager (preContingencyLimitViolationManager , limitReductions , violationsParameters );
285- postActionsViolationManager .detectViolations (lfNetwork );
288+ postActionsViolationManager .detectViolations (lfNetwork , isBranchDisabledDueToContingency );
286289
287290 return new OperatorStrategyResult (operatorStrategy , PostContingencyComputationStatus .CONVERGED ,
288291 new LimitViolationsResult (postActionsViolationManager .getLimitViolations ()),
@@ -297,8 +300,8 @@ private OperatorStrategyResult computeOperatorStrategyResultFromPostContingencyA
297300 private OperatorStrategyResult processOperatorStrategyResult (DcLoadFlowContext context , LfContingency contingency , OperatorStrategy operatorStrategy ,
298301 Function <List <LfAction >, double []> postContingencyAndOperatorStrategyStatesSupplier ,
299302 LimitViolationManager preContingencyLimitViolationManager , PostContingencyResult postContingencyResult ,
300- Map <String , LfAction > lfActionById , boolean createResultExtension , SecurityAnalysisParameters . IncreasedViolationsParameters violationsParameters ,
301- List <LimitReduction > limitReductions ) {
303+ Map <String , LfAction > lfActionById , Predicate < LfBranch > isBranchDisabledDueToContingency , boolean createResultExtension ,
304+ SecurityAnalysisParameters . IncreasedViolationsParameters violationsParameters , List <LimitReduction > limitReductions ) {
302305 // get the actions associated to the operator strategy
303306 List <String > actionIds = checkCondition (operatorStrategy , postContingencyResult .getLimitViolationsResult ());
304307 List <LfAction > operatorStrategyLfActions = actionIds .stream ()
@@ -311,7 +314,7 @@ private OperatorStrategyResult processOperatorStrategyResult(DcLoadFlowContext c
311314
312315 double [] postContingencyAndOperatorStrategyStates = postContingencyAndOperatorStrategyStatesSupplier .apply (operatorStrategyLfActions );
313316 OperatorStrategyResult operatorStrategyResult = computeOperatorStrategyResultFromPostContingencyAndOperatorStrategyStates (context , contingency , operatorStrategy , operatorStrategyLfActions ,
314- preContingencyLimitViolationManager , createResultExtension , violationsParameters , postContingencyAndOperatorStrategyStates , limitReductions );
317+ preContingencyLimitViolationManager , createResultExtension , violationsParameters , postContingencyAndOperatorStrategyStates , isBranchDisabledDueToContingency , limitReductions );
315318
316319 stopwatch .stop ();
317320 logActionEnd (context .getNetwork (), operatorStrategy , stopwatch );
@@ -333,9 +336,13 @@ private void addPostContingencyAndOperatorStrategyResults(DcLoadFlowContext cont
333336 ReportNode postContSimReportNode = Reports .createPostContingencySimulation (lfNetwork .getReportNode (), contingency .getContingency ().getId ());
334337 lfNetwork .setReportNode (postContSimReportNode );
335338
339+ // predicate to determine if a branch is disabled or not due to the contingency
340+ // note that branches with one side opened due to the contingency are considered are disabled
341+ Predicate <LfBranch > isBranchDisabled = branch -> lfContingency .getDisabledNetwork ().getBranchesStatus ().containsKey (branch );
342+
336343 // process post contingency result with supplier giving post contingency states
337344 PostContingencyResult postContingencyResult = processPostContingencyResult (context , contingency , lfContingency , toPostContingencyStates , preContingencyLimitViolationManager ,
338- preContingencyNetworkResult , createResultExtension , violationsParameters , limitReductions );
345+ preContingencyNetworkResult , isBranchDisabled , createResultExtension , violationsParameters , limitReductions );
339346 postContingencyResults .add (postContingencyResult );
340347
341348 // restore pre contingency states for next calculation
@@ -349,7 +356,7 @@ private void addPostContingencyAndOperatorStrategyResults(DcLoadFlowContext cont
349356
350357 // process operator strategy result with supplier giving post contingency and post operator strategy states
351358 OperatorStrategyResult operatorStrategyResult = processOperatorStrategyResult (context , lfContingency , operatorStrategy , toPostContingencyAndOperatorStrategyStates , preContingencyLimitViolationManager ,
352- postContingencyResult , lfActionById , createResultExtension , violationsParameters , limitReductions );
359+ postContingencyResult , lfActionById , isBranchDisabled , createResultExtension , violationsParameters , limitReductions );
353360 operatorStrategyResults .add (operatorStrategyResult );
354361
355362 // restore pre contingency states for next calculation
0 commit comments