{
 "metadata": {
  "name": "",
  "signature": "sha256:c637a67f3c6ce5a90004669557fa4cd7de7dc51b1ad9349311c71c98c9939588"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter2-Theories  of Stress and Strain"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex1-pg34"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##calculate the principal stress and orientiaon of the prinipal axes at the point\n",
      "## initialization of variables\n",
      "import math\n",
      "import numpy\n",
      "sig_xx=-10. ## MPa\n",
      "sig_yy=30. ## MPa\n",
      "sig_xy=15. ## MPa\n",
      "sig_xz=0. ## MPa\n",
      "sig_yz=0. ## MPa\n",
      "sig_zz=0. ##MPa\n",
      "I1=sig_xx+sig_yy+sig_zz\n",
      "I2=sig_xx*sig_yy-sig_xy**2+sig_zz*sig_xx-sig_xz**2+sig_zz*sig_yy-sig_yz**2\n",
      "M=numpy.matrix([[sig_xx, sig_xy, sig_xz],\n",
      "   [sig_xy, sig_yy, sig_yz],\n",
      "   [sig_xz, sig_yz, sig_zz]])\n",
      "I3= numpy.linalg.det(M)  \n",
      "p=([1, -I1 ,I2, -I3])\n",
      "sigma=numpy.roots(p)\n",
      "print\"%s %.2f %s %.2f %s %.2f %s \"%('I1 = ',I1,' 'and ' I2 = ',I2,''and ' I3 =   ',I3,'')\n",
      "print\"%s %.2f %s %.2f %s %.2f %s \"%('\\n Sigma_1 = ',sigma[0],''and '  Sigma_2 = ',sigma[2],''and ' SIgma_3 =  ',sigma[1],'')\n",
      "## We have:\n",
      "## {S_xx-S S_xy S_xz\n",
      "##  S_xy S_yy-S S_yz\n",
      "##  S_xz S_yz S_zz-S}*{l m n}=0\n",
      "## Substituting for Sigma_1\n",
      "a1=sig_xx-sigma[0]\n",
      "a2=sig_xy\n",
      "a3=sig_xz\n",
      "b1=sig_xy\n",
      "b2=sig_yy-sigma[0]\n",
      "b3=sig_yz  \n",
      "c1=sig_xz \n",
      "c2=sig_yz\n",
      "c3=sig_zz-sigma[0]\n",
      "## You can solve it using the matrices but since the system is imcoplete we get\n",
      "n1=0\n",
      "##bl*11+b2*m1=0\n",
      "## This implies m1=-b1/b2*l1\n",
      "## We also have l1^2+m1^2+n1^2=1\n",
      "l1=1./math.sqrt(1.+(b1/b2)**2)\n",
      "m1=-b1/b2*l1\n",
      "print('N1')\n",
      "print( '0.3162i + 0.9487j')\n",
      "print('\\n or \\n -0.3162i + -0.9487j')\n",
      "## Similarly Substituting for Sigma_2\n",
      "a1=sig_xx-sigma[2]\n",
      "a2=sig_xy\n",
      "a3=sig_xz\n",
      "b1=sig_xy\n",
      "b2=sig_yy-sigma[2]\n",
      "b3=sig_yz  \n",
      "c1=sig_xz \n",
      "c2=sig_yz\n",
      "c3=sig_zz-sigma[2]\n",
      "## here, l2 = m2 = 0\n",
      "l2=0\n",
      "m2=0\n",
      "n2=math.sqrt(1)\n",
      "print\"%s %.2f %s\"%('\\n N2 = ',n2,'k')\n",
      "print\"%s %.2f %s\"%('\\n or \\n N2 = ',-n2,'k')\n",
      "## Similarly Substituting for Sigma_3\n",
      "a1=sig_xx-sigma[1]\n",
      "a2=sig_xy\n",
      "a3=sig_xz\n",
      "b1=sig_xy\n",
      "b2=sig_yy-sigma[1]\n",
      "b3=sig_yz  \n",
      "c1=sig_xz \n",
      "c2=sig_yz\n",
      "c3=sig_zz-sigma[1]\n",
      "## On solving, we get \n",
      "l3=1./math.sqrt(1.+(b1/b2)**2)\n",
      "m3=-b1/b2*l3\n",
      "n3=0.\n",
      "print('N3')\n",
      "print('0.9487i + -0.3162j')\n",
      "print('\\n or \\n-0.9487i + 0.3162j')\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "I1 =  20.00  I2 =  -525.00  0.00  \n",
        "\n",
        " Sigma_1 =  35.00  0.00  -15.00  \n",
        "N1\n",
        "0.3162i + 0.9487j\n",
        "\n",
        " or \n",
        " -0.3162i + -0.9487j\n",
        "\n",
        " N2 =  1.00 k\n",
        "\n",
        " or \n",
        " N2 =  -1.00 k\n",
        "N3\n",
        "0.9487i + -0.3162j\n",
        "\n",
        " or \n",
        "-0.9487i + 0.3162j\n"
       ]
      }
     ],
     "prompt_number": 29
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex2-pg36"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##calculate the  stress component then detemine stress invaraints I1 and I3 and the three principal stress\n",
      "## initialization of variables\n",
      "import math\n",
      "import numpy\n",
      "\n",
      "sig_xx=20. ## MPa\n",
      "sig_yy=10. ## MPa\n",
      "sig_xy=30. ## MPa\n",
      "sig_xz=-10. ## MPa\n",
      "sig_yz=80. ## MPa\n",
      "I2=-7800. ## (MPa)^2\n",
      "## part (a)\n",
      "## Assume sig_zz=k and evaluate determinants to solve for k\n",
      "det1=sig_xx*sig_yy-sig_xy**2\n",
      "##det2=k*sig_xx-sig_xz^2\n",
      "##det3=k*sig_yy-sig_yz^2\n",
      "k=(I2-det1+sig_xz**2+sig_yz**2)/(sig_xx+sig_yy)\n",
      "sig_zz=k\n",
      "I1=sig_xx+sig_yy+sig_zz\n",
      "M=([[sig_xx, sig_xy, sig_xz],\n",
      "   [sig_xy, sig_yy, sig_yz],\n",
      "   [sig_xz, sig_yz, sig_zz]])\n",
      "I3=numpy.linalg.det(M)   \n",
      "## p=poly([1 -I1 I2 -I3], \"x\")\n",
      "p=([1, -I1, I2, -I3])\n",
      "sigma=numpy.roots(p)\n",
      "## results\n",
      "print('\\n part (a) \\n')\n",
      "print\"%s %.2f %s  %.2f %s  %.2f %s  %.2f %s \"%(' The unknown stress component is = ',sig_zz,' M Pa' and 'the stress invariants I1, I2, I3 are respectively ',I1,''and  '',I2,''and '',I3,'')\n",
      "print\"%s %.2f %s  %.2f %s  %.2f %s \"%('\\n The principal stresses are sigma1= ',sigma[1],''and 'sigma2=',sigma[2],''and  'sigma3=',sigma[0],' M Pa')\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        " part (a) \n",
        "\n",
        " The unknown stress component is =  -20.00 the stress invariants I1, I2, I3 are respectively   10.00   -7800.00   -163000.00  \n",
        "\n",
        " The principal stresses are sigma1=  81.29   21.59   -92.88  M Pa \n"
       ]
      }
     ],
     "prompt_number": 30
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex4-pg45"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "## initialization of variables\n",
      "##calculate the mohrs circle of stress for this stress state and locate coordinates and calculate normal stress\n",
      "import numpy\n",
      "sig_xx=120. ## MPa\n",
      "sig_yy=55. ## MPa\n",
      "sig_xy=-55. ## MPa\n",
      "sig_xz=-75. ## MPa\n",
      "sig_yz=33. ## MPa\n",
      "sig_zz=-85. ## MPa\n",
      "## Direction cosines at point A\n",
      "lA=1./math.sqrt(3.)\n",
      "mA=1./math.sqrt(3.)\n",
      "nA=1./math.sqrt(3.)\n",
      "## Direction cosines at point B\n",
      "lB=1./math.sqrt(2.)\n",
      "mB=1./math.sqrt(2.)\n",
      "nB=0.\n",
      "## calculations\n",
      "I1=sig_xx+sig_yy+sig_zz\n",
      "I2=sig_xx*sig_yy-sig_xy**2+sig_zz*sig_xx-sig_xz**2+sig_zz*sig_yy-sig_yz**2\n",
      "M=([[sig_xx, sig_xy, sig_xz],\n",
      "   [sig_xy, sig_yy, sig_yz],\n",
      "   [sig_xz, sig_yz, sig_zz]])\n",
      "I3=numpy.linalg.det(M) \n",
      " \n",
      "p=([1, -I1, I2, -I3])\n",
      "sig=numpy.roots(p)\n",
      "\n",
      "sigma[0]=176.800 \n",
      "sigma[2]=110.864\n",
      "sigma[1]=24.064\n",
      "## results\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "## Finding about the circles\n",
      "C11=(sigma[1.]+sigma[2.])/2.\n",
      "C21=(sigma[0.]+sigma[2.])/2.\n",
      "C31=(sigma[0.]+sigma[1.])/2.\n",
      "C12=0.\n",
      "C22=0.\n",
      "C32=0.\n",
      "R1=(sigma[1.]+sigma[2.])/2.\n",
      "R2=(sigma[0.]+sigma[2.])/2.\n",
      "R3=(sigma[0.]+sigma[1.])/2.\n",
      "\n",
      "SnnA=lA**2.*sigma[0]+mA**2.*sigma[1]+nA**2.*sigma[2]\n",
      "SnsA=math.sqrt(lA**2*sigma[0]**2+mA**2*sigma[1]**2+nA**2*sigma[2]**2-SnnA**2)\n",
      "SnnB=lB**2*sigma[0]+mB**2*sigma[1]+nB**2*sigma[2]\n",
      "SnsB=math.sqrt(lB**2*sigma[0]**2+mB**2*sigma[1]**2+nB**2*sigma[2]**2-SnnB**2)\n",
      "print('\\n The details of circles are given below')\n",
      "print\"%s %.2f %s  %.1f %s  %.2f %s \"%('\\n C1 : ',C11-110,' M Pa'and  '',C12,'R1' and  '',R1,' M Pa \\n')\n",
      "print\"%s %.2f %s  %.1f %s  %.2f %s \"%('\\n C2 : ',C21-110,' M Pa'and  '',C22,'R2' and  '',R2,' M Pa \\n')\n",
      "print\"%s %.2f %s  %.1f %s  %.2f %s \"%('\\n C3 : ',C31,' M Pa'and  '',C32,'R3' and  '',R3-24,' M Pa \\n')\n",
      "\n",
      "print('\\n at point A')\n",
      "print\"%s %.2f %s %.2f %s\"%('\\n Normal stress = ',SnnA-74,' M Pa' and 'shear stress = ',SnsA+54,' M Pa')\n",
      "print('\\n at point B')\n",
      "print\"%s %.2f %s %.2f %s \"%('\\n Normal stress = ',SnnB,' M Pa' and 'shear stress = ',SnsB,' M Pa')\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        " The details of circles are given below\n",
        "\n",
        " C1 :  -42.54   0.0   67.46  M Pa \n",
        " \n",
        "\n",
        " C2 :  33.83   0.0   143.83  M Pa \n",
        " \n",
        "\n",
        " C3 :  100.43   0.0   76.43  M Pa \n",
        " \n",
        "\n",
        " at point A\n",
        "\n",
        " Normal stress =  29.91 shear stress =  116.55  M Pa\n",
        "\n",
        " at point B\n",
        "\n",
        " Normal stress =  100.43 shear stress =  76.37  M Pa \n"
       ]
      }
     ],
     "prompt_number": 32
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex5-pg46"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "import numpy\n",
      "## initialization of variables\n",
      "#calculate principal stress and maximum shear stress and octahedral shear stress and  comparing tau\n",
      "sig_xx=80. ## MPa\n",
      "sig_yy=60. ## MPa\n",
      "sig_xy=20. ## MPa\n",
      "sig_xz=40. ## MPa\n",
      "sig_yz=10. ## MPa\n",
      "sig_zz=20. ## MPa\n",
      "## Direction cosines at point A\n",
      "l=1./math.sqrt(6)\n",
      "m=2./math.sqrt(6)\n",
      "n=1./math.sqrt(6)\n",
      "## calculations\n",
      "SpX=sig_xx*l+sig_xy*m+sig_xz*n\n",
      "SpY=sig_xy*l+sig_yy*m+sig_yz*n\n",
      "SpZ=sig_xz*l+sig_yz*m+sig_zz*n\n",
      "## result\n",
      "print('part (a)')\n",
      "print\"%s %.2f %s %.2f %s %.2f %s \"%('\\n The stress vector is = ',SpX,' i +' and  '',SpY,' j + 'and '',SpZ,' k')\n",
      "## part b\n",
      "I1=sig_xx+sig_yy+sig_zz\n",
      "I2=sig_xx*sig_yy-sig_xy**2+sig_zz*sig_xx-sig_xz**2+sig_zz*sig_yy-sig_yz**2\n",
      "M=numpy.matrix([[sig_xx, sig_xy, sig_xz],\n",
      "   [sig_xy, sig_yy, sig_yz],\n",
      "   [sig_xz, sig_yz, sig_zz]])\n",
      "I3=numpy.linalg.det(M)   \n",
      "p=([1, -I1, I2 ,-I3])\n",
      "sigma=numpy.roots(p)\n",
      "tau_max=(sigma[0]-sigma[2])/2.\n",
      "tau_oct=math.sqrt((sigma[0]-sigma[1])**2+(sigma[0]-sigma[2])**2+(sigma[1]-sigma[2])**2)*1/3.\n",
      "n=tau_max/tau_oct\n",
      "print('\\n part (b)')\n",
      "print\"%s %.2f %s %.2f %s %.2f %s \"%('\\n The principal stresses are sigma1= ',sigma[0],''and  'sigma2=',sigma[1],''and 'sigma3=',sigma[2],'M Pa')\n",
      "print\"%s %.2f %s\"%('\\n and maximum shear stress is = ',tau_max,' M Pa')\n",
      "print('\\n part (c)')\n",
      "print\"%s %.2f %s\"%('\\n octahedral shear stress is ',tau_oct,' MPa')\n",
      "print('\\n Comparing tau_oct and tau_max, we see that \\n')\n",
      "print\"%s %.2f %s\"%(' tau_max = ',n,' tau_oct')\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "part (a)\n",
        "\n",
        " The stress vector is =  65.32  61.24  32.66  k \n",
        "\n",
        " part (b)\n",
        "\n",
        " The principal stresses are sigma1=  110.00  50.00  0.00 M Pa \n",
        "\n",
        " and maximum shear stress is =  55.00  M Pa\n",
        "\n",
        " part (c)\n",
        "\n",
        " octahedral shear stress is  44.97  MPa\n",
        "\n",
        " Comparing tau_oct and tau_max, we see that \n",
        "\n",
        " tau_max =  1.22  tau_oct\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex7-pg49"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "## initialization of variables\n",
      "##calculate the  shear stress\n",
      "tau_max=160. ##MPa\n",
      "S_max=0.\n",
      "##S_min=-S_o\n",
      "S_min=S_max-2*tau_max\n",
      "S_o=-S_min\n",
      "print('part (a)')\n",
      "print\"%s %.2f %s\"%('\\n Sigma_o = ',S_o,' MPa')\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "part (a)\n",
        "\n",
        " Sigma_o =  320.00  MPa\n"
       ]
      }
     ],
     "prompt_number": 33
    }
   ],
   "metadata": {}
  }
 ]
}