@@ -30,9 +30,17 @@ public abstract class AbstractLfBranch extends AbstractElement implements LfBran
3030
3131 protected final LfBus bus2 ;
3232
33- private final Map < LimitType , List <LfLimit >> limits1 = new EnumMap <>( LimitType . class ) ;
33+ private List <LfLimit > currentLimits1 ;
3434
35- private final Map <LimitType , List <LfLimit >> limits2 = new EnumMap <>(LimitType .class );
35+ private List <LfLimit > activePowerLimits1 ;
36+
37+ private List <LfLimit > apparentPowerLimits1 ;
38+
39+ private List <LfLimit > currentLimits2 ;
40+
41+ private List <LfLimit > activePowerLimits2 ;
42+
43+ private List <LfLimit > apparentPowerLimits2 ;
3644
3745 protected final PiModel piModel ;
3846
@@ -61,6 +69,8 @@ static class ZeroImpedanceContext {
6169
6270 protected LfAsymLine asymLine ;
6371
72+ private static final String LIMIT_TYPE_UNSUPPORTED_TEMPLATE = "Getting %s limits is not supported." ;
73+
6474 protected AbstractLfBranch (LfNetwork network , LfBus bus1 , LfBus bus2 , PiModel piModel , LfNetworkParameters parameters ) {
6575 super (network );
6676 this .bus1 = bus1 ;
@@ -87,7 +97,7 @@ public Optional<ThreeSides> getOriginalSide() {
8797 * The resulting list will contain the permanent limit
8898 */
8999 protected static List <LfLimit > createSortedLimitsList (LoadingLimits loadingLimits , LfBus bus , double [] limitReductions ) {
90- LinkedList <LfLimit > sortedLimits = new LinkedList <>();
100+ List <LfLimit > sortedLimits = new ArrayList <>(3 );
91101 if (loadingLimits != null ) {
92102 double toPerUnit = getScaleForLimitType (loadingLimits .getLimitType (), bus );
93103
@@ -99,21 +109,21 @@ protected static List<LfLimit> createSortedLimitsList(LoadingLimits loadingLimit
99109 // https://javadoc.io/doc/com.powsybl/powsybl-core/latest/com/powsybl/iidm/network/CurrentLimits.html
100110 double reduction = limitReductions .length == 0 ? 1d : limitReductions [i + 1 ]; // Temporary limit's reductions are stored starting from index 1 in `limitReductions`
101111 double originalValuePerUnit = temporaryLimit .getValue () * toPerUnit ;
102- sortedLimits .addFirst ( LfLimit .createTemporaryLimit (temporaryLimit .getName (), temporaryLimit .getAcceptableDuration (),
112+ sortedLimits .add ( 0 , LfLimit .createTemporaryLimit (temporaryLimit .getName (), temporaryLimit .getAcceptableDuration (),
103113 originalValuePerUnit , reduction ));
104114 }
105115 i ++;
106116 }
107117 double reduction = limitReductions .length == 0 ? 1d : limitReductions [0 ];
108- sortedLimits .addLast (LfLimit .createPermanentLimit (loadingLimits .getPermanentLimit () * toPerUnit , reduction ));
118+ sortedLimits .add (LfLimit .createPermanentLimit (loadingLimits .getPermanentLimit () * toPerUnit , reduction ));
109119 }
110120 if (sortedLimits .size () > 1 ) {
111121 // we only make that fix if there is more than a permanent limit attached to the branch.
112122 for (int i = sortedLimits .size () - 1 ; i > 0 ; i --) {
113123 // From the permanent limit to the most serious temporary limit.
114124 sortedLimits .get (i ).setAcceptableDuration (sortedLimits .get (i - 1 ).getAcceptableDuration ());
115125 }
116- sortedLimits .getFirst ( ).setAcceptableDuration (0 );
126+ sortedLimits .get ( 0 ).setAcceptableDuration (0 );
117127 }
118128 return sortedLimits ;
119129 }
@@ -133,22 +143,76 @@ public LfBus getBus2() {
133143 return bus2 ;
134144 }
135145
146+ private List <LfLimit > getLimits1 (LimitType type ) {
147+ switch (type ) {
148+ case ACTIVE_POWER -> {
149+ return activePowerLimits1 ;
150+ }
151+ case APPARENT_POWER -> {
152+ return apparentPowerLimits1 ;
153+ }
154+ case CURRENT -> {
155+ return currentLimits1 ;
156+ }
157+ default -> throw new UnsupportedOperationException (String .format (LIMIT_TYPE_UNSUPPORTED_TEMPLATE , type .name ()));
158+ }
159+ }
160+
161+ private void setLimits1 (LimitType type , List <LfLimit > limits ) {
162+ switch (type ) {
163+ case ACTIVE_POWER -> activePowerLimits1 = limits ;
164+ case APPARENT_POWER -> apparentPowerLimits1 = limits ;
165+ case CURRENT -> currentLimits1 = limits ;
166+ default -> throw new UnsupportedOperationException (String .format (LIMIT_TYPE_UNSUPPORTED_TEMPLATE , type .name ()));
167+ }
168+ }
169+
136170 public <T extends LoadingLimits > List <LfLimit > getLimits1 (LimitType type , Supplier <Optional <T >> loadingLimitsSupplier , LimitReductionManager limitReductionManager ) {
137- // It is possible to apply the reductions here since the only supported ContingencyContext for LimitReduction is ALL.
138- return limits1 .computeIfAbsent (type , v -> {
171+ var limits = getLimits1 (type );
172+ if (limits == null ) {
173+ // It is possible to apply the reductions here since the only supported ContingencyContext for LimitReduction is ALL.
139174 var loadingLimits = loadingLimitsSupplier .get ().orElse (null );
140- return createSortedLimitsList (loadingLimits , bus1 ,
175+ limits = createSortedLimitsList (loadingLimits , bus1 ,
141176 getLimitReductions (TwoSides .ONE , limitReductionManager , loadingLimits ));
142- });
177+ setLimits1 (type , limits );
178+ }
179+ return limits ;
180+ }
181+
182+ private List <LfLimit > getLimits2 (LimitType type ) {
183+ switch (type ) {
184+ case ACTIVE_POWER -> {
185+ return activePowerLimits2 ;
186+ }
187+ case APPARENT_POWER -> {
188+ return apparentPowerLimits2 ;
189+ }
190+ case CURRENT -> {
191+ return currentLimits2 ;
192+ }
193+ default -> throw new UnsupportedOperationException (String .format (LIMIT_TYPE_UNSUPPORTED_TEMPLATE , type .name ()));
194+ }
195+ }
196+
197+ private void setLimits2 (LimitType type , List <LfLimit > limits ) {
198+ switch (type ) {
199+ case ACTIVE_POWER -> activePowerLimits2 = limits ;
200+ case APPARENT_POWER -> apparentPowerLimits2 = limits ;
201+ case CURRENT -> currentLimits2 = limits ;
202+ default -> throw new UnsupportedOperationException (String .format (LIMIT_TYPE_UNSUPPORTED_TEMPLATE , type .name ()));
203+ }
143204 }
144205
145206 public <T extends LoadingLimits > List <LfLimit > getLimits2 (LimitType type , Supplier <Optional <T >> loadingLimitsSupplier , LimitReductionManager limitReductionManager ) {
146- // It is possible to apply the reductions here since the only supported ContingencyContext for LimitReduction is ALL.
147- return limits2 .computeIfAbsent (type , v -> {
207+ var limits = getLimits2 (type );
208+ if (limits == null ) {
209+ // It is possible to apply the reductions here since the only supported ContingencyContext for LimitReduction is ALL.
148210 var loadingLimits = loadingLimitsSupplier .get ().orElse (null );
149- return createSortedLimitsList (loadingLimits , bus2 ,
211+ limits = createSortedLimitsList (loadingLimits , bus2 ,
150212 getLimitReductions (TwoSides .TWO , limitReductionManager , loadingLimits ));
151- });
213+ setLimits2 (type , limits );
214+ }
215+ return limits ;
152216 }
153217
154218 @ Override
0 commit comments