Skip to content

Commit

Permalink
Handling updown scalable get steady state power (#2710)
Browse files Browse the repository at this point in the history
Signed-off-by: Luma <zamarrenolm@aia.es>
  • Loading branch information
zamarrenolm authored Sep 21, 2023
1 parent 3206888 commit 9331edc
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 19 deletions.
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));
}
}

0 comments on commit 9331edc

Please sign in to comment.