import math
#calculate diameterof the bar in all cases
import numpy
from numpy.linalg import inv
sigmayp=350. ##MPa
sigma3=0.
M=8. ##kN
Mt=24. ##kNm
N=2.
v=0.3
## sigma= My/I ==32M/%pid**3
## tau= Mt*r/J ==16Mt/%pid**3
##sigma1=(16*(M+sqrt(M**2+Mt**2)))/(%pi*d**3)
##sigma2=(16*(M-sqrt(M**2+Mt**2)))/(%pi*d**3)
##solution a: max principal stress theory
##(16*(M+sqrt(M**2+Mt**2)))/(%pi*d**3)=sigmayp/N
a=(16.*(M+math.sqrt(M**2.+Mt**2.)))/math.pi
print(a)
b=sigmayp*10**6./N
print(b)
d=(a/b)**(1/3.)
print'%s %.5f %s'%("diameter of the bar in meter is= ",d,"")
##solution b:max shearing stress theory
c=(32.*math.sqrt(M**2.+Mt**2.))/math.pi
print(c)
d=(c/b)**(1/3.)
print'%s %.5f %s'%("diameter of the bar in meter is= ",d,"")
##solution c:max principal strain theory
##epsilon1=(sigma1-v(sigma2+sigma3))/E=epsilonyp/N=sigmayp/EN Or
##sigma1-v(sigma2+sigma3)=b given
##sigma1=b+v(sigma2+sigma3) substituting the values of the sigma 1,2 and 3 we get
##(16*(M+sqrt(M**2+Mt**2)-vM-v*sqrt(M**2+Mt**2)))/(%pi*d**3)=b
e=(16.*(M+math.sqrt(M**2.+Mt**2.)-v*M-v*math.sqrt(M**2.+Mt**2.)))/math.pi
print(e)
d=(e/b)**(1/3.)
print'%s %.5f %s'%("diameter of the bar in meter is= ",d,"")
##solution d:max energy of distortion theory
f=(16.*math.sqrt(4*M**2.+3.*Mt**2.))/math.pi
print'%s %.5f %s'%("f",f,"")
d=(f/b)**(1/3.)
print'%s %.5f %s'%("diameter of the bar in meter is= ",d,"")
print("all the values are converted into meter")
import math
#calculate max principal stress
sigmau1=300. ##MPa
sigmau2=700. ##MPa
b=0.105 ##m outer diameter
a=0.100 ##m inner diameter
##sigma1==(-sigma2)==tau
sigma3=0.
##Mt=J*tau/r= (%pi*(b**2-a**2))/2*b
##Mt=((%pi*(b**4-a**4))/(2*b))*tau equation a
q=(math.pi*(b**4.-a**4.))/(2.*b)
##solution a: max principal stress theory
tau=sigmau1
Mt=q*tau*10**6.
print'%s %.2f %s'%("max principal stress in Nm is= ",Mt,"")
##solution b:max shearing stress theory
## |sigma1-sigma2|=sigmau1
## 2*sigma1==sigmau1==2*tau or
Mt=q*tau*10**6
print'%s %.2f %s'%("max shearing stress in Nm is= ",Mt,"")
##solution c:Coulomb- mohr theory
##(tau/sigmau1)-(-tau/sigmau2)=1
tau=1*((sigmau1*sigmau2)/(sigmau1+sigmau2))
print'%s %.2f %s'%("tau in MPa is= ",tau,"")
Mt=q*tau*10**6
print'%s %.2f %s'%("Coulomb- mohr in Nm is= ",Mt,"")
import math
#calculate laod and intertia
a=0.05 ## m
Fm=90. ##kN
sigmacr=210. ## MPa
sigmayp=280. ## MPa
##sigmaa=Ma*c/I equation 1
##Ma=0.025*Fa
c=0.025
I=(a**4.)/12.
print'%s %.7f %s'%("I",I,"")
##sigmaa=((0.025*Fa)*c)/I substituting the values
##sigmam=Fm/A equation 2
sigmam=Fm/(a*a)
print'%s %.2f %s'%("in kilo Pa is= ",sigmam,"")
##(((1200*Fa)/sigmacr)+(sigmam/sigmayp))=1
Fa=(1.-(sigmam/sigmayp))*(sigmacr/1200.)
print'%s %.2f %s'%("load Fa in N is= ",Fa,"") ##wrong ans in textbook
import math
#calculate the value of pressure
r=0.04 ##m
t=5. ##mm
sigmae=250. ##MPa
sigmay=300. ##MPa
##sigmathetamax=(p*r)/t =8*p max values of tangential stresses
##sigmathetamin=((-p/4)*r)/t =-2*p min values of tangential stresses
##sigmazamax=(p*r)/2*t =4*p axial principal stresses
##sigmazmin=((-p/4)*r)/2*t =-p
##sigmathetaa=(sigmathetamax-sigmathetamin)/2= 5p alternating and mean stresses
##sigmathetam=(sigmathetamax+sigmathetamin)/2= 3p
##sigmaza=(sigmazamax-sigmazmin)/2 =2.5p
##sigmazm=(sigmazamax+sigmazmin)/2 =1.5p
##sqrt(sigmathetaa**2-sigmathetaa*sigmaza+sigmaza**2)=sigmaea
##sqrt(sigmathetam**2-sigmathetam*sigmazm+sigmazm**2)=sigmaem
##sqrt(25p**2-12.3p**2+6.25p**2)=sigmaea
##sqrt(9p**2-4.5p**2+2.25p**2)=sigmaem solving this equation we get
sigmaea=4.33 ##p
sigmaem=2.60 ##p
p=1./((sigmaea/sigmae)+(sigmaem/sigmay))
print'%s %.2f %s'%("the value of p in MPa is= ",p,"")
import math
import numpy
from numpy.linalg import inv
#find alternating and mean values of stresses and sigma and cycle
a=([[700 ,14 ,0], [14, -350, 0],[0, 0, -350]])
print(a)
c=([[-660, -7, 0], [-7 ,-350, 0], [0, 0, -350]])
print(c)
sigmau=2400. ##MPa
K=1.
sigmae=800. ##MPa
Nf=1. ##cycles for SAE
Nff=10**3 ##cycles for Gerber
Ne=10**8 ##cycles
sigmaxa=(700.+660.)/2.
print'%s %.2f %s'%("alternating and mean values of stresses in MPa is= ",sigmaxa,"")
sigmaxm=(700-660)/2.
print'%s %.2f %s'%("alternating and mean values of stresses in MPa is= ",sigmaxm,"")
sigmaya=(-350+350)/2.
print'%s %.2f %s'%("alternating and mean values of stresses in MPa is= ",sigmaya,"")
sigmaym=(-350-350)/2.
print'%s %.2f %s'%("alternating and mean values of stresses in MPa is= ",sigmaya,"")
sigmazm=(-350-350)/2.
print'%s %.2f %s'%("alternating and mean values of stresses in MPa is= ",sigmazm,"")
tauxya=(14+7)/2.
print'%s %.2f %s'%("alternating and mean values of stresses in MPa is= ",tauxya,"")
tauxym=(14-7)/2.
print'%s %.2f %s'%("alternating and mean values of stresses in MPa is= ",tauxym,"")
sigmaea=math.sqrt(((sigmaxa-sigmaya)**2.+(sigmaya-sigmaxa)**2.+6.*(tauxya)**2.)/2.)
print'%s %.2f %s'%("in MPa is =",sigmae,"")
sigmaem=math.sqrt(((sigmaxm-sigmaym)**2.+(sigmaym-sigmaxm)**2.+6.*(tauxym)**2.)/2.)
print'%s %.2f %s'%("in MPa is= ",sigmaem,"")
##solution a:
sigmacr=sigmaea/(1-(sigmaem/2400.))
print'%s %.3f %s'%("sigmacr",sigmacr,"")
b=math.log(sigmau/sigmae)/math.log(1./Ne)
print'%s %.3f %s'%("b",b,"")
Ncr=1.*(sigmacr/2400.)**(1./b)
print'%s %.3f %s'%("in cycles is= ",Ncr,"")
##solution b:
sigmacr=sigmaea/(1.-(sigmaem/sigmau)**2.)
print'%s %.3f %s'%("in MPa is= ",sigmacr,"")
b=math.log(2160./sigmae)/math.log(10**3./Ne)
print'%s %.3f %s'%("b",b,"")
Ncr=Nff*(sigmacr/(0.9*2400))**(-11.587)
print'%s %.3e %s'%("in cycles is= ",Ncr,"")
import math
#calculate Inertia and deflection of a point in meter and impact factor and pressure and static deflection of the beam and impact facotr
W=180. ##N
h=0.1 ##m
L=1.16 ##m
w=0.025 ##m
d=0.075 ##m
E=200. ##GPa
k=180. ##kN/m
I=w*d**3.
print'%s %.5f %s'%("I",I,"")
##deltast=(W*L**3)/(48*E*I) equation 1
deltast=(W*L**3*12.)/(48.*E*10**9.*I)
print'%s %.5f %s'%("deflection of a point in meter is= ",deltast,"")
##deltastmax=Mc/I equation 2
deltastmax=(W*L*12*0.0375)/(4*I)
print'%s %.2f %s'%("deflection of a point in Pa is= ",deltastmax,"")
##solution a:
a=1+math.sqrt(1.+((2.*h)/deltast))
print'%s %.2f %s'%("imapct factor is= ",a,"")
deltamax=deltast*a
print'%s %.2f %s'%("in meter is =",deltastmax,"")
sigmamax=deltastmax*a
print'%s %.2f %s'%("in Pa is= ",sigmamax,"")
##solution b:
deltast=deltast+(90./180000.)
print'%s %.5f %s'%("static deflection of the beam in meter is= ",deltast,"")
a=1+math.sqrt(1.+((2.*h)/deltast))
print'%s %.2f %s'%("imapct factor is= ",a,"")
deltamax=deltast*a
print'%s %.3f %s'%("in meter is =",deltamax,"")
sigmamax=deltastmax*a
print'%s %.2f %s'%("in Pa is= ",sigmamax,"")
#round off error