Skip to content

Commit

Permalink
Implement pMin and pMax override in ActivePowerControl Extension
Browse files Browse the repository at this point in the history
Signed-off-by: VIDAL Didier (Externe) <didier.vidal_externe@rte-france.com>
  • Loading branch information
vidaldid-rte committed Jun 24, 2024
1 parent c996cd3 commit 53b1117
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public LargestGeneratorSlackBusSelector(double plausibleActivePowerLimit, Set<Co
}

private static double getMaxP(LfBus bus) {
return bus.getGenerators().stream().mapToDouble(LfGenerator::getMaxP).sum();
return bus.getGenerators().stream().mapToDouble(LfGenerator::getActivePowerOperationMaxP).sum();
}

private boolean isGeneratorInvalid(LfGenerator generator) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/powsybl/openloadflow/network/LfAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,9 @@ private void applyGeneratorChange(LfNetworkParameters networkParameters) {
if (!generator.isDisabled()) {
double newTargetP = generatorChange.isRelative() ? generator.getTargetP() + generatorChange.activePowerValue() : generatorChange.activePowerValue();
generator.setTargetP(newTargetP);
if (!AbstractLfGenerator.checkActivePowerControl(generator.getId(), generator.getTargetP(), generator.getMinP(), generator.getMaxP(),
networkParameters.getPlausibleActivePowerLimit(), networkParameters.isUseActiveLimits(), null)) {
if (!AbstractLfGenerator.checkActivePowerControl(generator.getId(), generator.getTargetP(), generator.getActivePowerOperationMinP(),
generator.getActivePowerOperationMaxP(), networkParameters.getPlausibleActivePowerLimit(),
networkParameters.isUseActiveLimits(), null)) {
generator.setParticipating(false);
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/powsybl/openloadflow/network/LfGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ static double qToK(LfGenerator generator, double q) {

void setTargetP(double targetP);

/**
* The minimum P for active power operations (can be different from minP if overridden in the ActivePowerOperation extension)
* This limit is taken into account in the compensation.
*/
default double getActivePowerOperationMinP() {
return getMinP();
}

/**
* The maximum P for active power operations (can be different from maxP if overridden in the ActivePowerOperation extension)
* This limit is taken into account in the compensation.
*/
default double getActivePowerOperationMaxP() {
return getMaxP();
}

double getMinP();

double getMaxP();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/powsybl/openloadflow/network/LfNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ private void writeJson(LfGenerator generator, JsonGenerator jsonGenerator) throw
jsonGenerator.writeBooleanField("voltageControl", generator.getGeneratorControlType() == LfGenerator.GeneratorControlType.VOLTAGE);
jsonGenerator.writeNumberField("minP", generator.getMinP());
jsonGenerator.writeNumberField("maxP", generator.getMaxP());
jsonGenerator.writeNumberField("activePowerOperationMinP", generator.getActivePowerOperationMinP());
jsonGenerator.writeNumberField("activePowerOperationMaxP", generator.getActivePowerOperationMaxP());
}

public void writeJson(Writer writer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public SelectedReferenceBus select(LfNetwork lfNetwork) {
// if multiple generators of same priority, select based on highest maxP
LfGenerator referenceGenerator = lfGenerators.stream()
.filter(g -> g.getReferencePriority() == priority)
.min(Comparator.comparingDouble(LfGenerator::getMaxP).reversed().thenComparing(LfGenerator::getId)
.min(Comparator.comparingDouble(LfGenerator::getActivePowerOperationMaxP).reversed().thenComparing(LfGenerator::getId)
).orElseThrow(() -> new IllegalStateException("No reference Generator for network " + lfNetwork));
LfBus referenceBus = referenceGenerator.getBus();
return new SelectedGeneratorReferenceBus(referenceBus, METHOD_NAME, referenceGenerator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public double getLoadTargetQ() {

@Override
public double getMaxP() {
return generators.stream().mapToDouble(LfGenerator::getMaxP).sum();
return generators.stream().mapToDouble(LfGenerator::getActivePowerOperationMaxP).sum();
}

private double getLimitQ(ToDoubleFunction<LfGenerator> limitQ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ public double getMaxP() {
return getBattery().getMaxP() / PerUnit.SB;
}

@Override
public double getActivePowerOperationMinP() {
Battery battery = getBattery();
ActivePowerControl<Battery> activePowerControl = battery.getExtension(ActivePowerControl.class);
return activePowerControl == null ? getMinP() : activePowerControl.getMinPOverride().orElse(battery.getMinP()) / PerUnit.SB;
}

@Override
public double getActivePowerOperationMaxP() {
Battery battery = getBattery();
ActivePowerControl<Battery> activePowerControl = battery.getExtension(ActivePowerControl.class);
return activePowerControl == null ? getMaxP() : activePowerControl.getMaxPOverride().orElse(battery.getMaxP()) / PerUnit.SB;
}

@Override
protected Optional<ReactiveLimits> getReactiveLimits() {
return Optional.of(getBattery().getReactiveLimits());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,20 @@ public double getMaxP() {
return getGenerator().getMaxP() / PerUnit.SB;
}

@Override
public double getActivePowerOperationMinP() {
Generator generator = getGenerator();
ActivePowerControl<Generator> activePowerControl = generator.getExtension(ActivePowerControl.class);
return activePowerControl == null ? getMinP() : activePowerControl.getMinPOverride().orElse(generator.getMinP()) / PerUnit.SB;
}

@Override
public double getActivePowerOperationMaxP() {
Generator generator = getGenerator();
ActivePowerControl<Generator> activePowerControl = generator.getExtension(ActivePowerControl.class);
return activePowerControl == null ? getMaxP() : activePowerControl.getMaxPOverride().orElse(generator.getMaxP()) / PerUnit.SB;
}

@Override
protected Optional<ReactiveLimits> getReactiveLimits() {
return Optional.of(getGenerator().getReactiveLimits());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public ActivePowerDistribution.StepResult run(List<ParticipatingElement> partici
LfGenerator generator = (LfGenerator) participatingGenerator.getElement();
double factor = participatingGenerator.getFactor();

double minP = useActiveLimits ? generator.getMinP() : -Double.MAX_VALUE;
double maxP = useActiveLimits ? generator.getMaxP() : Double.MAX_VALUE;
double minP = useActiveLimits ? generator.getActivePowerOperationMinP() : -Double.MAX_VALUE;
double maxP = useActiveLimits ? generator.getActivePowerOperationMaxP() : Double.MAX_VALUE;
double targetP = generator.getTargetP();

// we don't want to change the generation sign
Expand Down Expand Up @@ -114,10 +114,10 @@ public ActivePowerDistribution.StepResult run(List<ParticipatingElement> partici

private double getParticipationFactor(LfGenerator generator) {
return switch (participationType) {
case MAX -> generator.getMaxP() / generator.getDroop();
case MAX -> generator.getActivePowerOperationMaxP() / generator.getDroop();
case TARGET -> Math.abs(generator.getTargetP());
case PARTICIPATION_FACTOR -> generator.getParticipationFactor();
case REMAINING_MARGIN -> Math.max(0.0, generator.getMaxP() - generator.getTargetP());
case REMAINING_MARGIN -> Math.max(0.0, generator.getActivePowerOperationMaxP() - generator.getTargetP());
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,43 @@ void testProportionalToP() {
assertActivePowerEquals(-117.236, g4.getTerminal());
}

@Test
void testProportionalToPWithOverride() {
// decrease g1 max limit power, so that distributed slack algo reach the g1 max
g1.setMaxP(105);
g1.getExtension(ActivePowerControl.class).setMaxPOverride(103);
parameters.setBalanceType(LoadFlowParameters.BalanceType.PROPORTIONAL_TO_GENERATION_P);
LoadFlowResult result = loadFlowRunner.run(network, parameters);

assertTrue(result.isFullyConverged());
assertActivePowerEquals(-103, g1.getTerminal());
assertActivePowerEquals(-261.579, g2.getTerminal());
assertActivePowerEquals(-117.711, g3.getTerminal());
assertActivePowerEquals(-117.711, g4.getTerminal());

// now compensation down
Load l1 = network.getLoad("l1");
l1.setP0(400); // was 600
result = loadFlowRunner.run(network, parameters);

assertTrue(result.isFullyConverged());
assertActivePowerEquals(-83.333, g1.getTerminal());
assertActivePowerEquals(-166.667, g2.getTerminal());
assertActivePowerEquals(-75.000, g3.getTerminal());
assertActivePowerEquals(-75.000, g4.getTerminal());

// With a pMin temporary limit for g1
g1.getExtension(ActivePowerControl.class).setMinPOverride(85);

result = loadFlowRunner.run(network, parameters);
assertTrue(result.isFullyConverged());
assertActivePowerEquals(-85, g1.getTerminal());
assertActivePowerEquals(-165.790, g2.getTerminal());
assertActivePowerEquals(-74.605, g3.getTerminal());
assertActivePowerEquals(-74.605, g4.getTerminal());

}

@Test
@SuppressWarnings("unchecked")
void testProportionalToParticipationFactor() {
Expand Down
4 changes: 3 additions & 1 deletion src/test/resources/n.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"targetQ" : 3.01,
"voltageControl" : true,
"minP" : -99.9999,
"maxP" : 49.99
"maxP" : 49.99,
"activePowerOperationMinP" : -99.9999,
"activePowerOperationMaxP" : 49.99
} ]
}, {
"id" : "VLHV1_0",
Expand Down
4 changes: 3 additions & 1 deletion src/test/resources/n2.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"targetQ" : 0.0,
"voltageControl" : true,
"minP" : 0.5,
"maxP" : 1.5
"maxP" : 1.5,
"activePowerOperationMinP" : 0.5,
"activePowerOperationMaxP" : 1.5
} ]
}, {
"id" : "VL2_0",
Expand Down

0 comments on commit 53b1117

Please sign in to comment.