@@ -147,23 +147,50 @@ public void apply(LoadFlowParameters.BalanceType balanceType) {
147147 shunt .setG (shunt .getG () - e .getValue ().getG ());
148148 shunt .setB (shunt .getB () - e .getValue ().getB ());
149149 }
150+ processLostPowerChanges (balanceType , true );
151+ }
152+
153+ /**
154+ * Process the power shifts due to the loss of loads, generators, and HVDCs.
155+ * @param balanceType the property defining how to manage active distribution.
156+ * @param updateAcQuantities a boolean to indicate if voltage/reactive dependent quantities should be updated or not.
157+ */
158+ public void processLostPowerChanges (LoadFlowParameters .BalanceType balanceType , boolean updateAcQuantities ) {
159+ processLostLoads (balanceType , updateAcQuantities );
160+ processLostGenerators (updateAcQuantities );
161+ processHvdcsWithoutPower ();
162+ }
163+
164+ private void processLostLoads (LoadFlowParameters .BalanceType balanceType , boolean updateAcQuantities ) {
150165 for (var e : lostLoads .entrySet ()) {
151166 LfLoad load = e .getKey ();
152167 LfLostLoad lostLoad = e .getValue ();
153168 PowerShift shift = lostLoad .getPowerShift ();
154169 load .setTargetP (load .getTargetP () - getUpdatedLoadP0 (load , balanceType , shift .getActive (), shift .getVariableActive (), lostLoad .getNotParticipatingLoadP0 ()));
155- load .setTargetQ (load .getTargetQ () - shift .getReactive ());
170+ if (updateAcQuantities ) {
171+ load .setTargetQ (load .getTargetQ () - shift .getReactive ());
172+ }
156173 load .setAbsVariableTargetP (load .getAbsVariableTargetP () - Math .abs (shift .getVariableActive ()));
157174 lostLoad .getOriginalIds ().forEach (loadId -> load .setOriginalLoadDisabled (loadId , true ));
158175 }
176+ }
177+
178+ private void processLostGenerators (boolean updateAcQuantities ) {
159179 Set <LfBus > generatorBuses = new HashSet <>();
160180 for (LfGenerator generator : lostGenerators ) {
181+ // DC and AC quantities
161182 generator .setTargetP (0 );
162183 generator .setInitialTargetP (0 );
163184 LfBus bus = generator .getBus ();
164185 generatorBuses .add (bus );
165186 generator .setParticipating (false );
166187 generator .setDisabled (true );
188+
189+ if (!updateAcQuantities ) {
190+ continue ;
191+ }
192+
193+ // Only AC quantities
167194 if (generator .getGeneratorControlType () != LfGenerator .GeneratorControlType .OFF ) {
168195 generator .setGeneratorControlType (LfGenerator .GeneratorControlType .OFF );
169196 bus .getGeneratorVoltageControl ().ifPresent (GeneratorVoltageControl ::updateReactiveKeys );
@@ -179,6 +206,12 @@ public void apply(LoadFlowParameters.BalanceType balanceType) {
179206 });
180207 }
181208 }
209+
210+ if (!updateAcQuantities ) {
211+ return ;
212+ }
213+
214+ // Only AC quantities
182215 for (LfBus bus : generatorBuses ) {
183216 if (bus .getGenerators ().stream ().noneMatch (gen -> gen .getGeneratorControlType () == LfGenerator .GeneratorControlType .VOLTAGE )) {
184217 bus .setGeneratorVoltageControlEnabled (false );
@@ -187,6 +220,9 @@ public void apply(LoadFlowParameters.BalanceType balanceType) {
187220 bus .setGeneratorReactivePowerControlEnabled (false );
188221 }
189222 }
223+ }
224+
225+ private void processHvdcsWithoutPower () {
190226 for (LfHvdc hvdc : hvdcsWithoutPower ) {
191227 hvdc .getConverterStation1 ().setTargetP (0.0 );
192228 hvdc .getConverterStation2 ().setTargetP (0.0 );
0 commit comments