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

[CSA] No longer read AE.isCombinableWithRemedialAction attribute #1130

Merged
merged 12 commits into from
Oct 24, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public class CsaProfileCnecCreator {
private Set<ElementaryCreationContext> csaProfileCnecCreationContexts;
private final CsaProfileCracCreationContext cracCreationContext;
private final CracCreationParameters cracCreationParameters;
private final String regionEic;
private final Map<String, String> borderPerTso;
private final Map<String, String> borderPerEic;

Expand All @@ -60,7 +59,6 @@ public CsaProfileCnecCreator(Crac crac, Network network, CsaProfileCrac nativeCr
this.nativeVoltageAngleLimitPerId = nativeCrac.getVoltageAngleLimits().stream().collect(Collectors.toMap(VoltageAngleLimit::mrid, voltageAngleLimit -> voltageAngleLimit));
this.cracCreationContext = cracCreationContext;
this.cracCreationParameters = cracCreationParameters;
this.regionEic = cracCreationParameters.getExtension(CsaCracCreationParameters.class).getCapacityCalculationRegionEicCode();
this.borderPerTso = cracCreationParameters.getExtension(CsaCracCreationParameters.class).getBorders().stream().collect(Collectors.toMap(Border::defaultForTso, Border::name));
this.borderPerEic = cracCreationParameters.getExtension(CsaCracCreationParameters.class).getBorders().stream().collect(Collectors.toMap(Border::eic, Border::name));
this.createAndAddCnecs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ public FlowCnecCreator(Crac crac, Network network, AssessedElement nativeAssesse
checkCnecDefinitionMode();
}

private static Set<Country> getBranchLocation(Branch<?> branch) {
bqth29 marked this conversation as resolved.
Show resolved Hide resolved
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 checkCnecDefinitionMode() {
if (nativeAssessedElement.conductingEquipment() == null && nativeCurrentLimit == null) {
throw new OpenRaoImportException(ImportStatus.INCOMPLETE_DATA, writeAssessedElementIgnoredReasonMessage("no ConductingEquipment or OperationalLimit was provided"));
Expand Down Expand Up @@ -220,10 +227,10 @@ private void addAllFlowCnecsFromBranchAndOperationalLimits(Branch<?> networkElem
twoSides -> operatorDoesNotUsePatlInFinalState
&& (networkElement.getCurrentLimits(twoSides).isEmpty() || networkElement.getCurrentLimits(twoSides).isPresent() && networkElement.getCurrentLimits(twoSides).get().getTemporaryLimits().isEmpty())));

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private boolean addOnConstraintUsageRules(String
remedialActionId, Set<AssessedElement> nativeAssessedElements, Set<AssessedElementWithRemedialAction> linkedAssessedElementWithRemedialActions, Set<ContingencyWithRemedialAction> linkedContingencyWithRemedialActions, Set<ElementaryCreationContext> cnecCreationContexts, RemedialActionAdder<?>
remedialActionAdder, List<String> alterations, Instant instant,
boolean isSchemeRemedialAction, RemedialActionType remedialActionType) {
Map<String, AssociationStatus> cnecStatusMap = OnConstraintUsageRuleHelper.processCnecsLinkedToRemedialAction(crac, remedialActionId, nativeAssessedElements, linkedAssessedElementWithRemedialActions, linkedContingencyWithRemedialActions, cnecCreationContexts);
Map<String, AssociationStatus> cnecStatusMap = OnConstraintUsageRuleHelper.processCnecsLinkedToRemedialAction(crac, remedialActionId, linkedAssessedElementWithRemedialActions, linkedContingencyWithRemedialActions, cnecCreationContexts);
cnecStatusMap.forEach((cnecId, cnecStatus) -> {
if (cnecStatus.isValid()) {
Cnec<?> cnec = crac.getCnec(cnecId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
import com.powsybl.openrao.data.cracapi.cnec.Cnec;
import com.powsybl.openrao.data.cracio.commons.api.ElementaryCreationContext;
import com.powsybl.openrao.data.cracio.csaprofiles.craccreator.constants.ElementCombinationConstraintKind;
import com.powsybl.openrao.data.cracio.csaprofiles.nc.AssessedElement;
import com.powsybl.openrao.data.cracio.csaprofiles.nc.AssessedElementWithRemedialAction;
import com.powsybl.openrao.data.cracio.csaprofiles.nc.ContingencyWithRemedialAction;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -34,20 +32,13 @@ public static Set<Cnec> getImportedCnecFromAssessedElementId(String assessedElem
return cnecCreationContexts.stream().filter(context -> context.isImported() && assessedElementId.equals(context.getNativeObjectId())).map(context -> crac.getCnec(context.getCreatedObjectId())).collect(Collectors.toSet());
}

public static Set<Cnec> getCnecsBuiltFromAssessedElementsCombinableWithRemedialActions(Crac crac, Set<ElementaryCreationContext> cnecCreationContexts, Set<AssessedElement> nativeAssessedElements) {
Set<Cnec> cnecsCombinableWithRemedialActions = new HashSet<>();
nativeAssessedElements.stream().filter(AssessedElement::isCombinableWithRemedialAction).forEach(nativeAssessedElement -> cnecsCombinableWithRemedialActions.addAll(getImportedCnecFromAssessedElementId(nativeAssessedElement.mrid(), crac, cnecCreationContexts)));
return cnecsCombinableWithRemedialActions;
}

public static Set<Cnec> filterCnecsThatHaveGivenContingencies(Set<Cnec> cnecs, Set<String> contingenciesIds) {
return cnecs.stream().filter(cnec -> cnec.getState().getContingency().isPresent() && contingenciesIds.contains(cnec.getState().getContingency().get().getId())).collect(Collectors.toSet());
}

public static Map<String, AssociationStatus> processCnecsLinkedToRemedialAction(Crac crac, String remedialActionId, Set<AssessedElement> nativeAssessedElements, Set<AssessedElementWithRemedialAction> linkedAssessedElementWithRemedialActions, Set<ContingencyWithRemedialAction> linkedContingencyWithRemedialActions, Set<ElementaryCreationContext> cnecCreationContexts) {
public static Map<String, AssociationStatus> processCnecsLinkedToRemedialAction(Crac crac, String remedialActionId, Set<AssessedElementWithRemedialAction> linkedAssessedElementWithRemedialActions, Set<ContingencyWithRemedialAction> linkedContingencyWithRemedialActions, Set<ElementaryCreationContext> cnecCreationContexts) {
Map<String, AssociationStatus> contingencyStatusMap = OnContingencyStateUsageRuleHelper.processContingenciesLinkedToRemedialAction(crac, remedialActionId, linkedContingencyWithRemedialActions);
Map<String, AssociationStatus> cnecStatusMap = new HashMap<>();
Set<Cnec> cnecsCombinableWithRemedialAction = getCnecsBuiltFromAssessedElementsCombinableWithRemedialActions(crac, cnecCreationContexts, nativeAssessedElements);
Map<String, ElementCombinationConstraintKind> validContingenciesUsageRules = contingencyStatusMap.entrySet().stream().filter(entry -> entry.getValue().isValid()).collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().elementCombinationConstraintKind()));

for (AssessedElementWithRemedialAction nativeAssessedElementWithRemedialAction : linkedAssessedElementWithRemedialActions) {
Expand All @@ -59,8 +50,6 @@ public static Map<String, AssociationStatus> processCnecsLinkedToRemedialAction(
continue;
}

cnecsCombinableWithRemedialAction.removeAll(cnecs);

if (cnecs.isEmpty()) {
cnecStatusMap.put(nativeAssessedElementWithRemedialAction.assessedElement(), new AssociationStatus(false, null, "OnConstraint usage rule for remedial action %s with assessed element %s ignored because no CNEC was imported by Open RAO from this assessed element.".formatted(remedialActionId, nativeAssessedElementWithRemedialAction.assessedElement())));
continue;
Expand Down Expand Up @@ -92,15 +81,6 @@ public static Map<String, AssociationStatus> processCnecsLinkedToRemedialAction(
);
}

// Add CNECs built from AssessedElements which are combinable with remedial actions
if (contingencyStatusMap.isEmpty()) {
// The remedial action is not associated to contingencies
cnecsCombinableWithRemedialAction.forEach(cnec -> cnecStatusMap.put(cnec.getId(), new AssociationStatus(true, ElementCombinationConstraintKind.CONSIDERED, "")));
} else {
// The remedial action is associated to contingencies (valid or not)
filterCnecsThatHaveGivenContingencies(cnecsCombinableWithRemedialAction, validContingenciesUsageRules.keySet()).forEach(cnec -> cnecStatusMap.put(cnec.getId(), new AssociationStatus(true, validContingenciesUsageRules.get(cnec.getState().getContingency().orElseThrow().getId()), "")));
}

return cnecStatusMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
/**
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
*/
public record AssessedElement(String mrid, boolean inBaseCase, String name, String operator, String conductingEquipment, String operationalLimit, boolean isCombinableWithContingency, boolean isCombinableWithRemedialAction, boolean normalEnabled, String securedForRegion, String scannedForRegion, double flowReliabilityMargin, String overlappingZone) implements IdentifiedObjectWithOperator {
public record AssessedElement(String mrid, boolean inBaseCase, String name, String operator, String conductingEquipment,
String operationalLimit, boolean isCombinableWithContingency,
boolean normalEnabled, String securedForRegion, String scannedForRegion,
double flowReliabilityMargin,
String overlappingZone) implements IdentifiedObjectWithOperator {
public static AssessedElement fromPropertyBag(PropertyBag propertyBag) {
return new AssessedElement(
propertyBag.getId(CsaProfileConstants.REQUEST_ASSESSED_ELEMENT),
Expand All @@ -22,7 +26,6 @@ public static AssessedElement fromPropertyBag(PropertyBag propertyBag) {
propertyBag.getId(CsaProfileConstants.REQUEST_ASSESSED_ELEMENT_CONDUCTING_EQUIPMENT),
propertyBag.getId(CsaProfileConstants.REQUEST_ASSESSED_ELEMENT_OPERATIONAL_LIMIT),
Boolean.parseBoolean(propertyBag.getOrDefault(CsaProfileConstants.REQUEST_ASSESSED_ELEMENT_IS_COMBINABLE_WITH_CONTINGENCY, "false")),
Boolean.parseBoolean(propertyBag.getOrDefault(CsaProfileConstants.REQUEST_ASSESSED_ELEMENT_IS_COMBINABLE_WITH_REMEDIAL_ACTION, "false")),
Boolean.parseBoolean(propertyBag.getOrDefault(CsaProfileConstants.REQUEST_ASSESSED_ELEMENT_NORMAL_ENABLED, "true")),
propertyBag.get(CsaProfileConstants.REQUEST_ASSESSED_ELEMENT_SECURED_FOR_REGION),
propertyBag.get(CsaProfileConstants.REQUEST_ASSESSED_ELEMENT_SCANNED_FOR_REGION),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ GRAPH <%s> {
OPTIONAL {
?assessedElement nc:AssessedElement.ScannedForRegion ?scannedForRegion .
}
OPTIONAL {
?assessedElement nc:AssessedElement.isCombinableWithRemedialAction ?isCombinableWithRemedialAction ;
}
OPTIONAL {
?assessedElement nc:AssessedElement.flowReliabilityMargin ?flowReliabilityMargin .
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,5 @@ void importAngleCnecs() {
assertCnecNotImported(cracCreationContext, "assessed-element-13", ImportStatus.INCONSISTENCY_IN_DATA, "AssessedElement assessed-element-13 ignored because the network element FFR2AA1 _generator is not a bus bar section");

assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3", cracCreationContext.getCrac().getInstant(CURATIVE_3_INSTANT_ID), UsageMethod.FORCED, AngleCnec.class);
assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE2 (assessed-element-2) - RTE_CO1 - curative 3", cracCreationContext.getCrac().getInstant(CURATIVE_3_INSTANT_ID), UsageMethod.AVAILABLE, AngleCnec.class);
assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3", cracCreationContext.getCrac().getInstant(CURATIVE_3_INSTANT_ID), UsageMethod.AVAILABLE, AngleCnec.class);
}
}
Loading
Loading