@@ -127,6 +127,16 @@ def handle_igm_ssh_vs_cgm_ssh_error(network_pre_instance: pypowsybl.network.Netw
127127 try :
128128 all_generators = network_pre_instance .get_elements (element_type = pypowsybl .network .ElementType .GENERATOR ,
129129 all_attributes = True ).reset_index ()
130+
131+ #remove generatiors missing regulation control from regulation control
132+ all_generators_missing_reg_but_try_reg = all_generators [((all_generators ["voltage_regulator_on" ] == True ) &
133+ (all_generators ["CGMES.RegulatingControl" ] == "" ))]
134+
135+ if not all_generators_missing_reg_but_try_reg .empty :
136+ logger .warning (f"Generators with regulation control missing but voltage_control on { len (all_generators_missing_reg_but_try_reg )} " )
137+ #setting generators to false that do not have regulation
138+ network_pre_instance .update_generators (id = all_generators_missing_reg_but_try_reg ["id" ].values .tolist (),voltage_regulator_on = [False ] * len (all_generators_missing_reg_but_try_reg ["id" ].values .tolist ()))
139+
130140 generators_mask = (all_generators ['CGMES.synchronousMachineOperatingMode' ].str .contains ('generator' ))
131141 not_generators = all_generators [~ generators_mask ]
132142 generators = all_generators [generators_mask ]
@@ -144,18 +154,18 @@ def handle_igm_ssh_vs_cgm_ssh_error(network_pre_instance: pypowsybl.network.Netw
144154 logger .warning (f"Found { len (curve_generators .index )} generators for "
145155 f"which p > max(reactive capacity curve(p)) or p < min(reactive capacity curve(p))" )
146156
147- # Solution 1: set max_p from curve max, it should contain p on target-p
157+ # Solution 1: set max_p from curve max, it should contain p on target-p. those generators are also removed from regulation control
148158 upper_limit_violated = curve_generators [(curve_generators ['max_p' ] > curve_generators ['curve_p_max' ])]
149159 if not upper_limit_violated .empty :
150160 logger .warning (f"Updating max p from curve for { len (upper_limit_violated .index )} generators" )
151161 upper_limit_violated ['max_p' ] = upper_limit_violated ['curve_p_max' ]
152- network_pre_instance .update_generators (upper_limit_violated [['id' , 'max_p' ]].set_index ('id' ))
162+ network_pre_instance .update_generators (upper_limit_violated [['id' , 'max_p' ]].assign ( voltage_regulator_on = False ). set_index ('id' ))
153163
154164 lower_limit_violated = curve_generators [(curve_generators ['min_p' ] < curve_generators ['curve_p_min' ])]
155165 if not lower_limit_violated .empty :
156166 logger .warning (f"Updating min p from curve for { len (lower_limit_violated .index )} generators" )
157167 lower_limit_violated .loc [:, 'min_p' ] = lower_limit_violated ['curve_p_min' ]
158- network_pre_instance .update_generators (lower_limit_violated [['id' , 'min_p' ]].set_index ('id' ))
168+ network_pre_instance .update_generators (lower_limit_violated [['id' , 'min_p' ]].assign ( voltage_regulator_on = False ). set_index ('id' ))
159169
160170 # Solution 2: discard generator from participating
161171 extensions = network_pre_instance .get_extensions ('activePowerControl' )
@@ -190,7 +200,7 @@ def handle_igm_ssh_vs_cgm_ssh_error(network_pre_instance: pypowsybl.network.Netw
190200 if not all_shunts_with_control_on_reg_missing .empty :
191201 logger .warning (f"Shunts with regulation control missing but voltage_control on { len (all_shunts_with_control_on_reg_missing )} " )
192202 #TODO set voltage_control_on to false. Atm try turning off
193- network_pre_instance .update_shunt_compensators (id = all_shunts_with_control_on_reg_missing .index .values .tolist (), connected = [False ]* len (all_shunts_with_control_on_reg_missing .index .values .tolist ()))
203+ network_pre_instance .update_shunt_compensators (id = all_shunts_with_control_on_reg_missing .index .values .tolist (), voltage_regulation_on = [False ]* len (all_shunts_with_control_on_reg_missing .index .values .tolist ()))
194204
195205
196206 except Exception as ex :
0 commit comments