I usually do for loops to stop every time step if I want to return values while a simulation is still running.
For this instance, I return the bus frequency value for every timestep.
ini_time = 1
end_time = 60
# Freq Channel
psspy.bus_frequency_channel([1,6365],r"""6365_frequency""")
ierr, rval = psspy.chnval(1)
frequency = []
# Define time steps
time_step_psse = psspy.dsrval('DELT',)[1]
time_steps_pre_simul = int(math.ceil((ini_time)/(psspy.dsrval('DELT',)[1])))
time_steps_post_simul = int(math.ceil((end_time - ini_time)/(psspy.dsrval('DELT',)[1])))
for k in range(time_steps_pre_simul - 2):
# simulation
psspy.run(0, psspy.dsrval('DELT',)[1]*(k+1), 1,1,0)
# read and write freq
freq_val = psspy.chnval(1)[1]
frequency.append(((freq_val+1)*60))
## Fault simulation
psspy.run(0, ini_time,1,1,0)
psspy.dist_machine_trip(trip_machine,r"""1""")
## Post fault simulation
for i in range(time_steps_post_inject - 2):
psspy.run(0, ini_time+psspy.dsrval('DELT',)[1]*(i+1), 1,1,0)
freq_val = psspy.chnval(1)[1]
frequency.append(((freq_val+1)*60))
This worked for me.
What is the reason to do this?
I need to disconnect generator when it become out of step