Skip to content

Commit

Permalink
Geographical filter
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Bouquet <[email protected]>
  • Loading branch information
bqth29 committed Jul 31, 2024
1 parent f2e67a6 commit 1876b3f
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.cnec;

import com.powsybl.contingency.ContingencyElement;
import com.powsybl.openrao.commons.Unit;
import com.powsybl.contingency.Contingency;
import com.powsybl.openrao.data.cracapi.Crac;
Expand Down Expand Up @@ -198,6 +199,13 @@ private void addFlowCnec(Branch<?> networkElement, Contingency contingency, Stri
cnecAdder.add();
}

private static Set<Country> getBranchLocation(Branch<?> branch) {
Set<Country> branchCountries = new HashSet<>();
branch.getTerminal(TwoSides.ONE).getVoltageLevel().getSubstation().flatMap(Substation::getCountry).ifPresent(branchCountries::add);
branch.getTerminal(TwoSides.TWO).getVoltageLevel().getSubstation().flatMap(Substation::getCountry).ifPresent(branchCountries::add);
return branchCountries;
}

private void addAllFlowCnecsFromBranchAndOperationalLimits(Branch<?> networkElement, Map<Integer, Map<TwoSides, Double>> thresholds, boolean useMaxAndMinThresholds) {
// Preventive CNEC
if (nativeAssessedElement.inBaseCase()) {
Expand All @@ -220,9 +228,22 @@ private void addAllFlowCnecsFromBranchAndOperationalLimits(Branch<?> networkElem
twoSides -> operatorDoesNotUsePatlInFinalState
&& (networkElement.getCurrentLimits(twoSides).isEmpty() || networkElement.getCurrentLimits(twoSides).isPresent() && networkElement.getCurrentLimits(twoSides).get().getTemporaryLimits().isEmpty())));

Set<Country> branchCountries = getBranchLocation(networkElement);

for (Contingency contingency : linkedContingencies) {
thresholds.forEach((acceptableDuration, limitThresholds) ->
limitThresholds.forEach((twoSides, threshold) -> addCurativeFlowCnec(networkElement, useMaxAndMinThresholds, instantToDurationMaps, forceUseOfPatl, contingency, acceptableDuration, twoSides, threshold)));

Set<Country> contingencyCountries = new HashSet<>();
contingency.getElements().stream()
.map(ContingencyElement::getId)
.map(network::getIdentifiable)
.filter(Branch.class::isInstance)
.map(Branch.class::cast)
.forEach(branch -> contingencyCountries.addAll(getBranchLocation(branch)));

if (!Collections.disjoint(branchCountries, contingencyCountries)) {
thresholds.forEach((acceptableDuration, limitThresholds) ->
limitThresholds.forEach((twoSides, threshold) -> addCurativeFlowCnec(networkElement, useMaxAndMinThresholds, instantToDurationMaps, forceUseOfPatl, contingency, acceptableDuration, twoSides, threshold)));
}
}
}
}
Expand Down

0 comments on commit 1876b3f

Please sign in to comment.