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

Add DecomposedFlow rescaler proportional to max AC current load #156

Merged
merged 18 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -7,12 +7,14 @@
package com.powsybl.flow_decomposition;

import com.powsybl.iidm.network.Country;
import com.powsybl.iidm.network.CurrentLimits;

import java.util.*;

/**
* @author Sebastien Murgey {@literal <sebastien.murgey at rte-france.com>}
* @author Hugo Schindler {@literal <hugo.schindler at rte-france.com>}
* @author Caio Luke {@literal <caio.luke at artelys.com>}
*/
public class DecomposedFlow {
private final String branchId;
Expand All @@ -26,6 +28,12 @@ public class DecomposedFlow {
private final double xNodeFlow;
private final double pstFlow;
private final double internalFlow;
private final double acTerminal1Current;
private final double acTerminal2Current;
private final double nominalVoltageTerminal1;
private final double nominalVoltageTerminal2;
private final CurrentLimits currentLimitsTerminal1;
private final CurrentLimits currentLimitsTerminal2;
OpenSuze marked this conversation as resolved.
Show resolved Hide resolved
private final Map<String, Double> loopFlowsMap = new TreeMap<>();
static final double NO_FLOW = 0.;
static final String AC_REFERENCE_FLOW_1_COLUMN_NAME = "Reference AC Flow 1";
Expand All @@ -49,6 +57,12 @@ protected DecomposedFlow(DecomposedFlowBuilder builder) {
this.pstFlow = builder.pstFlow;
this.internalFlow = builder.internalFlow;
this.loopFlowsMap.putAll(Objects.requireNonNull(builder.loopFlowsMap));
this.acTerminal1Current = builder.acCurrentTerminal1;
this.acTerminal2Current = builder.acCurrentTerminal2;
this.nominalVoltageTerminal1 = builder.nominalVoltageTerminal1;
this.nominalVoltageTerminal2 = builder.nominalVoltageTerminal2;
this.currentLimitsTerminal1 = builder.currentLimitsTerminal1;
this.currentLimitsTerminal2 = builder.currentLimitsTerminal2;
OpenSuze marked this conversation as resolved.
Show resolved Hide resolved
}

public String getBranchId() {
Expand Down Expand Up @@ -123,6 +137,30 @@ public double getMaxAbsAcFlow() {
return Math.max(Math.abs(acTerminal1ReferenceFlow), Math.abs(acTerminal2ReferenceFlow));
}

public double getAcTerminal1Current() {
return acTerminal1Current;
}

public double getAcTerminal2Current() {
return acTerminal2Current;
}

public double getNominalVoltageTerminal1() {
return nominalVoltageTerminal1;
}

public double getNominalVoltageTerminal2() {
return nominalVoltageTerminal2;
}

public CurrentLimits getCurrentLimitsTerminal1() {
return currentLimitsTerminal1;
}

public CurrentLimits getCurrentLimitsTerminal2() {
return currentLimitsTerminal2;
}

OpenSuze marked this conversation as resolved.
Show resolved Hide resolved
@Override
public String toString() {
return String.format("branchId: %s, contingencyId: %s, decomposition: %s", branchId, contingencyId, getAllKeyMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.powsybl.flow_decomposition;

import com.powsybl.iidm.network.Country;
import com.powsybl.iidm.network.CurrentLimits;

import java.util.Map;

Expand All @@ -28,6 +29,12 @@ public class DecomposedFlowBuilder {
protected double pstFlow;
protected double internalFlow;
protected Map<String, Double> loopFlowsMap;
protected double acCurrentTerminal1;
protected double acCurrentTerminal2;
protected double nominalVoltageTerminal1;
protected double nominalVoltageTerminal2;
protected CurrentLimits currentLimitsTerminal1;
protected CurrentLimits currentLimitsTerminal2;
OpenSuze marked this conversation as resolved.
Show resolved Hide resolved

public DecomposedFlowBuilder() {
// empty constructor
Expand Down Expand Up @@ -63,6 +70,16 @@ public DecomposedFlowBuilder withAcTerminal2ReferenceFlow(double acTerminal2Refe
return this;
}

public DecomposedFlowBuilder withNominalVoltageTerminal1(double nominalVoltageTerminal1) {
this.nominalVoltageTerminal1 = nominalVoltageTerminal1;
return this;
}

public DecomposedFlowBuilder withNominalVoltageTerminal2(double nominalVoltageTerminal2) {
this.nominalVoltageTerminal2 = nominalVoltageTerminal2;
return this;
}

public DecomposedFlowBuilder withDcReferenceFlow(double dcReferenceFlow) {
this.dcReferenceFlow = dcReferenceFlow;
return this;
Expand Down Expand Up @@ -93,6 +110,26 @@ public DecomposedFlowBuilder withLoopFlowsMap(Map<String, Double> loopFlowsMap)
return this;
}

public DecomposedFlowBuilder withAcCurrentTerminal1(double acCurrentTerminal1) {
this.acCurrentTerminal1 = acCurrentTerminal1;
return this;
}

public DecomposedFlowBuilder withAcCurrentTerminal2(double acCurrentTerminal2) {
this.acCurrentTerminal2 = acCurrentTerminal2;
return this;
}

public DecomposedFlowBuilder withCurrentLimitsTerminal1(CurrentLimits currentLimitsTerminal1) {
this.currentLimitsTerminal1 = currentLimitsTerminal1;
return this;
}

public DecomposedFlowBuilder withCurrentLimitsTerminal2(CurrentLimits currentLimitsTerminal2) {
this.currentLimitsTerminal2 = currentLimitsTerminal2;
return this;
}

OpenSuze marked this conversation as resolved.
Show resolved Hide resolved
public DecomposedFlow build() {
return new DecomposedFlow(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.powsybl.iidm.network.Branch;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.TwoSides;
import org.apache.commons.lang3.tuple.Pair;

import java.util.Collection;
import java.util.Map;
Expand All @@ -34,11 +35,56 @@ public static Map<String, Double> calculateAcTerminalReferenceFlows(Collection<B
return getTerminalReferenceFlow(xnecList, side);
}

public static Map<String, Pair<Double, Double>> getBothTerminalsReferenceFlowsAc(Collection<Branch> xnecList, LoadFlowRunningService.Result loadFlowServiceAcResult) {
OpenSuze marked this conversation as resolved.
Show resolved Hide resolved
if (loadFlowServiceAcResult.fallbackHasBeenActivated()) {
return xnecList.stream().collect(Collectors.toMap(Identifiable::getId, branch -> Pair.of(Double.NaN, Double.NaN)));
OpenSuze marked this conversation as resolved.
Show resolved Hide resolved
}
return getBothTerminalsReferenceFlows(xnecList);
}

public static Map<String, Double> getTerminalReferenceFlow(Collection<Branch> xnecList, TwoSides side) {
return xnecList.stream()
.collect(Collectors.toMap(
Identifiable::getId,
branch -> branch.getTerminal(side).getP()
));
}

public static Map<String, Pair<Double, Double>> getBothTerminalsReferenceFlows(Collection<Branch> xnecList) {
return xnecList.stream()
.collect(Collectors.toMap(
Identifiable::getId,
branch -> Pair.of(branch.getTerminal1().getP(), branch.getTerminal2().getP())
));
}

public static Map<String, Double> calculateAcTerminalCurrents(Collection<Branch> xnecList, LoadFlowRunningService.Result loadFlowServiceAcResult, TwoSides side) {
if (loadFlowServiceAcResult.fallbackHasBeenActivated()) {
return xnecList.stream().collect(Collectors.toMap(Identifiable::getId, branch -> Double.NaN));
}
return getTerminalCurrent(xnecList, side);
}

public static Map<String, Pair<Double, Double>> getBothTerminalsCurrentsAc(Collection<Branch> xnecList, LoadFlowRunningService.Result loadFlowServiceAcResult) {
if (loadFlowServiceAcResult.fallbackHasBeenActivated()) {
return xnecList.stream().collect(Collectors.toMap(Identifiable::getId, branch -> Pair.of(Double.NaN, Double.NaN)));
OpenSuze marked this conversation as resolved.
Show resolved Hide resolved
}
return getBothTerminalsCurrents(xnecList);
}

public static Map<String, Double> getTerminalCurrent(Collection<Branch> xnecList, TwoSides side) {
return xnecList.stream()
.collect(Collectors.toMap(
Identifiable::getId,
branch -> branch.getTerminal(side).getI()
));
}

public static Map<String, Pair<Double, Double>> getBothTerminalsCurrents(Collection<Branch> xnecList) {
return xnecList.stream()
.collect(Collectors.toMap(
Identifiable::getId,
branch -> Pair.of(branch.getTerminal1().getI(), branch.getTerminal2().getI())
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

import com.powsybl.commons.PowsyblException;
import com.powsybl.flow_decomposition.glsk_provider.AutoGlskProvider;
import com.powsybl.flow_decomposition.rescaler.DecomposedFlowRescaler;
import com.powsybl.flow_decomposition.rescaler.DecomposedFlowRescalerAcerMethodology;
import com.powsybl.flow_decomposition.rescaler.DecomposedFlowRescalerNoOp;
import com.powsybl.flow_decomposition.rescaler.DecomposedFlowRescalerProportional;
import com.powsybl.flow_decomposition.rescaler.*;
import com.powsybl.iidm.network.Branch;
import com.powsybl.iidm.network.Country;
import com.powsybl.iidm.network.Network;
Expand Down Expand Up @@ -143,6 +140,7 @@ private void decomposeFlowForState(Network network,
LoadFlowRunningService.Result loadFlowServiceAcResult) {
// AC load flow
saveAcReferenceFlows(flowDecompositionResultsBuilder, network, xnecList, loadFlowServiceAcResult);
saveAcCurrents(flowDecompositionResultsBuilder, network, xnecList, loadFlowServiceAcResult);

// Losses compensation
compensateLosses(network);
Expand All @@ -165,7 +163,7 @@ private void decomposeFlowForState(Network network,
computeAllocatedAndLoopFlows(flowDecompositionResultsBuilder, nodalInjectionsMatrix, ptdfMatrix);
computePstFlows(network, flowDecompositionResultsBuilder, networkMatrixIndexes, psdfMatrix);

flowDecompositionResultsBuilder.build(decomposedFlowRescaler);
flowDecompositionResultsBuilder.build(decomposedFlowRescaler, network);
}

public void addObserver(FlowDecompositionObserver observer) {
Expand All @@ -189,6 +187,14 @@ private void saveAcReferenceFlows(FlowDecompositionResults.PerStateBuilder flowD
observers.computedAcNodalInjections(network, loadFlowServiceAcResult.fallbackHasBeenActivated());
}

private void saveAcCurrents(FlowDecompositionResults.PerStateBuilder flowDecompositionResultBuilder, Network network, Set<Branch> xnecList, LoadFlowRunningService.Result loadFlowServiceAcResult) {
Map<String, Double> acTerminal1Currents = FlowComputerUtils.calculateAcTerminalCurrents(xnecList, loadFlowServiceAcResult, TwoSides.ONE);
Map<String, Double> acTerminal2Currents = FlowComputerUtils.calculateAcTerminalCurrents(xnecList, loadFlowServiceAcResult, TwoSides.TWO);
flowDecompositionResultBuilder.saveAcCurrentTerminal1(acTerminal1Currents);
flowDecompositionResultBuilder.saveAcCurrentTerminal2(acTerminal2Currents);
observers.computedAcCurrents(network, loadFlowServiceAcResult);
}

private Map<Country, Double> getZonesNetPosition(Network network) {
NetPositionComputer netPositionComputer = new NetPositionComputer();
return netPositionComputer.run(network);
Expand All @@ -205,6 +211,7 @@ private DecomposedFlowRescaler getDecomposedFlowRescaler() {
case NONE -> new DecomposedFlowRescalerNoOp();
case ACER_METHODOLOGY -> new DecomposedFlowRescalerAcerMethodology();
case PROPORTIONAL -> new DecomposedFlowRescalerProportional(parameters.getProportionalRescalerMinFlowTolerance());
case MAX_CURRENT_OVERLOAD -> new DecomposedFlowRescalerMaxCurrentOverload(parameters.getProportionalRescalerMinFlowTolerance());
default -> throw new PowsyblException("DecomposedFlowRescaler not defined for mode: " + parameters.getRescaleMode());
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.powsybl.flow_decomposition;

import com.powsybl.iidm.network.Country;
import org.apache.commons.lang3.tuple.Pair;

import java.util.Map;

Expand Down Expand Up @@ -93,12 +94,19 @@ public interface FlowDecompositionObserver {
*
* @param flows the flows for all branches
*/
void computedAcFlows(Map<String, Double> flows);
void computedAcFlows(Map<String, Pair<Double, Double>> flows);

/**
* Called when the DC loadflow is computed (for base case or contingency)
*
* @param flows the flows for all branches
*/
void computedDcFlows(Map<String, Double> flows);
void computedDcFlows(Map<String, Pair<Double, Double>> flows);

/**
* Called when the AC loadflow is computed (for base case or contingency)
*
* @param currents the currents for all branches
*/
void computedAcCurrents(Map<String, Pair<Double, Double>> currents);
OpenSuze marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.powsybl.flow_decomposition.LoadFlowRunningService.Result;
import com.powsybl.iidm.network.Country;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.TwoSides;
import org.apache.commons.lang3.tuple.Pair;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -88,7 +88,7 @@ public void computedAcFlows(Network network, Result loadFlowServiceAcResult) {
return;
}

Map<String, Double> acFlows = FlowComputerUtils.calculateAcTerminalReferenceFlows(network.getBranchStream().toList(), loadFlowServiceAcResult, TwoSides.ONE);
Map<String, Pair<Double, Double>> acFlows = FlowComputerUtils.getBothTerminalsReferenceFlowsAc(network.getBranchStream().toList(), loadFlowServiceAcResult);

for (FlowDecompositionObserver o : observers) {
o.computedAcFlows(acFlows);
Expand All @@ -100,13 +100,25 @@ public void computedDcFlows(Network network) {
return;
}

Map<String, Double> dcFlows = FlowComputerUtils.getTerminalReferenceFlow(network.getBranchStream().toList(), TwoSides.ONE);
Map<String, Pair<Double, Double>> dcFlows = FlowComputerUtils.getBothTerminalsReferenceFlows(network.getBranchStream().toList());

for (FlowDecompositionObserver o : observers) {
o.computedDcFlows(dcFlows);
}
}

public void computedAcCurrents(Network network, Result loadFlowServiceAcResult) {
if (observers.isEmpty()) {
return;
}

Map<String, Pair<Double, Double>> acCurrents = FlowComputerUtils.getBothTerminalsCurrentsAc(network.getBranchStream().toList(), loadFlowServiceAcResult);

for (FlowDecompositionObserver o : observers) {
o.computedAcCurrents(acCurrents);
}
}

public void computedAcNodalInjections(Network network, boolean fallbackHasBeenActivated) {
if (observers.isEmpty()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public class FlowDecompositionParameters {
public enum RescaleMode {
NONE,
ACER_METHODOLOGY,
PROPORTIONAL
PROPORTIONAL,
MAX_CURRENT_OVERLOAD
}

public static final RescaleMode DEFAULT_RESCALE_MODE = RescaleMode.NONE;
Expand Down
Loading
Loading