1111import com .powsybl .openloadflow .network .*;
1212import com .powsybl .openloadflow .sa .LimitReductionManager ;
1313import com .powsybl .openloadflow .util .Evaluable ;
14- import com .powsybl .openloadflow .util .PerUnit ;
1514import net .jafama .FastMath ;
1615import org .slf4j .Logger ;
1716import org .slf4j .LoggerFactory ;
@@ -30,17 +29,17 @@ public abstract class AbstractLfBranch extends AbstractElement implements LfBran
3029
3130 protected final LfBus bus2 ;
3231
33- private List <LfLimit > currentLimits1 ;
32+ private List <LfLimitsGroup > currentLimits1 ;
3433
35- private List <LfLimit > activePowerLimits1 ;
34+ private List <LfLimitsGroup > activePowerLimits1 ;
3635
37- private List <LfLimit > apparentPowerLimits1 ;
36+ private List <LfLimitsGroup > apparentPowerLimits1 ;
3837
39- private List <LfLimit > currentLimits2 ;
38+ private List <LfLimitsGroup > currentLimits2 ;
4039
41- private List <LfLimit > activePowerLimits2 ;
40+ private List <LfLimitsGroup > activePowerLimits2 ;
4241
43- private List <LfLimit > apparentPowerLimits2 ;
42+ private List <LfLimitsGroup > apparentPowerLimits2 ;
4443
4544 protected final PiModel piModel ;
4645
@@ -92,42 +91,6 @@ public Optional<ThreeSides> getOriginalSide() {
9291 return Optional .empty ();
9392 }
9493
95- /**
96- * Create the list of LfLimits from a LoadingLimits and a list of reductions.
97- * The resulting list will contain the permanent limit
98- */
99- protected static List <LfLimit > createSortedLimitsList (LoadingLimits loadingLimits , LfBus bus , double [] limitReductions ) {
100- List <LfLimit > sortedLimits = new ArrayList <>(3 );
101- if (loadingLimits != null ) {
102- double toPerUnit = getScaleForLimitType (loadingLimits .getLimitType (), bus );
103-
104- int i = 0 ;
105- for (LoadingLimits .TemporaryLimit temporaryLimit : loadingLimits .getTemporaryLimits ()) {
106- if (temporaryLimit .getAcceptableDuration () != 0 ) {
107- // it is not useful to add a limit with acceptable duration equal to zero as the only value plausible
108- // for this limit is infinity.
109- // https://javadoc.io/doc/com.powsybl/powsybl-core/latest/com/powsybl/iidm/network/CurrentLimits.html
110- double reduction = limitReductions .length == 0 ? 1d : limitReductions [i + 1 ]; // Temporary limit's reductions are stored starting from index 1 in `limitReductions`
111- double originalValuePerUnit = temporaryLimit .getValue () * toPerUnit ;
112- sortedLimits .add (0 , LfLimit .createTemporaryLimit (temporaryLimit .getName (), temporaryLimit .getAcceptableDuration (),
113- originalValuePerUnit , reduction ));
114- }
115- i ++;
116- }
117- double reduction = limitReductions .length == 0 ? 1d : limitReductions [0 ];
118- sortedLimits .add (LfLimit .createPermanentLimit (loadingLimits .getPermanentLimit () * toPerUnit , reduction ));
119- }
120- if (sortedLimits .size () > 1 ) {
121- // we only make that fix if there is more than a permanent limit attached to the branch.
122- for (int i = sortedLimits .size () - 1 ; i > 0 ; i --) {
123- // From the permanent limit to the most serious temporary limit.
124- sortedLimits .get (i ).setAcceptableDuration (sortedLimits .get (i - 1 ).getAcceptableDuration ());
125- }
126- sortedLimits .get (0 ).setAcceptableDuration (0 );
127- }
128- return sortedLimits ;
129- }
130-
13194 @ Override
13295 public ElementType getType () {
13396 return ElementType .BRANCH ;
@@ -143,7 +106,7 @@ public LfBus getBus2() {
143106 return bus2 ;
144107 }
145108
146- private List <LfLimit > getLimits1 (LimitType type ) {
109+ private List <LfLimitsGroup > getLimits1 (LimitType type ) {
147110 switch (type ) {
148111 case ACTIVE_POWER -> {
149112 return activePowerLimits1 ;
@@ -158,7 +121,7 @@ private List<LfLimit> getLimits1(LimitType type) {
158121 }
159122 }
160123
161- private void setLimits1 (LimitType type , List <LfLimit > limits ) {
124+ private void setLimits1 (LimitType type , List <LfLimitsGroup > limits ) {
162125 switch (type ) {
163126 case ACTIVE_POWER -> activePowerLimits1 = limits ;
164127 case APPARENT_POWER -> apparentPowerLimits1 = limits ;
@@ -167,19 +130,31 @@ private void setLimits1(LimitType type, List<LfLimit> limits) {
167130 }
168131 }
169132
170- public <T extends LoadingLimits > List <LfLimit > getLimits1 (LimitType type , Supplier <Optional <T >> loadingLimitsSupplier , LimitReductionManager limitReductionManager ) {
171- var limits = getLimits1 (type );
133+ private <T extends LoadingLimits > List <LfLimitsGroup > createLimits (Supplier <Map <String , T >> loadingLimitsSupplier , LimitReductionManager limitReductionManager , TwoSides side ) {
134+ // It is possible to apply the reductions here since the only supported ContingencyContext for LimitReduction is ALL.
135+ Map <String , T > allSelectedLoadingLimits = loadingLimitsSupplier .get (); // Map of all selected loading limits indexed by their operational limits group id
136+ List <LfLimitsGroup > limits = new ArrayList <>();
137+ for (Map .Entry <String , T > loadingLimitsEntry : allSelectedLoadingLimits .entrySet ()) {
138+ T loadingLimits = loadingLimitsEntry .getValue ();
139+ String operationalLimitsGroupId = loadingLimitsEntry .getKey ();
140+ limits .add (LfLimitsGroup .createSortedLimitsList (loadingLimits ,
141+ operationalLimitsGroupId ,
142+ side == TwoSides .ONE ? bus1 : bus2 ,
143+ getLimitReductions (side , limitReductionManager , loadingLimits )));
144+ }
145+ return limits ;
146+ }
147+
148+ public <T extends LoadingLimits > List <LfLimitsGroup > getLimits1 (LimitType type , Supplier <Map <String , T >> loadingLimitsSupplier , LimitReductionManager limitReductionManager ) {
149+ List <LfLimitsGroup > limits = getLimits1 (type );
172150 if (limits == null ) {
173- // It is possible to apply the reductions here since the only supported ContingencyContext for LimitReduction is ALL.
174- var loadingLimits = loadingLimitsSupplier .get ().orElse (null );
175- limits = createSortedLimitsList (loadingLimits , bus1 ,
176- getLimitReductions (TwoSides .ONE , limitReductionManager , loadingLimits ));
151+ limits = createLimits (loadingLimitsSupplier , limitReductionManager , TwoSides .ONE );
177152 setLimits1 (type , limits );
178153 }
179154 return limits ;
180155 }
181156
182- private List <LfLimit > getLimits2 (LimitType type ) {
157+ private List <LfLimitsGroup > getLimits2 (LimitType type ) {
183158 switch (type ) {
184159 case ACTIVE_POWER -> {
185160 return activePowerLimits2 ;
@@ -194,7 +169,7 @@ private List<LfLimit> getLimits2(LimitType type) {
194169 }
195170 }
196171
197- private void setLimits2 (LimitType type , List <LfLimit > limits ) {
172+ private void setLimits2 (LimitType type , List <LfLimitsGroup > limits ) {
198173 switch (type ) {
199174 case ACTIVE_POWER -> activePowerLimits2 = limits ;
200175 case APPARENT_POWER -> apparentPowerLimits2 = limits ;
@@ -203,13 +178,10 @@ private void setLimits2(LimitType type, List<LfLimit> limits) {
203178 }
204179 }
205180
206- public <T extends LoadingLimits > List <LfLimit > getLimits2 (LimitType type , Supplier <Optional < T >> loadingLimitsSupplier , LimitReductionManager limitReductionManager ) {
181+ public <T extends LoadingLimits > List <LfLimitsGroup > getLimits2 (LimitType type , Supplier <Map < String , T >> loadingLimitsSupplier , LimitReductionManager limitReductionManager ) {
207182 var limits = getLimits2 (type );
208183 if (limits == null ) {
209- // It is possible to apply the reductions here since the only supported ContingencyContext for LimitReduction is ALL.
210- var loadingLimits = loadingLimitsSupplier .get ().orElse (null );
211- limits = createSortedLimitsList (loadingLimits , bus2 ,
212- getLimitReductions (TwoSides .TWO , limitReductionManager , loadingLimits ));
184+ limits = createLimits (loadingLimitsSupplier , limitReductionManager , TwoSides .TWO );
213185 setLimits2 (type , limits );
214186 }
215187 return limits ;
@@ -264,19 +236,6 @@ protected void updateSolvedTapPosition(RatioTapChanger rtc, double ptcRho, doubl
264236 Transformers .findTapPosition (rtc , ptcRho , rho ).ifPresent (rtc ::setSolvedTapPosition );
265237 }
266238
267- protected static double getScaleForLimitType (LimitType type , LfBus bus ) {
268- switch (type ) {
269- case ACTIVE_POWER ,
270- APPARENT_POWER :
271- return 1.0 / PerUnit .SB ;
272- case CURRENT :
273- return 1.0 / PerUnit .ib (bus .getNominalV ());
274- case VOLTAGE :
275- default :
276- throw new UnsupportedOperationException (String .format ("Getting scale for limit type %s is not supported." , type ));
277- }
278- }
279-
280239 @ Override
281240 public Optional <TransformerVoltageControl > getVoltageControl () {
282241 return Optional .ofNullable (voltageControl );
0 commit comments