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

Current limit violations detection in DC security analysis #549

Merged
merged 18 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from 14 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 @@ -61,6 +61,8 @@ public class OpenLoadFlowParameters extends AbstractExtension<LoadFlowParameters

public static final boolean VOLTAGE_PER_REACTIVE_POWER_CONTROL_DEFAULT_VALUE = false;

public static final double DC_COS_PHI_DEFAULT_VALUE = 1.0;

public static final String SLACK_BUS_SELECTION_PARAM_NAME = "slackBusSelectionMode";

public static final String SLACK_BUSES_IDS_PARAM_NAME = "slackBusesIds";
Expand Down Expand Up @@ -91,6 +93,8 @@ public class OpenLoadFlowParameters extends AbstractExtension<LoadFlowParameters

public static final String TRANSFORMER_VOLTAGE_CONTROL_MODE_NAME = "transformerVoltageControlMode";

public static final String DC_COS_PHI_NAME = "dcCosPhi";
Copy link
Member

Choose a reason for hiding this comment

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

@annetill are you sure cos(phi) is the right naming? phi is used in OLF as the voltage angle. Would power factor more usual way of naming this?

Copy link
Member

Choose a reason for hiding this comment

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

Yes right, my mistake, I am going to fix the name.


public static final List<String> SPECIFIC_PARAMETERS_NAMES = List.of(SLACK_BUS_SELECTION_PARAM_NAME,
SLACK_BUSES_IDS_PARAM_NAME,
LOW_IMPEDANCE_BRANCH_MODE_PARAM_NAME,
Expand Down Expand Up @@ -157,6 +161,8 @@ public enum LowImpedanceBranchMode {

private TransformerVoltageControlMode transformerVoltageControlMode = TRANSFORMER_VOLTAGE_CONTROL_MODE_DEFAULT_VALUE;

private double dcCosPhi = DC_COS_PHI_DEFAULT_VALUE;

@Override
public String getName() {
return "open-load-flow-parameters";
Expand Down Expand Up @@ -305,6 +311,15 @@ public OpenLoadFlowParameters setTransformerVoltageControlMode(TransformerVoltag
return this;
}

public double getDcCosPhi() {
return dcCosPhi;
}

public OpenLoadFlowParameters setDcCosPhi(double dcCosPhi) {
this.dcCosPhi = dcCosPhi;
return this;
}

public static OpenLoadFlowParameters load() {
return load(PlatformConfig.defaultConfig());
}
Expand All @@ -329,7 +344,8 @@ public static OpenLoadFlowParameters load(PlatformConfig platformConfig) {
.setMaxIteration(config.getIntProperty(MAX_ITERATION_NAME, NewtonRaphsonParameters.DEFAULT_MAX_ITERATION))
.setNewtonRaphsonConvEpsPerEq(config.getDoubleProperty(NEWTON_RAPHSON_CONV_EPS_PER_EQ_NAME, DefaultNewtonRaphsonStoppingCriteria.DEFAULT_CONV_EPS_PER_EQ))
.setVoltageInitModeOverride(config.getEnumProperty(VOLTAGE_INIT_MODE_OVERRIDE_NAME, VoltageInitModeOverride.class, VOLTAGE_INIT_MODE_OVERRIDE_DEFAULT_VALUE))
.setTransformerVoltageControlMode(config.getEnumProperty(TRANSFORMER_VOLTAGE_CONTROL_MODE_NAME, TransformerVoltageControlMode.class, TRANSFORMER_VOLTAGE_CONTROL_MODE_DEFAULT_VALUE)));
.setTransformerVoltageControlMode(config.getEnumProperty(TRANSFORMER_VOLTAGE_CONTROL_MODE_NAME, TransformerVoltageControlMode.class, TRANSFORMER_VOLTAGE_CONTROL_MODE_DEFAULT_VALUE))
.setDcCosPhi(config.getDoubleProperty(DC_COS_PHI_NAME, DC_COS_PHI_DEFAULT_VALUE)));
return parameters;
}

Expand Down Expand Up @@ -368,6 +384,8 @@ public OpenLoadFlowParameters update(Map<String, String> properties) {
.ifPresent(prop -> this.setVoltageInitModeOverride(VoltageInitModeOverride.valueOf(prop)));
Optional.ofNullable(properties.get(TRANSFORMER_VOLTAGE_CONTROL_MODE_NAME))
.ifPresent(prop -> this.setTransformerVoltageControlMode(TransformerVoltageControlMode.valueOf(prop)));
Optional.ofNullable(properties.get(DC_COS_PHI_NAME))
.ifPresent(prop -> this.setDcCosPhi(Double.parseDouble(prop)));
return this;
}

Expand All @@ -389,6 +407,7 @@ public String toString() {
", newtonRaphsonConvEpsPerEq=" + newtonRaphsonConvEpsPerEq +
", voltageInitModeOverride=" + voltageInitModeOverride +
", transformerVoltageControlMode=" + transformerVoltageControlMode +
", dcCosPhi=" + dcCosPhi +
')';
}

Expand Down Expand Up @@ -424,6 +443,7 @@ public static void logDc(LoadFlowParameters parameters, OpenLoadFlowParameters p
LOGGER.info("Plausible active power limit: {}", parametersExt.getPlausibleActivePowerLimit());
LOGGER.info("Add ratio to lines with different nominal voltage at both ends: {}", parametersExt.isAddRatioToLinesWithDifferentNominalVoltageAtBothEnds());
LOGGER.info("Connected component mode: {}", parameters.getConnectedComponentMode());
LOGGER.info("DC cos phi: {}", parametersExt.getDcCosPhi());
}

/**
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/powsybl/openloadflow/sa/DcSecurityAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.powsybl.iidm.network.Branch;
import com.powsybl.iidm.network.Network;
import com.powsybl.math.matrix.MatrixFactory;
import com.powsybl.openloadflow.OpenLoadFlowParameters;
import com.powsybl.openloadflow.graph.GraphDecrementalConnectivityFactory;
import com.powsybl.openloadflow.network.LfBranch;
import com.powsybl.openloadflow.network.LfBus;
Expand Down Expand Up @@ -63,6 +64,10 @@ SecurityAnalysisReport runSync(String workingVariantId, SecurityAnalysisParamete
StateMonitor monitor = monitorIndex.getAllStateMonitor();
Map<String, BranchResult> preContingencyBranchResults = new HashMap<>();

// CosPhi for DC power to current conversion
OpenLoadFlowParameters parametersExt = OpenLoadFlowParameters.get(securityAnalysisParameters.getLoadFlowParameters());
double cosPhi = parametersExt.getDcCosPhi();

Map<Pair<String, Branch.Side>, LimitViolation> preContingencyLimitViolationsMap = new HashMap<>();
for (SensitivityValue sensValue : res.getValues(null)) {
SensitivityFactor factor = factors.get(sensValue.getFactorIndex());
Expand All @@ -71,6 +76,10 @@ SecurityAnalysisReport runSync(String workingVariantId, SecurityAnalysisParamete
preContingencyBranchResults.put(branchId, new BranchResult(branchId, sensValue.getFunctionReference(), Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN));
detector.checkActivePower(branch, Branch.Side.ONE, Math.abs(sensValue.getFunctionReference()),
violation -> preContingencyLimitViolationsMap.put(Pair.of(violation.getSubjectId(), violation.getSide()), violation));
detector.checkCurrent(branch, Branch.Side.ONE, currentActivePower(Math.abs(sensValue.getFunctionReference()), branch.getTerminal1().getVoltageLevel().getNominalV(), cosPhi),
violation -> preContingencyLimitViolationsMap.put(Pair.of(violation.getSubjectId(), violation.getSide()), violation));
detector.checkCurrent(branch, Branch.Side.TWO, currentActivePower(Math.abs(sensValue.getFunctionReference()), branch.getTerminal2().getVoltageLevel().getNominalV(), cosPhi),
violation -> preContingencyLimitViolationsMap.put(Pair.of(violation.getSubjectId(), violation.getSide()), violation));
}

LimitViolationsResult preContingencyResult = new LimitViolationsResult(true,
Expand Down Expand Up @@ -98,6 +107,10 @@ SecurityAnalysisReport runSync(String workingVariantId, SecurityAnalysisParamete
}
detector.checkActivePower(branch, Branch.Side.ONE, Math.abs(v.getFunctionReference()),
violation -> violations.put(Pair.of(violation.getSubjectId(), violation.getSide()), violation));
detector.checkCurrent(branch, Branch.Side.ONE, currentActivePower(Math.abs(v.getFunctionReference()), branch.getTerminal1().getVoltageLevel().getNominalV(), cosPhi),
violation -> violations.put(Pair.of(violation.getSubjectId(), violation.getSide()), violation));
detector.checkCurrent(branch, Branch.Side.TWO, currentActivePower(Math.abs(v.getFunctionReference()), branch.getTerminal2().getVoltageLevel().getNominalV(), cosPhi),
violation -> violations.put(Pair.of(violation.getSubjectId(), violation.getSide()), violation));
}
preContingencyLimitViolationsMap.forEach((subjectSideId, preContingencyViolation) -> {
LimitViolation postContingencyViolation = violations.get(subjectSideId);
Expand All @@ -110,4 +123,8 @@ SecurityAnalysisReport runSync(String workingVariantId, SecurityAnalysisParamete

return new SecurityAnalysisReport(new SecurityAnalysisResult(preContingencyResult, postContingencyResults, new ArrayList<>(preContingencyBranchResults.values()), Collections.emptyList(), Collections.emptyList()));
}

public static double currentActivePower(double activePower, double voltage, double cosPhi) {
return 1000 * activePower / (Math.sqrt(3) * cosPhi * voltage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ void testDefaultOpenLoadflowConfig() {
assertEquals(OpenLoadFlowParameters.THROWS_EXCEPTION_IN_CASE_OF_SLACK_DISTRIBUTION_FAILURE_DEFAULT_VALUE, olfParameters.isThrowsExceptionInCaseOfSlackDistributionFailure());
assertEquals(OpenLoadFlowParameters.SLACK_BUS_P_MAX_MISMATCH_DEFAULT_VALUE, olfParameters.getSlackBusPMaxMismatch(), 0.0);
assertEquals(OpenLoadFlowParameters.REACTIVE_POWER_REMOTE_CONTROL_DEFAULT_VALUE, olfParameters.hasReactivePowerRemoteControl());
assertEquals(OpenLoadFlowParameters.DC_COS_PHI_DEFAULT_VALUE, olfParameters.getDcCosPhi());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package com.powsybl.openloadflow.sa;

import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.io.table.AsciiTableFormatterFactory;
import com.powsybl.commons.io.table.TableFormatterConfig;
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.computation.ComputationManager;
import com.powsybl.contingency.*;
Expand Down Expand Up @@ -34,6 +36,7 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.io.OutputStreamWriter;
import java.util.*;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ForkJoinPool;
Expand Down Expand Up @@ -1521,4 +1524,84 @@ void testSwitchLoopIssue() {
assertEquals(-599.882, postContingencyResult.getBranchResult("L2").getP1(), LoadFlowAssert.DELTA_POWER);
assertEquals(608.214, postContingencyResult.getBranchResult("L2").getP2(), LoadFlowAssert.DELTA_POWER);
}

@Test
void testDcPermanentCurrentLimitViolations() {
Network network = FourBusNetworkFactory.create();
SecurityAnalysisParameters securityAnalysisParameters = new SecurityAnalysisParameters();
LoadFlowParameters lfParameters = new LoadFlowParameters()
.setDc(true);
setSlackBusId(lfParameters, "b1_vl_0");
securityAnalysisParameters.setLoadFlowParameters(lfParameters);

List<Contingency> contingencies = allBranches(network);

network.getLine("l14").newCurrentLimits1().setPermanentLimit(60.0).add();
network.getLine("l12").newCurrentLimits1().setPermanentLimit(120.0).add();
network.getLine("l23").newCurrentLimits2().setPermanentLimit(150.0).add();
network.getLine("l34").newCurrentLimits1().setPermanentLimit(90.0).add();
network.getLine("l13").newCurrentLimits2().setPermanentLimit(60.0).add();

List<StateMonitor> monitors = List.of(new StateMonitor(ContingencyContext.all(), Set.of("l14", "l12", "l23", "l34", "l13"), Collections.emptySet(), Collections.emptySet()));

SecurityAnalysisResult result = runSecurityAnalysis(network, contingencies, monitors, securityAnalysisParameters);

Security.print(result,
network,
new OutputStreamWriter(System.out),
new AsciiTableFormatterFactory(),
new Security.PostContingencyLimitViolationWriteConfig(null, TableFormatterConfig.load(), true, false));

assertTrue(result.getPreContingencyResult().getLimitViolationsResult().isComputationOk());
assertEquals(5, result.getPreContingencyResult().getLimitViolationsResult().getLimitViolations().size());
assertEquals(5, result.getPostContingencyResults().size());
assertEquals(2, result.getPostContingencyResults().get(0).getLimitViolationsResult().getLimitViolations().size());
assertEquals(2, result.getPostContingencyResults().get(1).getLimitViolationsResult().getLimitViolations().size());
assertEquals(4, result.getPostContingencyResults().get(2).getLimitViolationsResult().getLimitViolations().size());
assertEquals(4, result.getPostContingencyResults().get(3).getLimitViolationsResult().getLimitViolations().size());
assertEquals(4, result.getPostContingencyResults().get(4).getLimitViolationsResult().getLimitViolations().size());
}

@Test
void testDcTemporaryCurrentLimitViolations() {
Network network = FourBusNetworkFactory.create();
SecurityAnalysisParameters securityAnalysisParameters = new SecurityAnalysisParameters();
LoadFlowParameters lfParameters = new LoadFlowParameters()
.setDc(true);
OpenLoadFlowParameters lfParametersExt = new OpenLoadFlowParameters().setDcCosPhi(Math.tan(0.4));
lfParameters.addExtension(OpenLoadFlowParameters.class, lfParametersExt);
setSlackBusId(lfParameters, "b1_vl_0");
securityAnalysisParameters.setLoadFlowParameters(lfParameters);

List<Contingency> contingencies = allBranches(network);

network.getLine("l14").newCurrentLimits1().setPermanentLimit(60.0)
.beginTemporaryLimit().setName("60").setAcceptableDuration(Integer.MAX_VALUE).setValue(200.0).endTemporaryLimit()
.beginTemporaryLimit().setName("0").setAcceptableDuration(60).setValue(Double.MAX_VALUE).endTemporaryLimit().add();
network.getLine("l12").newCurrentLimits1().setPermanentLimit(120.0)
.beginTemporaryLimit().setName("60").setAcceptableDuration(Integer.MAX_VALUE).setValue(300.0).endTemporaryLimit()
.beginTemporaryLimit().setName("0").setAcceptableDuration(60).setValue(Double.MAX_VALUE).endTemporaryLimit().add();
network.getLine("l23").newCurrentLimits2().setPermanentLimit(150.0)
.beginTemporaryLimit().setName("60").setAcceptableDuration(Integer.MAX_VALUE).setValue(500.0).endTemporaryLimit()
.beginTemporaryLimit().setName("0").setAcceptableDuration(60).setValue(Double.MAX_VALUE).endTemporaryLimit().add();
network.getLine("l34").newCurrentLimits1().setPermanentLimit(90.0)
.beginTemporaryLimit().setName("60").setAcceptableDuration(Integer.MAX_VALUE).setValue(300.0).endTemporaryLimit()
.beginTemporaryLimit().setName("0").setAcceptableDuration(60).setValue(Double.MAX_VALUE).endTemporaryLimit().add();
network.getLine("l13").newCurrentLimits2().setPermanentLimit(60.0)
.beginTemporaryLimit().setName("60").setAcceptableDuration(Integer.MAX_VALUE).setValue(300.0).endTemporaryLimit()
.beginTemporaryLimit().setName("0").setAcceptableDuration(60).setValue(Double.MAX_VALUE).endTemporaryLimit().add();

List<StateMonitor> monitors = List.of(new StateMonitor(ContingencyContext.all(), Set.of("l14", "l12", "l23", "l34", "l13"), Collections.emptySet(), Collections.emptySet()));

SecurityAnalysisResult result = runSecurityAnalysis(network, contingencies, monitors, securityAnalysisParameters);

assertTrue(result.getPreContingencyResult().getLimitViolationsResult().isComputationOk());
assertEquals(5, result.getPreContingencyResult().getLimitViolationsResult().getLimitViolations().size());
assertEquals(5, result.getPostContingencyResults().size());
assertEquals(2, result.getPostContingencyResults().get(0).getLimitViolationsResult().getLimitViolations().size());
assertEquals(2, result.getPostContingencyResults().get(1).getLimitViolationsResult().getLimitViolations().size());
assertEquals(4, result.getPostContingencyResults().get(2).getLimitViolationsResult().getLimitViolations().size());
assertEquals(4, result.getPostContingencyResults().get(3).getLimitViolationsResult().getLimitViolations().size());
assertEquals(4, result.getPostContingencyResults().get(4).getLimitViolationsResult().getLimitViolations().size());
}
}
3 changes: 2 additions & 1 deletion src/test/resources/debug-parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"maxIteration" : 30,
"newtonRaphsonConvEpsPerEq" : 1.0E-4,
"voltageInitModeOverride" : "NONE",
"transformerVoltageControlMode" : "WITH_GENERATOR_VOLTAGE_CONTROL"
"transformerVoltageControlMode" : "WITH_GENERATOR_VOLTAGE_CONTROL",
"dcCosPhi" : 1.0
}
}
},
Expand Down