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

Fix per united susceptance in shunt modifications #73

Merged
merged 6 commits into from
Jun 27, 2024
Merged
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 @@ -6,19 +6,25 @@
*/
package com.powsybl.openreac.parameters.output.network;

import com.powsybl.ampl.converter.AmplConstants;
import com.powsybl.ampl.converter.AmplSubset;
import com.powsybl.commons.util.StringToIntMapper;
import com.powsybl.iidm.modification.ShuntCompensatorModification;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.ShuntCompensator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* @author Nicolas Pierre {@literal <nicolas.pierre at artelys.com>}
*/
public class ShuntCompensatorNetworkOutput extends AbstractNetworkOutput<ShuntCompensatorModification> {

private static final Logger LOGGER = LoggerFactory.getLogger(ShuntCompensatorNetworkOutput.class);
private static final String ELEMENT = "shunts";
public static final int EXPECTED_COLS = 6;
private static final int ID_COLUMN_INDEX = 1;
Expand Down Expand Up @@ -47,15 +53,18 @@ public int getExpectedColumns() {
@Override
protected void readLine(String[] tokens, StringToIntMapper<AmplSubset> stringToIntMapper) {
String id = stringToIntMapper.getId(AmplSubset.SHUNT, Integer.parseInt(tokens[ID_COLUMN_INDEX]));
double b = readDouble(tokens[B_COLUMN_INDEX]);
String busId = stringToIntMapper.getId(AmplSubset.BUS, Integer.parseInt(tokens[BUS_COLUMN_INDEX]));
Boolean reconnect = null;
ShuntCompensator shuntCompensator = network.getShuntCompensator(id);
if (busId != null && shuntCompensator != null && busId.equals(
shuntCompensator.getTerminal().getBusView().getConnectableBus().getId())) {
reconnect = true;
if (!Objects.isNull(shuntCompensator)) {
double b = readDouble(tokens[B_COLUMN_INDEX]) * AmplConstants.SB / Math.pow(shuntCompensator.getTerminal().getVoltageLevel().getNominalV(), 2);
String busId = stringToIntMapper.getId(AmplSubset.BUS, Integer.parseInt(tokens[BUS_COLUMN_INDEX]));
Boolean reconnect = null;
if (busId != null && busId.equals(shuntCompensator.getTerminal().getBusView().getConnectableBus().getId())) {
reconnect = true;
}
modifications.add(new ShuntCompensatorModification(id, reconnect, findSectionCount(shuntCompensator, b)));
} else {
LOGGER.warn("Shunt compensator with id {} not found in the network", id);
}
modifications.add(new ShuntCompensatorModification(id, reconnect, shuntCompensator == null ? null : findSectionCount(shuntCompensator, b)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ void testShunt() throws IOException {
values = reportShunts.getChildren().get(1).getValues();
assertEquals("SHUNT", values.get("shuntCompensatorId").toString());
assertEquals("25", values.get("maxSectionCount").toString());
assertEquals("2080.0", values.get("discretizedValue").toString());
assertEquals("2128.0", values.get("optimalValue").toString());
assertEquals("160.0", values.get("discretizedValue").toString());
assertEquals("123.4", values.get("optimalValue").toString());
assertEquals(TypedValue.TRACE_SEVERITY.getValue(), values.get("reportSeverity").toString());

assertTrue(shunt.getTerminal().isConnected()); // shunt has been reconnected
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.openreac.parameters.output;

import com.powsybl.ampl.converter.AmplSubset;
import com.powsybl.commons.util.StringToIntMapper;
import com.powsybl.iidm.network.Network;
import com.powsybl.openreac.parameters.output.network.ShuntCompensatorNetworkOutput;
import org.junit.jupiter.api.Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import static com.powsybl.openreac.network.ShuntNetworkFactory.create;
import static org.junit.jupiter.api.Assertions.*;

/**
* @author Pierre Arvy {@literal <pierre.arvy at artelys.com>}
*/
class ShuntCompensatorNetworkOutputTest {
@Test
void read() throws IOException {
Network network = create();
ShuntCompensatorNetworkOutput output = new ShuntCompensatorNetworkOutput(network, 0);
StringToIntMapper<AmplSubset> mapper = new StringToIntMapper<>(AmplSubset.class);
mapper.newInt(AmplSubset.SHUNT, "SHUNT");
for (int i = 0; i < 7; i++) {
mapper.newInt(AmplSubset.BUS, "BUS" + i);
}
try (InputStream input = getClass().getResourceAsStream("/mock_outputs/reactiveopf_results_shunts.csv");
InputStreamReader in = new InputStreamReader(input);
BufferedReader reader = new BufferedReader(in)) {
output.read(reader, mapper);
assertEquals(1, output.getModifications().size());
assertEquals("SHUNT", output.getModifications().get(0).getShuntCompensatorId());
assertNull(output.getModifications().get(0).getConnect());
assertEquals(0, output.getModifications().get(0).getSectionCount());
}
}

@Test
void readNullShuntCompensator() throws IOException {
Network network = create();
ShuntCompensatorNetworkOutput output = new ShuntCompensatorNetworkOutput(network, 0);
StringToIntMapper<AmplSubset> mapper = new StringToIntMapper<>(AmplSubset.class);
mapper.newInt(AmplSubset.SHUNT, "wrongId");
for (int i = 0; i < 7; i++) {
mapper.newInt(AmplSubset.BUS, "BUS" + i);
}
try (InputStream input = getClass().getResourceAsStream("/mock_outputs/reactiveopf_results_shunts.csv");
InputStreamReader in = new InputStreamReader(input);
BufferedReader reader = new BufferedReader(in)) {
output.read(reader, mapper);
assertEquals(0, output.getModifications().size());
}
}

@Test
void noShuntNumberInMapper() throws IOException {
Network network = create();
ShuntCompensatorNetworkOutput output = new ShuntCompensatorNetworkOutput(network, 0);
StringToIntMapper<AmplSubset> mapper = new StringToIntMapper<>(AmplSubset.class);
try (InputStream input = getClass().getResourceAsStream("/mock_outputs/reactiveopf_results_shunts.csv");
InputStreamReader in = new InputStreamReader(input);
BufferedReader reader = new BufferedReader(in)) {
assertThrows(IllegalArgumentException.class, () -> output.read(reader, mapper));
}
}

@Test
void noBusNumberInMapper() throws IOException {
Network network = create();
ShuntCompensatorNetworkOutput output = new ShuntCompensatorNetworkOutput(network, 0);
StringToIntMapper<AmplSubset> mapper = new StringToIntMapper<>(AmplSubset.class);
mapper.newInt(AmplSubset.SHUNT, "SHUNT");
try (InputStream input = getClass().getResourceAsStream("/mock_outputs/reactiveopf_results_shunts.csv");
InputStreamReader in = new InputStreamReader(input);
BufferedReader reader = new BufferedReader(in)) {
assertThrows(IllegalArgumentException.class, () -> output.read(reader, mapper));
}
}

}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#variant;num;bus;b(pu);Q(Mvar);section;
1;1;3;0.0133;136.453;0;
1;1;3;1.234;136.453;0;
Loading