Skip to content

Commit d712009

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 d712009

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
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: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
import com.powsybl.iidm.criteria.duration.PermanentDurationCriterion;
1919
import com.powsybl.iidm.network.LimitType;
2020
import com.powsybl.iidm.network.Network;
21+
import com.powsybl.iidm.network.NetworkFactory;
2122
import com.powsybl.iidm.network.VariantManagerConstants;
23+
import com.powsybl.iidm.serde.NetworkSerDe;
2224
import com.powsybl.loadflow.LoadFlowResult;
2325
import com.powsybl.network.store.client.NetworkStoreService;
2426
import com.powsybl.security.*;
@@ -42,6 +44,7 @@
4244
import java.util.Objects;
4345
import java.util.UUID;
4446
import java.util.concurrent.CompletableFuture;
47+
import java.util.concurrent.TimeUnit;
4548
import java.util.concurrent.atomic.AtomicReference;
4649
import java.util.function.Consumer;
4750
import java.util.function.Function;
@@ -108,6 +111,22 @@ protected CompletableFuture<SecurityAnalysisResult> getCompletableFuture(Securit
108111
.toList();
109112
List<LimitReduction> limitReductions = createLimitReductions(runContext);
110113

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

118137
return securityAnalysisRunner.runAsync(
119-
runContext.getNetwork(),
138+
network,
120139
variantId,
121140
n -> contingencies,
122141
runParameters)

0 commit comments

Comments
 (0)