Skip to content

Commit

Permalink
Add 6 points diagrams for generators
Browse files Browse the repository at this point in the history
Signed-off-by: p-arvy <pierre.arvy@artelys.com>
  • Loading branch information
p-arvy committed Dec 18, 2024
1 parent 2e707c3 commit 8fe1e4f
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 83 deletions.
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
2 changes: 2 additions & 0 deletions open-reac/src/main/resources/openreac/commons.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8fe1e4f

Please sign in to comment.