%pylab notebook
%precision %.4g
import cmath

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


Vt   = 480       # [V]
PF   =   0.8
fse  =  60       # [Hz]
p    =   8.0
Pout = 400 * 746 # [W]
Xs   =   0.6     # [Ohm]

"""
Explanation: Description
Assume that the motor of Problem 5-1 is operating at rated conditions.
End of explanation
"""


Pin = Pout
il = Pin / (sqrt(3) * Vt * PF)
il # [A]

"""
Explanation: (a)

What are the magnitudes and angles of $\vec{E}_A$ and $\vec{I}_A$ , and $I_F$?

(b)
Suppose the load is removed from the motor. 

What are the magnitudes and angles of $\vec{E}_A$ and $\vec{I}_A$ now?

SOLUTION
(a)
The line current flow at rated conditions is:
$$I_L = \frac{P}{\sqrt{3}V_TPF}$$
End of explanation
"""


ia = il / sqrt(3)
ia # [A]

"""
Explanation: Because the motor is $\Delta$-connected, the corresponding phase current is:
End of explanation
"""


Ia_angle = arccos(PF)
Ia_angle /pi *180 # [degrees]

Ia = ia * (cos(Ia_angle) + sin(Ia_angle)*1j)
print('''
Ia = {:.0f} A ∠{:.2f}°
=================='''.format(abs(Ia), Ia_angle / pi *180))

"""
Explanation: The angle of the current is:
End of explanation
"""


EA = Vt - Xs * 1j * Ia
EA_angle = arctan(EA.imag/EA.real)
print('''
Ea = {:.0f} V ∠{:.1f}°
=================='''.format(abs(EA), EA_angle / pi *180))

"""
Explanation: The internal generated voltage $\vec{E}_A$ is:
$$\vec{E}A = \vec{V}\phi - jX_S\vec{I}_A$$
End of explanation
"""


If1 = 4 # [A]
Ea1 = 480 # [V]
Ea2 = abs(EA)
If2 = (Ea2/Ea1) * If1
print('''
If2 = {:.2f} A
============'''.format(If2))

"""
Explanation: The field current is directly proportional to $|\vec{E}_A|$, which = 480V when $I_F = 4 A$. The required field current is:
$$\frac{|\vec{E}{A2}|}{|\vec{E}{A1}|} = \frac{I_{F2}}{I_{F1}}$$
End of explanation
"""


delta_b = 0*pi/180 # [rad]
EA_b = abs(EA) *(cos(delta_b) + sin(delta_b)*1j)
EA_b_angle = arctan(EA_b.imag/EA_b.real)

Ia_b = (Vt - EA_b) / (Xs*1j)
Ia_b_angle = arctan(Ia_b.imag/Ia_b.real)  # poosible warning might occur because of division by zero

print('''
EA_b = {:.1f} ∠{:>2.0f}°
Ia_b = {:.1f} ∠{:>2.0f}°
=================='''.format(abs(EA_b), EA_b_angle/pi*180, 
                             abs(Ia_b), Ia_b_angle/pi*180))

"""
Explanation: (b)
When the load is removed from the motor the magnitude of $|\vec{E}_A|$ remains unchanged but the torque
angle goes to $\delta = 0°$ . The resulting armature current is:
$$\vec{I}A = \frac{\vec{V}\phi - \vec{E}_A}{jX_S}$$
End of explanation
"""


