Skip to content

Commit

Permalink
Fix NPE on disconnected generator, in sensitivity analysis
Browse files Browse the repository at this point in the history
Signed-off-by: Sylvain Leclerc <sylvain.leclerc@rte-france.com>
  • Loading branch information
sylvlecl committed Apr 30, 2021
1 parent f1b6013 commit 36ab239
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,8 @@ public SensitivityFactorHolder readAndCheckFactors(Network network, Map<String,
checkRegulatingTerminal(network, variableId);
Terminal regulatingTerminal = getEquipmentRegulatingTerminal(network, variableId);
assert regulatingTerminal != null; // this cannot fail because it is checked in checkRegulatingTerminal
variableElement = lfNetwork.getBusById(regulatingTerminal.getBusView().getBus().getId());
Bus regulatedBus = regulatingTerminal.getBusView().getBus();
variableElement = regulatedBus != null ? lfNetwork.getBusById(regulatedBus.getId()) : null;
} else {
throw new PowsyblException("Variable type " + variableType + " not supported with function type " + functionType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,23 @@ void testBusVoltageOnAbsentBus() {
assertEquals("The bus ref for 'id' cannot be resolved.", e.getCause().getMessage());
}

@Test
void disconnectedGeneratorShouldBeSkipped() {
Network network = FourBusNetworkFactory.create();
SensitivityAnalysisParameters sensiParameters = createParameters(false, "b1_vl_0", true);
sensiParameters.getLoadFlowParameters().setBalanceType(LoadFlowParameters.BalanceType.PROPORTIONAL_TO_GENERATION_P_MAX);
//Disconnect g4 generator
network.getGenerator("g4").getTerminal().disconnect();

TargetVoltage targetVoltage = new TargetVoltage("g4", "g4", "g4");
BusVoltage busVoltage = new BusVoltage("b1", "b1", new IdBasedBusRef("b1"));
SensitivityFactorsProvider factorsProvider = n -> Collections.singletonList(new BusVoltagePerTargetV(busVoltage, targetVoltage));
SensitivityAnalysisResult result = sensiProvider.run(network, VariantManagerConstants.INITIAL_VARIANT_ID, factorsProvider, Collections.emptyList(),
sensiParameters, LocalComputationManager.getDefault())
.join();
assertTrue(result.getSensitivityValues().isEmpty());
}

@Test
void testBranchFunctionOutsideMainComponent() {
testBranchFunctionOutsideMainComponent(false);
Expand Down

0 comments on commit 36ab239

Please sign in to comment.