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

Improve DC initialisation #1009

Closed
wants to merge 8 commits into from
Closed
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 @@ -1676,7 +1676,7 @@ public static DcLoadFlowParameters createDcParameters(LoadFlowParameters paramet
.setLoadFlowModel(LoadFlowModel.DC)
.setShuntVoltageControl(false)
.setReactiveLimits(false)
.setHvdcAcEmulation(false) // FIXME
.setHvdcAcEmulation(parameters.isHvdcAcEmulation())
.setLowImpedanceThreshold(parametersExt.getLowImpedanceThreshold())
.setSvcVoltageMonitoring(false)
.setMaxSlackBusCount(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,17 @@
*/
package com.powsybl.openloadflow.ac.equations;

import com.powsybl.openloadflow.equations.Variable;
import com.powsybl.openloadflow.equations.AbstractHvdcAcEmulationSide1ActiveFlowEquationTerm;
import com.powsybl.openloadflow.equations.VariableSet;
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.network.LfHvdc;

import java.util.Objects;

/**
* @author Anne Tilloy {@literal <anne.tilloy at rte-france.com>}
*/
public class HvdcAcEmulationSide1ActiveFlowEquationTerm extends AbstractHvdcAcEmulationFlowEquationTerm {
public class HvdcAcEmulationSide1ActiveFlowEquationTerm extends AbstractHvdcAcEmulationSide1ActiveFlowEquationTerm<AcVariableType, AcEquationType> {

public HvdcAcEmulationSide1ActiveFlowEquationTerm(LfHvdc hvdc, LfBus bus1, LfBus bus2, VariableSet<AcVariableType> variableSet) {
super(hvdc, bus1, bus2, variableSet);
}

private double p1(double ph1, double ph2) {
double rawP = rawP(p0, k, ph1, ph2);
double boundedP = boundedP(rawP);
return (isController(rawP) ? 1 : getVscLossMultiplier()) * boundedP;
}

private static boolean isController(double rawP) {
return rawP >= 0;
}

private boolean isInOperatingRange(double rawP) {
return rawP < pMaxFromCS1toCS2 && rawP > -pMaxFromCS2toCS1;
}

protected double dp1dph1(double ph1, double ph2) {
double rawP = rawP(p0, k, ph1, ph2);
if (isInOperatingRange(rawP)) {
return (isController(rawP) ? 1 : getVscLossMultiplier()) * k;
} else {
return 0;
}
}

protected double dp1dph2(double ph1, double ph2) {
return -dp1dph1(ph1, ph2);
}

@Override
public double eval() {
return p1(ph1(), ph2());
}

@Override
public double der(Variable<AcVariableType> variable) {
Objects.requireNonNull(variable);
if (variable.equals(ph1Var)) {
return dp1dph1(ph1(), ph2());
} else if (variable.equals(ph2Var)) {
return dp1dph2(ph1(), ph2());
} else {
throw new IllegalStateException("Unknown variable: " + variable);
}
}

@Override
protected String getName() {
return "ac_emulation_p_1";
super(hvdc, bus1, bus2, variableSet, AcVariableType.BUS_PHI);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,17 @@
*/
package com.powsybl.openloadflow.ac.equations;

import com.powsybl.openloadflow.equations.Variable;
import com.powsybl.openloadflow.equations.AbstractHvdcAcEmulationSide2ActiveFlowEquationTerm;
import com.powsybl.openloadflow.equations.VariableSet;
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.network.LfHvdc;

import java.util.Objects;

/**
* @author Anne Tilloy {@literal <anne.tilloy at rte-france.com>}
*/
public class HvdcAcEmulationSide2ActiveFlowEquationTerm extends AbstractHvdcAcEmulationFlowEquationTerm {
public class HvdcAcEmulationSide2ActiveFlowEquationTerm extends AbstractHvdcAcEmulationSide2ActiveFlowEquationTerm<AcVariableType, AcEquationType> {

public HvdcAcEmulationSide2ActiveFlowEquationTerm(LfHvdc hvdc, LfBus bus1, LfBus bus2, VariableSet<AcVariableType> variableSet) {
super(hvdc, bus1, bus2, variableSet);
}

private double p2(double ph1, double ph2) {
double rawP = rawP(p0, k, ph1, ph2);
double boundedP = boundedP(rawP);
return -(isController(rawP) ? 1 : getVscLossMultiplier()) * boundedP;
}

private boolean isController(double rawP) {
return rawP < 0;
}

private boolean isInOperatingRange(double rawP) {
return rawP < pMaxFromCS2toCS1 && rawP > -pMaxFromCS1toCS2;
}

private double dp2dph1(double ph1, double ph2) {
double rawP = rawP(p0, k, ph1, ph2);
if (isInOperatingRange(rawP)) {
return -(isController(rawP) ? 1 : getVscLossMultiplier()) * k;
} else {
return 0;
}
}

private double dp2dph2(double ph1, double ph2) {
return -dp2dph1(ph1, ph2);
}

@Override
public double eval() {
return p2(ph1(), ph2());
}

@Override
public double der(Variable<AcVariableType> variable) {
Objects.requireNonNull(variable);
if (variable.equals(ph1Var)) {
return dp2dph1(ph1(), ph2());
} else if (variable.equals(ph2Var)) {
return dp2dph2(ph1(), ph2());
} else {
throw new IllegalStateException("Unknown variable: " + variable);
}
}

@Override
protected String getName() {
return "ac_emulation_p_2";
super(hvdc, bus1, bus2, variableSet, AcVariableType.BUS_PHI);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,37 @@ private void createBranches(EquationSystem<DcVariableType, DcEquationType> equat
}
}

private void createHvdcs(EquationSystem<DcVariableType, DcEquationType> equationSystem) {
for (LfHvdc hvdc : network.getHvdcs()) {
EquationTerm<DcVariableType, DcEquationType> p1 = null;
EquationTerm<DcVariableType, DcEquationType> p2 = null;
if (hvdc.getBus1() != null && hvdc.getBus2() != null && hvdc.isAcEmulation()) {
p1 = new HvdcAcEmulationSide1ActiveFlowEquationTerm(hvdc, hvdc.getBus1(), hvdc.getBus2(), equationSystem.getVariableSet());
p2 = new HvdcAcEmulationSide2ActiveFlowEquationTerm(hvdc, hvdc.getBus1(), hvdc.getBus2(), equationSystem.getVariableSet());
}

if (p1 != null) {
equationSystem.getEquation(hvdc.getBus1().getNum(), DcEquationType.BUS_TARGET_P)
.orElseThrow()
.addTerm(p1);
hvdc.setP1(p1);
}

if (p2 != null) {
equationSystem.getEquation(hvdc.getBus2().getNum(), DcEquationType.BUS_TARGET_P)
.orElseThrow()
.addTerm(p2);
hvdc.setP2(p2);
}
}
}

public EquationSystem<DcVariableType, DcEquationType> create(boolean withListener) {
EquationSystem<DcVariableType, DcEquationType> equationSystem = new EquationSystem<>();

createBuses(equationSystem);
createBranches(equationSystem);
createHvdcs(equationSystem);

EquationSystemPostProcessor.findAll().forEach(pp -> pp.onCreate(equationSystem));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) 2022, 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.dc.equations;

import com.powsybl.openloadflow.equations.AbstractHvdcAcEmulationSide1ActiveFlowEquationTerm;
import com.powsybl.openloadflow.equations.VariableSet;
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.network.LfHvdc;

/**
* @author Anne Tilloy {@literal <anne.tilloy at rte-france.com>}
*/
public class HvdcAcEmulationSide1ActiveFlowEquationTerm extends AbstractHvdcAcEmulationSide1ActiveFlowEquationTerm<DcVariableType, DcEquationType> {

public HvdcAcEmulationSide1ActiveFlowEquationTerm(LfHvdc hvdc, LfBus bus1, LfBus bus2, VariableSet<DcVariableType> variableSet) {
super(hvdc, bus1, bus2, variableSet, DcVariableType.BUS_PHI);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) 2022, 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.dc.equations;

import com.powsybl.openloadflow.equations.AbstractHvdcAcEmulationSide2ActiveFlowEquationTerm;
import com.powsybl.openloadflow.equations.VariableSet;
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.network.LfHvdc;

/**
* @author Anne Tilloy {@literal <anne.tilloy at rte-france.com>}
*/
public class HvdcAcEmulationSide2ActiveFlowEquationTerm extends AbstractHvdcAcEmulationSide2ActiveFlowEquationTerm<DcVariableType, DcEquationType> {

public HvdcAcEmulationSide2ActiveFlowEquationTerm(LfHvdc hvdc, LfBus bus1, LfBus bus2, VariableSet<DcVariableType> variableSet) {
super(hvdc, bus1, bus2, variableSet, DcVariableType.BUS_PHI);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
* 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;
package com.powsybl.openloadflow.equations;

import com.powsybl.openloadflow.equations.AbstractElementEquationTerm;
import com.powsybl.openloadflow.equations.Variable;
import com.powsybl.openloadflow.equations.VariableSet;
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.network.LfHvdc;

Expand All @@ -17,13 +14,14 @@
/**
* @author Anne Tilloy {@literal <anne.tilloy at rte-france.com>}
*/
public abstract class AbstractHvdcAcEmulationFlowEquationTerm extends AbstractElementEquationTerm<LfHvdc, AcVariableType, AcEquationType> {
public abstract class AbstractHvdcAcEmulationFlowEquationTerm<V extends Enum<V> & Quantity, E extends Enum<E> & Quantity>
extends AbstractElementEquationTerm<LfHvdc, V, E> {

protected final Variable<AcVariableType> ph1Var;
protected final Variable<V> ph1Var;

protected final Variable<AcVariableType> ph2Var;
protected final Variable<V> ph2Var;

protected final List<Variable<AcVariableType>> variables;
protected final List<Variable<V>> variables;

protected final double k;

Expand All @@ -37,10 +35,11 @@ public abstract class AbstractHvdcAcEmulationFlowEquationTerm extends AbstractEl

protected final double pMaxFromCS2toCS1;

protected AbstractHvdcAcEmulationFlowEquationTerm(LfHvdc hvdc, LfBus bus1, LfBus bus2, VariableSet<AcVariableType> variableSet) {
protected AbstractHvdcAcEmulationFlowEquationTerm(LfHvdc hvdc, LfBus bus1, LfBus bus2, VariableSet<V> variableSet,
V busPhiVariableType) {
super(hvdc);
ph1Var = variableSet.getVariable(bus1.getNum(), AcVariableType.BUS_PHI);
ph2Var = variableSet.getVariable(bus2.getNum(), AcVariableType.BUS_PHI);
ph1Var = variableSet.getVariable(bus1.getNum(), busPhiVariableType);
ph2Var = variableSet.getVariable(bus2.getNum(), busPhiVariableType);
variables = List.of(ph1Var, ph2Var);
k = hvdc.getDroop() * 180 / Math.PI;
p0 = hvdc.getP0();
Expand Down Expand Up @@ -78,7 +77,7 @@ protected double getVscLossMultiplier() {
}

@Override
public List<Variable<AcVariableType>> getVariables() {
public List<Variable<V>> getVariables() {
return variables;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Copyright (c) 2022, 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.equations;

import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.network.LfHvdc;

import java.util.Objects;

/**
* @author Anne Tilloy {@literal <anne.tilloy at rte-france.com>}
*/
public abstract class AbstractHvdcAcEmulationSide1ActiveFlowEquationTerm<V extends Enum<V> & Quantity, E extends Enum<E> & Quantity>
extends AbstractHvdcAcEmulationFlowEquationTerm<V, E> {

protected AbstractHvdcAcEmulationSide1ActiveFlowEquationTerm(LfHvdc hvdc, LfBus bus1, LfBus bus2, VariableSet<V> variableSet,
V busPhiVariableType) {
super(hvdc, bus1, bus2, variableSet, busPhiVariableType);
}

private double p1(double ph1, double ph2) {
double rawP = rawP(p0, k, ph1, ph2);
double boundedP = boundedP(rawP);
return (isController(rawP) ? 1 : getVscLossMultiplier()) * boundedP;
}

private static boolean isController(double rawP) {
return rawP >= 0;
}

private boolean isInOperatingRange(double rawP) {
return rawP < pMaxFromCS1toCS2 && rawP > -pMaxFromCS2toCS1;
}

protected double dp1dph1(double ph1, double ph2) {
double rawP = rawP(p0, k, ph1, ph2);
if (isInOperatingRange(rawP)) {
return (isController(rawP) ? 1 : getVscLossMultiplier()) * k;
} else {
return 0;
}
}

protected double dp1dph2(double ph1, double ph2) {
return -dp1dph1(ph1, ph2);
}

@Override
public double eval() {
return p1(ph1(), ph2());
}

@Override
public double der(Variable<V> variable) {
Objects.requireNonNull(variable);
if (variable.equals(ph1Var)) {
return dp1dph1(ph1(), ph2());
} else if (variable.equals(ph2Var)) {
return dp1dph2(ph1(), ph2());
} else {
throw new IllegalStateException("Unknown variable: " + variable);
}
}

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