Skip to content

Commit

Permalink
fix consistency, ensure that participationFactor > 0
Browse files Browse the repository at this point in the history
Signed-off-by: Caio Luke <caio.luke@artelys.com>
  • Loading branch information
cluke committed Jan 25, 2023
1 parent 28ff62e commit c8cbf6c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ default double getDroop() {
}

default double getParticipationFactor() {
return 0.0;
return 0;
}

double getCalculatedQ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public final class LfBatteryImpl extends AbstractLfGenerator {

private double droop;

private double participationFactor = 0.0;
private double participationFactor;

private LfBatteryImpl(Battery battery, LfNetwork network, LfNetworkParameters parameters, LfNetworkLoadingReport report) {
super(network, battery.getTargetP());
Expand All @@ -41,7 +41,7 @@ private LfBatteryImpl(Battery battery, LfNetwork network, LfNetworkParameters pa
if (!Double.isNaN(activePowerControl.getDroop())) {
droop = activePowerControl.getDroop();
}
if (!Double.isNaN(activePowerControl.getParticipationFactor())) {
if (activePowerControl.getParticipationFactor() > 0) {
participationFactor = activePowerControl.getParticipationFactor();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class LfGeneratorImpl extends AbstractLfGenerator {

private double droop;

private double participationFactor = 0.0;
private double participationFactor;

private LfGeneratorImpl(Generator generator, LfNetwork network, LfNetworkParameters parameters, LfNetworkLoadingReport report) {
super(network, generator.getTargetP());
Expand All @@ -44,7 +44,7 @@ private LfGeneratorImpl(Generator generator, LfNetwork network, LfNetworkParamet
if (!Double.isNaN(activePowerControl.getDroop())) {
droop = activePowerControl.getDroop();
}
if (!Double.isNaN(activePowerControl.getParticipationFactor())) {
if (activePowerControl.getParticipationFactor() > 0) {
participationFactor = activePowerControl.getParticipationFactor();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public List<ParticipatingElement> getParticipatingElements(Collection<LfBus> bus
return buses.stream()
.filter(bus -> bus.isParticipating() && !bus.isDisabled() && !bus.isFictitious())
.flatMap(bus -> bus.getGenerators().stream())
.filter(generator -> isParticipating(generator) && getParticipationFactor(generator) != 0)
.filter(generator -> isParticipating(generator) && getParticipationFactor(generator) > 0)

This comment has been minimized.

Copy link
@annetill

annetill Jan 25, 2023

Member

I am not sure with this fix. I prefer that you put this in the isParticipating(LfGeneror) method and make the check specific to each balance type.

This comment has been minimized.

Copy link
@jeandemanged

jeandemanged Jan 25, 2023

Member

agreed to refactor, here proposal

here only .filter(generator -> isParticipating(generator))

in isParticipating(LfGenerator):

  • case MAX: generator.isParticipating() && droop != 0
  • case TARGET: generator.isParticipating()
  • case PARTICIPATION_FACTOR: generator.isParticipating() && generator.getParticipationFactor() > 0
  • case REMAINING_MARGIN: generator.isParticipating() && generator.getMaxP() > generator.getTargetP()

This comment has been minimized.

Copy link
@annetill

annetill Jan 25, 2023

Member

Yes, agreed!

This comment has been minimized.

Copy link
@caioluke

caioluke Jan 25, 2023

Member

for the REMAINING_MARGIN couldn't it be just a PF > 0 as well? since

private double getParticipationFactor(LfGenerator generator) {
        double factor;
        switch (participationType) {
            case MAX:
                factor = generator.getMaxP() / generator.getDroop();
                break;
            case TARGET:
                factor = Math.abs(generator.getTargetP());
                break;
            case PARTICIPATION_FACTOR:
                factor = generator.getParticipationFactor();
                break;
            case REMAINING_MARGIN:
                factor = Math.max(0.0, generator.getMaxP() - generator.getTargetP());
                break;
            default:
                throw new UnsupportedOperationException("Unknown balance type mode: " + participationType);
        }
        return factor;
    }
.map(generator -> new ParticipatingElement(generator, getParticipationFactor(generator)))
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,19 @@ void testProportionalToGenerationParticipationFactorBalanceType() {
g1.setMaxP(100);

// set participationFactor
// g1 NaN participationFactor should be discarded
g2.getExtension(ActivePowerControl.class).setParticipationFactor(3.0);
g3.getExtension(ActivePowerControl.class).setParticipationFactor(2.0);
g4.getExtension(ActivePowerControl.class).setParticipationFactor(1.0);
g3.getExtension(ActivePowerControl.class).setParticipationFactor(1.0);
g4.getExtension(ActivePowerControl.class).setParticipationFactor(-4.0); // Should be discarded

parameters.setBalanceType(LoadFlowParameters.BalanceType.PROPORTIONAL_TO_GENERATION_PARTICIPATION_FACTOR);
LoadFlowResult result = loadFlowRunner.run(network, parameters);

assertTrue(result.isOk());
assertActivePowerEquals(-100, g1.getTerminal());
assertActivePowerEquals(-260, g2.getTerminal());
assertActivePowerEquals(-130, g3.getTerminal());
assertActivePowerEquals(-110, g4.getTerminal());
assertActivePowerEquals(-290, g2.getTerminal());
assertActivePowerEquals(-120, g3.getTerminal());
assertActivePowerEquals(-90, g4.getTerminal());
}

@Test
Expand Down

0 comments on commit c8cbf6c

Please sign in to comment.