@@ -30,9 +30,17 @@ public abstract class AbstractLfBranch extends AbstractElement implements LfBran
30
30
31
31
protected final LfBus bus2 ;
32
32
33
- private final Map < LimitType , List <LfLimit >> limits1 = new EnumMap <>( LimitType . class ) ;
33
+ private List <LfLimit > currentLimits1 ;
34
34
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 ;
36
44
37
45
protected final PiModel piModel ;
38
46
@@ -61,6 +69,8 @@ static class ZeroImpedanceContext {
61
69
62
70
protected LfAsymLine asymLine ;
63
71
72
+ private static final String LIMIT_TYPE_UNSUPPORTED_TEMPLATE = "Getting %s limits is not supported." ;
73
+
64
74
protected AbstractLfBranch (LfNetwork network , LfBus bus1 , LfBus bus2 , PiModel piModel , LfNetworkParameters parameters ) {
65
75
super (network );
66
76
this .bus1 = bus1 ;
@@ -87,7 +97,7 @@ public Optional<ThreeSides> getOriginalSide() {
87
97
* The resulting list will contain the permanent limit
88
98
*/
89
99
protected static List <LfLimit > createSortedLimitsList (LoadingLimits loadingLimits , LfBus bus , double [] limitReductions ) {
90
- LinkedList <LfLimit > sortedLimits = new LinkedList <>();
100
+ List <LfLimit > sortedLimits = new ArrayList <>(3 );
91
101
if (loadingLimits != null ) {
92
102
double toPerUnit = getScaleForLimitType (loadingLimits .getLimitType (), bus );
93
103
@@ -99,21 +109,21 @@ protected static List<LfLimit> createSortedLimitsList(LoadingLimits loadingLimit
99
109
// https://javadoc.io/doc/com.powsybl/powsybl-core/latest/com/powsybl/iidm/network/CurrentLimits.html
100
110
double reduction = limitReductions .length == 0 ? 1d : limitReductions [i + 1 ]; // Temporary limit's reductions are stored starting from index 1 in `limitReductions`
101
111
double originalValuePerUnit = temporaryLimit .getValue () * toPerUnit ;
102
- sortedLimits .addFirst ( LfLimit .createTemporaryLimit (temporaryLimit .getName (), temporaryLimit .getAcceptableDuration (),
112
+ sortedLimits .add ( 0 , LfLimit .createTemporaryLimit (temporaryLimit .getName (), temporaryLimit .getAcceptableDuration (),
103
113
originalValuePerUnit , reduction ));
104
114
}
105
115
i ++;
106
116
}
107
117
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 ));
109
119
}
110
120
if (sortedLimits .size () > 1 ) {
111
121
// we only make that fix if there is more than a permanent limit attached to the branch.
112
122
for (int i = sortedLimits .size () - 1 ; i > 0 ; i --) {
113
123
// From the permanent limit to the most serious temporary limit.
114
124
sortedLimits .get (i ).setAcceptableDuration (sortedLimits .get (i - 1 ).getAcceptableDuration ());
115
125
}
116
- sortedLimits .getFirst ( ).setAcceptableDuration (0 );
126
+ sortedLimits .get ( 0 ).setAcceptableDuration (0 );
117
127
}
118
128
return sortedLimits ;
119
129
}
@@ -133,22 +143,76 @@ public LfBus getBus2() {
133
143
return bus2 ;
134
144
}
135
145
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
+
136
170
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.
139
174
var loadingLimits = loadingLimitsSupplier .get ().orElse (null );
140
- return createSortedLimitsList (loadingLimits , bus1 ,
175
+ limits = createSortedLimitsList (loadingLimits , bus1 ,
141
176
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
+ }
143
204
}
144
205
145
206
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.
148
210
var loadingLimits = loadingLimitsSupplier .get ().orElse (null );
149
- return createSortedLimitsList (loadingLimits , bus2 ,
211
+ limits = createSortedLimitsList (loadingLimits , bus2 ,
150
212
getLimitReductions (TwoSides .TWO , limitReductionManager , loadingLimits ));
151
- });
213
+ setLimits2 (type , limits );
214
+ }
215
+ return limits ;
152
216
}
153
217
154
218
@ Override
0 commit comments