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

Proposal for handling UpDown scalable get steady state power instead of throwing exception #2710

Merged
merged 2 commits into from
Sep 21, 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
Expand Up @@ -166,7 +166,7 @@ public double minimumValue(Network n) {
}

@Override
public double getSteadyStatePower(Network network, ScalingConvention scalingConvention) {
public double getSteadyStatePower(Network network, double asked, ScalingConvention scalingConvention) {
DanglingLine line = network.getDanglingLine(id);
if (line == null) {
LOGGER.warn("DanglingLine {} not found", id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public double scale(Network n, double asked, ScalingParameters parameters) {
}

@Override
public double getSteadyStatePower(Network network, ScalingConvention scalingConvention) {
public double getSteadyStatePower(Network network, double asked, ScalingConvention scalingConvention) {
Generator generator = network.getGenerator(id);
if (generator == null) {
LOGGER.warn("Generator {} not found", id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public double scale(Network n, double asked, ScalingParameters parameters) {
}

@Override
public double getSteadyStatePower(Network network, ScalingConvention scalingConvention) {
public double getSteadyStatePower(Network network, double asked, ScalingConvention scalingConvention) {
Load load = network.getLoad(id);
if (load == null) {
LOGGER.warn("Load {} not found", id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public double scale(Network n, double asked, ScalingParameters parameters) {
Objects.requireNonNull(parameters);

// Compute the current power value
double currentGlobalPower = getSteadyStatePower(n, parameters.getScalingConvention());
double currentGlobalPower = getSteadyStatePower(n, asked, parameters.getScalingConvention());

// Variation asked
double variationAsked = Scalable.getVariationAsked(parameters, asked, currentGlobalPower);
Expand Down Expand Up @@ -308,8 +308,8 @@ private void reinitIterationPercentage() {
}

@Override
public double getSteadyStatePower(Network network, ScalingConvention scalingConvention) {
return scalablePercentageList.stream().mapToDouble(scalablePercentage -> scalablePercentage.getScalable().getSteadyStatePower(network, scalingConvention)).sum();
public double getSteadyStatePower(Network network, double asked, ScalingConvention scalingConvention) {
return scalablePercentageList.stream().mapToDouble(scalablePercentage -> scalablePercentage.getScalable().getSteadyStatePower(network, asked, scalingConvention)).sum();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,5 @@ static double getVariationAsked(ScalingParameters scalingParameters, double aske
* @param network Network in which the injections are defined
* @return the current power value
*/
double getSteadyStatePower(Network network, ScalingConvention scalingConvention);
double getSteadyStatePower(Network network, double asked, ScalingConvention scalingConvention);
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public double scale(Network n, double asked, ScalingParameters parameters) {
}

@Override
public double getSteadyStatePower(Network network, ScalingConvention scalingConvention) {
return getScalable(network).getSteadyStatePower(network, scalingConvention);
public double getSteadyStatePower(Network network, double asked, ScalingConvention scalingConvention) {
return getScalable(network).getSteadyStatePower(network, asked, scalingConvention);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public double scale(Network n, double asked, ScalingParameters parameters) {
Objects.requireNonNull(n);

// Compute the current power value
double currentGlobalPower = getSteadyStatePower(n, parameters.getScalingConvention());
double currentGlobalPower = getSteadyStatePower(n, asked, parameters.getScalingConvention());

// Variation asked
double variationAsked = Scalable.getVariationAsked(parameters, asked, currentGlobalPower);
Expand All @@ -57,7 +57,7 @@ public double scale(Network n, double asked, ScalingParameters parameters) {
}

@Override
public double getSteadyStatePower(Network network, ScalingConvention scalingConvention) {
return scalables.stream().mapToDouble(scalable -> scalable.getSteadyStatePower(network, scalingConvention)).sum();
public double getSteadyStatePower(Network network, double asked, ScalingConvention scalingConvention) {
return scalables.stream().mapToDouble(scalable -> scalable.getSteadyStatePower(network, asked, scalingConvention)).sum();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package com.powsybl.iidm.modification.scalable;

import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.Injection;
import com.powsybl.iidm.network.Network;

Expand Down Expand Up @@ -66,7 +65,7 @@ public double scale(Network n, double asked, ScalingParameters parameters) {
}

@Override
public double getSteadyStatePower(Network network, ScalingConvention scalingConvention) {
throw new PowsyblException("getCurrentPower should not be used on UpDownScalable, only on other types of Scalable");
public double getSteadyStatePower(Network network, double asked, ScalingConvention scalingConvention) {
return asked > 0 ? upScalable.getSteadyStatePower(network, asked, scalingConvention) : downScalable.getSteadyStatePower(network, asked, scalingConvention);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package com.powsybl.iidm.modification.scalable;

import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.Injection;
import com.powsybl.iidm.network.Network;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -90,8 +89,14 @@ void checkErrorOnGetCurrentPower() {
Scalable downScalable = Scalable.onLoad("l1", 50, 200);
Scalable upDownScalable = Scalable.upDown(upScalable, downScalable);

// Error raised
PowsyblException e0 = assertThrows(PowsyblException.class, () -> upDownScalable.getSteadyStatePower(testNetwork, Scalable.ScalingConvention.LOAD));
assertEquals("getCurrentPower should not be used on UpDownScalable, only on other types of Scalable", e0.getMessage());
testNetwork.getGenerator("g2").setTargetP(32);
double asked = 1;
assertEquals(-32, upDownScalable.getSteadyStatePower(testNetwork, asked, Scalable.ScalingConvention.LOAD));
assertEquals(32, upDownScalable.getSteadyStatePower(testNetwork, asked, Scalable.ScalingConvention.GENERATOR));

testNetwork.getLoad("l1").setP0(42);
asked = -1;
assertEquals(42, upDownScalable.getSteadyStatePower(testNetwork, asked, Scalable.ScalingConvention.LOAD));
assertEquals(-42, upDownScalable.getSteadyStatePower(testNetwork, asked, Scalable.ScalingConvention.GENERATOR));
}
}