diff --git a/src/main/java/com/powsybl/openloadflow/network/HvdcState.java b/src/main/java/com/powsybl/openloadflow/network/HvdcState.java new file mode 100644 index 0000000000..a5058c5aff --- /dev/null +++ b/src/main/java/com/powsybl/openloadflow/network/HvdcState.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2023, 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.openloadflow.network; + +/** + * @author Anne Tilloy + */ +public class HvdcState extends ElementState { + + public HvdcState(LfHvdc hvdc) { + super(hvdc); + } + + public static HvdcState save(LfHvdc hvdc) { + return new HvdcState(hvdc); + } +} diff --git a/src/main/java/com/powsybl/openloadflow/network/NetworkState.java b/src/main/java/com/powsybl/openloadflow/network/NetworkState.java index 57ac31bffd..10f62b5bd5 100644 --- a/src/main/java/com/powsybl/openloadflow/network/NetworkState.java +++ b/src/main/java/com/powsybl/openloadflow/network/NetworkState.java @@ -23,9 +23,12 @@ public class NetworkState { private final List branchStates; - protected NetworkState(List busStates, List branchStates) { + private final List hvdcStates; + + protected NetworkState(List busStates, List branchStates, List hvdcStates) { this.busStates = Objects.requireNonNull(busStates); this.branchStates = Objects.requireNonNull(branchStates); + this.hvdcStates = Objects.requireNonNull(hvdcStates); } public static NetworkState save(LfNetwork network) { @@ -33,12 +36,14 @@ public static NetworkState save(LfNetwork network) { LOGGER.trace("Saving network state"); List busStates = ElementState.save(network.getBuses(), BusState::save); List branchStates = ElementState.save(network.getBranches(), BranchState::save); - return new NetworkState(busStates, branchStates); + List hvdcStates = ElementState.save(network.getHvdcs(), HvdcState::save); + return new NetworkState(busStates, branchStates, hvdcStates); } public void restore() { LOGGER.trace("Restoring network state"); ElementState.restore(busStates); ElementState.restore(branchStates); + ElementState.restore(hvdcStates); } } diff --git a/src/test/java/com/powsybl/openloadflow/sensi/ac/AcSensitivityAnalysisContingenciesTest.java b/src/test/java/com/powsybl/openloadflow/sensi/ac/AcSensitivityAnalysisContingenciesTest.java index e336161fa5..72e766a2fc 100644 --- a/src/test/java/com/powsybl/openloadflow/sensi/ac/AcSensitivityAnalysisContingenciesTest.java +++ b/src/test/java/com/powsybl/openloadflow/sensi/ac/AcSensitivityAnalysisContingenciesTest.java @@ -1194,4 +1194,30 @@ void testPredefinedResults4() { assertEquals(0, result.getBranchFlow1SensitivityValue("l23", "l23", "l12"), LoadFlowAssert.DELTA_POWER); assertEquals(Double.NaN, result.getBranchFlow1SensitivityValue("l23", "l23", "l23"), LoadFlowAssert.DELTA_POWER); } + + @Test + void testRestoreAfterContingencyOnHvdc() { + Network network = HvdcNetworkFactory.createWithHvdcInAcEmulation(); + network.getGeneratorStream().forEach(gen -> gen.setMaxP(2 * gen.getMaxP())); + network.getHvdcLine("hvdc34").newExtension(HvdcAngleDroopActivePowerControlAdder.class) + .withDroop(180) + .withP0(0.f) + .withEnabled(true) + .add(); + + SensitivityAnalysisParameters sensiParameters = createParameters(false, "b1_vl_0", true); + sensiParameters.getLoadFlowParameters().getExtension(OpenLoadFlowParameters.class).setSlackBusPMaxMismatch(0.001); + + List factors = createFactorMatrix(Stream.of("g1", "g5").map(network::getGenerator).collect(Collectors.toList()), + Stream.of("l12", "l25", "l56").map(network::getBranch).collect(Collectors.toList())); + + List contingencies = List.of(new Contingency("hvdc34", new HvdcLineContingency("hvdc34")), + new Contingency("l45", new BranchContingency("l45"))); + + SensitivityAnalysisResult result = sensiRunner.run(network, factors, contingencies, Collections.emptyList(), sensiParameters); + + assertEquals(0.269, result.getBranchFlow1SensitivityValue("l45", "g1", "l12"), LoadFlowAssert.DELTA_POWER); + assertEquals(0.356, result.getBranchFlow1SensitivityValue("l45", "g1", "l25"), LoadFlowAssert.DELTA_POWER); + assertEquals(-0.144, result.getBranchFlow1SensitivityValue("l45", "g1", "l56"), LoadFlowAssert.DELTA_POWER); + } }