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

[WIP] Automatic fix of incompatible target voltages #1115

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add method to directly check on IIDM network
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@gmail.com>
  • Loading branch information
geofjamg committed Nov 16, 2024
commit 70c43265cf4e5523bc738ff0b5b6b1cab70f2bc2
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
import com.powsybl.openloadflow.dc.equations.DcApproximationType;
import com.powsybl.openloadflow.dc.equations.DcEquationSystemCreationParameters;
import com.powsybl.openloadflow.graph.GraphConnectivityFactory;
import com.powsybl.openloadflow.graph.NaiveGraphConnectivityFactory;
import com.powsybl.openloadflow.lf.AbstractLoadFlowParameters;
import com.powsybl.openloadflow.network.*;
import com.powsybl.openloadflow.network.util.PreviousValueVoltageInitializer;
@@ -1961,6 +1962,14 @@ public static DcLoadFlowParameters createDcParameters(LoadFlowParameters paramet
.setMaxOuterLoopIterations(parametersExt.getMaxOuterLoopIterations());
}

static GraphConnectivityFactory<LfBus, LfBranch> getConnectivityFactory(OpenLoadFlowParameters parametersExt,
GraphConnectivityFactory<LfBus, LfBranch> defaultConnectivityFactory) {
return parametersExt.isNetworkCacheEnabled() && !parametersExt.getActionableSwitchesIds().isEmpty()
|| parametersExt.isSimulateAutomationSystems()
? new NaiveGraphConnectivityFactory<>(LfBus::getNum)
: defaultConnectivityFactory;
}

public static boolean equals(LoadFlowParameters parameters1, LoadFlowParameters parameters2) {
Objects.requireNonNull(parameters1);
Objects.requireNonNull(parameters2);
Original file line number Diff line number Diff line change
@@ -32,7 +32,6 @@
import com.powsybl.openloadflow.dc.DcLoadFlowResult;
import com.powsybl.openloadflow.graph.EvenShiloachGraphDecrementalConnectivityFactory;
import com.powsybl.openloadflow.graph.GraphConnectivityFactory;
import com.powsybl.openloadflow.graph.NaiveGraphConnectivityFactory;
import com.powsybl.openloadflow.lf.AbstractLoadFlowResult;
import com.powsybl.openloadflow.lf.outerloop.OuterLoop;
import com.powsybl.openloadflow.network.*;
@@ -93,13 +92,6 @@ public String getVersion() {
return new PowsyblCoreVersion().getMavenProjectVersion();
}

private GraphConnectivityFactory<LfBus, LfBranch> getConnectivityFactory(OpenLoadFlowParameters parametersExt) {
return parametersExt.isNetworkCacheEnabled() && !parametersExt.getActionableSwitchesIds().isEmpty()
|| parametersExt.isSimulateAutomationSystems()
? new NaiveGraphConnectivityFactory<>(LfBus::getNum)
: connectivityFactory;
}

private void updateAcState(Network network, LoadFlowParameters parameters, OpenLoadFlowParameters parametersExt,
AcLoadFlowResult result, AcLoadFlowParameters acParameters, boolean atLeastOneComponentHasToBeUpdated) {
if (parametersExt.isNetworkCacheEnabled()) {
@@ -134,7 +126,7 @@ private void updateAcState(Network network, LoadFlowParameters parameters, OpenL
}

private LoadFlowResult runAc(Network network, LoadFlowParameters parameters, OpenLoadFlowParameters parametersExt, ReportNode reportNode) {
GraphConnectivityFactory<LfBus, LfBranch> selectedConnectivityFactory = getConnectivityFactory(parametersExt);
GraphConnectivityFactory<LfBus, LfBranch> selectedConnectivityFactory = OpenLoadFlowParameters.getConnectivityFactory(parametersExt, connectivityFactory);
AcLoadFlowParameters acParameters = OpenLoadFlowParameters.createAcParameters(network, parameters, parametersExt, matrixFactory, selectedConnectivityFactory);
acParameters.setDetailedReport(parametersExt.getReportedFeatures().contains(OpenLoadFlowParameters.ReportedFeatures.NEWTON_RAPHSON_LOAD_FLOW));

Original file line number Diff line number Diff line change
@@ -8,7 +8,14 @@
package com.powsybl.openloadflow;

import com.google.common.base.Stopwatch;
import com.powsybl.iidm.network.Network;
import com.powsybl.loadflow.LoadFlowParameters;
import com.powsybl.math.matrix.DenseMatrix;
import com.powsybl.math.matrix.MatrixFactory;
import com.powsybl.math.matrix.SparseMatrixFactory;
import com.powsybl.openloadflow.ac.AcJacobianMatrix;
import com.powsybl.openloadflow.ac.AcLoadFlowParameters;
import com.powsybl.openloadflow.ac.equations.AcEquationSystemCreator;
import com.powsybl.openloadflow.ac.equations.AcEquationType;
import com.powsybl.openloadflow.ac.equations.AcVariableType;
import com.powsybl.openloadflow.ac.solver.AcSolverUtil;
@@ -18,7 +25,10 @@
import com.powsybl.openloadflow.equations.EquationTerm;
import com.powsybl.openloadflow.equations.JacobianMatrix;
import com.powsybl.openloadflow.equations.VariableSet;
import com.powsybl.openloadflow.graph.EvenShiloachGraphDecrementalConnectivityFactory;
import com.powsybl.openloadflow.graph.GraphConnectivityFactory;
import com.powsybl.openloadflow.network.*;
import com.powsybl.openloadflow.network.impl.LfNetworkLoaderImpl;
import com.powsybl.openloadflow.network.util.UniformValueVoltageInitializer;
import org.apache.commons.lang3.mutable.MutableInt;
import org.jgrapht.Graph;
@@ -51,6 +61,41 @@ public RemoteVoltageTargetChecker(LfNetwork network,
this.j = Objects.requireNonNull(j);
}

public static Set<String> findElementsToDiscardFromVoltageControl(Network network, LoadFlowParameters parameters) {
return findElementsToDiscardFromVoltageControl(network, parameters, new SparseMatrixFactory());
}

public static Set<String> findElementsToDiscardFromVoltageControl(Network network, LoadFlowParameters parameters, MatrixFactory matrixFactory) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add a reason ?
Incompatible with XXX
Irrealistic

(It seems at this time there is even no log to understand the discard recommendation)

Objects.requireNonNull(network);
Objects.requireNonNull(parameters);
Set<String> generatorIds = new TreeSet<>();
OpenLoadFlowParameters parametersExt = OpenLoadFlowParameters.get(parameters);
GraphConnectivityFactory<LfBus, LfBranch> selectedConnectivityFactory = OpenLoadFlowParameters.getConnectivityFactory(parametersExt, new EvenShiloachGraphDecrementalConnectivityFactory<>());
AcLoadFlowParameters acParameters = OpenLoadFlowParameters.createAcParameters(network, parameters, parametersExt, matrixFactory, selectedConnectivityFactory);
for (LfNetwork lfNetwork : LfNetwork.load(network, new LfNetworkLoaderImpl(), acParameters.getNetworkParameters())) {
var equationSystem = new AcEquationSystemCreator(lfNetwork, acParameters.getEquationSystemCreationParameters())
.create();
try (var j = new AcJacobianMatrix(equationSystem, matrixFactory, lfNetwork)) {
var result = new RemoteVoltageTargetChecker(lfNetwork, equationSystem, j)
.check(new RemoteVoltageTargetCheckerParameters(matrixFactory));
for (var incompatibleTarget : result.getIncompatibleTargets()) {
LfBus controlledBus1 = incompatibleTarget.controlledBus1();
LfBus controlledBus2 = incompatibleTarget.controlledBus2();
for (LfBus controlledBus : List.of(controlledBus1, controlledBus2)) {
controlledBus.getGeneratorVoltageControl()
.ifPresent(vc -> generatorIds.addAll(vc.getControlledBus().getGenerators().stream().map(LfGenerator::getOriginalId).toList()));
controlledBus.getShuntVoltageControl()
.ifPresent(vc -> generatorIds.addAll(vc.getControlledBus().getGenerators().stream().map(LfGenerator::getOriginalId).toList()));
}
}
for (var unrealisticTarget : result.getUnrealisticTargets()) {
generatorIds.addAll(unrealisticTarget.controllerBus().getGenerators().stream().map(LfGenerator::getOriginalId).toList());
}
}
}
return generatorIds;
}

private static Graph<LfBus, LfBranch> createGraph(LfNetwork lfNetwork) {
Graph<LfBus, LfBranch> graph = new Pseudograph<>(LfBranch.class);
for (LfBranch branch : lfNetwork.getBranches()) {