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

Introduce ScalingParameters for Scalable #2461

Merged
merged 10 commits into from
Mar 15, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,10 @@ public double minimumValue(Network n, ScalingConvention powerConvention) {
return value;
}

@Override
public double scale(Network n, double asked) {
return scale(n, asked, ScalingConvention.GENERATOR);
}

@Override
public void filterInjections(Network n, List<Injection> injections, List<String> notFoundInjections) {
for (Scalable scalable : getScalables()) {
scalable.filterInjections(n, injections, notFoundInjections);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,4 @@ public double minimumValue(Network n) {
return minimumValue(n, ScalingConvention.GENERATOR);
}

@Override
public double scale(Network n, double asked) {
return scale(n, asked, ScalingConvention.GENERATOR);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ public void filterInjections(Network n, List<Injection> injections, List<String>
* If scalingConvention is GENERATOR, the load active power decreases for positive "asked" and increases inversely
*/
@Override
public double scale(Network n, double asked, Scalable.ScalingConvention scalingConvention) {
public double scale(Network n, double asked, ScalingParameters parameters) {
Objects.requireNonNull(n);
Objects.requireNonNull(scalingConvention);
Objects.requireNonNull(parameters);

DanglingLine dl = n.getDanglingLine(id);

Expand All @@ -122,7 +122,7 @@ public double scale(Network n, double asked, Scalable.ScalingConvention scalingC
}

Terminal t = dl.getTerminal();
if (!t.isConnected()) {
if (!t.isConnected() && parameters.isReconnect()) {
t.connect();
LOGGER.info("Connecting {}", dl.getId());
}
Expand All @@ -138,7 +138,7 @@ public double scale(Network n, double asked, Scalable.ScalingConvention scalingC
double availableDown = oldP0 - minValue;
double availableUp = maxValue - oldP0;

if (scalingConvention == LOAD) {
if (parameters.getScalingConvention() == LOAD) {
done = asked > 0 ? Math.min(asked, availableUp) : -Math.min(-asked, availableDown);
dl.setP0(oldP0 + done);
} else {
Expand All @@ -161,9 +161,4 @@ public double maximumValue(Network n) {
public double minimumValue(Network n) {
return minimumValue(n, scalingConvention);
}

@Override
public double scale(Network n, double asked) {
return scale(n, asked, scalingConvention);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ public void filterInjections(Network n, List<Injection> injections, List<String>
* If scalingConvention is LOAD, the generator active power decreases for positive "asked" and increases inversely
*/
@Override
public double scale(Network n, double asked, ScalingConvention scalingConvention) {
public double scale(Network n, double asked, ScalingParameters parameters) {
Objects.requireNonNull(n);
Objects.requireNonNull(scalingConvention);
Objects.requireNonNull(parameters);

Generator g = n.getGenerator(id);
double done = 0;
Expand All @@ -118,7 +118,7 @@ public double scale(Network n, double asked, ScalingConvention scalingConvention
}

Terminal t = g.getTerminal();
if (!t.isConnected()) {
if (!t.isConnected() && parameters.isReconnect()) {
new ConnectGenerator(g.getId()).apply(n);
LOGGER.info("Connecting {}", g.getId());
}
Expand All @@ -136,7 +136,7 @@ public double scale(Network n, double asked, ScalingConvention scalingConvention
double availableUp = maximumTargetP - oldTargetP;
double availableDown = oldTargetP - minimumTargetP;

if (scalingConvention == GENERATOR) {
if (parameters.getScalingConvention() == GENERATOR) {
done = asked > 0 ? Math.min(asked, availableUp) : -Math.min(-asked, availableDown);
g.setTargetP(oldTargetP + done);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ public void filterInjections(Network n, List<Injection> injections, List<String>
}
}

private double scale(Network n, double asked, ScalingConvention scalingConvention, boolean constantPowerFactor) {
@Override
public double scale(Network n, double asked, ScalingParameters parameters) {
Objects.requireNonNull(n);
Objects.requireNonNull(scalingConvention);
Objects.requireNonNull(parameters);

Load l = n.getLoad(id);

Expand All @@ -108,7 +109,7 @@ private double scale(Network n, double asked, ScalingConvention scalingConventio
}

Terminal t = l.getTerminal();
if (!t.isConnected()) {
if (!t.isConnected() && parameters.isReconnect()) {
t.connect();
LOGGER.info("Connecting {}", l.getId());
}
Expand All @@ -125,7 +126,7 @@ private double scale(Network n, double asked, ScalingConvention scalingConventio
double availableDown = oldP0 - minValue;
double availableUp = maxValue - oldP0;

if (scalingConvention == LOAD) {
if (parameters.getScalingConvention() == LOAD) {
done = asked > 0 ? Math.min(asked, availableUp) : -Math.min(-asked, availableDown);
l.setP0(oldP0 + done);
} else {
Expand All @@ -136,7 +137,7 @@ private double scale(Network n, double asked, ScalingConvention scalingConventio
LOGGER.info("Change active power setpoint of {} from {} to {} ",
l.getId(), oldP0, l.getP0());

if (constantPowerFactor) {
if (parameters.isConstantPowerFactor()) {
l.setQ0(l.getP0() * oldQ0 / oldP0);
LOGGER.info("Change reactive power setpoint of {} from {} to {} ",
l.getId(), oldQ0, l.getQ0());
Expand All @@ -145,24 +146,4 @@ private double scale(Network n, double asked, ScalingConvention scalingConventio
return done;
}

/**
* {@inheritDoc}
*
* If scalingConvention is LOAD, the load active power increases for positive "asked" and decreases inversely
* If scalingConvention is GENERATOR, the load active power decreases for positive "asked" and increases inversely
*/
@Override
public double scale(Network n, double asked, ScalingConvention scalingConvention) {
return scale(n, asked, scalingConvention, false);
}

@Override
public double scaleWithConstantPowerFactor(Network n, double asked, ScalingConvention scalingConvention) {
return scale(n, asked, scalingConvention, true);
}

@Override
public double scaleWithConstantPowerFactor(Network n, double asked) {
return scaleWithConstantPowerFactor(n, asked, ScalingConvention.GENERATOR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

/**
* Scalable that divides scale proportionally between multiple scalable.
* Scale may be iterative or not.
* If the iterative mode is activated, the residues due to scalable saturation is divided between the
* other scalable composing the ProportionalScalable.
*
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
* @author Sebastien Murgey {@literal <sebastien.murgey at rte-france.com>}
Expand Down Expand Up @@ -64,19 +61,12 @@ void setIterationPercentage(double iterationPercentage) {

private final List<ScalablePercentage> scalablePercentageList;

private final boolean iterative;

ProportionalScalable(List<Float> percentages, List<Scalable> scalables) {
this(percentages, scalables, false);
}

ProportionalScalable(List<Float> percentages, List<Scalable> scalables, boolean iterative) {
checkPercentages(percentages, scalables);
this.scalablePercentageList = new ArrayList<>();
for (int i = 0; i < scalables.size(); i++) {
this.scalablePercentageList.add(new ScalablePercentage(scalables.get(i), percentages.get(i)));
}
this.iterative = iterative;
}

Collection<Scalable> getScalables() {
Expand Down Expand Up @@ -122,28 +112,24 @@ private void updateIterationPercentages() {
});
}

private double iterativeScale(Network n, double asked, ScalingConvention scalingConvention, boolean constantPowerFactor) {
private double iterativeScale(Network n, double asked, ScalingParameters parameters) {
double done = 0;
while (Math.abs(asked - done) > EPSILON && notSaturated()) {
checkIterationPercentages();
done += scaleIteration(n, asked - done, scalingConvention, constantPowerFactor);
done += scaleIteration(n, asked - done, parameters);
updateIterationPercentages();
}
return done;
}

private double scaleIteration(Network n, double asked, ScalingConvention scalingConvention, boolean constantPowerFactor) {
private double scaleIteration(Network n, double asked, ScalingParameters parameters) {
double done = 0;
for (ScalablePercentage scalablePercentage : scalablePercentageList) {
Scalable s = scalablePercentage.getScalable();
double iterationPercentage = scalablePercentage.getIterationPercentage();
double askedOnScalable = iterationPercentage / 100 * asked;
double doneOnScalable = 0;
if (constantPowerFactor) {
doneOnScalable = s.scaleWithConstantPowerFactor(n, askedOnScalable, scalingConvention);
} else {
doneOnScalable = s.scale(n, askedOnScalable, scalingConvention);
}
doneOnScalable = s.scale(n, askedOnScalable, parameters);
if (Math.abs(doneOnScalable - askedOnScalable) > EPSILON) {
scalablePercentage.setIterationPercentage(0);
}
Expand All @@ -153,31 +139,14 @@ private double scaleIteration(Network n, double asked, ScalingConvention scaling
}

@Override
public double scaleWithConstantPowerFactor(Network n, double asked) {
return scaleWithConstantPowerFactor(n, asked, ScalingConvention.GENERATOR);
}

@Override
public double scaleWithConstantPowerFactor(Network n, double asked, ScalingConvention scalingConvention) {
Objects.requireNonNull(n);
Objects.requireNonNull(scalingConvention);
reinitIterationPercentage();
if (iterative) {
return iterativeScale(n, asked, scalingConvention, true);
} else {
return scaleIteration(n, asked, scalingConvention, true);
}
}

@Override
public double scale(Network n, double asked, ScalingConvention scalingConvention) {
public double scale(Network n, double asked, ScalingParameters parameters) {
Objects.requireNonNull(n);
Objects.requireNonNull(scalingConvention);
Objects.requireNonNull(parameters);
reinitIterationPercentage();
if (iterative) {
return iterativeScale(n, asked, scalingConvention, false);
if (parameters.isIterative()) {
return iterativeScale(n, asked, parameters);
} else {
return scaleIteration(n, asked, scalingConvention, false);
return scaleIteration(n, asked, parameters);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,43 +134,10 @@ enum ScalingConvention {
* @param asked value asked to adjust the scalable active power
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add param annotation in the javadoc for the new parameter

* @return the actual value of the scalable active power adjustment
*/
double scale(Network n, double asked);
double scale(Network n, double asked, ScalingParameters parameters);

/**
* Scale the given network.
* The actual scaling value may be different to the one asked, if
* the Scalable limit is reached.
*
* @param n network
* @param asked value asked to adjust the scalable active power
* @param scalingConvention power convention used for scaling
* @return the actual value of the scalable active power adjustment
* @see ScalingConvention
*/
double scale(Network n, double asked, ScalingConvention scalingConvention);

/**
* Scale the given network using Generator convention by default.
* If the object is a load, scaling is done with constant power factor.
* @param n network
* @param asked value asked to adjust the scalable active power and reactive power if load
* @return the actual value of the scalable active power adjustment
*/
default double scaleWithConstantPowerFactor(Network n, double asked) {
return scale(n, asked);
}

/**
* Scale the given network.
* The actual scaling value may be different to the one asked, if
* the Scalable limit is reached. If the Scalable is a load, the power factor is kept constant.
* @param n network
* @param asked value asked to adjust the scalable active power and reactive power if load
* @param scalingConvention power convention used for scaling
* @return the actual value of the scalable active power adjustment
*/
default double scaleWithConstantPowerFactor(Network n, double asked, ScalingConvention scalingConvention) {
return scale(n, asked, scalingConvention);
default double scale(Network n, double asked) {
return scale(n, asked, new ScalingParameters());
}

/**
Expand Down Expand Up @@ -251,10 +218,6 @@ static ProportionalScalable proportional(List<Float> percentages, List<Scalable>
return new ProportionalScalable(percentages, scalables);
}

static ProportionalScalable proportional(List<Float> percentages, List<Scalable> scalables, boolean iterative) {
return new ProportionalScalable(percentages, scalables, iterative);
}

static ProportionalScalable proportional(float percentage, Scalable scalable) {
return new ProportionalScalable(Collections.singletonList(percentage), Collections.singletonList(scalable));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void filterInjections(Network network, List<Injection> injections, List<S
}

@Override
public double scale(Network n, double asked, ScalingConvention scalingConvention) {
return getScalable(n).scale(n, asked, scalingConvention);
public double scale(Network n, double asked, ScalingParameters parameters) {
return getScalable(n).scale(n, asked, parameters);
}
}
Loading