diff --git a/flow-decomposition/src/main/java/com/powsybl/flow_decomposition/FlowDecompositionComputer.java b/flow-decomposition/src/main/java/com/powsybl/flow_decomposition/FlowDecompositionComputer.java index 6a4df0cf..0ed46f69 100644 --- a/flow-decomposition/src/main/java/com/powsybl/flow_decomposition/FlowDecompositionComputer.java +++ b/flow-decomposition/src/main/java/com/powsybl/flow_decomposition/FlowDecompositionComputer.java @@ -17,6 +17,8 @@ import com.powsybl.loadflow.LoadFlowParameters; import com.powsybl.sensitivity.SensitivityAnalysis; import com.powsybl.sensitivity.SensitivityVariableType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Map; @@ -28,8 +30,10 @@ */ public class FlowDecompositionComputer { + private static final Logger LOGGER = LoggerFactory.getLogger(FlowDecompositionComputer.class); static final String DEFAULT_LOAD_FLOW_PROVIDER = null; static final String DEFAULT_SENSITIVITY_ANALYSIS_PROVIDER = null; + public static final LoadFlowParameters.ConnectedComponentMode MAIN_CONNECTED_COMPONENT = LoadFlowParameters.ConnectedComponentMode.MAIN; private final LoadFlowParameters loadFlowParameters; private final FlowDecompositionParameters parameters; private final LoadFlowRunningService loadFlowRunningService; @@ -46,7 +50,12 @@ public FlowDecompositionComputer(FlowDecompositionParameters flowDecompositionPa LoadFlowParameters loadFlowParameters, String loadFlowProvider, String sensitivityAnalysisProvider) { this.parameters = flowDecompositionParameters; - this.loadFlowParameters = loadFlowParameters; + this.loadFlowParameters = loadFlowParameters.copy(); + if (!MAIN_CONNECTED_COMPONENT.equals(this.loadFlowParameters.getConnectedComponentMode())) { + LOGGER.warn("Flow decomposition is currently available only on the main synchronous component. Changing connected component mode from {} to MAIN.", + this.loadFlowParameters.getConnectedComponentMode()); + this.loadFlowParameters.setConnectedComponentMode(MAIN_CONNECTED_COMPONENT); + } this.loadFlowRunningService = new LoadFlowRunningService(LoadFlow.find(loadFlowProvider)); this.sensitivityAnalysisRunner = SensitivityAnalysis.find(sensitivityAnalysisProvider); this.lossesCompensator = parameters.isLossesCompensationEnabled() ? new LossesCompensator(parameters) : null; @@ -273,4 +282,8 @@ private void computePstFlows(Network network, SparseMatrixWithIndexesCSC pstFlowMatrix = pstFlowComputer.run(network, networkMatrixIndexes, psdfMatrix); flowDecompositionResultBuilder.savePstFlowMatrix(pstFlowMatrix); } + + protected LoadFlowParameters getLoadFlowParameters() { + return this.loadFlowParameters; + } } diff --git a/flow-decomposition/src/main/java/com/powsybl/flow_decomposition/FlowDecompositionObserver.java b/flow-decomposition/src/main/java/com/powsybl/flow_decomposition/FlowDecompositionObserver.java index b8a48b7b..3f35d695 100644 --- a/flow-decomposition/src/main/java/com/powsybl/flow_decomposition/FlowDecompositionObserver.java +++ b/flow-decomposition/src/main/java/com/powsybl/flow_decomposition/FlowDecompositionObserver.java @@ -62,9 +62,9 @@ public interface FlowDecompositionObserver { /** * Called when the PTDF matrix is computed (for base case or contingency) * - * @param pdtfMatrix the matrix of ptdf indexed by (line, node) + * @param ptdfMatrix the matrix of ptdf indexed by (line, node) */ - void computedPtdfMatrix(Map> pdtfMatrix); + void computedPtdfMatrix(Map> ptdfMatrix); /** * Called when the PSDF matrix is computed (for base case or contingency) diff --git a/flow-decomposition/src/main/java/com/powsybl/flow_decomposition/LoadFlowRunningService.java b/flow-decomposition/src/main/java/com/powsybl/flow_decomposition/LoadFlowRunningService.java index 071cffb5..d1388e6e 100644 --- a/flow-decomposition/src/main/java/com/powsybl/flow_decomposition/LoadFlowRunningService.java +++ b/flow-decomposition/src/main/java/com/powsybl/flow_decomposition/LoadFlowRunningService.java @@ -32,13 +32,13 @@ class LoadFlowRunningService { Result runAcLoadflow(Network network, LoadFlowParameters loadFlowParameters, boolean isDcFallbackEnabledAfterAcDivergence) { LoadFlowParameters acEnforcedParameters = enforceAcLoadFlowCalculation(loadFlowParameters); LoadFlowResult acLoadFlowResult = runner.run(network, acEnforcedParameters); - if (!acLoadFlowResult.isOk() && isDcFallbackEnabledAfterAcDivergence) { + if (!acLoadFlowResult.isFullyConverged() && isDcFallbackEnabledAfterAcDivergence) { LOGGER.warn("AC loadflow divergence. Running DC loadflow as fallback procedure."); return runDcLoadflow(network, loadFlowParameters) .setFallbackHasBeenActivated(FALLBACK_HAS_BEEN_ACTIVATED); } - if (!acLoadFlowResult.isOk()) { - throw new PowsyblException("AC loadfow divergence without fallback procedure enabled."); + if (!acLoadFlowResult.isFullyConverged()) { + throw new PowsyblException("AC loadflow divergence without fallback procedure enabled."); } return new Result(acLoadFlowResult, FALLBACK_HAS_NOT_BEEN_ACTIVATED); } @@ -46,8 +46,8 @@ Result runAcLoadflow(Network network, LoadFlowParameters loadFlowParameters, boo Result runDcLoadflow(Network network, LoadFlowParameters loadFlowParameters) { LoadFlowParameters dcEnforcedParameters = enforceDcLoadFlowCalculation(loadFlowParameters); LoadFlowResult dcLoadFlowResult = runner.run(network, dcEnforcedParameters); - if (!dcLoadFlowResult.isOk()) { - throw new PowsyblException("DC loadfow divergence."); + if (!dcLoadFlowResult.isFullyConverged()) { + throw new PowsyblException("DC loadflow divergence."); } return new Result(dcLoadFlowResult, FALLBACK_HAS_NOT_BEEN_ACTIVATED); } diff --git a/flow-decomposition/src/test/java/com/powsybl/flow_decomposition/FlowDecompositionObserverTest.java b/flow-decomposition/src/test/java/com/powsybl/flow_decomposition/FlowDecompositionObserverTest.java index cdd71bed..c58d53c4 100644 --- a/flow-decomposition/src/test/java/com/powsybl/flow_decomposition/FlowDecompositionObserverTest.java +++ b/flow-decomposition/src/test/java/com/powsybl/flow_decomposition/FlowDecompositionObserverTest.java @@ -120,9 +120,9 @@ public void computedNodalInjectionsMatrix(Map> nodal } @Override - public void computedPtdfMatrix(Map> pdtfMatrix) { + public void computedPtdfMatrix(Map> ptdfMatrix) { addEvent(Event.COMPUTED_PTDF_MATRIX); - this.ptdfs.put(currentContingency, pdtfMatrix); + this.ptdfs.put(currentContingency, ptdfMatrix); } @Override diff --git a/flow-decomposition/src/test/java/com/powsybl/flow_decomposition/FlowDecompositionTests.java b/flow-decomposition/src/test/java/com/powsybl/flow_decomposition/FlowDecompositionTests.java index 73294242..8d5c952b 100644 --- a/flow-decomposition/src/test/java/com/powsybl/flow_decomposition/FlowDecompositionTests.java +++ b/flow-decomposition/src/test/java/com/powsybl/flow_decomposition/FlowDecompositionTests.java @@ -196,6 +196,16 @@ void testFlowDecompositionOnHvdcNetwork() { assertTrue(flowDecompositionResults.getZoneSet().contains(Country.NL)); } + @Test + void testConnectedComponentModeChangesFromAllToMain() { + LoadFlowParameters loadFlowParameters = new LoadFlowParameters().setConnectedComponentMode(LoadFlowParameters.ConnectedComponentMode.ALL); + FlowDecompositionComputer flowDecompositionComputer = new FlowDecompositionComputer(new FlowDecompositionParameters(), loadFlowParameters); + // lfParameters inside flow decomposition changed from all to main + assertEquals(FlowDecompositionComputer.MAIN_CONNECTED_COMPONENT, flowDecompositionComputer.getLoadFlowParameters().getConnectedComponentMode()); + // original lfParameters didn't change + assertEquals(LoadFlowParameters.ConnectedComponentMode.ALL, loadFlowParameters.getConnectedComponentMode()); + } + private static FlowDecompositionResults runFlowDecomposition(Network network, XnecProvider xnecProvider) { FlowDecompositionParameters flowDecompositionParameters = new FlowDecompositionParameters() .setEnableLossesCompensation(FlowDecompositionParameters.ENABLE_LOSSES_COMPENSATION) diff --git a/flow-decomposition/src/test/java/com/powsybl/flow_decomposition/LoadFlowFallbackTests.java b/flow-decomposition/src/test/java/com/powsybl/flow_decomposition/LoadFlowFallbackTests.java index 7280b58d..6bb7d910 100644 --- a/flow-decomposition/src/test/java/com/powsybl/flow_decomposition/LoadFlowFallbackTests.java +++ b/flow-decomposition/src/test/java/com/powsybl/flow_decomposition/LoadFlowFallbackTests.java @@ -26,7 +26,7 @@ */ class LoadFlowFallbackTests { - public static final String FALLBACK_MESSAGE = "AC loadfow divergence without fallback procedure enabled"; + public static final String FALLBACK_MESSAGE = "AC loadflow divergence without fallback procedure enabled."; @Test void testIntegrationOfDisabledFallbackOnNetworkThatDoesNotConvergeInAc() { @@ -38,7 +38,7 @@ void testIntegrationOfDisabledFallbackOnNetworkThatDoesNotConvergeInAc() { XnecProvider xnecProvider = XnecProviderByIds.builder().addNetworkElementsOnBasecase(Set.of("UNUSED")).build(); Executable flowComputerExecutable = () -> flowComputer.run(xnecProvider, network); Exception exception = assertThrows(PowsyblException.class, flowComputerExecutable, FALLBACK_MESSAGE); - assertEquals("AC loadfow divergence without fallback procedure enabled.", exception.getMessage()); + assertEquals(FALLBACK_MESSAGE, exception.getMessage()); } @Test @@ -48,7 +48,7 @@ void testLoadFlowServiceWhenLoadFlowConvergeInACWithFallbackActivated() { LoadFlowRunningService loadFlowRunningService = new LoadFlowRunningService(LoadFlow.find()); LoadFlowRunningService.Result loadFlowResult = loadFlowRunningService.runAcLoadflow( network, new LoadFlowParameters(), LoadFlowRunningService.FALLBACK_HAS_BEEN_ACTIVATED); - assertTrue(loadFlowResult.getLoadFlowResult().isOk()); + assertTrue(loadFlowResult.getLoadFlowResult().isFullyConverged()); assertFalse(loadFlowResult.fallbackHasBeenActivated()); } @@ -59,7 +59,7 @@ void testLoadFlowServiceWhenLoadFlowConvergeInACWithoutFallbackActivated() { LoadFlowRunningService loadFlowRunningService = new LoadFlowRunningService(LoadFlow.find()); LoadFlowRunningService.Result loadFlowResult = loadFlowRunningService.runAcLoadflow( network, new LoadFlowParameters(), LoadFlowRunningService.FALLBACK_HAS_NOT_BEEN_ACTIVATED); - assertTrue(loadFlowResult.getLoadFlowResult().isOk()); + assertTrue(loadFlowResult.getLoadFlowResult().isFullyConverged()); assertFalse(loadFlowResult.fallbackHasBeenActivated()); } @@ -70,7 +70,7 @@ void testLoadFlowServiceWhenLoadFlowDoesNotConvergeInACWithFallbackActivated() { LoadFlowRunningService loadFlowRunningService = new LoadFlowRunningService(LoadFlow.find()); LoadFlowRunningService.Result loadFlowResult = loadFlowRunningService.runAcLoadflow( network, new LoadFlowParameters(), LoadFlowRunningService.FALLBACK_HAS_BEEN_ACTIVATED); - assertTrue(loadFlowResult.getLoadFlowResult().isOk()); + assertTrue(loadFlowResult.getLoadFlowResult().isFullyConverged()); assertTrue(loadFlowResult.fallbackHasBeenActivated()); } @@ -82,6 +82,6 @@ void testLoadFlowServiceWhenLoadFlowDoesNotConvergeInACWithoutFallback() { Executable loadFlowRunningServiceExecutable = () -> loadFlowRunningService.runAcLoadflow( network, new LoadFlowParameters(), LoadFlowRunningService.FALLBACK_HAS_NOT_BEEN_ACTIVATED); Exception exception = assertThrows(PowsyblException.class, loadFlowRunningServiceExecutable, FALLBACK_MESSAGE); - assertEquals("AC loadfow divergence without fallback procedure enabled.", exception.getMessage()); + assertEquals(FALLBACK_MESSAGE, exception.getMessage()); } } diff --git a/flow-decomposition/src/test/java/com/powsybl/flow_decomposition/NodalInjectionTests.java b/flow-decomposition/src/test/java/com/powsybl/flow_decomposition/NodalInjectionTests.java index eef4bd3a..76908963 100644 --- a/flow-decomposition/src/test/java/com/powsybl/flow_decomposition/NodalInjectionTests.java +++ b/flow-decomposition/src/test/java/com/powsybl/flow_decomposition/NodalInjectionTests.java @@ -94,7 +94,7 @@ void testThatReferenceNodalInjectionsAreWellComputedOnLoopFlowNetwork() { private static Map> getNodalInjections(String networkFileName) { Network network = importNetwork(networkFileName); LoadFlowResult loadFlowResult = LoadFlow.run(network); - if (!loadFlowResult.isOk()) { + if (!loadFlowResult.isFullyConverged()) { LoadFlow.run(network, LoadFlowParameters.load().setDc(true)); } AutoGlskProvider glskProvider = new AutoGlskProvider(); @@ -111,7 +111,7 @@ private static Map> getNodalInjections(String networ private static Map getReferenceNodalInjections(String networkFileName) { Network network = importNetwork(networkFileName); LoadFlowResult loadFlowResult = LoadFlow.run(network); - if (!loadFlowResult.isOk()) { + if (!loadFlowResult.isFullyConverged()) { LoadFlow.run(network, LoadFlowParameters.load().setDc(true)); } List xnecList = network.getBranchStream().collect(Collectors.toList());