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 sensitivities on intensity #231

Merged
merged 25 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fd4b83f
add intensity sensitivity
Djazouli Feb 26, 2021
d86716f
Add coherence between DELTA_I and DELTA_POWER
Djazouli Mar 5, 2021
891063f
Merge branch 'master' into intensity_from_ac
Djazouli Mar 5, 2021
a0d651b
merge fix
Djazouli Mar 5, 2021
52dc43d
Merge branch 'master' into intensity_from_ac
Djazouli Mar 8, 2021
9f996a3
merge fix
Djazouli Mar 8, 2021
26b0be0
refactor closed branch intensity
Djazouli Mar 9, 2021
e00e0da
Merge branch 'master' into intensity_from_ac
Djazouli Mar 9, 2021
e73a6f1
compute intensity on open branches without using p and q
Djazouli Mar 9, 2021
3d02aa5
use i1 eval instead of old formula with p and q
Djazouli Mar 9, 2021
304fc08
Add unit tests for LfSwitch.
annetill Mar 9, 2021
e4b1266
Fix unit test.
annetill Mar 9, 2021
909e14d
check that we cannot compute intensity sensi in DC
Djazouli Mar 9, 2021
cdc1de1
First import of unit test for the new intensity magnitude equations.
annetill Mar 9, 2021
b70c001
Merge branch 'intensity_from_ac' of https://github.com/powsybl/powsyb…
annetill Mar 9, 2021
835e20f
add test on open branch for intensity magnitude
Djazouli Mar 10, 2021
c8a0f5a
some renaming
Djazouli Mar 11, 2021
6170b2d
Small fix.
annetill Mar 11, 2021
aff7569
Replace intensity with current
Djazouli Mar 11, 2021
56f4852
Merge branch 'master' into intensity_from_ac
geofjamg Mar 15, 2021
c6ca639
update intensity only after the convergence of newton raphson
Djazouli Mar 16, 2021
bd43ab1
create intensity equations only for the factors that requires intensity
Djazouli Mar 16, 2021
611800a
rename BranchesCurrentManager
Djazouli Mar 16, 2021
50077aa
changes requested
Djazouli Mar 17, 2021
ba56bc6
Merge branch 'master' into intensity_from_ac
geofjamg Mar 17, 2021
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
13 changes: 6 additions & 7 deletions src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -120,11 +117,12 @@ private static SlackBusSelector getSlackBusSelector(Network network, LoadFlowPar

public static AcLoadFlowParameters createAcParameters(Network network, MatrixFactory matrixFactory, LoadFlowParameters parameters,
OpenLoadFlowParameters parametersExt, boolean breakers) {
return createAcParameters(network, matrixFactory, parameters, parametersExt, breakers, false);
return createAcParameters(network, matrixFactory, parameters, parametersExt, breakers, false, null);
}

public static AcLoadFlowParameters createAcParameters(Network network, MatrixFactory matrixFactory, LoadFlowParameters parameters,
OpenLoadFlowParameters parametersExt, boolean breakers, boolean forceA1Var) {
OpenLoadFlowParameters parametersExt, boolean breakers, boolean forceA1Var,
Set<String> branchesWithCurrent) {

SlackBusSelector slackBusSelector = getSlackBusSelector(network, parameters, parametersExt);

Expand Down Expand Up @@ -173,7 +171,8 @@ public static AcLoadFlowParameters createAcParameters(Network network, MatrixFac
breakers,
parametersExt.getPlausibleActivePowerLimit(),
forceA1Var,
parametersExt.isAddRatioToLinesWithDifferentNominalVoltageAtBothEnds());
parametersExt.isAddRatioToLinesWithDifferentNominalVoltageAtBothEnds(),
branchesWithCurrent);
}

private LoadFlowResult runAc(Network network, LoadFlowParameters parameters, OpenLoadFlowParameters parametersExt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
abstract class AbstractBranchAcFlowEquationTerm extends AbstractNamedEquationTerm {

public static final double CURRENT_NORMALIZATION_FACTOR = 1000d / Math.sqrt(3d);

protected final LfBranch branch;

protected final double b1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
import java.util.List;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
* @author Gael Macherel <gael.macherel at artelys.com>
*/
abstract class AbstractOpenBranchAcFlowEquationTerm extends AbstractBranchAcFlowEquationTerm {
abstract class AbstractOpenSide1BranchAcFlowEquationTerm extends AbstractBranchAcFlowEquationTerm {

protected final List<Variable> variables;

protected double shunt;

protected AbstractOpenBranchAcFlowEquationTerm(LfBranch branch, VariableType variableType,
protected AbstractOpenSide1BranchAcFlowEquationTerm(LfBranch branch, VariableType variableType,
LfBus bus, VariableSet variableSet,
boolean deriveA1, boolean deriveR1) {
super(branch);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright (c) 2019, 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.powsybl.openloadflow.ac.equations;

import com.powsybl.openloadflow.equations.Variable;
import com.powsybl.openloadflow.equations.VariableSet;
import com.powsybl.openloadflow.equations.VariableType;
import com.powsybl.openloadflow.network.LfBranch;
import com.powsybl.openloadflow.network.LfBus;

import java.util.Collections;
import java.util.List;

/**
* @author Gael Macherel <gael.macherel at artelys.com>
*/
abstract class AbstractOpenSide2BranchAcFlowEquationTerm extends AbstractBranchAcFlowEquationTerm {

protected final List<Variable> variables;

protected double shunt;

protected AbstractOpenSide2BranchAcFlowEquationTerm(LfBranch branch, VariableType variableType,
LfBus bus, VariableSet variableSet,
boolean deriveA1, boolean deriveR1) {
super(branch);
variables = Collections.singletonList(variableSet.getVariable(bus.getNum(), variableType));
shunt = (g2 + y * sinKsi) * (g2 + y * sinKsi) + (-b2 + y * cosKsi) * (-b2 + y * cosKsi);

if (deriveA1 || deriveR1) {
throw new IllegalArgumentException("Variable A1 or R1 on open branch not supported: " + branch.getId());
}
}

@Override
public List<Variable> getVariables() {
return variables;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -264,21 +264,34 @@ private static void createImpedantBranch(LfBranch branch, LfBus bus1, LfBus bus2
EquationTerm q1 = null;
EquationTerm p2 = null;
EquationTerm q2 = null;
EquationTerm i1 = null;
EquationTerm i2 = null;
boolean deriveA1 = creationParameters.isPhaseControl() && branch.isPhaseController()
&& branch.getDiscretePhaseControl().getMode() == DiscretePhaseControl.Mode.CONTROLLER;
deriveA1 = deriveA1 || (creationParameters.isForceA1Var() && branch.hasPhaseControlCapability());
boolean createCurrent = creationParameters.getBranchesWithCurrent() == null || creationParameters.getBranchesWithCurrent().contains(branch.getId());
boolean deriveR1 = creationParameters.isTransformerVoltageControl() && branch.isVoltageController();
if (bus1 != null && bus2 != null) {
p1 = new ClosedBranchSide1ActiveFlowEquationTerm(branch, bus1, bus2, variableSet, deriveA1, deriveR1);
q1 = new ClosedBranchSide1ReactiveFlowEquationTerm(branch, bus1, bus2, variableSet, deriveA1, deriveR1);
p2 = new ClosedBranchSide2ActiveFlowEquationTerm(branch, bus1, bus2, variableSet, deriveA1, deriveR1);
q2 = new ClosedBranchSide2ReactiveFlowEquationTerm(branch, bus1, bus2, variableSet, deriveA1, deriveR1);
if (createCurrent) {
i1 = new ClosedBranchSide1CurrentMagnitudeEquationTerm(branch, bus1, bus2, variableSet, deriveA1, deriveR1);
i2 = new ClosedBranchSide2CurrentMagnitudeEquationTerm(branch, bus1, bus2, variableSet, deriveA1, deriveR1);
}
} else if (bus1 != null) {
p1 = new OpenBranchSide2ActiveFlowEquationTerm(branch, bus1, variableSet, deriveA1, deriveR1);
q1 = new OpenBranchSide2ReactiveFlowEquationTerm(branch, bus1, variableSet, deriveA1, deriveR1);
if (createCurrent) {
i1 = new OpenBranchSide2CurrentMagnitudeEquationTerm(branch, bus1, variableSet, deriveA1, deriveR1);
}
} else if (bus2 != null) {
p2 = new OpenBranchSide1ActiveFlowEquationTerm(branch, bus2, variableSet, deriveA1, deriveR1);
q2 = new OpenBranchSide1ReactiveFlowEquationTerm(branch, bus2, variableSet, deriveA1, deriveR1);
if (createCurrent) {
i2 = new OpenBranchSide1CurrentMagnitudeEquationTerm(branch, bus2, variableSet, deriveA1, deriveR1);
}
}

if (p1 != null) {
Expand Down Expand Up @@ -308,6 +321,18 @@ private static void createImpedantBranch(LfBranch branch, LfBus bus1, LfBus bus2
equationSystem.createEquation(branch.getNum(), EquationType.BRANCH_ALPHA1)
.addTerm(new BranchA1EquationTerm(branch, variableSet));
}

if (i1 != null) {
Equation i = equationSystem.createEquation(bus1.getNum(), EquationType.BUS_I).addTerm(i1);
i.setUpdateType(EquationSystem.EquationUpdateType.AFTER_NR); // only update those equations after the newton raphson
branch.setI1(i1);
}

if (i2 != null) {
Equation i = equationSystem.createEquation(bus2.getNum(), EquationType.BUS_I).addTerm(i2);
i.setUpdateType(EquationSystem.EquationUpdateType.AFTER_NR); // only update those equations after the newton raphson
branch.setI2(i2);
}
}

private static void createBranchEquations(LfNetwork network, VariableSet variableSet, AcEquationSystemCreationParameters creationParameters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package com.powsybl.openloadflow.ac.equations;

import java.util.Set;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
Expand All @@ -17,14 +19,21 @@ public class AcEquationSystemCreationParameters {

private final boolean forceA1Var;

private final Set<String> branchesWithCurrent;

public AcEquationSystemCreationParameters(boolean phaseControl, boolean transformerVoltageControl) {
this(phaseControl, transformerVoltageControl, false);
}

public AcEquationSystemCreationParameters(boolean phaseControl, boolean transformerVoltageControl, boolean forceA1Var) {
this(phaseControl, transformerVoltageControl, forceA1Var, null);
}

public AcEquationSystemCreationParameters(boolean phaseControl, boolean transformerVoltageControl, boolean forceA1Var, Set<String> branchesWithCurrent) {
this.phaseControl = phaseControl;
this.transformerVoltageControl = transformerVoltageControl;
this.forceA1Var = forceA1Var;
this.branchesWithCurrent = branchesWithCurrent;
}

public boolean isPhaseControl() {
Expand All @@ -38,4 +47,8 @@ public boolean isTransformerVoltageControl() {
public boolean isForceA1Var() {
return forceA1Var;
}

public Set<String> getBranchesWithCurrent() {
return branchesWithCurrent;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* Copyright (c) 2019, 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.powsybl.openloadflow.ac.equations;

import com.powsybl.openloadflow.equations.Variable;
import com.powsybl.openloadflow.equations.VariableSet;
import com.powsybl.openloadflow.network.LfBranch;
import com.powsybl.openloadflow.network.LfBus;
import net.jafama.FastMath;

import java.util.Objects;

import static com.powsybl.openloadflow.network.PiModel.A2;
import static com.powsybl.openloadflow.network.PiModel.R2;

/**
* @author Gael Macherel <gael.macherel at artelys.com>
*/
public class ClosedBranchSide1CurrentMagnitudeEquationTerm extends AbstractClosedBranchAcFlowEquationTerm {

private double i1;

private double di1dv1;

private double di1dv2;

private double di1dph1;

private double di1dph2;

private double di1da1;

public ClosedBranchSide1CurrentMagnitudeEquationTerm(LfBranch branch, LfBus bus1, LfBus bus2, VariableSet variableSet,
boolean deriveA1, boolean deriveR1) {
super(branch, bus1, bus2, variableSet, deriveA1, deriveR1);
}

@Override
protected double calculateDer(double dph1, double dph2, double dv1, double dv2, double a1, double r1) {
return di1dph1 * dph1 + di1dph2 * dph2 + di1dv1 * dv1 + di1dv2 * dv2;
}

@Override
public void update(double[] x) {
Objects.requireNonNull(x);
double v1 = x[v1Var.getRow()];
double v2 = x[v2Var.getRow()];
double ph1 = x[ph1Var.getRow()];
double ph2 = x[ph2Var.getRow()];
double r1 = r1Var != null && r1Var.isActive() ? x[r1Var.getRow()] : branch.getPiModel().getR1();
double w1 = r1 * v1;
double w2 = y * R2 * v2;
double cosPh1 = FastMath.cos(ph1);
double sinPh1 = FastMath.sin(ph1);
double cosPh1Ksi = FastMath.cos(ph1 + ksi);
double sinPh1Ksi = FastMath.sin(ph1 + ksi);
double theta = ksi - (a1Var != null && a1Var.isActive() ? x[a1Var.getRow()] : branch.getPiModel().getA1())
+ A2 + ph2;
double sinTheta = FastMath.sin(theta);
double cosTheta = FastMath.cos(theta);

double reI1 = r1 * (w1 * (g1 * cosPh1 - b1 * sinPh1 + y * sinPh1Ksi) - w2 * sinTheta) * CURRENT_NORMALIZATION_FACTOR;
double imI1 = r1 * (w1 * (g1 * sinPh1 + b1 * cosPh1 - y * cosPh1Ksi) + w2 * cosTheta) * CURRENT_NORMALIZATION_FACTOR;
i1 = Math.hypot(reI1, imI1);

double dreI1dv1 = r1 * r1 * (g1 * cosPh1 - b1 * sinPh1 + y * sinPh1Ksi) * CURRENT_NORMALIZATION_FACTOR;
double dreI1dv2 = r1 * (-y * R2 * sinTheta) * CURRENT_NORMALIZATION_FACTOR;
double dreI1dph1 = r1 * w1 * (-g1 * sinPh1 - b1 * cosPh1 + y * cosPh1Ksi) * CURRENT_NORMALIZATION_FACTOR;
double dreI1dph2 = r1 * (-w2 * cosTheta) * CURRENT_NORMALIZATION_FACTOR;

double dimI1dv1 = r1 * r1 * (g1 * sinPh1 + b1 * cosPh1 - y * cosPh1Ksi) * CURRENT_NORMALIZATION_FACTOR;
double dimI1dv2 = r1 * (y * R2 * cosTheta) * CURRENT_NORMALIZATION_FACTOR;
double dimI1dph1 = r1 * w1 * (g1 * cosPh1 - b1 * sinPh1 + y * sinPh1Ksi) * CURRENT_NORMALIZATION_FACTOR;
double dimI1dph2 = r1 * (-w2 * sinTheta) * CURRENT_NORMALIZATION_FACTOR;

di1dv1 = (reI1 * dreI1dv1 + imI1 * dimI1dv1) / i1;
di1dv2 = (reI1 * dreI1dv2 + imI1 * dimI1dv2) / i1;
di1dph1 = (reI1 * dreI1dph1 + imI1 * dimI1dph1) / i1;
di1dph2 = (reI1 * dreI1dph2 + imI1 * dimI1dph2) / i1;

if (a1Var != null) {
di1da1 = -di1dph2;
}
}

@Override
public double eval() {
return i1;
}

@Override
public double der(Variable variable) {
Objects.requireNonNull(variable);
if (variable.equals(v1Var)) {
return di1dv1;
} else if (variable.equals(v2Var)) {
return di1dv2;
} else if (variable.equals(ph1Var)) {
return di1dph1;
} else if (variable.equals(ph2Var)) {
return di1dph2;
} else if (variable.equals(a1Var)) {
return di1da1;
} else {
throw new IllegalStateException("Unknown variable: " + variable);
}
}

@Override
protected String getName() {
return "ac_i_closed_1";
}
}
Loading