Skip to content

Commit

Permalink
review remarks
Browse files Browse the repository at this point in the history
Signed-off-by: Didier Vidal <didier.vidal_externe@rte-france.com>
  • Loading branch information
vidaldid-rte committed Jun 27, 2024
1 parent d944023 commit 0336456
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ default String getName() {
OptionalDouble getMinTargetP();

/**
* Sets the overridden minimal active power.
* Sets the minimum value for targetP. The value must be in the [pmin,pmax] interval of the extended
* generator or battery.
* @param minTargetP The overridden value of minP. A Nan value removes the override.
*/
void setMinTargetP(double minTargetP);
Expand All @@ -73,7 +74,8 @@ default String getName() {
OptionalDouble getMaxTargetP();

/**
* Sets the overridden maximal active power.
* Sets the maximum value for targetP. The value must be in the [pmin,pmax] interval of the extended
* generator or battery.
* @param maxTargetP The overridden value of maxP. A Nan value removes the override.
*/
void setMaxTargetP(double maxTargetP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ public ActivePowerControlImpl(T component,
this.minTargetP = new TDoubleArrayList(variantArraySize);
this.maxTargetP = new TDoubleArrayList(variantArraySize);
this.allTDoubleArrayLists = List.of(this.droop, this.participationFactor, this.minTargetP, this.maxTargetP);
double checkedMinTargetP = checkTargetPLimit(minTargetP, "minTargetP", component);
double checkedMaxTargetP = checkTargetPLimit(maxTargetP, "maxTargetP", component);
for (int i = 0; i < variantArraySize; i++) {
this.participate.add(participate);
this.droop.add(droop);
this.participationFactor.add(participationFactor);
this.minTargetP.add(checkTargetPLimit(minTargetP, "minTargetP", component));
this.maxTargetP.add(checkTargetPLimit(maxTargetP, "maxTargetP", component));
this.minTargetP.add(checkedMinTargetP);
this.maxTargetP.add(checkedMaxTargetP);
}
checkTargetPLimits(minTargetP, maxTargetP);
checkLimitOrder(minTargetP, maxTargetP);
}

record PLimits(double minP, double maxP) { }
Expand All @@ -77,8 +79,7 @@ private PLimits getPLimits(T injection) {
if (injection instanceof Generator generator) {
maxP = generator.getMaxP();
minP = generator.getMinP();
}
if (injection instanceof Battery battery) {
} else if (injection instanceof Battery battery) {
maxP = battery.getMaxP();
minP = battery.getMinP();
}
Expand All @@ -88,7 +89,9 @@ private PLimits getPLimits(T injection) {
private double withinPMinMax(double value, T injection) {
PLimits pLimits = getPLimits(injection);

if (!Double.isNaN(value) && (value < pLimits.minP || value > pLimits.maxP)) {
// The test always returns false if value is undefined (Double.Nan) as it should,
// as side effect of Nan arithmetic operators Nan handling, as they are used below.
if (value < pLimits.minP || value > pLimits.maxP) {
LOGGER.warn("targetP limit is now outside of pMin,pMax for component " + injection.getId() + ". Returning closest value in [pmin,pMax].");
return value < pLimits.minP ? pLimits.minP : pLimits.maxP;
}
Expand All @@ -108,7 +111,7 @@ private double checkTargetPLimit(double targetPLimit, String name, T injection)
return targetPLimit;
}

private void checkTargetPLimits(double minTargetP, double maxTargetP) {
private void checkLimitOrder(double minTargetP, double maxTargetP) {
if (!Double.isNaN(minTargetP) && !Double.isNaN(maxTargetP)) {
if (minTargetP > maxTargetP) {
throw new PowsyblException("invalid targetP limits [" + minTargetP + ", " + maxTargetP + "]");
Expand Down Expand Up @@ -177,7 +180,7 @@ public OptionalDouble getMinTargetP() {

@Override
public void setMinTargetP(double minTargetP) {
checkTargetPLimits(minTargetP, maxTargetP.get(getVariantIndex()));
checkLimitOrder(minTargetP, maxTargetP.get(getVariantIndex()));
this.minTargetP.set(getVariantIndex(), checkTargetPLimit(minTargetP, "minTargetP", getExtendable()));
}

Expand All @@ -189,7 +192,7 @@ public OptionalDouble getMaxTargetP() {

@Override
public void setMaxTargetP(double maxTargetP) {
checkTargetPLimits(minTargetP.get(getVariantIndex()), maxTargetP);
checkLimitOrder(minTargetP.get(getVariantIndex()), maxTargetP);
this.maxTargetP.set(getVariantIndex(), checkTargetPLimit(maxTargetP, "maxTargetP", getExtendable()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void setUp() throws IOException {
}

@Test
void testtargetPLimits() throws IOException {
void testTargetPLimits() throws IOException {
network.getGenerator("GEN").getExtension(ActivePowerControl.class).setMaxTargetP(800.);
network.getBattery("BAT").getExtension(ActivePowerControl.class).setMinTargetP(10.);
Network network2 = allFormatsRoundTripTest(network, "/activePowerControlWithLimitRoundTripRef.xml", CURRENT_IIDM_VERSION);
Expand Down

0 comments on commit 0336456

Please sign in to comment.