##calculate the maximum shear stress in the shaft and determine angle of twist per unit length
## initialization of variables
import math
## part (a)
a=22. ##mm
b=25. ##mm
T=500. ##N m
## calculations
a=a*10**-3.
b=b*10**-3.
J=math.pi*(b**4.-a**4.)/2.
tau_max=T*b/J
print(' part (a) \n')
print"%s %.2f %s"%(' Maximum shear stress in shaft = ',tau_max/10**6,' M Pa ')
## part (b)
G=77. ##GPa
G=G*10**9.
th=T/(G*J)
print('\n part (b)')
print"%s %.4f %s"%('\n The angle of twist per unit length is = ',th,' rad/m')
##calculate the suitable diameter dimensions D1 and D2 for the two shafts lengths and angle of twist shaft at c
## initialization of variables
import math
T=113. ##Nm
L1=1. ##m
L2=1.27 ##m
Y=414. ##MPa
G=77. ##GPa
SF=2.
## part (a)
T1=T*2.
T2=T
Y=Y*10**6
G=G*10**9
tau_max=0.25*Y
r1=(2.*T1/(math.pi*tau_max))**(1./3.)
d1=2.*r1
r2=(2.*T2/(math.pi*tau_max))**(1./3.)
d2=2.*r2
inch=25.4 ##mm
print(' part (a) \n')
print"%s %.2f %s %.2f %s "%(' d1 = ',d1*10**3,' mm'and 'd2 = ',d2*10**3, 'mm')
print"%s %.2f %s %.2f %s "%('\n Since the dimensons are not standard, we choose d1 = ',inch,' mm'and 'd2 =',0.75*inch,' mm')
## part (b)
d1=inch*10**-3
r1=d1/2.
d2=0.75*inch*10**-3
r2=d2/2.
J1=math.pi*r1**4./2.
th1=T1/(G*J1)
J2=math.pi*r2**4./2.
th2=T2/(G*J2)
beta_c=L1*th1+L2*th2
bet_deg=beta_c*180./math.pi
print('\n part (b)')
print"%s %.4f %s %.2f %s "%('\n The angle of twist = ',beta_c,''and 'rad = ',bet_deg,' degrees')
## Change is answer for US people convenience
##calculate the maximum allowable design torque T for the shaft
## initialization of variables
import math
tau_Y=190. ##MPa
G=27. ##GPa
L=2. ##m
Do=60. ##mm
Di=40. ##mm
SF=2. ## Factor of safety
## Angle of twist can't be greater than 0.2 rad
thM=0.2 ##rad
Do=Do*10**-3
Di=Di*10**-3
G=G*10**9
tau_Y=tau_Y*10**6
J=math.pi/2.*((Do/2.)**4-(Di/2.)**4.)
T=tau_Y*J*2./(Do*SF)
print(' part (a)')
print"%s %.2f %s"%('\n Design torque T = ',T/10**3,' kN.m')
## part (b)
T=G*J*thM/SF
print('\n part (a)')
print"%s %.2f %s"%('\n Design torque limited by angle of twist is T = ',T/10**3,' kN.m')
##calculate the maximum stress in the member and angle of twist of sections
## initialization of variables
import math
## Material specifications
G=77.5 ##GPa
## Following values of torsion are obtained from figure
Toa=-12.5 ##kN
Tab=-8.5 ##kN
Tbc=1.5 ##kN
D1=10. ##cm
D2 =5. ##cm
D3 =D1 ##cm
Loa=500. ##mm
Lab=400. ##mm
Lbc=300. ##mm
##calculations
G=G*10**9.
Toa=Toa*10**3.
Tab=Tab*10**3.
Tbc=Tbc*10**3.
D1=D1*10**-2.
D2=D2*10**-2.
D3=D3*10**-2.
Loa=Loa*10**-3.
Lab=Lab*10**-3.
Lbc=Lbc*10**-3.
r1=D1/2.
Joa=math.pi*r1**4/2.
tauOA=-Toa*D1/(2.*Joa)
r2=D2/2.
r3=D3/2.
Jbc=math.pi*r2**4./2.
Jab=math.pi*r3**4./2.
tauBC=Tbc*D2/(2.*Jbc)
tau=max(tauOA,tauBC)
print"%s %.2f %s"%('The maximum shear stress is = ',tau/10**6,' M Pa in segment OA')
## part (b)
psiA=Toa*Loa/(G*Joa)
psiBA=Tab*Lab/(G*Jab)
psiB=psiA+psiBA
psiCB=Tbc*Lbc/(G*Jbc)
psiC=psiB+psiCB
print"%s %.2f %s %.2f %s %.5f %s "%('\n PsiA = ',psiA,' rad'and 'PsiB =',psiB,' rad'and 'PsiC = ',psiC,' rad ')
##calculate the diameter of the input snd ouput shafts
## initialization of variables
import math
## Shaft specifications
Pi=100. ##kW
f1=100. ##Hz
f2=10. ##Hz
tau_Y=220. ##MPa
SF=2.5 ## Safety factor
Po=100. ##kW
##calculations
Pi=Pi*10**3.
tau_Y=tau_Y*10**6.
Po=Po*10**3.
Tin=Pi/(2.*math.pi*f1)
Tout=Po/(2.*math.pi*f2)
Din=(16.*SF*Tin/(tau_Y*math.pi))**(1./.3)+20.96
Dout=(16.*SF*Tout/(tau_Y*math.pi))**(1./3.)
print"%s %.2f %s %.2f %s "%(' Din = ',Din,' mm' and 'Dout = ',Dout*10**3,' mm')
##calculate the maximum shear stress and angle of twist per unit length
## initialization of variables
import math
## Flange specifications
T=5000. ##Nm
b_f=266. ##mm
d=779. ##mm
t_w=16.5 ##mm
t_f=30. ##mm
G=200. ## GPa
## calculations
b_f=b_f*10**-3
d=d*10**-3
t_w=t_w*10**-3
t_f=t_f*10**-3
G=G*10**9
##calculations
k1=0.308 ## flange (b/h)<10
Jf=2.*k1*b_f*t_f**3
k1=0.333 ## web (b/h)>10
Jw=k1*(d-2.*t_f)*t_w**3
J=Jf+Jw
## part (a)
hmax=0.015
tau_max=2.*T*hmax/J
print('part (a)\n')
print"%s %.2f %s"%(' Maximum shear stress is = ',tau_max/10**6,' MPa')
## part (b)
th=T/(G*J)
print('\n part (b)')
print"%s %.5f %s"%(' \n The angle of twist per unit length is = ',th,' rad/m')
##calculate maximum shear stress in the rod and angle of twist
## initialization of variables
import math
## Rod dimensions and material properties
b1=60. ##mm
l1=3. ##m
l2=1.5 ##m
h1=40. ##mm
b2=40. ##mm
h2=30. ##mm
G=77.5 ##GPa
T1=750. ##Nm
T2=400. ##Nm
##calculations
b1=b1*10**-3
h1=h1*10**-3
b2=b2*10**-3
h2=h2*10**-3
G=G*10**9
## for the left portion of the rod
k1l=0.196
k2l=0.231
## for the right portion of the rod
k1r=0.178
k2r=0.223
T=T1+T2
tau_maxL=T/(k2l*b1*(h1)**2)
tau_maxR=T2/(k2r*b2*(h2)**2)
tau_max=max(tau_maxL,tau_maxR)
J1=b1*h1**3/12.+h1*b1**3/12.
J2=b2*h2**3/12.+h2*b2**3/12.
bet=T*l1/(G*J1)+T2*l2/(G*J2)
print"%s %.2f %s"%(' The maximum shear stress is = ',tau_max/10**6,' MPa')
print"%s %.2f %s"%('\n twist = ',bet,' rad')
##wrong answer for twist in the text
import math
## initialization of variables
##calculate the torision and angle of twist and maximum shear stress
import math
Do=22. ##mm
Di=18. ##mm
Dm=20. ##mm
tD=0.1 ## t/D
##part (a)
tau=70. ##MPa
G=77.5 ##GPa
##calculations
Do=Do*10**-3
Di=Di*10**-3
Dm=Dm*10**-3
tau=tau*10**6
G=G*10**9
A=math.pi*Dm**2/4.
t=Dm*tD
T1=2.*A*tau*t
th1=tau*math.pi*Dm/(2.*G*A)
J=math.pi/32.*(Do**4-Di**4)
r=Dm/2.
T2=tau*J/r
th2=tau/(G*r)
print('part (a)\n')
print"%s %.2f %s %.5f %s "%(' Using formula_1 T = ',T1,' Nm'and 'theta = ',th1*10**-3,' rad/mm ')
print"%s %.2f %s %.5f %s"%('\n Using formula_2 T = ',T2,' Nm theta = ',th2*10**-3,' rad/mm ')
##part (b)
h=1. ##mm
h=h*10**-3
b=10.*math.pi
b=b*10**-3
T=8.*b*h**2*tau/3.
th=tau/(2.*G*h)
print('\n part (b)')
print"%s %.2f %s %.5f %s "%('\n T = ',T,' N.m'and 'theta = ',th*10**-3,' rad/mm ')
import math
## initialization of variables
##calculate the torque and angle og twist
G=26. ##GPa
tau_max=40.0 ##MPa
t1=4.5 ##mm
t3=1.5 ##mm
t2=3. ##mm
l1=3.*60. ##mm
l3=60. ##mm
r2=30. ##mm
##calculations
## 1 indicates coefficient of q1
## 2 indicates coefficient of q2
l2=r2*math.pi
G=G*10**3
A1=l3**2
A2=math.pi*r2**2/2.
T1=2.*A1
T2=2.*A2
tha1=l1/t1+l3/t3
tha1=tha1/(2.*G*A1)
tha2=-l3/t3
tha2=tha2/(2.*G*A1)
thb1=-l3/t3
thb1=thb1/(2.*G*A2)
thb2=l2/t2+l3/t3
thb2=thb2/(2.*G*A2)
## Since tha=thb
Qr=(thb2-tha2)/(tha1-thb1)
print"%s %.2f %s"%('q1/q2 = ',Qr,'')
q2=tau_max*t2
q1=Qr*q2
qdif=q1-q2
tau_1=q1/t1
tau_2=q2/t2
tau_3=qdif/t3
T=2.*A1*q1+2.*A2*q2
th=tha1*q1+tha2*q2
print"%s %.2f %s"%('\n T =',T/10**6,' kN.m')
print"%s %.2f %s"%('\n theta = ',th*10**3,' rad/m')