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

[Draft] Improve fast DC AS performances #1169

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
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 @@ -68,7 +68,11 @@ protected AbstractClosedBranchDcFlowEquationTerm(LfBranch branch, LfBus bus1, Lf
* Update power only if the branch is a PiModelArray.
*/
protected double getPower() {
return isPowerPreComputed ? power : computePower(useTransformerRatio, dcApproximationType, element.getPiModel());
return getPower(element.getPiModel());
}

protected double getPower(PiModel piModel) {
return isPowerPreComputed ? power : computePower(useTransformerRatio, dcApproximationType, piModel);
}

public static double computePower(boolean useTransformerRatio, DcApproximationType dcApproximationType, PiModel piModel) {
Expand Down Expand Up @@ -117,7 +121,15 @@ protected double ph2() {
return ph2(sv);
}

protected abstract double eval(double ph1, double ph2, double a1);
protected double eval(double ph1, double ph2, double a1) {
return eval(ph1, ph2, a1, element.getPiModel());
}

protected abstract double eval(double ph1, double ph2, double a1, PiModel piModel);

public double eval(StateVector sv, PiModel piModel) {
return eval(ph1(sv), ph2(sv), a1(sv), piModel);
}

@Override
public double eval() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.powsybl.openloadflow.equations.VariableSet;
import com.powsybl.openloadflow.network.LfBranch;
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.network.PiModel;

import java.util.Objects;

Expand All @@ -36,9 +37,9 @@ public static ClosedBranchSide1DcFlowEquationTerm create(LfBranch branch, LfBus
}

@Override
protected double eval(double ph1, double ph2, double a1) {
protected double eval(double ph1, double ph2, double a1, PiModel piModel) {
double deltaPhase = ph2 - ph1 + A2 - a1;
return -getPower() * deltaPhase;
return -getPower(piModel) * deltaPhase;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.powsybl.openloadflow.equations.VariableSet;
import com.powsybl.openloadflow.network.LfBranch;
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.network.PiModel;

import java.util.Objects;

Expand All @@ -36,9 +37,9 @@ public static ClosedBranchSide2DcFlowEquationTerm create(LfBranch branch, LfBus
}

@Override
protected double eval(double ph1, double ph2, double a1) {
protected double eval(double ph1, double ph2, double a1, PiModel piModel) {
double deltaPhase = ph2 - ph1 + A2 - a1;
return getPower() * deltaPhase;
return getPower(piModel) * deltaPhase;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
import com.powsybl.openloadflow.dc.equations.DcVariableType;
import com.powsybl.openloadflow.equations.EquationSystem;
import com.powsybl.openloadflow.graph.GraphConnectivity;
import com.powsybl.openloadflow.network.ElementType;
import com.powsybl.openloadflow.network.LfBranch;
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.network.LfNetwork;
import com.powsybl.openloadflow.network.*;
import com.powsybl.openloadflow.network.impl.PropagatedContingency;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -38,31 +35,38 @@ public final class ConnectivityBreakAnalysis {

public static final class ConnectivityAnalysisResult {

private PropagatedContingency contingency;
private final PropagatedContingency propagatedContingency;

private final LfNetwork network;

private final Set<String> elementsToReconnect;

private final Set<LfBus> disabledBuses;

private final Set<LfBus> slackConnectedComponent;
private final Set<LfBus> slackConnectedComponentBuses; // buses of connected component where the slack is

private final Set<LfBranch> partialDisabledBranches; // branches disabled because of connectivity loss.

private ConnectivityAnalysisResult(Set<String> elementsToReconnect,
GraphConnectivity<LfBus, LfBranch> connectivity,
LfNetwork lfNetwork) {
this.elementsToReconnect = elementsToReconnect;
slackConnectedComponent = connectivity.getConnectedComponent(lfNetwork.getSlackBus());
disabledBuses = connectivity.getVerticesRemovedFromMainComponent();
partialDisabledBranches = connectivity.getEdgesRemovedFromMainComponent();
private final int createdSynchronousComponents;

public ConnectivityAnalysisResult(PropagatedContingency propagatedContingency, LfNetwork network) {
this(propagatedContingency, network, Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), 0);
}

public PropagatedContingency getPropagatedContingency() {
return contingency;
public ConnectivityAnalysisResult(PropagatedContingency propagatedContingency, LfNetwork network, Set<String> elementsToReconnect,
Set<LfBus> disabledBuses, Set<LfBus> slackConnectedComponentBuses,
Set<LfBranch> partialDisabledBranches, int createdSynchronousComponents) {
this.propagatedContingency = Objects.requireNonNull(propagatedContingency);
this.network = Objects.requireNonNull(network);
this.elementsToReconnect = elementsToReconnect;
this.disabledBuses = disabledBuses;
this.slackConnectedComponentBuses = slackConnectedComponentBuses;
this.partialDisabledBranches = partialDisabledBranches;
this.createdSynchronousComponents = createdSynchronousComponents;
}

public void setPropagatedContingency(PropagatedContingency contingency) {
this.contingency = contingency;
public PropagatedContingency getPropagatedContingency() {
return propagatedContingency;
}

public Set<String> getElementsToReconnect() {
Expand All @@ -73,13 +77,22 @@ public Set<LfBus> getDisabledBuses() {
return disabledBuses;
}

public Set<LfBus> getSlackConnectedComponent() {
return slackConnectedComponent;
public Set<LfBus> getSlackConnectedComponentBuses() {
return slackConnectedComponentBuses;
}

public Set<LfBranch> getPartialDisabledBranches() {
return partialDisabledBranches;
}

public Optional<LfContingency> toLfContingency() {
return propagatedContingency.toLfContingency(network, false, (network, contingencyId, branchesToOpen, relocateSlackBus) -> {
return new PropagatedContingency.ContingencyConnectivityLossImpact(true,
createdSynchronousComponents,
disabledBuses,
Collections.emptySet()); // FIXME
});
}
}

public record ConnectivityBreakAnalysisResults(List<PropagatedContingency> nonBreakingConnectivityContingencies,
Expand Down Expand Up @@ -160,8 +173,9 @@ private static List<ConnectivityAnalysisResult> computeConnectivityData(LfNetwor
} else {
// only compute for factors that have to be computed for this contingency lost
Set<String> elementsToReconnect = computeElementsToReconnect(connectivity, breakingConnectivityElements);
ConnectivityAnalysisResult connectivityAnalysisResult = new ConnectivityAnalysisResult(elementsToReconnect, connectivity, lfNetwork);
connectivityAnalysisResult.setPropagatedContingency(contingency);
int createdSynchronousComponents = connectivity.getNbConnectedComponents() - 1;
ConnectivityAnalysisResult connectivityAnalysisResult = new ConnectivityAnalysisResult(contingency, lfNetwork, elementsToReconnect, connectivity.getVerticesRemovedFromMainComponent(),
connectivity.getConnectedComponent(lfNetwork.getSlackBus()), connectivity.getEdgesRemovedFromMainComponent(), createdSynchronousComponents);
connectivityAnalysisResults.add(connectivityAnalysisResult);
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import com.powsybl.math.matrix.LUDecomposition;
import com.powsybl.openloadflow.dc.DcLoadFlowContext;
import com.powsybl.openloadflow.dc.DcLoadFlowParameters;
import com.powsybl.openloadflow.dc.equations.AbstractClosedBranchDcFlowEquationTerm;
import com.powsybl.openloadflow.dc.equations.ClosedBranchSide1DcFlowEquationTerm;
import com.powsybl.openloadflow.dc.equations.DcEquationSystemCreationParameters;
import com.powsybl.openloadflow.dc.equations.DcEquationType;
import com.powsybl.openloadflow.dc.equations.*;
import com.powsybl.openloadflow.equations.Equation;
import com.powsybl.openloadflow.network.*;

Expand Down Expand Up @@ -65,14 +62,15 @@ public WoodburyEngine(DcEquationSystemCreationParameters creationParameters, Lis
* Note that it does not update the state vector and the network at the end (because we don't need it to just evaluate a few equations).
*/
public static double[] runDcLoadFlowWithModifiedTargetVector(DcLoadFlowContext loadFlowContext, DisabledNetwork disabledNetwork, ReportNode reportNode) {
return runDcLoadFlowWithModifiedTargetVector(loadFlowContext, disabledNetwork, reportNode, Collections.emptyList());
return runDcLoadFlowWithModifiedTargetVector(loadFlowContext, disabledNetwork, reportNode, null, Collections.emptyList());
}

/**
* A simplified version of DcLoadFlowEngine that supports on the fly bus and branch disabling, and pst actions.
* Note that it does not update the state vector and the network at the end (because we don't need it to just evaluate a few equations).
*/
public static double[] runDcLoadFlowWithModifiedTargetVector(DcLoadFlowContext loadFlowContext, DisabledNetwork disabledNetwork, ReportNode reportNode, List<LfAction> pstActions) {
public static double[] runDcLoadFlowWithModifiedTargetVector(DcLoadFlowContext loadFlowContext, DisabledNetwork disabledNetwork, ReportNode reportNode,
LfContingency contingency, List<LfAction> pstActions) {
Collection<LfBus> remainingBuses;
if (disabledNetwork.getBuses().isEmpty()) {
remainingBuses = loadFlowContext.getNetwork().getBuses();
Expand Down
42 changes: 26 additions & 16 deletions src/main/java/com/powsybl/openloadflow/network/LfContingency.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,36 +143,46 @@ public void apply(LoadFlowParameters.BalanceType balanceType) {
shunt.setG(shunt.getG() - e.getValue().getG());
shunt.setB(shunt.getB() - e.getValue().getB());
}
applyOnGeneratorsLoadsHvdcs(balanceType, true);
}

// TODO : to be rename / clean
public void applyOnGeneratorsLoadsHvdcs(LoadFlowParameters.BalanceType balanceType, boolean ac) {
for (var e : lostLoads.entrySet()) {
LfLoad load = e.getKey();
LfLostLoad lostLoad = e.getValue();
PowerShift shift = lostLoad.getPowerShift();
load.setTargetP(load.getTargetP() - getUpdatedLoadP0(load, balanceType, shift.getActive(), shift.getVariableActive(), lostLoad.getNotParticipatingLoadP0()));
load.setTargetQ(load.getTargetQ() - shift.getReactive());
if (ac) {
load.setTargetQ(load.getTargetQ() - shift.getReactive());
}
load.setAbsVariableTargetP(load.getAbsVariableTargetP() - Math.abs(shift.getVariableActive()));
lostLoad.getOriginalIds().forEach(loadId -> load.setOriginalLoadDisabled(loadId, true));
}
Set<LfBus> generatorBuses = new HashSet<>();
for (LfGenerator generator : lostGenerators) {
generator.setTargetP(0);
generator.setInitialTargetP(0);
LfBus bus = generator.getBus();
generatorBuses.add(bus);
generator.setParticipating(false);
generator.setDisabled(true);
if (generator.getGeneratorControlType() != LfGenerator.GeneratorControlType.OFF) {
generator.setGeneratorControlType(LfGenerator.GeneratorControlType.OFF);
bus.getGeneratorVoltageControl().ifPresent(GeneratorVoltageControl::updateReactiveKeys);
bus.getGeneratorReactivePowerControl().ifPresent(GeneratorReactivePowerControl::updateReactiveKeys);
} else {
bus.setGenerationTargetQ(bus.getGenerationTargetQ() - generator.getTargetQ());
}
if (generator instanceof LfStaticVarCompensator svc) {
svc.getStandByAutomatonShunt().ifPresent(svcShunt -> {
// it means that the generator in contingency is a static var compensator with an active stand by automaton shunt
shuntsShift.put(svcShunt, new AdmittanceShift(0, svcShunt.getB()));
svcShunt.setB(0);
});

if (ac) {
LfBus bus = generator.getBus();
generatorBuses.add(bus);
if (generator.getGeneratorControlType() != LfGenerator.GeneratorControlType.OFF) {
generator.setGeneratorControlType(LfGenerator.GeneratorControlType.OFF);
bus.getGeneratorVoltageControl().ifPresent(GeneratorVoltageControl::updateReactiveKeys);
bus.getGeneratorReactivePowerControl().ifPresent(GeneratorReactivePowerControl::updateReactiveKeys);
} else {
bus.setGenerationTargetQ(bus.getGenerationTargetQ() - generator.getTargetQ());
}
if (generator instanceof LfStaticVarCompensator svc) {
svc.getStandByAutomatonShunt().ifPresent(svcShunt -> {
// it means that the generator in contingency is a static var compensator with an active stand by automaton shunt
shuntsShift.put(svcShunt, new AdmittanceShift(0, svcShunt.getB()));
svcShunt.setB(0);
});
}
}
}
for (LfBus bus : generatorBuses) {
Expand Down
Loading
Loading