{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 12: Fatigue of Metals"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "### Example 12.1, Mean Stress, Page No. 387"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Bar Diameter = 1.45673 in\n"
     ]
    }
   ],
   "source": [
    "from math import pi\n",
    "from math import sqrt\n",
    "\n",
    "#variable declaration\n",
    "sigma_u=158;             # in ksi\n",
    "sigma0=147;             # in ksi\n",
    "sigma_e=75;             # in ksi\n",
    "l_max=75;             # in ksi\n",
    "l_min=-25;             # in ksi\n",
    "sf=2.5;\n",
    "\n",
    "#calculation\n",
    "sigma_m=(l_max+l_min)/2;\n",
    "sigma_a=(l_max-l_min)/2;\n",
    "sigma_e=sigma_e/sf;\n",
    "A=sigma_a/sigma_e+sigma_m/sigma_u;\n",
    "D=sqrt(4*A/pi);\n",
    "\n",
    "#result\n",
    "print('\\nBar Diameter = %g in')%(D);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 12.2, Low Cycle Fatigue, Page No. 391"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "d_e_e = 0.000681818\n",
      "d_e_p = 0.000608182\n",
      "Number of Cycles = 48884 cycles\n"
     ]
    }
   ],
   "source": [
    "\n",
    "\n",
    "#variable declaration\n",
    "sigma_b=75.0;\n",
    "e_b=0.000645;\n",
    "e_f=0.3;\n",
    "E=22*10**4;\n",
    "c=-0.6;\n",
    "\n",
    "#calculation\n",
    "d_e_e=float(2*sigma_b/E);\n",
    "d_e_p=2*e_b-d_e_e;\n",
    "N=((d_e_p/(2*e_f))**(1/c))/2;\n",
    "\n",
    "#result\n",
    "print('\\nd_e_e = %g\\nd_e_p = %g\\nNumber of Cycles = %g cycles')%(d_e_e,d_e_p,N);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 12.3, Fatigue Crack Proportion, Page No. 401"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fatigue Cycles = 261417 cycles\n"
     ]
    }
   ],
   "source": [
    "from math import pi\n",
    "\n",
    "#variable declaration\n",
    "ai=0.5;\n",
    "ai=ai*10**-3;           #conversion to m\n",
    "sigma_max=180.0;\n",
    "Kc=100.0;\n",
    "alpha=1.12;\n",
    "p=3.0;\n",
    "A=6.9*10**-12;\n",
    "\n",
    "#calculation\n",
    "af=(Kc/(sigma_max*alpha))**2/pi;\n",
    "Nf=float(af**(1-(p/2))-ai**(1-(p/2)))/float((1-p/2)*A*(sigma_max**3)*(pi**(p/2))*(alpha**p));\n",
    "\n",
    "#result\n",
    "print('Fatigue Cycles = %g cycles')%(Nf);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 12.4, Stress Concentration of Fatigue, Page No. 404"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Mean Stress = 25464.8 psi\n",
      "Fluctuating Bending Stress = 33658.4 psi\n",
      "Effective Maximum Stress = 59123.2 psi\n",
      "Effective Minimum Stress = 8193.63 psi\n",
      "sigma_a = 39834.1 psi\n",
      "\n",
      "\n",
      "Note: Calculation Errors in the book\n"
     ]
    }
   ],
   "source": [
    "\n",
    "\n",
    "from math import sqrt\n",
    "from math import pi\n",
    "\n",
    "#variable declaration\n",
    "rho=0.0004;\n",
    "S_u=190000;\n",
    "M=200;\n",
    "Pm=5000;\n",
    "D=0.5;\n",
    "dh=0.05;\n",
    "r=dh/2;\n",
    "Kt=2.2;\n",
    "\n",
    "#calculation\n",
    "Kf=1+(Kt-1)/(1+sqrt(rho/r));\n",
    "q=(Kf-1)/(Kt-1);\n",
    "A=pi/4*D**2;\n",
    "sigma_m=Pm/A;\n",
    "I=pi/64*D**4;\n",
    "sigma_a=Kf*((M*D)/(2*I));\n",
    "sigma_max=sigma_a+sigma_m;\n",
    "sigma_min=sigma_a-sigma_m;\n",
    "sigma_e=S_u/2;\n",
    "sigma_a1=sigma_e/Kf*(1-sigma_m/S_u);\n",
    "\n",
    "#result\n",
    "print('\\nMean Stress = %g psi\\nFluctuating Bending Stress = %g psi\\nEffective Maximum Stress = %g psi\\nEffective Minimum Stress = %g psi\\nsigma_a = %g psi\\n\\n\\nNote: Calculation Errors in the book')%(sigma_m,sigma_a,sigma_max,sigma_min,sigma_a1);\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 12.5, Infinite Life Design, Page No. 422"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Fatigue Limit = 14245.3 psi\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#variable declaration\n",
    "Kt=1.68;\n",
    "q=0.9;\n",
    "sigma_ed=42000;\n",
    "Cs=0.9;\n",
    "Cf=0.75;\n",
    "Cz=0.81;\n",
    "\n",
    "#calculation\n",
    "Kf=q*(Kt-1)+1;\n",
    "sigma_e=sigma_ed*Cs*Cf*Cz;\n",
    "sigma_en=sigma_e/Kf;\n",
    "\n",
    "#result\n",
    "print('\\nFatigue Limit = %g psi')%(sigma_en);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 12.6, Local Strain method, Page No. 424"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Number of cycles = 14785.5 cycles\n",
      "Fatigue damage per cycle = 6.7634e-05\n",
      "Number of cycles with correction of mean stress= 129289 cycles\n",
      "Fatigue damage per cycle  with correction of mean stress= 7.7346e-06 damage per year\n",
      "Shaft will fail in 2.2446 days\n"
     ]
    }
   ],
   "source": [
    "\n",
    "from scipy.optimize import fsolve\n",
    "\n",
    "#variable declaration\n",
    "K=189;\n",
    "n=0.12;\n",
    "ef=1.06;\n",
    "sigma_f=190;\n",
    "b=-0.08;\n",
    "c=-0.66;\n",
    "E=30000000.0;\n",
    "E=E/1000;        #conversion to ksi\n",
    "s=200.0;\n",
    "sigma_m=167.0;\n",
    "sigma_a=17.0;\n",
    "se=s**2/E;\n",
    "\n",
    "#calculation\n",
    "def f(ds):\n",
    "    return (ds**2)/(2*E)+(ds**((1+n)/n))/((2*K)**(1/n))-se/2;\n",
    "ds=fsolve(f,1)\n",
    "de=se/ds;\n",
    "def f1(N2):\n",
    "    return (N2**(b))*(sigma_f/E)+ef*(N2**(c))-de/2;\n",
    "N2=fsolve(f1,1);\n",
    "N_1=N2/2;\n",
    "de_e2=sigma_a/E;\n",
    "def f2(N2):\n",
    "    return (N2**b)*((sigma_f-sigma_m)/E)+ef*(N2**c)-de_e2;\n",
    "N2=fsolve(f2,1);\n",
    "N_2=N2/2;\n",
    "C_pd=2*60*60*8;\n",
    "f=N_2/C_pd;\n",
    "\n",
    "#result\n",
    "print('\\nNumber of cycles = %g cycles\\nFatigue damage per cycle = %g\\nNumber of cycles with correction of mean stress= %g cycles\\nFatigue damage per cycle  with correction of mean stress= %g damage per year\\nShaft will fail in %g days')%(N_1,1/N_1,N_2,1/N_2,f);\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}