Skip to content

Commit

Permalink
add boolean for warm start update and refactor TUs.
Browse files Browse the repository at this point in the history
Signed-off-by: parvy <[email protected]>
  • Loading branch information
p-arvy committed Jan 17, 2024
1 parent 295119b commit 023995c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class OpenReacResult {
private final List<StaticVarCompensatorModification> svcModifications;
private final List<RatioTapPositionModification> tapPositionModifications;
private final List<BusResult> voltagePlan;
private boolean warmStart = true;

/**
* @param status the final status of the OpenReac run.
Expand Down Expand Up @@ -90,6 +91,14 @@ public List<BusResult> getVoltagePlan() {
return voltagePlan;
}

public boolean getWarmStat() {
return warmStart;
}

public void setWarmStart(boolean warmStart) {
this.warmStart = warmStart;
}

public List<NetworkModification> getAllNetworkModifications() {
List<NetworkModification> modifs = new ArrayList<>(getGeneratorModifications().size() +
getShuntsModifications().size() +
Expand All @@ -114,9 +123,10 @@ public void applyAllModifications(Network network) {
double v = busResult.getV() * b.getVoltageLevel().getNominalV();
double angle = busResult.getAngle();

// warm start
b.setV(v);
b.setAngle(angle);
if (getWarmStat()) {
b.setV(v);
b.setAngle(angle);
}

// update target of ratio tap changers regulating voltage on b
network.getTwoWindingsTransformerStream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ void testRunAsync() throws IOException {
subFolder + "/reactiveopf_results_rtc.csv",
subFolder + "/reactiveopf_results_shunts.csv",
subFolder + "/reactiveopf_results_static_var_compensators.csv",
subFolder + "/reactiveopf_results_vsc_converter_stations.csv"));
subFolder + "/reactiveopf_results_vsc_converter_stations.csv",
subFolder + "/reactiveopf_results_voltages.csv"));
// To really run open reac, use the commented 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),
Expand All @@ -245,24 +246,7 @@ void testRunAsync() throws IOException {
}

private void testAllModifAndLoadFlow(Network network, String subFolder, OpenReacParameters parameters) throws IOException {
LocalCommandExecutor localCommandExecutor = new TestLocalCommandExecutor(
List.of(subFolder + "/reactiveopf_results_generators.csv",
subFolder + "/reactiveopf_results_indic.txt",
subFolder + "/reactiveopf_results_rtc.csv",
subFolder + "/reactiveopf_results_shunts.csv",
subFolder + "/reactiveopf_results_static_var_compensators.csv",
subFolder + "/reactiveopf_results_vsc_converter_stations.csv",
subFolder + "/reactiveopf_results_voltages.csv"));
// 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())) {
OpenReacResult openReacResult = OpenReacRunner.run(network,
network.getVariantManager().getWorkingVariantId(), parameters, new OpenReacConfig(true),
computationManager);
assertEquals(OpenReacStatus.OK, openReacResult.getStatus());
openReacResult.applyAllModifications(network);
}
runAndApplyAllModifications(network, subFolder, parameters, true);
LoadFlowResult loadFlowResult = LoadFlow.run(network);
assertTrue(loadFlowResult.isOk());
}
Expand Down Expand Up @@ -343,6 +327,26 @@ public void testWarmStart() throws IOException {
Network network = VoltageControlNetworkFactory.createNetworkWithT2wt();
setDefaultVoltageLimits(network);
String subFolder = "openreac-output-warm-start";
OpenReacParameters parameters = new OpenReacParameters();

runAndApplyAllModifications(network, subFolder, parameters, false); // without warm start, no update
assertEquals(Double.NaN, network.getBusBreakerView().getBus("BUS_1").getV());
assertEquals(Double.NaN, network.getBusBreakerView().getBus("BUS_1").getAngle());
assertEquals(Double.NaN, network.getBusBreakerView().getBus("BUS_2").getV());
assertEquals(Double.NaN, network.getBusBreakerView().getBus("BUS_2").getAngle());
assertEquals(Double.NaN, network.getBusBreakerView().getBus("BUS_3").getV());
assertEquals(Double.NaN, network.getBusBreakerView().getBus("BUS_3").getAngle());

runAndApplyAllModifications(network, subFolder, parameters, true);
assertEquals(119.592, network.getBusBreakerView().getBus("BUS_1").getV());
assertEquals(0.014, network.getBusBreakerView().getBus("BUS_1").getAngle());
assertEquals(118.8, network.getBusBreakerView().getBus("BUS_2").getV());
assertEquals(0, network.getBusBreakerView().getBus("BUS_2").getAngle());
assertEquals(22.935, network.getBusBreakerView().getBus("BUS_3").getV());
assertEquals(-0.082, network.getBusBreakerView().getBus("BUS_3").getAngle());
}

private void runAndApplyAllModifications(Network network, String subFolder, OpenReacParameters parameters, boolean warmStart) throws IOException {
LocalCommandExecutor localCommandExecutor = new TestLocalCommandExecutor(
List.of(subFolder + "/reactiveopf_results_generators.csv",
subFolder + "/reactiveopf_results_indic.txt",
Expand All @@ -354,20 +358,14 @@ public void testWarmStart() throws IOException {
// 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())) {
localCommandExecutor, ForkJoinPool.commonPool())) {
OpenReacResult openReacResult = OpenReacRunner.run(network,
network.getVariantManager().getWorkingVariantId(), new OpenReacParameters(),
network.getVariantManager().getWorkingVariantId(), parameters,
new OpenReacConfig(true), computationManager);
assertEquals(OpenReacStatus.OK, openReacResult.getStatus());
openReacResult.setWarmStart(warmStart);
openReacResult.applyAllModifications(network);
}

assertEquals(119.592, network.getBusBreakerView().getBus("BUS_1").getV());
assertEquals(0.014, network.getBusBreakerView().getBus("BUS_1").getAngle());
assertEquals(118.8, network.getBusBreakerView().getBus("BUS_2").getV());
assertEquals(0, network.getBusBreakerView().getBus("BUS_2").getAngle());
assertEquals(22.935, network.getBusBreakerView().getBus("BUS_3").getV());
assertEquals(-0.082, network.getBusBreakerView().getBus("BUS_3").getAngle());
}

public static Network create() {
Expand Down

0 comments on commit 023995c

Please sign in to comment.