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

Wrong function reference for BranchFlowPerPSTAngle factor #324

Merged
merged 5 commits into from
Jul 6, 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
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,25 @@ private void createBranchSensitivityValue(LfSensitivityFactor factor, DenseMatri
} else {
sensiValue = factor.getBaseSensitivityValue();
flowValue = factor.getFunctionReference();
boolean zeroSensiValue = false;
for (ComputedContingencyElement contingencyElement : contingencyElements) {
if (contingencyElement.getElement().getId().equals(functionBranchId)
|| contingencyElement.getElement().getId().equals(factor.getVariableId())) {
// the sensitivity on a removed branch is 0, the sensitivity if the variable was a removed branch is 0
double contingencySensitivity = p1.calculateSensi(contingenciesStates, contingencyElement.getContingencyIndex());
flowValue += contingencyElement.getAlphaForFunctionReference() * contingencySensitivity;
sensiValue += contingencyElement.getAlphaForSensitivityValue() * contingencySensitivity;
if (contingencyElement.getElement().getId().equals(functionBranchId)) {
// the monitored branch is in contingency, the sensitivity value equals to zero and its post-contingency flow
// equals to zero too.
sensiValue = 0d;
flowValue = 0d;
break;
}
double contingencySensitivity = p1.calculateSensi(contingenciesStates, contingencyElement.getContingencyIndex());
flowValue += contingencyElement.getAlphaForFunctionReference() * contingencySensitivity;
sensiValue += contingencyElement.getAlphaForSensitivityValue() * contingencySensitivity;
if (contingencyElement.getElement().getId().equals(factor.getVariableId())) {
// the equipment responsible for the variable is indeed in contingency, the sensitivity value equals to zero.
// No assumption about the reference flow on the monitored branch.
zeroSensiValue = true;
}
}
if (contingency != null && contingency.getHvdcIdsToOpen().contains(factor.getVariableId())) {
if ((contingency != null && contingency.getHvdcIdsToOpen().contains(factor.getVariableId())) || zeroSensiValue) {
sensiValue = 0d;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.powsybl.computation.local.LocalComputationManager;
import com.powsybl.contingency.*;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.test.PhaseShifterTestCaseFactory;
import com.powsybl.loadflow.LoadFlowParameters;
import com.powsybl.openloadflow.network.*;
import com.powsybl.openloadflow.sensi.*;
Expand Down Expand Up @@ -1801,4 +1802,19 @@ void testDanglingLineContingencyDistributedSlackOnGenerators() {
assertEquals(2.0624, finalP, LoadFlowAssert.DELTA_POWER);
assertEquals(0.1875, finalP - initialP, LoadFlowAssert.DELTA_POWER);
}

@Test
void contingencyOnPhaseTapChangerTest() {
Network network = PhaseShifterTestCaseFactory.create();
SensitivityAnalysisParameters parameters = createParameters(true, "VL1_0", true);
parameters.getLoadFlowParameters().setBalanceType(LoadFlowParameters.BalanceType.PROPORTIONAL_TO_GENERATION_P_MAX);
SensitivityFactorsProvider factorsProvider2 = n -> List.of(new BranchFlowPerPSTAngle(new BranchFlow("L1", "L1", "L1"),
new PhaseTapChangerAngle("PS1", "PS1", "PS1")));
List<Contingency> contingencies = List.of(new Contingency("PS1", new BranchContingency("PS1")));
SensitivityAnalysisResult result = sensiProvider.run(network, VariantManagerConstants.INITIAL_VARIANT_ID, factorsProvider2, contingencies,
parameters, LocalComputationManager.getDefault())
.join();
assertEquals(100.0, getContingencyFunctionReference(result, "L1", "PS1"), LoadFlowAssert.DELTA_POWER);
assertEquals(0.0, getContingencyValue(result, "PS1", "PS1", "L1"), LoadFlowAssert.DELTA_POWER);
}
}