com.farao_community.farao.data.crac_impl.HvdcRangeActionImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of farao-crac-impl Show documentation
Show all versions of farao-crac-impl Show documentation
Object model for CRAC implementation
/*
* Copyright (c) 2021, 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.farao_community.farao.data.crac_impl;
import com.farao_community.farao.commons.FaraoException;
import com.farao_community.farao.data.crac_api.NetworkElement;
import com.farao_community.farao.data.crac_api.range.StandardRange;
import com.farao_community.farao.data.crac_api.range_action.HvdcRangeAction;
import com.farao_community.farao.data.crac_api.usage_rule.UsageRule;
import com.powsybl.iidm.network.HvdcLine;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.extensions.HvdcAngleDroopActivePowerControl;
import org.apache.commons.lang3.NotImplementedException;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import static com.farao_community.farao.commons.logs.FaraoLoggerProvider.TECHNICAL_LOGS;
/**
* Elementary HVDC range remedial action.
*
* @author Godelaine de Montmorillon {@literal }
* @author Baptiste Seguinot {@literal }
*/
public class HvdcRangeActionImpl extends AbstractRangeAction implements HvdcRangeAction {
private final NetworkElement networkElement;
private final List ranges;
private final double initialSetpoint;
HvdcRangeActionImpl(String id, String name, String operator, List usageRules, List ranges,
double initialSetpoint, NetworkElement networkElement, String groupId, Integer speed) {
super(id, name, operator, usageRules, groupId, speed);
this.networkElement = networkElement;
this.ranges = ranges;
this.initialSetpoint = initialSetpoint;
}
@Override
public NetworkElement getNetworkElement() {
return networkElement;
}
@Override
public List getRanges() {
return ranges;
}
@Override
public Set getNetworkElements() {
return Collections.singleton(networkElement);
}
@Override
public double getMinAdmissibleSetpoint(double previousInstantSetPoint) {
double minAdmissibleSetpoint = Double.NEGATIVE_INFINITY;
for (StandardRange range : ranges) {
switch (range.getRangeType()) {
case ABSOLUTE:
minAdmissibleSetpoint = Math.max(minAdmissibleSetpoint, range.getMin());
break;
case RELATIVE_TO_INITIAL_NETWORK:
minAdmissibleSetpoint = Math.max(minAdmissibleSetpoint, initialSetpoint + range.getMin());
break;
case RELATIVE_TO_PREVIOUS_INSTANT:
minAdmissibleSetpoint = Math.max(minAdmissibleSetpoint, previousInstantSetPoint + range.getMin());
break;
default:
throw new NotImplementedException("Range Action type is not implemented yet.");
}
}
return minAdmissibleSetpoint;
}
@Override
public double getMaxAdmissibleSetpoint(double previousInstantSetPoint) {
double maxAdmissibleSetpoint = Double.POSITIVE_INFINITY;
for (StandardRange range : ranges) {
switch (range.getRangeType()) {
case ABSOLUTE:
maxAdmissibleSetpoint = Math.min(maxAdmissibleSetpoint, range.getMax());
break;
case RELATIVE_TO_INITIAL_NETWORK:
maxAdmissibleSetpoint = Math.min(maxAdmissibleSetpoint, initialSetpoint + range.getMax());
break;
case RELATIVE_TO_PREVIOUS_INSTANT:
maxAdmissibleSetpoint = Math.min(maxAdmissibleSetpoint, previousInstantSetPoint + range.getMax());
break;
default:
throw new NotImplementedException("Range Action type is not implemented yet.");
}
}
return maxAdmissibleSetpoint;
}
@Override
public double getInitialSetpoint() {
return initialSetpoint;
}
@Override
public void apply(Network network, double targetSetpoint) {
findAndDisableHvdcAngleDroopActivePowerControl(network);
if (targetSetpoint < 0) {
getHvdcLine(network).setConvertersMode(HvdcLine.ConvertersMode.SIDE_1_INVERTER_SIDE_2_RECTIFIER);
} else {
getHvdcLine(network).setConvertersMode(HvdcLine.ConvertersMode.SIDE_1_RECTIFIER_SIDE_2_INVERTER);
}
getHvdcLine(network).setActivePowerSetpoint(Math.abs(targetSetpoint));
}
public void findAndDisableHvdcAngleDroopActivePowerControl(Network network) {
if (isAngleDroopActivePowerControlEnabled(network)) {
HvdcLine hvdcLine = getHvdcLine(network);
TECHNICAL_LOGS.debug("Disabling HvdcAngleDroopActivePowerControl on HVDC line {}", hvdcLine.getId());
hvdcLine.getExtension(HvdcAngleDroopActivePowerControl.class).setEnabled(false);
}
}
public boolean isAngleDroopActivePowerControlEnabled(Network network) {
HvdcAngleDroopActivePowerControl hvdcAngleDroopActivePowerControl = getHvdcLine(network).getExtension(HvdcAngleDroopActivePowerControl.class);
return (hvdcAngleDroopActivePowerControl != null) && hvdcAngleDroopActivePowerControl.isEnabled();
}
private HvdcLine getHvdcLine(Network network) {
HvdcLine hvdcLine = network.getHvdcLine(networkElement.getId());
if (hvdcLine == null) {
throw new FaraoException(String.format("HvdcLine %s does not exist in the current network.", networkElement.getId()));
}
return hvdcLine;
}
@Override
public double getCurrentSetpoint(Network network) {
if (getHvdcLine(network).getConvertersMode() == HvdcLine.ConvertersMode.SIDE_1_RECTIFIER_SIDE_2_INVERTER) {
return getHvdcLine(network).getActivePowerSetpoint();
} else {
return -getHvdcLine(network).getActivePowerSetpoint();
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
return this.networkElement.equals(((HvdcRangeAction) o).getNetworkElement())
&& this.ranges.equals(((HvdcRangeAction) o).getRanges());
}
@Override
public int hashCode() {
int hashCode = super.hashCode();
for (StandardRange range : ranges) {
hashCode += 31 * range.hashCode();
}
hashCode += 31 * networkElement.hashCode();
return hashCode;
}
}