diff --git a/pom.xml b/pom.xml index df8ad38e..22a9c39b 100644 --- a/pom.xml +++ b/pom.xml @@ -85,6 +85,11 @@ + + com.powsybl + powsybl-open-loadflow + 1.13.0 + @@ -195,6 +200,12 @@ micrometer-registry-prometheus runtime + + + com.powsybl + powsybl-iidm-impl + runtime + diff --git a/src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisParametersService.java b/src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisParametersService.java index 03270a42..849de6c9 100644 --- a/src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisParametersService.java +++ b/src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisParametersService.java @@ -77,14 +77,13 @@ public SecurityAnalysisRunContext createRunContext(UUID networkUuid, String vari } public SecurityAnalysisParametersDTO toSecurityAnalysisParameters(SecurityAnalysisParametersEntity entity) { - SecurityAnalysisParameters securityAnalysisParameters; + SecurityAnalysisParameters securityAnalysisParameters = SecurityAnalysisParameters.load(); List> limitReductions = new ArrayList<>(); if (entity == null) { - securityAnalysisParameters = SecurityAnalysisParameters.load() - // the default values are overloaded - .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)); + // the default values are overloaded + 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)); } else { - securityAnalysisParameters = new SecurityAnalysisParameters().setIncreasedViolationsParameters(getIncreasedViolationsParameters(entity.getFlowProportionalThreshold(), entity.getLowVoltageProportionalThreshold(), entity.getLowVoltageAbsoluteThreshold(), entity.getHighVoltageProportionalThreshold(), entity.getHighVoltageAbsoluteThreshold())); + securityAnalysisParameters.setIncreasedViolationsParameters(getIncreasedViolationsParameters(entity.getFlowProportionalThreshold(), entity.getLowVoltageProportionalThreshold(), entity.getLowVoltageAbsoluteThreshold(), entity.getHighVoltageProportionalThreshold(), entity.getHighVoltageAbsoluteThreshold())); limitReductions = entity.toLimitReductionsValues(); } diff --git a/src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisWorkerService.java b/src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisWorkerService.java index 92c473be..837e2988 100644 --- a/src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisWorkerService.java +++ b/src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisWorkerService.java @@ -18,7 +18,9 @@ import com.powsybl.iidm.criteria.duration.PermanentDurationCriterion; import com.powsybl.iidm.network.LimitType; import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.NetworkFactory; import com.powsybl.iidm.network.VariantManagerConstants; +import com.powsybl.iidm.serde.NetworkSerDe; import com.powsybl.loadflow.LoadFlowResult; import com.powsybl.network.store.client.NetworkStoreService; import com.powsybl.security.*; @@ -42,6 +44,7 @@ import java.util.Objects; import java.util.UUID; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; import java.util.function.Function; @@ -108,6 +111,22 @@ protected CompletableFuture getCompletableFuture(Securit .toList(); List limitReductions = createLimitReductions(runContext); + Network network = runContext.getNetwork(); + // FIXME: Remove this part when multithread variant access is implemented in the network-store + if (runContext.getProvider().equals("OpenLoadFlow")) { + long startTime = System.nanoTime(); + Network originalNetwork = runContext.getNetwork(); + String originalVariant = originalNetwork.getVariantManager().getWorkingVariantId(); + originalNetwork.getVariantManager().setWorkingVariant(variantId); + + network = NetworkSerDe.copy(originalNetwork, NetworkFactory.find("Default")); + if (!variantId.equals(VariantManagerConstants.INITIAL_VARIANT_ID)) { + network.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, variantId); + } + LOGGER.info("Network copied to iidm-impl in {} ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime)); + originalNetwork.getVariantManager().setWorkingVariant(originalVariant); + } + SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters() .setSecurityAnalysisParameters(runContext.getParameters().securityAnalysisParameters()) .setComputationManager(executionService.getComputationManager()) @@ -116,7 +135,7 @@ protected CompletableFuture getCompletableFuture(Securit .setReportNode(runContext.getReportNode()); return securityAnalysisRunner.runAsync( - runContext.getNetwork(), + network, variantId, n -> contingencies, runParameters)