phase shift transformer modelling PSS/E
Hi,
I working on python script to change phase shifter taps for a transformer, from -20 to +20 degrees. The idea is to perform a sweep of angles to see the flow change for each tap movement, I don't want to use automatic tap position option in PSS/E. I am changing winding angle for the PST. Is this approach correct for simulating PST by changing winding angle for symmetrical PST behavior simulation? Thank you. So my script looks like this:
import psspy
import csv
import time
# PSS/E default constants
_i = psspy._i
_f = psspy._f
_s = psspy._s
# --- User Input for Transformer Angle Range ---
try:
start_angle = float(input("Enter the starting angle (degrees): "))
end_angle = float(input("Enter the ending angle (degrees): "))
step = float(input("Enter the angle step size (degrees): "))
if step <= 0:
raise ValueError("Step size must be positive.")
if start_angle > end_angle:
raise ValueError("Start angle must be less than or equal to end angle.")
except ValueError as e:
print(f"Error: {e}. Using default values: start=0, end=30, step=1")
start_angle, end_angle, step = -20, +20, 1
# --- User Input for Transformer Node Numbers ---
try:
from_bus = int(input("Enter the 'from' bus number: "))
to_bus = int(input("Enter the 'to' bus number: "))
if from_bus <= 0 or to_bus <= 0:
raise ValueError("Bus numbers must be positive integers.")
except ValueError as e:
print(f"Error: {e}. Using default bus numbers: from=1, to=2")
from_bus, to_bus = 1, 2
# --- CSV File Setup ---
timestamp = time.strftime("%Y%m%d_%H%M%S")
csv_filename = f"xfmr_{from_bus}_{to_bus}_report_{timestamp}.csv"
csv_headers = ['Angle (deg)', 'Bus Number', 'Voltage (pu)', 'Angle (deg)', 'P (MW)', 'Q (MVAR)']
with open(csv_filename, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(csv_headers)
print(f"\nRunning transformer angle sweep: {start_angle}° to {end_angle}° (step={step})")
print(f"Transformer: From bus {from_bus} to bus {to_bus}")
print(f"Results will be saved to {csv_filename}\n")
# --- Main Loop ---
for angle in range(int(start_angle), int(end_angle + step), int(step)):
print(f"Processing angle = {angle}°...")
# Apply angle to both windings (optional depending on model)
psspy.two_winding_chng_6(from_bus, to_bus, r"""1""",
[_i]*16,
[_f]*5 + [angle] + [_f]*15,
[_f]*12, _s, _s)
psspy.two_winding_chng_6(from_bus, to_bus, r"""2""",
[_i]*16,
[_f]*5 + [angle] + [_f]*15,
[_f]*12, _s, _s)
# Solve power flow
psspy.fnsl([0, 0, 0, 1, 0, 0, 99, 0])
# Read voltage and angle at 'to' bus
ierr, voltage = psspy.busdat(to_bus, 'PU')
ierr, angle_deg = psspy.busdat(to_bus, 'ANGLED')
# --- Get P, Q flow through transformer ---
# Assume ID='1' unless you use another ID
tx_id = '1'
ierr_p, p_mw = psspy.brnmsc(from_bus, to_bus, tx_id, 'P')
ierr_q, q_mvar = psspy.brnmsc(from_bus, to_bus, tx_id, 'Q')
if ierr_p != 0 or ierr_q != 0:
print(f"Warning: Couldn't read P or Q at angle {angle}")
p_mw, q_mvar = 0.0, 0.0
# Save to CSV
with open(csv_filename, 'a', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow([angle, to_bus, voltage, angle_deg, round(p_mw, 3), round(q_mvar, 3)])
print(f"Angle {angle}° completed.\n")
print("✅ All angles processed!")
add a comment