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

Fix HVDC set point increase sensitivity convention #488

Merged
merged 4 commits into from
Apr 6, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ private static HvdcConverterStation<?> getOtherConversionStation(HvdcConverterSt
public static double getActivePowerSetpointMultiplier(HvdcConverterStation<?> station) {
// For sensitivity analysis, we need the multiplier by converter station for an increase of 1MW
// of the HVDC active power setpoint.
// VSC injection follow here a load sign convention as LCC injection.
// As a first approximation, we don't take into account the losses due to HVDC line itself.
boolean isConverterStationRectifier = isRectifier(station);
double sign = getSign(station);
if (isConverterStationRectifier) {
return sign;
return -1;
} else {
return sign * (1 - (station.getLossFactor() + getOtherConversionStation(station).getLossFactor()) / 100);
return 1 - (station.getLossFactor() + getOtherConversionStation(station).getLossFactor()) / 100;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -913,16 +913,12 @@ public SensitivityFactorHolder<V, E> readAndCheckFactors(Network network, Map<St
// => we create a multi (bi) variables factor
Map<LfElement, Double> injectionLfBuses = new HashMap<>(2);
if (bus1 != null) {
// VSC injection follow here a load sign convention as LCC injection.
// FIXME: for LCC, Q changes when P changes
injectionLfBuses.put(bus1, (hvdcLine.getConverterStation1() instanceof VscConverterStation ? -1 : 1)
* HvdcConverterStations.getActivePowerSetpointMultiplier(hvdcLine.getConverterStation1()));
injectionLfBuses.put(bus1, HvdcConverterStations.getActivePowerSetpointMultiplier(hvdcLine.getConverterStation1()));
}
if (bus2 != null) {
// VSC injection follow here a load sign convention as LCC injection.
// FIXME: for LCC, Q changes when P changes
injectionLfBuses.put(bus2, (hvdcLine.getConverterStation2() instanceof VscConverterStation ? -1 : 1)
* HvdcConverterStations.getActivePowerSetpointMultiplier(hvdcLine.getConverterStation2()));
injectionLfBuses.put(bus2, HvdcConverterStations.getActivePowerSetpointMultiplier(hvdcLine.getConverterStation2()));
}

factorHolder.addFactor(new MultiVariablesLfSensitivityFactor<>(factorIndex[0], variableId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ void testHvdcSensi() {
Map<String, Double> loadFlowDiff = network.getLineStream().map(Identifiable::getId)
.collect(Collectors.toMap(
lineId -> lineId,
line -> (network.getLine(line).getTerminal1().getP() - network1.getLine(line).getTerminal1().getP()) / SENSI_CHANGE
line -> (network1.getLine(line).getTerminal1().getP() - network.getLine(line).getTerminal1().getP()) / SENSI_CHANGE
));

List<SensitivityFactor> factors = SensitivityFactor.createMatrix(SensitivityFunctionType.BRANCH_ACTIVE_POWER_1, List.of("l12", "l13", "l23"),
Expand All @@ -683,20 +683,34 @@ void testHvdcSensiWithLCCs() {
// FIXME
// Note that in case of LCC converter stations, in AC, an increase of the setpoint of the HDVC line is not equivalent to
// running two LFs and comparing the differences as we don't change Q at LCCs when we change P.
Network network = HvdcNetworkFactory.createNetworkWithGenerators();

SensitivityAnalysisParameters sensiParameters = createParameters(false, "b1_vl_0", false);
sensiParameters.getLoadFlowParameters().getExtension(OpenLoadFlowParameters.class).setSlackBusSelectionMode(SlackBusSelectionMode.MOST_MESHED);
Network network = HvdcNetworkFactory.createNetworkWithGenerators();
runLf(network, sensiParameters.getLoadFlowParameters());

Network network1 = HvdcNetworkFactory.createNetworkWithGenerators();
network1.getHvdcLine("hvdc34").setActivePowerSetpoint(network1.getHvdcLine("hvdc34").getActivePowerSetpoint() + SENSI_CHANGE);

runLf(network1, sensiParameters.getLoadFlowParameters());
Map<String, Double> loadFlowDiff = network.getLineStream().map(Identifiable::getId)
.collect(Collectors.toMap(
lineId -> lineId,
line -> (network1.getLine(line).getTerminal1().getP() - network.getLine(line).getTerminal1().getP()) / SENSI_CHANGE
));

List<SensitivityFactor> factors = SensitivityFactor.createMatrix(SensitivityFunctionType.BRANCH_ACTIVE_POWER_1, List.of("l12", "l13", "l23"),
SensitivityVariableType.HVDC_LINE_ACTIVE_POWER, List.of("hvdc34"),
false, ContingencyContext.all());

SensitivityAnalysisResult result = sensiRunner.run(network, factors, Collections.emptyList(), Collections.emptyList(), sensiParameters);

assertEquals(-0.341889, result.getBranchFlow1SensitivityValue("hvdc34", "l12"), LoadFlowAssert.DELTA_POWER);
assertEquals(0.341889, result.getBranchFlow1SensitivityValue("hvdc34", "l13"), LoadFlowAssert.DELTA_POWER);
assertEquals(0.63611, result.getBranchFlow1SensitivityValue("hvdc34", "l23"), LoadFlowAssert.DELTA_POWER);
assertEquals(0.36218, loadFlowDiff.get("l12"), LoadFlowAssert.DELTA_POWER);
assertEquals(-0.35967, loadFlowDiff.get("l13"), LoadFlowAssert.DELTA_POWER);
assertEquals(-0.61191, loadFlowDiff.get("l23"), LoadFlowAssert.DELTA_POWER);

assertEquals(0.341889, result.getBranchFlow1SensitivityValue("hvdc34", "l12"), LoadFlowAssert.DELTA_POWER);
assertEquals(-0.341889, result.getBranchFlow1SensitivityValue("hvdc34", "l13"), LoadFlowAssert.DELTA_POWER);
assertEquals(-0.63611, result.getBranchFlow1SensitivityValue("hvdc34", "l23"), LoadFlowAssert.DELTA_POWER);
}

@Test
Expand All @@ -713,7 +727,7 @@ void testHvdcSensiWithBothSides() {
Map<String, Double> loadFlowDiff = network.getLineStream().map(Identifiable::getId)
.collect(Collectors.toMap(
lineId -> lineId,
line -> (network.getLine(line).getTerminal1().getP() - network1.getLine(line).getTerminal1().getP()) / SENSI_CHANGE
line -> (network1.getLine(line).getTerminal1().getP() - network.getLine(line).getTerminal1().getP()) / SENSI_CHANGE
));

List<SensitivityFactor> factors = SensitivityFactor.createMatrix(SensitivityFunctionType.BRANCH_ACTIVE_POWER_1, List.of("l12", "l13", "l23", "l25", "l45", "l46", "l56"),
Expand Down Expand Up @@ -747,7 +761,7 @@ void testHvdcSensiWithBothSidesDistributed() {
Map<String, Double> loadFlowDiff = network.getLineStream().map(Identifiable::getId)
.collect(Collectors.toMap(
lineId -> lineId,
line -> (network.getLine(line).getTerminal1().getP() - network1.getLine(line).getTerminal1().getP()) / SENSI_CHANGE
line -> (network1.getLine(line).getTerminal1().getP() - network.getLine(line).getTerminal1().getP()) / SENSI_CHANGE
));

List<SensitivityFactor> factors = SensitivityFactor.createMatrix(SensitivityFunctionType.BRANCH_ACTIVE_POWER_1, List.of("l12", "l13", "l23", "l25", "l45", "l46", "l56"),
Expand All @@ -765,6 +779,40 @@ void testHvdcSensiWithBothSidesDistributed() {
assertEquals(loadFlowDiff.get("l56"), result.getBranchFlow1SensitivityValue("hvdc34", "l56"), LoadFlowAssert.DELTA_POWER);
}

@Test
void testHvdcSensiWithBothSidesDistributed2() {
SensitivityAnalysisParameters sensiParameters = createParameters(false, "b1_vl_0", true);
sensiParameters.getLoadFlowParameters().getExtension(OpenLoadFlowParameters.class).setSlackBusPMaxMismatch(0.01);

Network network = HvdcNetworkFactory.createNetworkWithGenerators2();
network.getGeneratorStream().forEach(gen -> gen.setMaxP(2 * gen.getMaxP()));
runLf(network, sensiParameters.getLoadFlowParameters());

Network network1 = HvdcNetworkFactory.createNetworkWithGenerators2();
network1.getGeneratorStream().forEach(gen -> gen.setMaxP(2 * gen.getMaxP()));
network1.getGenerator("g1").setTargetP(network1.getGenerator("g1").getTargetP() + SENSI_CHANGE);
runLf(network1, sensiParameters.getLoadFlowParameters());
Map<String, Double> loadFlowDiff = network.getLineStream().map(Identifiable::getId)
.collect(Collectors.toMap(
lineId -> lineId,
line -> (network1.getLine(line).getTerminal1().getP() - network.getLine(line).getTerminal1().getP()) / SENSI_CHANGE
));

List<SensitivityFactor> factors = SensitivityFactor.createMatrix(SensitivityFunctionType.BRANCH_ACTIVE_POWER_1, List.of("l12", "l13", "l23", "l25", "l45", "l46", "l56"),
SensitivityVariableType.INJECTION_ACTIVE_POWER, List.of("g1"),
false, ContingencyContext.all());

SensitivityAnalysisResult result = sensiRunner.run(network, factors, Collections.emptyList(), Collections.emptyList(), sensiParameters);

assertEquals(loadFlowDiff.get("l12"), result.getBranchFlow1SensitivityValue("g1", "l12"), LoadFlowAssert.DELTA_POWER);
assertEquals(loadFlowDiff.get("l13"), result.getBranchFlow1SensitivityValue("g1", "l13"), LoadFlowAssert.DELTA_POWER);
assertEquals(loadFlowDiff.get("l23"), result.getBranchFlow1SensitivityValue("g1", "l23"), LoadFlowAssert.DELTA_POWER);
assertEquals(loadFlowDiff.get("l25"), result.getBranchFlow1SensitivityValue("g1", "l25"), LoadFlowAssert.DELTA_POWER);
assertEquals(loadFlowDiff.get("l45"), result.getBranchFlow1SensitivityValue("g1", "l45"), LoadFlowAssert.DELTA_POWER);
assertEquals(loadFlowDiff.get("l46"), result.getBranchFlow1SensitivityValue("g1", "l46"), LoadFlowAssert.DELTA_POWER);
assertEquals(loadFlowDiff.get("l56"), result.getBranchFlow1SensitivityValue("g1", "l56"), LoadFlowAssert.DELTA_POWER);
}

@Test
void testHvdcInjectionNotFound() {
testHvdcInjectionNotFound(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ void testHvdcSensiRescale() {
network.getGeneratorStream().forEach(gen -> gen.setMaxP(2 * gen.getMaxP()));
Map<String, Double> loadFlowDiff = network.getLineStream()
.map(Identifiable::getId)
.collect(Collectors.toMap(Function.identity(), line -> (network1.getLine(line).getTerminal1().getP() - network2.getLine(line).getTerminal1().getP()) / SENSI_CHANGE));
.collect(Collectors.toMap(Function.identity(), line -> (network2.getLine(line).getTerminal1().getP() - network1.getLine(line).getTerminal1().getP()) / SENSI_CHANGE));

List<SensitivityFactor> factors = SensitivityFactor.createMatrix(SensitivityFunctionType.BRANCH_ACTIVE_POWER_1, List.of("l12", "l13", "l23", "l25", "l45", "l46", "l56"),
SensitivityVariableType.HVDC_LINE_ACTIVE_POWER, List.of("hvdc34"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ void testHvdcSensi() {
Map<String, Double> loadFlowDiff = network.getLineStream().map(Identifiable::getId)
.collect(Collectors.toMap(
lineId -> lineId,
line -> (network.getLine(line).getTerminal1().getP() - network1.getLine(line).getTerminal1().getP()) / SENSI_CHANGE
line -> (network1.getLine(line).getTerminal1().getP() - network.getLine(line).getTerminal1().getP()) / SENSI_CHANGE
));

List<SensitivityFactor> factors = SensitivityFactor.createMatrix(SensitivityFunctionType.BRANCH_ACTIVE_POWER_1, List.of("l12", "l13", "l23"),
Expand Down Expand Up @@ -544,7 +544,7 @@ void testHvdcSensiWithBothSides() {
Map<String, Double> loadFlowDiff = network.getLineStream().map(Identifiable::getId)
.collect(Collectors.toMap(
lineId -> lineId,
line -> (network.getLine(line).getTerminal1().getP() - network1.getLine(line).getTerminal1().getP()) / SENSI_CHANGE
line -> (network1.getLine(line).getTerminal1().getP() - network.getLine(line).getTerminal1().getP()) / SENSI_CHANGE
));

List<SensitivityFactor> factors = SensitivityFactor.createMatrix(SensitivityFunctionType.BRANCH_ACTIVE_POWER_1, List.of("l12", "l13", "l23", "l25", "l45", "l46", "l56"),
Expand Down Expand Up @@ -578,7 +578,7 @@ void testHvdcSensiWithBothSidesDistributed() {
Map<String, Double> loadFlowDiff = network.getLineStream().map(Identifiable::getId)
.collect(Collectors.toMap(
lineId -> lineId,
line -> (network.getLine(line).getTerminal1().getP() - network1.getLine(line).getTerminal1().getP()) / SENSI_CHANGE
line -> (network1.getLine(line).getTerminal1().getP() - network.getLine(line).getTerminal1().getP()) / SENSI_CHANGE
));

List<SensitivityFactor> factors = SensitivityFactor.createMatrix(SensitivityFunctionType.BRANCH_ACTIVE_POWER_1, List.of("l12", "l13", "l23", "l25", "l45", "l46", "l56"),
Expand Down Expand Up @@ -612,7 +612,7 @@ void testHvdcSensiVsc() {
Map<String, Double> loadFlowDiff = network.getLineStream().map(Identifiable::getId)
.collect(Collectors.toMap(
lineId -> lineId,
line -> (network.getLine(line).getTerminal1().getP() - network1.getLine(line).getTerminal1().getP()) / SENSI_CHANGE
line -> (network1.getLine(line).getTerminal1().getP() - network.getLine(line).getTerminal1().getP()) / SENSI_CHANGE
));

List<SensitivityFactor> factors = SensitivityFactor.createMatrix(SensitivityFunctionType.BRANCH_ACTIVE_POWER_1, List.of("l12", "l13", "l23"),
Expand All @@ -626,6 +626,38 @@ void testHvdcSensiVsc() {
assertEquals(loadFlowDiff.get("l23"), result.getBranchFlow1SensitivityValue("hvdc34", "l23"), LoadFlowAssert.DELTA_POWER);
}

@Test
void testHvdcSensiVsc2() {
SensitivityAnalysisParameters sensiParameters = createParameters(true, List.of("b1_vl_0", "b4_vl_0"), true);

// test injection increase on loads
Network network = HvdcNetworkFactory.createTwoCcLinkedByAHvdcVscWithGenerators();
network.getHvdcLine("hvdc34").setConvertersMode(HvdcLine.ConvertersMode.SIDE_1_RECTIFIER_SIDE_2_INVERTER);
network.getGeneratorStream().forEach(gen -> gen.setMaxP(5 * gen.getMaxP()));
runLf(network, sensiParameters.getLoadFlowParameters());

Network network1 = HvdcNetworkFactory.createTwoCcLinkedByAHvdcVscWithGenerators();
network1.getHvdcLine("hvdc34").setConvertersMode(HvdcLine.ConvertersMode.SIDE_1_RECTIFIER_SIDE_2_INVERTER);
network1.getHvdcLine("hvdc34").setActivePowerSetpoint(network1.getHvdcLine("hvdc34").getActivePowerSetpoint() + SENSI_CHANGE);
network1.getGeneratorStream().forEach(gen -> gen.setMaxP(5 * gen.getMaxP()));
runLf(network1, sensiParameters.getLoadFlowParameters());
Map<String, Double> loadFlowDiff = network.getLineStream().map(Identifiable::getId)
.collect(Collectors.toMap(
lineId -> lineId,
line -> (network1.getLine(line).getTerminal1().getP() - network.getLine(line).getTerminal1().getP()) / SENSI_CHANGE
));

List<SensitivityFactor> factors = SensitivityFactor.createMatrix(SensitivityFunctionType.BRANCH_ACTIVE_POWER_1, List.of("l12", "l13", "l23"),
SensitivityVariableType.HVDC_LINE_ACTIVE_POWER, List.of("hvdc34"),
false, ContingencyContext.all());

SensitivityAnalysisResult result = sensiRunner.run(network, factors, Collections.emptyList(), Collections.emptyList(), sensiParameters);

assertEquals(loadFlowDiff.get("l12"), result.getBranchFlow1SensitivityValue("hvdc34", "l12"), LoadFlowAssert.DELTA_POWER);
assertEquals(loadFlowDiff.get("l13"), result.getBranchFlow1SensitivityValue("hvdc34", "l13"), LoadFlowAssert.DELTA_POWER);
assertEquals(loadFlowDiff.get("l23"), result.getBranchFlow1SensitivityValue("hvdc34", "l23"), LoadFlowAssert.DELTA_POWER);
}

@Test
void testHvdcInjectionNotFound() {
testHvdcInjectionNotFound(true);
Expand Down