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 Importer] Read CNECs borders #1124

Merged
merged 3 commits into from
Sep 9, 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 @@ -23,6 +23,7 @@
import com.powsybl.iidm.network.TieLine;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

Expand All @@ -39,8 +40,9 @@ public abstract class AbstractCnecCreator {
protected final String rejectedLinksAssessedElementContingency;
protected final boolean aeSecuredForRegion;
protected final boolean aeScannedForRegion;
protected final String border;

protected AbstractCnecCreator(Crac crac, Network network, AssessedElement nativeAssessedElement, List<Contingency> linkedContingencies, Set<ElementaryCreationContext> csaProfileCnecCreationContexts, CsaProfileCracCreationContext cracCreationContext, String rejectedLinksAssessedElementContingency, boolean aeSecuredForRegion, boolean aeScannedForRegion) {
protected AbstractCnecCreator(Crac crac, Network network, AssessedElement nativeAssessedElement, List<Contingency> linkedContingencies, Set<ElementaryCreationContext> csaProfileCnecCreationContexts, CsaProfileCracCreationContext cracCreationContext, String rejectedLinksAssessedElementContingency, boolean aeSecuredForRegion, boolean aeScannedForRegion, Map<String, String> borderPerTso, Map<String, String> borderPerEic) {
this.crac = crac;
this.network = network;
this.nativeAssessedElement = nativeAssessedElement;
Expand All @@ -50,6 +52,7 @@ protected AbstractCnecCreator(Crac crac, Network network, AssessedElement native
this.rejectedLinksAssessedElementContingency = rejectedLinksAssessedElementContingency;
this.aeSecuredForRegion = aeSecuredForRegion;
this.aeScannedForRegion = aeScannedForRegion;
this.border = getCnecBorder(borderPerTso, borderPerEic);
}

protected Identifiable<?> getNetworkElementInNetwork(String networkElementId) {
Expand Down Expand Up @@ -99,7 +102,8 @@ private void initCnecAdder(CnecAdder<?> cnecAdder, Contingency contingency, Stri
.withId(cnecName)
.withName(cnecName)
.withInstant(instantId)
.withOperator(CsaProfileCracUtils.getTsoNameFromUrl(nativeAssessedElement.operator()));
.withOperator(CsaProfileCracUtils.getTsoNameFromUrl(nativeAssessedElement.operator()))
.withBorder(border);
if (cnecAdder instanceof FlowCnecAdder) {
// The following 2 lines mustn't be called for angle & voltage CNECs
cnecAdder.withOptimized(aeSecuredForRegion)
Expand All @@ -114,4 +118,11 @@ protected void markCnecAsImportedAndHandleRejectedContingencies(String cnecName)
csaProfileCnecCreationContexts.add(StandardElementaryCreationContext.imported(nativeAssessedElement.mrid(), cnecName, cnecName, true, "some cnec for the same assessed element are not imported because of incorrect data for assessed elements for contingencies : " + rejectedLinksAssessedElementContingency));
}
}

protected String getCnecBorder(Map<String, String> borderPerTso, Map<String, String> borderPerEic) {
if (nativeAssessedElement.overlappingZone() != null) {
return borderPerEic.getOrDefault(CsaProfileCracUtils.getEicFromUrl(nativeAssessedElement.overlappingZone()), null);
}
return borderPerTso.getOrDefault(CsaProfileCracUtils.getTsoNameFromUrl(nativeAssessedElement.operator()), null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.powsybl.openrao.data.cracio.commons.OpenRaoImportException;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
Expand All @@ -31,8 +32,8 @@ public class AngleCnecCreator extends AbstractCnecCreator {

private final VoltageAngleLimit nativeVoltageAngleLimit;

public AngleCnecCreator(Crac crac, Network network, AssessedElement nativeAssessedElement, VoltageAngleLimit nativeVoltageAngleLimit, List<Contingency> linkedContingencies, Set<ElementaryCreationContext> csaProfileCnecCreationContexts, CsaProfileCracCreationContext cracCreationContext, String rejectedLinksAssessedElementContingency, boolean aeSecuredForRegion, boolean aeScannedForRegion) {
super(crac, network, nativeAssessedElement, linkedContingencies, csaProfileCnecCreationContexts, cracCreationContext, rejectedLinksAssessedElementContingency, aeSecuredForRegion, aeScannedForRegion);
public AngleCnecCreator(Crac crac, Network network, AssessedElement nativeAssessedElement, VoltageAngleLimit nativeVoltageAngleLimit, List<Contingency> linkedContingencies, Set<ElementaryCreationContext> csaProfileCnecCreationContexts, CsaProfileCracCreationContext cracCreationContext, String rejectedLinksAssessedElementContingency, boolean aeSecuredForRegion, boolean aeScannedForRegion, Map<String, String> borderPerTso, Map<String, String> borderPerEic) {
super(crac, network, nativeAssessedElement, linkedContingencies, csaProfileCnecCreationContexts, cracCreationContext, rejectedLinksAssessedElementContingency, aeSecuredForRegion, aeScannedForRegion, borderPerTso, borderPerEic);
this.nativeVoltageAngleLimit = nativeVoltageAngleLimit;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.powsybl.openrao.data.cracio.csaprofiles.nc.AssessedElement;
import com.powsybl.openrao.data.cracio.csaprofiles.nc.AssessedElementWithContingency;
import com.powsybl.openrao.data.cracio.csaprofiles.nc.VoltageAngleLimit;
import com.powsybl.openrao.data.cracio.csaprofiles.parameters.Border;
import com.powsybl.openrao.data.cracio.csaprofiles.parameters.CsaCracCreationParameters;
import com.powsybl.openrao.data.cracio.commons.OpenRaoImportException;

Expand All @@ -46,6 +47,8 @@ public class CsaProfileCnecCreator {
private final CsaProfileCracCreationContext cracCreationContext;
private final CracCreationParameters cracCreationParameters;
private final String regionEic;
private final Map<String, String> borderPerTso;
private final Map<String, String> borderPerEic;

public CsaProfileCnecCreator(Crac crac, Network network, CsaProfileCrac nativeCrac, CsaProfileCracCreationContext cracCreationContext, CracCreationParameters cracCreationParameters) {
this.crac = crac;
Expand All @@ -58,6 +61,8 @@ public CsaProfileCnecCreator(Crac crac, Network network, CsaProfileCrac nativeCr
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 Expand Up @@ -104,16 +109,16 @@ private void addCnec(AssessedElement nativeAssessedElement, Set<AssessedElementW

// If not, we check if it is defined with a ConductingEquipment instead, otherwise we ignore
if (limitType == null) {
new FlowCnecCreator(crac, network, nativeAssessedElement, null, combinableContingencies.stream().toList(), csaProfileCnecCreationContexts, cracCreationContext, rejectedLinksAssessedElementContingency, aeSecuredForRegion, aeScannedForRegion, cracCreationParameters).addFlowCnecs();
new FlowCnecCreator(crac, network, nativeAssessedElement, null, combinableContingencies.stream().toList(), csaProfileCnecCreationContexts, cracCreationContext, rejectedLinksAssessedElementContingency, aeSecuredForRegion, aeScannedForRegion, cracCreationParameters, borderPerTso, borderPerEic).addFlowCnecs();
return;
}

if (com.powsybl.openrao.data.cracio.csaprofiles.craccreator.constants.LimitType.CURRENT.equals(limitType)) {
new FlowCnecCreator(crac, network, nativeAssessedElement, nativeCurrentLimitPerId.get(nativeAssessedElement.operationalLimit()), combinableContingencies.stream().toList(), csaProfileCnecCreationContexts, cracCreationContext, rejectedLinksAssessedElementContingency, aeSecuredForRegion, aeScannedForRegion, cracCreationParameters).addFlowCnecs();
new FlowCnecCreator(crac, network, nativeAssessedElement, nativeCurrentLimitPerId.get(nativeAssessedElement.operationalLimit()), combinableContingencies.stream().toList(), csaProfileCnecCreationContexts, cracCreationContext, rejectedLinksAssessedElementContingency, aeSecuredForRegion, aeScannedForRegion, cracCreationParameters, borderPerTso, borderPerEic).addFlowCnecs();
} else if (com.powsybl.openrao.data.cracio.csaprofiles.craccreator.constants.LimitType.VOLTAGE.equals(limitType)) {
new VoltageCnecCreator(crac, network, nativeAssessedElement, nativeVoltageLimitPerId.get(nativeAssessedElement.operationalLimit()), combinableContingencies.stream().toList(), csaProfileCnecCreationContexts, cracCreationContext, rejectedLinksAssessedElementContingency, aeSecuredForRegion, aeScannedForRegion).addVoltageCnecs();
new VoltageCnecCreator(crac, network, nativeAssessedElement, nativeVoltageLimitPerId.get(nativeAssessedElement.operationalLimit()), combinableContingencies.stream().toList(), csaProfileCnecCreationContexts, cracCreationContext, rejectedLinksAssessedElementContingency, aeSecuredForRegion, aeScannedForRegion, borderPerTso, borderPerEic).addVoltageCnecs();
} else {
new AngleCnecCreator(crac, network, nativeAssessedElement, nativeVoltageAngleLimitPerId.get(nativeAssessedElement.operationalLimit()), combinableContingencies.stream().toList(), csaProfileCnecCreationContexts, cracCreationContext, rejectedLinksAssessedElementContingency, aeSecuredForRegion, aeScannedForRegion).addAngleCnecs();
new AngleCnecCreator(crac, network, nativeAssessedElement, nativeVoltageAngleLimitPerId.get(nativeAssessedElement.operationalLimit()), combinableContingencies.stream().toList(), csaProfileCnecCreationContexts, cracCreationContext, rejectedLinksAssessedElementContingency, aeSecuredForRegion, aeScannedForRegion, borderPerTso, borderPerEic).addAngleCnecs();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public class FlowCnecCreator extends AbstractCnecCreator {
private final FlowCnecInstantHelper instantHelper;
private final CurrentLimit nativeCurrentLimit;

public FlowCnecCreator(Crac crac, Network network, AssessedElement nativeAssessedElement, CurrentLimit nativeCurrentLimit, List<Contingency> linkedContingencies, Set<ElementaryCreationContext> csaProfileCnecCreationContexts, CsaProfileCracCreationContext cracCreationContext, String rejectedLinksAssessedElementContingency, boolean aeSecuredForRegion, boolean aeScannedForRegion, CracCreationParameters cracCreationParameters) {
super(crac, network, nativeAssessedElement, linkedContingencies, csaProfileCnecCreationContexts, cracCreationContext, rejectedLinksAssessedElementContingency, aeSecuredForRegion, aeScannedForRegion);
public FlowCnecCreator(Crac crac, Network network, AssessedElement nativeAssessedElement, CurrentLimit nativeCurrentLimit, List<Contingency> linkedContingencies, Set<ElementaryCreationContext> csaProfileCnecCreationContexts, CsaProfileCracCreationContext cracCreationContext, String rejectedLinksAssessedElementContingency, boolean aeSecuredForRegion, boolean aeScannedForRegion, CracCreationParameters cracCreationParameters, Map<String, String> borderPerTso, Map<String, String> borderPerEic) {
super(crac, network, nativeAssessedElement, linkedContingencies, csaProfileCnecCreationContexts, cracCreationContext, rejectedLinksAssessedElementContingency, aeSecuredForRegion, aeScannedForRegion, borderPerTso, borderPerEic);
this.defaultMonitoredSides = cracCreationParameters.getDefaultMonitoredSides();
this.nativeCurrentLimit = nativeCurrentLimit;
this.instantHelper = new FlowCnecInstantHelper(cracCreationParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.powsybl.openrao.data.cracio.commons.OpenRaoImportException;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
Expand All @@ -31,8 +32,8 @@ public class VoltageCnecCreator extends AbstractCnecCreator {

private final VoltageLimit nativeVoltageLimit;

public VoltageCnecCreator(Crac crac, Network network, AssessedElement nativeAssessedElement, VoltageLimit nativeVoltageLimit, List<Contingency> linkedContingencies, Set<ElementaryCreationContext> csaProfileCnecCreationContexts, CsaProfileCracCreationContext cracCreationContext, String rejectedLinksAssessedElementContingency, boolean aeSecuredForRegion, boolean aeScannedForRegion) {
super(crac, network, nativeAssessedElement, linkedContingencies, csaProfileCnecCreationContexts, cracCreationContext, rejectedLinksAssessedElementContingency, aeSecuredForRegion, aeScannedForRegion);
public VoltageCnecCreator(Crac crac, Network network, AssessedElement nativeAssessedElement, VoltageLimit nativeVoltageLimit, List<Contingency> linkedContingencies, Set<ElementaryCreationContext> csaProfileCnecCreationContexts, CsaProfileCracCreationContext cracCreationContext, String rejectedLinksAssessedElementContingency, boolean aeSecuredForRegion, boolean aeScannedForRegion, Map<String, String> borderPerTso, Map<String, String> borderPerEic) {
super(crac, network, nativeAssessedElement, linkedContingencies, csaProfileCnecCreationContexts, cracCreationContext, rejectedLinksAssessedElementContingency, aeSecuredForRegion, aeScannedForRegion, borderPerTso, borderPerEic);
this.nativeVoltageLimit = nativeVoltageLimit;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.openrao.data.cracio.csaprofiles.craccreator.constants;

/**
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
*/
public enum CsaBorder {
SPAIN_FRANCE("ES-FR", "10YDOM--ES-FR--D"),
SPAIN_PORTUGAL("ES-PT", "10YDOM--ES-PT--T");

private final String shortName;
private final String eiCode;

CsaBorder(String shortName, String eiCode) {
this.shortName = shortName;
this.eiCode = eiCode;
}

public String getShortName() {
return shortName;
}

public String getEiCode() {
return eiCode;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.openrao.data.cracio.csaprofiles.craccreator.constants;

/**
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
*/
public enum CsaOperator {
REE, REN, RTE
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ private CsaProfileConstants() {
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 OVERLAPPING_ZONE = "overlappingZone";

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 @@ -12,7 +12,7 @@
/**
* @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) implements IdentifiedObjectWithOperator {
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 static AssessedElement fromPropertyBag(PropertyBag propertyBag) {
return new AssessedElement(
propertyBag.getId(CsaProfileConstants.REQUEST_ASSESSED_ELEMENT),
Expand All @@ -26,7 +26,7 @@ public static AssessedElement fromPropertyBag(PropertyBag propertyBag) {
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),
propertyBag.get(CsaProfileConstants.REQUEST_FLOW_RELIABILITY_MARGIN) == null ? 0d : Double.parseDouble(propertyBag.get(CsaProfileConstants.REQUEST_FLOW_RELIABILITY_MARGIN))
);
propertyBag.get(CsaProfileConstants.REQUEST_FLOW_RELIABILITY_MARGIN) == null ? 0d : Double.parseDouble(propertyBag.get(CsaProfileConstants.REQUEST_FLOW_RELIABILITY_MARGIN)),
propertyBag.get(CsaProfileConstants.OVERLAPPING_ZONE));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.openrao.data.cracio.csaprofiles.parameters;

/**
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
*/
public record Border(String name, String eic, String defaultForTso) {
}
Loading
Loading