import math
#initialisation of variables
I_a = 10 *complex(math.cos(0),math.sin(0))
I_b = 10 *complex(math.cos(180 * math.pi / 180),math.sin(180 * math.pi / 180))
I_c = 0
a = 1.0 * complex(math.cos(120.0 * math.pi / 180),math.sin(120 * math.pi / 180))
#Calculations
#Phase 'a'
print('Phase a')
I_a0=(1.0/3)*(I_a+I_b+I_c)
I_a1=(1.0/3)*(I_a+a*I_b+a**2*I_c)
I_a2=(1.0/3)*(I_a+a**2*I_b+a*I_c)
print( "I_a0 = {0:.2f}".format(abs(I_a0.real)))
print("Angle = %.2f A " %(math.degrees(math.atan2(I_a0.imag,I_a0.real))))
print( "I_a1 = {0:.2f}".format(abs(I_a1.real)))
print("Angle = %.2f A " %(math.degrees(math.atan2(I_a1.imag,I_a1.real))))
print( "I_a2 = {0:.2f}".format(abs(I_a2.real)))
print("Angle = %.2f A\n " %(math.degrees(math.atan2(I_a2.imag,I_a2.real))))
#Phase 'b'
print('Phase b')
I_b0 = I_a0
I_b1=a**2*I_a1
I_b2=a*I_a2
#Results
print( "I_b0 = {0:.2f}".format(abs(I_b0.real)))
print("Angle = %.2f A " %(math.degrees(math.atan2(I_b0.imag,I_b0.real))))
print( "I_b1 = {0:.2f}".format(abs(I_b1.real)))
print("Angle = %.2f A " %(math.degrees(math.atan2(I_b1.imag,I_b1.real))))
print( "I_b2 = {0:.2f}".format(abs(I_b2.real)))
print("Angle = %.2f A\n " %(math.degrees(math.atan2(I_b2.imag,I_b2.real))))
#Phase 'c'
print('Phase c')
I_c0=I_a0
I_c1=a*I_a1
I_c2=a**2*I_a2
#Results
print( "I_c0 = {0:.2f}".format(abs(I_c0.real)))
print("Angle = %.2f A " %(math.degrees(math.atan2(I_c0.imag,I_c0.real))))
print( "I_c1 = {0:.2f}".format(abs(I_c1.real)))
print("Angle = %.2f A " %(math.degrees(math.atan2(I_c1.imag,I_c1.real))))
print( "I_c2 = {0:.2f}".format(abs(I_c2.real)))
print("Angle = %.2f A " %(math.degrees(math.atan2(I_c2.imag,I_c2.real))))
import math
#initialisation of variables
V_ab = 0.8 * complex(math.cos(82.8 * math.pi /180),math.sin(82.8 * math.pi / 180))
V_bc = 1.2 * complex(math.cos(-41.4 * math.pi /180),math.sin(-41.4 * math.pi / 180))
V_ca = 1 * complex(math.cos(180 * math.pi /180),math.sin(180 * math.pi / 180))
a = 1 * complex(math.cos(120 * math.pi / 180),math.sin(120 * math.pi / 180))
#Symmetrical components of line voltage
#math.since neutral connection is absent zero sequence components are absent
V_ab1=(1.0/3)*(V_ab+a*V_bc+a**2*V_ca)
V_ab2=(1.0/3)*(V_ab+a**2*V_bc+a*V_ca)
V_a1 = V_ab1 * complex(math.cos(-30 * math.pi / 180),math.sin(-30 * math.pi / 180))
V_a2 = V_ab2 * complex(math.cos(30 * math.pi / 180),math.sin(30 * math.pi / 180))
r = 1 * complex(math.cos(0),math.sin(0))
I_a1 = V_a1 / r
I_a2 = V_a2 / r
V_A1 = -1 *complex(V_a1)
V_A2 = complex(V_a2)
V_A = V_A1 + V_A2
V_B1 = a**2 * V_A1
V_B2 = a * V_A2
V_B = V_B1 + V_B2
V_C1 = a * V_A1
V_C2 = a**2 * V_A2
V_C = V_C1 + V_C2
V_AB = V_A - V_B
V_BC = V_B - V_C
V_CA = V_C - V_A
I_A = V_A / r
I_B = V_B / r
I_C = V_C / r
#Results
print('Line-neutral voltages')
print( "V_AB = {0:.2f}".format(abs(V_AB.real)))
print("Angle = %.2f per unit " %(math.degrees(math.atan2(V_AB.imag,V_AB.real))))
print( "V_BC = {0:.2f}".format(abs(V_BC.real)))
print("Angle = %.2f per unit " %(math.degrees(math.atan2(V_BC.imag,V_BC.real))))
print( "V_CA = {0:.2f}".format(abs(V_CA.real)))
print("Angle = %.2f per unit " %(math.degrees(math.atan2(V_CA.imag,V_CA.real))))
print('Line-line voltages')
print( "V_AB = {0:.2f}".format(abs(V_AB.real)/math.sqrt(3)))
print("Angle = %.2f per unit " %(math.degrees(math.atan2(V_AB.imag,V_AB.real))))
print( "V_BC = {0:.2f}".format(abs(V_BC.real)/math.sqrt(3)))
print("Angle = %.2f per unit " %(math.degrees(math.atan2(V_BC.imag,V_BC.real))))
print( "V_CA = {0:.2f}".format(abs(V_CA.real)/math.sqrt(3)))
print("Angle = %.2f per unit " %(math.degrees(math.atan2(V_CA.imag,V_CA.real))))
print('Line currents')
print( "I_A = {0:.2f}".format(abs(I_A.real)))
print("Angle = %.2f per unit " %(math.degrees(math.atan2(I_A.imag,I_A.real))))
print( "I_B = {0:.2f}".format(abs(I_B.real)))
print("Angle = %.2f per unit " %(math.degrees(math.atan2(I_B.imag,I_B.real))))
print( "I_C = {0:.2f}".format(abs(I_C.real)))
print("Angle = %.2f per unit " %(math.degrees(math.atan2(I_C.imag,I_C.real))))
import math
#initialisation of variables
def pucalc(pu_Z_given,base_kV_given,base_kV_new,base_kVA_new,base_kVA_given):
X11=(pu_Z_given * (base_kV_given/base_kV_new)**2 * (base_kVA_new/base_kVA_given))
return X11
#Given
P_g = 300e6
V_g = 20e3
X11_g = 0.20
l = 64
V_m = 13.2e3
P_m1 = 200e6
P_m2 = 100e6
X11_m = 0.20
T1_P = 350e6
T1_vht = 230e3
T1_vlt = 20e3
x_T1 = 0.10
T2_1_P = 100e6
T2_1_vht = 127e3
T2_1_vlt = 13.2e3
x_T2 = 0.10
x_line = 0.5#ohm per km
V_base = V_g
P_base = P_g
x0 = 0.05
x_cl = 0.4
x0_line = 1.5#ohm per km
#Calculations
T2_P = 3*T2_1_P
T2_vht = math.sqrt(3)*T2_1_vht
T2_vlt = T2_1_vlt
V_base_line = (T1_vht/T1_vlt)*V_base
V_base_m = V_base_line * (T2_vlt/T2_vht)
z_line_base = (V_base_line)**2/P_base
x_line_pu = x_line * l / z_line_base
x0_g = x0
x0_m1 = pucalc(x0,V_m,V_base_m,P_base,P_m1)
x0_m2 = pucalc(x0,V_m,V_base_m,P_base,P_m2)
Z_g = (V_g**2) / P_base
Z_m = (V_base_m)**2 / P_base
Zn_g = 3 * x_cl / Z_g
Zn_m = 3 * x_cl / Z_m
X_0 = x0_line * l / z_line_base
#Results
print(" Generator X0 = %.2f per unit" %x0_g)
print(" Motor 1 X0 = %.4f per unit" %x0_m1)
print(" Motor 2 X0 = %.4f per unit" %x0_m2)
print(" Generator base impedance = %.3f per unit" %Z_g)
print(" Motor base impedance = %.3f per unit" %Z_m)
print(" In generator 3Zn = %.3f per unit" %Zn_g)
print(" In motor 3Zn = %.3f per unit" %Zn_m)
print(" Transmission line X0 = %.4f per unit" %X_0)
#zero-sequence diagram is shown in xcos file