%pylab notebook

"""
Explanation: Excercises Electric Machinery Fundamentals
Chapter 6
Problem 6-8
End of explanation
"""


R1  =  0.10   # [Ohm]
R20 =  0.07   # [Ohm]
Xm  = 10.0    # [Ohm]
X1  =  0.21   # [Ohm]
X20 =  0.21   # [Ohm]
Pmech = 500   # [W]
Pmisc =   0   # [W]
Pcore = 400   # [W]
Vphi  = 120   # [V]
n_sync = 1800 # [r/min]
w_sync = n_sync * 2*pi/60.0 # [rad/s]

"""
Explanation: Description
For the motor of Problem 6-5.

How much additional resistance (referred to the stator circuit) would it be necessary to add to the rotor circuit to make the maximum torque occur at starting conditions (when the shaft is not moving)? 
Plot the torque-speed characteristic of this motor with the additional resistance inserted.
End of explanation
"""


Zth = (Xm*1j * (R1 + X1*1j)) / (R1 + (X1+Xm)*1j)
Rth = real(Zth)
Xth = imag(Zth)

s_max = 1.0
R2 = s_max * sqrt(Rth**2 + (Xth + X20)**2)
print('R2 = {:.3f} Ω'.format(R2))

"""
Explanation: SOLUTION
To get the maximum torque at starting, the $s_\text{max}$ must be 1.00. Therefore,
$$s_\text{max} = \frac{R_2}{\sqrt{R_{TH}^2+(X_{TH}+X_2)^2}}$$
$R_2$ and $X_2$ are given which means we still need to determine $R_{TH}$ and $X_{TH}$ from:
$$Z_{TH} = \frac{jX_M(R_1+jX_1)}{R_1 + j(X_1+X_M)}$$
End of explanation
"""


dR2 = R2 - R20
print('''
dR2 = {:.3f} Ω
============='''.format(dR2))

s = linspace(0,50,51) / 50 # generate an array with 51 values between 0 and 50
s[0] = 0.001  # avoid division by zero

"""
Explanation: Since the existing resistance is $0.070\,\Omega$, the additional resistance to be added to the rotor circuit is:
End of explanation
"""


Vth = Vphi * ( Xm / sqrt(R1**2 + (X1 + Xm)**2) )
Zth = ((Xm*1j) * (R1 + X1*1j)) / (R1 + (X1 + Xm)*1j)
Rth = Zth.real
Xth = Zth.imag

"""
Explanation: Calculate the Thevenin voltage and impedance:
End of explanation
"""


n_m = (1 - s) * n_sync
tau_ind= (3 * Vphi**2 * R2/s) / (w_sync * ((Rth + R2/s)**2 + (Xth + X20)**2) )

rc('text', usetex=True)   # enable LaTeX commands for plot
title(r'\bf Induction Motor Torque-Speed Characteristic')
xlabel(r'$n_m$ [r/min]')
ylabel(r'$\tau_{ind}$ [Nm]')
plot(n_m, tau_ind,  linewidth = 2)
grid()

"""
Explanation: Now calculate the torque-speed characteristic for many slips between 0 and 1. Note that the first slip value is set to 0.001 instead of exactly 0 to avoid divide-by-zero problems.
End of explanation
"""


