-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export buses voltage and update targets V (#53)
* Refactor output classes. * Add TU for wrong number of columns. * Small renaming. * Add export of voltage plan. * remove useless id. * Add TU for VoltagePlanOutput. * update/add TU. * Add warm-start and TU. * Add boolean for warm start update and refactor TUs. * Fix codesmell. * Refactor and add TUs. * Refactor mock files. * Add TU for missing regulated bus. * Add log when bus/regulation terminal is null. * Improve coverage. * Keep same changes but on modifiable tap changers/shunts. * Remove restriction on target V update. * Rework to clarify. --------- Signed-off-by: parvy <[email protected]> Co-authored-by: Anne Tilloy <[email protected]>
- Loading branch information
Showing
27 changed files
with
617 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
open-reac/src/main/java/com/powsybl/openreac/parameters/output/VoltageProfileOutput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright (c) 2024, 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.openreac.parameters.output; | ||
|
||
import com.powsybl.ampl.converter.AmplSubset; | ||
import com.powsybl.commons.util.StringToIntMapper; | ||
import com.powsybl.openreac.parameters.AmplIOUtils; | ||
import org.jgrapht.alg.util.Pair; | ||
|
||
import java.util.*; | ||
|
||
/** | ||
* @author Pierre Arvy <pierre.arvy at artelys.com> | ||
*/ | ||
public class VoltageProfileOutput extends AbstractNoThrowOutput { | ||
|
||
private static final String ELEMENT = "voltages"; | ||
public static final int EXPECTED_COLS = 5; | ||
private static final int ID_COLUMN_INDEX = 4; | ||
private static final int V_COLUMN_INDEX = 2; | ||
private static final int ANGLE_COLUMN_INDEX = 3; | ||
|
||
private final Map<String, Pair<Double, Double>> voltageProfile = new HashMap<>(); | ||
|
||
public Map<String, Pair<Double, Double>> getVoltageProfile() { | ||
return voltageProfile; | ||
} | ||
|
||
@Override | ||
public String getElement() { | ||
return ELEMENT; | ||
} | ||
|
||
@Override | ||
public int getExpectedColumns() { | ||
return EXPECTED_COLS; | ||
} | ||
|
||
@Override | ||
protected void readLine(String[] tokens, StringToIntMapper<AmplSubset> stringToIntMapper) { | ||
String id = AmplIOUtils.removeQuotes(tokens[ID_COLUMN_INDEX]); | ||
double v = readDouble(tokens[V_COLUMN_INDEX]); | ||
double angle = readDouble(tokens[ANGLE_COLUMN_INDEX]); | ||
voltageProfile.put(id, Pair.of(v, angle)); | ||
} | ||
|
||
@Override | ||
public boolean throwOnMissingFile() { | ||
triggerErrorState(); | ||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
open-reac/src/test/java/com/powsybl/openreac/OpenReacResultsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package com.powsybl.openreac; | ||
|
||
import com.powsybl.ieeecdf.converter.IeeeCdfNetworkFactory; | ||
import com.powsybl.iidm.modification.ShuntCompensatorModification; | ||
import com.powsybl.iidm.modification.tapchanger.RatioTapPositionModification; | ||
import com.powsybl.iidm.network.Network; | ||
import com.powsybl.iidm.network.RatioTapChanger; | ||
import com.powsybl.iidm.network.ShuntCompensator; | ||
import com.powsybl.openreac.network.ShuntNetworkFactory; | ||
import com.powsybl.openreac.network.VoltageControlNetworkFactory; | ||
import com.powsybl.openreac.parameters.OpenReacAmplIOFiles; | ||
import com.powsybl.openreac.parameters.input.OpenReacParameters; | ||
import com.powsybl.openreac.parameters.output.OpenReacResult; | ||
import com.powsybl.openreac.parameters.output.OpenReacStatus; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.util.HashMap; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
class OpenReacResultsTest { | ||
|
||
@Test | ||
void testTransformerTargetVUpdateWithoutVoltageResult() throws IOException { | ||
Network network = VoltageControlNetworkFactory.createNetworkWithT2wt(); | ||
String t2wtId = "T2wT"; | ||
RatioTapChanger rtc = network.getTwoWindingsTransformer(t2wtId).getRatioTapChanger() | ||
.setTargetDeadband(0) | ||
.setRegulating(true); | ||
|
||
// add transformer as variable for target V update | ||
OpenReacAmplIOFiles io = getIOWithMockVoltageProfile(network); | ||
io.getNetworkModifications().getTapPositionModifications().add(new RatioTapPositionModification(t2wtId, 0)); | ||
|
||
OpenReacResult results = new OpenReacResult(OpenReacStatus.OK, io, new HashMap<>()); | ||
IllegalStateException e = assertThrows(IllegalStateException.class, () -> results.applyAllModifications(network)); | ||
assertEquals("Voltage profile not found for bus " + rtc.getRegulationTerminal().getBusView().getBus().getId(), e.getMessage()); | ||
} | ||
|
||
@Test | ||
void testTransformerTargetVUpdateWithoutRegulationBus() throws IOException { | ||
Network network = VoltageControlNetworkFactory.createNetworkWithT2wt(); | ||
String t2wtId = "T2wT"; | ||
RatioTapChanger rtc = network.getTwoWindingsTransformer(t2wtId).getRatioTapChanger() | ||
.setTargetDeadband(0) | ||
.setRegulating(true); | ||
rtc.getRegulationTerminal().disconnect(); | ||
|
||
// add transformer as variable for target V update | ||
OpenReacAmplIOFiles io = getIOWithMockVoltageProfile(network); | ||
io.getNetworkModifications().getTapPositionModifications().add(new RatioTapPositionModification(t2wtId, 0)); | ||
|
||
// apply results without warm start (to avoid exception) | ||
OpenReacResult results = new OpenReacResult(OpenReacStatus.OK, io, new HashMap<>()); | ||
results.setUpdateNetworkWithVoltages(false); | ||
results.applyAllModifications(network); | ||
|
||
// target V is not updated | ||
assertEquals(33, rtc.getTargetV()); | ||
} | ||
|
||
@Test | ||
void testShuntTargetVUpdateWithoutVoltageResult() throws IOException { | ||
Network network = ShuntNetworkFactory.create(); | ||
ShuntCompensator shunt = network.getShuntCompensator("SHUNT"); | ||
String regulatedBusId = shunt.getRegulatingTerminal().getBusView().getBus().getId(); | ||
|
||
OpenReacAmplIOFiles io = getIOWithMockVoltageProfile(network); | ||
io.getNetworkModifications().getShuntModifications().add(new ShuntCompensatorModification("SHUNT", true, 0)); | ||
|
||
OpenReacResult results = new OpenReacResult(OpenReacStatus.OK, io, new HashMap<>()); | ||
IllegalStateException e = assertThrows(IllegalStateException.class, () -> results.applyAllModifications(network)); | ||
assertEquals("Voltage profile not found for bus " + regulatedBusId, e.getMessage()); | ||
} | ||
|
||
@Test | ||
void testShuntUpdateWithoutRegulationBus() throws IOException { | ||
Network network = ShuntNetworkFactory.create(); | ||
ShuntCompensator shunt = network.getShuntCompensator("SHUNT"); | ||
shunt.getRegulatingTerminal().disconnect(); | ||
|
||
OpenReacAmplIOFiles io = getIOWithMockVoltageProfile(network); | ||
io.getNetworkModifications().getShuntModifications().add(new ShuntCompensatorModification("SHUNT", null, 0)); | ||
|
||
// apply results without warm start | ||
OpenReacResult results = new OpenReacResult(OpenReacStatus.OK, io, new HashMap<>()); | ||
results.setUpdateNetworkWithVoltages(false); | ||
results.applyAllModifications(network); | ||
|
||
// target V not updated | ||
assertEquals(393, shunt.getTargetV()); | ||
} | ||
|
||
@Test | ||
void testWrongVoltageResult() throws IOException { | ||
Network network = IeeeCdfNetworkFactory.create14(); | ||
OpenReacAmplIOFiles io = getIOWithMockVoltageProfile(network); | ||
String idBusNotFound = io.getVoltageProfileOutput().getVoltageProfile().keySet().iterator().next(); | ||
OpenReacResult results = new OpenReacResult(OpenReacStatus.OK, io, new HashMap<>()); | ||
IllegalStateException e = assertThrows(IllegalStateException.class, () -> results.applyAllModifications(network)); | ||
assertEquals("Bus " + idBusNotFound + " not found in network " + network.getId(), e.getMessage()); | ||
} | ||
|
||
private OpenReacAmplIOFiles getIOWithMockVoltageProfile(Network network) throws IOException { | ||
OpenReacAmplIOFiles io = new OpenReacAmplIOFiles(new OpenReacParameters(), network, true); | ||
try (InputStream input = getClass().getResourceAsStream("/mock_outputs/reactiveopf_results_voltages.csv"); | ||
InputStreamReader in = new InputStreamReader(input); | ||
BufferedReader reader = new BufferedReader(in)) { | ||
io.getVoltageProfileOutput().read(reader, null); | ||
} | ||
return io; | ||
} | ||
} |
Oops, something went wrong.