#Variable declaration
kVA_A = 2500.0 #Rating of alternator A(kVA)
x_A = 8.0 #Reactance of alternator A(%)
kVA_B = 5000.0 #Rating of alternator B(kVA)
x_B = 6.0 #Reactance of alternator B(%)
kVA_CB = 150000.0 #Rating of circuit breaker(kVA)
kVA_T = 10000.0 #Rating of transformer(kVA)
x_T = 7.5 #Reactance of transformer(%)
V = 3300.0 #System voltage(V)
#Calculation
kVA_base = 10000.0 #Base kVA
X_A = kVA_base/kVA_A*x_A #Reactance of generator A(%)
X_B = kVA_base/kVA_B*x_B #Reactance of generator B(%)
X_eq = X_A*X_B/(X_A+X_B) #Combined reactance of A & B(%)
kVA_SC_G = kVA_base/X_eq*100 #Short-circuit kVA due to generators(kVA)
kVA_SC_T = kVA_base/x_T*100 #Short-circuit kVA due to grid supply(kVA)
X = (kVA_base*100/(kVA_CB-kVA_SC_G))-x_T #Reactance necessary to protect switchgear(%)
I_fl = kVA_base*1000/(3**0.5*V) #Full load current corresponding to 10000 kVA(A)
X_phase = X*V/(3**0.5*I_fl*100) #Actual value of reactance per phase(ohm)
#Result
print('Reactance necessary to protect the switchgear = %.3f ohm/phase' %X_phase)
#Variable declaration
X = 10.0 #Reactance of reactor(%)
kVA = 30000.0 #Rating of generator(kVA)
X_sc = 20.0 #Short-circuit reactance(%)
#Calculation
X_1 = 1.0/3*(X_sc+X) #Combined reactance of generator A,B,C & associated reactors(%)
X_2 = X_1+X #Combined reactance upto fault(%)
X_total_a = X_2/2.0 #Total reactance upto fault(%)
kVA_SC_a = 100/X_total_a*kVA #Short-circuit kVA(kVA)
X_total_b = 1.0/4*X_sc #Total reactance upto fault when E,F,G & H are short-circuited(%)
kVA_SC_b = 100/X_total_b*kVA #Short-circuit kVA(kVA)
#Result
print('Case(a): kVA developed under short-circuit when reactors are in circuit = %.f kVA' %kVA_SC_a)
print('Case(b): kVA developed under short-circuit when reactors are short-circuited = %.f kVA' %kVA_SC_b)
from sympy import Symbol,solve
#Variable declaration
kVA = 20000.0 #Rating of generator(kVA)
f = 50.0 #Frequency(Hz)
V = 11.0*10**3 #Voltage of generator(V)
X_G = 20.0 #Generator short-circuit reactance(%)
x = 60.0 #Reactance falls to 60% normal value
#Calculation
kVA_base = 20000.0 #Base kVA
X = Symbol('X') #Reactance of each reactors E,F,G & H(%)
X_AE = X+X_G #Reactances of A & E in series(%)
X_BF = X+X_G #Reactances of B & F in series(%)
X_CD = X+X_G #Reactances of C & D in series(%)
X_eq = X_AE*X_BF*X_CD/(X_BF*X_CD+X_AE*X_CD+X_AE*X_BF) #Combined reactances of 3 groups in parallel(%)
X_f = X_eq+X #Reactances of these groups to fault via tie-bar(%)
X_solve = solve(((100-x)/100*X_f)-6.66666666666667) #Solution of reactance of each reactors E,F,G & H(%)
X_sol = X_solve[0] #value of reactance of each reactors E,F,G & H(%)
I_fl = kVA_base*1000/(3**0.5*V) #Full load current corresponding to 20000 kVA & 11 kV(A)
X_ohm = X_sol*V/(3**0.5*100*I_fl) #Ohmic value of reactance X(ohm)
#Result
print('Reactance of each reactor = %.4f ohm' %X_ohm)
print('\nNOTE: Changes in the obtained answer from that of textbook is due to more precision here')
#Variable declaration
kVA_base = 10000.0 #Base kVA
V = 6.6*10**3 #Voltage of generator(V)
X_A = 7.5 #Reactance of generator A(%)
X_B = 7.5 #Reactance of generator B(%)
X_C = 10.0 #Reactance of generator C(%)
X_D = 10.0 #Reactance of generator D(%)
X_E = 8.0 #Reactance of reactor E(%)
X_F = 8.0 #Reactance of reactor F(%)
X_G = 6.5 #Reactance of reactor G(%)
X_H = 6.5 #Reactance of reactor H(%)
#Calculation
Z_1 = X_B*X_C/(X_H+X_B+X_C) #Impedance(%). Fig E2.7
Z_2 = X_H*X_C/(X_H+X_B+X_C) #Impedance(%). Fig E2.7
Z_3 = X_B*X_H/(X_H+X_B+X_C) #Impedance(%). Fig E2.7
Z_4 = Z_2+X_F #Impedance(%). Fig E2.8 & Fig 2.9
Z_5 = Z_3+X_E #Impedance(%). Fig E2.8 & Fig 2.9
Z_6 = X_D*Z_1/(X_D+Z_1+Z_4) #Impedance(%). Fig E2.10
Z_7 = X_D*Z_4/(X_D+Z_1+Z_4) #Impedance(%). Fig E2.10
Z_8 = Z_1*Z_4/(X_D+Z_1+Z_4) #Impedance(%). Fig E2.10
Z_9 = Z_7+X_G #Impedance(%). Fig E2.11 & Fig 2.12
Z_10 = Z_8+Z_5 #Impedance(%). Fig E2.11 & Fig 2.12
Z_11 = Z_9*Z_10/(Z_9+Z_10) #Impedance(%). Fig 2.12 & Fig 2.13
Z_12 = Z_6+Z_11 #Impedance(%). Fig 2.13
Z_eq = X_A*Z_12/(X_A+Z_12) #Final Impedance(%). Fig 2.13 & Fig 2.14
MVA_SC = kVA_base*100/(Z_eq*1000) #Instantaneous symmetrical short-circuit MVA for a fault at X(MVA)
#Result
print('Instantaneous symmetrical short-circuit MVA for a fault at X = %.f MVA' %MVA_SC)
print('\nNOTE: Changes in the obtained answer from that of textbook is due to more approximation in the textbook')