%pylab notebook

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


VS_m     = sqrt(2) * 200 # [V]
VS_angle = 0             # [rad]|[deg]
IS_m     = sqrt(2)*5     # [A]
IS_deg   = -36.87        # angle of IS in [deg]
IS_rad   = IS_deg/180*pi # angle of IS in [rad]
a        =   0.5
Req      =   0.20        # [Ohm]
Rc       = 300.0         # [Ohm]
Xeq      =   0.80        # [Ohm]
Xm       = 100.0         # [Ohm]

"""
Explanation: Description
The secondary winding of a real transformer has a terminal voltage of

$v_S(t) = \sqrt{2}\cdot 200 \sin(2\pi\cdot 60\,Hz\cdot t)\,V = 282.8 \sin(377t)\,V$. 

The turns ratio of the transformer is 

$100:200 \rightarrow a = 0.5$ .

If the secondary current of the transformer is 


$i_S(t) = \sqrt{2}\cdot 5 \sin(377t - 36.87°)\, A$.


What is the primary current of this transformer? 

What are its voltage regulation and efficiency?

The impedances of this transformer referred to the primary side are:
 $$R_{eq} = 0.20\,\Omega \qquad R_{C} = 300\,\Omega$$
 $$X_{eq} = 0.80\,\Omega \qquad X_{M} = 100\,\Omega$$
End of explanation
"""


VS = VS_m / sqrt(2) * (cos(VS_angle) + sin(VS_angle)*1j) # [V]
IS = IS_m / sqrt(2) * (cos(IS_rad) + sin(IS_rad)*1j)     # [A]
print('VS = {:>5.1f} V ∠{:>3.0f}°'.format(
            abs(VS), VS_angle))
print('IS = {:>5.1f} A ∠{:>3.2f}°'.format(
            abs(IS), (IS_deg)))

"""
Explanation: SOLUTION
The equivalent circuit of this transformer is shown below. (Since no particular equivalent circuit was specified, we are using the approximate equivalent circuit referred to the primary side.)
<img src="figs/FigC_2-18a.jpg" width="70%">
The secondary voltage and current are:
End of explanation
"""


VSp = a * VS    
print('VSp = {:.1f} V ∠{:.0f}°'.format(
            abs(VSp), VS_angle)) # the turns ratio has no effect on the angle

"""
Explanation: The secondary voltage referred to the primary side is:
$$\vec{V}'_S = a\vec{V}_S$$
End of explanation
"""


ISp = IS / a
print('ISp = {:.1f} A ∠{:.2f}°'.format(
            abs(ISp), IS_deg))  # the turns ratio has no effect on the angle

"""
Explanation: The secondary current referred to the primary side is:
$$\vec{I}'_S = \frac{\vec{I}_S}{a}$$
End of explanation
"""


VP = VSp + ISp * (Req + Xeq*1j)
VP_angle = arctan(VP.imag/VP.real)
print('VP = {:.1f} V ∠{:.1f}°'.format(
            abs(VP), degrees(VP_angle)))

"""
Explanation: The primary circuit voltage is given by:
$$\vec{V}P = \vec{V}'_S + \vec{I}'_S(R{eq} + jX_{eq})$$
End of explanation
"""


IC = VP / Rc
IM = VP / (Xm*1j)
Iex = IC + IM
Iex_angle = arctan(Iex.imag/Iex.real)
print('Iex = {:.2f} A ∠{:.1f}°'.format(
            abs(Iex), Iex_angle/pi*180))  # angle in [deg]

"""
Explanation: The excitation current of this transformer is:
$$\vec{I}_{EX} = \vec{I}_C + \vec{I}_M$$
End of explanation
"""


IP = ISp + Iex
IP_angle = arctan(IP.imag/IP.real)
print('VS = {:.1f} V ∠{:.1f}°'.format(
            abs(IP), IP_angle/pi*180)) # angle in [deg]
print('===================')

"""
Explanation: Therefore, the total primary current of this transformer is:
$$\vec{I}P = \vec{I}'_S + \vec{I}{EX}$$
End of explanation
"""


VR = (abs(VP) - a*abs(VS))/(a*abs(VS)) * 100
print('VR = {:.1f}%'.format(VR))
print('=========')

"""
Explanation: The voltage regulation of the transformer at this load is:
$$VR = \frac{V_P - aV_S}{aV_S} \cdot 100\%$$
End of explanation
"""


Pin = abs(VP) * abs(IP) * cos(VP_angle - IP_angle)
print('Pin = {:.0f} W'.format(Pin))

"""
Explanation: The input power to this transformer is:
$$P_{IN} = V_PI_P\cos\theta$$
End of explanation
"""


Pout = abs(VS) * abs(IS) * cos(VS_angle - IS_rad)
print('Pout = {:.0f} W'.format(Pout))

"""
Explanation: The output power from this transformer is:
$$P_{OUT} = V_SI_S\cos\theta$$
End of explanation
"""


eta = Pout / Pin * 100
print('η = {:.1f} %'.format(eta))
print('==========')

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


