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 small reference flow values instead of strict zero #828

Merged
merged 6 commits into from
Aug 31, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
public class DcSensitivityAnalysis extends AbstractSensitivityAnalysis<DcVariableType, DcEquationType> {

private static final double CONNECTIVITY_LOSS_THRESHOLD = 10e-7;
private static final double REFERENCE_FLOW_ZER0_THRESHOLD = 1e-13;

private static final class ComputedContingencyElement {

Expand Down Expand Up @@ -288,12 +289,26 @@ private void createBranchSensitivityValue(LfSensitivityFactor<DcVariableType, Dc
}
}

functionValue = fixZeroReferenceFlow(contingency, functionValue);

double unscaledSensi = unscaleSensitivity(factor, sensitivityValue);
if (!filterSensitivityValue(unscaledSensi, factor.getVariableType(), factor.getFunctionType(), parameters)) {
resultWriter.writeSensitivityValue(factor.getIndex(), contingency != null ? contingency.getIndex() : -1, unscaledSensi, unscaleFunction(factor, functionValue));
}
}

/**
annetill marked this conversation as resolved.
Show resolved Hide resolved
* Post contingency reference flow, that should be strictly zero, for numeric reason and because it is computed
* from shifting pre-contingency non zero flow, we cannot end up to a strict zero: so we convert to zero very
* small values.
*/
private static double fixZeroReferenceFlow(PropagatedContingency contingency, double functionValue) {
if (contingency != null) {
return Math.abs(functionValue) < REFERENCE_FLOW_ZER0_THRESHOLD ? 0 : functionValue;
}
return functionValue;
}

/**
* Calculate the sensitivity value for pre-contingency state only.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.powsybl.ieeecdf.converter.IeeeCdfNetworkFactory;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.extensions.HvdcAngleDroopActivePowerControlAdder;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.iidm.network.test.PhaseShifterTestCaseFactory;
import com.powsybl.loadflow.LoadFlowParameters;
import com.powsybl.openloadflow.OpenLoadFlowParameters;
Expand Down Expand Up @@ -2262,4 +2263,71 @@ void testPredefinedResults3() {
assertEquals(0, result.getBranchFlow1SensitivityValue("l23", "l23", "l12", SensitivityVariableType.TRANSFORMER_PHASE), LoadFlowAssert.DELTA_POWER);
assertEquals(Double.NaN, result.getBranchFlow1SensitivityValue("l23", "l23", "l23", SensitivityVariableType.TRANSFORMER_PHASE), LoadFlowAssert.DELTA_POWER);
}

/**
* NHV1_NHV1
* --------------------------
* / \
* NGEN --- NHV1 NHV2 --- NLOAD
* \ /
* ----------- NHV3 -----------
* NHV1_NHV2_1 NHV1_NHV2_2
*/
@Test
void testOneOfTwoSerialLinesContingency() {
Network network = EurostagTutorialExample1Factory.create();
network.getLine("NHV1_NHV2_1").remove();
Substation p3 = network.newSubstation()
.setId("P3")
.setCountry(Country.FR)
.add();
VoltageLevel vlhv3 = p3.newVoltageLevel()
.setId("VLHV3")
.setNominalV(380)
.setTopologyKind(TopologyKind.BUS_BREAKER)
.add();
vlhv3.getBusBreakerView().newBus()
.setId("NHV3")
.add();
network.newLine()
.setId("NHV1_NHV2_1_1")
.setVoltageLevel1("VLHV1")
.setBus1("NHV1")
.setVoltageLevel2("VLHV3")
.setBus2("NHV3")
.setR(3.0 / 2)
.setX(33.0 / 2)
.setB1(386E-6 / 4)
.setB2(386E-6 / 3)
.add();
network.newLine()
.setId("NHV1_NHV2_1_2")
.setVoltageLevel1("VLHV3")
.setBus1("NHV3")
.setVoltageLevel2("VLHV2")
.setBus2("NHV2")
.setR(3.0 / 2)
.setX(33.0 / 2)
.setB1(386E-6 / 4)
.setB2(386E-6 / 3)
.add();

SensitivityAnalysisParameters sensiParameters = createParameters(true, "VLLOAD_0");

List<SensitivityFactor> factors = List.of(new SensitivityFactor(
SensitivityFunctionType.BRANCH_ACTIVE_POWER_1,
"NHV1_NHV2_1_2",
SensitivityVariableType.INJECTION_ACTIVE_POWER,
"GEN",
false,
ContingencyContext.all())
);

List<Contingency> contingencies = List.of(Contingency.line("NHV1_NHV2_1_1"));

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

assertEquals(303.5d, result.getBranchFlow1FunctionReferenceValue("NHV1_NHV2_1_2"), LoadFlowAssert.DELTA_POWER);
assertEquals(0, result.getBranchFlow1FunctionReferenceValue("NHV1_NHV2_1_1", "NHV1_NHV2_1_2"), 0d); // strict zero and not anymore a small value
}
}