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

[WIP] DC Area Interchange Control Outer Loop #1099

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected static Optional<AcOuterLoop> createDistributedSlackOuterLoop(LoadFlowP
protected static Optional<AcOuterLoop> createAreaInterchangeControlOuterLoop(LoadFlowParameters parameters, OpenLoadFlowParameters parametersExt) {
if (parametersExt.isAreaInterchangeControl()) {
ActivePowerDistribution activePowerDistribution = ActivePowerDistribution.create(parameters.getBalanceType(), parametersExt.isLoadPowerFactorConstant(), parametersExt.isUseActiveLimits());
return Optional.of(new AreaInterchangeControlOuterloop(activePowerDistribution, parametersExt.getSlackBusPMaxMismatch(), parametersExt.getAreaInterchangePMaxMismatch()));
return Optional.of(new AcAreaInterchangeControlOuterLoop(activePowerDistribution, parametersExt.getSlackBusPMaxMismatch(), parametersExt.getAreaInterchangePMaxMismatch()));
}
return Optional.empty();
}
Expand Down Expand Up @@ -137,7 +137,7 @@ protected static Optional<AcOuterLoop> createAutomationSystemOuterLoop(OpenLoadF
}

static List<AcOuterLoop> filterInconsistentOuterLoops(List<AcOuterLoop> outerLoops) {
if (outerLoops.stream().anyMatch(AreaInterchangeControlOuterloop.class::isInstance)) {
if (outerLoops.stream().anyMatch(AcAreaInterchangeControlOuterLoop.class::isInstance)) {
return outerLoops.stream().filter(o -> {
if (o instanceof DistributedSlackOuterLoop) {
LOGGER.warn("Distributed slack and area interchange control are both enabled. " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ExplicitAcOuterLoopConfig extends AbstractAcOuterLoopConfig {
TransformerVoltageControlOuterLoop.NAME,
AutomationSystemOuterLoop.NAME,
IncrementalTransformerReactivePowerControlOuterLoop.NAME,
AreaInterchangeControlOuterloop.NAME);
AcAreaInterchangeControlOuterLoop.NAME);

private static Optional<AcOuterLoop> createOuterLoop(String name, LoadFlowParameters parameters, OpenLoadFlowParameters parametersExt) {
return switch (name) {
Expand Down Expand Up @@ -69,7 +69,7 @@ private static Optional<AcOuterLoop> createOuterLoop(String name, LoadFlowParame
parametersExt.getGeneratorVoltageControlMinNominalVoltage());
case AutomationSystemOuterLoop.NAME -> createAutomationSystemOuterLoop(parametersExt);
case IncrementalTransformerReactivePowerControlOuterLoop.NAME -> createTransformerReactivePowerControlOuterLoop(parametersExt);
case AreaInterchangeControlOuterloop.NAME -> createAreaInterchangeControlOuterLoop(parameters, parametersExt);
case AcAreaInterchangeControlOuterLoop.NAME -> createAreaInterchangeControlOuterLoop(parameters, parametersExt);
default -> throw new PowsyblException("Unknown outer loop '" + name + "'");
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,9 @@ public static DcLoadFlowParameters createDcParameters(LoadFlowParameters paramet
.setLowImpedanceThreshold(parametersExt.getLowImpedanceThreshold())
.setSvcVoltageMonitoring(false)
.setMaxSlackBusCount(1)
.setLinePerUnitMode(parametersExt.getLinePerUnitMode());
.setLinePerUnitMode(parametersExt.getLinePerUnitMode())
.setAreaInterchangeControl(parametersExt.isAreaInterchangeControl())
.setAreaInterchangeControlAreaType(parametersExt.getAreaInterchangeControlAreaType());

var equationSystemCreationParameters = new DcEquationSystemCreationParameters()
.setUpdateFlows(true)
Expand All @@ -1934,11 +1936,15 @@ public static DcLoadFlowParameters createDcParameters(LoadFlowParameters paramet
return new DcLoadFlowParameters()
.setNetworkParameters(networkParameters)
.setEquationSystemCreationParameters(equationSystemCreationParameters)
.setSlackDistributionFailureBehavior(parametersExt.getSlackDistributionFailureBehavior())
.setMatrixFactory(matrixFactory)
.setDistributedSlack(parameters.isDistributedSlack())
.setAreaInterchangeControl(parametersExt.isAreaInterchangeControl())
.setBalanceType(parameters.getBalanceType())
.setSetVToNan(true)
.setMaxOuterLoopIterations(parametersExt.getMaxOuterLoopIterations());
.setMaxOuterLoopIterations(parametersExt.getMaxOuterLoopIterations())
.setSlackBusPMaxMismatch(parametersExt.getSlackBusPMaxMismatch())
.setAreaInterchangePMaxMismatch(parametersExt.getAreaInterchangePMaxMismatch());
}

public static boolean equals(LoadFlowParameters parameters1, LoadFlowParameters parameters2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private LoadFlowResult.ComponentResult processResult(Network network, DcLoadFlow
0, // iterationCount
referenceBusAndSlackBusesResults.referenceBusId(),
referenceBusAndSlackBusesResults.slackBusResultList(),
Double.NaN);
result.getDistributedActivePower() * PerUnit.SB);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package com.powsybl.openloadflow.ac;

import com.powsybl.openloadflow.OpenLoadFlowParameters;
import com.powsybl.openloadflow.ac.equations.AcEquationSystemCreationParameters;
import com.powsybl.openloadflow.ac.outerloop.AcOuterLoop;
import com.powsybl.openloadflow.ac.solver.AcSolverFactory;
Expand Down Expand Up @@ -42,8 +41,6 @@ public class AcLoadFlowParameters extends AbstractLoadFlowParameters<AcLoadFlowP

private boolean asymmetrical = LfNetworkParameters.ASYMMETRICAL_DEFAULT_VALUE;

private OpenLoadFlowParameters.SlackDistributionFailureBehavior slackDistributionFailureBehavior = OpenLoadFlowParameters.SlackDistributionFailureBehavior.LEAVE_ON_SLACK_BUS;

private AcSolverFactory solverFactory = new NewtonRaphsonFactory();

private boolean detailedReport = false;
Expand Down Expand Up @@ -111,15 +108,6 @@ public AcLoadFlowParameters setAsymmetrical(boolean asymmetrical) {
return this;
}

public OpenLoadFlowParameters.SlackDistributionFailureBehavior getSlackDistributionFailureBehavior() {
return slackDistributionFailureBehavior;
}

public AcLoadFlowParameters setSlackDistributionFailureBehavior(OpenLoadFlowParameters.SlackDistributionFailureBehavior slackDistributionFailureBehavior) {
this.slackDistributionFailureBehavior = Objects.requireNonNull(slackDistributionFailureBehavior);
return this;
}

public AcSolverFactory getSolverFactory() {
return solverFactory;
}
Expand Down
25 changes: 2 additions & 23 deletions src/main/java/com/powsybl/openloadflow/ac/AcLoadFlowResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,16 @@ public static AcLoadFlowResult createNoCalculationResult(LfNetwork network) {
return new AcLoadFlowResult(network, 0, 0, AcSolverStatus.NO_CALCULATION, OuterLoopResult.stable(), Double.NaN, Double.NaN);
}

private final int outerLoopIterations;

private final int solverIterations;

private final AcSolverStatus solverStatus;

private final OuterLoopResult outerLoopResult;

private final double distributedActivePower;

public AcLoadFlowResult(LfNetwork network, int outerLoopIterations, int solverIterations,
AcSolverStatus solverStatus, OuterLoopResult outerLoopResult,
double slackBusActivePowerMismatch, double distributedActivePower) {
super(network, slackBusActivePowerMismatch);
this.outerLoopIterations = outerLoopIterations;
super(network, slackBusActivePowerMismatch, outerLoopIterations, outerLoopResult, distributedActivePower);
this.solverIterations = solverIterations;
this.solverStatus = Objects.requireNonNull(solverStatus);
this.outerLoopResult = Objects.requireNonNull(outerLoopResult);
this.distributedActivePower = distributedActivePower;
}

public int getOuterLoopIterations() {
return outerLoopIterations;
}

public int getSolverIterations() {
Expand All @@ -59,17 +46,9 @@ public AcSolverStatus getSolverStatus() {
return solverStatus;
}

public OuterLoopResult getOuterLoopResult() {
return outerLoopResult;
}

public double getDistributedActivePower() {
return distributedActivePower;
}

@Override
public boolean isSuccess() {
return solverStatus == AcSolverStatus.CONVERGED && outerLoopResult.status() == OuterLoopStatus.STABLE;
return solverStatus == AcSolverStatus.CONVERGED && getOuterLoopResult().status() == OuterLoopStatus.STABLE;
}

public boolean isWithNetworkUpdate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public class AcOuterLoopContext extends AbstractOuterLoopContext<AcVariableType,

private int iteration; // current iterations of this single outer loop type

private int outerLoopTotalIterations; // current total iterations over all outer loop types, for reporting purposes

private AcSolverResult lastSolverResult;

AcOuterLoopContext(LfNetwork network) {
Expand All @@ -45,11 +43,4 @@ public void setLastSolverResult(AcSolverResult lastSolverResult) {
this.lastSolverResult = lastSolverResult;
}

public int getOuterLoopTotalIterations() {
return outerLoopTotalIterations;
}

public void setOuterLoopTotalIterations(int outerLoopTotalIterations) {
this.outerLoopTotalIterations = outerLoopTotalIterations;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
import com.powsybl.commons.report.ReportNode;
import com.powsybl.openloadflow.ac.equations.AcEquationType;
import com.powsybl.openloadflow.ac.equations.AcVariableType;
import com.powsybl.openloadflow.ac.outerloop.AcActivePowerDistributionOuterLoop;
import com.powsybl.openloadflow.ac.outerloop.AcOuterLoop;
import com.powsybl.openloadflow.ac.outerloop.AreaInterchangeControlOuterloop;
import com.powsybl.openloadflow.ac.outerloop.DistributedSlackOuterLoop;
import com.powsybl.openloadflow.ac.solver.*;
import com.powsybl.openloadflow.lf.LoadFlowEngine;
import com.powsybl.openloadflow.lf.outerloop.DistributedSlackContextData;
import com.powsybl.openloadflow.lf.outerloop.OuterLoopResult;
import com.powsybl.openloadflow.lf.outerloop.OuterLoopStatus;
import com.powsybl.openloadflow.network.LfNetwork;
Expand Down Expand Up @@ -209,8 +207,8 @@ public AcLoadFlowResult run() {
for (var outerLoopAndContext : Lists.reverse(outerLoopsAndContexts)) {
var outerLoop = outerLoopAndContext.getLeft();
var outerLoopContext = outerLoopAndContext.getRight();
if (outerLoop instanceof DistributedSlackOuterLoop || outerLoop instanceof AreaInterchangeControlOuterloop) {
distributedActivePower = ((DistributedSlackContextData) outerLoopContext.getData()).getDistributedActivePower();
if (outerLoop instanceof AcActivePowerDistributionOuterLoop activePowerDistributionOuterLoop) {
distributedActivePower = activePowerDistributionOuterLoop.getDistributedActivePower(outerLoopContext);
}
outerLoop.cleanup(outerLoopContext);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* 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.ac.outerloop;

import com.powsybl.openloadflow.ac.AcLoadFlowContext;
import com.powsybl.openloadflow.ac.AcLoadFlowParameters;
import com.powsybl.openloadflow.ac.AcOuterLoopContext;
import com.powsybl.openloadflow.ac.equations.AcEquationType;
import com.powsybl.openloadflow.ac.equations.AcVariableType;
import com.powsybl.openloadflow.lf.outerloop.ActivePowerDistributionOuterLoop;

/**
* @author Valentin Mouradian {@literal <valentin.mouradian at artelys.com>}
*/
public interface AcActivePowerDistributionOuterLoop extends ActivePowerDistributionOuterLoop<AcVariableType, AcEquationType, AcLoadFlowParameters, AcLoadFlowContext, AcOuterLoopContext> {
@Override
default double getSlackBusActivePowerMismatch(AcOuterLoopContext context) {
return context.getLastSolverResult().getSlackBusActivePowerMismatch();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* 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.ac.outerloop;

import com.powsybl.openloadflow.ac.AcLoadFlowContext;
import com.powsybl.openloadflow.ac.AcLoadFlowParameters;
import com.powsybl.openloadflow.ac.AcOuterLoopContext;
import com.powsybl.openloadflow.ac.equations.AcEquationType;
import com.powsybl.openloadflow.ac.equations.AcVariableType;
import com.powsybl.openloadflow.lf.outerloop.AbstractAreaInterchangeControlOuterLoop;
import com.powsybl.openloadflow.network.util.ActivePowerDistribution;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @author Valentin Mouradian {@literal <valentin.mouradian at artelys.com>}
*/
public class AcAreaInterchangeControlOuterLoop
extends AbstractAreaInterchangeControlOuterLoop<AcVariableType, AcEquationType, AcLoadFlowParameters, AcLoadFlowContext, AcOuterLoopContext>
implements AcOuterLoop, AcActivePowerDistributionOuterLoop {

private static final Logger LOGGER = LoggerFactory.getLogger(AcAreaInterchangeControlOuterLoop.class);

public static final String NAME = "AreaInterchangeControl";

public AcAreaInterchangeControlOuterLoop(ActivePowerDistribution activePowerDistribution, double slackBusPMaxMismatch, double areaInterchangePMaxMismatch) {
super(activePowerDistribution, new DistributedSlackOuterLoop(activePowerDistribution, slackBusPMaxMismatch), slackBusPMaxMismatch, areaInterchangePMaxMismatch, LOGGER);
}

@Override
public String getName() {
return NAME;
}

}
Loading