Skip to content

Commit 48d2cd2

Browse files
committed
Add support for multithread with OpenLoadFlow in security analysis
* Copy network to iidm-impl while multithread variant access is not supported in the network-store * SecurityAnalysisParameters.load() in any case to retrieve specific parameters set in the PlatformConfig (like threadCount)
1 parent b0e6939 commit 48d2cd2

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@
8585
<dependencyManagement>
8686
<dependencies>
8787
<!-- overrides of imports -->
88+
<!-- <dependency>-->
89+
<!-- <groupId>com.powsybl</groupId>-->
90+
<!-- <artifactId>powsybl-open-loadflow</artifactId>-->
91+
<!-- <version>1.13.0</version>-->
92+
<!-- </dependency>-->
8893

8994
<!-- imports -->
9095
<dependency>
@@ -195,6 +200,12 @@
195200
<artifactId>micrometer-registry-prometheus</artifactId>
196201
<scope>runtime</scope>
197202
</dependency>
203+
<!-- FIXME: Remove this runtime dependency when variant multithread access is implemented in the network-store -->
204+
<dependency>
205+
<groupId>com.powsybl</groupId>
206+
<artifactId>powsybl-iidm-impl</artifactId>
207+
<scope>runtime</scope>
208+
</dependency>
198209

199210
<!-- Test dependencies -->
200211
<dependency>

src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisParametersService.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,13 @@ public SecurityAnalysisRunContext createRunContext(UUID networkUuid, String vari
7777
}
7878

7979
public SecurityAnalysisParametersDTO toSecurityAnalysisParameters(SecurityAnalysisParametersEntity entity) {
80-
SecurityAnalysisParameters securityAnalysisParameters;
80+
SecurityAnalysisParameters securityAnalysisParameters = SecurityAnalysisParameters.load();
8181
List<List<Double>> limitReductions = new ArrayList<>();
8282
if (entity == null) {
83-
securityAnalysisParameters = SecurityAnalysisParameters.load()
84-
// the default values are overloaded
85-
.setIncreasedViolationsParameters(getIncreasedViolationsParameters(DEFAULT_FLOW_PROPORTIONAL_THRESHOLD, DEFAULT_LOW_VOLTAGE_PROPORTIONAL_THRESHOLD, DEFAULT_LOW_VOLTAGE_ABSOLUTE_THRESHOLD, DEFAULT_HIGH_VOLTAGE_PROPORTIONAL_THRESHOLD, DEFAULT_HIGH_VOLTAGE_ABSOLUTE_THRESHOLD));
83+
// the default values are overloaded
84+
securityAnalysisParameters.setIncreasedViolationsParameters(getIncreasedViolationsParameters(DEFAULT_FLOW_PROPORTIONAL_THRESHOLD, DEFAULT_LOW_VOLTAGE_PROPORTIONAL_THRESHOLD, DEFAULT_LOW_VOLTAGE_ABSOLUTE_THRESHOLD, DEFAULT_HIGH_VOLTAGE_PROPORTIONAL_THRESHOLD, DEFAULT_HIGH_VOLTAGE_ABSOLUTE_THRESHOLD));
8685
} else {
87-
securityAnalysisParameters = new SecurityAnalysisParameters().setIncreasedViolationsParameters(getIncreasedViolationsParameters(entity.getFlowProportionalThreshold(), entity.getLowVoltageProportionalThreshold(), entity.getLowVoltageAbsoluteThreshold(), entity.getHighVoltageProportionalThreshold(), entity.getHighVoltageAbsoluteThreshold()));
86+
securityAnalysisParameters.setIncreasedViolationsParameters(getIncreasedViolationsParameters(entity.getFlowProportionalThreshold(), entity.getLowVoltageProportionalThreshold(), entity.getLowVoltageAbsoluteThreshold(), entity.getHighVoltageProportionalThreshold(), entity.getHighVoltageAbsoluteThreshold()));
8887
limitReductions = entity.toLimitReductionsValues();
8988
}
9089

src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisWorkerService.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
import com.powsybl.iidm.criteria.duration.IntervalTemporaryDurationCriterion;
1717
import com.powsybl.iidm.criteria.duration.LimitDurationCriterion;
1818
import com.powsybl.iidm.criteria.duration.PermanentDurationCriterion;
19-
import com.powsybl.iidm.network.LimitType;
20-
import com.powsybl.iidm.network.Network;
21-
import com.powsybl.iidm.network.VariantManagerConstants;
19+
import com.powsybl.iidm.network.*;
20+
import com.powsybl.iidm.serde.NetworkSerDe;
2221
import com.powsybl.loadflow.LoadFlowResult;
2322
import com.powsybl.network.store.client.NetworkStoreService;
23+
import com.powsybl.network.store.client.PreloadingStrategy;
2424
import com.powsybl.security.*;
2525
import com.powsybl.security.limitreduction.LimitReduction;
2626
import com.powsybl.ws.commons.LogUtils;
@@ -42,6 +42,7 @@
4242
import java.util.Objects;
4343
import java.util.UUID;
4444
import java.util.concurrent.CompletableFuture;
45+
import java.util.concurrent.TimeUnit;
4546
import java.util.concurrent.atomic.AtomicReference;
4647
import java.util.function.Consumer;
4748
import java.util.function.Function;
@@ -92,6 +93,11 @@ public SecurityAnalysisResult run(SecurityAnalysisRunContext runContext) {
9293
}
9394
}
9495

96+
@Override
97+
protected PreloadingStrategy getNetworkPreloadingStrategy() {
98+
return PreloadingStrategy.ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW;
99+
}
100+
95101
@Override
96102
protected String getComputationType() {
97103
return COMPUTATION_TYPE;
@@ -108,6 +114,20 @@ protected CompletableFuture<SecurityAnalysisResult> getCompletableFuture(Securit
108114
.toList();
109115
List<LimitReduction> limitReductions = createLimitReductions(runContext);
110116

117+
Network network = runContext.getNetwork();
118+
// FIXME: Remove this part when multithread variant access is implemented in the network-store
119+
if (runContext.getProvider().equals("OpenLoadFlow")) {
120+
long startTime = System.nanoTime();
121+
Network originalNetwork = runContext.getNetwork();
122+
String originalVariant = originalNetwork.getVariantManager().getWorkingVariantId();
123+
originalNetwork.getVariantManager().setWorkingVariant(variantId);
124+
125+
network = NetworkSerDe.copy(originalNetwork, NetworkFactory.find("Default"));
126+
network.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, variantId);
127+
LOGGER.info("Network copied to iidm-impl in {} ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime));
128+
originalNetwork.getVariantManager().setWorkingVariant(originalVariant);
129+
}
130+
111131
SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters()
112132
.setSecurityAnalysisParameters(runContext.getParameters().securityAnalysisParameters())
113133
.setComputationManager(executionService.getComputationManager())
@@ -116,7 +136,7 @@ protected CompletableFuture<SecurityAnalysisResult> getCompletableFuture(Securit
116136
.setReportNode(runContext.getReportNode());
117137

118138
return securityAnalysisRunner.runAsync(
119-
runContext.getNetwork(),
139+
network,
120140
variantId,
121141
n -> contingencies,
122142
runParameters)

0 commit comments

Comments
 (0)