9
9
10
10
import com .powsybl .commons .PowsyblException ;
11
11
import com .powsybl .iidm .network .*;
12
+ import com .powsybl .iidm .network .extensions .ActivePowerControl ;
12
13
import com .powsybl .openloadflow .network .*;
13
14
import com .powsybl .openloadflow .network .LfAsymGenerator ;
14
15
import com .powsybl .openloadflow .util .PerUnit ;
@@ -61,6 +62,37 @@ protected AbstractLfGenerator(LfNetwork network, double targetP) {
61
62
this .network = Objects .requireNonNull (network );
62
63
}
63
64
65
+ protected record ActivePowerControlHelper (boolean participating , double participationFactor , double droop , double minTargetP , double maxTargetP ) {
66
+
67
+ @ SuppressWarnings ("unchecked" )
68
+ static ActivePowerControlHelper create (Injection <?> injection , double minP , double maxP ) {
69
+ boolean participating = true ;
70
+ double participationFactor = 0 ;
71
+ double droop = DEFAULT_DROOP ;
72
+ double minTargetP = minP ;
73
+ double maxTargetP = maxP ;
74
+
75
+ var activePowerControl = injection .getExtension (ActivePowerControl .class );
76
+ if (activePowerControl != null ) {
77
+ participating = activePowerControl .isParticipate ();
78
+ if (!Double .isNaN (activePowerControl .getDroop ())) {
79
+ droop = activePowerControl .getDroop ();
80
+ }
81
+ if (activePowerControl .getParticipationFactor () > 0 ) {
82
+ participationFactor = activePowerControl .getParticipationFactor ();
83
+ }
84
+ if (activePowerControl .getMinTargetP ().isPresent ()) {
85
+ minTargetP = activePowerControl .getMinTargetP ().getAsDouble ();
86
+ }
87
+ if (activePowerControl .getMaxTargetP ().isPresent ()) {
88
+ maxTargetP = activePowerControl .getMaxTargetP ().getAsDouble ();
89
+ }
90
+ }
91
+
92
+ return new ActivePowerControlHelper (participating , participationFactor , droop , minTargetP , maxTargetP );
93
+ }
94
+ }
95
+
64
96
@ Override
65
97
public String getOriginalId () {
66
98
return getId ();
@@ -326,7 +358,8 @@ public void setParticipating(boolean participating) {
326
358
// nothing to do
327
359
}
328
360
329
- public static boolean checkActivePowerControl (String generatorId , double targetP , double minP , double maxP , double plausibleActivePowerLimit ,
361
+ public static boolean checkActivePowerControl (String generatorId , double targetP , double maxP ,
362
+ double minTargetP , double maxTargetP , double plausibleActivePowerLimit ,
330
363
boolean useActiveLimits , LfNetworkLoadingReport report ) {
331
364
boolean participating = true ;
332
365
if (Math .abs (targetP ) < POWER_EPSILON_SI ) {
@@ -352,25 +385,25 @@ public static boolean checkActivePowerControl(String generatorId, double targetP
352
385
// if active power limits are not to be enforced, we can skip the rest of the checks
353
386
return participating ;
354
387
}
355
- if (targetP > maxP ) {
356
- LOGGER .trace ("Discard generator '{}' from active power control because targetP ({} MW) > maxP ({} MW)" ,
357
- generatorId , targetP , maxP );
388
+ if (targetP > maxTargetP ) {
389
+ LOGGER .trace ("Discard generator '{}' from active power control because targetP ({} MW) > maxTargetP ({} MW)" ,
390
+ generatorId , targetP , maxTargetP );
358
391
if (report != null ) {
359
392
report .generatorsDiscardedFromActivePowerControlBecauseTargetPGreaterThanMaxP ++;
360
393
}
361
394
participating = false ;
362
395
}
363
- if (targetP < minP ) {
364
- LOGGER .trace ("Discard generator '{}' from active power control because targetP ({} MW) < minP ({} MW)" ,
365
- generatorId , targetP , minP );
396
+ if (targetP < minTargetP ) {
397
+ LOGGER .trace ("Discard generator '{}' from active power control because targetP ({} MW) < minTargetP ({} MW)" ,
398
+ generatorId , targetP , minTargetP );
366
399
if (report != null ) {
367
400
report .generatorsDiscardedFromActivePowerControlBecauseTargetPLowerThanMinP ++;
368
401
}
369
402
participating = false ;
370
403
}
371
- if ((maxP - minP ) < POWER_EPSILON_SI ) {
404
+ if ((maxTargetP - minTargetP ) < POWER_EPSILON_SI ) {
372
405
LOGGER .trace ("Discard generator '{}' from active power control because maxP ({} MW) equals minP ({} MW)" ,
373
- generatorId , maxP , minP );
406
+ generatorId , minTargetP , minTargetP );
374
407
if (report != null ) {
375
408
report .generatorsDiscardedFromActivePowerControlBecauseMaxPEqualsMinP ++;
376
409
}
0 commit comments