%pylab notebook

"""
Explanation: Excercises Electric Machinery Fundamentals
Chapter 2
Problem 2-1
<hr>

Preface:
The solution given here is based on the incorrect voltage ratio as given in text in the book. The mistake is that the author of the book was basing the turns-ratio on the voltage levels under load. This means that the internal losses (i.e., voltage drops)  are included in the turns-ratio $a$ which normally should represent the physical turns-ratio $n$, i.e., at no-load.
I've decided to provide the solution which is based on the wrong 8000/277 turns ratio anyway so that you can compare this with the calculations you have done so far. In addition I've created a corrected version Problem_2-01_corrected.ipynb which uses the correct turns-ratio $n$ of 8000/283 (the correct no-load voltage is actually calculated in part (c) here).
<hr>
End of explanation
"""


RP = 5.0      #[Ohm] 
RS = 0.005    #[Ohm]
XP = 6.0j     #[Ohm]
XS = 0.006j   #[Ohm] 
RC = 50e3     #[Ohm]
XM = 10e3j    #[Ohm]

V_high = 8000 #[V]
V_low  = 277  #[V]
S = 100e3     #[VA]

"""
Explanation: Description
A 100-kVA 8000/277-V distribution transformer has the following resistances and reactances:
$R_P = 5\,\Omega \qquad  R_S = 0.005\,\Omega$
$X_P = 6\,\Omega \qquad X_S = 0.006\,\Omega$
$R_C = 50\,k\Omega  \qquad X_M = 10\,k\Omega$
End of explanation
"""


a = V_high/V_low
print('a = {:.2f}'.format(a))

"""
Explanation: The excitation branch impedances are given referred to the high-voltage side of the transformer.
(a)

Find the equivalent circuit of this transformer referred to the low-voltage side.

(b)

Find the per-unit equivalent circuit of this transformer.

(c)
Assume that this transformer is supplying rated load at 277 V and 0.85 PF lagging.

What is this transformer’s input voltage? 
What is its voltage regulation?

(d)

What are the copper losses and core losses in this transformer under the conditions of part (c)?

(e)

What is the transformer’s efficiency under the conditions of part (c)?

SOLUTION
(a)
The turns ratio $a$ of this transformer is
End of explanation
"""


R_P = RP / a**2
X_P = XP / a**2
print('R_P = {:.3f} Ω'.format(R_P))
print('X_P = {:.4f} Ω'.format(abs(X_P)))

"""
Explanation: Therefore, the primary impedances referred to the low voltage (secondary) side are:
$$R_P' = \frac{R_P}{a^2}$$
$$X_P' = \frac{X_P}{a^2}$$
End of explanation
"""


R_C = RC / a**2
X_M = XM / a**2
print('R_C = {:.0f} Ω'.format(R_C))
print('X_M = {:.0f} Ω'.format(abs(X_M)))

"""
Explanation: and the excitation branch elements referred to the secondary side are:
$$R_C' = \frac{R_C}{a^2}$$
$$X_M' = \frac{X_M}{a^2}$$
End of explanation
"""


S_base = 100e3  #[VA]
V_base = 277.0  #[V]

"""
Explanation: The resulting equivalent circuit is:
<img src="figs/Problem_2-01a.jpg" width="70%">
(b)
The rated kVA of the transformer is 100 kVA, and the rated voltage on the secondary side is 277 V
End of explanation
"""


I_base = S_base / V_base
print('I_base = {:.0f} A'.format(I_base))

"""
Explanation: So the rated current $I_\text{base}$ in the secondary side is:
End of explanation
"""


Z_base = V_base / I_base
print('Z_base = {:.3f} Ω'.format(Z_base))

"""
Explanation: Therefore, the base impedance on the primary side is:
$$Z_{base} = \frac{V_{base}}{I_{base}}$$
End of explanation
"""


Req = RP/a**2 + RS          #[Ohm]
Xeq = XP/a**2 + XS          #[Ohm]
print('Req = {:.3f} Ω'.format(Req))
print('Xeq = {:.4f} Ω'.format(Xeq))

"""
Explanation: Since $Z_{pu} = Z_\text{actual} / Z_\text{base}$
The resulting per-unit equivalent circuit is as shown below:
<img src="figs/Problem_2-01b.jpg" width="70%">
(c)
To simplify the calculations, use the simplified equivalent circuit referred to the secondary side of the transformer:
End of explanation
"""


VS = 277  # [V]
PF = 0.85          

"""
Explanation: <img src="figs/Problem_2-01c.jpg" width="70%">
And the transformer is supplying rated load at 277V and 0.85PF lagging.
End of explanation
"""


Is = S / abs(VS)                            # absolute value of IS [A]
IS_angle = -arccos(PF)                      # angle of IS [rad]
IS = Is*cos(IS_angle) + Is*sin(IS_angle)*1j # value of IS [A]
print('IS = {:.0f} A ∠{:.1f}°'.format(*(abs(IS), degrees(IS_angle))))

"""
Explanation: The secondary current $I_S$ in this transformer is:
End of explanation
"""


V_P = VS + (Req + Xeq)*IS
print('V_P = {:.0f} V ∠{:.1f}°'.format(*(abs(V_P), angle(V_P, deg=True))))   

"""
Explanation: Therefore, the primary voltage on this transformer (referred to the secondary side) is:
$$V_P' = V_S + (R_{EQ}+jX_{EQ})I_S$$
End of explanation
"""


VR = (abs(V_P)-abs(VS))/abs(VS) * 100
print('VR = {:.2f} %'.format(VR))

"""
Explanation: The voltage regulation $VR$ of the transformer under these conditions is:
End of explanation
"""


P_out = S * PF                              
P_cu = abs(IS)**2 * Req
P_core = abs(V_P)**2 / R_C
print('P_OUT  = {:>6.1f} kW'.format(P_out/1000))
print('P_CU   = {:>6.1f} W'.format(P_cu))
print('P_core = {:>6.1f} W'.format(P_core))

"""
Explanation: (d)
Under the conditions of part (c) the transformer’s output power copper losses $P_{OUT}$ and core losses $P_{CU}$ are:
$$P_{OUT} = S \cos\theta$$
$$P_{CU} = (I_S)^2R_{EQ}$$
$$P_{core} = \frac{V_P'^2}{R_C}$$
End of explanation
"""


eta = P_out/ (P_out + P_cu + P_core) * 100
print('η = {:.1f} %'.format(eta))

"""
Explanation: (e)
The efficiency of this transformer is:
$$\eta = \frac{P_{OUT}}{P_{OUT}+P_{CU}+P_\text{core}} \cdot 100\,\%$$
End of explanation
"""


