Skip to content

Commit 1eaf8b1

Browse files
Refacto of processLostGenerators
Signed-off-by: Hadrien <[email protected]>
1 parent 33f85f8 commit 1eaf8b1

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

src/main/java/com/powsybl/openloadflow/network/LfContingency.java

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -178,37 +178,46 @@ private void processLostLoads(LoadFlowParameters.BalanceType balanceType, boolea
178178
private void processLostGenerators(boolean updateAcParameters) {
179179
Set<LfBus> generatorBuses = new HashSet<>();
180180
for (LfGenerator generator : lostGenerators) {
181+
// DC and AC parameters
181182
generator.setTargetP(0);
182183
generator.setInitialTargetP(0);
183184
LfBus bus = generator.getBus();
184185
generatorBuses.add(bus);
185186
generator.setParticipating(false);
186187
generator.setDisabled(true);
187-
if (updateAcParameters) {
188-
if (generator.getGeneratorControlType() != LfGenerator.GeneratorControlType.OFF) {
189-
generator.setGeneratorControlType(LfGenerator.GeneratorControlType.OFF);
190-
bus.getGeneratorVoltageControl().ifPresent(GeneratorVoltageControl::updateReactiveKeys);
191-
bus.getGeneratorReactivePowerControl().ifPresent(GeneratorReactivePowerControl::updateReactiveKeys);
192-
} else {
193-
bus.setGenerationTargetQ(bus.getGenerationTargetQ() - generator.getTargetQ());
194-
}
195-
if (generator instanceof LfStaticVarCompensator svc) {
196-
svc.getStandByAutomatonShunt().ifPresent(svcShunt -> {
197-
// it means that the generator in contingency is a static var compensator with an active stand by automaton shunt
198-
shuntsShift.put(svcShunt, new AdmittanceShift(0, svcShunt.getB()));
199-
svcShunt.setB(0);
200-
});
201-
}
188+
189+
if (!updateAcParameters) {
190+
continue;
191+
}
192+
193+
// Only AC parameters
194+
if (generator.getGeneratorControlType() != LfGenerator.GeneratorControlType.OFF) {
195+
generator.setGeneratorControlType(LfGenerator.GeneratorControlType.OFF);
196+
bus.getGeneratorVoltageControl().ifPresent(GeneratorVoltageControl::updateReactiveKeys);
197+
bus.getGeneratorReactivePowerControl().ifPresent(GeneratorReactivePowerControl::updateReactiveKeys);
198+
} else {
199+
bus.setGenerationTargetQ(bus.getGenerationTargetQ() - generator.getTargetQ());
200+
}
201+
if (generator instanceof LfStaticVarCompensator svc) {
202+
svc.getStandByAutomatonShunt().ifPresent(svcShunt -> {
203+
// it means that the generator in contingency is a static var compensator with an active stand by automaton shunt
204+
shuntsShift.put(svcShunt, new AdmittanceShift(0, svcShunt.getB()));
205+
svcShunt.setB(0);
206+
});
202207
}
203208
}
204-
if (updateAcParameters) {
205-
for (LfBus bus : generatorBuses) {
206-
if (bus.getGenerators().stream().noneMatch(gen -> gen.getGeneratorControlType() == LfGenerator.GeneratorControlType.VOLTAGE)) {
207-
bus.setGeneratorVoltageControlEnabled(false);
208-
}
209-
if (bus.getGenerators().stream().noneMatch(gen -> gen.getGeneratorControlType() == LfGenerator.GeneratorControlType.REMOTE_REACTIVE_POWER)) {
210-
bus.setGeneratorReactivePowerControlEnabled(false);
211-
}
209+
210+
if (!updateAcParameters) {
211+
return;
212+
}
213+
214+
// Only AC parameters
215+
for (LfBus bus : generatorBuses) {
216+
if (bus.getGenerators().stream().noneMatch(gen -> gen.getGeneratorControlType() == LfGenerator.GeneratorControlType.VOLTAGE)) {
217+
bus.setGeneratorVoltageControlEnabled(false);
218+
}
219+
if (bus.getGenerators().stream().noneMatch(gen -> gen.getGeneratorControlType() == LfGenerator.GeneratorControlType.REMOTE_REACTIVE_POWER)) {
220+
bus.setGeneratorReactivePowerControlEnabled(false);
212221
}
213222
}
214223
}

0 commit comments

Comments
 (0)