Skip to content

Commit

Permalink
Merge branch 'main' into add_readmes
Browse files Browse the repository at this point in the history
  • Loading branch information
OpenSuze committed Apr 30, 2024
2 parents b5b3f85 + b016492 commit c24a575
Show file tree
Hide file tree
Showing 170 changed files with 2,117 additions and 805 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ public String toString() {
public static final String REQUEST_ASSESSED_ELEMENT_WITH_CONTINGENCY_NORMAL_ENABLED = "normalEnabled";
public static final String REQUEST_ASSESSED_ELEMENT_SCANNED_FOR_REGION = "scannedForRegion";
public static final String REQUEST_ASSESSED_ELEMENT_SECURED_FOR_REGION = "securedForRegion";
public static final String REQUEST_FLOW_RELIABILITY_MARGIN = "flowReliabilityMargin";

public static final String REQUEST_CURRENT_LIMIT = "currentLimit";
public static final String REQUEST_VOLTAGE_LIMIT = "voltageLimit";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.contingency.CsaProfileContingencyCreator;
import com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.remedialaction.CsaProfileRemedialActionsCreator;
import com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.remedialaction.ElementaryActionsHelper;
import com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.remedialaction.OnConstraintUsageRuleHelper;
import com.google.auto.service.AutoService;
import com.powsybl.iidm.network.Network;
import com.powsybl.openrao.data.craccreation.creator.csaprofile.parameters.CsaCracCreationParameters;
Expand Down Expand Up @@ -61,12 +60,12 @@ public CsaProfileCracCreationContext createCrac(CsaProfileCrac nativeCrac, Netwo
Map<String, String> overridingData = nativeCrac.getOverridingCracData(offsetDateTime);
PropertyBags contingencies = CsaProfileCracUtils.overrideData(nativeCrac.getContingencies(), overridingData, CsaProfileConstants.OverridingObjectsFields.CONTINGENCY);
PropertyBags assessedElements = CsaProfileCracUtils.overrideData(nativeCrac.getAssessedElements(), overridingData, CsaProfileConstants.OverridingObjectsFields.ASSESSED_ELEMENT);
PropertyBags assessedElementsWithContingencies = CsaProfileCracUtils.overrideData(nativeCrac.getAssessedElementsWithContingencies(), overridingData, CsaProfileConstants.OverridingObjectsFields.ASSESSED_ELEMENT_WITH_CONTINGENCY);
PropertyBags assessedElementWithContingencies = CsaProfileCracUtils.overrideData(nativeCrac.getAssessedElementsWithContingencies(), overridingData, CsaProfileConstants.OverridingObjectsFields.ASSESSED_ELEMENT_WITH_CONTINGENCY);
PropertyBags currentLimits = CsaProfileCracUtils.overrideData(nativeCrac.getCurrentLimits(), overridingData, CsaProfileConstants.OverridingObjectsFields.CURRENT_LIMIT);
PropertyBags voltageLimits = CsaProfileCracUtils.overrideData(nativeCrac.getVoltageLimits(), overridingData, CsaProfileConstants.OverridingObjectsFields.VOLTAGE_LIMIT);
PropertyBags angleLimits = CsaProfileCracUtils.overrideData(nativeCrac.getAngleLimits(), overridingData, CsaProfileConstants.OverridingObjectsFields.VOLTAGE_ANGLE_LIMIT);
PropertyBags assessedElementsWithRemedialAction = CsaProfileCracUtils.overrideData(nativeCrac.getAssessedElementsWithRemedialAction(), overridingData, CsaProfileConstants.OverridingObjectsFields.ASSESSED_ELEMENT_WITH_REMEDIAL_ACTION);
PropertyBags contingenciesWithRemedialAction = CsaProfileCracUtils.overrideData(nativeCrac.getContingencyWithRemedialAction(), overridingData, CsaProfileConstants.OverridingObjectsFields.CONTINGENCY_WITH_REMEDIAL_ACTION);
PropertyBags assessedElementWithRemedialActions = CsaProfileCracUtils.overrideData(nativeCrac.getAssessedElementsWithRemedialAction(), overridingData, CsaProfileConstants.OverridingObjectsFields.ASSESSED_ELEMENT_WITH_REMEDIAL_ACTION);
PropertyBags contingencyWithRemedialActions = CsaProfileCracUtils.overrideData(nativeCrac.getContingencyWithRemedialAction(), overridingData, CsaProfileConstants.OverridingObjectsFields.CONTINGENCY_WITH_REMEDIAL_ACTION);
PropertyBags gridStateAlterationRemedialAction = CsaProfileCracUtils.overrideData(nativeCrac.getGridStateAlterationRemedialAction(), overridingData, CsaProfileConstants.OverridingObjectsFields.GRID_STATE_ALTERATION_REMEDIAL_ACTION);
PropertyBags remedialActionSchemes = CsaProfileCracUtils.overrideData(nativeCrac.getRemedialActionScheme(), overridingData, CsaProfileConstants.OverridingObjectsFields.REMEDIAL_ACTION_SCHEME);
PropertyBags gridStateAlterationsCollection = CsaProfileCracUtils.overrideData(nativeCrac.getGridStateAlterationCollection(), overridingData, CsaProfileConstants.OverridingObjectsFields.GRID_STATE_ALTERATION);
Expand All @@ -80,11 +79,10 @@ public CsaProfileCracCreationContext createCrac(CsaProfileCrac nativeCrac, Netwo

createContingencies(contingencies, nativeCrac.getContingencyEquipments());

createCnecs(assessedElements, assessedElementsWithContingencies, currentLimits, voltageLimits, angleLimits, cracCreationParameters.getDefaultMonitoredSides(), regionEicCode);
createCnecs(assessedElements, assessedElementWithContingencies, currentLimits, voltageLimits, angleLimits, cracCreationParameters.getDefaultMonitoredSides(), regionEicCode);

OnConstraintUsageRuleHelper onConstraintUsageRuleAdder = new OnConstraintUsageRuleHelper(creationContext.getCnecCreationContexts(), assessedElements, assessedElementsWithRemedialAction);
ElementaryActionsHelper elementaryActionsHelper = new ElementaryActionsHelper(gridStateAlterationRemedialAction, schemeRemedialActions, remedialActionSchemes, nativeCrac.getStage(), gridStateAlterationsCollection, assessedElementsWithRemedialAction, contingenciesWithRemedialAction, staticPropertyRanges, topologyActions, rotatingMachineActions, shuntCompensatorModifications, tapPositionActions, nativeCrac.getRemedialActionGroups(), remedialActionDependencies);
createRemedialActions(onConstraintUsageRuleAdder, elementaryActionsHelper, spsMaxTimeToImplementThreshold);
ElementaryActionsHelper elementaryActionsHelper = new ElementaryActionsHelper(gridStateAlterationRemedialAction, schemeRemedialActions, remedialActionSchemes, nativeCrac.getStage(), gridStateAlterationsCollection, assessedElementWithRemedialActions, contingencyWithRemedialActions, staticPropertyRanges, topologyActions, rotatingMachineActions, shuntCompensatorModifications, tapPositionActions, nativeCrac.getRemedialActionGroups(), remedialActionDependencies);
createRemedialActions(elementaryActionsHelper, spsMaxTimeToImplementThreshold, assessedElements, assessedElementWithRemedialActions, contingencyWithRemedialActions, creationContext.getCnecCreationContexts());
creationContext.buildCreationReport();
return creationContext.creationSuccess(crac);
}
Expand Down Expand Up @@ -116,8 +114,8 @@ private boolean checkTimeCoherence(PropertyBag header, OffsetDateTime offsetDate
return isValidInterval(offsetDateTime, startTime, endTime);
}

private void createRemedialActions(OnConstraintUsageRuleHelper onConstraintUsageRuleAdder, ElementaryActionsHelper elementaryActionsHelper, int spsMaxTimeToImplementThreshold) {
new CsaProfileRemedialActionsCreator(crac, network, creationContext, onConstraintUsageRuleAdder, elementaryActionsHelper, spsMaxTimeToImplementThreshold);
private void createRemedialActions(ElementaryActionsHelper elementaryActionsHelper, int spsMaxTimeToImplementThreshold, PropertyBags assessedElements, PropertyBags assessedElementWithRemedialActions, PropertyBags contingencyWithRemedialActions, Set<CsaProfileElementaryCreationContext> cnecCreationContexts) {
new CsaProfileRemedialActionsCreator(crac, network, creationContext, elementaryActionsHelper, spsMaxTimeToImplementThreshold, assessedElements, assessedElementWithRemedialActions, contingencyWithRemedialActions, cnecCreationContexts);
}

private void createContingencies(PropertyBags contingenciesPropertyBags, PropertyBags contingencyEquipmentsPropertyBags) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ private CsaProfileCracUtils() {

}

public static Map<String, Set<PropertyBag>> getMappedPropertyBagsSet(PropertyBags propertyBags, String property) {
public static Map<String, Set<PropertyBag>> groupPropertyBags(PropertyBags propertyBags, String groupingPoperty) {
Map<String, Set<PropertyBag>> mappedPropertyBags = new HashMap<>();
for (PropertyBag propertyBag : propertyBags) {
String propValue = propertyBag.getId(property);
String propValue = propertyBag.getId(groupingPoperty);
Set<PropertyBag> propPropertyBags = mappedPropertyBags.computeIfAbsent(propValue, k -> new HashSet<>());
propPropertyBags.add(propertyBag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import java.util.Optional;
import java.util.Set;

import static com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.CsaProfileCracUtils.getTsoNameFromUrl;

public abstract class AbstractCnecCreator {
protected final Crac crac;
protected final Network network;
Expand Down Expand Up @@ -84,10 +82,9 @@ protected String getCnecName(String instantId, Contingency contingency, int tatl
return "%s - TATL %s".formatted(getCnecName(instantId, contingency), tatlDuration);
}

protected boolean addCnecBaseInformation(CnecAdder<?> cnecAdder, Contingency contingency, String instantId) {
protected void addCnecBaseInformation(CnecAdder<?> cnecAdder, Contingency contingency, String instantId) {
String cnecName = getCnecName(instantId, contingency);
initCnecAdder(cnecAdder, contingency, instantId, cnecName);
return true;
}

protected void addCnecBaseInformation(CnecAdder<?> cnecAdder, Contingency contingency, String instantId, int tatlDuration) {
Expand All @@ -100,7 +97,7 @@ private void initCnecAdder(CnecAdder<?> cnecAdder, Contingency contingency, Stri
.withId(cnecName)
.withName(cnecName)
.withInstant(instantId)
.withOperator(getTsoNameFromUrl(assessedElementOperator))
.withOperator(CsaProfileCracUtils.getTsoNameFromUrl(assessedElementOperator))
.withOptimized(aeSecuredForRegion)
.withMonitored(aeScannedForRegion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.IdentifiableType;
import com.powsybl.iidm.network.Network;
import com.powsybl.openrao.data.craccreation.util.OpenRaoImportException;
import com.powsybl.triplestore.api.PropertyBag;

import java.util.List;
import java.util.Objects;
import java.util.Set;

public class AngleCnecCreator extends AbstractCnecCreator {
Expand All @@ -35,21 +35,17 @@ public void addAngleCnecs() {

private void addAngleCnec(String instantId, Contingency contingency) {
AngleCnecAdder angleCnecAdder = initAngleCnec();
if (addAngleLimit(angleCnecAdder)) {
if (!addCnecBaseInformation(angleCnecAdder, contingency, instantId)) {
return;
}
angleCnecAdder.add();
markCnecAsImportedAndHandleRejectedContingencies(getCnecName(instantId, contingency));
}
addAngleLimit(angleCnecAdder);
addCnecBaseInformation(angleCnecAdder, contingency, instantId);
angleCnecAdder.add();
markCnecAsImportedAndHandleRejectedContingencies(getCnecName(instantId, contingency));
}

private AngleCnecAdder initAngleCnec() {
return crac.newAngleCnec()
.withReliabilityMargin(0);
return crac.newAngleCnec().withReliabilityMargin(0);
}

private boolean addAngleLimit(AngleCnecAdder angleCnecAdder) {
private void addAngleLimit(AngleCnecAdder angleCnecAdder) {
String isFlowToRefTerminalStr = operationalLimitPropertyBag.get(CsaProfileConstants.REQUEST_IS_FLOW_TO_REF_TERMINAL);
boolean isFlowToRefTerminalIsNull = isFlowToRefTerminalStr == null;
boolean isFlowToRefTerminal = isFlowToRefTerminalIsNull || Boolean.parseBoolean(isFlowToRefTerminalStr);
Expand All @@ -58,54 +54,37 @@ private boolean addAngleLimit(AngleCnecAdder angleCnecAdder) {
String terminal2Id = operationalLimitPropertyBag.getId("terminal2");

String networkElement1Id = checkAngleNetworkElementAndGetId(terminal1Id);
if (networkElement1Id == null) {
return false;
}
String networkElement2Id = checkAngleNetworkElementAndGetId(terminal2Id);
if (networkElement2Id == null) {
return false;
}

boolean areNetworkElementsOk = this.addAngleCnecElements(angleCnecAdder, networkElement1Id, networkElement2Id, isFlowToRefTerminal);
if (!areNetworkElementsOk) {
return false;
}

return this.addAngleLimitThreshold(angleCnecAdder, operationalLimitPropertyBag, isFlowToRefTerminalIsNull);
addAngleCnecElements(angleCnecAdder, networkElement1Id, networkElement2Id, isFlowToRefTerminal);
addAngleLimitThreshold(angleCnecAdder, operationalLimitPropertyBag, isFlowToRefTerminalIsNull);
}

private String checkAngleNetworkElementAndGetId(String terminalId) {
Identifiable<?> networkElement = this.getNetworkElementInNetwork(terminalId);
if (networkElement == null) {
csaProfileCnecCreationContexts.add(CsaProfileElementaryCreationContext.notImported(assessedElementId, ImportStatus.ELEMENT_NOT_FOUND_IN_NETWORK, writeAssessedElementIgnoredReasonMessage("the angle limit equipment " + terminalId + " is missing in network")));
return null;
throw new OpenRaoImportException(ImportStatus.ELEMENT_NOT_FOUND_IN_NETWORK, writeAssessedElementIgnoredReasonMessage("the angle limit equipment " + terminalId + " is missing in network"));
}
if (!networkElement.getType().equals(IdentifiableType.BUS)) {
csaProfileCnecCreationContexts.add(CsaProfileElementaryCreationContext.notImported(assessedElementId, ImportStatus.INCONSISTENCY_IN_DATA, writeAssessedElementIgnoredReasonMessage("the network element " + networkElement.getId() + " is not a bus bar section")));
return null;
throw new OpenRaoImportException(ImportStatus.INCONSISTENCY_IN_DATA, writeAssessedElementIgnoredReasonMessage("the network element " + networkElement.getId() + " is not a bus bar section"));
}
return networkElement.getId();
}

private boolean addAngleLimitThreshold(AngleCnecAdder angleCnecAdder, PropertyBag angleLimit, boolean isFlowToRefTerminalIsNull) {
private void addAngleLimitThreshold(AngleCnecAdder angleCnecAdder, PropertyBag angleLimit, boolean isFlowToRefTerminalIsNull) {
String normalValueStr = angleLimit.get(CsaProfileConstants.REQUEST_VOLTAGE_ANGLE_LIMIT_NORMAL_VALUE);
Double normalValue = Double.valueOf(normalValueStr);
if (normalValue < 0) {
csaProfileCnecCreationContexts.add(CsaProfileElementaryCreationContext.notImported(assessedElementId, ImportStatus.INCONSISTENCY_IN_DATA, writeAssessedElementIgnoredReasonMessage("the angle limit's normal value is negative")));
return false;
throw new OpenRaoImportException(ImportStatus.INCONSISTENCY_IN_DATA, writeAssessedElementIgnoredReasonMessage("the angle limit's normal value is negative"));
}
String direction = angleLimit.get(CsaProfileConstants.REQUEST_OPERATIONAL_LIMIT_DIRECTION);
if (CsaProfileConstants.OperationalLimitDirectionKind.HIGH.toString().equals(direction)) {
if (handleMissingIsFlowToRefTerminalForNotAbsoluteDirection(isFlowToRefTerminalIsNull, CsaProfileConstants.OperationalLimitDirectionKind.HIGH)) {
return false;
}
handleMissingIsFlowToRefTerminalForNotAbsoluteDirection(isFlowToRefTerminalIsNull, CsaProfileConstants.OperationalLimitDirectionKind.HIGH);
angleCnecAdder.newThreshold()
.withUnit(Unit.DEGREE)
.withMax(normalValue).add();
} else if (CsaProfileConstants.OperationalLimitDirectionKind.LOW.toString().equals(direction)) {
if (handleMissingIsFlowToRefTerminalForNotAbsoluteDirection(isFlowToRefTerminalIsNull, CsaProfileConstants.OperationalLimitDirectionKind.LOW)) {
return false;
}
handleMissingIsFlowToRefTerminalForNotAbsoluteDirection(isFlowToRefTerminalIsNull, CsaProfileConstants.OperationalLimitDirectionKind.LOW);
angleCnecAdder.newThreshold()
.withUnit(Unit.DEGREE)
.withMin(-normalValue).add();
Expand All @@ -115,25 +94,20 @@ private boolean addAngleLimitThreshold(AngleCnecAdder angleCnecAdder, PropertyBa
.withMin(-normalValue)
.withMax(normalValue).add();
}
return true;
}

private boolean handleMissingIsFlowToRefTerminalForNotAbsoluteDirection(boolean isFlowToRefTerminalIsNull, CsaProfileConstants.OperationalLimitDirectionKind direction) {
private void handleMissingIsFlowToRefTerminalForNotAbsoluteDirection(boolean isFlowToRefTerminalIsNull, CsaProfileConstants.OperationalLimitDirectionKind direction) {
if (isFlowToRefTerminalIsNull) {
csaProfileCnecCreationContexts.add(CsaProfileElementaryCreationContext.notImported(assessedElementId, ImportStatus.INCONSISTENCY_IN_DATA, writeAssessedElementIgnoredReasonMessage("of an ambiguous angle limit direction definition from an undefined VoltageAngleLimit.isFlowToRefTerminal and an OperationalLimit.OperationalLimitType: " + direction)));
return true;
throw new OpenRaoImportException(ImportStatus.INCONSISTENCY_IN_DATA, writeAssessedElementIgnoredReasonMessage("of an ambiguous angle limit direction definition from an undefined VoltageAngleLimit.isFlowToRefTerminal and an OperationalLimit.OperationalLimitType: " + direction));
}
return false;
}

private boolean addAngleCnecElements(AngleCnecAdder angleCnecAdder, String networkElement1Id, String networkElement2Id, boolean isFlowToRefTerminal) {
if (Objects.equals(networkElement1Id, networkElement2Id)) {
csaProfileCnecCreationContexts.add(CsaProfileElementaryCreationContext.notImported(assessedElementId, ImportStatus.INCONSISTENCY_IN_DATA, writeAssessedElementIgnoredReasonMessage("AngleCNEC's importing and exporting equipments are the same: " + networkElement1Id)));
return false;
private void addAngleCnecElements(AngleCnecAdder angleCnecAdder, String networkElement1Id, String networkElement2Id, boolean isFlowToRefTerminal) {
if (networkElement1Id.equals(networkElement2Id)) {
throw new OpenRaoImportException(ImportStatus.INCONSISTENCY_IN_DATA, writeAssessedElementIgnoredReasonMessage("AngleCNEC's importing and exporting equipments are the same: " + networkElement1Id));
}
String importingElement = isFlowToRefTerminal ? networkElement1Id : networkElement2Id;
String exportingElement = isFlowToRefTerminal ? networkElement2Id : networkElement1Id;
angleCnecAdder.withImportingNetworkElement(importingElement).withExportingNetworkElement(exportingElement);
return true;
}
}
Loading

0 comments on commit c24a575

Please sign in to comment.