In order to get a load flow case with the P and Q flow between two busses at a particular level, do an iterative process:
- run load flow
- measure P and Q flow
- adjust P and Q for the generator
here is some sample code:
def dispatch_p_and_pf(p_setpoint, pf_setpoint, p_gen_bus, q_gen_bus, Q_from_bus, Q_to_bus, P_from_bus, P_to_bus):
# iteratively adjusts two machines in the load flow case, until the P and Q flows between the meas_bus and poc_bus match the setpoints.
# The machines at which P and Q are adjusted are allowed to be different, for cases where P is set by a generator and Q by a STATCOM
p_sched = p_setpoint
q_sched = default_p_sp *sqrt((1/pf_setpoint)**2 - 1) * np.sign(pf_setpoint)
count = 0
p_gen = p_sched
q_gen = q_sched
print('Perror \tQerror \tPctrl \tQctrl \tPgen \tQgen' )
while count < nbr_solve_iterations:
psspy.machine_chng_2(p_gen_bus,r"""1""",[_i,_i,_i,_i,_i,_i],[ p_gen,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f])
psspy.machine_chng_2(q_gen_bus,r"""1""",[_i,_i,_i,_i,_i,_i],[ _f,q_gen,q_gen,q_gen,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f])
psspy.fdns([0,2,0,0,0,0,99,0])
psspy.fdns([0,2,0,0,0,0,99,0])
ierr, p_control = psspy.brnmsc(P_from_bus, P_to_bus, '1','P')
ierr, q_control = psspy.brnmsc(Q_from_bus, Q_to_bus, '1','Q')
p_error = p_sched - p_control
q_error = q_sched - q_control
if abs(p_error) < error_tol and abs(q_error) < error_tol :
break # the systesm is now set up correctly
p_gen = p_gen + p_error
if p_gen > Pbase:
p_gen = Pbase
q_gen = q_gen + q_error
count +=1
print('%3.2f \t%3.2f \t%3.2f \t%3.2f \t%3.2f \t%3.2f' % (p_error, q_error, p_control, q_control, p_gen, q_gen))