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 6 points diagram to compute Qmin/Qmax of generators in ACOPF #92

Open
wants to merge 3 commits into
base: add-rho-alpha-for-znull-branches-in-acopf
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
72 changes: 57 additions & 15 deletions open-reac/src/main/resources/openreac/acopf_preprocessing.run
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,17 @@ for {(g,n) in UNITON} {
}

if abs(unit_qp[1,g,n]) >= PQmax then {
let corrected_unit_qp[g,n] := -defaultQmaxPmaxRatio * corrected_unit_Pmax[g,n];
printf{LOG_DEBUG} "%Q for %Q is %Q -> corrected to %Q\n","unit_qp",unit_id[1,g,n],unit_qp[1,g,n],corrected_unit_qp[g,n];
}
else let corrected_unit_qp[g,n] := unit_qp[1,g,n];
let corrected_unit_qp[g,n] := -defaultQmaxPmaxRatio * corrected_unit_Pmax[g,n];
printf{LOG_DEBUG} "%Q for %Q is %Q -> corrected to %Q\n","unit_qp",unit_id[1,g,n],unit_qp[1,g,n],corrected_unit_qp[g,n];
}
else let corrected_unit_qp[g,n] := unit_qp[1,g,n];

# TODO : update print
if abs(unit_qp0[1,g,n]) >= PQmax then {
let corrected_unit_q0[g,n] := -defaultQmaxPmaxRatio * corrected_unit_Pmax[g,n];
printf{LOG_DEBUG} "%Q for %Q is %Q -> corrected to %Q\n","unit_qp",unit_id[1,g,n],unit_qp[1,g,n],corrected_unit_qp[g,n];
}
else let corrected_unit_q0[g,n] := unit_qp0[1,g,n];

if abs(unit_qP[1,g,n]) >= PQmax then {
let corrected_unit_qP[g,n] := -defaultQmaxPmaxRatio * corrected_unit_Pmax[g,n];
Expand All @@ -187,10 +194,17 @@ for {(g,n) in UNITON} {
else let corrected_unit_qP[g,n] := unit_qP[1,g,n];

if abs(unit_Qp[1,g,n]) >= PQmax then {
let corrected_unit_Qp[g,n] := defaultQmaxPmaxRatio * corrected_unit_Pmax[g,n];
printf{LOG_DEBUG} "%Q for %Q is %Q -> corrected to %Q\n","unit_Qp",unit_id[1,g,n],unit_Qp[1,g,n],corrected_unit_Qp[g,n];
}
else let corrected_unit_Qp[g,n] := unit_Qp[1,g,n];
let corrected_unit_Qp[g,n] := defaultQmaxPmaxRatio * corrected_unit_Pmax[g,n];
printf{LOG_DEBUG} "%Q for %Q is %Q -> corrected to %Q\n","unit_Qp",unit_id[1,g,n],unit_Qp[1,g,n],corrected_unit_Qp[g,n];
}
else let corrected_unit_Qp[g,n] := unit_Qp[1,g,n];

# TODO : update print
if abs(unit_Qp0[1,g,n]) >= PQmax then {
let corrected_unit_Q0[g,n] := defaultQmaxPmaxRatio * corrected_unit_Pmax[g,n];
printf{LOG_DEBUG} "%Q for %Q is %Q -> corrected to %Q\n","unit_Qp",unit_id[1,g,n],unit_Qp[1,g,n],corrected_unit_Qp[g,n];
}
else let corrected_unit_Q0[g,n] := unit_Qp0[1,g,n];

if abs(unit_QP[1,g,n]) >= PQmax then {
let corrected_unit_QP[g,n] := defaultQmaxPmaxRatio * corrected_unit_Pmax[g,n];
Expand All @@ -206,12 +220,20 @@ for {(g,n) in UNITON} {
}

if corrected_unit_qP[g,n] > corrected_unit_QP[g,n] then {
printf{LOG_WARNING} "Warning unit %Q : unit_qP > unit_QP -> we invert them",unit_id[1,g,n];
let tempo := corrected_unit_qP[g,n];
let corrected_unit_qP[g,n] := corrected_unit_QP[g,n];
let corrected_unit_QP[g,n] := tempo;
}
printf{LOG_WARNING} "Warning unit %Q : unit_qP > unit_QP -> we invert them",unit_id[1,g,n];
let tempo := corrected_unit_qP[g,n];
let corrected_unit_qP[g,n] := corrected_unit_QP[g,n];
let corrected_unit_QP[g,n] := tempo;
}

if corrected_unit_q0[g,n] > corrected_unit_Q0[g,n] then {
printf{LOG_WARNING} "Warning unit %Q : unit_qP > unit_QP -> we invert them",unit_id[1,g,n];
let tempo := corrected_unit_q0[g,n];
let corrected_unit_q0[g,n] := corrected_unit_Q0[g,n];
let corrected_unit_Q0[g,n] := tempo;
}

# TODO : add corner cases here
if abs(corrected_unit_qP[g,n]-corrected_unit_QP[g,n]) <= minimalQPrange
and abs(corrected_unit_qp[g,n]-corrected_unit_Qp[g,n]) <= minimalQPrange
and abs(corrected_unit_QP[g,n]-corrected_unit_qp[g,n]) <= minimalQPrange
Expand All @@ -225,8 +247,28 @@ for {(g,n) in UNITON} {
let corrected_unit_Qp[g,n] := tempo;
}

let corrected_unit_Qmin[g,n] := min(corrected_unit_qP[g,n],corrected_unit_qp[g,n]);
let corrected_unit_Qmax[g,n] := min(corrected_unit_QP[g,n],corrected_unit_Qp[g,n]);
# cases when Qmin/Qmax are taken between Pmin and Pmax
if (unit_Pc[1,g,n] >= corrected_unit_Pmin[g,n] and unit_Pc[1,g,n] <= corrected_unit_Pmax[g,n] and (corrected_unit_Pmin[g,n] > 0 or corrected_unit_Pmax[g,n] < 0)) then {
let corrected_unit_Qmin[g,n] := corrected_unit_qp[g,n] + (unit_Pc[1,g,n] - corrected_unit_Pmin[g,n]) / (corrected_unit_Pmax[g,n] - corrected_unit_Pmin[g,n]) * (corrected_unit_qP[g,n] - corrected_unit_qp[g,n]);
let corrected_unit_Qmax[g,n] := corrected_unit_Qp[g,n] + (unit_Pc[1,g,n] - corrected_unit_Pmin[g,n]) / (corrected_unit_Pmax[g,n] - corrected_unit_Pmin[g,n]) * (corrected_unit_QP[g,n] - corrected_unit_Qp[g,n]);

# cases when Qmin/Qmax are taken between 0 and Pmax
} else if ((unit_Pc[1,g,n] >= corrected_unit_Pmin[g,n] and unit_Pc[1,g,n] <= corrected_unit_Pmax[g,n] and unit_Pc[1,g,n] > 0)
or (unit_Pc[1,g,n] < 0 and unit_Pc[1,g,n] >= corrected_unit_Pmax[g,n])) then {
let corrected_unit_Qmin[g,n] := corrected_unit_q0[g,n] + (unit_Pc[1,g,n] - 0) / (corrected_unit_Pmax[g,n] - 0) * (corrected_unit_qP[g,n] - corrected_unit_q0[g,n]);
let corrected_unit_Qmax[g,n] := corrected_unit_Q0[g,n] + (unit_Pc[1,g,n] - 0) / (corrected_unit_Pmax[g,n] - 0) * (corrected_unit_QP[g,n] - corrected_unit_Q0[g,n]);

# cases when Qmin/Qmax are taken between 0 and Pmin
} else if ((unit_Pc[1,g,n] >= corrected_unit_Pmin[g,n] and unit_Pc[1,g,n] <= corrected_unit_Pmax[g,n] and unit_Pc[1,g,n] < 0)
or (unit_Pc[1,g,n] > 0 and unit_Pc[1,g,n] <= corrected_unit_Pmin[g,n])) then {
let corrected_unit_Qmin[g,n] := corrected_unit_qp[g,n] + (unit_Pc[1,g,n] - corrected_unit_Pmin[g,n]) / (0 - corrected_unit_Pmin[g,n]) * (corrected_unit_q0[g,n] - corrected_unit_qp[g,n]);
let corrected_unit_Qmax[g,n] := corrected_unit_Qp[g,n] + (unit_Pc[1,g,n] - corrected_unit_Pmin[g,n]) / (0 - corrected_unit_Pmin[g,n]) * (corrected_unit_Q0[g,n] - corrected_unit_Qp[g,n]);
} else {
# TODO : add case when P_t is not in ramp up/down or in the diagram
# TODO : same when diagram has only 4 points...
let corrected_unit_Qmin[g,n] := min(corrected_unit_qP[g,n],corrected_unit_qp[g,n]);
let corrected_unit_Qmax[g,n] := min(corrected_unit_QP[g,n],corrected_unit_Qp[g,n]);
}

if unit_Pc[1,g,n] > corrected_unit_Pmax[g,n] or unit_Pc[1,g,n] < corrected_unit_Pmin[g,n]
then printf{LOG_WARNING} "Warning unit %Q Pc=%Q not in bounds [ Pmin=%Q ; Pmax=%Q ]\n",
Expand Down
16 changes: 9 additions & 7 deletions open-reac/src/main/resources/openreac/commons.mod
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,19 @@ check {(qq,m,n) in ALL_BRANCHCC}: abs(branch_X_mod[qq,m,n]) > 0;

# If in BRANCHZNULL, then set Gor/Gex/Bor/Bex to 0
param branch_Gor_mod{(qq,m,n) in ALL_BRANCHCC} :=
if (qq,m,n) in BRANCHCC and (qq,m,n) in BRANCHZNULL then 0
if (qq,m,n) in BRANCHCC and (qq,m,n) in BRANCHZNULL and substation_Vnomi[1,bus_substation[1,m]] != substation_Vnomi[1,bus_substation[1,n]] then 0
else branch_Gor[1,qq,m,n];

param branch_Gex_mod{(qq,m,n) in ALL_BRANCHCC} :=
if (qq,m,n) in BRANCHCC and (qq,m,n) in BRANCHZNULL then 0
if (qq,m,n) in BRANCHCC and (qq,m,n) in BRANCHZNULL and substation_Vnomi[1,bus_substation[1,m]] != substation_Vnomi[1,bus_substation[1,n]] then 0
else branch_Gex[1,qq,m,n];

param branch_Bor_mod{(qq,m,n) in ALL_BRANCHCC} :=
if (qq,m,n) in BRANCHCC and (qq,m,n) in BRANCHZNULL then 0
if (qq,m,n) in BRANCHCC and (qq,m,n) in BRANCHZNULL and substation_Vnomi[1,bus_substation[1,m]] != substation_Vnomi[1,bus_substation[1,n]] then 0
else branch_Bor[1,qq,m,n];

param branch_Bex_mod{(qq,m,n) in ALL_BRANCHCC} :=
if (qq,m,n) in BRANCHCC and (qq,m,n) in BRANCHZNULL then 0
if (qq,m,n) in BRANCHCC and (qq,m,n) in BRANCHZNULL and substation_Vnomi[1,bus_substation[1,m]] != substation_Vnomi[1,bus_substation[1,n]] then 0
else branch_Bex[1,qq,m,n];

# Busses with valid voltage value
Expand Down Expand Up @@ -203,19 +203,19 @@ param branch_admi {(qq,m,n) in ALL_BRANCHCC} =

# Later in this file, a variable branch_Ror_var will be created, to replace branch_Ror when it is not variable
param branch_Ror {(qq,m,n) in ALL_BRANCHCC} =
( if ((qq,m,n) in BRANCHCC_REGL)
( if (branch_ptrRegl[1,qq,m,n] != -1)
then tap_ratio[1,regl_table[1,branch_ptrRegl[1,qq,m,n]],regl_tap0[1,branch_ptrRegl[1,qq,m,n]]]
else 1.0
)
* ( if ((qq,m,n) in BRANCHCC_DEPH)
* ( if (branch_ptrDeph[1,qq,m,n] != -1)
then tap_ratio[1,deph_table[1,branch_ptrDeph[1,qq,m,n]],deph_tap0[1,branch_ptrDeph[1,qq,m,n]]]
else 1.0
)
* (branch_cstratio[1,qq,m,n]);
param branch_Rex {(q,m,n) in ALL_BRANCHCC} = 1; # In IIDM, everything is in bus1 so ratio at bus2 is always 1

param branch_dephor {(qq,m,n) in ALL_BRANCHCC} =
if ((qq,m,n) in BRANCHCC_DEPH)
if (branch_ptrDeph[1,qq,m,n] != -1)
then tap_angle [1,deph_table[1,branch_ptrDeph[1,qq,m,n]],deph_tap0[1,branch_ptrDeph[1,qq,m,n]]]
else 0;
param branch_dephex {(qq,m,n) in ALL_BRANCHCC} = 0; # In IIDM, everything is in bus1 so dephase at bus2 is always 0
Expand All @@ -228,7 +228,9 @@ param corrected_unit_Pmin{UNITON} default defaultPmin;
param corrected_unit_Pmax{UNITON} default defaultPmax;
param corrected_unit_qP {UNITON} default defaultQmin;
param corrected_unit_qp {UNITON} default defaultQmin;
param corrected_unit_q0 {UNITON} default defaultQmin;
param corrected_unit_QP {UNITON} default defaultQmax;
param corrected_unit_Qp {UNITON} default defaultQmax;
param corrected_unit_Q0 {UNITON} default defaultQmax;
param corrected_unit_Qmin{UNITON} default defaultQmin;
param corrected_unit_Qmax{UNITON} default defaultQmax;
2 changes: 1 addition & 1 deletion open-reac/src/main/resources/openreac/iidm_importer.mod
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ check {(t,g,n) in UNIT}: t in TIME;
check {(t,g,n) in UNIT}: (t,n) in BUS or n==-1;
check {(t,g,n) in UNIT}: (t,unit_substation[t,g,n]) in SUBSTATIONS;
check {(t,g,n) in UNIT}: (t,unit_vregul_bus[t,g,n]) in BUS or unit_vregul_bus[t,g,n] == -1;
check {(t,g,n) in UNIT}: unit_Pmax[t,g,n] >= -Pnull;
#check {(t,g,n) in UNIT}: unit_Pmax[t,g,n] >= -Pnull;
check {(t,g,n) in UNIT}: unit_Pmax[t,g,n] >= unit_Pmin[t,g,n];
# Checks below are useless since values will be corrected for units in UNITON
#check {(t,g,n) in UNIT}: unit_Qp[t,g,n] >= unit_qp[t,g,n];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected static Generator createGenerator(Bus b, String id, double p, double v)
.setConnectableBus(b.getId())
.setEnergySource(EnergySource.OTHER)
.setMinP(0)
.setMaxP(p)
.setMaxP(2)
.setTargetP(p)
.setTargetV(v)
.setVoltageRegulatorOn(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,15 +915,12 @@ public static Network createWithShuntSharedRemoteControl() {
}

/**
* SVC test case.
*
* g1 ld1
* | |
* b1---------b2
* l1 |
* svc1
* l1
*/
public static Network createWithStaticVarCompensator() {
public static Network createWithTwoBuses() {
Network network = Network.create("svc", "test");
Substation s1 = network.newSubstation()
.setId("S1")
Expand Down Expand Up @@ -964,14 +961,6 @@ public static Network createWithStaticVarCompensator() {
.setP0(101)
.setQ0(150)
.add();
vl2.newStaticVarCompensator()
.setId("svc1")
.setConnectableBus("b2")
.setBus("b2")
.setRegulationMode(StaticVarCompensator.RegulationMode.OFF)
.setBmin(-0.008)
.setBmax(0.008)
.add();
network.newLine()
.setId("l1")
.setBus1("b1")
Expand All @@ -982,6 +971,28 @@ public static Network createWithStaticVarCompensator() {
return network;
}

/**
* SVC test case.
*
* g1 ld1
* | |
* b1---------b2
* l1 |
* svc1
*/
public static Network createWithStaticVarCompensator() {
Network network = createWithTwoBuses();
network.getVoltageLevel("vl2").newStaticVarCompensator()
.setId("svc1")
.setConnectableBus("b2")
.setBus("b2")
.setRegulationMode(StaticVarCompensator.RegulationMode.OFF)
.setBmin(-0.008)
.setBmax(0.008)
.add();
return network;
}

/**
* l1 - b1 ================ b2 - g2
* || |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
import com.powsybl.commons.test.ComparisonUtils;
import com.powsybl.computation.ComputationManager;
import com.powsybl.computation.local.LocalCommandExecutor;
import com.powsybl.computation.local.LocalComputationConfig;
import com.powsybl.computation.local.LocalComputationManager;
import com.powsybl.iidm.network.*;
import com.powsybl.loadflow.LoadFlow;
import com.powsybl.loadflow.LoadFlowResult;
import com.powsybl.openreac.OpenReacConfig;
import com.powsybl.openreac.OpenReacRunner;
import com.powsybl.openreac.parameters.input.OpenReacParameters;
import com.powsybl.openreac.parameters.input.algo.OpenReacAmplLogLevel;
import com.powsybl.openreac.parameters.output.OpenReacResult;
import com.powsybl.openreac.parameters.output.OpenReacStatus;
import org.junit.jupiter.api.AfterEach;
Expand All @@ -32,7 +32,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ForkJoinPool;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -135,11 +134,14 @@ protected OpenReacResult runOpenReac(Network network, String subFolder, OpenReac
}
LocalCommandExecutor localCommandExecutor = new TestLocalCommandExecutor(outputFileNames);
// To really run open reac, use the commentede line below. Be sure that open-reac/src/test/resources/com/powsybl/config/test/config.yml contains your ampl path
// try (ComputationManager computationManager = new LocalComputationManager()) {
try (ComputationManager computationManager = new LocalComputationManager(new LocalComputationConfig(tmpDir),
localCommandExecutor, ForkJoinPool.commonPool())) {
return OpenReacRunner.run(network, network.getVariantManager().getWorkingVariantId(), parameters,
try (ComputationManager computationManager = new LocalComputationManager()) {
// try (ComputationManager computationManager = new LocalComputationManager(new LocalComputationConfig(tmpDir),
// localCommandExecutor, ForkJoinPool.commonPool())) {
parameters.setLogLevelAmpl(OpenReacAmplLogLevel.DEBUG);
OpenReacResult result = OpenReacRunner.run(network, network.getVariantManager().getWorkingVariantId(), parameters,
new OpenReacConfig(true), computationManager, reportNode, null);
System.out.println(result.getIndicators().get("directory"));
return result;
}
}

Expand Down
Loading
Loading