Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve parameters management #187

Merged
merged 7 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/main/java/com/powsybl/openloadflow/OpenLoadFlowParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class OpenLoadFlowParameters extends AbstractExtension<LoadFlowParameters

private boolean throwsExceptionInCaseOfSlackDistributionFailure = THROWS_EXCEPTION_IN_CASE_OF_SLACK_DISTRIBUTION_FAILURE_DEFAULT_VALUE;

private boolean voltageRemoteControl = VOLTAGE_REMOTE_CONTROLE_DEFAULT_VALUE;
private boolean voltageRemoteControl = VOLTAGE_REMOTE_CONTROL_DEFAULT_VALUE;

private LowImpedanceBranchMode lowImpedanceBranchMode = LOW_IMPEDANCE_BRANCH_MODE_DEFAULT_VALUE;

Expand All @@ -46,6 +46,8 @@ public enum LowImpedanceBranchMode {

private boolean dcUseTransformerRatio = DC_USE_TRANSFORMER_RATIO_DEFAULT_VALUE;

private boolean updateFlows = UPDATE_FLOWS_DEFAULT_VALUE;

@Override
public String getName() {
return "OpenLoadFlowParameters";
Expand Down Expand Up @@ -109,6 +111,15 @@ public OpenLoadFlowParameters setDcUseTransformerRatio(boolean dcUseTransformerR
return this;
}

public boolean isUpdateFlows() {
annetill marked this conversation as resolved.
Show resolved Hide resolved
return updateFlows;
}

public OpenLoadFlowParameters setUpdateFlows(boolean updateFlows) {
this.updateFlows = updateFlows;
return this;
}

public static OpenLoadFlowParameters load() {
return new OpenLoadFlowConfigLoader().load(PlatformConfig.defaultConfig());
}
Expand All @@ -124,12 +135,13 @@ public OpenLoadFlowParameters load(PlatformConfig platformConfig) {
.ifPresent(config -> parameters
.setSlackBusSelector(getSlackBusSelector(config))
.setLowImpedanceBranchMode(config.getEnumProperty(LOW_IMPEDANCE_BRANCH_MODE_PARAM_NAME, LowImpedanceBranchMode.class, LOW_IMPEDANCE_BRANCH_MODE_DEFAULT_VALUE))
.setVoltageRemoteControl(config.getBooleanProperty(VOLTAGE_REMOTE_CONTROLE_PARAM_NAME, VOLTAGE_REMOTE_CONTROLE_DEFAULT_VALUE))
.setVoltageRemoteControl(config.getBooleanProperty(VOLTAGE_REMOTE_CONTROL_PARAM_NAME, VOLTAGE_REMOTE_CONTROL_DEFAULT_VALUE))
.setThrowsExceptionInCaseOfSlackDistributionFailure(
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))
.setUpdateFlows(config.getBooleanProperty(UPDATE_FLOWS_PARAM_NAME, UPDATE_FLOWS_DEFAULT_VALUE))
);
return parameters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private static ImmutableMap<String, String> createMetrics(AcLoadFlowResult resul
prefix + "status", result.getNewtonRaphsonStatus().name());
}

private static VoltageInitializer getVoltageInitializer(LoadFlowParameters parameters) {
public static VoltageInitializer getVoltageInitializer(LoadFlowParameters parameters) {
switch (parameters.getVoltageInitMode()) {
case UNIFORM_VALUES:
return new UniformValueVoltageInitializer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.powsybl.iidm.network.Bus;
import com.powsybl.iidm.network.Injection;
import com.powsybl.iidm.network.Network;
import com.powsybl.loadflow.LoadFlowParameters;
import com.powsybl.math.matrix.DenseMatrix;
import com.powsybl.math.matrix.MatrixFactory;
import com.powsybl.openloadflow.OpenLoadFlowParameters;
Expand All @@ -29,6 +30,8 @@
import java.util.Objects;
import java.util.stream.Collectors;

import static com.powsybl.openloadflow.OpenLoadFlowProvider.getVoltageInitializer;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
Expand Down Expand Up @@ -135,9 +138,11 @@ private List<SensitivityValue> calculateSensitivityValues(Network network, List<
/**
* https://people.montefiore.uliege.be/vct/elec0029/lf.pdf
*/
public List<SensitivityValue> analyse(Network network, List<SensitivityFactor> factors, OpenLoadFlowParameters lfParametersExt) {
public List<SensitivityValue> analyse(Network network, List<SensitivityFactor> factors, LoadFlowParameters lfParameters,
OpenLoadFlowParameters lfParametersExt) {
Objects.requireNonNull(network);
Objects.requireNonNull(factors);
Objects.requireNonNull(lfParameters);
Objects.requireNonNull(lfParametersExt);

// create LF network (we only manage main connected component)
Expand All @@ -151,7 +156,8 @@ public List<SensitivityValue> analyse(Network network, List<SensitivityFactor> f
EquationSystem equationSystem = AcEquationSystem.create(lfNetwork, new VariableSet());

// create jacobian matrix from current network state
PreviousValueVoltageInitializer voltageInitializer = new PreviousValueVoltageInitializer();
VoltageInitializer voltageInitializer = getVoltageInitializer(lfParameters);

JacobianMatrix j = createJacobianMatrix(equationSystem, voltageInitializer);

// initialize right hand side from valid factors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,10 @@ private Map<String, Double> getParticipationFactorByBus(LfNetwork lfNetwork, Loa
return participationFactorByBusMap;
}

public List<SensitivityValue> analyse(Network network, List<SensitivityFactor> factors, LoadFlowParameters lfParameters, OpenLoadFlowParameters lfParametersExt,
OpenSensitivityAnalysisParameters sensiParametersExt) {
public List<SensitivityValue> analyse(Network network, List<SensitivityFactor> factors, LoadFlowParameters lfParameters, OpenLoadFlowParameters lfParametersExt) {
Objects.requireNonNull(network);
Objects.requireNonNull(factors);
Objects.requireNonNull(lfParametersExt);
Objects.requireNonNull(sensiParametersExt);

// create LF network (we only manage main connected component)
List<LfNetwork> lfNetworks = LfNetwork.load(network, lfParametersExt.getSlackBusSelector());
Expand Down Expand Up @@ -292,7 +290,7 @@ public List<SensitivityValue> analyse(Network network, List<SensitivityFactor> f
DenseMatrix rhs = initRhs(lfNetwork, equationSystem, factorsByVarConfig);

// create jacobian matrix either using base network calculated voltages or nominal voltages
VoltageInitializer voltageInitializer = sensiParametersExt.isUseBaseCaseVoltage() ? new PreviousValueVoltageInitializer()
VoltageInitializer voltageInitializer = lfParameters.getVoltageInitMode() == LoadFlowParameters.VoltageInitMode.PREVIOUS_VALUES ? new PreviousValueVoltageInitializer()
: new UniformValueVoltageInitializer();
JacobianMatrix j = createJacobianMatrix(equationSystem, voltageInitializer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@
*/
public class OpenSensitivityAnalysisParameters extends AbstractExtension<SensitivityAnalysisParameters> {

private static final boolean DEFAULT_USE_BASE_CASE_VOLTAGE = true;

private boolean useBaseCaseVoltage = DEFAULT_USE_BASE_CASE_VOLTAGE;

public boolean isUseBaseCaseVoltage() {
return useBaseCaseVoltage;
}

public OpenSensitivityAnalysisParameters setUseBaseCaseVoltage(boolean useBaseCaseVoltage) {
this.useBaseCaseVoltage = useBaseCaseVoltage;
return this;
}

@Override
public String getName() {
return "OpenSensitivityAnalysisParameters";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public CompletableFuture<SensitivityAnalysisResult> run(Network network, String

List<SensitivityValue> sensitivityValues;
if (lfParameters.isDc()) {
sensitivityValues = dcSensitivityAnalysis.analyse(network, factors, lfParameters, lfParametersExt, sensiParametersExt);
sensitivityValues = dcSensitivityAnalysis.analyse(network, factors, lfParameters, lfParametersExt);
} else {
sensitivityValues = acSensitivityAnalysis.analyse(network, factors, lfParametersExt);
sensitivityValues = acSensitivityAnalysis.analyse(network, factors, lfParameters, lfParametersExt);
}

boolean ok = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public final class ParameterConstants {
public static final String THROWS_EXCEPTION_IN_CASE_OF_SLACK_DISTRIBUTION_FAILURE_PARAM_NAME = "throwsExceptionInCaseOfSlackDistributionFailure";
public static final boolean THROWS_EXCEPTION_IN_CASE_OF_SLACK_DISTRIBUTION_FAILURE_DEFAULT_VALUE = true;

public static final String VOLTAGE_REMOTE_CONTROLE_PARAM_NAME = "voltageRemoteControl";
public static final boolean VOLTAGE_REMOTE_CONTROLE_DEFAULT_VALUE = false;
public static final String VOLTAGE_REMOTE_CONTROL_PARAM_NAME = "voltageRemoteControl";
public static final boolean VOLTAGE_REMOTE_CONTROL_DEFAULT_VALUE = true;

public static final String LOW_IMPEDANCE_BRANCH_MODE_PARAM_NAME = "lowImpedanceBranchMode";
public static final LowImpedanceBranchMode LOW_IMPEDANCE_BRANCH_MODE_DEFAULT_VALUE = LowImpedanceBranchMode.REPLACE_BY_ZERO_IMPEDANCE_LINE;
Expand All @@ -32,7 +32,10 @@ public final class ParameterConstants {
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 = false;
public static final boolean DC_USE_TRANSFORMER_RATIO_DEFAULT_VALUE = true;

public static final String UPDATE_FLOWS_PARAM_NAME = "updateFlows";
Copy link
Member

@geofjamg geofjamg Dec 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used anymore?

public static final boolean UPDATE_FLOWS_DEFAULT_VALUE = true;

private ParameterConstants() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void testConfig() {
assertTrue(olfParameters.getSlackBusSelector() instanceof FirstSlackBusSelector);

assertTrue(olfParameters.isThrowsExceptionInCaseOfSlackDistributionFailure());
assertFalse(olfParameters.hasVoltageRemoteControl());
assertTrue(olfParameters.hasVoltageRemoteControl());
assertEquals(LOW_IMPEDANCE_BRANCH_MODE_DEFAULT_VALUE, olfParameters.getLowImpedanceBranchMode());
}

Expand All @@ -96,9 +96,12 @@ void testDefaultOpenLoadflowConfig() {

OpenLoadFlowParameters olfParameters = parameters.getExtension(OpenLoadFlowParameters.class);
assertEquals(SLACK_BUS_SELECTOR_DEFAULT_VALUE, olfParameters.getSlackBusSelector());
assertEquals(VOLTAGE_REMOTE_CONTROLE_DEFAULT_VALUE, olfParameters.hasVoltageRemoteControl());
assertEquals(VOLTAGE_REMOTE_CONTROL_DEFAULT_VALUE, olfParameters.hasVoltageRemoteControl());
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(UPDATE_FLOWS_DEFAULT_VALUE, olfParameters.isUpdateFlows());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

import com.powsybl.iidm.network.*;
import com.powsybl.loadflow.LoadFlow;
import com.powsybl.loadflow.LoadFlowParameters;
import com.powsybl.loadflow.LoadFlowResult;
import com.powsybl.math.matrix.DenseMatrixFactory;
import com.powsybl.openloadflow.OpenLoadFlowParameters;
import com.powsybl.openloadflow.OpenLoadFlowProvider;
import com.powsybl.openloadflow.util.LoadFlowAssert;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -26,6 +28,7 @@ class GeneratorRemoteControlLocalRescaleTest {
private Bus b1;
private Bus b2;
private LoadFlow.Runner loadFlowRunner;
private LoadFlowParameters parameters;

@BeforeEach
void setUp() {
Expand Down Expand Up @@ -86,11 +89,15 @@ void setUp() {
.add();

loadFlowRunner = new LoadFlow.Runner(new OpenLoadFlowProvider(new DenseMatrixFactory()));
parameters = new LoadFlowParameters();
OpenLoadFlowParameters parametersExt = new OpenLoadFlowParameters()
.setVoltageRemoteControl(false);
this.parameters.addExtension(OpenLoadFlowParameters.class, parametersExt);
}

@Test
void test() {
LoadFlowResult result = loadFlowRunner.run(network);
LoadFlowResult result = loadFlowRunner.run(network, parameters);
assertTrue(result.isOk());
LoadFlowAssert.assertVoltageEquals(20.67, b1); // check local targetV has been correctly rescaled
LoadFlowAssert.assertVoltageEquals(395.927, b2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.VariantManagerConstants;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.loadflow.LoadFlowParameters;
import com.powsybl.openloadflow.util.LoadFlowAssert;
import com.powsybl.sensitivity.SensitivityAnalysisParameters;
import com.powsybl.sensitivity.SensitivityAnalysisResult;
Expand All @@ -32,6 +33,7 @@ void testEsgTuto() {
runAcLf(network);

SensitivityAnalysisParameters sensiParameters = createParameters(false, "VLLOAD_0");
sensiParameters.getLoadFlowParameters().setVoltageInitMode(LoadFlowParameters.VoltageInitMode.PREVIOUS_VALUES);
SensitivityFactorsProvider factorsProvider = n -> createFactorMatrix(network.getGeneratorStream().collect(Collectors.toList()),
network.getLineStream().collect(Collectors.toList()));
SensitivityAnalysisResult result = sensiProvider.run(network, VariantManagerConstants.INITIAL_VARIANT_ID, factorsProvider, new EmptyContingencyListProvider(),
Expand Down