From cc718eb103c301f4a0ac8a87aa9eaf316b0d037d Mon Sep 17 00:00:00 2001 From: Bertrand Rix Date: Thu, 20 May 2021 13:19:39 +0200 Subject: [PATCH 1/8] Use new parameters from powsybl-core isDcUseTransformerRatio and countriesToBalance. Signed-off-by: Bertrand Rix --- .../openloadflow/OpenLoadFlowParameters.java | 13 ------------- .../openloadflow/OpenLoadFlowProvider.java | 9 +++++---- .../ac/outerloop/AcLoadFlowParameters.java | 11 ++++++++++- .../ac/outerloop/AcloadFlowEngine.java | 8 +++----- .../powsybl/openloadflow/dc/DcLoadFlowEngine.java | 5 +++-- .../openloadflow/network/LfNetworkParameters.java | 15 +++++++++++++-- .../network/impl/LfNetworkLoaderImpl.java | 8 ++++++++ .../openloadflow/sensi/AcSensitivityAnalysis.java | 2 +- .../openloadflow/sensi/DcSensitivityAnalysis.java | 6 +++--- .../openloadflow/util/ParameterConstants.java | 3 --- .../openloadflow/OpenLoadFlowParametersTest.java | 1 - .../GeneratorTargetVoltageInconsistencyTest.java | 5 +++-- 12 files changed, 49 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/OpenLoadFlowParameters.java b/src/main/java/com/powsybl/openloadflow/OpenLoadFlowParameters.java index 273315a29d..acf3071185 100644 --- a/src/main/java/com/powsybl/openloadflow/OpenLoadFlowParameters.java +++ b/src/main/java/com/powsybl/openloadflow/OpenLoadFlowParameters.java @@ -38,8 +38,6 @@ public enum LowImpedanceBranchMode { private boolean loadPowerFactorConstant = LOAD_POWER_FACTOR_CONSTANT_DEFAULT_VALUE; - private boolean dcUseTransformerRatio = DC_USE_TRANSFORMER_RATIO_DEFAULT_VALUE; - private double plausibleActivePowerLimit = PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE; private boolean addRatioToLinesWithDifferentNominalVoltageAtBothEnds = ADD_RATIO_TO_LINES_WITH_DIFFERENT_NOMINAL_VOLTAGE_AT_BOTH_ENDS_DEFAULT_VALUE; @@ -105,15 +103,6 @@ public OpenLoadFlowParameters setLoadPowerFactorConstant(boolean loadPowerFactor return this; } - public boolean isDcUseTransformerRatio() { - return dcUseTransformerRatio; - } - - public OpenLoadFlowParameters setDcUseTransformerRatio(boolean dcUseTransformerRatio) { - this.dcUseTransformerRatio = dcUseTransformerRatio; - return this; - } - public double getPlausibleActivePowerLimit() { return plausibleActivePowerLimit; } @@ -157,7 +146,6 @@ public String toString() { ", voltageRemoteControl=" + voltageRemoteControl + ", lowImpedanceBranchMode=" + lowImpedanceBranchMode + ", loadPowerFactorConstant=" + loadPowerFactorConstant + - ", dcUseTransformerRatio=" + dcUseTransformerRatio + ", plausibleActivePowerLimit=" + plausibleActivePowerLimit + ", addRatioToLinesWithDifferentNominalVoltageAtBothEnds=" + addRatioToLinesWithDifferentNominalVoltageAtBothEnds + ", slackBusPMaxMismatch=" + slackBusPMaxMismatch + @@ -181,7 +169,6 @@ public OpenLoadFlowParameters load(PlatformConfig platformConfig) { config.getBooleanProperty(THROWS_EXCEPTION_IN_CASE_OF_SLACK_DISTRIBUTION_FAILURE_PARAM_NAME, THROWS_EXCEPTION_IN_CASE_OF_SLACK_DISTRIBUTION_FAILURE_DEFAULT_VALUE) ) .setLoadPowerFactorConstant(config.getBooleanProperty(LOAD_POWER_FACTOR_CONSTANT_PARAM_NAME, LOAD_POWER_FACTOR_CONSTANT_DEFAULT_VALUE)) - .setDcUseTransformerRatio(config.getBooleanProperty(DC_USE_TRANSFORMER_RATIO_PARAM_NAME, DC_USE_TRANSFORMER_RATIO_DEFAULT_VALUE)) .setPlausibleActivePowerLimit(config.getDoubleProperty(PLAUSIBLE_ACTIVE_POWER_LIMIT_PARAM_NAME, PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE)) .setAddRatioToLinesWithDifferentNominalVoltageAtBothEnds(config.getBooleanProperty(ADD_RATIO_TO_LINES_WITH_DIFFERENT_NOMINAL_VOLTAGE_AT_BOTH_ENDS_NAME, ADD_RATIO_TO_LINES_WITH_DIFFERENT_NOMINAL_VOLTAGE_AT_BOTH_ENDS_DEFAULT_VALUE)) .setSlackBusPMaxMismatch(config.getDoubleProperty(SLACK_BUS_P_MAX_MISMATCH_NAME, SLACK_BUS_P_MAX_MISMATCH_DEFAULT_VALUE)) diff --git a/src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java b/src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java index fa14c1c3e7..4f21cb252e 100644 --- a/src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java +++ b/src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java @@ -181,7 +181,8 @@ public static AcLoadFlowParameters createAcParameters(Network network, MatrixFac forceA1Var, parametersExt.isAddRatioToLinesWithDifferentNominalVoltageAtBothEnds(), branchesWithCurrent, - parameters.getConnectedComponentMode() == LoadFlowParameters.ConnectedComponentMode.MAIN); + parameters.getConnectedComponentMode() == LoadFlowParameters.ConnectedComponentMode.MAIN, + parameters.getCountriesToBalance()); } private LoadFlowResult runAc(Network network, LoadFlowParameters parameters, OpenLoadFlowParameters parametersExt, Reporter reporter) { @@ -247,7 +248,7 @@ private LoadFlowResult runDc(Network network, LoadFlowParameters parameters, Ope SlackBusSelector slackBusSelector = getSlackBusSelector(network, parameters, parametersExt); LOGGER.info("Slack bus selector: {}", slackBusSelector.getClass().getSimpleName()); - LOGGER.info("Use transformer ratio: {}", parametersExt.isDcUseTransformerRatio()); + LOGGER.info("Use transformer ratio: {}", parameters.isDcUseTransformerRatio()); LOGGER.info("Distributed slack: {}", parameters.isDistributedSlack()); LOGGER.info("Balance type: {}", parameters.getBalanceType()); LOGGER.info("Plausible active power limit: {}", parametersExt.getPlausibleActivePowerLimit()); @@ -257,7 +258,7 @@ private LoadFlowResult runDc(Network network, LoadFlowParameters parameters, Ope DcLoadFlowParameters dcParameters = new DcLoadFlowParameters(slackBusSelector, matrixFactory, true, - parametersExt.isDcUseTransformerRatio(), + parameters.isDcUseTransformerRatio(), parameters.isDistributedSlack(), parameters.getBalanceType(), forcePhaseControlOffAndAddAngle1Var, @@ -266,7 +267,7 @@ private LoadFlowResult runDc(Network network, LoadFlowParameters parameters, Ope true, parameters.getConnectedComponentMode() == LoadFlowParameters.ConnectedComponentMode.MAIN); - List results = new DcLoadFlowEngine(network, dcParameters, reporter) + List results = new DcLoadFlowEngine(network, dcParameters, reporter, parameters.getCountriesToBalance()) .run(reporter); Networks.resetState(network); diff --git a/src/main/java/com/powsybl/openloadflow/ac/outerloop/AcLoadFlowParameters.java b/src/main/java/com/powsybl/openloadflow/ac/outerloop/AcLoadFlowParameters.java index 4fc8e36d6e..8c75d60bdf 100644 --- a/src/main/java/com/powsybl/openloadflow/ac/outerloop/AcLoadFlowParameters.java +++ b/src/main/java/com/powsybl/openloadflow/ac/outerloop/AcLoadFlowParameters.java @@ -6,6 +6,7 @@ */ package com.powsybl.openloadflow.ac.outerloop; +import com.powsybl.iidm.network.Country; import com.powsybl.math.matrix.MatrixFactory; import com.powsybl.openloadflow.ac.nr.NewtonRaphsonStoppingCriteria; import com.powsybl.openloadflow.equations.VoltageInitializer; @@ -52,13 +53,16 @@ public class AcLoadFlowParameters { private final boolean computeMainConnectedComponentOnly; + private final Set countriesToBalance; + public AcLoadFlowParameters(SlackBusSelector slackBusSelector, VoltageInitializer voltageInitializer, NewtonRaphsonStoppingCriteria stoppingCriteria, List outerLoops, MatrixFactory matrixFactory, boolean voltageRemoteControl, boolean phaseControl, boolean transformerVoltageControlOn, boolean minImpedance, boolean twtSplitShuntAdmittance, boolean breakers, double plausibleActivePowerLimit, boolean forceA1Var, boolean addRatioToLinesWithDifferentNominalVoltageAtBothEnds, - Set branchesWithCurrent, boolean computeMainConnectedComponentOnly) { + Set branchesWithCurrent, boolean computeMainConnectedComponentOnly, + Set countriesToBalance) { this.slackBusSelector = Objects.requireNonNull(slackBusSelector); this.voltageInitializer = Objects.requireNonNull(voltageInitializer); this.stoppingCriteria = Objects.requireNonNull(stoppingCriteria); @@ -75,6 +79,7 @@ public AcLoadFlowParameters(SlackBusSelector slackBusSelector, VoltageInitialize this.addRatioToLinesWithDifferentNominalVoltageAtBothEnds = addRatioToLinesWithDifferentNominalVoltageAtBothEnds; this.branchesWithCurrent = branchesWithCurrent; this.computeMainConnectedComponentOnly = computeMainConnectedComponentOnly; + this.countriesToBalance = countriesToBalance; } public SlackBusSelector getSlackBusSelector() { @@ -145,4 +150,8 @@ public boolean isComputeMainConnectedComponentOnly() { return computeMainConnectedComponentOnly; } + public Set getCountriesToBalance() { + return countriesToBalance; + } + } diff --git a/src/main/java/com/powsybl/openloadflow/ac/outerloop/AcloadFlowEngine.java b/src/main/java/com/powsybl/openloadflow/ac/outerloop/AcloadFlowEngine.java index b857ed550c..543be5e5a2 100644 --- a/src/main/java/com/powsybl/openloadflow/ac/outerloop/AcloadFlowEngine.java +++ b/src/main/java/com/powsybl/openloadflow/ac/outerloop/AcloadFlowEngine.java @@ -21,10 +21,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; /** @@ -59,7 +56,8 @@ public static List createNetworks(Object network, AcLoadFlowParameter parameters.isBreakers(), parameters.getPlausibleActivePowerLimit(), parameters.isAddRatioToLinesWithDifferentNominalVoltageAtBothEnds(), - parameters.isComputeMainConnectedComponentOnly()); + parameters.isComputeMainConnectedComponentOnly(), + parameters.getCountriesToBalance()); return LfNetwork.load(network, networkParameters, reporter); } diff --git a/src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowEngine.java b/src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowEngine.java index a609407277..ff147df367 100644 --- a/src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowEngine.java +++ b/src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowEngine.java @@ -8,6 +8,7 @@ import com.powsybl.commons.reporter.Report; import com.powsybl.commons.reporter.Reporter; +import com.powsybl.iidm.network.Country; import com.powsybl.loadflow.LoadFlowResult; import com.powsybl.math.matrix.MatrixFactory; import com.powsybl.openloadflow.OpenLoadFlowReportConstants; @@ -42,9 +43,9 @@ public DcLoadFlowEngine(LfNetwork network, MatrixFactory matrixFactory, boolean parameters = new DcLoadFlowParameters(new FirstSlackBusSelector(), matrixFactory, setVToNan); } - public DcLoadFlowEngine(Object network, DcLoadFlowParameters parameters, Reporter reporter) { + public DcLoadFlowEngine(Object network, DcLoadFlowParameters parameters, Reporter reporter, Set countriesToBalance) { LfNetworkParameters lfNetworkParameters = new LfNetworkParameters(parameters.getSlackBusSelector(), false, false, false, false, - parameters.getPlausibleActivePowerLimit(), false, parameters.isComputeMainConnectedComponentOnly()); + parameters.getPlausibleActivePowerLimit(), false, parameters.isComputeMainConnectedComponentOnly(), countriesToBalance); this.networks = LfNetwork.load(network, lfNetworkParameters, reporter); this.parameters = Objects.requireNonNull(parameters); } diff --git a/src/main/java/com/powsybl/openloadflow/network/LfNetworkParameters.java b/src/main/java/com/powsybl/openloadflow/network/LfNetworkParameters.java index a933e2e15f..fef5eac316 100644 --- a/src/main/java/com/powsybl/openloadflow/network/LfNetworkParameters.java +++ b/src/main/java/com/powsybl/openloadflow/network/LfNetworkParameters.java @@ -6,8 +6,12 @@ */ package com.powsybl.openloadflow.network; +import com.powsybl.iidm.network.Country; import com.powsybl.openloadflow.util.ParameterConstants; +import java.util.Collections; +import java.util.Set; + /** * @author Geoffroy Jamgotchian */ @@ -29,16 +33,18 @@ public class LfNetworkParameters { private final boolean computeMainConnectedComponentOnly; + private final Set countriesToBalance; + public LfNetworkParameters(SlackBusSelector slackBusSelector) { this(slackBusSelector, false, false, false, false, ParameterConstants.PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE, false, - true); + true, Collections.emptySet()); } public LfNetworkParameters(SlackBusSelector slackBusSelector, boolean generatorVoltageRemoteControl, boolean minImpedance, boolean twtSplitShuntAdmittance, boolean breakers, double plausibleActivePowerLimit, boolean addRatioToLinesWithDifferentNominalVoltageAtBothEnds, - boolean computeMainConnectedComponentOnly) { + boolean computeMainConnectedComponentOnly, Set countriesToBalance) { this.slackBusSelector = slackBusSelector; this.generatorVoltageRemoteControl = generatorVoltageRemoteControl; this.minImpedance = minImpedance; @@ -47,6 +53,7 @@ public LfNetworkParameters(SlackBusSelector slackBusSelector, boolean generatorV this.plausibleActivePowerLimit = plausibleActivePowerLimit; this.addRatioToLinesWithDifferentNominalVoltageAtBothEnds = addRatioToLinesWithDifferentNominalVoltageAtBothEnds; this.computeMainConnectedComponentOnly = computeMainConnectedComponentOnly; + this.countriesToBalance = countriesToBalance; } public SlackBusSelector getSlackBusSelector() { @@ -80,4 +87,8 @@ public boolean isAddRatioToLinesWithDifferentNominalVoltageAtBothEnds() { public boolean isComputeMainConnectedComponentOnly() { return computeMainConnectedComponentOnly; } + + public Set getCountriesToBalance() { + return countriesToBalance; + } } diff --git a/src/main/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImpl.java b/src/main/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImpl.java index f09e4bb2ca..a2cfcc2d72 100644 --- a/src/main/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImpl.java +++ b/src/main/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImpl.java @@ -49,6 +49,7 @@ private static void createBuses(List buses, LfNetworkParameters parameters, LoadingContext loadingContext, LfNetworkLoadingReport report) { for (Bus bus : buses) { LfBusImpl lfBus = createBus(bus, parameters, lfNetwork, loadingContext, report); + lfBus.setDisabled(lfBus.isDisabled() || !participateToBalance(parameters, bus)); lfNetwork.addBus(lfBus); lfBuses.add(lfBus); } @@ -566,4 +567,11 @@ public Optional> load(Object network, LfNetworkParameters parame return Optional.empty(); } + + static boolean participateToBalance(LfNetworkParameters parameters, Bus b) { + return parameters.getCountriesToBalance().isEmpty() + || b.getVoltageLevel().getSubstation().getCountry() + .map(country -> parameters.getCountriesToBalance().contains(country)) + .orElse(false); + } } diff --git a/src/main/java/com/powsybl/openloadflow/sensi/AcSensitivityAnalysis.java b/src/main/java/com/powsybl/openloadflow/sensi/AcSensitivityAnalysis.java index 0911ac10f3..ec709c4e89 100644 --- a/src/main/java/com/powsybl/openloadflow/sensi/AcSensitivityAnalysis.java +++ b/src/main/java/com/powsybl/openloadflow/sensi/AcSensitivityAnalysis.java @@ -159,7 +159,7 @@ public void analyse(Network network, List contingencies, SlackBusSelector slackBusSelector = SlackBusSelector.fromMode(lfParametersExt.getSlackBusSelectionMode(), lfParametersExt.getSlackBusId()); LfNetworkParameters lfNetworkParameters = new LfNetworkParameters(slackBusSelector, lfParametersExt.hasVoltageRemoteControl(), true, lfParameters.isTwtSplitShuntAdmittance(), false, lfParametersExt.getPlausibleActivePowerLimit(), - false, true); + false, true, lfParameters.getCountriesToBalance()); List lfNetworks = LfNetwork.load(network, lfNetworkParameters, reporter); LfNetwork lfNetwork = lfNetworks.get(0); checkContingencies(network, lfNetwork, contingencies); diff --git a/src/main/java/com/powsybl/openloadflow/sensi/DcSensitivityAnalysis.java b/src/main/java/com/powsybl/openloadflow/sensi/DcSensitivityAnalysis.java index 02b533496b..86c28b3c8f 100644 --- a/src/main/java/com/powsybl/openloadflow/sensi/DcSensitivityAnalysis.java +++ b/src/main/java/com/powsybl/openloadflow/sensi/DcSensitivityAnalysis.java @@ -598,7 +598,7 @@ public void analyse(Network network, List contingencies, // create the network (we only manage main connected component) SlackBusSelector slackBusSelector = SlackBusSelector.fromMode(lfParametersExt.getSlackBusSelectionMode(), lfParametersExt.getSlackBusId()); LfNetworkParameters lfNetworkParameters = new LfNetworkParameters(slackBusSelector, false, true, lfParameters.isTwtSplitShuntAdmittance(), - false, lfParametersExt.getPlausibleActivePowerLimit(), false, true); + false, lfParametersExt.getPlausibleActivePowerLimit(), false, true, lfParameters.getCountriesToBalance()); List lfNetworks = LfNetwork.load(network, lfNetworkParameters, reporter); LfNetwork lfNetwork = lfNetworks.get(0); checkContingencies(network, lfNetwork, contingencies); @@ -622,13 +622,13 @@ public void analyse(Network network, List contingencies, // create DC load flow engine for setting the function reference DcLoadFlowParameters dcLoadFlowParameters = new DcLoadFlowParameters(slackBusSelector, matrixFactory, - true, lfParametersExt.isDcUseTransformerRatio(), lfParameters.isDistributedSlack(), lfParameters.getBalanceType(), true, + true, lfParameters.isDcUseTransformerRatio(), lfParameters.isDistributedSlack(), lfParameters.getBalanceType(), true, lfParametersExt.getPlausibleActivePowerLimit(), lfParametersExt.isAddRatioToLinesWithDifferentNominalVoltageAtBothEnds(), true, true); DcLoadFlowEngine dcLoadFlowEngine = new DcLoadFlowEngine(lfNetworks, dcLoadFlowParameters); // create DC equation system for sensitivity analysis DcEquationSystemCreationParameters dcEquationSystemCreationParameters = new DcEquationSystemCreationParameters(dcLoadFlowParameters.isUpdateFlows(), true, - dcLoadFlowParameters.isForcePhaseControlOffAndAddAngle1Var(), lfParametersExt.isDcUseTransformerRatio()); + dcLoadFlowParameters.isForcePhaseControlOffAndAddAngle1Var(), lfParameters.isDcUseTransformerRatio()); EquationSystem equationSystem = DcEquationSystem.create(lfNetwork, new VariableSet(), dcEquationSystemCreationParameters); // we wrap the factor into a class that allows us to have access to their branch and EquationTerm instantly diff --git a/src/main/java/com/powsybl/openloadflow/util/ParameterConstants.java b/src/main/java/com/powsybl/openloadflow/util/ParameterConstants.java index ac2c6d2eff..9775f6f4de 100644 --- a/src/main/java/com/powsybl/openloadflow/util/ParameterConstants.java +++ b/src/main/java/com/powsybl/openloadflow/util/ParameterConstants.java @@ -32,9 +32,6 @@ public final class ParameterConstants { public static final String LOAD_POWER_FACTOR_CONSTANT_PARAM_NAME = "loadPowerFactorConstant"; public static final boolean LOAD_POWER_FACTOR_CONSTANT_DEFAULT_VALUE = false; - public static final String DC_USE_TRANSFORMER_RATIO_PARAM_NAME = "dcUseTransformerRatio"; - public static final boolean DC_USE_TRANSFORMER_RATIO_DEFAULT_VALUE = true; - public static final String PLAUSIBLE_ACTIVE_POWER_LIMIT_PARAM_NAME = "plausibleActivePowerLimit"; public static final double PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE = 10000; diff --git a/src/test/java/com/powsybl/openloadflow/OpenLoadFlowParametersTest.java b/src/test/java/com/powsybl/openloadflow/OpenLoadFlowParametersTest.java index ebd4b6378f..5954e748af 100644 --- a/src/test/java/com/powsybl/openloadflow/OpenLoadFlowParametersTest.java +++ b/src/test/java/com/powsybl/openloadflow/OpenLoadFlowParametersTest.java @@ -101,7 +101,6 @@ void testDefaultOpenLoadflowConfig() { assertEquals(LOW_IMPEDANCE_BRANCH_MODE_DEFAULT_VALUE, olfParameters.getLowImpedanceBranchMode()); assertEquals(THROWS_EXCEPTION_IN_CASE_OF_SLACK_DISTRIBUTION_FAILURE_DEFAULT_VALUE, olfParameters.isThrowsExceptionInCaseOfSlackDistributionFailure()); - assertEquals(DC_USE_TRANSFORMER_RATIO_DEFAULT_VALUE, olfParameters.isDcUseTransformerRatio()); assertEquals(SLACK_BUS_P_MAX_MISMATCH_DEFAULT_VALUE, olfParameters.getSlackBusPMaxMismatch(), 0.0); } diff --git a/src/test/java/com/powsybl/openloadflow/ac/GeneratorTargetVoltageInconsistencyTest.java b/src/test/java/com/powsybl/openloadflow/ac/GeneratorTargetVoltageInconsistencyTest.java index 60a11cbd30..662ba7909e 100644 --- a/src/test/java/com/powsybl/openloadflow/ac/GeneratorTargetVoltageInconsistencyTest.java +++ b/src/test/java/com/powsybl/openloadflow/ac/GeneratorTargetVoltageInconsistencyTest.java @@ -11,6 +11,7 @@ import com.powsybl.openloadflow.util.ParameterConstants; import org.junit.jupiter.api.Test; +import java.util.Collections; import java.util.List; import java.util.Optional; @@ -201,7 +202,7 @@ void remoteTest() { FirstSlackBusSelector slackBusSelector = new FirstSlackBusSelector(); LfNetworkParameters parameters = new LfNetworkParameters(slackBusSelector, true, false, false, false, ParameterConstants.PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE, false, - true); + true, Collections.emptySet()); Generator g = network.getGenerator("g2"); assertEquals(0.5625, g.getTargetV() / g.getTerminal().getVoltageLevel().getNominalV()); @@ -312,7 +313,7 @@ void remoteAndLocalTest() { FirstSlackBusSelector slackBusSelector = new FirstSlackBusSelector(); LfNetworkParameters parameters = new LfNetworkParameters(slackBusSelector, true, false, false, false, ParameterConstants.PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE, false, - true); + true, Collections.emptySet()); assertEquals(412, network.getGenerator("g1").getTargetV()); assertEquals(413, g2.getTargetV()); From 81288bdfc2446ee338cc964ad3a6082028456867 Mon Sep 17 00:00:00 2001 From: Bertrand Rix Date: Thu, 20 May 2021 14:48:39 +0200 Subject: [PATCH 2/8] Add a participating boolean to lfBus, controling whether the bus is participating to the computation based on its substation country. Signed-off-by: Bertrand Rix --- .../com/powsybl/openloadflow/network/LfBus.java | 2 ++ .../openloadflow/network/impl/LfBusImpl.java | 14 +++++++++++--- .../network/impl/LfDanglingLineBus.java | 5 +++++ .../network/impl/LfNetworkLoaderImpl.java | 3 +-- .../openloadflow/network/impl/LfStarBus.java | 5 +++++ .../GenerationActivePowerDistributionStep.java | 2 +- .../util/LoadActivePowerDistributionStep.java | 2 +- .../openloadflow/network/impl/LfBusImplTest.java | 2 +- 8 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/network/LfBus.java b/src/main/java/com/powsybl/openloadflow/network/LfBus.java index 0840cf5722..95077af162 100644 --- a/src/main/java/com/powsybl/openloadflow/network/LfBus.java +++ b/src/main/java/com/powsybl/openloadflow/network/LfBus.java @@ -122,4 +122,6 @@ public interface LfBus extends LfElement { void setQ(Evaluable q); Evaluable getQ(); + + boolean isParticipating(); } diff --git a/src/main/java/com/powsybl/openloadflow/network/impl/LfBusImpl.java b/src/main/java/com/powsybl/openloadflow/network/impl/LfBusImpl.java index b031499c88..da6f2b7829 100644 --- a/src/main/java/com/powsybl/openloadflow/network/impl/LfBusImpl.java +++ b/src/main/java/com/powsybl/openloadflow/network/impl/LfBusImpl.java @@ -25,17 +25,20 @@ public class LfBusImpl extends AbstractLfBus { private final double highVoltageLimit; - protected LfBusImpl(Bus bus, LfNetwork network, double v, double angle) { + private final boolean participating; + + protected LfBusImpl(Bus bus, LfNetwork network, double v, double angle, boolean participating) { super(network, v, angle); this.bus = bus; nominalV = bus.getVoltageLevel().getNominalV(); lowVoltageLimit = bus.getVoltageLevel().getLowVoltageLimit(); highVoltageLimit = bus.getVoltageLevel().getHighVoltageLimit(); + this.participating = participating; } - public static LfBusImpl create(Bus bus, LfNetwork network) { + public static LfBusImpl create(Bus bus, LfNetwork network, boolean participating) { Objects.requireNonNull(bus); - return new LfBusImpl(bus, network, bus.getV(), bus.getAngle()); + return new LfBusImpl(bus, network, bus.getV(), bus.getAngle(), participating); } @Override @@ -79,4 +82,9 @@ public void updateState(boolean reactiveLimits, boolean writeSlackBus) { super.updateState(reactiveLimits, writeSlackBus); } + + @Override + public boolean isParticipating() { + return participating; + } } diff --git a/src/main/java/com/powsybl/openloadflow/network/impl/LfDanglingLineBus.java b/src/main/java/com/powsybl/openloadflow/network/impl/LfDanglingLineBus.java index f2012dc36e..591a269033 100644 --- a/src/main/java/com/powsybl/openloadflow/network/impl/LfDanglingLineBus.java +++ b/src/main/java/com/powsybl/openloadflow/network/impl/LfDanglingLineBus.java @@ -69,4 +69,9 @@ public void updateState(boolean reactiveLimits, boolean writeSlackBus) { super.updateState(reactiveLimits, writeSlackBus); } + + @Override + public boolean isParticipating() { + return true; + } } diff --git a/src/main/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImpl.java b/src/main/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImpl.java index a2cfcc2d72..e3e20e6928 100644 --- a/src/main/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImpl.java +++ b/src/main/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImpl.java @@ -49,7 +49,6 @@ private static void createBuses(List buses, LfNetworkParameters parameters, LoadingContext loadingContext, LfNetworkLoadingReport report) { for (Bus bus : buses) { LfBusImpl lfBus = createBus(bus, parameters, lfNetwork, loadingContext, report); - lfBus.setDisabled(lfBus.isDisabled() || !participateToBalance(parameters, bus)); lfNetwork.addBus(lfBus); lfBuses.add(lfBus); } @@ -131,7 +130,7 @@ private static Bus getBus(Terminal terminal, boolean breakers) { private static LfBusImpl createBus(Bus bus, LfNetworkParameters parameters, LfNetwork lfNetwork, LoadingContext loadingContext, LfNetworkLoadingReport report) { - LfBusImpl lfBus = LfBusImpl.create(bus, lfNetwork); + LfBusImpl lfBus = LfBusImpl.create(bus, lfNetwork, participateToBalance(parameters, bus)); bus.visitConnectedEquipments(new DefaultTopologyVisitor() { diff --git a/src/main/java/com/powsybl/openloadflow/network/impl/LfStarBus.java b/src/main/java/com/powsybl/openloadflow/network/impl/LfStarBus.java index cfa965a4b5..37dc8e24ee 100644 --- a/src/main/java/com/powsybl/openloadflow/network/impl/LfStarBus.java +++ b/src/main/java/com/powsybl/openloadflow/network/impl/LfStarBus.java @@ -61,4 +61,9 @@ public void updateState(boolean reactiveLimits, boolean writeSlackBus) { super.updateState(reactiveLimits, writeSlackBus); } + + @Override + public boolean isParticipating() { + return true; + } } diff --git a/src/main/java/com/powsybl/openloadflow/network/util/GenerationActivePowerDistributionStep.java b/src/main/java/com/powsybl/openloadflow/network/util/GenerationActivePowerDistributionStep.java index 96d648d2ea..c0cd08f472 100644 --- a/src/main/java/com/powsybl/openloadflow/network/util/GenerationActivePowerDistributionStep.java +++ b/src/main/java/com/powsybl/openloadflow/network/util/GenerationActivePowerDistributionStep.java @@ -43,7 +43,7 @@ public String getElementType() { @Override public List getParticipatingElements(Collection buses) { return buses.stream() - .filter(bus -> !(bus.isDisabled() || bus.isFictitious())) + .filter(bus -> !(bus.isDisabled() || bus.isFictitious() || !bus.isParticipating())) .flatMap(bus -> bus.getGenerators().stream()) .filter(generator -> generator.isParticipating() && getParticipationFactor(generator) != 0) .map(generator -> new ParticipatingElement(generator, getParticipationFactor(generator))) diff --git a/src/main/java/com/powsybl/openloadflow/network/util/LoadActivePowerDistributionStep.java b/src/main/java/com/powsybl/openloadflow/network/util/LoadActivePowerDistributionStep.java index 7765561c95..3d937046cb 100644 --- a/src/main/java/com/powsybl/openloadflow/network/util/LoadActivePowerDistributionStep.java +++ b/src/main/java/com/powsybl/openloadflow/network/util/LoadActivePowerDistributionStep.java @@ -40,7 +40,7 @@ public String getElementType() { @Override public List getParticipatingElements(Collection buses) { return buses.stream() - .filter(bus -> bus.getPositiveLoadCount() > 0 && getVariableLoadTargetP(bus) > 0 && !(bus.isFictitious() || bus.isDisabled())) + .filter(bus -> bus.getPositiveLoadCount() > 0 && getVariableLoadTargetP(bus) > 0 && !(bus.isFictitious() || bus.isDisabled() || !bus.isParticipating())) .map(bus -> new ParticipatingElement(bus, getVariableLoadTargetP(bus))) .collect(Collectors.toList()); } diff --git a/src/test/java/com/powsybl/openloadflow/network/impl/LfBusImplTest.java b/src/test/java/com/powsybl/openloadflow/network/impl/LfBusImplTest.java index 5e2a5be9b0..88a1172dc7 100644 --- a/src/test/java/com/powsybl/openloadflow/network/impl/LfBusImplTest.java +++ b/src/test/java/com/powsybl/openloadflow/network/impl/LfBusImplTest.java @@ -129,7 +129,7 @@ void updateGeneratorsStateTest() { List networks = LfNetwork.load(EurostagTutorialExample1Factory.create(), new MostMeshedSlackBusSelector()); LfNetwork mainNetwork = networks.get(0); - LfBusImpl lfBus = new LfBusImpl(bus1, mainNetwork, 385, 0); + LfBusImpl lfBus = new LfBusImpl(bus1, mainNetwork, 385, 0, true); LfNetworkLoadingReport lfNetworkLoadingReport = new LfNetworkLoadingReport(); lfBus.addStaticVarCompensator(svc1, true, lfNetworkLoadingReport); lfBus.addStaticVarCompensator(svc2, true, lfNetworkLoadingReport); From fe9a81a144f5bf88eb538698357b45a69d44c67f Mon Sep 17 00:00:00 2001 From: Bertrand Rix Date: Thu, 20 May 2021 14:57:52 +0200 Subject: [PATCH 3/8] Hardcode participating to false for DanglingLineBuse and StarBus. Also update debug-parameters.json Signed-off-by: Bertrand Rix --- .../powsybl/openloadflow/network/impl/LfDanglingLineBus.java | 2 +- .../java/com/powsybl/openloadflow/network/impl/LfStarBus.java | 2 +- src/test/resources/debug-parameters.json | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/network/impl/LfDanglingLineBus.java b/src/main/java/com/powsybl/openloadflow/network/impl/LfDanglingLineBus.java index 591a269033..dae9ee0754 100644 --- a/src/main/java/com/powsybl/openloadflow/network/impl/LfDanglingLineBus.java +++ b/src/main/java/com/powsybl/openloadflow/network/impl/LfDanglingLineBus.java @@ -72,6 +72,6 @@ public void updateState(boolean reactiveLimits, boolean writeSlackBus) { @Override public boolean isParticipating() { - return true; + return false; } } diff --git a/src/main/java/com/powsybl/openloadflow/network/impl/LfStarBus.java b/src/main/java/com/powsybl/openloadflow/network/impl/LfStarBus.java index 37dc8e24ee..d99d30c2c8 100644 --- a/src/main/java/com/powsybl/openloadflow/network/impl/LfStarBus.java +++ b/src/main/java/com/powsybl/openloadflow/network/impl/LfStarBus.java @@ -64,6 +64,6 @@ public void updateState(boolean reactiveLimits, boolean writeSlackBus) { @Override public boolean isParticipating() { - return true; + return false; } } diff --git a/src/test/resources/debug-parameters.json b/src/test/resources/debug-parameters.json index 3ec71e4abd..93a4f2a36f 100644 --- a/src/test/resources/debug-parameters.json +++ b/src/test/resources/debug-parameters.json @@ -23,7 +23,6 @@ "throwsExceptionInCaseOfSlackDistributionFailure" : false, "lowImpedanceBranchMode" : "REPLACE_BY_ZERO_IMPEDANCE_LINE", "loadPowerFactorConstant" : false, - "dcUseTransformerRatio" : true, "plausibleActivePowerLimit" : 10000.0, "addRatioToLinesWithDifferentNominalVoltageAtBothEnds" : false, "slackBusPMaxMismatch" : 1.0 From e7f678d60135a2c1e9ccd8539374bd8fd4bd23bf Mon Sep 17 00:00:00 2001 From: Bertrand Rix Date: Thu, 20 May 2021 15:26:16 +0200 Subject: [PATCH 4/8] Add a test disabling substation in some countries for computations. Signed-off-by: Bertrand Rix --- .../ac/DistributedSlackOnGenerationTest.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/powsybl/openloadflow/ac/DistributedSlackOnGenerationTest.java b/src/test/java/com/powsybl/openloadflow/ac/DistributedSlackOnGenerationTest.java index 7504f962b6..299f9ba4c4 100644 --- a/src/test/java/com/powsybl/openloadflow/ac/DistributedSlackOnGenerationTest.java +++ b/src/test/java/com/powsybl/openloadflow/ac/DistributedSlackOnGenerationTest.java @@ -6,9 +6,7 @@ */ package com.powsybl.openloadflow.ac; -import com.powsybl.iidm.network.Generator; -import com.powsybl.iidm.network.Line; -import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.ActivePowerControl; import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; import com.powsybl.loadflow.LoadFlow; @@ -22,6 +20,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.EnumSet; import java.util.concurrent.CompletionException; import static com.powsybl.openloadflow.util.LoadFlowAssert.assertActivePowerEquals; @@ -155,4 +154,24 @@ void generatorWithMaxPEqualsToMinP() { assertThrows(CompletionException.class, () -> loadFlowRunner.run(network, parameters), "Failed to distribute slack bus active power mismatch, -1.4404045651214226 MW remains"); } + + @Test + void nonParticipatingBus() { + + //B1 and B2 are located in germany the rest is in france + Substation b1s = network.getSubstation("b1_s"); + b1s.setCountry(Country.GE); + Substation b2s = network.getSubstation("b2_s"); + b2s.setCountry(Country.GE); + + //Only substation located in france are used + parameters.setCountriesToBalance(EnumSet.of(Country.FR)); + LoadFlowResult result = loadFlowRunner.run(network, parameters); + + assertTrue(result.isOk()); + assertActivePowerEquals(-100, g1.getTerminal()); + assertActivePowerEquals(-200, g2.getTerminal()); + assertActivePowerEquals(-150, g3.getTerminal()); + assertActivePowerEquals(-150, g4.getTerminal()); + } } From 8696e03180b5aefb1c014ad492200b719a78e73d Mon Sep 17 00:00:00 2001 From: Bertrand Rix Date: Thu, 20 May 2021 17:38:59 +0200 Subject: [PATCH 5/8] Rename participateToBalance to participateToSlackDistribution. Signed-off-by: Bertrand Rix --- .../openloadflow/network/impl/LfNetworkLoaderImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImpl.java b/src/main/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImpl.java index e3e20e6928..b8247982bd 100644 --- a/src/main/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImpl.java +++ b/src/main/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImpl.java @@ -130,7 +130,7 @@ private static Bus getBus(Terminal terminal, boolean breakers) { private static LfBusImpl createBus(Bus bus, LfNetworkParameters parameters, LfNetwork lfNetwork, LoadingContext loadingContext, LfNetworkLoadingReport report) { - LfBusImpl lfBus = LfBusImpl.create(bus, lfNetwork, participateToBalance(parameters, bus)); + LfBusImpl lfBus = LfBusImpl.create(bus, lfNetwork, participateToSlackDistribution(parameters, bus)); bus.visitConnectedEquipments(new DefaultTopologyVisitor() { @@ -567,7 +567,7 @@ public Optional> load(Object network, LfNetworkParameters parame return Optional.empty(); } - static boolean participateToBalance(LfNetworkParameters parameters, Bus b) { + static boolean participateToSlackDistribution(LfNetworkParameters parameters, Bus b) { return parameters.getCountriesToBalance().isEmpty() || b.getVoltageLevel().getSubstation().getCountry() .map(country -> parameters.getCountriesToBalance().contains(country)) From bb52525e602d0e0efbcd6d5c7e9dfc623dc93330 Mon Sep 17 00:00:00 2001 From: Bertrand Rix Date: Fri, 21 May 2021 09:24:37 +0200 Subject: [PATCH 6/8] Modifications after review. Signed-off-by: Bertrand Rix --- .../openloadflow/OpenLoadFlowProvider.java | 5 +++-- .../ac/outerloop/AcLoadFlowParameters.java | 3 ++- .../openloadflow/dc/DcLoadFlowEngine.java | 6 +++--- .../openloadflow/dc/DcLoadFlowParameters.java | 17 ++++++++++++++--- .../network/LfNetworkParameters.java | 2 +- .../sensi/DcSensitivityAnalysis.java | 2 +- 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java b/src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java index 4f21cb252e..9a8c064102 100644 --- a/src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java +++ b/src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java @@ -265,9 +265,10 @@ private LoadFlowResult runDc(Network network, LoadFlowParameters parameters, Ope parametersExt.getPlausibleActivePowerLimit(), parametersExt.isAddRatioToLinesWithDifferentNominalVoltageAtBothEnds(), true, - parameters.getConnectedComponentMode() == LoadFlowParameters.ConnectedComponentMode.MAIN); + parameters.getConnectedComponentMode() == LoadFlowParameters.ConnectedComponentMode.MAIN, + parameters.getCountriesToBalance()); - List results = new DcLoadFlowEngine(network, dcParameters, reporter, parameters.getCountriesToBalance()) + List results = new DcLoadFlowEngine(network, dcParameters, reporter) .run(reporter); Networks.resetState(network); diff --git a/src/main/java/com/powsybl/openloadflow/ac/outerloop/AcLoadFlowParameters.java b/src/main/java/com/powsybl/openloadflow/ac/outerloop/AcLoadFlowParameters.java index 8c75d60bdf..d32161c43a 100644 --- a/src/main/java/com/powsybl/openloadflow/ac/outerloop/AcLoadFlowParameters.java +++ b/src/main/java/com/powsybl/openloadflow/ac/outerloop/AcLoadFlowParameters.java @@ -12,6 +12,7 @@ import com.powsybl.openloadflow.equations.VoltageInitializer; import com.powsybl.openloadflow.network.SlackBusSelector; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Set; @@ -151,7 +152,7 @@ public boolean isComputeMainConnectedComponentOnly() { } public Set getCountriesToBalance() { - return countriesToBalance; + return Collections.unmodifiableSet(countriesToBalance); } } diff --git a/src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowEngine.java b/src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowEngine.java index ff147df367..070279f49f 100644 --- a/src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowEngine.java +++ b/src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowEngine.java @@ -40,12 +40,12 @@ public class DcLoadFlowEngine { public DcLoadFlowEngine(LfNetwork network, MatrixFactory matrixFactory, boolean setVToNan) { this.networks = Collections.singletonList(network); - parameters = new DcLoadFlowParameters(new FirstSlackBusSelector(), matrixFactory, setVToNan); + parameters = new DcLoadFlowParameters(new FirstSlackBusSelector(), matrixFactory, setVToNan, EnumSet.noneOf(Country.class)); } - public DcLoadFlowEngine(Object network, DcLoadFlowParameters parameters, Reporter reporter, Set countriesToBalance) { + public DcLoadFlowEngine(Object network, DcLoadFlowParameters parameters, Reporter reporter) { LfNetworkParameters lfNetworkParameters = new LfNetworkParameters(parameters.getSlackBusSelector(), false, false, false, false, - parameters.getPlausibleActivePowerLimit(), false, parameters.isComputeMainConnectedComponentOnly(), countriesToBalance); + parameters.getPlausibleActivePowerLimit(), false, parameters.isComputeMainConnectedComponentOnly(), parameters.getCountriesToBalance()); this.networks = LfNetwork.load(network, lfNetworkParameters, reporter); this.parameters = Objects.requireNonNull(parameters); } diff --git a/src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowParameters.java b/src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowParameters.java index d2bb90743e..955ae11862 100644 --- a/src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowParameters.java +++ b/src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowParameters.java @@ -6,12 +6,15 @@ */ package com.powsybl.openloadflow.dc; +import com.powsybl.iidm.network.Country; import com.powsybl.loadflow.LoadFlowParameters; import com.powsybl.math.matrix.MatrixFactory; import com.powsybl.openloadflow.network.SlackBusSelector; import com.powsybl.openloadflow.util.ParameterConstants; +import java.util.Collections; import java.util.Objects; +import java.util.Set; /** * @author Geoffroy Jamgotchian @@ -40,15 +43,18 @@ public class DcLoadFlowParameters { private final boolean computeMainConnectedComponentOnly; - public DcLoadFlowParameters(SlackBusSelector slackBusSelector, MatrixFactory matrixFactory, boolean setVToNan) { + private final Set countriesToBalance; + + public DcLoadFlowParameters(SlackBusSelector slackBusSelector, MatrixFactory matrixFactory, boolean setVToNan, Set countriesToBalance) { this(slackBusSelector, matrixFactory, false, true, false, LoadFlowParameters.BalanceType.PROPORTIONAL_TO_GENERATION_P_MAX, false, - ParameterConstants.PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE, false, setVToNan, true); + ParameterConstants.PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE, false, setVToNan, true, countriesToBalance); } public DcLoadFlowParameters(SlackBusSelector slackBusSelector, MatrixFactory matrixFactory, boolean updateFlows, boolean useTransformerRatio, boolean distributedSlack, LoadFlowParameters.BalanceType balanceType, boolean forcePhaseControlOffAndAddAngle1Var, double plausibleActivePowerLimit, - boolean addRatioToLinesWithDifferentNominalVoltageAtBothEnds, boolean setVToNan, boolean computeMainConnectedComponentOnly) { + boolean addRatioToLinesWithDifferentNominalVoltageAtBothEnds, boolean setVToNan, boolean computeMainConnectedComponentOnly, + Set countriesToBalance) { this.slackBusSelector = Objects.requireNonNull(slackBusSelector); this.matrixFactory = Objects.requireNonNull(matrixFactory); this.updateFlows = updateFlows; @@ -60,6 +66,7 @@ public DcLoadFlowParameters(SlackBusSelector slackBusSelector, MatrixFactory mat this.addRatioToLinesWithDifferentNominalVoltageAtBothEnds = addRatioToLinesWithDifferentNominalVoltageAtBothEnds; this.setVToNan = setVToNan; this.computeMainConnectedComponentOnly = computeMainConnectedComponentOnly; + this.countriesToBalance = countriesToBalance; } public SlackBusSelector getSlackBusSelector() { @@ -106,4 +113,8 @@ public boolean isComputeMainConnectedComponentOnly() { return computeMainConnectedComponentOnly; } + public Set getCountriesToBalance() { + return Collections.unmodifiableSet(countriesToBalance); + } + } diff --git a/src/main/java/com/powsybl/openloadflow/network/LfNetworkParameters.java b/src/main/java/com/powsybl/openloadflow/network/LfNetworkParameters.java index fef5eac316..381b71f19c 100644 --- a/src/main/java/com/powsybl/openloadflow/network/LfNetworkParameters.java +++ b/src/main/java/com/powsybl/openloadflow/network/LfNetworkParameters.java @@ -89,6 +89,6 @@ public boolean isComputeMainConnectedComponentOnly() { } public Set getCountriesToBalance() { - return countriesToBalance; + return Collections.unmodifiableSet(countriesToBalance); } } diff --git a/src/main/java/com/powsybl/openloadflow/sensi/DcSensitivityAnalysis.java b/src/main/java/com/powsybl/openloadflow/sensi/DcSensitivityAnalysis.java index 86c28b3c8f..da576fa768 100644 --- a/src/main/java/com/powsybl/openloadflow/sensi/DcSensitivityAnalysis.java +++ b/src/main/java/com/powsybl/openloadflow/sensi/DcSensitivityAnalysis.java @@ -623,7 +623,7 @@ public void analyse(Network network, List contingencies, // create DC load flow engine for setting the function reference DcLoadFlowParameters dcLoadFlowParameters = new DcLoadFlowParameters(slackBusSelector, matrixFactory, true, lfParameters.isDcUseTransformerRatio(), lfParameters.isDistributedSlack(), lfParameters.getBalanceType(), true, - lfParametersExt.getPlausibleActivePowerLimit(), lfParametersExt.isAddRatioToLinesWithDifferentNominalVoltageAtBothEnds(), true, true); + lfParametersExt.getPlausibleActivePowerLimit(), lfParametersExt.isAddRatioToLinesWithDifferentNominalVoltageAtBothEnds(), true, true, lfParameters.getCountriesToBalance()); DcLoadFlowEngine dcLoadFlowEngine = new DcLoadFlowEngine(lfNetworks, dcLoadFlowParameters); // create DC equation system for sensitivity analysis From 47fbd5a645c8f5a48feba5a573fb91ab21e01b55 Mon Sep 17 00:00:00 2001 From: Bertrand Rix Date: Fri, 21 May 2021 09:42:16 +0200 Subject: [PATCH 7/8] Simplify again Dc engin constructor. Signed-off-by: Bertrand Rix --- .../java/com/powsybl/openloadflow/dc/DcLoadFlowEngine.java | 3 +-- .../com/powsybl/openloadflow/dc/DcLoadFlowParameters.java | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowEngine.java b/src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowEngine.java index 070279f49f..a79947f90e 100644 --- a/src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowEngine.java +++ b/src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowEngine.java @@ -8,7 +8,6 @@ import com.powsybl.commons.reporter.Report; import com.powsybl.commons.reporter.Reporter; -import com.powsybl.iidm.network.Country; import com.powsybl.loadflow.LoadFlowResult; import com.powsybl.math.matrix.MatrixFactory; import com.powsybl.openloadflow.OpenLoadFlowReportConstants; @@ -40,7 +39,7 @@ public class DcLoadFlowEngine { public DcLoadFlowEngine(LfNetwork network, MatrixFactory matrixFactory, boolean setVToNan) { this.networks = Collections.singletonList(network); - parameters = new DcLoadFlowParameters(new FirstSlackBusSelector(), matrixFactory, setVToNan, EnumSet.noneOf(Country.class)); + parameters = new DcLoadFlowParameters(new FirstSlackBusSelector(), matrixFactory, setVToNan); } public DcLoadFlowEngine(Object network, DcLoadFlowParameters parameters, Reporter reporter) { diff --git a/src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowParameters.java b/src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowParameters.java index 955ae11862..44daaafd07 100644 --- a/src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowParameters.java +++ b/src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowParameters.java @@ -45,9 +45,9 @@ public class DcLoadFlowParameters { private final Set countriesToBalance; - public DcLoadFlowParameters(SlackBusSelector slackBusSelector, MatrixFactory matrixFactory, boolean setVToNan, Set countriesToBalance) { + public DcLoadFlowParameters(SlackBusSelector slackBusSelector, MatrixFactory matrixFactory, boolean setVToNan) { this(slackBusSelector, matrixFactory, false, true, false, LoadFlowParameters.BalanceType.PROPORTIONAL_TO_GENERATION_P_MAX, false, - ParameterConstants.PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE, false, setVToNan, true, countriesToBalance); + ParameterConstants.PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE, false, setVToNan, true, LoadFlowParameters.DEFAULT_COUNTRIES_TO_BALANCE); } public DcLoadFlowParameters(SlackBusSelector slackBusSelector, MatrixFactory matrixFactory, boolean updateFlows, From 9f0ef8686d602e64398306086bee6caece5c40c4 Mon Sep 17 00:00:00 2001 From: Bertrand Rix Date: Fri, 21 May 2021 12:24:50 +0200 Subject: [PATCH 8/8] Change boolean algebra. Signed-off-by: Bertrand Rix --- .../network/util/GenerationActivePowerDistributionStep.java | 2 +- .../network/util/LoadActivePowerDistributionStep.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/network/util/GenerationActivePowerDistributionStep.java b/src/main/java/com/powsybl/openloadflow/network/util/GenerationActivePowerDistributionStep.java index c0cd08f472..badf6851c0 100644 --- a/src/main/java/com/powsybl/openloadflow/network/util/GenerationActivePowerDistributionStep.java +++ b/src/main/java/com/powsybl/openloadflow/network/util/GenerationActivePowerDistributionStep.java @@ -43,7 +43,7 @@ public String getElementType() { @Override public List getParticipatingElements(Collection buses) { return buses.stream() - .filter(bus -> !(bus.isDisabled() || bus.isFictitious() || !bus.isParticipating())) + .filter(bus -> bus.isParticipating() && !bus.isDisabled() && !bus.isFictitious()) .flatMap(bus -> bus.getGenerators().stream()) .filter(generator -> generator.isParticipating() && getParticipationFactor(generator) != 0) .map(generator -> new ParticipatingElement(generator, getParticipationFactor(generator))) diff --git a/src/main/java/com/powsybl/openloadflow/network/util/LoadActivePowerDistributionStep.java b/src/main/java/com/powsybl/openloadflow/network/util/LoadActivePowerDistributionStep.java index 3d937046cb..65f345b895 100644 --- a/src/main/java/com/powsybl/openloadflow/network/util/LoadActivePowerDistributionStep.java +++ b/src/main/java/com/powsybl/openloadflow/network/util/LoadActivePowerDistributionStep.java @@ -40,7 +40,7 @@ public String getElementType() { @Override public List getParticipatingElements(Collection buses) { return buses.stream() - .filter(bus -> bus.getPositiveLoadCount() > 0 && getVariableLoadTargetP(bus) > 0 && !(bus.isFictitious() || bus.isDisabled() || !bus.isParticipating())) + .filter(bus -> bus.getPositiveLoadCount() > 0 && getVariableLoadTargetP(bus) > 0 && bus.isParticipating() && !bus.isDisabled() && !bus.isFictitious()) .map(bus -> new ParticipatingElement(bus, getVariableLoadTargetP(bus))) .collect(Collectors.toList()); }