%pylab notebook

"""
Explanation: Excercises Electric Machinery Fundamentals
Chapter 2
Problem 2-11
End of explanation
"""


Sbase = 100e6 # [VA]
Vp0   = 230e3 # [V]
Vs0   = 115e3 # [V]

Rc_pu  = 100.0
Xm_pu  =  20.0
Req_pu =   0.015
Xeq_pu =   0.06

"""
Explanation: Description
A 100-MVA 230/115-kV $\Delta$-Y three-phase power transformer has a per-unit resistance of 0.015 pu and a per-unit reactance of 0.06 pu. The excitation branch elements are $R_C =100\,pu$ and $X_M = 20\,pu$.
End of explanation
"""


Sload = 80e6  # [VA]
PF    = 0.8
Vls_a = Vs0

Ils_a = Sload / (sqrt(3)*Vls_a)
print('Ils_a = {:.0f} A'.format(Ils_a))

"""
Explanation: (a)
If this transformer supplies a load of 80 MVA at 0.8 PF lagging.

draw the phasor diagram of one phase of the transformer.

(b)

What is the voltage regulation of the transformer bank under these conditions?

(c)

Sketch the equivalent circuit referred to the low-voltage side of one phase of this transformer.
Calculate all the transformer impedances referred to the low-voltage side.

(d)

Determine the losses in the transformer and the efficiency of the transformer under the conditions of part (b).

SOLUTION
(a)
The transformer supplies a load of 80 MVA at 0.8 PF lagging. Therefore, the secondary line current of the transformer (referred to the secondary side) is:
$$I_{LS} = \frac{S_\text{load}}{\sqrt{3}V_{LS}}$$
End of explanation
"""


Vls_base = Vs0

Ils_base_a = Sbase / (sqrt(3)*Vls_base)
print('Ils_base_a = {:.0f} A'.format(Ils_base_a))

"""
Explanation: The base apparent power is $S_\text{base} = 100\,MVA$ , and the base line voltage on the secondary side is $V_{LS_\text{base}} = 115\,kV$ , so the base value of the secondary line current is:
$$I_{LS_\text{base}} = \frac{S_\text{base}}{\sqrt{3}V_{LS_\text{base}}}$$
End of explanation
"""


Ils_pu_a = Ils_a / Ils_base_a
ILS_pu_a_angle = -arccos(PF)
ILS_pu_a = Ils_pu_a * (cos(ILS_pu_a_angle) + sin(ILS_pu_a_angle)*1j)

print('ILS_pu_a = {:.1f} ∠{:.2f}°'.format(
            abs(ILS_pu_a), ILS_pu_a_angle/pi*180))

"""
Explanation: so the per-unit secondary current is:
$$\vec{I}{LS{pu}} = \frac{\vec{I}{LS}}{I{LS_\text{base}}}$$
End of explanation
"""


VS_pu = 1.0                                    
Zeq_pu = Req_pu + Xeq_pu*1j      

VP_pu = VS_pu + ILS_pu_a*Zeq_pu
VP_pu_angle = arctan(VP_pu.imag/VP_pu.real)
print('VS_pu = {:.3f} ∠{:.1f}°'.format(
           abs(VP_pu), VP_pu_angle/pi*180))

"""
Explanation: The per-unit phasor diagram is shown below:
<img src="figs/Problem_2-11a.jpg" width="50%">
(b)
The per-unit primary voltage of this transformer is:
$$\vec{V}P = \vec{V}_S + \vec{I}Z\text{EQ}$$
End of explanation
"""


VR = (abs(VP_pu) - abs(VS_pu)) / abs(VS_pu) * 100
print('''
VR = {:.1f}%
=========
'''.format(VR))

"""
Explanation: and the voltage regulation is:
$$VR = \frac{V_P - V_S}{V_S} \cdot 100\%$$
End of explanation
"""


Vphis_base = Vls_base / sqrt(3)
print('Vphi_base = {:.1f} kV'.format(Vphis_base/1000))

"""
Explanation: (c)
The secondary side of this transfer is Y-connected, so the base phase voltage of the low voltage (secondary) side of this transformer is:
$$V_{\phi S_\text{base}} = \frac{V_{LS_\text{base}}}{\sqrt{3}}$$
End of explanation
"""


Zbase = 3 * Vphis_base**2 / Sbase
print('Zbase = {:.0f} Ω'.format(Zbase))

"""
Explanation: The base impedance of the transformer referred to the low-voltage side is:
$$Z_\text{base} = \frac{3V_{\phi S_\text{base}}^2}{S_\text{base}}$$
End of explanation
"""


Req = Req_pu*Zbase
Xeq = Xeq_pu*Zbase
Rc = Rc_pu*Zbase
Xm = Xm_pu*Zbase

print('''
Req,s = {:.2f} Ω    Xeq,s = {:.2f}  Ω
Rc,s  = {:.1f} kΩ    Xm,s = {:.2f} kΩ
==================================
'''.format(Req, Xeq, Rc/1000, Xm/1000))

"""
Explanation: Each per-unit impedance is converted to actual ohms referred to the low-voltage side by multiplying it by this base impedance. 
The resulting equivalent circuit is shown below:
<img src="figs/Problem_2-11b.jpg" width="60%">
End of explanation
"""


Peq_pu = abs(ILS_pu_a)**2 *Req_pu
print('Peq_pu = {:.4f}'.format(Peq_pu))

"""
Explanation: (d)
The per-unit losses in the series resistance are:
$$P_\text{EQ} = I^2R_\text{EQ}$$
End of explanation
"""


Peq = Sbase * Peq_pu
print('''
Peq = {:.2f} MW
=============
'''.format(Peq/1e6))

"""
Explanation: and the actual losses in the series resistance are:
$$P_\text{EQ} = S_\text{base}P_{\text{EQ}_\text{pu}}$$
End of explanation
"""


Rex_pu = Rc_pu

Pex_pu = abs(VP_pu)**2 / Rex_pu
print('Pex_pu = {:.4f}'.format(Pex_pu))

"""
Explanation: The per-unit losses in the excitation branch are:
$$P_{\text{EX}\text{pu}} = \frac{V^2}{R\text{EX}}$$
End of explanation
"""


Pex = Sbase*Pex_pu
print('''
Pex = {:.2f} MW
=============
'''.format(Pex/1e6))

"""
Explanation: and the actual losses in the excitation branch are:
$$P_{EX} = S_{base}P_{EX,pu}$$
End of explanation
"""


Pload_pu = PF*Sload/Sbase
print('Pload_pu = {:.2f}'.format(Pload_pu))

"""
Explanation: The per-unit power supplied to the load:
$$P_{\text{load}\text{pu}} = \frac{P\text{load}}{S_\text{base}}= \frac{PF  \cdot S \text{load}}{S\text{base}}$$
End of explanation
"""


Pin_pu= Pload_pu + Peq_pu + Pex_pu
Pout_pu = Pload_pu
eta = Pout_pu/Pin_pu * 100
print('''
η = {:.1f} %
==========
'''.format(eta))

"""
Explanation: Therefore, the transformer’s efficiency is:
$$\eta = \frac{P_{OUT}}{P_{IN}} \cdot 100\%$$
End of explanation
"""


