diff --git a/pom.xml b/pom.xml index 97f490767a..26d6726385 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,7 @@ data distribution loopflow-computation + pst-regulation ra-optimisation sensitivity-analysis util diff --git a/pst-regulation/pom.xml b/pst-regulation/pom.xml new file mode 100644 index 0000000000..e5c58028d2 --- /dev/null +++ b/pst-regulation/pom.xml @@ -0,0 +1,98 @@ + + + 4.0.0 + + com.powsybl + powsybl-open-rao + 7.2.0-SNAPSHOT + + + open-rao-pst-regulation + jar + PST Regulation + Post-RAO PST regulatoin module + + + 21 + 21 + UTF-8 + + + + com.powsybl + open-rao-rao-result-api + ${project.version} + + + ${project.groupId} + open-rao-rao-api + ${project.version} + + + ${project.groupId} + open-rao-util + ${project.version} + + + com.powsybl + powsybl-open-loadflow + compile + + + ${project.groupId} + open-rao-sensitivity-analysis + ${project.version} + + + ${project.groupId} + open-rao-search-tree-rao + ${project.version} + + + + + org.junit.jupiter + junit-jupiter + test + + + org.mockito + mockito-core + test + + + ch.qos.logback + logback-core + 1.5.32 + test + + + ch.qos.logback + logback-classic + + + com.powsybl + powsybl-config-test + test + + + com.powsybl + powsybl-commons-test + ${powsybl.core.version} + test + + + com.powsybl + powsybl-iidm-impl + test + + + com.powsybl + powsybl-ucte-converter + test + + + + \ No newline at end of file diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/ElementaryPstRegulationInput.java b/pst-regulation/src/main/java/com/powsybl/openrao/pstregulation/ElementaryPstRegulationInput.java similarity index 91% rename from ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/ElementaryPstRegulationInput.java rename to pst-regulation/src/main/java/com/powsybl/openrao/pstregulation/ElementaryPstRegulationInput.java index d94d89f1dd..389035408d 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/ElementaryPstRegulationInput.java +++ b/pst-regulation/src/main/java/com/powsybl/openrao/pstregulation/ElementaryPstRegulationInput.java @@ -1,11 +1,11 @@ /* - * Copyright (c) 2025, RTE (http://www.rte-france.com) + * Copyright (c) 2026, RTE (http://www.rte-france.com) * 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/. */ -package com.powsybl.openrao.searchtreerao.castor.algorithm.pstregulation; +package com.powsybl.openrao.pstregulation; import com.powsybl.iidm.network.Branch; import com.powsybl.iidm.network.Network; @@ -43,9 +43,7 @@ public static ElementaryPstRegulationInput of(PstRangeAction pstRangeAction, Str if (pstRangeAction.getNetworkElement().getId().equals(monitoredNetworkElement)) { double thresholdOne = getMostLimitingThreshold(curativeFlowCnecs, TwoSides.ONE); double thresholdTwo = getMostLimitingThreshold(curativeFlowCnecs, TwoSides.TWO); - return thresholdOne <= thresholdTwo ? - new ElementaryPstRegulationInput(pstRangeAction, TwoSides.ONE, thresholdOne) : - new ElementaryPstRegulationInput(pstRangeAction, TwoSides.TWO, thresholdTwo); + return thresholdOne <= thresholdTwo ? new ElementaryPstRegulationInput(pstRangeAction, TwoSides.ONE, thresholdOne) : new ElementaryPstRegulationInput(pstRangeAction, TwoSides.TWO, thresholdTwo); } // otherwise, the terminal in common with the element in series it monitors is used @@ -103,7 +101,6 @@ private static Pair getSidesOfCommonTerminal(PstRangeAction } } - throw new OpenRaoException("Two-windings transformer '%s' and branch '%s' do not share a common terminal so PST regulation cannot be performed." - .formatted(twoWindingsTransformerId, monitoredNetworkElement)); + throw new OpenRaoException("Two-windings transformer '%s' and branch '%s' do not share a common terminal so PST regulation cannot be performed.".formatted(twoWindingsTransformerId, monitoredNetworkElement)); } } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/CastorPstRegulation.java b/pst-regulation/src/main/java/com/powsybl/openrao/pstregulation/PstRegulation.java similarity index 54% rename from ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/CastorPstRegulation.java rename to pst-regulation/src/main/java/com/powsybl/openrao/pstregulation/PstRegulation.java index 3cbfe2d52b..10b9352535 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/CastorPstRegulation.java +++ b/pst-regulation/src/main/java/com/powsybl/openrao/pstregulation/PstRegulation.java @@ -1,11 +1,11 @@ /* - * Copyright (c) 2025, RTE (http://www.rte-france.com) + * Copyright (c) 2026, RTE (http://www.rte-france.com) * 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/. */ -package com.powsybl.openrao.searchtreerao.castor.algorithm.pstregulation; +package com.powsybl.openrao.pstregulation; import com.powsybl.contingency.Contingency; import com.powsybl.iidm.network.Network; @@ -19,16 +19,31 @@ import com.powsybl.openrao.data.crac.api.State; import com.powsybl.openrao.data.crac.api.cnec.FlowCnec; import com.powsybl.openrao.data.crac.api.rangeaction.PstRangeAction; +import com.powsybl.openrao.data.raoresult.api.ComputationStatus; import com.powsybl.openrao.data.raoresult.api.RaoResult; +import com.powsybl.openrao.raoapi.RaoInput; import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.powsybl.openrao.raoapi.parameters.extensions.OpenRaoSearchTreeParameters; import com.powsybl.openrao.raoapi.parameters.extensions.SearchTreeRaoPstRegulationParameters; +import com.powsybl.openrao.searchtreerao.castor.algorithm.PostPerimeterSensitivityAnalysis; +import com.powsybl.openrao.searchtreerao.castor.algorithm.PrePerimeterSensitivityAnalysis; +import com.powsybl.openrao.searchtreerao.castor.algorithm.StateTree; +import com.powsybl.openrao.searchtreerao.commons.ToolProvider; +import com.powsybl.openrao.searchtreerao.result.api.OptimizationResult; +import com.powsybl.openrao.searchtreerao.result.api.PrePerimeterResult; +import com.powsybl.openrao.searchtreerao.result.impl.NetworkActionsResultImpl; +import com.powsybl.openrao.searchtreerao.result.impl.OptimizationResultImpl; import com.powsybl.openrao.searchtreerao.result.impl.PostPerimeterResult; -import com.powsybl.openrao.searchtreerao.result.impl.SkippedOptimizationResultImpl; +import com.powsybl.openrao.searchtreerao.result.impl.PreventiveAndCurativesRaoResultImpl; +import com.powsybl.openrao.searchtreerao.result.impl.RangeActionActivationResultImpl; +import com.powsybl.openrao.searchtreerao.result.impl.RangeActionSetpointResultImpl; +import com.powsybl.openrao.sensitivityanalysis.AppliedRemedialActions; import com.powsybl.openrao.util.AbstractNetworkPool; import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -43,55 +58,34 @@ import static com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider.BUSINESS_LOGS; import static com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider.BUSINESS_WARNS; import static com.powsybl.openrao.raoapi.parameters.extensions.MultithreadingParameters.getAvailableCPUs; -import static com.powsybl.openrao.searchtreerao.commons.RaoUtil.getFlowUnit; /** * @author Thomas Bouquet {@literal } */ -public final class CastorPstRegulation { - private CastorPstRegulation() { +public final class PstRegulation { + private static final String INITIAL_SCENARIO = "InitialScenario"; + + private PstRegulation() { } - public static Set regulatePsts(Map pstsToRegulate, - Map postContingencyResults, - Network network, - Crac crac, - RaoParameters raoParameters, - RaoResult raoResult) { - // filter out non-curative PSTs - // currently, only PSTs with a usage rule for a given state are regulated + public static RaoResult regulatePsts(Network network, Crac crac, RaoResult raoResult, RaoParameters raoParameters) { + Map pstsToRegulate = SearchTreeRaoPstRegulationParameters.getPstsToRegulate(raoParameters); + if (pstsToRegulate.isEmpty()) { + return raoResult; + } + Set rangeActionsToRegulate = getPstRangeActionsForRegulation(pstsToRegulate.keySet(), crac); if (rangeActionsToRegulate.isEmpty()) { - return Set.of(); + return raoResult; } - Set statesToRegulate = getStatesToRegulate( - crac, - postContingencyResults, - getFlowUnit(raoParameters), - rangeActionsToRegulate, - SearchTreeRaoPstRegulationParameters.getPstsToRegulate(raoParameters), - network - ); + Set statesToRegulate = getStatesToRegulate(crac, raoResult, getFlowUnit(raoParameters), rangeActionsToRegulate, SearchTreeRaoPstRegulationParameters.getPstsToRegulate(raoParameters), network); if (statesToRegulate.isEmpty()) { - return Set.of(); + return raoResult; } - Set contingencies = statesToRegulate.stream() - .map(PstRegulationInput::curativeState) - .map(State::getContingency) - .filter(Optional::isPresent) - .map(Optional::get) - .collect(Collectors.toSet()); - BUSINESS_LOGS.info( - "{} contingency scenario(s) to regulate: {}", - contingencies.size(), - String.join(", ", contingencies.stream() - .map(contingency -> contingency.getName().orElse(contingency.getId())) - .sorted() - .toList() - ) - ); + Set contingencies = statesToRegulate.stream().map(PstRegulationInput::curativeState).map(State::getContingency).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toSet()); + BUSINESS_LOGS.info("{} contingency scenario(s) to regulate: {}", contingencies.size(), String.join(", ", contingencies.stream().map(contingency -> contingency.getName().orElse(contingency.getId())).sorted().toList())); BUSINESS_LOGS.info("{} PST(s) to regulate: {}", rangeActionsToRegulate.size(), String.join(", ", rangeActionsToRegulate.stream().map(PstRangeAction::getName).sorted().toList())); // update loadflow parameters @@ -116,16 +110,24 @@ public static Set regulatePsts(Map pstsToRe } } networkPool.shutdownAndAwaitTermination(1000, TimeUnit.SECONDS); - return pstRegulationResults; - } catch (OpenRaoException | InterruptedException e) { + return mergePstRegulationResultsWithRaoResult(pstRegulationResults, raoResult, network, crac, raoParameters); + } catch (Exception e) { Thread.currentThread().interrupt(); - BUSINESS_WARNS.warn("An error occurred during PST regulation, pre-regulation RAO result will be kept."); - return Set.of(); + BUSINESS_WARNS.warn("An error occurred during PST regulation, pre-regulation RAO result will be kept. Error was: {}", e.getMessage()); + return raoResult; } finally { loadFlowParameters.setPhaseShifterRegulationOn(initialPhaseShifterRegulationOnValue); } } + private static Unit getFlowUnit(RaoParameters raoParameters) { + OpenRaoSearchTreeParameters searchTreeParameters = raoParameters.getExtension(OpenRaoSearchTreeParameters.class); + if (searchTreeParameters != null) { + return searchTreeParameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters().getLoadFlowParameters().isDc() ? Unit.MEGAWATT : Unit.AMPERE; + } + return Unit.AMPERE; + } + /** * Determines the states for which PST regulation must be applied. There are two conditions: *
    @@ -134,32 +136,20 @@ public static Set regulatePsts(Map pstsToRe *
* For all such states, the associated PST regulation input is included in a set that is returned. */ - private static Set getStatesToRegulate(Crac crac, - Map postContingencyResults, - Unit unit, - Set rangeActionsToRegulate, - Map linesInSeriesWithPst, - Network network) { + private static Set getStatesToRegulate(Crac crac, RaoResult raoResult, Unit unit, Set rangeActionsToRegulate, Map linesInSeriesWithPst, Network network) { Instant lastInstant = crac.getLastInstant(); return lastInstant.isCurative() ? crac.getStates(lastInstant).stream() - .filter(postContingencyResults::containsKey) - .filter(curativeState -> !(postContingencyResults.get(curativeState).optimizationResult() instanceof SkippedOptimizationResultImpl)) - .map(curativeState -> getPstRegulationInput(curativeState, crac, postContingencyResults.get(curativeState), unit, rangeActionsToRegulate, linesInSeriesWithPst, network)) + .filter(state -> raoResult.getComputationStatus(state) != ComputationStatus.FAILURE) + .map(curativeState -> getPstRegulationInput(curativeState, crac, raoResult, unit, rangeActionsToRegulate, linesInSeriesWithPst, network)) .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toSet()) : Set.of(); } - private static Optional getPstRegulationInput(State curativeState, - Crac crac, - PostPerimeterResult postPerimeterResult, - Unit unit, - Set rangeActionsToRegulate, - Map linesInSeriesWithPst, - Network network) { - Optional limitingElement = getMostLimitingElementProtectedByPst(curativeState, crac, postPerimeterResult, unit, new HashSet<>(linesInSeriesWithPst.values())); + private static Optional getPstRegulationInput(State curativeState, Crac crac, RaoResult raoResult, Unit unit, Set rangeActionsToRegulate, Map linesInSeriesWithPst, Network network) { + Optional limitingElement = getMostLimitingElementProtectedByPst(curativeState, crac, raoResult, unit, new HashSet<>(linesInSeriesWithPst.values())); if (limitingElement.isPresent()) { Set elementaryPstRegulationInputs = rangeActionsToRegulate.stream() .filter(pstRangeAction -> linesInSeriesWithPst.containsKey(pstRangeAction.getNetworkElement().getId())) @@ -174,12 +164,8 @@ private static Optional getPstRegulationInput(State curative * If the most limiting element of a curative state is overloaded and is in series with a PST, it is returned. * If not, an empty optional value is returned instead. */ - private static Optional getMostLimitingElementProtectedByPst(State curativeState, Crac crac, PostPerimeterResult postPerimeterResult, Unit unit, Set linesInSeriesWithPst) { - Map marginPerCnec = crac.getFlowCnecs(curativeState).stream() - .collect(Collectors.toMap( - Function.identity(), - flowCnec -> postPerimeterResult.optimizationResult().getMargin(flowCnec, unit) - )); + private static Optional getMostLimitingElementProtectedByPst(State curativeState, Crac crac, RaoResult raoResult, Unit unit, Set linesInSeriesWithPst) { + Map marginPerCnec = crac.getFlowCnecs(curativeState).stream().collect(Collectors.toMap(Function.identity(), flowCnec -> raoResult.getMargin(curativeState.getInstant(), flowCnec, unit))); List> sortedNegativeMargins = marginPerCnec.entrySet().stream() .filter(entry -> entry.getValue() < 0) .sorted(Map.Entry.comparingByValue()).toList(); @@ -195,9 +181,7 @@ private static Optional getMostLimitingElementProtectedByPst(State cur } private static LoadFlowParameters getLoadFlowParameters(RaoParameters raoParameters) { - return raoParameters.hasExtension(OpenRaoSearchTreeParameters.class) ? - raoParameters.getExtension(OpenRaoSearchTreeParameters.class).getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters().getLoadFlowParameters() : - new LoadFlowParameters(); + return raoParameters.hasExtension(OpenRaoSearchTreeParameters.class) ? raoParameters.getExtension(OpenRaoSearchTreeParameters.class).getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters().getLoadFlowParameters() : new LoadFlowParameters(); } private static void updateLoadFlowParametersForPstRegulation(LoadFlowParameters loadFlowParameters) { @@ -242,12 +226,7 @@ private static int getNumberOfThreads(Crac crac, RaoParameters raoParameters) { /** * Performs PST regulation for a curative state. The taps are changed during the loadflow iterations. */ - private static PstRegulationResult regulatePstsForContingencyScenario(PstRegulationInput pstRegulationInput, - Crac crac, - Set rangeActionsToRegulate, - RaoResult raoResult, - LoadFlowParameters loadFlowParameters, - AbstractNetworkPool networkPool) throws InterruptedException { + private static PstRegulationResult regulatePstsForContingencyScenario(PstRegulationInput pstRegulationInput, Crac crac, Set rangeActionsToRegulate, RaoResult raoResult, LoadFlowParameters loadFlowParameters, AbstractNetworkPool networkPool) throws InterruptedException { Network networkClone = networkPool.getAvailableNetwork(); Contingency contingency = pstRegulationInput.curativeState().getContingency().orElseThrow(); simulateContingencyAndApplyCurativeActions(contingency, networkClone, crac, raoResult); @@ -269,11 +248,7 @@ private static void simulateContingencyAndApplyCurativeActions(Contingency conti } private static Map getInitialTapPerPst(Set rangeActionsToRegulate, Network networkClone) { - return rangeActionsToRegulate.stream() - .collect(Collectors.toMap( - Function.identity(), - pstRangeAction -> networkClone.getTwoWindingsTransformer(pstRangeAction.getNetworkElement().getId()).getPhaseTapChanger().getTapPosition() - )); + return rangeActionsToRegulate.stream().collect(Collectors.toMap(Function.identity(), pstRangeAction -> networkClone.getTwoWindingsTransformer(pstRangeAction.getNetworkElement().getId()).getPhaseTapChanger().getTapPosition())); } private static void logPstRegulationResultsForContingencyScenario(Contingency contingency, @@ -293,10 +268,82 @@ private static void logPstRegulationResultsForContingencyScenario(Contingency co ); String allShiftedPstsDetails = shiftDetails.isEmpty() ? "no PST shifted" : String.join(", ", shiftDetails); if (!shiftDetails.isEmpty()) { - BUSINESS_LOGS.info( - "FlowCNEC '{}' of contingency scenario '{}' is overloaded and is the most limiting element, PST regulation has been triggered: {}", - mostLimitingElement.getId(), contingency.getName().orElse(contingency.getId()), allShiftedPstsDetails - ); + BUSINESS_LOGS.info("FlowCNEC '{}' of contingency scenario '{}' is overloaded and is the most limiting element, PST regulation has been triggered: {}", mostLimitingElement.getId(), contingency.getName().orElse(contingency.getId()), allShiftedPstsDetails); + } + } + + private static RaoResult mergePstRegulationResultsWithRaoResult(Set pstRegulationResults, RaoResult raoResult, Network network, Crac crac, RaoParameters raoParameters) { + Map resultsPerState = pstRegulationResults.stream().collect(Collectors.toMap( + pstRegulationResult -> crac.getState(pstRegulationResult.contingency(), crac.getLastInstant()), + Function.identity() + )); + + ToolProvider toolProvider = ToolProvider.buildFromRaoInputAndParameters(RaoInput.build(network, crac).build(), raoParameters); + PrePerimeterSensitivityAnalysis prePerimeterSensitivityAnalysis = new PrePerimeterSensitivityAnalysis(crac, crac.getFlowCnecs(), crac.getRangeActions(), raoParameters, toolProvider, true); + PrePerimeterResult initialFlowResult = prePerimeterSensitivityAnalysis.runInitialSensitivityAnalysis(network); + + // create a new network variant from initial variant for performing the results merging + String variantName = "PSTRegulationResultsMerging"; + network.getVariantManager().setWorkingVariant(INITIAL_SCENARIO); + network.getVariantManager().cloneVariant(INITIAL_SCENARIO, variantName); + network.getVariantManager().setWorkingVariant(variantName); + + // apply PRAs + State preventiveState = crac.getPreventiveState(); + applyOptimalRemedialActionsForState(network, raoResult, preventiveState); + PrePerimeterResult postPraResult = prePerimeterSensitivityAnalysis.runBasedOnInitialResults(network, initialFlowResult, Set.of(), new AppliedRemedialActions()); + + OptimizationResult preventiveResult = new OptimizationResultImpl( + postPraResult, postPraResult, postPraResult, + new NetworkActionsResultImpl(Map.of(preventiveState, raoResult.getActivatedNetworkActionsDuringState(preventiveState))), + new RangeActionActivationResultImpl(new RangeActionSetpointResultImpl(raoResult.getOptimizedSetPointsOnState(preventiveState))) + ); + PostPerimeterResult postPreventivePerimeterResult = new PostPerimeterSensitivityAnalysis(crac, crac.getFlowCnecs(), crac.getRangeActions(), raoParameters, toolProvider, true).runBasedOnInitialPreviousAndOptimizationResults(network, initialFlowResult, postPraResult, Set.of(), preventiveResult, new AppliedRemedialActions()); + + Map postRegulationPostContingencyResults = new HashMap<>(); + + List postOutageInstants = crac.getSortedInstants().stream().filter(instant -> instant.isAuto() || instant.isCurative()).toList(); + + for (Contingency contingency : crac.getContingencies()) { + AppliedRemedialActions appliedRemedialActions = new AppliedRemedialActions(); + + network.getVariantManager().cloneVariant(variantName, contingency.getId()); + network.getVariantManager().setWorkingVariant(contingency.getId()); + + PrePerimeterResult prePerimeterResult = postPreventivePerimeterResult.prePerimeterResultForAllFollowingStates(); + + for (Instant instant : postOutageInstants) { + State state = crac.getState(contingency, instant); + if (state != null) { + appliedRemedialActions.addAppliedNetworkActions(state, raoResult.getActivatedNetworkActionsDuringState(state)); + appliedRemedialActions.addAppliedRangeActions(state, raoResult.getOptimizedSetPointsOnState(state)); + + if (resultsPerState.containsKey(state)) { + PstRegulationResult pstRegulationResult = resultsPerState.get(state); + pstRegulationResult.regulatedTapPerPst().forEach((pstRangeAction, regulatedTap) -> appliedRemedialActions.addAppliedRangeAction(state, pstRangeAction, pstRangeAction.convertTapToAngle(regulatedTap))); + } + + appliedRemedialActions.getAppliedNetworkActions(state).forEach(networkAction -> networkAction.apply(network)); + appliedRemedialActions.getAppliedRangeActions(state).forEach((rangeAction, setPoint) -> rangeAction.apply(network, setPoint)); + + PrePerimeterResult postInstantPerimeterResult = prePerimeterSensitivityAnalysis.runBasedOnInitialResults(network, initialFlowResult, Collections.emptySet(), new AppliedRemedialActions()); + + OptimizationResult newOptimizationResult = new OptimizationResultImpl( + postInstantPerimeterResult, + postInstantPerimeterResult, + postInstantPerimeterResult, + new NetworkActionsResultImpl(Map.of(state, raoResult.getActivatedNetworkActionsDuringState(state))), + new RangeActionActivationResultImpl(postInstantPerimeterResult) + ); + PostPerimeterResult postPerimeterStateResult = new PostPerimeterSensitivityAnalysis(crac, crac.getFlowCnecs(), crac.getRangeActions(), raoParameters, toolProvider, true).runBasedOnInitialPreviousAndOptimizationResults(network, initialFlowResult, prePerimeterResult, Set.of(), newOptimizationResult, new AppliedRemedialActions()); + postRegulationPostContingencyResults.put(state, postPerimeterStateResult); + + prePerimeterResult = postInstantPerimeterResult; + } + } } + + StateTree stateTree = new StateTree(crac); + return new PreventiveAndCurativesRaoResultImpl(stateTree, initialFlowResult, postPreventivePerimeterResult, postRegulationPostContingencyResults, crac, raoParameters); } } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/PstRegulationInput.java b/pst-regulation/src/main/java/com/powsybl/openrao/pstregulation/PstRegulationInput.java similarity index 81% rename from ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/PstRegulationInput.java rename to pst-regulation/src/main/java/com/powsybl/openrao/pstregulation/PstRegulationInput.java index 1d41bb1818..9fff256ca5 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/PstRegulationInput.java +++ b/pst-regulation/src/main/java/com/powsybl/openrao/pstregulation/PstRegulationInput.java @@ -1,11 +1,11 @@ /* - * Copyright (c) 2025, RTE (http://www.rte-france.com) + * Copyright (c) 2026, RTE (http://www.rte-france.com) * 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/. */ -package com.powsybl.openrao.searchtreerao.castor.algorithm.pstregulation; +package com.powsybl.openrao.pstregulation; import com.powsybl.openrao.data.crac.api.State; import com.powsybl.openrao.data.crac.api.cnec.FlowCnec; diff --git a/pst-regulation/src/main/java/com/powsybl/openrao/pstregulation/PstRegulationOutput.java b/pst-regulation/src/main/java/com/powsybl/openrao/pstregulation/PstRegulationOutput.java new file mode 100644 index 0000000000..3a5d9e66c4 --- /dev/null +++ b/pst-regulation/src/main/java/com/powsybl/openrao/pstregulation/PstRegulationOutput.java @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2026, RTE (http://www.rte-france.com) + * 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/. + */ + +package com.powsybl.openrao.pstregulation; + +/** + * @author Thomas Bouquet {@literal } + */ +public class PstRegulationOutput { +} diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/PstRegulationResult.java b/pst-regulation/src/main/java/com/powsybl/openrao/pstregulation/PstRegulationResult.java similarity index 80% rename from ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/PstRegulationResult.java rename to pst-regulation/src/main/java/com/powsybl/openrao/pstregulation/PstRegulationResult.java index 282c7df212..d7b92177d8 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/PstRegulationResult.java +++ b/pst-regulation/src/main/java/com/powsybl/openrao/pstregulation/PstRegulationResult.java @@ -1,11 +1,11 @@ /* - * Copyright (c) 2025, RTE (http://www.rte-france.com) + * Copyright (c) 2026, RTE (http://www.rte-france.com) * 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/. */ -package com.powsybl.openrao.searchtreerao.castor.algorithm.pstregulation; +package com.powsybl.openrao.pstregulation; import com.powsybl.contingency.Contingency; import com.powsybl.openrao.data.crac.api.rangeaction.PstRangeAction; diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/PstRegulator.java b/pst-regulation/src/main/java/com/powsybl/openrao/pstregulation/PstRegulator.java similarity index 84% rename from ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/PstRegulator.java rename to pst-regulation/src/main/java/com/powsybl/openrao/pstregulation/PstRegulator.java index 355910a484..ab0e0d9eeb 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/PstRegulator.java +++ b/pst-regulation/src/main/java/com/powsybl/openrao/pstregulation/PstRegulator.java @@ -1,11 +1,11 @@ /* - * Copyright (c) 2025, RTE (http://www.rte-france.com) + * Copyright (c) 2026, RTE (http://www.rte-france.com) * 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/. */ -package com.powsybl.openrao.searchtreerao.castor.algorithm.pstregulation; +package com.powsybl.openrao.pstregulation; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.PhaseTapChanger; @@ -30,11 +30,7 @@ private PstRegulator() { public static Map regulatePsts(Set elementaryPstRegulationInputs, Network network, LoadFlowParameters loadFlowParameters) { elementaryPstRegulationInputs.forEach(elementaryPstRegulationInput -> setRegulationForPst(network, elementaryPstRegulationInput)); LoadFlow.find("OpenLoadFlow").run(network, loadFlowParameters); - return elementaryPstRegulationInputs.stream() - .collect(Collectors.toMap( - ElementaryPstRegulationInput::pstRangeAction, - pstRegulationInput -> getRegulatedTap(network, pstRegulationInput.pstRangeAction()) - )); + return elementaryPstRegulationInputs.stream().collect(Collectors.toMap(ElementaryPstRegulationInput::pstRangeAction, pstRegulationInput -> getRegulatedTap(network, pstRegulationInput.pstRangeAction()))); } private static void setRegulationForPst(Network network, ElementaryPstRegulationInput elementaryPstRegulationInput) { @@ -59,10 +55,7 @@ private static TwoWindingsTransformer getTwoWindingsTransformer(Network network, private static void setRegulationTerminal(TwoWindingsTransformer twt, ElementaryPstRegulationInput elementaryPstRegulationInput) { PhaseTapChanger phaseTapChanger = twt.getPhaseTapChanger(); if (phaseTapChanger.getRegulationTerminal() == null) { - OpenRaoLoggerProvider.TECHNICAL_LOGS.info( - "No default regulation terminal defined for phase tap changer of two-windings transformer %s, terminal on side %s will be used." - .formatted(twt.getId(), elementaryPstRegulationInput.limitingSide()) - ); + OpenRaoLoggerProvider.TECHNICAL_LOGS.info("No default regulation terminal defined for phase tap changer of two-windings transformer %s, terminal on side %s will be used.".formatted(twt.getId(), elementaryPstRegulationInput.limitingSide())); phaseTapChanger.setRegulationTerminal(twt.getTerminal(elementaryPstRegulationInput.limitingSide())); } } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/ElementaryPstRegulationInputTest.java b/pst-regulation/src/test/java/com/powsybl/openrao/pstregulation/ElementaryPstRegulationInputTest.java similarity index 98% rename from ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/ElementaryPstRegulationInputTest.java rename to pst-regulation/src/test/java/com/powsybl/openrao/pstregulation/ElementaryPstRegulationInputTest.java index 15b6bc3bd0..d219e758cc 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/ElementaryPstRegulationInputTest.java +++ b/pst-regulation/src/test/java/com/powsybl/openrao/pstregulation/ElementaryPstRegulationInputTest.java @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package com.powsybl.openrao.searchtreerao.castor.algorithm.pstregulation; +package com.powsybl.openrao.pstregulation; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.TwoSides; diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/CastorPstRegulationTest.java b/pst-regulation/src/test/java/com/powsybl/openrao/pstregulation/PstRegulationTest.java similarity index 61% rename from ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/CastorPstRegulationTest.java rename to pst-regulation/src/test/java/com/powsybl/openrao/pstregulation/PstRegulationTest.java index 7bd5fe44e1..72b9141863 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/CastorPstRegulationTest.java +++ b/pst-regulation/src/test/java/com/powsybl/openrao/pstregulation/PstRegulationTest.java @@ -5,31 +5,23 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package com.powsybl.openrao.searchtreerao.castor.algorithm.pstregulation; +package com.powsybl.openrao.pstregulation; import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.read.ListAppender; import com.powsybl.iidm.network.Network; -import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.commons.logs.RaoBusinessLogs; import com.powsybl.openrao.data.crac.api.Crac; -import com.powsybl.openrao.data.crac.api.Instant; -import com.powsybl.openrao.data.crac.api.State; import com.powsybl.openrao.data.crac.api.rangeaction.PstRangeAction; import com.powsybl.openrao.data.raoresult.api.RaoResult; import com.powsybl.openrao.raoapi.json.JsonRaoParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; -import com.powsybl.openrao.searchtreerao.result.api.OptimizationResult; -import com.powsybl.openrao.searchtreerao.result.impl.PostPerimeterResult; import org.junit.jupiter.api.Test; -import org.mockito.Mockito; import org.slf4j.LoggerFactory; import java.io.IOException; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Set; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -37,43 +29,24 @@ /** * @author Thomas Bouquet {@literal } */ -class CastorPstRegulationTest { +class PstRegulationTest { @Test void testPstRegulationWithSeveralContingencyScenarios() throws IOException { Network network = Network.read("4NodesSeries.uct", getClass().getResourceAsStream("/network/4NodesSeries.uct")); + network.getVariantManager().cloneVariant(network.getVariantManager().getWorkingVariantId(), "InitialScenario"); + network.getVariantManager().setWorkingVariant("InitialScenario"); + Crac crac = Crac.read("crac-for-regulation.json", getClass().getResourceAsStream("/crac/crac-for-regulation.json"), network); RaoResult raoResult = RaoResult.read(getClass().getResourceAsStream("/raoResult/raoResultPreRegulation.json"), crac); RaoParameters raoParameters = JsonRaoParameters.read(getClass().getResourceAsStream("/parameters/RaoParameters_ac_3pstsRegulation.json")); - Instant curativeInstant = crac.getLastInstant(); PstRangeAction pst12 = crac.getPstRangeAction("pstFr12"); PstRangeAction pst34 = crac.getPstRangeAction("pstFr34"); - // mock optimization result to give the same values as RAO result - Map postContingencyResults = new HashMap<>(); - crac.getStates(curativeInstant).forEach( - curativeState -> { - OptimizationResult optimizationResult = Mockito.mock(OptimizationResult.class); - crac.getFlowCnecs(curativeState).forEach( - flowCnec -> Mockito.when(optimizationResult.getMargin(flowCnec, Unit.AMPERE)).thenReturn(raoResult.getMargin(curativeInstant, flowCnec, Unit.AMPERE)) - ); - - PostPerimeterResult postPerimeterResult = Mockito.mock(PostPerimeterResult.class); - Mockito.when(postPerimeterResult.optimizationResult()).thenReturn(optimizationResult); - - postContingencyResults.put(curativeState, postPerimeterResult); - } - ); - ListAppender listAppender = getBusinessLogs(); List logsList = listAppender.list; - Map pstsToRegulate = Map.of( - "FFR1AA1 FFR2AA1 2", "FFR1AA1 FFR2AA1 2", - "FFR2AA1 FFR3AA1 2", "FFR2AA1 FFR3AA1 2", - "FFR3AA1 FFR4AA1 2", "FFR3AA1 FFR4AA1 2" - ); - Set pstRegulationResults = CastorPstRegulation.regulatePsts(pstsToRegulate, postContingencyResults, network, crac, raoParameters, raoResult); + RaoResult raoResultWithPstRegulation = PstRegulation.regulatePsts(network, crac, raoResult, raoParameters); List logMessages = logsList.stream().map(ILoggingEvent::getFormattedMessage).sorted().toList(); assertEquals("2 PST(s) to regulate: pstFr12, pstFr34", logMessages.get(0)); @@ -82,11 +55,9 @@ void testPstRegulationWithSeveralContingencyScenarios() throws IOException { // PST FR2-FR3 is only preventive so it cannot be regulated assertEquals("PST FFR2AA1 FFR3AA1 2 cannot be regulated as no curative PST range action was defined for it.", logMessages.get(5)); - assertEquals(3, pstRegulationResults.size()); - // Contingency FR1-FR2 - PstRegulationResult pstRegulationResultCoFr12 = getPstRegulationResultForGivenContingency(pstRegulationResults, "Contingency FR 12"); - assertEquals(Map.of(pst12, -15, pst34, -5), pstRegulationResultCoFr12.regulatedTapPerPst()); + assertEquals(-15, raoResultWithPstRegulation.getOptimizedTapOnState(crac.getState("Contingency FR 12", crac.getLastInstant()), pst12)); + assertEquals(-5, raoResultWithPstRegulation.getOptimizedTapOnState(crac.getState("Contingency FR 12", crac.getLastInstant()), pst34)); assertEquals( "FlowCNEC 'cnecFr34PstCurative - Co12' of contingency scenario 'Contingency FR 12' is overloaded and is the most limiting element, " + "PST regulation has been triggered: pstFr12 (-10 -> -15), pstFr34 (0 -> -5)", @@ -94,8 +65,8 @@ void testPstRegulationWithSeveralContingencyScenarios() throws IOException { ); // Contingency FR2-FR3 - PstRegulationResult pstRegulationResultCoFr23 = getPstRegulationResultForGivenContingency(pstRegulationResults, "Contingency FR 23"); - assertEquals(Map.of(pst12, -5, pst34, -5), pstRegulationResultCoFr23.regulatedTapPerPst()); + assertEquals(-5, raoResultWithPstRegulation.getOptimizedTapOnState(crac.getState("Contingency FR 23", crac.getLastInstant()), pst12)); + assertEquals(-5, raoResultWithPstRegulation.getOptimizedTapOnState(crac.getState("Contingency FR 23", crac.getLastInstant()), pst34)); assertEquals( "FlowCNEC 'cnecFr23PstCurative - Co23' of contingency scenario 'Contingency FR 23' is overloaded and is the most limiting element, " + "PST regulation has been triggered: pstFr12 (0 -> -5), pstFr34 (0 -> -5)", @@ -103,8 +74,8 @@ void testPstRegulationWithSeveralContingencyScenarios() throws IOException { ); // Contingency FR3-FR4 - PstRegulationResult pstRegulationResultCoFr34 = getPstRegulationResultForGivenContingency(pstRegulationResults, "Contingency FR 34"); - assertEquals(Map.of(pst12, -5, pst34, -15), pstRegulationResultCoFr34.regulatedTapPerPst()); + assertEquals(-5, raoResultWithPstRegulation.getOptimizedTapOnState(crac.getState("Contingency FR 34", crac.getLastInstant()), pst12)); + assertEquals(-15, raoResultWithPstRegulation.getOptimizedTapOnState(crac.getState("Contingency FR 34", crac.getLastInstant()), pst34)); assertEquals( "FlowCNEC 'cnecFr12PstCurative - Co34' of contingency scenario 'Contingency FR 34' is overloaded and is the most limiting element, " + "PST regulation has been triggered: pstFr12 (0 -> -5)", diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/PstRegulatorTest.java b/pst-regulation/src/test/java/com/powsybl/openrao/pstregulation/PstRegulatorTest.java similarity index 97% rename from ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/PstRegulatorTest.java rename to pst-regulation/src/test/java/com/powsybl/openrao/pstregulation/PstRegulatorTest.java index 12451c7685..0b6e46499f 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/pstregulation/PstRegulatorTest.java +++ b/pst-regulation/src/test/java/com/powsybl/openrao/pstregulation/PstRegulatorTest.java @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package com.powsybl.openrao.searchtreerao.castor.algorithm.pstregulation; +package com.powsybl.openrao.pstregulation; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.TwoSides; diff --git a/ra-optimisation/search-tree-rao/src/test/resources/crac/crac-3-psts-monitored-line-in-series.json b/pst-regulation/src/test/resources/crac/crac-3-psts-monitored-line-in-series.json similarity index 100% rename from ra-optimisation/search-tree-rao/src/test/resources/crac/crac-3-psts-monitored-line-in-series.json rename to pst-regulation/src/test/resources/crac/crac-3-psts-monitored-line-in-series.json diff --git a/ra-optimisation/search-tree-rao/src/test/resources/crac/crac-3-psts.json b/pst-regulation/src/test/resources/crac/crac-3-psts.json similarity index 100% rename from ra-optimisation/search-tree-rao/src/test/resources/crac/crac-3-psts.json rename to pst-regulation/src/test/resources/crac/crac-3-psts.json diff --git a/ra-optimisation/search-tree-rao/src/test/resources/crac/crac-for-regulation.json b/pst-regulation/src/test/resources/crac/crac-for-regulation.json similarity index 100% rename from ra-optimisation/search-tree-rao/src/test/resources/crac/crac-for-regulation.json rename to pst-regulation/src/test/resources/crac/crac-for-regulation.json diff --git a/ra-optimisation/search-tree-rao/src/test/resources/crac/crac-regulation-1-PST.json b/pst-regulation/src/test/resources/crac/crac-regulation-1-PST.json similarity index 100% rename from ra-optimisation/search-tree-rao/src/test/resources/crac/crac-regulation-1-PST.json rename to pst-regulation/src/test/resources/crac/crac-regulation-1-PST.json diff --git a/pst-regulation/src/test/resources/network/2Nodes2ParallelLinesPST.uct b/pst-regulation/src/test/resources/network/2Nodes2ParallelLinesPST.uct new file mode 100644 index 0000000000..49add21201 --- /dev/null +++ b/pst-regulation/src/test/resources/network/2Nodes2ParallelLinesPST.uct @@ -0,0 +1,12 @@ +##C 2007.05.01 +##N +##ZBE +BBE1AA1 BE1 0 2 400.00 0.00000 0.00000 -1000.0 0.00000 9000.00 -9000.0 9000.00 -9000.0 +##ZFR +FFR1AA1 FR1 0 2 400.00 1000.00 0.00000 00000.0 0.00000 9000.00 -9000.0 9000.00 -9000.0 +##L +BBE1AA1 FFR1AA1 1 0 0.0000 10.000 0.000000 5000 +##T +BBE1AA1 FFR1AA1 2 0 400.0 400.0 1000. 0.0000 10.000 0.000000 0.0 500 PST +##R +BBE1AA1 FFR1AA1 2 -0.68 90.00 16 0 SYMM diff --git a/ra-optimisation/search-tree-rao/src/test/resources/network/2Nodes4ParallelLines3PSTs.uct b/pst-regulation/src/test/resources/network/2Nodes4ParallelLines3PSTs.uct similarity index 100% rename from ra-optimisation/search-tree-rao/src/test/resources/network/2Nodes4ParallelLines3PSTs.uct rename to pst-regulation/src/test/resources/network/2Nodes4ParallelLines3PSTs.uct diff --git a/ra-optimisation/search-tree-rao/src/test/resources/network/4NodesSeries.uct b/pst-regulation/src/test/resources/network/4NodesSeries.uct similarity index 100% rename from ra-optimisation/search-tree-rao/src/test/resources/network/4NodesSeries.uct rename to pst-regulation/src/test/resources/network/4NodesSeries.uct diff --git a/ra-optimisation/search-tree-rao/src/test/resources/parameters/RaoParameters_ac_3pstsRegulation.json b/pst-regulation/src/test/resources/parameters/RaoParameters_ac_3pstsRegulation.json similarity index 100% rename from ra-optimisation/search-tree-rao/src/test/resources/parameters/RaoParameters_ac_3pstsRegulation.json rename to pst-regulation/src/test/resources/parameters/RaoParameters_ac_3pstsRegulation.json diff --git a/ra-optimisation/search-tree-rao/src/test/resources/raoResult/raoResultPreRegulation.json b/pst-regulation/src/test/resources/raoResult/raoResultPreRegulation.json similarity index 100% rename from ra-optimisation/search-tree-rao/src/test/resources/raoResult/raoResultPreRegulation.json rename to pst-regulation/src/test/resources/raoResult/raoResultPreRegulation.json diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimization.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimization.java index e4a08b9a72..56aeefa6fe 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimization.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimization.java @@ -8,12 +8,10 @@ package com.powsybl.openrao.searchtreerao.castor.algorithm; import com.powsybl.iidm.network.Network; -import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.data.crac.api.Crac; import com.powsybl.openrao.data.crac.api.Instant; import com.powsybl.openrao.data.crac.api.State; import com.powsybl.openrao.data.crac.api.cnec.FlowCnec; -import com.powsybl.openrao.data.crac.api.networkaction.NetworkAction; import com.powsybl.openrao.data.crac.api.rangeaction.RangeAction; import com.powsybl.openrao.data.raoresult.api.ComputationStatus; import com.powsybl.openrao.data.raoresult.api.OptimizationStepsExecuted; @@ -23,9 +21,6 @@ import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.powsybl.openrao.raoapi.parameters.extensions.LoadFlowAndSensitivityParameters; import com.powsybl.openrao.raoapi.parameters.extensions.OpenRaoSearchTreeParameters; -import com.powsybl.openrao.raoapi.parameters.extensions.SearchTreeRaoPstRegulationParameters; -import com.powsybl.openrao.searchtreerao.castor.algorithm.pstregulation.CastorPstRegulation; -import com.powsybl.openrao.searchtreerao.castor.algorithm.pstregulation.PstRegulationResult; import com.powsybl.openrao.searchtreerao.commons.RaoLogger; import com.powsybl.openrao.searchtreerao.commons.RaoUtil; import com.powsybl.openrao.searchtreerao.commons.ToolProvider; @@ -33,16 +28,12 @@ import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.PreventiveOptimizationPerimeter; import com.powsybl.openrao.searchtreerao.commons.parameters.TreeParameters; import com.powsybl.openrao.searchtreerao.commons.parameters.UnoptimizedCnecParameters; -import com.powsybl.openrao.searchtreerao.result.api.FlowResult; import com.powsybl.openrao.searchtreerao.result.api.OptimizationResult; import com.powsybl.openrao.searchtreerao.result.api.PrePerimeterResult; import com.powsybl.openrao.searchtreerao.result.impl.FailedRaoResultImpl; -import com.powsybl.openrao.searchtreerao.result.impl.NetworkActionsResultImpl; import com.powsybl.openrao.searchtreerao.result.impl.OneStateOnlyRaoResultImpl; -import com.powsybl.openrao.searchtreerao.result.impl.OptimizationResultImpl; import com.powsybl.openrao.searchtreerao.result.impl.PostPerimeterResult; import com.powsybl.openrao.searchtreerao.result.impl.PreventiveAndCurativesRaoResultImpl; -import com.powsybl.openrao.searchtreerao.result.impl.RangeActionActivationResultImpl; import com.powsybl.openrao.searchtreerao.result.impl.RemedialActionActivationResultImpl; import com.powsybl.openrao.searchtreerao.result.impl.UnoptimizedRaoResultImpl; import com.powsybl.openrao.searchtreerao.searchtree.algorithms.SearchTree; @@ -59,7 +50,6 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.CompletableFuture; -import java.util.stream.Collectors; import static com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider.BUSINESS_LOGS; import static com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider.TECHNICAL_LOGS; @@ -284,54 +274,8 @@ public CompletableFuture run() { ); } - CompletableFuture raoResult = postCheckResults(mergedRaoResults, initialOutput, raoParameters.getObjectiveFunctionParameters(), true); - - // PST regulation - Map pstsToRegulate = SearchTreeRaoPstRegulationParameters.getPstsToRegulate(raoParameters); - if (!pstsToRegulate.isEmpty()) { - BUSINESS_LOGS.info("----- PST regulation [start]"); - network.getVariantManager().cloneVariant(INITIAL_SCENARIO, PST_REGULATION); - network.getVariantManager().setWorkingVariant(PST_REGULATION); - Set pstRegulationResults = CastorPstRegulation.regulatePsts( - pstsToRegulate, finalPostContingencyResults, network, crac, raoParameters, mergedRaoResults); - Map postRegulationResults = mergeRaoAndPstRegulationResults( - pstRegulationResults, finalSecondPreventiveResult, finalPostContingencyResults, prePerimeterSensitivityAnalysis, initialOutput, toolProvider); - RaoResult raoResultWithRegulation = new PreventiveAndCurativesRaoResultImpl( - stateTree, - initialOutput, - postPreventiveResult, - finalSecondPreventiveResult, - postRegulationResults, - crac, - raoParameters); - raoResultWithRegulation.setExecutionDetails(mergedRaoResults.getExecutionDetails()); - BUSINESS_LOGS.info("----- PST regulation [end]"); - BUSINESS_LOGS.info("Merging RAO and PST regulation results:"); - RaoLogger.logMostLimitingElementsResults( - BUSINESS_LOGS, - stateTree.getBasecaseScenario(), - finalSecondPreventiveResult.optimizationResult(), - stateTree.getContingencyScenarios(), - postRegulationResults, - raoParameters.getObjectiveFunctionParameters().getType(), - getFlowUnit(raoParameters), - NUMBER_LOGGED_ELEMENTS_END_RAO - ); - RaoLogger.checkIfMostLimitingElementIsFictional( - BUSINESS_LOGS, - stateTree.getBasecaseScenario(), - finalSecondPreventiveResult.optimizationResult(), - stateTree.getContingencyScenarios(), - postRegulationResults, - raoParameters.getObjectiveFunctionParameters().getType(), - getFlowUnit(raoParameters) - ); - return postCheckResults(raoResultWithRegulation, initialOutput, raoParameters.getObjectiveFunctionParameters(), false); - } - - return raoResult; - } catch (OpenRaoException e) { - //TODO: Check possible exceptions here + return postCheckResults(mergedRaoResults, initialOutput, raoParameters.getObjectiveFunctionParameters(), true); + } catch (RuntimeException e) { BUSINESS_LOGS.error("{} \n {}", e.getMessage(), ExceptionUtils.getStackTrace(e)); return CompletableFuture.completedFuture(new FailedRaoResultImpl(String.format("RAO failed during %s : %s", currentStep, e.getMessage()))); } @@ -470,81 +414,6 @@ private Pair> optimizePreventivePerimeter(Stat return Pair.of(optResult, optPerimeter.getFlowCnecs()); } - private Map mergeRaoAndPstRegulationResults(Set pstRegulationResults, - PostPerimeterResult postPraResult, - Map postContingencyResults, - PrePerimeterSensitivityAnalysis prePerimeterSensitivityAnalysis, - FlowResult initialFlowResult, - ToolProvider toolProvider) { - // create a new network variant from initial variant for performing the results merging - String variantName = "PSTRegulationResultsMerging"; - network.getVariantManager().setWorkingVariant(INITIAL_SCENARIO); - network.getVariantManager().cloneVariant(INITIAL_SCENARIO, variantName); - network.getVariantManager().setWorkingVariant(variantName); - - // apply PRAs - applyRemedialActions(network, postPraResult.optimizationResult(), crac.getPreventiveState()); - - Set regulatedStates = pstRegulationResults.stream() - .map(pstRegulationResult -> crac.getState(pstRegulationResult.contingency().getId(), crac.getLastInstant())) - .collect(Collectors.toSet()); - Map> appliedNetworkActions = new HashMap<>(); - - // gather all applied ARAs and CRAs - AppliedRemedialActions appliedRemedialActions = new AppliedRemedialActions(); - postContingencyResults.forEach((state, postPerimeterResult) -> { - appliedNetworkActions.put(state, postPerimeterResult.optimizationResult().getActivatedNetworkActions()); - appliedRemedialActions.addAppliedNetworkActions(state, postPerimeterResult.optimizationResult().getActivatedNetworkActions()); - appliedRemedialActions.addAppliedRangeActions(state, getAppliedRangeActionsAndSetPoint(state, postPraResult.optimizationResult())); - appliedRemedialActions.addAppliedRangeActions(state, getAppliedRangeActionsAndSetPoint(state, postPerimeterResult.optimizationResult())); - }); - - // overwrite PST range action results for regulated PSTs - pstRegulationResults.forEach(pstRegulationResult -> - pstRegulationResult.regulatedTapPerPst().forEach((pstRangeAction, regulatedTap) -> - appliedRemedialActions.addAppliedRangeAction( - crac.getState(pstRegulationResult.contingency().getId(), crac.getLastInstant()), - pstRangeAction, - pstRangeAction.convertTapToAngle(regulatedTap) - ) - ) - ); - - PrePerimeterResult postCraSensitivityAnalysisOutput = prePerimeterSensitivityAnalysis.runBasedOnInitialResults(network, initialFlowResult, Collections.emptySet(), appliedRemedialActions); - - Map postRegulationPostContingencyResults = new HashMap<>(); - - // override optimization result - RangeActionActivationResultImpl postRegulationRangeActionActivationResult = new RangeActionActivationResultImpl(postCraSensitivityAnalysisOutput); - postContingencyResults.keySet().forEach(state -> - appliedRemedialActions.getAppliedRangeActions(state).forEach((rangeAction, setPoint) -> - postRegulationRangeActionActivationResult.putResult(rangeAction, state, setPoint) - ) - ); - OptimizationResult newOptimizationResult = new OptimizationResultImpl( - postCraSensitivityAnalysisOutput, - postCraSensitivityAnalysisOutput, - postCraSensitivityAnalysisOutput, - new NetworkActionsResultImpl(appliedNetworkActions), - postRegulationRangeActionActivationResult - ); - - for (State state : postContingencyResults.keySet()) { - // For instants before pst regulation instant, keep previous results - if (state.getInstant().comesBefore(crac.getLastInstant())) { - postRegulationPostContingencyResults.put(state, postContingencyResults.get(state)); - } else { - // For curative instant, update regulatedStates with newly computed sensi result - postRegulationPostContingencyResults.put(state, new PostPerimeterResult( - regulatedStates.contains(state) ? newOptimizationResult : postContingencyResults.get(state).optimizationResult(), - postCraSensitivityAnalysisOutput - )); - } - } - - return postRegulationPostContingencyResults; - } - private static Map, Double> getAppliedRangeActionsAndSetPoint(State state, OptimizationResult optimizationResult) { Map, Double> optimizedRangeActions = new HashMap<>(); optimizationResult.getActivatedRangeActions(state).forEach(rangeAction -> optimizedRangeActions.put(rangeAction, optimizationResult.getOptimizedSetpoint(rangeAction, state))); diff --git a/tests/pom.xml b/tests/pom.xml index ac41696b6b..cb01b61baa 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -324,6 +324,12 @@ commons-io runtime + + com.powsybl + open-rao-pst-regulation + 7.2.0-SNAPSHOT + test + \ No newline at end of file diff --git a/tests/src/test/java/com/powsybl/openrao/tests/steps/PstRegulationSteps.java b/tests/src/test/java/com/powsybl/openrao/tests/steps/PstRegulationSteps.java new file mode 100644 index 0000000000..db0e447604 --- /dev/null +++ b/tests/src/test/java/com/powsybl/openrao/tests/steps/PstRegulationSteps.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2026, RTE (http://www.rte-france.com) + * 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/. + */ + +package com.powsybl.openrao.tests.steps; + +import com.powsybl.openrao.pstregulation.PstRegulation; +import io.cucumber.java.en.When; + +/** + * @author Thomas Bouquet {@literal } + */ +public class PstRegulationSteps { + @When("I launch PST regulation") + public void launchPSTRegulation() { + CommonTestData.setRaoResult(PstRegulation.regulatePsts(CommonTestData.getNetwork(), CommonTestData.getCrac(), CommonTestData.getRaoResult(), CommonTestData.getRaoParameters())); + } +} diff --git a/tests/src/test/java/com/powsybl/openrao/tests/steps/RaoSteps.java b/tests/src/test/java/com/powsybl/openrao/tests/steps/RaoSteps.java index 3e3fe8468f..ed704bb849 100644 --- a/tests/src/test/java/com/powsybl/openrao/tests/steps/RaoSteps.java +++ b/tests/src/test/java/com/powsybl/openrao/tests/steps/RaoSteps.java @@ -163,69 +163,69 @@ public void iLaunchLoopflowComputation(String timestamp) { @Then("the calculation succeeds") public void theCalculationSucceeds() { - assertEquals(ComputationStatus.DEFAULT, raoResult.getComputationStatus()); + assertEquals(ComputationStatus.DEFAULT, CommonTestData.getRaoResult().getComputationStatus()); } @Then("the calculation partially fails") public void theCalculationPartiallyFails() { - assertEquals(ComputationStatus.PARTIAL_FAILURE, raoResult.getComputationStatus()); + assertEquals(ComputationStatus.PARTIAL_FAILURE, CommonTestData.getRaoResult().getComputationStatus()); } @Then("the calculation fails") public void theCalculationFails() { - assertEquals(ComputationStatus.FAILURE, raoResult.getComputationStatus()); + assertEquals(ComputationStatus.FAILURE, CommonTestData.getRaoResult().getComputationStatus()); } @Then("its security status should be {string}") public void statusShouldBe(String status) { - assertEquals("secured".equalsIgnoreCase(status), raoResult.isSecure(PhysicalParameter.FLOW)); + assertEquals("secured".equalsIgnoreCase(status), CommonTestData.getRaoResult().isSecure(PhysicalParameter.FLOW)); } @Then("the value of the objective function initially should be {double}") public void objectiveFunctionValueInitialShouldBe(double expectedValue) { - assertEquals(expectedValue, raoResult.getCost(null), flowAmpereTolerance(expectedValue)); + assertEquals(expectedValue, CommonTestData.getRaoResult().getCost(null), flowAmpereTolerance(expectedValue)); } @Then("the value of the objective function after PRA should be {double}") public void objectiveFunctionValueAfterPraShouldBe(double expectedValue) { - assertEquals(expectedValue, raoResult.getCost(crac.getPreventiveInstant()), flowAmpereTolerance(expectedValue)); + assertEquals(expectedValue, CommonTestData.getRaoResult().getCost(crac.getPreventiveInstant()), flowAmpereTolerance(expectedValue)); } @Then("the value of the objective function after ARA should be {double}") public void objectiveFunctionValueAfterAraShouldBe(double expectedValue) { Instant instant = crac.hasAutoInstant() ? crac.getInstant(InstantKind.AUTO) : crac.getOutageInstant(); - assertEquals(expectedValue, raoResult.getCost(instant), flowAmpereTolerance(expectedValue)); + assertEquals(expectedValue, CommonTestData.getRaoResult().getCost(instant), flowAmpereTolerance(expectedValue)); } @Then("the value of the objective function after CRA should be {double}") public void objectiveFunctionValueAfterCraShouldBe(double expectedValue) { - assertEquals(expectedValue, raoResult.getCost(crac.getLastInstant()), flowAmpereTolerance(expectedValue)); + assertEquals(expectedValue, CommonTestData.getRaoResult().getCost(crac.getLastInstant()), flowAmpereTolerance(expectedValue)); } @Then("the value of the objective function before optimisation should be {double}") public void objectiveFunctionValueBeforeOptShouldBe(double expectedValue) { - assertEquals(expectedValue, raoResult.getCost(null), flowAmpereTolerance(expectedValue)); + assertEquals(expectedValue, CommonTestData.getRaoResult().getCost(null), flowAmpereTolerance(expectedValue)); } @Then("{int} remedial actions are used in preventive") public void countPra(int expectedCount) { - assertEquals(expectedCount, raoResult.getActivatedNetworkActionsDuringState(preventiveState).size() + raoResult.getActivatedRangeActionsDuringState(preventiveState).size()); + assertEquals(expectedCount, CommonTestData.getRaoResult().getActivatedNetworkActionsDuringState(preventiveState).size() + raoResult.getActivatedRangeActionsDuringState(preventiveState).size()); } @Then("{int} network actions are used in preventive") public void countNetworkActionPra(int expectedCount) { - assertEquals(expectedCount, raoResult.getActivatedNetworkActionsDuringState(preventiveState).size()); + assertEquals(expectedCount, CommonTestData.getRaoResult().getActivatedNetworkActionsDuringState(preventiveState).size()); } @Then("{int} ± {int} remedial actions are used in preventive") public void countPra(int expectedCount, int tolerance) { - assertEquals(expectedCount, raoResult.getActivatedNetworkActionsDuringState(preventiveState).size() + raoResult.getActivatedRangeActionsDuringState(preventiveState).size(), tolerance); + assertEquals(expectedCount, CommonTestData.getRaoResult().getActivatedNetworkActionsDuringState(preventiveState).size() + raoResult.getActivatedRangeActionsDuringState(preventiveState).size(), tolerance); } @Then("{int} remedial actions are used after {string} at {string}") public void countCra(int expectedCount, String contingencyId, String instant) { State state = getState(contingencyId, instant); - assertEquals(expectedCount, raoResult.getActivatedRangeActionsDuringState(state).size() + raoResult.getActivatedNetworkActionsDuringState(state).size()); + assertEquals(expectedCount, CommonTestData.getRaoResult().getActivatedRangeActionsDuringState(state).size() + raoResult.getActivatedNetworkActionsDuringState(state).size()); } @Then("the remedial action {string} is used in preventive") @@ -268,51 +268,51 @@ public void remedialActionNotUsedInPreventive(String remedialAction) { @Then("the tap of PstRangeAction {string} should be {int} in preventive") public void theTapOfPstRangeActionShouldBe(String pstRangeActionId, int chosenPstTap) { - assertEquals(chosenPstTap, raoResult.getOptimizedTapOnState(preventiveState, (PstRangeAction) crac.getRangeAction(pstRangeActionId))); + assertEquals(chosenPstTap, CommonTestData.getRaoResult().getOptimizedTapOnState(preventiveState, (PstRangeAction) crac.getRangeAction(pstRangeActionId))); } @Then("the tap of PstRangeAction {string} should be {int} ± {int} in preventive") public void theTapOfPstRangeActionShouldBe(String pstRangeActionId, int chosenPstTap, int tolerance) { - assertEquals(chosenPstTap, raoResult.getOptimizedTapOnState(preventiveState, (PstRangeAction) crac.getRangeAction(pstRangeActionId)), tolerance); + assertEquals(chosenPstTap, CommonTestData.getRaoResult().getOptimizedTapOnState(preventiveState, (PstRangeAction) crac.getRangeAction(pstRangeActionId)), tolerance); } @Then("the tap of PstRangeAction {string} should be {int} after {string} at {string}") public void theTapOfPstRangeActionShouldBe(String pstRangeActionId, int chosenPstTap, String contingencyId, String instant) { PstRangeAction rangeAction = (PstRangeAction) crac.getRangeAction(pstRangeActionId); - assertEquals(chosenPstTap, raoResult.getOptimizedTapOnState(getState(contingencyId, instant), rangeAction)); + assertEquals(chosenPstTap, CommonTestData.getRaoResult().getOptimizedTapOnState(getState(contingencyId, instant), rangeAction)); } @Then("the setpoint of RangeAction {string} should be {double} MW in preventive") public void theSetpointOfRangeActionShouldBe(String rangeActionId, double chosenSetpoint) { - assertEquals(chosenSetpoint, raoResult.getOptimizedSetPointOnState(preventiveState, crac.getRangeAction(rangeActionId)), TOLERANCE_RANGEACTION_SETPOINT); + assertEquals(chosenSetpoint, CommonTestData.getRaoResult().getOptimizedSetPointOnState(preventiveState, crac.getRangeAction(rangeActionId)), TOLERANCE_RANGEACTION_SETPOINT); } @Then("the initial setpoint of RangeAction {string} should be {double}") public void theInitialSetpointOfRangeActionShouldBe(String rangeActionId, double chosenSetpoint) { - assertEquals(chosenSetpoint, raoResult.getPreOptimizationSetPointOnState(preventiveState, crac.getRangeAction(rangeActionId)), TOLERANCE_RANGEACTION_SETPOINT); + assertEquals(chosenSetpoint, CommonTestData.getRaoResult().getPreOptimizationSetPointOnState(preventiveState, crac.getRangeAction(rangeActionId)), TOLERANCE_RANGEACTION_SETPOINT); } @Then("the initial tap of PstRangeAction {string} should be {int}") public void theInitialTapOfPstRangeActionShouldBe(String pstRangeActionId, int chosenTap) { - assertEquals(chosenTap, raoResult.getPreOptimizationTapOnState(preventiveState, crac.getPstRangeAction(pstRangeActionId))); + assertEquals(chosenTap, CommonTestData.getRaoResult().getPreOptimizationTapOnState(preventiveState, crac.getPstRangeAction(pstRangeActionId))); } @Then("the setpoint of RangeAction {string} should be {double} MW after {string} at {string}") public void theSetpointOfRangeActionShouldBe(String rangeActionId, double chosenSetpoint, String contingencyId, String instant) { RangeAction rangeAction = crac.getRangeAction(rangeActionId); - assertEquals(chosenSetpoint, raoResult.getOptimizedSetPointOnState(getState(contingencyId, instant), rangeAction), TOLERANCE_RANGEACTION_SETPOINT); + assertEquals(chosenSetpoint, CommonTestData.getRaoResult().getOptimizedSetPointOnState(getState(contingencyId, instant), rangeAction), TOLERANCE_RANGEACTION_SETPOINT); } @Then("the setpoint of RangeAction {string} should be {double} before {string} at {string}") public void theSetpointOfRangeActionShouldBeBefore(String rangeActionId, double chosenSetpoint, String contingencyId, String instant) { RangeAction rangeAction = crac.getRangeAction(rangeActionId); - assertEquals(chosenSetpoint, raoResult.getPreOptimizationSetPointOnState(getState(contingencyId, instant), rangeAction), TOLERANCE_RANGEACTION_SETPOINT); + assertEquals(chosenSetpoint, CommonTestData.getRaoResult().getPreOptimizationSetPointOnState(getState(contingencyId, instant), rangeAction), TOLERANCE_RANGEACTION_SETPOINT); } @Then("the tap of PstRangeAction {string} should be {int} before {string} at {string}") public void theSetpointOfRangeActionShouldBeBefore(String pstRangeActionId, int chosenTap, String contingencyId, String instant) { PstRangeAction pstRangeAction = crac.getPstRangeAction(pstRangeActionId); - assertEquals(chosenTap, raoResult.getPreOptimizationTapOnState(getState(contingencyId, instant), pstRangeAction)); + assertEquals(chosenTap, CommonTestData.getRaoResult().getPreOptimizationTapOnState(getState(contingencyId, instant), pstRangeAction)); } private State getState(String contingencyId, String instantId) { @@ -361,22 +361,22 @@ private double getTargetPFromVariant(final String generatorId, final String sear @Then("the initial margin on cnec {string} should be {double} A") public void initialMarginInA(String cnecId, Double expectedMargin) { - assertEquals(expectedMargin, raoResult.getMargin(null, crac.getFlowCnec(cnecId), Unit.AMPERE), flowAmpereTolerance(expectedMargin)); + assertEquals(expectedMargin, CommonTestData.getRaoResult().getMargin(null, crac.getFlowCnec(cnecId), Unit.AMPERE), flowAmpereTolerance(expectedMargin)); } @Then("the margin on cnec {string} after PRA should be {double} A") public void afterPraMarginInA(String cnecId, Double expectedMargin) { - assertEquals(expectedMargin, raoResult.getMargin(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), Unit.AMPERE), flowAmpereTolerance(expectedMargin)); + assertEquals(expectedMargin, CommonTestData.getRaoResult().getMargin(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), Unit.AMPERE), flowAmpereTolerance(expectedMargin)); } @Then("the margin on cnec {string} after ARA should be {double} A") public void afterAraMarginInA(String cnecId, Double expectedMargin) { - assertEquals(expectedMargin, raoResult.getMargin(crac.getInstant(InstantKind.AUTO), crac.getFlowCnec(cnecId), Unit.AMPERE), flowAmpereTolerance(expectedMargin)); + assertEquals(expectedMargin, CommonTestData.getRaoResult().getMargin(crac.getInstant(InstantKind.AUTO), crac.getFlowCnec(cnecId), Unit.AMPERE), flowAmpereTolerance(expectedMargin)); } @Then("the margin on cnec {string} after CRA should be {double} A") public void afterCraMarginInA(String cnecId, Double expectedMargin) { - assertEquals(expectedMargin, raoResult.getMargin(crac.getInstant(InstantKind.CURATIVE), crac.getFlowCnec(cnecId), Unit.AMPERE), flowAmpereTolerance(expectedMargin)); + assertEquals(expectedMargin, CommonTestData.getRaoResult().getMargin(crac.getInstant(InstantKind.CURATIVE), crac.getFlowCnec(cnecId), Unit.AMPERE), flowAmpereTolerance(expectedMargin)); } @Then("the worst margin is {double} A") @@ -405,23 +405,23 @@ public void worstMarginAndCnecInA(double expectedMargin, String expectedCnecName @Then("the initial margin on cnec {string} should be {double} MW") public void initialMarginInMW(String cnecId, Double expectedMargin) { - assertEquals(expectedMargin, raoResult.getMargin(null, crac.getFlowCnec(cnecId), Unit.MEGAWATT), flowMegawattTolerance(expectedMargin)); + assertEquals(expectedMargin, CommonTestData.getRaoResult().getMargin(null, crac.getFlowCnec(cnecId), Unit.MEGAWATT), flowMegawattTolerance(expectedMargin)); } @Then("the margin on cnec {string} after PRA should be {double} MW") public void afterPraMarginInMW(String cnecId, Double expectedMargin) { - assertEquals(expectedMargin, raoResult.getMargin(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), Unit.MEGAWATT), flowMegawattTolerance(expectedMargin)); + assertEquals(expectedMargin, CommonTestData.getRaoResult().getMargin(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), Unit.MEGAWATT), flowMegawattTolerance(expectedMargin)); } @Then("the margin on cnec {string} after ARA should be {double} MW") public void afterAraMarginInMW(String cnecId, Double expectedMargin) { Instant instant = crac.hasAutoInstant() ? crac.getInstant(InstantKind.AUTO) : crac.getOutageInstant(); - assertEquals(expectedMargin, raoResult.getMargin(instant, crac.getFlowCnec(cnecId), Unit.MEGAWATT), flowMegawattTolerance(expectedMargin)); + assertEquals(expectedMargin, CommonTestData.getRaoResult().getMargin(instant, crac.getFlowCnec(cnecId), Unit.MEGAWATT), flowMegawattTolerance(expectedMargin)); } @Then("the margin on cnec {string} after CRA should be {double} MW") public void afterCraMarginInMW(String cnecId, Double expectedMargin) { - assertEquals(expectedMargin, raoResult.getMargin(crac.getInstant(InstantKind.CURATIVE), crac.getFlowCnec(cnecId), Unit.MEGAWATT), flowMegawattTolerance(expectedMargin)); + assertEquals(expectedMargin, CommonTestData.getRaoResult().getMargin(crac.getInstant(InstantKind.CURATIVE), crac.getFlowCnec(cnecId), Unit.MEGAWATT), flowMegawattTolerance(expectedMargin)); } @Then("the worst margin is {double} MW") @@ -444,22 +444,22 @@ public void worstMarginAndCnecInMW(double expectedMargin, String expectedCnecNam @Then("the initial relative margin on cnec {string} should be {double} A") public void initialRelativeMarginInA(String cnecId, Double expectedMargin) { - assertEquals(expectedMargin, raoResult.getRelativeMargin(null, crac.getFlowCnec(cnecId), Unit.AMPERE), flowAmpereTolerance(expectedMargin)); + assertEquals(expectedMargin, CommonTestData.getRaoResult().getRelativeMargin(null, crac.getFlowCnec(cnecId), Unit.AMPERE), flowAmpereTolerance(expectedMargin)); } @Then("the relative margin on cnec {string} after PRA should be {double} A") public void afterPraRelativeMarginInA(String cnecId, Double expectedMargin) { - assertEquals(expectedMargin, raoResult.getRelativeMargin(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), Unit.AMPERE), flowAmpereTolerance(expectedMargin)); + assertEquals(expectedMargin, CommonTestData.getRaoResult().getRelativeMargin(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), Unit.AMPERE), flowAmpereTolerance(expectedMargin)); } @Then("the relative margin on cnec {string} after ARA should be {double} A") public void afterAraRelativeMarginInA(String cnecId, Double expectedMargin) { - assertEquals(expectedMargin, raoResult.getRelativeMargin(crac.getInstant(InstantKind.AUTO), crac.getFlowCnec(cnecId), Unit.AMPERE), flowAmpereTolerance(expectedMargin)); + assertEquals(expectedMargin, CommonTestData.getRaoResult().getRelativeMargin(crac.getInstant(InstantKind.AUTO), crac.getFlowCnec(cnecId), Unit.AMPERE), flowAmpereTolerance(expectedMargin)); } @Then("the relative margin on cnec {string} after CRA should be {double} A") public void afterCraRelativeMarginInA(String cnecId, Double expectedMargin) { - assertEquals(expectedMargin, raoResult.getRelativeMargin(crac.getInstant(InstantKind.CURATIVE), crac.getFlowCnec(cnecId), Unit.AMPERE), flowAmpereTolerance(expectedMargin)); + assertEquals(expectedMargin, CommonTestData.getRaoResult().getRelativeMargin(crac.getInstant(InstantKind.CURATIVE), crac.getFlowCnec(cnecId), Unit.AMPERE), flowAmpereTolerance(expectedMargin)); } @Then("the worst relative margin is {double} A") @@ -482,22 +482,22 @@ public void worstRelativeMarginAndCnecInA(double expectedMargin, String expected @Then("the initial relative margin on cnec {string} should be {double} MW") public void initialRelativeMarginInMW(String cnecId, Double expectedMargin) { - assertEquals(expectedMargin, raoResult.getRelativeMargin(null, crac.getFlowCnec(cnecId), Unit.MEGAWATT), flowMegawattTolerance(expectedMargin)); + assertEquals(expectedMargin, CommonTestData.getRaoResult().getRelativeMargin(null, crac.getFlowCnec(cnecId), Unit.MEGAWATT), flowMegawattTolerance(expectedMargin)); } @Then("the relative margin on cnec {string} after PRA should be {double} MW") public void afterPraRelativeMarginInMW(String cnecId, Double expectedMargin) { - assertEquals(expectedMargin, raoResult.getRelativeMargin(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), Unit.MEGAWATT), flowMegawattTolerance(expectedMargin)); + assertEquals(expectedMargin, CommonTestData.getRaoResult().getRelativeMargin(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), Unit.MEGAWATT), flowMegawattTolerance(expectedMargin)); } @Then("the relative margin on cnec {string} after ARA should be {double} MW") public void afterAraRelativeMarginInMW(String cnecId, Double expectedMargin) { - assertEquals(expectedMargin, raoResult.getRelativeMargin(crac.getInstant(InstantKind.AUTO), crac.getFlowCnec(cnecId), Unit.MEGAWATT), flowMegawattTolerance(expectedMargin)); + assertEquals(expectedMargin, CommonTestData.getRaoResult().getRelativeMargin(crac.getInstant(InstantKind.AUTO), crac.getFlowCnec(cnecId), Unit.MEGAWATT), flowMegawattTolerance(expectedMargin)); } @Then("the relative margin on cnec {string} after CRA should be {double} MW") public void afterCraRelativeMarginInMW(String cnecId, Double expectedMargin) { - assertEquals(expectedMargin, raoResult.getRelativeMargin(crac.getInstant(InstantKind.CURATIVE), crac.getFlowCnec(cnecId), Unit.MEGAWATT), flowMegawattTolerance(expectedMargin)); + assertEquals(expectedMargin, CommonTestData.getRaoResult().getRelativeMargin(crac.getInstant(InstantKind.CURATIVE), crac.getFlowCnec(cnecId), Unit.MEGAWATT), flowMegawattTolerance(expectedMargin)); } @Then("the worst relative margin is {double} MW") @@ -520,41 +520,41 @@ public void worstRelativeMarginAndCnecInMW(double expectedMargin, String expecte @Then("the initial flow on cnec {string} should be {double} A on side 1 and {double} A on side 2") public void initialFlowInA(String cnecId, Double expectedFlow1, Double expectedFlow2) { - assertEquals(expectedFlow1, raoResult.getFlow(null, crac.getFlowCnec(cnecId), TwoSides.ONE, Unit.AMPERE), flowAmpereTolerance(expectedFlow1)); - assertEquals(expectedFlow2, raoResult.getFlow(null, crac.getFlowCnec(cnecId), TwoSides.TWO, Unit.AMPERE), flowAmpereTolerance(expectedFlow2)); + assertEquals(expectedFlow1, CommonTestData.getRaoResult().getFlow(null, crac.getFlowCnec(cnecId), TwoSides.ONE, Unit.AMPERE), flowAmpereTolerance(expectedFlow1)); + assertEquals(expectedFlow2, CommonTestData.getRaoResult().getFlow(null, crac.getFlowCnec(cnecId), TwoSides.TWO, Unit.AMPERE), flowAmpereTolerance(expectedFlow2)); } @Then("the flow on cnec {string} after PRA should be {double} A on side 1 and {double} A on side 2") public void afterPraFlowInA(String cnecId, Double expectedFlow1, Double expectedFlow2) { - assertEquals(expectedFlow1, raoResult.getFlow(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), TwoSides.ONE, Unit.AMPERE), flowAmpereTolerance(expectedFlow1)); - assertEquals(expectedFlow2, raoResult.getFlow(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), TwoSides.TWO, Unit.AMPERE), flowAmpereTolerance(expectedFlow2)); + assertEquals(expectedFlow1, CommonTestData.getRaoResult().getFlow(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), TwoSides.ONE, Unit.AMPERE), flowAmpereTolerance(expectedFlow1)); + assertEquals(expectedFlow2, CommonTestData.getRaoResult().getFlow(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), TwoSides.TWO, Unit.AMPERE), flowAmpereTolerance(expectedFlow2)); } @Then("the flow on cnec {string} after ARA should be {double} A on side 1 and {double} A on side 2") public void afterAraFlowInA(String cnecId, Double expectedFlow1, Double expectedFlow2) { - assertEquals(expectedFlow1, raoResult.getFlow(crac.getInstant(InstantKind.AUTO), crac.getFlowCnec(cnecId), TwoSides.ONE, Unit.AMPERE), flowAmpereTolerance(expectedFlow1)); - assertEquals(expectedFlow2, raoResult.getFlow(crac.getInstant(InstantKind.AUTO), crac.getFlowCnec(cnecId), TwoSides.TWO, Unit.AMPERE), flowAmpereTolerance(expectedFlow2)); + assertEquals(expectedFlow1, CommonTestData.getRaoResult().getFlow(crac.getInstant(InstantKind.AUTO), crac.getFlowCnec(cnecId), TwoSides.ONE, Unit.AMPERE), flowAmpereTolerance(expectedFlow1)); + assertEquals(expectedFlow2, CommonTestData.getRaoResult().getFlow(crac.getInstant(InstantKind.AUTO), crac.getFlowCnec(cnecId), TwoSides.TWO, Unit.AMPERE), flowAmpereTolerance(expectedFlow2)); } @Then("the flow on cnec {string} after CRA should be {double} A on side 1 and {double} A on side 2") public void afterCraFlowInA(String cnecId, Double expectedFlow1, Double expectedFlow2) { - assertEquals(expectedFlow1, raoResult.getFlow(crac.getInstant(InstantKind.CURATIVE), crac.getFlowCnec(cnecId), TwoSides.TWO, Unit.AMPERE), flowAmpereTolerance(expectedFlow1)); - assertEquals(expectedFlow2, raoResult.getFlow(crac.getInstant(InstantKind.CURATIVE), crac.getFlowCnec(cnecId), TwoSides.ONE, Unit.AMPERE), flowAmpereTolerance(expectedFlow2)); + assertEquals(expectedFlow1, CommonTestData.getRaoResult().getFlow(crac.getInstant(InstantKind.CURATIVE), crac.getFlowCnec(cnecId), TwoSides.TWO, Unit.AMPERE), flowAmpereTolerance(expectedFlow1)); + assertEquals(expectedFlow2, CommonTestData.getRaoResult().getFlow(crac.getInstant(InstantKind.CURATIVE), crac.getFlowCnec(cnecId), TwoSides.ONE, Unit.AMPERE), flowAmpereTolerance(expectedFlow2)); } @Then("the initial flow on cnec {string} should be {double} A on side {int}") public void initialFlowInABothSides(String cnecId, Double expectedFlow, Integer side) { - assertEquals(expectedFlow, raoResult.getFlow(null, crac.getFlowCnec(cnecId), getTwoSideFromInteger(side), Unit.AMPERE), flowAmpereTolerance(expectedFlow)); + assertEquals(expectedFlow, CommonTestData.getRaoResult().getFlow(null, crac.getFlowCnec(cnecId), getTwoSideFromInteger(side), Unit.AMPERE), flowAmpereTolerance(expectedFlow)); } @Then("the flow on cnec {string} after PRA should be {double} A on side {int}") public void afterPraFlowInABothSides(String cnecId, Double expectedFlow, Integer side) { - assertEquals(expectedFlow, raoResult.getFlow(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), getTwoSideFromInteger(side), Unit.AMPERE), flowAmpereTolerance(expectedFlow)); + assertEquals(expectedFlow, CommonTestData.getRaoResult().getFlow(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), getTwoSideFromInteger(side), Unit.AMPERE), flowAmpereTolerance(expectedFlow)); } @Then("the flow on cnec {string} after ARA should be {double} A on side {int}") public void afterAraFlowInABothSides(String cnecId, Double expectedFlow, Integer side) { - assertEquals(expectedFlow, raoResult.getFlow(crac.getInstant(InstantKind.AUTO), crac.getFlowCnec(cnecId), getTwoSideFromInteger(side), Unit.AMPERE), flowAmpereTolerance(expectedFlow)); + assertEquals(expectedFlow, CommonTestData.getRaoResult().getFlow(crac.getInstant(InstantKind.AUTO), crac.getFlowCnec(cnecId), getTwoSideFromInteger(side), Unit.AMPERE), flowAmpereTolerance(expectedFlow)); } @Then("the flow on cnec {string} after CRA should be {double} A on side {int}") @@ -562,13 +562,13 @@ public void afterCraFlowInABothSides(String cnecId, Double expectedFlow, Integer Instant lastCurativeInstant = crac.getInstants(InstantKind.CURATIVE).stream() .sorted(Comparator.comparingInt(instant -> -instant.getOrder())) .toList().get(0); - assertEquals(expectedFlow, raoResult.getFlow(lastCurativeInstant, crac.getFlowCnec(cnecId), getTwoSideFromInteger(side), Unit.AMPERE), flowAmpereTolerance(expectedFlow)); + assertEquals(expectedFlow, CommonTestData.getRaoResult().getFlow(lastCurativeInstant, crac.getFlowCnec(cnecId), getTwoSideFromInteger(side), Unit.AMPERE), flowAmpereTolerance(expectedFlow)); } @Then("the flow on cnec {string} after {string} instant remedial actions should be {double} A on side {int}") public void afterInstantFlowInABothSides(String cnecId, String instantId, Double expectedFlow, Integer side) { Instant instant = crac.getInstant(instantId); - assertEquals(expectedFlow, raoResult.getFlow(instant, crac.getFlowCnec(cnecId), getTwoSideFromInteger(side), Unit.AMPERE), flowAmpereTolerance(expectedFlow)); + assertEquals(expectedFlow, CommonTestData.getRaoResult().getFlow(instant, crac.getFlowCnec(cnecId), getTwoSideFromInteger(side), Unit.AMPERE), flowAmpereTolerance(expectedFlow)); } /* @@ -577,49 +577,49 @@ public void afterInstantFlowInABothSides(String cnecId, String instantId, Double @Then("the initial flow on cnec {string} should be {double} MW on side 1 and {double} MW on side 2") public void initialFlowInMW(String cnecId, Double expectedFlow1, Double expectedFlow2) { - assertEquals(expectedFlow1, raoResult.getFlow(null, crac.getFlowCnec(cnecId), TwoSides.ONE, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow1)); - assertEquals(expectedFlow2, raoResult.getFlow(null, crac.getFlowCnec(cnecId), TwoSides.TWO, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow2)); + assertEquals(expectedFlow1, CommonTestData.getRaoResult().getFlow(null, crac.getFlowCnec(cnecId), TwoSides.ONE, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow1)); + assertEquals(expectedFlow2, CommonTestData.getRaoResult().getFlow(null, crac.getFlowCnec(cnecId), TwoSides.TWO, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow2)); } @Then("the flow on cnec {string} after PRA should be {double} MW on side 1 and {double} MW on side 2") public void afterPraFlowInMW(String cnecId, Double expectedFlow1, Double expectedFlow2) { - assertEquals(expectedFlow1, raoResult.getFlow(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), TwoSides.ONE, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow1)); - assertEquals(expectedFlow2, raoResult.getFlow(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), TwoSides.TWO, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow2)); + assertEquals(expectedFlow1, CommonTestData.getRaoResult().getFlow(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), TwoSides.ONE, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow1)); + assertEquals(expectedFlow2, CommonTestData.getRaoResult().getFlow(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), TwoSides.TWO, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow2)); } @Then("the flow on cnec {string} after ARA should be {double} MW on side 1 and {double} MW on side 2") public void afterAraFlowInMW(String cnecId, Double expectedFlow1, Double expectedFlow2) { - assertEquals(expectedFlow1, raoResult.getFlow(crac.getInstant(InstantKind.AUTO), crac.getFlowCnec(cnecId), TwoSides.ONE, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow1)); - assertEquals(expectedFlow2, raoResult.getFlow(crac.getInstant(InstantKind.AUTO), crac.getFlowCnec(cnecId), TwoSides.TWO, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow2)); + assertEquals(expectedFlow1, CommonTestData.getRaoResult().getFlow(crac.getInstant(InstantKind.AUTO), crac.getFlowCnec(cnecId), TwoSides.ONE, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow1)); + assertEquals(expectedFlow2, CommonTestData.getRaoResult().getFlow(crac.getInstant(InstantKind.AUTO), crac.getFlowCnec(cnecId), TwoSides.TWO, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow2)); } @Then("the flow on cnec {string} after CRA should be {double} MW on side 1 and {double} MW on side 2") public void afterCraFlowInMW(String cnecId, Double expectedFlow1, Double expectedFlow2) { Instant lastCurativeInstant = crac.getInstants(InstantKind.CURATIVE).stream().sorted(Comparator.comparingInt(instant -> -instant.getOrder())).toList().get(0); - assertEquals(expectedFlow1, raoResult.getFlow(lastCurativeInstant, crac.getFlowCnec(cnecId), TwoSides.ONE, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow1)); - assertEquals(expectedFlow2, raoResult.getFlow(lastCurativeInstant, crac.getFlowCnec(cnecId), TwoSides.TWO, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow2)); + assertEquals(expectedFlow1, CommonTestData.getRaoResult().getFlow(lastCurativeInstant, crac.getFlowCnec(cnecId), TwoSides.ONE, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow1)); + assertEquals(expectedFlow2, CommonTestData.getRaoResult().getFlow(lastCurativeInstant, crac.getFlowCnec(cnecId), TwoSides.TWO, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow2)); } @Then("the flow on cnec {string} after {string} instant remedial actions should be {double} MW on side 1 and {double} MW on side 2") public void afterInstantFlowInMW(String cnecId, String instantId, Double expectedFlow1, Double expectedFlow2) { Instant instant = crac.getInstant(instantId); - assertEquals(expectedFlow1, raoResult.getFlow(instant, crac.getFlowCnec(cnecId), TwoSides.ONE, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow1)); - assertEquals(expectedFlow2, raoResult.getFlow(instant, crac.getFlowCnec(cnecId), TwoSides.TWO, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow2)); + assertEquals(expectedFlow1, CommonTestData.getRaoResult().getFlow(instant, crac.getFlowCnec(cnecId), TwoSides.ONE, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow1)); + assertEquals(expectedFlow2, CommonTestData.getRaoResult().getFlow(instant, crac.getFlowCnec(cnecId), TwoSides.TWO, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow2)); } @Then("the initial flow on cnec {string} should be {double} MW on side {int}") public void initialFlowInMWBothSides(String cnecId, Double expectedFlow, Integer side) { - assertEquals(expectedFlow, raoResult.getFlow(null, crac.getFlowCnec(cnecId), getTwoSideFromInteger(side), Unit.MEGAWATT), flowMegawattTolerance(expectedFlow)); + assertEquals(expectedFlow, CommonTestData.getRaoResult().getFlow(null, crac.getFlowCnec(cnecId), getTwoSideFromInteger(side), Unit.MEGAWATT), flowMegawattTolerance(expectedFlow)); } @Then("the flow on cnec {string} after PRA should be {double} MW on side {int}") public void afterPraFlowInMWBothSides(String cnecId, Double expectedFlow, Integer side) { - assertEquals(expectedFlow, raoResult.getFlow(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), getTwoSideFromInteger(side), Unit.MEGAWATT), flowMegawattTolerance(expectedFlow)); + assertEquals(expectedFlow, CommonTestData.getRaoResult().getFlow(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), getTwoSideFromInteger(side), Unit.MEGAWATT), flowMegawattTolerance(expectedFlow)); } @Then("the flow on cnec {string} after ARA should be {double} MW on side {int}") public void afterAraFlowInMWBothSides(String cnecId, Double expectedFlow, Integer side) { - assertEquals(expectedFlow, raoResult.getFlow(crac.getInstant(InstantKind.AUTO), crac.getFlowCnec(cnecId), getTwoSideFromInteger(side), Unit.MEGAWATT), flowMegawattTolerance(expectedFlow)); + assertEquals(expectedFlow, CommonTestData.getRaoResult().getFlow(crac.getInstant(InstantKind.AUTO), crac.getFlowCnec(cnecId), getTwoSideFromInteger(side), Unit.MEGAWATT), flowMegawattTolerance(expectedFlow)); } @Then("the flow on cnec {string} after CRA should be {double} MW on side {int}") @@ -627,13 +627,13 @@ public void afterCraFlowInMWBothSides(String cnecId, Double expectedFlow, Intege Instant lastCurativeInstant = crac.getInstants(InstantKind.CURATIVE).stream() .sorted(Comparator.comparingInt(instant -> -instant.getOrder())) .toList().get(0); - assertEquals(expectedFlow, raoResult.getFlow(lastCurativeInstant, crac.getFlowCnec(cnecId), getTwoSideFromInteger(side), Unit.MEGAWATT), flowMegawattTolerance(expectedFlow)); + assertEquals(expectedFlow, CommonTestData.getRaoResult().getFlow(lastCurativeInstant, crac.getFlowCnec(cnecId), getTwoSideFromInteger(side), Unit.MEGAWATT), flowMegawattTolerance(expectedFlow)); } @Then("the flow on cnec {string} after {string} instant remedial actions should be {double} MW on side {int}") public void afterInstantFlowInMWBothSides(String cnecId, String instantId, Double expectedFlow, Integer side) { Instant instant = crac.getInstant(instantId); - assertEquals(expectedFlow, raoResult.getFlow(instant, crac.getFlowCnec(cnecId), getTwoSideFromInteger(side), Unit.MEGAWATT), flowMegawattTolerance(expectedFlow)); + assertEquals(expectedFlow, CommonTestData.getRaoResult().getFlow(instant, crac.getFlowCnec(cnecId), getTwoSideFromInteger(side), Unit.MEGAWATT), flowMegawattTolerance(expectedFlow)); } /* @@ -736,13 +736,13 @@ public void loopflowThresholdInMW(String cnecId, Double expectedFlow) { @Then("the absolute PTDF sum on cnec {string} initially should be {double}") public void absPtdfSum(String cnecId, Double expectedPtdfSum) { FlowCnec cnec = crac.getFlowCnec(cnecId); - assertEquals(expectedPtdfSum, raoResult.getPtdfZonalSum(null, cnec, cnec.getMonitoredSides().iterator().next()), TOLERANCE_PTDF); + assertEquals(expectedPtdfSum, CommonTestData.getRaoResult().getPtdfZonalSum(null, cnec, cnec.getMonitoredSides().iterator().next()), TOLERANCE_PTDF); } @Then("the absolute PTDF sum on cnec {string} after {string} should be {double}") public void absPtdfSumAfterInstant(String cnecId, String instantKind, Double expectedPtdfSum) { FlowCnec cnec = crac.getFlowCnec(cnecId); - assertEquals(expectedPtdfSum, raoResult.getPtdfZonalSum(crac.getInstant(InstantKind.valueOf(instantKind.toUpperCase())), cnec, cnec.getMonitoredSides().iterator().next()), TOLERANCE_PTDF); + assertEquals(expectedPtdfSum, CommonTestData.getRaoResult().getPtdfZonalSum(crac.getInstant(InstantKind.valueOf(instantKind.toUpperCase())), cnec, cnec.getMonitoredSides().iterator().next()), TOLERANCE_PTDF); } private void launchRao(int timeLimit) { @@ -839,6 +839,6 @@ private Pair getWorstCnec(Unit unit, boolean relative) { @Then("the execution details should be {string}") public void getOptimizationSteps(String string) { - assertEquals(string, raoResult.getExecutionDetails()); + assertEquals(string, CommonTestData.getRaoResult().getExecutionDetails()); } } diff --git a/tests/src/test/resources/com/powsybl/openrao/tests/features/6_post_computation_features/6_1_pst_regulation/6_1_1_pst_regulation.feature b/tests/src/test/resources/com/powsybl/openrao/tests/features/6_post_computation_features/6_1_pst_regulation/6_1_1_pst_regulation.feature index a6c7a3e08c..0f16aa1c7e 100644 --- a/tests/src/test/resources/com/powsybl/openrao/tests/features/6_post_computation_features/6_1_pst_regulation/6_1_1_pst_regulation.feature +++ b/tests/src/test/resources/com/powsybl/openrao/tests/features/6_post_computation_features/6_1_pst_regulation/6_1_1_pst_regulation.feature @@ -36,6 +36,7 @@ Feature: 6.1.1: PST Regulation Given crac file is "epic91/crac-91-13-1.json" Given configuration file is "epic91/RaoParameters_ac_pstRegulation.json" When I launch rao + When I launch PST regulation Then the execution details should be "The RAO only went through first preventive" Then its security status should be "UNSECURED" Then the worst margin is -1382.77 A @@ -77,6 +78,7 @@ Feature: 6.1.1: PST Regulation Given crac file is "epic91/crac-91-13-2.json" Given configuration file is "epic91/RaoParameters_ac_pstRegulation.json" When I launch rao + When I launch PST regulation Then the execution details should be "The RAO only went through first preventive" Then its security status should be "UNSECURED" Then the worst margin is -247.23 A @@ -143,6 +145,7 @@ Feature: 6.1.1: PST Regulation Given crac file is "epic91/crac-91-13-3.json" Given configuration file is "epic91/RaoParameters_ac_3pstsRegulation.json" When I launch rao + When I launch PST regulation Then the execution details should be "The RAO only went through first preventive" Then its security status should be "UNSECURED" # Preventive taps @@ -185,6 +188,7 @@ Feature: 6.1.1: PST Regulation Given crac file is "epic91/crac-91-13-4.json" Given configuration file is "epic91/RaoParameters_ac_2pstsRegulation.json" When I launch rao + When I launch PST regulation Then the execution details should be "The RAO only went through first preventive" Then its security status should be "UNSECURED" Then the worst margin is -733.27 A @@ -217,6 +221,7 @@ Feature: 6.1.1: PST Regulation Given crac file is "epic91/crac-91-13-5.json" Given configuration file is "epic91/RaoParameters_ac_pstRegulationSeries.json" When I launch rao + When I launch PST regulation Then the execution details should be "The RAO only went through first preventive" Then its security status should be "UNSECURED" Then the worst margin is -1187.64 A