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

Refactor parameters #361

Merged
merged 8 commits into from
Oct 2, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
98 changes: 62 additions & 36 deletions src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@
import com.powsybl.math.matrix.MatrixFactory;
import com.powsybl.math.matrix.SparseMatrixFactory;
import com.powsybl.openloadflow.ac.DefaultOuterLoopConfig;
import com.powsybl.openloadflow.ac.equations.AcEquationSystemCreationParameters;
import com.powsybl.openloadflow.ac.nr.DcValueVoltageInitializer;
import com.powsybl.openloadflow.ac.nr.DefaultNewtonRaphsonStoppingCriteria;
import com.powsybl.openloadflow.ac.nr.NewtonRaphsonParameters;
import com.powsybl.openloadflow.ac.nr.NewtonRaphsonStatus;
import com.powsybl.openloadflow.ac.nr.NewtonRaphsonStoppingCriteria;
import com.powsybl.openloadflow.ac.outerloop.*;
import com.powsybl.openloadflow.dc.DcLoadFlowEngine;
import com.powsybl.openloadflow.dc.DcLoadFlowParameters;
import com.powsybl.openloadflow.dc.DcLoadFlowResult;
import com.powsybl.openloadflow.dc.equations.DcEquationSystemCreationParameters;
import com.powsybl.openloadflow.equations.PreviousValueVoltageInitializer;
import com.powsybl.openloadflow.equations.UniformValueVoltageInitializer;
import com.powsybl.openloadflow.equations.VoltageInitializer;
import com.powsybl.openloadflow.network.LfNetworkParameters;
import com.powsybl.openloadflow.network.NetworkSlackBusSelector;
import com.powsybl.openloadflow.network.PerUnit;
import com.powsybl.openloadflow.network.SlackBusSelector;
Expand Down Expand Up @@ -142,8 +144,6 @@ public static AcLoadFlowParameters createAcParameters(Network network, MatrixFac

VoltageInitializer voltageInitializer = getVoltageInitializer(parameters);

NewtonRaphsonStoppingCriteria stoppingCriteria = new DefaultNewtonRaphsonStoppingCriteria();

LOGGER.info("Slack bus selector: {}", slackBusSelector.getClass().getSimpleName());
LOGGER.info("Voltage level initializer: {}", voltageInitializer.getClass().getSimpleName());
LOGGER.info("Distributed slack: {}", parameters.isDistributedSlack());
Expand All @@ -168,25 +168,30 @@ public static AcLoadFlowParameters createAcParameters(Network network, MatrixFac
LOGGER.info("Outer loops: {}", outerLoops.stream().map(OuterLoop::getType).collect(Collectors.toList()));
}

return new AcLoadFlowParameters(slackBusSelector,
voltageInitializer,
stoppingCriteria,
outerLoops, matrixFactory,
parametersExt.hasVoltageRemoteControl(),
parameters.isPhaseShifterRegulationOn(),
parameters.isTransformerVoltageControlOn(),
parametersExt.getLowImpedanceBranchMode() == OpenLoadFlowParameters.LowImpedanceBranchMode.REPLACE_BY_MIN_IMPEDANCE_LINE,
parameters.isTwtSplitShuntAdmittance(),
breakers,
parametersExt.getPlausibleActivePowerLimit(),
forceA1Var,
parametersExt.isAddRatioToLinesWithDifferentNominalVoltageAtBothEnds(),
branchesWithCurrent,
parameters.getConnectedComponentMode() == LoadFlowParameters.ConnectedComponentMode.MAIN,
parameters.getCountriesToBalance(),
parameters.isDistributedSlack() && parameters.getBalanceType() == LoadFlowParameters.BalanceType.PROPORTIONAL_TO_CONFORM_LOAD,
parametersExt.isVoltagePerReactivePowerControl(),
parametersExt.hasReactivePowerRemoteControl());
var networkParameters = new LfNetworkParameters(slackBusSelector,
parametersExt.hasVoltageRemoteControl(),
parametersExt.getLowImpedanceBranchMode() == OpenLoadFlowParameters.LowImpedanceBranchMode.REPLACE_BY_MIN_IMPEDANCE_LINE,
parameters.isTwtSplitShuntAdmittance(),
breakers,
parametersExt.getPlausibleActivePowerLimit(),
parametersExt.isAddRatioToLinesWithDifferentNominalVoltageAtBothEnds(),
parameters.getConnectedComponentMode() == LoadFlowParameters.ConnectedComponentMode.MAIN,
parameters.getCountriesToBalance(),
parameters.isDistributedSlack() && parameters.getBalanceType() == LoadFlowParameters.BalanceType.PROPORTIONAL_TO_CONFORM_LOAD,
parameters.isPhaseShifterRegulationOn(),
parameters.isTransformerVoltageControlOn(),
parametersExt.isVoltagePerReactivePowerControl(),
parametersExt.hasReactivePowerRemoteControl());

var equationSystemCreationParameters = new AcEquationSystemCreationParameters(forceA1Var, branchesWithCurrent);

var newtonRaphsonParameters = new NewtonRaphsonParameters()
.setVoltageInitializer(voltageInitializer);

return new AcLoadFlowParameters(networkParameters,
equationSystemCreationParameters,
newtonRaphsonParameters,
outerLoops, matrixFactory);
}

private LoadFlowResult runAc(Network network, LoadFlowParameters parameters, OpenLoadFlowParameters parametersExt, Reporter reporter) {
Expand Down Expand Up @@ -251,7 +256,9 @@ private LoadFlowResult runAc(Network network, LoadFlowParameters parameters, Ope
return new LoadFlowResultImpl(ok, Collections.emptyMap(), null, componentResults);
}

private LoadFlowResult runDc(Network network, LoadFlowParameters parameters, OpenLoadFlowParameters parametersExt, Reporter reporter) {
private static DcLoadFlowParameters createDcParameters(Network network, MatrixFactory matrixFactory,
LoadFlowParameters parameters, OpenLoadFlowParameters parametersExt,
boolean forcePhaseControlOffAndAddAngle1Var) {
SlackBusSelector slackBusSelector = getSlackBusSelector(network, parameters, parametersExt);

LOGGER.info("Slack bus selector: {}", slackBusSelector.getClass().getSimpleName());
Expand All @@ -262,18 +269,37 @@ private LoadFlowResult runDc(Network network, LoadFlowParameters parameters, Ope
LOGGER.info("Add ratio to lines with different nominal voltage at both ends: {}", parametersExt.isAddRatioToLinesWithDifferentNominalVoltageAtBothEnds());
LOGGER.info("Connected component mode: {}", parameters.getConnectedComponentMode());

DcLoadFlowParameters dcParameters = new DcLoadFlowParameters(slackBusSelector,
matrixFactory,
true,
parameters.isDcUseTransformerRatio(),
parameters.isDistributedSlack(),
parameters.getBalanceType(),
forcePhaseControlOffAndAddAngle1Var,
parametersExt.getPlausibleActivePowerLimit(),
parametersExt.isAddRatioToLinesWithDifferentNominalVoltageAtBothEnds(),
true,
parameters.getConnectedComponentMode() == LoadFlowParameters.ConnectedComponentMode.MAIN,
parameters.getCountriesToBalance());
var networkParameters = new LfNetworkParameters(slackBusSelector,
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, it might be worth it to put a createDcLoadFlowParameters(parameters, parametersExt, slackBusSelector). And to factorize it with the other similar method (in DcSensitivityAnalysis)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done but we cannot share the code as parameters are differents

false,
false,
false,
false,
parametersExt.getPlausibleActivePowerLimit(),
false,
parameters.getConnectedComponentMode() == LoadFlowParameters.ConnectedComponentMode.MAIN,
parameters.getCountriesToBalance(),
parameters.isDistributedSlack() && parameters.getBalanceType() == LoadFlowParameters.BalanceType.PROPORTIONAL_TO_CONFORM_LOAD,
false,
false,
false,
false);

var equationSystemCreationParameters = new DcEquationSystemCreationParameters(true,
false,
forcePhaseControlOffAndAddAngle1Var,
parameters.isDcUseTransformerRatio());

return new DcLoadFlowParameters(networkParameters,
equationSystemCreationParameters,
matrixFactory,
parameters.isDistributedSlack(),
parameters.getBalanceType(),
true);
}

private LoadFlowResult runDc(Network network, LoadFlowParameters parameters, OpenLoadFlowParameters parametersExt, Reporter reporter) {

var dcParameters = createDcParameters(network, matrixFactory, parameters, parametersExt, forcePhaseControlOffAndAddAngle1Var);

List<DcLoadFlowResult> results = new DcLoadFlowEngine(network, dcParameters, reporter)
.run(reporter);
Expand Down
Loading