{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 15: Fundamentals of Metalworking"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 15.1, Mechanics of Metal Working, Page No. 506"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Enginering Strain = 1\n",
      "True Strain = 0.693147\n",
      "Reduction = 1\n",
      "\n",
      "\n",
      "Enginering Strain = -0.5\n",
      "True Strain = -0.693147\n",
      "Reduction = -1\n"
     ]
    }
   ],
   "source": [
    "from math import log\n",
    "\n",
    "#For Bar which is double in length\n",
    "#variable declaration 1\n",
    "L2=2;\n",
    "L1=1;\n",
    "\n",
    "#calculation 1\n",
    "e=(L2-L1)/L1;\n",
    "e1=log(L2/L1);\n",
    "r=1-L1/L2;\n",
    "\n",
    "#result 1\n",
    "print('\\nEnginering Strain = %g\\nTrue Strain = %g\\nReduction = %g')%(e,e1,r);\n",
    "\n",
    "\n",
    "\n",
    "#For bar which is halved in length\n",
    "#variable declaration 2\n",
    "L1=1;\n",
    "L2=0.5;\n",
    "\n",
    "#calculation 2\n",
    "e=(L2-L1)/L1;\n",
    "e1=log(L2/L1);\n",
    "r=1-L1/L2;\n",
    "\n",
    "#result 2\n",
    "print('\\n\\nEnginering Strain = %g\\nTrue Strain = %g\\nReduction = %g')%(e,e1,r);\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "### Example 15.2, Mechanics of Metal Working, Page No. 511"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Plastic work done in 1st step = 39752.1 lb/in^2\n",
      "Plastic work done in 2nd step = 97934.8 lb/in^2\n",
      "\n"
     ]
    }
   ],
   "source": [
    "\n",
    "from scipy.integrate import quad\n",
    "from math import log\n",
    "\n",
    "#variable declaration\n",
    "D0=25.0;\n",
    "D1=20.0;\n",
    "D2=15.0;\n",
    "def integrand(e):\n",
    "    return 200000*e**0.5\n",
    "\n",
    "#calculation\n",
    "ep1=log((D0/D1)**2);\n",
    "U1,U1_err=quad(integrand,0,ep1);\n",
    "ep2=log((D1/D2)**2);\n",
    "U2,U2_err=quad(integrand,ep1,ep1+ep2);\n",
    "\n",
    "#result\n",
    "print('\\nPlastic work done in 1st step = %g lb/in^2\\nPlastic work done in 2nd step = %g lb/in^2\\n')%(U1,U2);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 15.3, Hodography, Page No. 517"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Pressure  = 2.88675\n"
     ]
    }
   ],
   "source": [
    "\n",
    "from math import sin\n",
    "from math import radians\n",
    "\n",
    "#variable declaration\n",
    "alpha=60;\n",
    "\n",
    "#calculation\n",
    "r=radians(alpha);\n",
    "mu=1/sin(r);\n",
    "p_2k=mu*5/2;\n",
    "\n",
    "#result\n",
    "print('Pressure  = %g')%(p_2k);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 15.4, Temperature in Metalworking, Page No. 526"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Temperature Rise for aluminium = 78.4808 C\n",
      "Temperature Rise for titanium = 162.686 C\n",
      "\n"
     ]
    }
   ],
   "source": [
    "\n",
    "\n",
    "#variable declaration\n",
    "Al_s=200;\n",
    "Al_e=1;\n",
    "Al_p=2.69;\n",
    "Al_c=0.215;\n",
    "Ti_s=400;\n",
    "Ti_e=1;\n",
    "Ti_p=4.5;\n",
    "Ti_c=0.124;\n",
    "J=4.186;\n",
    "b=0.95;\n",
    "\n",
    "#calculation\n",
    "Al_Td=Al_s*Al_e*b/(Al_p*Al_c*J);\n",
    "Ti_Td=Ti_s*Ti_e*b/(Ti_p*Ti_c*J);\n",
    "\n",
    "#result\n",
    "print('\\nTemperature Rise for aluminium = %g C\\nTemperature Rise for titanium = %g C\\n')%(Al_Td,Ti_Td);\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 15.5, Friction and Lubrication, Page No. 546"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "For OD after deformation being 70 mm, Di = 22.3607 mm\n",
      "Precent change in inside diameter = 25.4644 percent\n",
      "Peak pressure = 1.93531\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "For OD after deformation being 81.4 mm, Di = 35.0137 mm\n",
      "Precent change in inside diameter = -16.7124 percent\n",
      "Peak pressure = 1.17321\n"
     ]
    }
   ],
   "source": [
    "\n",
    "\n",
    "from math import sqrt\n",
    "\n",
    "#variable declaration\n",
    "Do=60;\n",
    "Di=30;\n",
    "def1=70;\n",
    "def2=81.4;\n",
    "h=10;\n",
    "a=30;\n",
    "\n",
    "#calculation1\n",
    "di=sqrt((Do**2-Di**2)*2-def1**2);\n",
    "pr=(Di-di)/Di*100;\n",
    "m=0.27;\n",
    "p_s=1+2*m*a/(sqrt(3)*h);\n",
    "\n",
    "#result 1\n",
    "print('\\nFor OD after deformation being 70 mm, Di = %g mm\\nPrecent change in inside diameter = %g percent\\nPeak pressure = %g')%(di,pr,p_s);\n",
    "\n",
    "#calculation 2\n",
    "di=sqrt(def2**2-(Do**2-Di**2)*2);\n",
    "pr=(Di-di)/Di*100;\n",
    "m=0.05;\n",
    "p_s=1+2*m*a/(sqrt(3)*h);\n",
    "\n",
    "#result 2\n",
    "print('\\n\\n\\n\\nFor OD after deformation being 81.4 mm, Di = %g mm\\nPrecent change in inside diameter = %g percent\\nPeak pressure = %g')%(di,pr,p_s);\n"
   ]
  }
 ],
 "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
}