Skip to content

Commit

Permalink
load-flow int. deprecated method usage: fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
CBiasuzzi authored and sylvlecl committed Nov 2, 2018
1 parent 01011d1 commit 9af8c8a
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected static CompletableFuture<Boolean> project(ComputationManager computati
LoadFlowParameters loadFlowParameters = LoadFlowParameters.load();
LoadFlowParameters loadFlowParameters2 = LoadFlowParameters.load().setNoGeneratorReactiveLimits(true);

return loadFlow.runAsync(workingStateId, loadFlowParameters)
return loadFlow.run(workingStateId, loadFlowParameters)
.thenComposeAsync(loadFlowResult -> {
LOGGER.debug("Pre-projector load flow metrics: {}", loadFlowResult.getMetrics());
if (!loadFlowResult.isOk()) {
Expand All @@ -140,7 +140,7 @@ protected static CompletableFuture<Boolean> project(ComputationManager computati
if (!Boolean.TRUE.equals(ok)) {
throw new StopException("Projector failed");
}
return loadFlow.runAsync(workingStateId, loadFlowParameters2);
return loadFlow.run(workingStateId, loadFlowParameters2);
}, computationManager.getExecutor())
.thenApplyAsync(loadFlowResult -> {
LOGGER.debug("Post-projector load flow metrics: {}", loadFlowResult.getMetrics());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ public static void insert(Network n, LoadFlowFactory loadFlowFactory, Computatio
long start = System.currentTimeMillis();

LoadFlow loadFlow = loadFlowFactory.create(n, computationManager, 0);
LoadFlowResult result = loadFlow.run(new LoadFlowParameters(LoadFlowParameters.VoltageInitMode.UNIFORM_VALUES));
LoadFlowResult result = loadFlow.run(n.getStateManager().getWorkingStateId(), new LoadFlowParameters(LoadFlowParameters.VoltageInitMode.UNIFORM_VALUES)).join();
// if (LOGGER.isTraceEnabled()) {
// LOGGER.trace("\n{}", result.getLogs());
// }
Expand All @@ -729,7 +729,7 @@ public static void insert(Network n, LoadFlowFactory loadFlowFactory, Computatio
if (config.isRemoveAlreadyExistingStators()) {
removeStepUpTransformersAlreadyPresents(n, statorVoltageLevels, config);

result = loadFlow.run(new LoadFlowParameters(LoadFlowParameters.VoltageInitMode.UNIFORM_VALUES));
result = loadFlow.run(n.getStateManager().getWorkingStateId(), new LoadFlowParameters(LoadFlowParameters.VoltageInitMode.UNIFORM_VALUES)).join();
// if (LOGGER.isTraceEnabled()) {
// LOGGER.trace("\n{}", result.getLogs());
// }
Expand All @@ -754,7 +754,7 @@ public static void insert(Network n, LoadFlowFactory loadFlowFactory, Computatio
LOGGER.debug(" {}: {}", entry.getKey(), entry.getValue());
}

result = loadFlow.run(new LoadFlowParameters(LoadFlowParameters.VoltageInitMode.UNIFORM_VALUES));
result = loadFlow.run(n.getStateManager().getWorkingStateId(), new LoadFlowParameters(LoadFlowParameters.VoltageInitMode.UNIFORM_VALUES)).join();
// if (LOGGER.isTraceEnabled()) {
// LOGGER.trace("\n{}", result.getLogs());
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.powsybl.computation.ComputationManager;
import com.powsybl.computation.local.LocalComputationManager;
import com.powsybl.loadflow.LoadFlowParameters;
import eu.itesla_project.iidm.ddb.service.DDBManager;
import eu.itesla_project.iidm.ejbclient.EjbClientCtx;
import com.powsybl.iidm.network.*;
Expand Down Expand Up @@ -154,7 +155,7 @@ private void runLoadFlow(ComputationManager computationManager) throws Exception
int priority = 1;
LoadFlow loadflow = loadFlowFactory.create(_network, computationManager, priority);
//((HELMLoadFlow) loadflow).setSlack(this._slackId);
LoadFlowResult lfResults = loadflow.run();
LoadFlowResult lfResults = loadflow.run(_network.getStateManager().getWorkingStateId(), LoadFlowParameters.load()).join();

if (!lfResults.isOk()) {
System.out.println("LF has not been successfuly completed.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package eu.itesla_project.modules;

import com.google.auto.service.AutoService;
import com.powsybl.loadflow.LoadFlowParameters;
import com.powsybl.security.LimitViolationFilter;
import com.powsybl.tools.Command;
import com.powsybl.tools.Tool;
Expand Down Expand Up @@ -146,7 +147,7 @@ public void run(CommandLine line, ToolRunningContext context) throws Exception {
if (result.isFeasible()) {
context.getOutputStream().println("running loadflow...");

LoadFlowResult result2 = loadFlow.run();
LoadFlowResult result2 = loadFlow.run(network.getStateManager().getWorkingStateId(), LoadFlowParameters.load()).join();

context.getOutputStream().println("loadflow status is " + (result2.isOk() ? "ok" : "nok") + " (" + result2.getMetrics() + ")");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.google.auto.service.AutoService;
import com.google.common.collect.Queues;
import com.powsybl.loadflow.LoadFlowParameters;
import eu.itesla_project.cases.CaseRepository;
import eu.itesla_project.cases.CaseRepositoryFactory;
import eu.itesla_project.cases.CaseType;
Expand Down Expand Up @@ -363,6 +364,7 @@ public void run(CommandLine line, ToolRunningContext context) throws Exception {

int cores = Runtime.getRuntime().availableProcessors();
ExecutorService executorService = Executors.newFixedThreadPool(cores);
LoadFlowParameters loadFlowParameters = LoadFlowParameters.load();
try {
List<Future<?>> tasks = new ArrayList<>(cores);
for (int i = 0; i < cores; i++) {
Expand All @@ -386,7 +388,7 @@ public void run(CommandLine line, ToolRunningContext context) throws Exception {
Map<RuleId, Map<HistoDbAttributeId, Object>> valuesPerRule = new HashMap<>();

LoadFlow loadFlow = loadFlowFactory.create(network, context.getComputationManager(), 0);
LoadFlowResult loadFlowResult = loadFlow.run();
LoadFlowResult loadFlowResult = loadFlow.run(network.getStateManager().getWorkingStateId(), loadFlowParameters).join();

context.getErrorStream().println("load flow terminated (" + loadFlowResult.isOk() + ") on " + network.getId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static Network merge(CaseRepository caseRepository, DateTime date, CaseTy
if (optimize) {
for (Network network : networks) {
LoadFlow loadFlow = loadFlowFactory.create(network, computationManager, loadFlowPriority);
LoadFlowResult result = loadFlow.run(loadFlowParameters);
LoadFlowResult result = loadFlow.run(network.getStateManager().getWorkingStateId(), loadFlowParameters).join();
if (!result.isOk()) {
LOGGER.error("LF divergence on network " + network.getId());
}
Expand Down Expand Up @@ -128,7 +128,7 @@ public static Network merge(CaseRepository caseRepository, DateTime date, CaseTy
}

LoadFlow loadFlow = loadFlowFactory.create(merge, computationManager, loadFlowPriority);
LoadFlowResult result = loadFlow.run(loadFlowParameters);
LoadFlowResult result = loadFlow.run(merge.getStateManager().getWorkingStateId(), loadFlowParameters).join();
if (!result.isOk()) {
throw new RuntimeException("Merge LF divergence");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ protected boolean runLoadFlow(WorkflowContext context, WorkflowStartContext star
LOGGER.debug("Workflow {}, sample {}: load flow started", id, sample.getId());

try {
LoadFlowResult result = context.getLoadflow().run(context.getLoadFlowParameters());
LoadFlowResult result = context.getLoadflow().run(context.getNetwork().getStateManager().getWorkingStateId(), context.getLoadFlowParameters()).join();

LOGGER.debug("Workflow {}, sample {}: load flow terminated (ok={})", id, sample.getId(), result.isOk());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class StopException extends RuntimeException {
}, executorService)
.thenComposeAsync(aVoid -> {
LOGGER.debug("Workflow {}, case {}: loadflow started", id, caseNum);
return context.loadFlow.runAsync(getCaseId(caseNum), loadFlowParameters);
return context.loadFlow.run(getCaseId(caseNum), loadFlowParameters);
}, executorService)
.thenAcceptAsync(loadFlowResult -> {
context.network.getStateManager().setWorkingState(getCaseId(caseNum));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ public String getLogs() {
return null;
}
};
Mockito.when(loadFlow.run(Matchers.any(LoadFlowParameters.class)))
.thenReturn(loadFlowResult);
Mockito.when(loadFlow.run(Matchers.any(String.class), Matchers.any(LoadFlowParameters.class)))
.thenReturn(CompletableFuture.completedFuture(loadFlowResult));

// dynamic simulation stabilization mock
Stabilization stabilization = Mockito.mock(Stabilization.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.StateManager;
import com.powsybl.loadflow.LoadFlow;
import com.powsybl.loadflow.LoadFlowParameters;
import com.powsybl.loadflow.LoadFlowResult;
import eu.itesla_project.modules.constraints.ConstraintsModifier;
import eu.itesla_project.modules.contingencies.ActionParameters;
Expand Down Expand Up @@ -61,6 +62,8 @@ public class StateAnalyzer implements Callable<Void> {
Map<String, Boolean> loadflowResults = new HashMap<String, Boolean>();
private ConstraintsModifier constraintsModifier;
private final String logHeader;
private final LoadFlowParameters loadFlowParameters;


public StateAnalyzer(OnlineWorkflowContext context, MontecarloSampler sampler, LoadFlow loadFlow,
OnlineRulesFacade rulesFacade, CorrectiveControlOptimizer optimizer, Stabilization stabilization,
Expand Down Expand Up @@ -94,6 +97,7 @@ public StateAnalyzer(OnlineWorkflowContext context, MontecarloSampler sampler, L
initStatus();
stateListener.onUpdate(stateId, status, context.timeHorizon);
this.logHeader = " [WorkflowId=" + context.getWorkflowId() + "] ";
this.loadFlowParameters = LoadFlowParameters.load();
}

private void initStatus() {
Expand Down Expand Up @@ -132,7 +136,7 @@ public Void call() throws Exception {
status.put(currentStatus, OnlineTaskStatus.RUNNING);
stateListener.onUpdate(stateId, status, context.timeHorizon);
logger.info(this.logHeader + "{}: loadflow started", stateId);
LoadFlowResult result = loadFlow.run();
LoadFlowResult result = loadFlow.run(context.getNetwork().getStateManager().getWorkingStateId(), loadFlowParameters).join();
status.put(currentStatus, result.isOk() ? OnlineTaskStatus.SUCCESS : OnlineTaskStatus.FAILED);
stateListener.onUpdate(stateId, status, context.timeHorizon);
logger.info(this.logHeader + "{}: loadflow terminated", stateId);
Expand Down Expand Up @@ -456,7 +460,7 @@ private boolean computePostContingencyState(Network network, String stateId, Con
try {
// run load flow on post contingency state
logger.info(this.logHeader + "{}: running load flow on post contingency state {}", stateId, postContingencyStateId);
LoadFlowResult result = loadFlow.run();
LoadFlowResult result = loadFlow.run(network.getStateManager().getWorkingStateId(), loadFlowParameters).join();
if (!alreadyProcessed) {
// store post contingency state
Integer stateIdInt = Integer.parseInt(stateId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public ImpactAnalysisResult run(SimulationState state, Set<String> contingencyId
try {
createPostContingencyState(contingency, baseStateId, contingencyStateId);

LoadFlowResult loadFlowResult = loadFlow.run(loadFlowParameters);
LoadFlowResult loadFlowResult = loadFlow.run(network.getStateManager().getWorkingStateId(), loadFlowParameters).join();

analyseLoadFlowResult(baseStateId, index, contingency, contingencyStateId, loadFlowResult, baseViolationsByType,
metrics, securityIndexes, okCount);
Expand Down Expand Up @@ -307,7 +307,7 @@ public CompletableFuture<ImpactAnalysisResult> runAsync(SimulationState state, S

results.add(
CompletableFuture.runAsync(() -> createPostContingencyState(contingency, baseStateId, contingencyStateId), computationManager.getExecutor())
.thenComposeAsync(aVoid -> loadFlow.runAsync(contingencyStateId, loadFlowParameters),
.thenComposeAsync(aVoid -> loadFlow.run(contingencyStateId, loadFlowParameters),
computationManager.getExecutor())
.thenAcceptAsync(loadFlowResult -> analyseLoadFlowResult(baseStateId, index, contingency, contingencyStateId, loadFlowResult, baseViolationsByType,
metrics, securityIndexes, okCount), computationManager.getExecutor())
Expand Down
14 changes: 7 additions & 7 deletions wca-integration/src/main/java/eu/itesla_project/wca/WCAImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ private CompletableFuture<WCAClusterNum> createClustersWorkflowTask(Contingency
contingency.toTask().modify(network, computationManager);

}, computationManager.getExecutor())
.thenCompose(aVoid -> loadFlow.runAsync(contingencyStateId[0], LOAD_FLOW_PARAMETERS))
.thenCompose(aVoid -> loadFlow.run(contingencyStateId[0], LOAD_FLOW_PARAMETERS))
.thenCompose(loadFlowResult -> {
if (!loadFlowResult.isOk()) {
LOGGER.warn("Network {}, contingency {}: load flow on post contingency state diverged, metrics = {}",
Expand Down Expand Up @@ -546,7 +546,7 @@ private CompletableFuture<WCAClusterNum> createClustersWorkflowTask(Contingency
}
LoadFlowResult loadFlowResult1;
try {
loadFlowResult1 = loadFlow.run(LOAD_FLOW_PARAMETERS);
loadFlowResult1 = loadFlow.run(network.getStateManager().getWorkingStateId(), LOAD_FLOW_PARAMETERS).join();
if (loadFlowResult1.isOk()) {
boolean violationsRemoved = false;
boolean actionApplied = false;
Expand Down Expand Up @@ -629,7 +629,7 @@ private CompletableFuture<WCAClusterNum> createClustersWorkflowTask(Contingency
WCAUtils.applyInjections(network, clustersUncertaintiesState, clusterResults2.getInjections());
LOGGER.info("Network {}, contingency {}: running loadflow on post contingency state with 'clusters' uncertainties",
network.getId(), contingency.getId());
loadFlow.runAsync(clustersUncertaintiesState, LOAD_FLOW_PARAMETERS)
loadFlow.run(clustersUncertaintiesState, LOAD_FLOW_PARAMETERS)
.thenAccept(loadFlowResult2 -> {
if (!loadFlowResult2.isOk()) {
LOGGER.info("Network {}, contingency {}: loadflow on state with 'clusters' uncertainties diverged: metrics = {}",
Expand Down Expand Up @@ -683,7 +683,7 @@ private CompletableFuture<List<CompletableFuture<WCACluster>>> createWcaTask(Str
LoadFlow loadFlow = loadFlowFactory.create(network, computationManager, 0);

return loadFlow
.runAsync(baseStateId, LOAD_FLOW_PARAMETERS)
.run(baseStateId, LOAD_FLOW_PARAMETERS)
.thenApply(loadFlowInBaseStateResult -> {

network.getStateManager().setWorkingState(baseStateId);
Expand Down Expand Up @@ -769,7 +769,7 @@ private CompletableFuture<List<CompletableFuture<WCACluster>>> createWcaTask(Str
network.getStateManager().setWorkingState(domainsUncertaintiesState);
WCAUtils.applyInjections(network, domainsUncertaintiesState, domainsResult.getInjections());
LOGGER.info("Network {}: running loadflow on state with 'domains' uncertainties", network.getId());
return loadFlow.runAsync(domainsUncertaintiesState, LOAD_FLOW_PARAMETERS)
return loadFlow.run(domainsUncertaintiesState, LOAD_FLOW_PARAMETERS)
.thenApply(loadFlowResult -> {
if (!loadFlowResult.isOk()) {
LOGGER.info("Network {}: loadflow on state with 'domains' uncertainties diverged, metrics = {}", network.getId(), loadFlowResult.getMetrics());
Expand Down Expand Up @@ -836,7 +836,7 @@ private CompletableFuture<List<CompletableFuture<WCACluster>>> createWcaTask(Str
}
LoadFlowResult loadFlowResult1;
try {
loadFlowResult1 = loadFlow.run(LOAD_FLOW_PARAMETERS);
loadFlowResult1 = loadFlow.run(network.getStateManager().getWorkingStateId(), LOAD_FLOW_PARAMETERS).join();
if (loadFlowResult1.isOk()) {
List<LimitViolation> preventiveStateLimitViolations = violationsFilter.apply(Security.checkLimits(network), network);
Optional<LimitViolation> notSolvedLimitViolation = preventiveStateLimitViolations
Expand Down Expand Up @@ -966,7 +966,7 @@ private CompletableFuture<List<CompletableFuture<WCACluster>>> createWcaTask(Str
}
});
}, computationManager.getExecutor())
.thenCompose(ignored -> loadFlow.runAsync(baseStateId, LOAD_FLOW_PARAMETERS))
.thenCompose(ignored -> loadFlow.run(baseStateId, LOAD_FLOW_PARAMETERS))
.thenAccept(ignored -> {
// check that the violations have disappeared? this check has already been done previously
// update basecase remaining violations
Expand Down
Loading

0 comments on commit 9af8c8a

Please sign in to comment.