From dec6e7c92c54aa92b13150136c089c386cc6ce05 Mon Sep 17 00:00:00 2001 From: vmouradian Date: Tue, 3 Dec 2024 13:27:39 +0100 Subject: [PATCH] introduce contingency parameters extension Signed-off-by: vmouradian --- .../sa/ContingencyParameters.java | 47 +++++++++++++++++++ .../sa/OpenSecurityAnalysisTest.java | 14 +++++- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/powsybl/openloadflow/sa/ContingencyParameters.java diff --git a/src/main/java/com/powsybl/openloadflow/sa/ContingencyParameters.java b/src/main/java/com/powsybl/openloadflow/sa/ContingencyParameters.java new file mode 100644 index 0000000000..df5e685d2b --- /dev/null +++ b/src/main/java/com/powsybl/openloadflow/sa/ContingencyParameters.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2024, Coreso SA (https://www.coreso.eu/) and TSCNET Services GmbH (https://www.tscnet.eu/) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.openloadflow.sa; + +import com.powsybl.commons.extensions.AbstractExtension; +import com.powsybl.contingency.Contingency; +import com.powsybl.loadflow.LoadFlowParameters; + +/** + * @author Valentin Mouradian {@literal } + */ +public class ContingencyParameters extends AbstractExtension { + + private boolean distributedSlack; + + private boolean areaInterchangeControl; + + private LoadFlowParameters.BalanceType balanceType; + + public ContingencyParameters(boolean distributedSlack, boolean areaInterchangeControl, LoadFlowParameters.BalanceType balanceType) { + this.distributedSlack = distributedSlack; + this.areaInterchangeControl = areaInterchangeControl; + this.balanceType = balanceType; + } + + @Override + public String getName() { + return "ContingencyParameters"; + } + + public boolean isDistributedSlack() { + return distributedSlack; + } + + public boolean isAreaInterchangeControl() { + return areaInterchangeControl; + } + + public LoadFlowParameters.BalanceType getBalanceType() { + return balanceType; + } +} diff --git a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java index 2037ddab94..0a51796349 100644 --- a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java +++ b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java @@ -62,7 +62,6 @@ import static com.powsybl.openloadflow.util.LoadFlowAssert.*; import static java.util.Collections.emptySet; import static org.junit.jupiter.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Geoffroy Jamgotchian {@literal } @@ -3997,4 +3996,17 @@ void testNoCc0Sc0() { assertEquals(LoadFlowResult.ComponentResult.Status.CONVERGED, saResultAll.getPreContingencyResult().getStatus()); assertEquals(6, saResultAll.getPreContingencyResult().getNetworkResult().getBusResults().size()); // 6 buses in total } + + @Test + void testContingencyParametersExtension() { + Contingency contingency = new Contingency("L2", new BranchContingency("L2")); + contingency.addExtension(ContingencyParameters.class, new ContingencyParameters(false, true, LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD)); + + ContingencyParameters contingencyParameters = contingency.getExtension(ContingencyParameters.class); + + assertEquals(contingencyParameters, contingency.getExtensionByName("ContingencyParameters")); + assertFalse(contingencyParameters.isDistributedSlack()); + assertTrue(contingencyParameters.isAreaInterchangeControl()); + assertEquals(LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD, contingencyParameters.getBalanceType()); + } }