@@ -247,61 +247,59 @@ public static void addNetworkActionAssociatedWithHvdcRangeAction(Crac crac, Netw
247247
248248 String hvdcLineId = hvdcRangeAction .getNetworkElement ().getId ();
249249
250- Set <NetworkAction > acEmulationSwitchActionOnHvdcLine = crac .getNetworkActions ().stream ()
250+ Set <NetworkAction > acEmulationDeactivationActionOnHvdcLine = crac .getNetworkActions ().stream ()
251251 .filter (ra -> ra .getElementaryActions ().stream ().allMatch (action -> action instanceof HvdcAction ))
252- .filter (ra -> ra .getElementaryActions ().stream ().anyMatch (action ->
252+ .filter (ra -> ra .getElementaryActions ().stream ().allMatch (action ->
253253 ((HvdcAction ) action ).getHvdcId ().equals (hvdcLineId )
254254 )).collect (Collectors .toSet ());
255255
256256 HvdcAngleDroopActivePowerControl hvdcAngleDoopActivePowerControl = IidmHvdcHelper .getHvdcLine (network , hvdcLineId ).getExtension (HvdcAngleDroopActivePowerControl .class );
257257 if (hvdcAngleDoopActivePowerControl != null && hvdcAngleDoopActivePowerControl .isEnabled ()) {
258258 String networkActionId = String .format ("%s_%s" , "acEmulationDeactivation" , hvdcLineId );
259- if (acEmulationSwitchActionOnHvdcLine .isEmpty ()) {
259+ if (acEmulationDeactivationActionOnHvdcLine .isEmpty ()) {
260260 // create the network action using the adder
261- NetworkActionAdder acEmulationSwitchActionAdder = crac .newNetworkAction ()
261+ NetworkActionAdder acEmulationDeactivationActionAdder = crac .newNetworkAction ()
262262 .withId (networkActionId )
263263 .withOperator (hvdcRangeAction .getOperator ())
264- .newAcEmulationSwitchAction ()
264+ .newAcEmulationDeactivationAction ()
265265 .withNetworkElement (hvdcLineId )
266- .withActionType (ActionType .DEACTIVATE )
267266 .add ();
268- addAllUsageRuleNotInAuto (hvdcRangeAction , acEmulationSwitchActionAdder );
269- acEmulationSwitchActionAdder .add ();
267+ addAllUsageRuleNotInAuto (hvdcRangeAction , acEmulationDeactivationActionAdder );
268+ acEmulationDeactivationActionAdder .add ();
270269 } else {
271- NetworkAction acEmulationSwitchAction = acEmulationSwitchActionOnHvdcLine .iterator ().next ();
270+ NetworkAction acEmulationDeactivationAction = acEmulationDeactivationActionOnHvdcLine .iterator ().next ();
272271 hvdcRangeAction .getUsageRules ().stream ().forEach (
273- usageRule -> acEmulationSwitchAction .addUsageRule (usageRule )
272+ usageRule -> acEmulationDeactivationAction .addUsageRule (usageRule )
274273 );
275274 }
276275 }
277276 });
278277 }
279278
280279 // Add all the usage rule of the range action to the network action except if its in auto.
281- static void addAllUsageRuleNotInAuto (HvdcRangeAction hvdcRangeAction , NetworkActionAdder acEmulationSwitchActionAdder ) {
280+ static void addAllUsageRuleNotInAuto (HvdcRangeAction hvdcRangeAction , NetworkActionAdder acEmulationDeactivationActionAdder ) {
282281 hvdcRangeAction .getUsageRules ().forEach (
283282 usageRule -> {
284283 if (usageRule .getClass ().equals (OnInstantImpl .class )) {
285-
286- acEmulationSwitchActionAdder
284+ acEmulationDeactivationActionAdder
287285 .newOnInstantUsageRule ()
288286 .withInstant (usageRule .getInstant ().getId ())
289287 .add ();
290288 } else if (usageRule .getClass ().equals (OnConstraintImpl .class )) {
291289 OnConstraint <?> onConstraint = (OnConstraint <?>) usageRule ;
292- acEmulationSwitchActionAdder .newOnConstraintUsageRule ()
290+ acEmulationDeactivationActionAdder .newOnConstraintUsageRule ()
293291 .withInstant (onConstraint .getInstant ().getId ())
294292 .withCnec (onConstraint .getCnec ().getId ())
295293 .add ();
296294 } else if (usageRule .getClass ().equals (OnContingencyStateImpl .class )) {
297295 OnContingencyState onContingencyState = (OnContingencyState ) usageRule ;
298- acEmulationSwitchActionAdder .newOnContingencyStateUsageRule ()
296+ acEmulationDeactivationActionAdder .newOnContingencyStateUsageRule ()
299297 .withContingency (onContingencyState .getContingency ().getId ())
300298 .withInstant (onContingencyState .getInstant ().getId ())
301299 .add ();
302300 } else if (usageRule .getClass ().equals (OnFlowConstraintInCountryImpl .class )) {
303301 OnFlowConstraintInCountry onFlowConstraintInCountry = (OnFlowConstraintInCountry ) usageRule ;
304- acEmulationSwitchActionAdder .newOnFlowConstraintInCountryUsageRule ()
302+ acEmulationDeactivationActionAdder .newOnFlowConstraintInCountryUsageRule ()
305303 .withCountry (onFlowConstraintInCountry .getCountry ())
306304 .withInstant (onFlowConstraintInCountry .getInstant ().getId ())
307305 .withContingency (onFlowConstraintInCountry .getContingency ().get ().getId ())
@@ -321,18 +319,18 @@ static void updateHvdcRangeActionInitialSetpoint(Crac crac, Network network, Rao
321319 if (!hvdcRangeActionOnAcEmulationHvdcLinecrac .isEmpty ()) {
322320 // Run load flow to update flow on all the line of the network
323321 LoadFlow .find (raoParameters .getExtension (OpenRaoSearchTreeParameters .class ).getLoadFlowAndSensitivityParameters ().getLoadFlowProvider ()).run (network , raoParameters .getExtension (OpenRaoSearchTreeParameters .class ).getLoadFlowAndSensitivityParameters ().getSensitivityWithLoadFlowParameters ().getLoadFlowParameters ());
324-
325- network .getHvdcLines ().forEach (hvdcLine -> {
322+ hvdcRangeActionOnAcEmulationHvdcLinecrac .stream ().forEach (hvdcRangeAction -> {
323+ String hvdcLineId = hvdcRangeAction .getNetworkElement ().getId ();
324+ HvdcLine hvdcLine = IidmHvdcHelper .getHvdcLine (network , hvdcLineId );
326325 double activePowerSetpoint = computeFlowOnHvdcLine (hvdcLine );
327- hvdcLine .setConvertersMode (activePowerSetpoint > 0 ? HvdcLine .ConvertersMode .SIDE_1_RECTIFIER_SIDE_2_INVERTER : HvdcLine .ConvertersMode .SIDE_1_INVERTER_SIDE_2_RECTIFIER );
328- hvdcLine .setActivePowerSetpoint (Math .abs (activePowerSetpoint ));
326+ // is NaN if the line is disconnected
327+ if (activePowerSetpoint != Double .NaN ) {
328+ hvdcLine .setConvertersMode (activePowerSetpoint > 0 ? HvdcLine .ConvertersMode .SIDE_1_RECTIFIER_SIDE_2_INVERTER : HvdcLine .ConvertersMode .SIDE_1_INVERTER_SIDE_2_RECTIFIER );
329+ hvdcLine .setActivePowerSetpoint (Math .abs (activePowerSetpoint ));
330+ hvdcRangeAction .setInitialSetpoint (activePowerSetpoint );
331+ }
329332 });
330333
331- // Update all the initial setpoint
332- hvdcRangeActionOnAcEmulationHvdcLinecrac
333- .forEach (hvdcRangeAction -> {
334- hvdcRangeAction .setInitialSetpoint (IidmHvdcHelper .getCurrentSetpoint (network , hvdcRangeAction .getNetworkElement ().getId ()));
335- });
336334 }
337335 }
338336}
0 commit comments