From 0f54523cf9954e610ab95ff623bf4c777f755965 Mon Sep 17 00:00:00 2001 From: Anne Tilloy Date: Wed, 23 Aug 2023 20:03:11 +0200 Subject: [PATCH 1/2] Clean proposal. Signed-off-by: Anne Tilloy --- .../com/powsybl/openloadflow/OpenLoadFlowParameters.java | 3 +-- .../openloadflow/dc/DcValueVoltageInitializer.java | 5 ++++- .../dc/equations/DcEquationSystemCreationParameters.java | 9 +-------- .../dc/equations/DcEquationSystemCreator.java | 7 ++++++- .../openloadflow/sensi/DcSensitivityAnalysis.java | 3 +-- .../powsybl/openloadflow/dc/DcLoadFlowMatrixTest.java | 2 +- .../java/com/powsybl/openloadflow/dc/DcLoadFlowTest.java | 2 +- .../openloadflow/equations/EquationSystemTest.java | 2 +- 8 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/OpenLoadFlowParameters.java b/src/main/java/com/powsybl/openloadflow/OpenLoadFlowParameters.java index 0ee3c6a1b3..7c51bc3e30 100644 --- a/src/main/java/com/powsybl/openloadflow/OpenLoadFlowParameters.java +++ b/src/main/java/com/powsybl/openloadflow/OpenLoadFlowParameters.java @@ -1276,8 +1276,7 @@ public static DcLoadFlowParameters createDcParameters(LoadFlowParameters paramet var equationSystemCreationParameters = new DcEquationSystemCreationParameters(true, forcePhaseControlOffAndAddAngle1Var, - parameters.isDcUseTransformerRatio(), - parameters.isPhaseShifterRegulationOn()); + parameters.isDcUseTransformerRatio()); return new DcLoadFlowParameters(networkParameters, equationSystemCreationParameters, diff --git a/src/main/java/com/powsybl/openloadflow/dc/DcValueVoltageInitializer.java b/src/main/java/com/powsybl/openloadflow/dc/DcValueVoltageInitializer.java index 35400d280c..ea9d671dea 100644 --- a/src/main/java/com/powsybl/openloadflow/dc/DcValueVoltageInitializer.java +++ b/src/main/java/com/powsybl/openloadflow/dc/DcValueVoltageInitializer.java @@ -49,8 +49,10 @@ public void prepare(LfNetwork network) { // modified by slack distribution, so that AC load flow can restart from original state List busStates = distributedSlack ? ElementState.save(network.getBuses(), BusDcState::save) : null; + boolean isPhaseControl = networkParameters.isPhaseControl(); + networkParameters.setPhaseControl(false); // not supported yet. DcLoadFlowParameters parameters = new DcLoadFlowParameters(networkParameters, - new DcEquationSystemCreationParameters(false, false, useTransformerRatio, false), + new DcEquationSystemCreationParameters(false, false, useTransformerRatio), matrixFactory, distributedSlack, balanceType, @@ -67,6 +69,7 @@ public void prepare(LfNetwork network) { if (busStates != null) { ElementState.restore(busStates); } + networkParameters.setPhaseControl(isPhaseControl); // restoration. } @Override diff --git a/src/main/java/com/powsybl/openloadflow/dc/equations/DcEquationSystemCreationParameters.java b/src/main/java/com/powsybl/openloadflow/dc/equations/DcEquationSystemCreationParameters.java index 7625c39cdf..a6d23f2807 100644 --- a/src/main/java/com/powsybl/openloadflow/dc/equations/DcEquationSystemCreationParameters.java +++ b/src/main/java/com/powsybl/openloadflow/dc/equations/DcEquationSystemCreationParameters.java @@ -21,14 +21,11 @@ public class DcEquationSystemCreationParameters { private final boolean useTransformerRatio; - private final boolean phaseShifterRegulationOn; - public DcEquationSystemCreationParameters(boolean updateFlows, boolean forcePhaseControlOffAndAddAngle1Var, - boolean useTransformerRatio, boolean phaseShifterRegulationOn) { + boolean useTransformerRatio) { this.updateFlows = updateFlows; this.forcePhaseControlOffAndAddAngle1Var = forcePhaseControlOffAndAddAngle1Var; this.useTransformerRatio = useTransformerRatio; - this.phaseShifterRegulationOn = phaseShifterRegulationOn; } public boolean isUpdateFlows() { @@ -43,10 +40,6 @@ public boolean isUseTransformerRatio() { return useTransformerRatio; } - public boolean isPhaseShifterRegulationOn() { - return phaseShifterRegulationOn; - } - @Override public String toString() { return "DcEquationSystemCreationParameters(" + diff --git a/src/main/java/com/powsybl/openloadflow/dc/equations/DcEquationSystemCreator.java b/src/main/java/com/powsybl/openloadflow/dc/equations/DcEquationSystemCreator.java index f6553af8d3..58f9927074 100644 --- a/src/main/java/com/powsybl/openloadflow/dc/equations/DcEquationSystemCreator.java +++ b/src/main/java/com/powsybl/openloadflow/dc/equations/DcEquationSystemCreator.java @@ -80,7 +80,7 @@ private static void createImpedantBranch(EquationSystem equationSystem) { for (LfBranch branch : network.getBranches()) { LfBus bus1 = branch.getBus1(); diff --git a/src/main/java/com/powsybl/openloadflow/sensi/DcSensitivityAnalysis.java b/src/main/java/com/powsybl/openloadflow/sensi/DcSensitivityAnalysis.java index 3bd8e5b362..d6b0e6f0fd 100644 --- a/src/main/java/com/powsybl/openloadflow/sensi/DcSensitivityAnalysis.java +++ b/src/main/java/com/powsybl/openloadflow/sensi/DcSensitivityAnalysis.java @@ -213,8 +213,7 @@ private static DcLoadFlowParameters createDcLoadFlowParameters(LfNetworkParamete LoadFlowParameters lfParameters, OpenLoadFlowParameters parametersExt) { var equationSystemCreationParameters = new DcEquationSystemCreationParameters(true, true, - lfParameters.isDcUseTransformerRatio(), - false); + lfParameters.isDcUseTransformerRatio()); return new DcLoadFlowParameters(networkParameters, equationSystemCreationParameters, diff --git a/src/test/java/com/powsybl/openloadflow/dc/DcLoadFlowMatrixTest.java b/src/test/java/com/powsybl/openloadflow/dc/DcLoadFlowMatrixTest.java index 180a63f8c5..cff224be08 100644 --- a/src/test/java/com/powsybl/openloadflow/dc/DcLoadFlowMatrixTest.java +++ b/src/test/java/com/powsybl/openloadflow/dc/DcLoadFlowMatrixTest.java @@ -58,7 +58,7 @@ void buildDcMatrix() { List lfNetworks = Networks.load(network, new FirstSlackBusSelector()); LfNetwork mainNetwork = lfNetworks.get(0); - DcEquationSystemCreationParameters creationParameters = new DcEquationSystemCreationParameters(true, false, true, false); + DcEquationSystemCreationParameters creationParameters = new DcEquationSystemCreationParameters(true, false, true); EquationSystem equationSystem = new DcEquationSystemCreator(mainNetwork, creationParameters).create(false); for (LfBus b : mainNetwork.getBuses()) { diff --git a/src/test/java/com/powsybl/openloadflow/dc/DcLoadFlowTest.java b/src/test/java/com/powsybl/openloadflow/dc/DcLoadFlowTest.java index bf4a5eafb5..022a0cfd59 100644 --- a/src/test/java/com/powsybl/openloadflow/dc/DcLoadFlowTest.java +++ b/src/test/java/com/powsybl/openloadflow/dc/DcLoadFlowTest.java @@ -283,7 +283,7 @@ void testDisabledNonImpedantBranch() { .setLoadFlowModel(LoadFlowModel.DC) .setBreakers(true); DcLoadFlowParameters dcLoadFlowParameters = new DcLoadFlowParameters(lfNetworkParameters, - new DcEquationSystemCreationParameters(true, false, true, false), + new DcEquationSystemCreationParameters(true, false, true), new DenseMatrixFactory(), true, parameters.getBalanceType(), diff --git a/src/test/java/com/powsybl/openloadflow/equations/EquationSystemTest.java b/src/test/java/com/powsybl/openloadflow/equations/EquationSystemTest.java index 69ece37a25..63f3bd7643 100644 --- a/src/test/java/com/powsybl/openloadflow/equations/EquationSystemTest.java +++ b/src/test/java/com/powsybl/openloadflow/equations/EquationSystemTest.java @@ -173,7 +173,7 @@ void writeDcSystemTest() { List lfNetworks = Networks.load(EurostagTutorialExample1Factory.create(), new FirstSlackBusSelector()); LfNetwork network = lfNetworks.get(0); - EquationSystem equationSystem = new DcEquationSystemCreator(network, new DcEquationSystemCreationParameters(true, false, true, false)).create(false); + EquationSystem equationSystem = new DcEquationSystemCreator(network, new DcEquationSystemCreationParameters(true, false, true)).create(false); String ref = String.join(System.lineSeparator(), "bus_target_φ0 = φ0", "bus_target_p1 = dc_p_2(φ0, φ1) + dc_p_1(φ1, φ2) + dc_p_1(φ1, φ2)", From c4e703fdec84565948027c8a95e6cad2fbbc89e7 Mon Sep 17 00:00:00 2001 From: Geoffroy Jamgotchian Date: Wed, 23 Aug 2023 21:08:59 +0200 Subject: [PATCH 2/2] Clean Signed-off-by: Geoffroy Jamgotchian --- .../dc/DcValueVoltageInitializer.java | 8 ++-- .../network/LfNetworkParameters.java | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/dc/DcValueVoltageInitializer.java b/src/main/java/com/powsybl/openloadflow/dc/DcValueVoltageInitializer.java index ea9d671dea..f7ec6976fb 100644 --- a/src/main/java/com/powsybl/openloadflow/dc/DcValueVoltageInitializer.java +++ b/src/main/java/com/powsybl/openloadflow/dc/DcValueVoltageInitializer.java @@ -49,9 +49,10 @@ public void prepare(LfNetwork network) { // modified by slack distribution, so that AC load flow can restart from original state List busStates = distributedSlack ? ElementState.save(network.getBuses(), BusDcState::save) : null; - boolean isPhaseControl = networkParameters.isPhaseControl(); - networkParameters.setPhaseControl(false); // not supported yet. - DcLoadFlowParameters parameters = new DcLoadFlowParameters(networkParameters, + LfNetworkParameters networkParametersDcInit = new LfNetworkParameters(networkParameters) + .setPhaseControl(false); // not supported yet. + + DcLoadFlowParameters parameters = new DcLoadFlowParameters(networkParametersDcInit, new DcEquationSystemCreationParameters(false, false, useTransformerRatio), matrixFactory, distributedSlack, @@ -69,7 +70,6 @@ public void prepare(LfNetwork network) { if (busStates != null) { ElementState.restore(busStates); } - networkParameters.setPhaseControl(isPhaseControl); // restoration. } @Override diff --git a/src/main/java/com/powsybl/openloadflow/network/LfNetworkParameters.java b/src/main/java/com/powsybl/openloadflow/network/LfNetworkParameters.java index 97d9740337..cac39aa8f6 100644 --- a/src/main/java/com/powsybl/openloadflow/network/LfNetworkParameters.java +++ b/src/main/java/com/powsybl/openloadflow/network/LfNetworkParameters.java @@ -13,6 +13,7 @@ import com.powsybl.openloadflow.graph.GraphConnectivityFactory; import java.util.Collections; +import java.util.HashSet; import java.util.Objects; import java.util.Set; @@ -108,6 +109,43 @@ public class LfNetworkParameters { private boolean asymmetrical = ASYMMETRICAL_DEFAULT_VALUE; + public LfNetworkParameters() { + } + + public LfNetworkParameters(LfNetworkParameters other) { + Objects.requireNonNull(other); + this.slackBusSelector = other.slackBusSelector; + this.connectivityFactory = other.connectivityFactory; + this.generatorVoltageRemoteControl = other.generatorVoltageRemoteControl; + this.minImpedance = other.minImpedance; + this.twtSplitShuntAdmittance = other.twtSplitShuntAdmittance; + this.breakers = other.breakers; + this.plausibleActivePowerLimit = other.plausibleActivePowerLimit; + this.computeMainConnectedComponentOnly = other.computeMainConnectedComponentOnly; + this.countriesToBalance = new HashSet<>(other.countriesToBalance); + this.distributedOnConformLoad = other.distributedOnConformLoad; + this.phaseControl = other.phaseControl; + this.transformerVoltageControl = other.transformerVoltageControl; + this.voltagePerReactivePowerControl = other.voltagePerReactivePowerControl; + this.reactivePowerRemoteControl = other.reactivePowerRemoteControl; + this.loadFlowModel = other.loadFlowModel; + this.shuntVoltageControl = other.shuntVoltageControl; + this.reactiveLimits = other.reactiveLimits; + this.hvdcAcEmulation = other.hvdcAcEmulation; + this.minPlausibleTargetVoltage = other.minPlausibleTargetVoltage; + this.maxPlausibleTargetVoltage = other.maxPlausibleTargetVoltage; + this.minNominalVoltageTargetVoltageCheck = other.minNominalVoltageTargetVoltageCheck; + this.loaderPostProcessorSelection = new HashSet<>(other.loaderPostProcessorSelection); + this.reactiveRangeCheckMode = other.reactiveRangeCheckMode; + this.lowImpedanceThreshold = other.lowImpedanceThreshold; + this.svcVoltageMonitoring = other.svcVoltageMonitoring; + this.maxSlackBusCount = other.maxSlackBusCount; + this.debugDir = other.debugDir; + this.secondaryVoltageControl = other.secondaryVoltageControl; + this.cacheEnabled = other.cacheEnabled; + this.asymmetrical = other.asymmetrical; + } + public SlackBusSelector getSlackBusSelector() { return slackBusSelector; }