Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/powsybl/open-rao into remov…
Browse files Browse the repository at this point in the history
…e_cnecs_series_pst_feature

Signed-off-by: Philippe Edwards <philippe.edwards@rte-france.com>
  • Loading branch information
phiedw committed Jun 4, 2024
2 parents d57d83c + 7c99376 commit 0046945
Show file tree
Hide file tree
Showing 92 changed files with 4,703 additions and 2,417 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -471,16 +471,16 @@ private static void addOnFlowConstraintUsageRule(RemedialActionAdder<?> adder, F
if (flowCnec.getState().getInstant().comesBefore(instant)) {
return;
}
adder.newOnFlowConstraintUsageRule()
.withFlowCnec(flowCnec.getId())
adder.newOnConstraintUsageRule()
.withCnec(flowCnec.getId())
.withUsageMethod(instant.isAuto() ? UsageMethod.FORCED : UsageMethod.AVAILABLE)
.withInstant(instant.getId())
.add();
}

private static void addOnAngleConstraintUsageRule(RemedialActionAdder<?> adder, AngleCnec angleCnec, Instant instant) {
adder.newOnAngleConstraintUsageRule()
.withAngleCnec(angleCnec.getId())
adder.newOnConstraintUsageRule()
.withCnec(angleCnec.getId())
.withUsageMethod(instant.isAuto() ? UsageMethod.FORCED : UsageMethod.AVAILABLE)
.withInstant(instant.getId())
.add();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.powsybl.contingency.ContingencyElement;
import com.powsybl.openrao.commons.Unit;
import com.powsybl.openrao.data.cracapi.*;
import com.powsybl.openrao.data.cracapi.cnec.AngleCnec;
import com.powsybl.openrao.data.cracapi.cnec.FlowCnec;
import com.powsybl.openrao.data.cracapi.cnec.Side;
import com.powsybl.openrao.data.cracapi.networkaction.*;
Expand Down Expand Up @@ -280,24 +281,27 @@ private void assertNetworkActionImported(String id, Set<String> networkElements,
private void assertHasOnFlowConstraintUsageRule(RemedialAction<?> ra, Instant instant, String flowCnecId) {
assertTrue(
ra.getUsageRules().stream()
.filter(OnFlowConstraint.class::isInstance)
.map(OnFlowConstraint.class::cast)
.filter(OnConstraint.class::isInstance)
.map(OnConstraint.class::cast)
.anyMatch(
ur -> ur.getInstant().equals(instant)
&& ur.getFlowCnec().getId().equals(flowCnecId)
&& ur.getCnec() instanceof FlowCnec
&& ur.getCnec().getId().equals(flowCnecId)
&& ur.getUsageMethod().equals(instant.isAuto() ? UsageMethod.FORCED : UsageMethod.AVAILABLE)
));
}

private void assertHasOnAngleUsageRule(String raId, String angleCnecId) {
RemedialAction ra = importedCrac.getRemedialAction(raId);
RemedialAction<?> ra = importedCrac.getRemedialAction(raId);
assertTrue(
ra.getUsageRules().stream()
.filter(OnAngleConstraint.class::isInstance)
.filter(OnConstraint.class::isInstance)
.map(OnConstraint.class::cast)
.anyMatch(
ur -> ((OnAngleConstraint) ur).getInstant().isCurative()
&& ((OnAngleConstraint) ur).getAngleCnec().getId().equals(angleCnecId)
&& ((OnAngleConstraint) ur).getUsageMethod().equals(UsageMethod.AVAILABLE)
ur -> ur.getInstant().isCurative()
&& ur.getCnec() instanceof AngleCnec
&& ur.getCnec().getId().equals(angleCnecId)
&& ur.getUsageMethod().equals(UsageMethod.AVAILABLE)
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import com.powsybl.openrao.data.cracapi.*;
import com.powsybl.openrao.data.cracapi.cnec.Cnec;
import com.powsybl.openrao.data.cracapi.cnec.FlowCnec;
import com.powsybl.openrao.data.cracapi.cnec.VoltageCnec;
import com.powsybl.openrao.data.cracapi.networkaction.*;
import com.powsybl.openrao.data.cracapi.usagerule.*;
import com.powsybl.openrao.data.craccreation.creator.api.ImportStatus;
Expand Down Expand Up @@ -117,25 +115,11 @@ private boolean addOnConstraintUsageRules(String remedialActionId, Set<AssessedE
Cnec<?> cnec = crac.getCnec(cnecId);
UsageMethod usageMethod = getUsageMethod(cnecStatus.elementCombinationConstraintKind(), isSchemeRemedialAction, instant, remedialActionType);
if (isOnConstraintInstantCoherent(cnec.getState().getInstant(), instant)) {
if (cnec instanceof FlowCnec) {
remedialActionAdder.newOnFlowConstraintUsageRule()
.withInstant(instant.getId())
.withFlowCnec(cnecId)
.withUsageMethod(usageMethod)
.add();
} else if (cnec instanceof VoltageCnec) {
remedialActionAdder.newOnVoltageConstraintUsageRule()
.withInstant(instant.getId())
.withVoltageCnec(cnecId)
.withUsageMethod(usageMethod)
.add();
} else {
remedialActionAdder.newOnAngleConstraintUsageRule()
.withInstant(instant.getId())
.withAngleCnec(cnecId)
.withUsageMethod(usageMethod)
.add();
}
remedialActionAdder.newOnConstraintUsageRule()
.withInstant(instant.getId())
.withCnec(cnecId)
.withUsageMethod(usageMethod)
.add();
}
} else {
alterations.add(cnecStatus.statusDetails());
Expand Down Expand Up @@ -259,9 +243,7 @@ private Set<String> createRemedialActionGroups() {
standaloneRasImplicatedIntoAGroup.addAll(dependingEnabledRemedialActions.stream().map(RemedialActionDependency::remedialAction).collect(Collectors.toSet()));
throw new OpenRaoImportException(ImportStatus.INCONSISTENCY_IN_DATA, "Remedial action group " + remedialActionGroup.mrid() + " will not be imported because the remedial action " + refRemedialActionDependency.remedialAction() + " does not exist or not imported. All RA's depending in that group will be ignored: " + printRaIds(dependingEnabledRemedialActions));
}
List<UsageRule> onAngleConstraintUsageRules = refNetworkAction.getUsageRules().stream().filter(OnAngleConstraint.class::isInstance).toList();
List<UsageRule> onFlowConstraintUsageRules = refNetworkAction.getUsageRules().stream().filter(OnFlowConstraint.class::isInstance).toList();
List<UsageRule> onVoltageConstraintUsageRules = refNetworkAction.getUsageRules().stream().filter(OnVoltageConstraint.class::isInstance).toList();
List<UsageRule> onConstraintUsageRules = refNetworkAction.getUsageRules().stream().filter(OnConstraint.class::isInstance).toList();
List<UsageRule> onContingencyStateUsageRules = refNetworkAction.getUsageRules().stream().filter(OnContingencyState.class::isInstance).toList();
List<UsageRule> onInstantUsageRules = refNetworkAction.getUsageRules().stream().filter(OnInstant.class::isInstance).toList();

Expand Down Expand Up @@ -289,7 +271,7 @@ private Set<String> createRemedialActionGroups() {
if (operators.size() == 1) {
networkActionAdder.withOperator(operators.iterator().next());
}
addUsageRulesToGroup(onAngleConstraintUsageRules, onFlowConstraintUsageRules, onVoltageConstraintUsageRules, onContingencyStateUsageRules, onInstantUsageRules, injectionSetpoints, pstSetPoints, topologicalActions, networkActionAdder);
addUsageRulesToGroup(onConstraintUsageRules, onContingencyStateUsageRules, onInstantUsageRules, injectionSetpoints, pstSetPoints, topologicalActions, networkActionAdder);
addElementaryActionsToGroup(injectionSetpoints, pstSetPoints, topologicalActions, networkActionAdder);
networkActionAdder.add();
contextByRaId.put(remedialActionGroup.mrid(), CsaProfileElementaryCreationContext.imported(remedialActionGroup.mrid(), remedialActionGroup.mrid(), groupName, "The RemedialActionGroup with mRID " + remedialActionGroup.mrid() + " was turned into a remedial action from the following remedial actions: " + printRaIds(dependingEnabledRemedialActions), true));
Expand Down Expand Up @@ -328,29 +310,13 @@ private static void addElementaryActionsToGroup(List<ElementaryAction> injection
});
}

private static void addUsageRulesToGroup(List<UsageRule> onAngleConstraintUsageRules, List<UsageRule> onFlowConstraintUsageRules, List<UsageRule> onVoltageConstraintUsageRules, List<UsageRule> onContingencyStateUsageRules, List<UsageRule> onInstantUsageRules, List<ElementaryAction> injectionSetpoints, List<ElementaryAction> pstSetPoints, List<ElementaryAction> topologicalActions, NetworkActionAdder networkActionAdder) {
onAngleConstraintUsageRules.forEach(ur -> {
OnAngleConstraint onAngleConstraintUsageRule = (OnAngleConstraint) ur;
networkActionAdder.newOnAngleConstraintUsageRule()
.withInstant(onAngleConstraintUsageRule.getInstant().getId())
.withUsageMethod(onAngleConstraintUsageRule.getUsageMethod())
.withAngleCnec(onAngleConstraintUsageRule.getAngleCnec().getId())
.add();
});
onFlowConstraintUsageRules.forEach(ur -> {
OnFlowConstraint onFlowConstraintUsageRule = (OnFlowConstraint) ur;
networkActionAdder.newOnFlowConstraintUsageRule()
.withInstant(onFlowConstraintUsageRule.getInstant().getId())
.withUsageMethod(onFlowConstraintUsageRule.getUsageMethod())
.withFlowCnec(onFlowConstraintUsageRule.getFlowCnec().getId())
.add();
});
onVoltageConstraintUsageRules.forEach(ur -> {
OnVoltageConstraint onVoltageConstraintUsageRule = (OnVoltageConstraint) ur;
networkActionAdder.newOnVoltageConstraintUsageRule()
.withInstant(onVoltageConstraintUsageRule.getInstant().getId())
.withUsageMethod(onVoltageConstraintUsageRule.getUsageMethod())
.withVoltageCnec(onVoltageConstraintUsageRule.getVoltageCnec().getId())
private static void addUsageRulesToGroup(List<UsageRule> onConstraintUsageRules, List<UsageRule> onContingencyStateUsageRules, List<UsageRule> onInstantUsageRules, List<ElementaryAction> injectionSetpoints, List<ElementaryAction> pstSetPoints, List<ElementaryAction> topologicalActions, NetworkActionAdder networkActionAdder) {
onConstraintUsageRules.forEach(ur -> {
OnConstraint<?> onConstraintUsageRule = (OnConstraint<?>) ur;
networkActionAdder.newOnConstraintUsageRule()
.withInstant(onConstraintUsageRule.getInstant().getId())
.withUsageMethod(onConstraintUsageRule.getUsageMethod())
.withCnec(onConstraintUsageRule.getCnec().getId())
.add();
});
onContingencyStateUsageRules.forEach(ur -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.powsybl.openrao.data.cracapi.Instant;
import com.powsybl.openrao.data.cracapi.NetworkElement;
import com.powsybl.openrao.data.cracapi.cnec.AngleCnec;
import com.powsybl.openrao.data.cracapi.cnec.Cnec;
import com.powsybl.openrao.data.cracapi.cnec.FlowCnec;
import com.powsybl.openrao.data.cracapi.cnec.Side;
import com.powsybl.openrao.data.cracapi.cnec.VoltageCnec;
Expand Down Expand Up @@ -180,32 +181,16 @@ public static void assertHasOnContingencyStateUsageRule(CsaProfileCracCreationCo
assertHasOnContingencyStateUsageRule(cracCreationContext, raId, contingencyId, cracCreationContext.getCrac().getInstant(instant), usageMethod);
}

public static void assertHasOnFlowConstraintUsageRule(CsaProfileCracCreationContext cracCreationContext, String raId, String flowCnecId, Instant instant, UsageMethod usageMethod) {
public static void assertHasOnConstraintUsageRule(CsaProfileCracCreationContext cracCreationContext, String raId, String cnecId, Instant instant, UsageMethod usageMethod, Class<? extends Cnec<?>> cnecType) {
assertTrue(
cracCreationContext.getCrac().getRemedialAction(raId).getUsageRules().stream().filter(OnFlowConstraint.class::isInstance)
.map(OnFlowConstraint.class::cast)
.anyMatch(ur -> ur.getFlowCnec().getId().equals(flowCnecId) && ur.getInstant().equals(instant) && ur.getUsageMethod().equals(usageMethod))
cracCreationContext.getCrac().getRemedialAction(raId).getUsageRules().stream().filter(OnConstraint.class::isInstance)
.map(OnConstraint.class::cast)
.anyMatch(ur -> ur.getCnec().getId().equals(cnecId) && cnecType.isInstance(ur.getCnec()) && ur.getInstant().equals(instant) && ur.getUsageMethod().equals(usageMethod))
);
}

public static void assertHasOnFlowConstraintUsageRule(CsaProfileCracCreationContext cracCreationContext, String raId, String flowCnecId, String instant, UsageMethod usageMethod) {
assertHasOnFlowConstraintUsageRule(cracCreationContext, raId, flowCnecId, cracCreationContext.getCrac().getInstant(instant), usageMethod);
}

public static void assertHasOnAngleConstraintUsageRule(CsaProfileCracCreationContext cracCreationContext, String raId, String angleCnecId, Instant instant, UsageMethod usageMethod) {
assertTrue(
cracCreationContext.getCrac().getRemedialAction(raId).getUsageRules().stream().filter(OnAngleConstraint.class::isInstance)
.map(OnAngleConstraint.class::cast)
.anyMatch(ur -> ur.getAngleCnec().getId().equals(angleCnecId) && ur.getInstant().equals(instant) && ur.getUsageMethod().equals(usageMethod))
);
}

public static void assertHasOnVoltageConstraintUsageRule(CsaProfileCracCreationContext cracCreationContext, String raId, String voltageCnecId, Instant instant, UsageMethod usageMethod) {
assertTrue(
cracCreationContext.getCrac().getRemedialAction(raId).getUsageRules().stream().filter(OnVoltageConstraint.class::isInstance)
.map(OnVoltageConstraint.class::cast)
.anyMatch(ur -> ur.getVoltageCnec().getId().equals(voltageCnecId) && ur.getInstant().equals(instant) && ur.getUsageMethod().equals(usageMethod))
);
public static void assertHasOnConstraintUsageRule(CsaProfileCracCreationContext cracCreationContext, String raId, String flowCnecId, String instant, UsageMethod usageMethod, Class<? extends Cnec<?>> cnecType) {
assertHasOnConstraintUsageRule(cracCreationContext, raId, flowCnecId, cracCreationContext.getCrac().getInstant(instant), usageMethod, cnecType);
}

public static void assertRaNotImported(CsaProfileCracCreationContext cracCreationContext, String raId, ImportStatus importStatus, String importStatusDetail) {
Expand Down
Loading

0 comments on commit 0046945

Please sign in to comment.