Skip to content

Commit

Permalink
Merge branch 'main' into csa/testing
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Mitri <peter.mitri@rte-france.com>
  • Loading branch information
pet-mit authored Jul 3, 2024
2 parents 45515a9 + 1a23e48 commit 4d4a53a
Show file tree
Hide file tree
Showing 329 changed files with 9,052 additions and 4,798 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import com.powsybl.openrao.data.cracapi.CracFactory;
import com.powsybl.openrao.data.cracapi.RaUsageLimits;
import com.powsybl.openrao.data.cracapi.cnec.Side;
import com.powsybl.iidm.network.TwoSides;
import com.google.common.base.Suppliers;
import com.powsybl.commons.config.PlatformConfig;
import com.powsybl.commons.extensions.AbstractExtendable;
Expand Down Expand Up @@ -42,17 +42,17 @@ public interface ConfigLoader<E extends Extension<CracCreationParameters>> exten
private String cracFactoryName = DEFAULT_CRAC_FACTORY_NAME;

public enum MonitoredLineSide {
MONITOR_LINES_ON_LEFT_SIDE(Set.of(Side.LEFT)),
MONITOR_LINES_ON_RIGHT_SIDE(Set.of(Side.RIGHT)),
MONITOR_LINES_ON_BOTH_SIDES(Set.of(Side.LEFT, Side.RIGHT));
MONITOR_LINES_ON_SIDE_ONE(Set.of(TwoSides.ONE)),
MONITOR_LINES_ON_SIDE_TWO(Set.of(TwoSides.TWO)),
MONITOR_LINES_ON_BOTH_SIDES(Set.of(TwoSides.ONE, TwoSides.TWO));

private final Set<Side> monitoredSides;
private final Set<TwoSides> monitoredSides;

MonitoredLineSide(Set<Side> monitoredSides) {
MonitoredLineSide(Set<TwoSides> monitoredSides) {
this.monitoredSides = monitoredSides;
}

Set<Side> getMonitoredSides() {
Set<TwoSides> getMonitoredSides() {
return monitoredSides;
}
}
Expand Down Expand Up @@ -88,7 +88,7 @@ public CracFactory getCracFactory() {
return CracFactory.find(cracFactoryName);
}

public Set<Side> getDefaultMonitoredSides() {
public Set<TwoSides> getDefaultMonitoredSides() {
return defaultMonitoredLineSide.getMonitoredSides();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public final class JsonCracCreationParametersConstants {

static final String DEFAULT_MONITORED_LINE_SIDE = "default-monitored-line-side";
private static final String MONITOR_LINES_ON_LEFT_SIDE_TEXT = "monitor-lines-on-left-side";
private static final String MONITOR_LINES_ON_SIDE_ONE_TEXT = "monitor-lines-on-side-one";
private static final String MONITOR_LINES_ON_RIGHT_SIDE_TEXT = "monitor-lines-on-right-side";
private static final String MONITOR_LINES_ON_SIDE_TWO_TEXT = "monitor-lines-on-side-two";
private static final String MONITOR_LINES_ON_BOTH_SIDES_TEXT = "monitor-lines-on-both-sides";
public static final String RA_USAGE_LIMITS_PER_INSTANT = "ra-usage-limits-per-instant";
public static final String INSTANT = "instant";
Expand All @@ -42,29 +44,23 @@ private JsonCracCreationParametersConstants() {
}

static String serializeMonitoredLineSide(CracCreationParameters.MonitoredLineSide monitoredLineSide) {
switch (monitoredLineSide) {
case MONITOR_LINES_ON_LEFT_SIDE:
return MONITOR_LINES_ON_LEFT_SIDE_TEXT;
case MONITOR_LINES_ON_RIGHT_SIDE:
return MONITOR_LINES_ON_RIGHT_SIDE_TEXT;
case MONITOR_LINES_ON_BOTH_SIDES:
return MONITOR_LINES_ON_BOTH_SIDES_TEXT;
default:
throw new OpenRaoException(String.format("Unknown monitored line side: %s", monitoredLineSide));
}
return switch (monitoredLineSide) {
case MONITOR_LINES_ON_SIDE_ONE -> MONITOR_LINES_ON_SIDE_ONE_TEXT;
case MONITOR_LINES_ON_SIDE_TWO -> MONITOR_LINES_ON_SIDE_TWO_TEXT;
case MONITOR_LINES_ON_BOTH_SIDES -> MONITOR_LINES_ON_BOTH_SIDES_TEXT;
};
}

static CracCreationParameters.MonitoredLineSide deserializeMonitoredLineSide(String monitoredLineSide) {
switch (monitoredLineSide) {
case MONITOR_LINES_ON_LEFT_SIDE_TEXT:
return CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_LEFT_SIDE;
case MONITOR_LINES_ON_RIGHT_SIDE_TEXT:
return CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_RIGHT_SIDE;
case MONITOR_LINES_ON_BOTH_SIDES_TEXT:
return CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_BOTH_SIDES;
default:
throw new OpenRaoException(String.format("Unknown monitored line side: %s", monitoredLineSide));
}
return switch (monitoredLineSide) {
case MONITOR_LINES_ON_SIDE_ONE_TEXT, MONITOR_LINES_ON_LEFT_SIDE_TEXT ->
CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_ONE;
case MONITOR_LINES_ON_SIDE_TWO_TEXT, MONITOR_LINES_ON_RIGHT_SIDE_TEXT ->
CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_TWO;
case MONITOR_LINES_ON_BOTH_SIDES_TEXT ->
CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_BOTH_SIDES;
default -> throw new OpenRaoException(String.format("Unknown monitored line side: %s", monitoredLineSide));
};
}

static void serializeRaUsageLimits(CracCreationParameters parameters, JsonGenerator jsonGenerator) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import com.powsybl.openrao.data.cracapi.Crac;
import com.powsybl.openrao.data.cracapi.InstantKind;
import com.powsybl.openrao.data.cracapi.cnec.Side;
import com.powsybl.iidm.network.TwoSides;
import com.powsybl.openrao.data.craccreation.creator.api.CracCreator;
import com.powsybl.openrao.data.craccreation.creator.api.parameters.CracCreationParameters;
import com.powsybl.openrao.data.craccreation.creator.cim.CimCrac;
Expand Down Expand Up @@ -98,7 +98,7 @@ private void createContingencies() {
new CimContingencyCreator(cimTimeSeries, crac, network, creationContext).createAndAddContingencies();
}

private void createCnecs(Set<Side> defaultMonitoredSides) {
private void createCnecs(Set<TwoSides> defaultMonitoredSides) {
new MonitoredSeriesCreator(cimTimeSeries, network, creationContext, defaultMonitoredSides).createAndAddMonitoredSeries();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
import com.powsybl.openrao.data.cracapi.Instant;
import com.powsybl.openrao.data.cracapi.InstantKind;
import com.powsybl.openrao.data.cracapi.cnec.FlowCnecAdder;
import com.powsybl.openrao.data.cracapi.cnec.Side;
import com.powsybl.iidm.network.TwoSides;
import com.powsybl.openrao.data.craccreation.creator.api.ImportStatus;
import com.powsybl.openrao.data.craccreation.creator.cim.craccreator.CimCracCreationContext;
import com.powsybl.openrao.data.craccreation.creator.cim.craccreator.CimCracUtils;
import com.powsybl.openrao.data.craccreation.creator.cim.xsd.*;
import com.powsybl.openrao.data.craccreation.util.cgmes.CgmesBranchHelper;
import com.powsybl.iidm.network.Branch;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.TwoSides;
import org.apache.commons.lang3.StringUtils;

import java.util.*;
Expand All @@ -41,9 +40,9 @@ public class MonitoredSeriesCreator {
private final List<TimeSeries> cimTimeSeries;
private Map<String, MonitoredSeriesCreationContext> monitoredSeriesCreationContexts;
private final CimCracCreationContext cracCreationContext;
private final Set<Side> defaultMonitoredSides;
private final Set<TwoSides> defaultMonitoredSides;

public MonitoredSeriesCreator(List<TimeSeries> cimTimeSeries, Network network, CimCracCreationContext cracCreationContext, Set<Side> defaultMonitoredSides) {
public MonitoredSeriesCreator(List<TimeSeries> cimTimeSeries, Network network, CimCracCreationContext cracCreationContext, Set<TwoSides> defaultMonitoredSides) {
this.cimTimeSeries = cimTimeSeries;
this.crac = cracCreationContext.getCrac();
this.network = network;
Expand Down Expand Up @@ -301,7 +300,7 @@ private void addCnecsOnContingency(String cnecNativeId, CgmesBranchHelper branch
// If a CNEC with the same ID has already been created, we assume that the 2 CNECs are the same
// (we know network element and state are the same, we assume that thresholds are the same.
// This is true if the TSO is consistent in the definition of its CNECs; and two different TSOs can only
// share tielines, but those are distinguished by the RIGHT/LEFT label)
// share tielines, but those are distinguished by the TWO/ONE label)
cracCreationContext.getCreationReport().warn(
String.format("Multiple CNECs on same network element (%s) and same state (%s%s%s) have been detected. Only one CNEC will be created.", branchHelper.getBranch().getId(), contingencyId, Objects.isNull(contingency) ? "" : " - ", instant)
);
Expand All @@ -312,18 +311,18 @@ private void addCnecsOnContingency(String cnecNativeId, CgmesBranchHelper branch
private String addThreshold(FlowCnecAdder flowCnecAdder, Unit unit, CgmesBranchHelper branchHelper, String cnecId, String direction, double threshold) {
String modifiedCnecId = cnecId;

Set<Side> monitoredSides = defaultMonitoredSides;
Set<TwoSides> monitoredSides = defaultMonitoredSides;
if (branchHelper.isHalfLine()) {
modifiedCnecId += " - " + (branchHelper.getTieLineSide() == TwoSides.ONE ? "LEFT" : "RIGHT");
monitoredSides = Set.of(Side.fromIidmSide(branchHelper.getTieLineSide()));
modifiedCnecId += " - " + (branchHelper.getTieLineSide() == TwoSides.ONE ? "ONE" : "TWO");
monitoredSides = Set.of(branchHelper.getTieLineSide());
} else if (unit.equals(Unit.AMPERE) &&
Math.abs(branchHelper.getBranch().getTerminal1().getVoltageLevel().getNominalV() - branchHelper.getBranch().getTerminal2().getVoltageLevel().getNominalV()) > 1.) {
// If unit is absolute amperes, monitor low voltage side
monitoredSides = branchHelper.getBranch().getTerminal1().getVoltageLevel().getNominalV() <= branchHelper.getBranch().getTerminal2().getVoltageLevel().getNominalV() ?
Set.of(Side.LEFT) : Set.of(Side.RIGHT);
Set.of(TwoSides.ONE) : Set.of(TwoSides.TWO);
} else if (unit.equals(Unit.PERCENT_IMAX)) {
// If unit is %Imax, check that Imax exists
monitoredSides = monitoredSides.stream().filter(side -> hasCurrentLimit(branchHelper.getBranch(), side.iidmSide())).collect(Collectors.toSet());
monitoredSides = monitoredSides.stream().filter(side -> hasCurrentLimit(branchHelper.getBranch(), side)).collect(Collectors.toSet());
if (monitoredSides.isEmpty()) {
throw new OpenRaoException(String.format("Cannot create any PERCENT_IMAX threshold on branch %s, as it holds no current limit at the wanted side", branchHelper.getIdInNetwork()));
}
Expand All @@ -343,7 +342,7 @@ private String addThreshold(FlowCnecAdder flowCnecAdder, Unit unit, CgmesBranchH
return modifiedCnecId;
}

private void addThreshold(FlowCnecAdder flowCnecAdder, Unit unit, Double min, Double max, Set<Side> sides) {
private void addThreshold(FlowCnecAdder flowCnecAdder, Unit unit, Double min, Double max, Set<TwoSides> sides) {
sides.forEach(side ->
flowCnecAdder.newThreshold()
.withUnit(unit)
Expand All @@ -358,8 +357,8 @@ private void setNominalVoltage(FlowCnecAdder flowCnecAdder, CgmesBranchHelper br
double voltageLevelLeft = branchHelper.getBranch().getTerminal1().getVoltageLevel().getNominalV();
double voltageLevelRight = branchHelper.getBranch().getTerminal2().getVoltageLevel().getNominalV();
if (voltageLevelLeft > 1e-6 && voltageLevelRight > 1e-6) {
flowCnecAdder.withNominalVoltage(voltageLevelLeft, Side.LEFT);
flowCnecAdder.withNominalVoltage(voltageLevelRight, Side.RIGHT);
flowCnecAdder.withNominalVoltage(voltageLevelLeft, TwoSides.ONE);
flowCnecAdder.withNominalVoltage(voltageLevelRight, TwoSides.TWO);
} else {
throw new OpenRaoException(String.format("Voltage level for branch %s is 0 in network.", branchHelper.getBranch().getId()));
}
Expand All @@ -369,8 +368,8 @@ private void setCurrentsLimit(FlowCnecAdder flowCnecAdder, CgmesBranchHelper bra
Double currentLimitLeft = getCurrentLimit(branchHelper.getBranch(), TwoSides.ONE);
Double currentLimitRight = getCurrentLimit(branchHelper.getBranch(), TwoSides.TWO);
if (Objects.nonNull(currentLimitLeft) && Objects.nonNull(currentLimitRight)) {
flowCnecAdder.withIMax(currentLimitLeft, Side.LEFT);
flowCnecAdder.withIMax(currentLimitRight, Side.RIGHT);
flowCnecAdder.withIMax(currentLimitLeft, TwoSides.ONE);
flowCnecAdder.withIMax(currentLimitRight, TwoSides.TWO);
} else {
throw new OpenRaoException(String.format("Unable to get branch current limits from network for branch %s", branchHelper.getBranch().getId()));
}
Expand Down
Loading

0 comments on commit 4d4a53a

Please sign in to comment.