Skip to content

Commit

Permalink
refactor flow extraction
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Verger <guillaume.verger@artelys.com>
  • Loading branch information
gverger committed Jan 31, 2024
1 parent 644475a commit fc66424
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2024, Coreso SA (https://www.coreso.eu/) and TSCNET Services GmbH (https://www.tscnet.eu/)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.flow_decomposition;

import com.powsybl.iidm.network.Branch;
import com.powsybl.iidm.network.Identifiable;

import java.util.Collection;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author Guillaume Verger {@literal <guillaume.verger at artelys.com>}
*/
class AcReferenceFlowComputer {
private static ReferenceFlowComputer flowComputer = new ReferenceFlowComputer();

Map<String, Double> run(Collection<Branch> xnecList, LoadFlowRunningService.Result loadFlowServiceAcResult) {
if (loadFlowServiceAcResult.fallbackHasBeenActivated()) {
return xnecList.stream().collect(Collectors.toMap(Identifiable::getId, branch -> Double.NaN));
}

return flowComputer.run(xnecList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.powsybl.flow_decomposition.glsk_provider.AutoGlskProvider;
import com.powsybl.iidm.network.Branch;
import com.powsybl.iidm.network.Country;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.Network;
import com.powsybl.loadflow.LoadFlow;
import com.powsybl.loadflow.LoadFlowParameters;
Expand All @@ -19,7 +18,6 @@
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
* @author Sebastien Murgey {@literal <sebastien.murgey at rte-france.com>}
Expand Down Expand Up @@ -180,12 +178,7 @@ private LoadFlowRunningService.Result runAcLoadFlow(Network network) {
}

private void saveAcReferenceFlow(FlowDecompositionResults.PerStateBuilder flowDecompositionResultBuilder, Set<Branch> xnecList, LoadFlowRunningService.Result loadFlowServiceAcResult) {
Map<String, Double> acReferenceFlows;
if (loadFlowServiceAcResult.fallbackHasBeenActivated()) {
acReferenceFlows = xnecList.stream().collect(Collectors.toMap(Identifiable::getId, branch -> Double.NaN));
} else {
acReferenceFlows = getXnecReferenceFlows(xnecList);
}
Map<String, Double> acReferenceFlows = new AcReferenceFlowComputer().run(xnecList, loadFlowServiceAcResult);
flowDecompositionResultBuilder.saveAcReferenceFlow(acReferenceFlows);
}

Expand All @@ -194,9 +187,8 @@ private Map<Country, Double> getZonesNetPosition(Network network) {
return netPositionComputer.run(network);
}

private Map<String, Double> getXnecReferenceFlows(Set<Branch> xnecList) {
ReferenceFlowComputer referenceFlowComputer = new ReferenceFlowComputer();
return referenceFlowComputer.run(xnecList);
private Map<String, Double> getBranchReferenceFlows(Set<Branch> branches) {
return new ReferenceFlowComputer().run(branches);
}

private void compensateLosses(Network network) {
Expand All @@ -218,7 +210,7 @@ private SparseMatrixWithIndexesTriplet getNodalInjectionsMatrix(Network network,
}

private void saveDcReferenceFlow(FlowDecompositionResults.PerStateBuilder flowDecompositionResultBuilder, Set<Branch> xnecList) {
flowDecompositionResultBuilder.saveDcReferenceFlow(getXnecReferenceFlows(xnecList));
flowDecompositionResultBuilder.saveDcReferenceFlow(getBranchReferenceFlows(xnecList));
}

private SensitivityAnalyser getSensitivityAnalyser(Network network, NetworkMatrixIndexes networkMatrixIndexes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@

import com.powsybl.flow_decomposition.LoadFlowRunningService.Result;
import com.powsybl.iidm.network.Country;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.Network;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author Guillaume Verger {@literal <guillaume.verger at artelys.com>}
Expand Down Expand Up @@ -88,13 +86,8 @@ public void computedAcFlows(Network network, Result loadFlowServiceAcResult) {
return;
}

Map<String, Double> acFlows;
if (loadFlowServiceAcResult.fallbackHasBeenActivated()) {
acFlows = network.getBranchStream().collect(Collectors.toMap(Identifiable::getId, branch -> Double.NaN));
} else {
ReferenceFlowComputer flowComputer = new ReferenceFlowComputer();
acFlows = flowComputer.run(network.getBranchStream().collect(Collectors.toSet()));
}
Map<String, Double> acFlows =
new AcReferenceFlowComputer().run(network.getBranchStream().toList(), loadFlowServiceAcResult);

for (FlowDecompositionObserver o : observers) {
o.computedAcFlows(acFlows);
Expand All @@ -107,7 +100,7 @@ public void computedDcFlows(Network network) {
}

ReferenceFlowComputer flowComputer = new ReferenceFlowComputer();
Map<String, Double> dcFlows = flowComputer.run(network.getBranchStream().collect(Collectors.toSet()));
Map<String, Double> dcFlows = flowComputer.run(network.getBranchStream().toList());

for (FlowDecompositionObserver o : observers) {
o.computedDcFlows(dcFlows);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
import com.powsybl.iidm.network.Branch;
import com.powsybl.iidm.network.Identifiable;

import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
* @author Sebastien Murgey {@literal <sebastien.murgey at rte-france.com>}
* @author Hugo Schindler {@literal <hugo.schindler at rte-france.com>}
*/
class ReferenceFlowComputer {
Map<String, Double> run(Set<Branch> xnecList) {
Map<String, Double> run(Collection<Branch> xnecList) {
return xnecList.stream()
.collect(Collectors.toMap(
Identifiable::getId,
Expand Down

0 comments on commit fc66424

Please sign in to comment.