Skip to content

Commit da71f30

Browse files
authored
Fix performance issue when accessing loading limits from IIDM (#1162)
Signed-off-by: Geoffroy Jamgotchian <[email protected]>
1 parent c7f69ad commit da71f30

File tree

5 files changed

+31
-24
lines changed

5 files changed

+31
-24
lines changed

src/main/java/com/powsybl/openloadflow/network/impl/AbstractLfBranch.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.slf4j.LoggerFactory;
1818

1919
import java.util.*;
20+
import java.util.function.Supplier;
2021

2122
/**
2223
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
@@ -132,16 +133,22 @@ public LfBus getBus2() {
132133
return bus2;
133134
}
134135

135-
public List<LfLimit> getLimits1(LimitType type, LoadingLimits loadingLimits, LimitReductionManager limitReductionManager) {
136+
public <T extends LoadingLimits> List<LfLimit> getLimits1(LimitType type, Supplier<Optional<T>> loadingLimitsSupplier, LimitReductionManager limitReductionManager) {
136137
// It is possible to apply the reductions here since the only supported ContingencyContext for LimitReduction is ALL.
137-
return limits1.computeIfAbsent(type, v -> createSortedLimitsList(loadingLimits, bus1,
138-
getLimitReductions(TwoSides.ONE, limitReductionManager, loadingLimits)));
138+
return limits1.computeIfAbsent(type, v -> {
139+
var loadingLimits = loadingLimitsSupplier.get().orElse(null);
140+
return createSortedLimitsList(loadingLimits, bus1,
141+
getLimitReductions(TwoSides.ONE, limitReductionManager, loadingLimits));
142+
});
139143
}
140144

141-
public List<LfLimit> getLimits2(LimitType type, LoadingLimits loadingLimits, LimitReductionManager limitReductionManager) {
145+
public <T extends LoadingLimits> List<LfLimit> getLimits2(LimitType type, Supplier<Optional<T>> loadingLimitsSupplier, LimitReductionManager limitReductionManager) {
142146
// It is possible to apply the reductions here since the only supported ContingencyContext for LimitReduction is ALL.
143-
return limits2.computeIfAbsent(type, v -> createSortedLimitsList(loadingLimits, bus2,
144-
getLimitReductions(TwoSides.TWO, limitReductionManager, loadingLimits)));
147+
return limits2.computeIfAbsent(type, v -> {
148+
var loadingLimits = loadingLimitsSupplier.get().orElse(null);
149+
return createSortedLimitsList(loadingLimits, bus2,
150+
getLimitReductions(TwoSides.TWO, limitReductionManager, loadingLimits));
151+
});
145152
}
146153

147154
@Override

src/main/java/com/powsybl/openloadflow/network/impl/LfBranchImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ public List<LfLimit> getLimits1(final LimitType type, LimitReductionManager limi
237237
var branch = getBranch();
238238
switch (type) {
239239
case ACTIVE_POWER:
240-
return getLimits1(type, branch.getActivePowerLimits1().orElse(null), limitReductionManager);
240+
return getLimits1(type, branch::getActivePowerLimits1, limitReductionManager);
241241
case APPARENT_POWER:
242-
return getLimits1(type, branch.getApparentPowerLimits1().orElse(null), limitReductionManager);
242+
return getLimits1(type, branch::getApparentPowerLimits1, limitReductionManager);
243243
case CURRENT:
244-
return getLimits1(type, branch.getCurrentLimits1().orElse(null), limitReductionManager);
244+
return getLimits1(type, branch::getCurrentLimits1, limitReductionManager);
245245
case VOLTAGE:
246246
default:
247247
throw new UnsupportedOperationException(String.format("Getting %s limits is not supported.", type.name()));
@@ -253,11 +253,11 @@ public List<LfLimit> getLimits2(final LimitType type, LimitReductionManager limi
253253
var branch = getBranch();
254254
switch (type) {
255255
case ACTIVE_POWER:
256-
return getLimits2(type, branch.getActivePowerLimits2().orElse(null), limitReductionManager);
256+
return getLimits2(type, branch::getActivePowerLimits2, limitReductionManager);
257257
case APPARENT_POWER:
258-
return getLimits2(type, branch.getApparentPowerLimits2().orElse(null), limitReductionManager);
258+
return getLimits2(type, branch::getApparentPowerLimits2, limitReductionManager);
259259
case CURRENT:
260-
return getLimits2(type, branch.getCurrentLimits2().orElse(null), limitReductionManager);
260+
return getLimits2(type, branch::getCurrentLimits2, limitReductionManager);
261261
case VOLTAGE:
262262
default:
263263
throw new UnsupportedOperationException(String.format("Getting %s limits is not supported.", type.name()));

src/main/java/com/powsybl/openloadflow/network/impl/LfDanglingLineBranch.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ public List<LfLimit> getLimits1(final LimitType type, LimitReductionManager limi
8383
var danglingLine = getDanglingLine();
8484
switch (type) {
8585
case ACTIVE_POWER:
86-
return getLimits1(type, danglingLine.getActivePowerLimits().orElse(null), limitReductionManager);
86+
return getLimits1(type, danglingLine::getActivePowerLimits, limitReductionManager);
8787
case APPARENT_POWER:
88-
return getLimits1(type, danglingLine.getApparentPowerLimits().orElse(null), limitReductionManager);
88+
return getLimits1(type, danglingLine::getApparentPowerLimits, limitReductionManager);
8989
case CURRENT:
90-
return getLimits1(type, danglingLine.getCurrentLimits().orElse(null), limitReductionManager);
90+
return getLimits1(type, danglingLine::getCurrentLimits, limitReductionManager);
9191
case VOLTAGE:
9292
default:
9393
throw new UnsupportedOperationException(String.format("Getting %s limits is not supported.", type.name()));

src/main/java/com/powsybl/openloadflow/network/impl/LfLegBranch.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ public List<LfLimit> getLimits1(final LimitType type, LimitReductionManager limi
150150
var leg = getLeg();
151151
switch (type) {
152152
case ACTIVE_POWER:
153-
return getLimits1(type, leg.getActivePowerLimits().orElse(null), limitReductionManager);
153+
return getLimits1(type, leg::getActivePowerLimits, limitReductionManager);
154154
case APPARENT_POWER:
155-
return getLimits1(type, leg.getApparentPowerLimits().orElse(null), limitReductionManager);
155+
return getLimits1(type, leg::getApparentPowerLimits, limitReductionManager);
156156
case CURRENT:
157-
return getLimits1(type, leg.getCurrentLimits().orElse(null), limitReductionManager);
157+
return getLimits1(type, leg::getCurrentLimits, limitReductionManager);
158158
case VOLTAGE:
159159
default:
160160
throw new UnsupportedOperationException(String.format("Getting %s limits is not supported.", type.name()));

src/main/java/com/powsybl/openloadflow/network/impl/LfTieLineBranch.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ public List<BranchResult> createBranchResult(double preContingencyBranchP1, doub
105105
public List<LfLimit> getLimits1(final LimitType type, LimitReductionManager limitReductionManager) {
106106
switch (type) {
107107
case ACTIVE_POWER:
108-
return getLimits1(type, getHalf1().getActivePowerLimits().orElse(null), limitReductionManager);
108+
return getLimits1(type, getHalf1()::getActivePowerLimits, limitReductionManager);
109109
case APPARENT_POWER:
110-
return getLimits1(type, getHalf1().getApparentPowerLimits().orElse(null), limitReductionManager);
110+
return getLimits1(type, getHalf1()::getApparentPowerLimits, limitReductionManager);
111111
case CURRENT:
112-
return getLimits1(type, getHalf1().getCurrentLimits().orElse(null), limitReductionManager);
112+
return getLimits1(type, getHalf1()::getCurrentLimits, limitReductionManager);
113113
case VOLTAGE:
114114
default:
115115
throw new UnsupportedOperationException(String.format("Getting %s limits is not supported.", type.name()));
@@ -120,11 +120,11 @@ public List<LfLimit> getLimits1(final LimitType type, LimitReductionManager limi
120120
public List<LfLimit> getLimits2(final LimitType type, LimitReductionManager limitReductionManager) {
121121
switch (type) {
122122
case ACTIVE_POWER:
123-
return getLimits2(type, getHalf2().getActivePowerLimits().orElse(null), limitReductionManager);
123+
return getLimits2(type, getHalf2()::getActivePowerLimits, limitReductionManager);
124124
case APPARENT_POWER:
125-
return getLimits2(type, getHalf2().getApparentPowerLimits().orElse(null), limitReductionManager);
125+
return getLimits2(type, getHalf2()::getApparentPowerLimits, limitReductionManager);
126126
case CURRENT:
127-
return getLimits2(type, getHalf2().getCurrentLimits().orElse(null), limitReductionManager);
127+
return getLimits2(type, getHalf2()::getCurrentLimits, limitReductionManager);
128128
case VOLTAGE:
129129
default:
130130
throw new UnsupportedOperationException(String.format("Getting %s limits is not supported.", type.name()));

0 commit comments

Comments
 (0)