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

Refactor tests #923

Merged
merged 16 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,11 @@ public String toString() {
public static final String REQUEST_SHUNT_COMPENSATOR_MODIFICATION = "shuntCompensatorModification";
public static final String REQUEST_TAP_POSITION_ACTION = "tapPositionAction";
public static final String CGMES = "CGMES";
public static final String REQUEST_OPERATIONAL_LIMIT_NORMAL_VALUE = "normalValue";
public static final String REQUEST_OPERATIONAL_LIMIT_VALUE = "value";
public static final String REQUEST_VOLTAGE_ANGLE_LIMIT_NORMAL_VALUE = "normalValue";
public static final String REQUEST_OPERATIONAL_LIMIT_TERMINAL = "terminal";
public static final String REQUEST_OPERATIONAL_LIMIT_KIND = "kind";
public static final String REQUEST_OPERATIONAL_LIMIT_EQUIPMENT = "equipment";
public static final String REQUEST_OPERATIONAL_LIMIT_TYPE = "limitType";
public static final String REQUEST_OPERATIONAL_LIMIT_DIRECTION = "direction";
public static final String REQUEST_OPERATIONAL_LIMIT_ACCEPTABLE_DURATION = "acceptableDuration";
public static final String REQUEST_VOLTAGE_LIMIT_IS_INFINITE_DURATION = "isInfiniteDuration";
Expand All @@ -249,6 +251,7 @@ public String toString() {
public static final List<String> CURRENT_LIMIT_POSSIBLE_ALIASES_BY_TYPE_RIGHT = List.of("CGMES.Terminal2", "CGMES.Terminal_Boundary_2");
public static final List<String> CURRENT_LIMIT_POSSIBLE_ALIASES_BY_TYPE_TIE_LINE = List.of("CGMES.Terminal1", "CGMES.Terminal_Boundary");
public static final String IEC_URL = "http://iec.ch/TC57/";
public static final String ENTSOE_URL = "http://entsoe.eu/CIM/SchemaExtension/3/1#";

public enum ElementCombinationConstraintKind {
CONSIDERED("considered"),
Expand All @@ -268,20 +271,22 @@ public String toString() {
}
}

public enum LimitKind {
public enum LimitTypeKind {
PATL("patl"),
TATL("tatl");
TATL("tatl"),
HIGH_VOLTAGE("highVoltage"),
LOW_VOLTAGE("lowVoltage");

LimitKind(String name) {
LimitTypeKind(String name) {
this.name = name;
}

private final String name;
private static final String URL = IEC_URL + "CIM100-European#LimitKind.";
private static final String URL = ENTSOE_URL + "LimitTypeKind.";

@Override
public String toString() {
return LimitKind.URL + this.name;
return LimitTypeKind.URL + this.name;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static int convertDurationToSeconds(String duration) {
public static void checkPropertyReference(PropertyBag propertyBag, String remedialActionId, String propertyBagKind, String expectedPropertyReference) {
String actualPropertyReference = propertyBag.get(CsaProfileConstants.GRID_ALTERATION_PROPERTY_REFERENCE);
if (!actualPropertyReference.equals(expectedPropertyReference)) {
throw new OpenRaoImportException(ImportStatus.INCONSISTENCY_IN_DATA, String.format("Remedial action '%s' will not be imported because '%s' must have a property reference with '%s' value, but it was: '%s'", remedialActionId, propertyBagKind, expectedPropertyReference, actualPropertyReference));
throw new OpenRaoImportException(ImportStatus.INCONSISTENCY_IN_DATA, String.format("Remedial action %s will not be imported because %s must have a property reference with %s value, but it was: %s", remedialActionId, propertyBagKind, expectedPropertyReference, actualPropertyReference));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected Identifiable<?> getNetworkElementInNetwork(String networkElementId) {
}

protected String writeAssessedElementIgnoredReasonMessage(String reason) {
return "Assessed Element " + assessedElementId + " ignored because " + reason + ".";
return "AssessedElement " + assessedElementId + " ignored because " + reason;
}

protected String getCnecName(String instantId, Contingency contingency) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ private void addAngleCnec(String instantId, Contingency contingency) {

private AngleCnecAdder initAngleCnec() {
return crac.newAngleCnec()
.withMonitored(true)
.withOptimized(false)
.withReliabilityMargin(0);
.withMonitored(true)
.withOptimized(false)
.withReliabilityMargin(0);
}

private boolean addAngleLimit(AngleCnecAdder angleCnecAdder) {
Expand Down Expand Up @@ -77,7 +77,7 @@ private boolean addAngleLimit(AngleCnecAdder angleCnecAdder) {
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("angle limit equipment is missing in network : " + terminalId)));
csaProfileCnecCreationContexts.add(CsaProfileElementaryCreationContext.notImported(assessedElementId, ImportStatus.ELEMENT_NOT_FOUND_IN_NETWORK, writeAssessedElementIgnoredReasonMessage("the angle limit equipment " + terminalId + " is missing in network")));
return null;
}
if (!networkElement.getType().equals(IdentifiableType.BUS)) {
Expand All @@ -88,7 +88,7 @@ private String checkAngleNetworkElementAndGetId(String terminalId) {
}

private boolean addAngleLimitThreshold(AngleCnecAdder angleCnecAdder, PropertyBag angleLimit, boolean isFlowToRefTerminalIsNull) {
String normalValueStr = angleLimit.get(CsaProfileConstants.REQUEST_OPERATIONAL_LIMIT_NORMAL_VALUE);
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")));
Expand All @@ -100,35 +100,35 @@ private boolean addAngleLimitThreshold(AngleCnecAdder angleCnecAdder, PropertyBa
return false;
}
angleCnecAdder.newThreshold()
.withUnit(Unit.DEGREE)
.withMax(normalValue).add();
.withUnit(Unit.DEGREE)
.withMax(normalValue).add();
} else if (CsaProfileConstants.OperationalLimitDirectionKind.LOW.toString().equals(direction)) {
if (handleMissingIsFlowToRefTerminalForNotAbsoluteDirection(isFlowToRefTerminalIsNull, CsaProfileConstants.OperationalLimitDirectionKind.LOW)) {
return false;
}
angleCnecAdder.newThreshold()
.withUnit(Unit.DEGREE)
.withMin(-normalValue).add();
.withUnit(Unit.DEGREE)
.withMin(-normalValue).add();
} else if (CsaProfileConstants.OperationalLimitDirectionKind.ABSOLUTE.toString().equals(direction)) {
angleCnecAdder.newThreshold()
.withUnit(Unit.DEGREE)
.withMin(-normalValue)
.withMax(normalValue).add();
.withUnit(Unit.DEGREE)
.withMin(-normalValue)
.withMax(normalValue).add();
}
return true;
}

private boolean 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)));
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;
}
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)));
csaProfileCnecCreationContexts.add(CsaProfileElementaryCreationContext.notImported(assessedElementId, ImportStatus.INCONSISTENCY_IN_DATA, writeAssessedElementIgnoredReasonMessage("AngleCNEC's importing and exporting equipments are the same: " + networkElement1Id)));
return false;
}
String importingElement = isFlowToRefTerminal ? networkElement1Id : networkElement2Id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ private void addCnec(PropertyBag assessedElementPropertyBag) {
String inBaseCaseStr = assessedElementPropertyBag.get(CsaProfileConstants.REQUEST_ASSESSED_ELEMENT_IN_BASE_CASE);
boolean inBaseCase = Boolean.parseBoolean(inBaseCaseStr);

Set<PropertyBag> assessedElementsWithContingencies = getAssessedElementsWithContingencies(assessedElementId, assessedElementPropertyBag, inBaseCase);
if (!inBaseCase && assessedElementsWithContingencies == null) {
return;
}
Set<PropertyBag> assessedElementsWithContingencies = this.assessedElementsWithContingenciesPropertyBags.get(assessedElementPropertyBag.getId(CsaProfileConstants.REQUEST_ASSESSED_ELEMENT));

String isCombinableWithContingencyStr = assessedElementPropertyBag.get(CsaProfileConstants.REQUEST_ASSESSED_ELEMENT_IS_COMBINABLE_WITH_CONTINGENCY);
boolean isCombinableWithContingency = Boolean.parseBoolean(isCombinableWithContingencyStr);

if (!inBaseCase && !isCombinableWithContingency && assessedElementsWithContingencies == null) {
csaProfileCnecCreationContexts.add(CsaProfileElementaryCreationContext.notImported(assessedElementId, ImportStatus.INCONSISTENCY_IN_DATA, "AssessedElement %s ignored because the assessed element is not in base case and not combinable with contingencies, but no explicit link to a contingency was found".formatted(assessedElementId)));
return;
}

Set<Contingency> combinableContingencies;
if (isCombinableWithContingency) {
combinableContingencies = cracCreationContext.getCrac().getContingencies();
Expand Down Expand Up @@ -130,15 +132,6 @@ private boolean aeProfileDataCheck(String assessedElementId, PropertyBag assesse
return true;
}

private Set<PropertyBag> getAssessedElementsWithContingencies(String assessedElementId, PropertyBag assessedElementPropertyBag, boolean inBaseCase) {
Set<PropertyBag> assessedElementsWithContingencies = this.assessedElementsWithContingenciesPropertyBags.get(assessedElementPropertyBag.getId(CsaProfileConstants.REQUEST_ASSESSED_ELEMENT));

if (!inBaseCase && assessedElementsWithContingencies == null) {
csaProfileCnecCreationContexts.add(CsaProfileElementaryCreationContext.notImported(assessedElementId, ImportStatus.INCOMPLETE_DATA, "no link between the assessed element and a contingency"));
}
return assessedElementsWithContingencies;
}

private CsaProfileConstants.LimitType getLimit(String assessedElementId, PropertyBag assessedElementPropertyBag) {
if (checkLimit(this.currentLimitsPropertyBags, "current", assessedElementId, assessedElementPropertyBag)) {
return CsaProfileConstants.LimitType.CURRENT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ public void addFlowCnecs() {
}
}

addAllFlowCnecsFromBranchAndOperationalLimits((Branch<?>) branch, thresholds, useMaxAndMinThresholds);
addAllFlowCnecsFromBranchAndOperationalLimits((Branch<?>) branch, thresholds, useMaxAndMinThresholds, definitionMode == FlowCnecDefinitionMode.CONDUCTING_EQUIPMENT);
}

private FlowCnecAdder initFlowCnec() {
return crac.newFlowCnec()
.withMonitored(false)
.withOptimized(true)
.withReliabilityMargin(0);
.withMonitored(false)
.withOptimized(true)
.withReliabilityMargin(0);
}

private Identifiable<?> getFlowCnecBranch(String networkElementId) {
Identifiable<?> networkElement = getNetworkElementInNetwork(networkElementId);
if (networkElement == null) {
csaProfileCnecCreationContexts.add(CsaProfileElementaryCreationContext.notImported(assessedElementId, ImportStatus.ELEMENT_NOT_FOUND_IN_NETWORK, writeAssessedElementIgnoredReasonMessage("the following is element missing from the network : " + networkElementId)));
csaProfileCnecCreationContexts.add(CsaProfileElementaryCreationContext.notImported(assessedElementId, ImportStatus.ELEMENT_NOT_FOUND_IN_NETWORK, writeAssessedElementIgnoredReasonMessage("the following element is missing from the network: " + networkElementId)));
return null;
}
if (!(networkElement instanceof Branch)) {
Expand Down Expand Up @@ -143,8 +143,8 @@ private Side getSideFromNonTieLine(Identifiable<?> networkElement, String termin

private void addFlowCnecThreshold(FlowCnecAdder flowCnecAdder, Side side, double threshold, boolean useMaxAndMinThresholds) {
BranchThresholdAdder adder = flowCnecAdder.newThreshold().withSide(side)
.withUnit(Unit.AMPERE)
.withMax(threshold);
.withUnit(Unit.AMPERE)
.withMax(threshold);
if (useMaxAndMinThresholds) {
adder.withMin(-threshold);
}
Expand Down Expand Up @@ -250,16 +250,15 @@ private void addCurativeFlowCnec(Branch<?> networkElement, Contingency contingen
markCnecAsImportedAndHandleRejectedContingencies(cnecName, contingency);
}

private void addAllFlowCnecsFromBranchAndOperationalLimits(Branch<?> networkElement, Map<Integer, EnumMap<TwoSides, Double>> thresholds, boolean useMaxAndMinThresholds) {
private void addAllFlowCnecsFromBranchAndOperationalLimits(Branch<?> networkElement, Map<Integer, EnumMap<TwoSides, Double>> thresholds, boolean useMaxAndMinThresholds, boolean definedWithConductingEquipment) {
EnumMap<TwoSides, Double> patlThresholds = thresholds.get(Integer.MAX_VALUE);
boolean hasPatl = thresholds.get(Integer.MAX_VALUE) != null;

if (inBaseCase) {
// If no PATL, we use the lowest TATL instead (as in PowSyBl).
// Only happens when the AssessedElement is defined with an OperationalLimit
if (hasPatl) {
addFlowCnec(networkElement, null, crac.getPreventiveInstant().getId(), patlThresholds, useMaxAndMinThresholds, false);
} else {
} else if (definedWithConductingEquipment) {
// No PATL thus the longest acceptable duration is strictly lower than Integer.MAX_VALUE
Optional<Integer> longestAcceptableDuration = thresholds.keySet().stream().max(Integer::compareTo);
longestAcceptableDuration.ifPresent(integer -> addFlowCnec(networkElement, null, crac.getPreventiveInstant().getId(), thresholds.get(integer), useMaxAndMinThresholds, true));
Expand Down Expand Up @@ -294,22 +293,22 @@ private void addTatls(Branch<?> networkElement, Map<Integer, EnumMap<TwoSides, D
private Map<Integer, EnumMap<TwoSides, Double>> getPermanentAndTemporaryLimitsOfOperationalLimit(Identifiable<?> branch, String terminalId) {
Map<Integer, EnumMap<TwoSides, Double>> thresholds = new HashMap<>();

String limitKind = operationalLimitPropertyBag.get(CsaProfileConstants.REQUEST_OPERATIONAL_LIMIT_KIND);
String limitType = operationalLimitPropertyBag.get(CsaProfileConstants.REQUEST_OPERATIONAL_LIMIT_TYPE);
Side side = getSideFromNetworkElement(branch, terminalId);
String normalValueStr = operationalLimitPropertyBag.get(CsaProfileConstants.REQUEST_OPERATIONAL_LIMIT_NORMAL_VALUE);
Double normalValue = Double.valueOf(normalValueStr);
String valueStr = operationalLimitPropertyBag.get(CsaProfileConstants.REQUEST_OPERATIONAL_LIMIT_VALUE);
Double value = Double.valueOf(valueStr);

if (side != null) {
int acceptableDuration;
if (CsaProfileConstants.LimitKind.PATL.toString().equals(limitKind)) {
if (CsaProfileConstants.LimitTypeKind.PATL.toString().equals(limitType)) {
acceptableDuration = Integer.MAX_VALUE;
} else if (CsaProfileConstants.LimitKind.TATL.toString().equals(limitKind)) {
} else if (CsaProfileConstants.LimitTypeKind.TATL.toString().equals(limitType)) {
String acceptableDurationStr = operationalLimitPropertyBag.get(CsaProfileConstants.REQUEST_OPERATIONAL_LIMIT_ACCEPTABLE_DURATION);
acceptableDuration = Integer.parseInt(acceptableDurationStr);
} else {
return thresholds;
}
thresholds.put(acceptableDuration, new EnumMap<>(Map.of(side.iidmSide(), normalValue)));
thresholds.put(acceptableDuration, new EnumMap<>(Map.of(side.iidmSide(), value)));
}

return thresholds;
Expand Down
Loading
Loading