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

Battery modification #2625

Merged
merged 8 commits into from
Jul 6, 2023
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
@@ -0,0 +1,87 @@
/**
* Copyright (c) 2023, 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.iidm.modification;

import com.powsybl.commons.reporter.Reporter;
import com.powsybl.computation.ComputationManager;
import com.powsybl.iidm.network.Network;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;
import java.util.OptionalDouble;

/**
* Simple {@link NetworkModification} for elements that needs to modify
* their voltage and reactive setpoints. This is used for SVCs and for VSC
* converter stations. Note that a VSC converter station follows a generator
* convention but SVCs follow a load convention.
*
* @author Nicolas PIERRE <nicolas.pierre at artelys.com>
*/
public abstract class AbstractSetpointModification<T> extends AbstractNetworkModification {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractSetpointModification.class);

private final String elementId;
private final Double voltageSetpoint;
private final Double reactivePowerSetpoint;

protected AbstractSetpointModification(String elementId, Double voltageSetpoint, Double reactivePowerSetpoint) {
if (voltageSetpoint == null && reactivePowerSetpoint == null) {
LOGGER.warn("Creating a {} modification with no modification", getElementName());
}
this.elementId = Objects.requireNonNull(elementId);
this.voltageSetpoint = voltageSetpoint;
this.reactivePowerSetpoint = reactivePowerSetpoint;
}

@Override
public void apply(Network network, boolean throwException, ComputationManager computationManager,
Reporter reporter) {
T networkElement = getNetworkElement(network, elementId);

if (networkElement == null) {
logOrThrow(throwException, getElementName() + " '" + elementId + "' not found");
return;
}
if (voltageSetpoint != null) {
setVoltageSetpoint(networkElement, voltageSetpoint);
}
if (reactivePowerSetpoint != null) {
setReactivePowerSetpoint(networkElement, reactivePowerSetpoint);
}
}

public abstract String getElementName();

protected abstract void setVoltageSetpoint(T networkElement, Double voltageSetpoint);

protected abstract void setReactivePowerSetpoint(T networkElement, Double reactivePowerSetpoint);

public abstract T getNetworkElement(Network network, String elementID);

protected String getElementId() {
return elementId;
}

public Double getReactivePowerSetpoint() {
return reactivePowerSetpoint;
}

public OptionalDouble getOptionalReactivePowerSetpoint() {
return reactivePowerSetpoint == null ? OptionalDouble.empty() : OptionalDouble.of(reactivePowerSetpoint);
}

public Double getVoltageSetpoint() {
return voltageSetpoint;
}

public OptionalDouble getOptionalVoltageSetpoint() {
return voltageSetpoint == null ? OptionalDouble.empty() : OptionalDouble.of(voltageSetpoint);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Copyright (c) 2023, 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.iidm.modification;

import com.powsybl.commons.reporter.Reporter;
import com.powsybl.computation.ComputationManager;
import com.powsybl.iidm.network.Battery;
import com.powsybl.iidm.network.Network;

import java.util.Objects;

/**
* Simple {@link NetworkModification} for a battery.
*
* @author Nicolas PIERRE <nicolas.pierre at artelys.com>
*/
public class BatteryModification extends AbstractNetworkModification {

private final String batteryId;
private final Double targetQ;
private final Double targetP;

public BatteryModification(String batteryId, Double targetP, Double targetQ) {
this.batteryId = Objects.requireNonNull(batteryId);
this.targetP = targetP;
this.targetQ = targetQ;
}

@Override
public void apply(Network network, boolean throwException, ComputationManager computationManager,
Reporter reporter) {
Battery battery = network.getBattery(batteryId);
if (battery == null) {
logOrThrow(throwException, "Battery '" + batteryId + "' not found");
return;
}
if (targetP != null) {
battery.setTargetP(targetP);
}
if (targetQ != null) {
battery.setTargetQ(targetQ);
}
}

public String getBatteryId() {
return batteryId;
}

public Double getTargetP() {
return targetP;
}

public Double getTargetQ() {
return targetQ;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,73 +6,41 @@
*/
package com.powsybl.iidm.modification;

import com.powsybl.commons.reporter.Reporter;
import com.powsybl.computation.ComputationManager;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.StaticVarCompensator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;
import java.util.OptionalDouble;

/**
* Simple {@link NetworkModification} for static var compensator.
* Simple {@link NetworkModification} for a static var compensator.
*
* @author Nicolas PIERRE <nicolas.pierre at artelys.com>
*/
public class StaticVarCompensatorModification extends AbstractNetworkModification {

private static final Logger LOGGER = LoggerFactory.getLogger(StaticVarCompensatorModification.class);

private final String svcId;
private final Double voltageSetpoint;
private final Double reactivePowerSetpoint;
public class StaticVarCompensatorModification extends AbstractSetpointModification<StaticVarCompensator> {

public StaticVarCompensatorModification(String svcId, Double voltageSetpoint,
Double reactivePowerSetpoint) {
if (voltageSetpoint == null && reactivePowerSetpoint == null) {
LOGGER.warn("Creating a VscConverterStationModification with no change !");
}
this.svcId = Objects.requireNonNull(svcId);
this.voltageSetpoint = voltageSetpoint;
this.reactivePowerSetpoint = reactivePowerSetpoint;
public StaticVarCompensatorModification(String elementId, Double voltageSetpoint, Double reactivePowerSetpoint) {
super(elementId, voltageSetpoint, reactivePowerSetpoint);
}

@Override
public void apply(Network network, boolean throwException, ComputationManager computationManager,
Reporter reporter) {
StaticVarCompensator svc = network.getStaticVarCompensator(svcId);

if (svc == null) {
logOrThrow(throwException, "StaticVarcompensator '" + svcId + "' not found");
return;
}
if (voltageSetpoint != null) {
svc.setVoltageSetpoint(voltageSetpoint);
}
if (reactivePowerSetpoint != null) {
svc.setReactivePowerSetpoint(reactivePowerSetpoint);
}
public String getElementName() {
return "StaticVarCompensator";
}

public String getSvcId() {
return svcId;
}

public Double getReactivePowerSetpoint() {
return reactivePowerSetpoint;
@Override
protected void setVoltageSetpoint(StaticVarCompensator networkElement, Double voltageSetpoint) {
networkElement.setVoltageSetpoint(voltageSetpoint);
}

public OptionalDouble getOptionalReactivePowerSetpoint() {
return reactivePowerSetpoint == null ? OptionalDouble.empty() : OptionalDouble.of(reactivePowerSetpoint);
@Override
protected void setReactivePowerSetpoint(StaticVarCompensator networkElement, Double reactivePowerSetpoint) {
networkElement.setReactivePowerSetpoint(reactivePowerSetpoint);
}

public Double getVoltageSetpoint() {
return voltageSetpoint;
@Override
public StaticVarCompensator getNetworkElement(Network network, String elementID) {
return network.getStaticVarCompensator(elementID);
}

public OptionalDouble getOptionalVoltageSetpoint() {
return voltageSetpoint == null ? OptionalDouble.empty() : OptionalDouble.of(voltageSetpoint);
public String getStaticVarCompensatorId() {
return getElementId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,73 +6,41 @@
*/
package com.powsybl.iidm.modification;

import com.powsybl.commons.reporter.Reporter;
import com.powsybl.computation.ComputationManager;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.VscConverterStation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;
import java.util.OptionalDouble;

/**
* Simple {@link NetworkModification} for vsc converter stations.
* Simple {@link NetworkModification} for a VSC converter station.
*
* @author Nicolas PIERRE <nicolas.pierre at artelys.com>
*/
public class VscConverterStationModification extends AbstractNetworkModification {

private static final Logger LOGGER = LoggerFactory.getLogger(VscConverterStationModification.class);

private final String vscId;
private final Double voltageSetpoint;
private final Double reactivePowerSetpoint;
public class VscConverterStationModification extends AbstractSetpointModification<VscConverterStation> {

public VscConverterStationModification(String vscId, Double voltageSetpoint,
Double reactivePowerSetpoint) {
if (voltageSetpoint == null && reactivePowerSetpoint == null) {
LOGGER.warn("Creating a VscConverterStationModification with no change !");
}
this.vscId = Objects.requireNonNull(vscId);
this.voltageSetpoint = voltageSetpoint;
this.reactivePowerSetpoint = reactivePowerSetpoint;
public VscConverterStationModification(String elementId, Double voltageSetpoint, Double reactivePowerSetpoint) {
super(elementId, voltageSetpoint, reactivePowerSetpoint);
}

@Override
public void apply(Network network, boolean throwException, ComputationManager computationManager,
Reporter reporter) {
VscConverterStation vsc = network.getVscConverterStation(vscId);

if (vsc == null) {
logOrThrow(throwException, "VscConverterStation '" + vscId + "' not found");
return;
}
if (voltageSetpoint != null) {
vsc.setVoltageSetpoint(voltageSetpoint);
}
if (reactivePowerSetpoint != null) {
vsc.setReactivePowerSetpoint(reactivePowerSetpoint);
}
public String getElementName() {
return "VscConverterStation";
}

public String getVscId() {
return vscId;
}

public Double getReactivePowerSetpoint() {
return reactivePowerSetpoint;
@Override
protected void setVoltageSetpoint(VscConverterStation networkElement, Double voltageSetpoint) {
networkElement.setVoltageSetpoint(voltageSetpoint);
}

public OptionalDouble getOptionalReactivePowerSetpoint() {
return reactivePowerSetpoint == null ? OptionalDouble.empty() : OptionalDouble.of(reactivePowerSetpoint);
@Override
protected void setReactivePowerSetpoint(VscConverterStation networkElement, Double reactivePowerSetpoint) {
networkElement.setReactivePowerSetpoint(reactivePowerSetpoint);
}

public Double getVoltageSetpoint() {
return voltageSetpoint;
@Override
public VscConverterStation getNetworkElement(Network network, String elementID) {
return network.getVscConverterStation(elementID);
}

public OptionalDouble getOptionalVoltageSetpoint() {
return voltageSetpoint == null ? OptionalDouble.empty() : OptionalDouble.of(voltageSetpoint);
public String getVscConverterStationId() {
return getElementId();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (c) 2023, 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.iidm.modification;

import com.powsybl.iidm.network.Battery;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.test.BatteryNetworkFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @author Nicolas PIERRE <nicolas.pierre at artelys.com>
*/
class TestBatteryModification {

private Network network;
private Battery battery;

@BeforeEach
public void setUp() {
network = BatteryNetworkFactory.create();
assertTrue(network.getBatteryCount() > 0);
battery = network.getBatteries().iterator().next();
battery.setTargetQ(0);
}

@Test
void testBatteryModification() {
BatteryModification batteryModification = new BatteryModification(battery.getId(), 1.0, null);
assertEquals(9999.99, battery.getTargetP());
batteryModification.apply(network);
assertEquals(1., battery.getTargetP());

BatteryModification batteryModification2 = new BatteryModification(battery.getId(), null, 2.0);
assertEquals(0, battery.getTargetQ());
batteryModification2.apply(network);
assertEquals(2., battery.getTargetQ());
}
}