{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 5 - Sedimentation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Page 264 Example 5.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " concentration(Y) (kg water/kg solids):\n",
      "\n",
      "5.0\n",
      "\n",
      "4.2\n",
      "\n",
      "3.7\n",
      "\n",
      "3.1\n",
      "\n",
      "2.5\n",
      "\n",
      "\n",
      " water to overflow (Y-U) (kg water/kg solids):\n",
      "\n",
      "\n",
      " 3.5\n",
      "\n",
      "\n",
      " 2.7\n",
      "\n",
      "\n",
      " 2.2\n",
      "\n",
      "\n",
      " 1.6\n",
      "\n",
      "\n",
      " 1.0\n",
      "\n",
      "\n",
      " sedimentation rate uc (m/sec):\n",
      "\n",
      " 0.000200  \n",
      "\n",
      " 0.000120  \n",
      "\n",
      " 0.000094  \n",
      "\n",
      " 0.000070  \n",
      "\n",
      " 0.000050  \n",
      "\n",
      " \n",
      "\n",
      "(Y-U)/Uc (s/m):\n",
      "\n",
      "\n",
      " 17500\n",
      "\n",
      "\n",
      " 22500\n",
      "\n",
      "\n",
      " 23400\n",
      "\n",
      "\n",
      " 22900\n",
      "\n",
      "\n",
      " 20000\n",
      "\n",
      "\n",
      "Maximum value of (Y-U)/Uc = 23400s/m\n",
      "\n",
      " The required area of the thickener is :31.12m**2\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "#Basis 1 kg of solids\n",
    "feed_rate_solid = 1.33#  #Mass rate of feed of solids in kg/sec\n",
    "U = 1.5#                 #Mass rate of solids in the underflow in kg/sec\n",
    "Y = [5.0,4.2,3.7,3.1,2.5]#\n",
    "print\"\\n concentration(Y) (kg water/kg solids):\\n\"\n",
    "for y in Y:\n",
    "     print\"%.1f\\n\"%(y)\n",
    "print\"\\n water to overflow (Y-U) (kg water/kg solids):\\n\"\n",
    "O=[]\n",
    "for y in Y:\n",
    "    O.append(y - 1.5)##Amount of water to overflow in kg water/kg solids\n",
    "for o in O:\n",
    "    print\"\\n %.1f\\n\"%(o)\n",
    "Uc = [2.00*10**(-4),1.20*10**(-4), 0.94*10**(-4), 0.70*10**(-4), 0.50*10**(-4)]\n",
    "print\"\\n sedimentation rate uc (m/sec):\\n\"\n",
    "for uc in Uc:\n",
    "    print\" %f  \\n\"%(uc)#\n",
    "X =[1.75*10**4, 2.25*10**4, 2.34*10**4, 2.29*10**4, 2.00*10**4]##X = (Y-U)/Uc\n",
    "print\" \\n\\n(Y-U)/Uc (s/m):\\n\"\n",
    "for x in X:\n",
    "    print\"\\n %d\\n\"%(x)#\n",
    "z = max(X)# #prints the maximum value of X\n",
    "print\"\\nMaximum value of (Y-U)/Uc = %ds/m\"%(z)#\n",
    "\n",
    "#Calculating the require darea of the thickener\n",
    "A = z*1.33/1000# #1.33 is the mass feed rate of solids in kg/sec\n",
    "#1000 is the density of water in kg/m**3\n",
    "print\"\\n The required area of the thickener is :%.2fm**2\\n\"%(A)#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Page 265 Example 5.2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "H(mm)\n",
      "900 \t800 \t700 \t600 \t500 \t400 \t300 \t260 \t250 \t220 \t200 \t180 \t\n",
      "\n",
      "c(kg/m**3):\n",
      "\n",
      "200 \t225 \t257 \t300 \t360 \t450 \t600 \t692 \t720 \t818 \t900 \t1000 \t\n",
      "\n",
      "Sedimentation flux(kg.s/m**2):\n",
      "\n",
      "4.1667 \t3.6111 \t3.0556 \t2.5000 \t1.9444 \t1.3889 \t0.8333 \t0.6111 \t0.5556 \t0.3889 \t0.2778 \t0.1667 \t\n",
      "uc/(1/c-1/1200)\n",
      "kg.sec/m**2:\n",
      "\n",
      "0.0536 \t0.0497 \t0.0469 \t0.0440 \t0.0420 \t0.0384 \t0.0360 \t0.0330 \t0.0333 \t0.0343 \t0.0360 \t0.0400 \t\n",
      "1000*(1/c-1/cu)\n",
      "m**3/kg*10**3\n",
      "\n",
      "4.167 \t3.611 \t3.056 \t2.500 \t1.944 \t1.389 \t0.833 \t0.611 \t0.556 \t0.389 \t0.278 \t0.167 \t\n",
      "\n",
      "\n",
      "(1/c-1/1200)/uc\n",
      " m**2.kg/sec\n",
      "\n",
      "18.7 \t20.1 \t21.3 \t22.7 \t23.8 \t26.0 \t27.8 \t30.3 \t30.0 \t29.2 \t27.8 \t25.0 \t\n",
      "\n",
      "\n",
      "the maximum value of (1/c-1/1200)/uc is 30.3 m**2*kg/s\n",
      "\n",
      " The area required is A = Qc[(1/c-1/cu)/uc]max = 202m**2\n"
     ]
    }
   ],
   "source": [
    "#Area of the tank required to give an underflow concentration of 1200kg/m**3 for a feed rate of 2 m**3/min\n",
    "\n",
    "#Initial height of slurry in the tank\n",
    "H = [900, 800, 700, 600, 500, 400, 300, 260, 250, 220, 200, 180]\n",
    "uc = [13.4, 10.76, 8.6, 6.6, 4.9, 3.2, 1.8 ,1.21, 1.11, 0.80, 0.60, 0.40]\n",
    "i=0#\n",
    "c=[];x=[];sed=[];y=[];z=[]\n",
    "while i<12:\n",
    "    c.append(200*900/H[(i)])\n",
    "    x.append(1000*(1/c[i]-1/1200))\n",
    "    sed.append(c[(i)]*uc[(i)]/(1000*60))\n",
    "    y.append(uc[(i)]*10**(-3)/((1/c[(i)]-1/1200)*60))\n",
    "    z.append(1/y[(i)])\n",
    "    i=i+1#\n",
    "\n",
    "print\"\\nH(mm)\"\n",
    "for h in H:print\"%d \\t\"%(h),#\n",
    "print \n",
    "print\"\\nc(kg/m**3):\\n\"\n",
    "for cc in c:print\"%d \\t\"%(cc),\n",
    "print    \n",
    "print\"\\nSedimentation flux(kg.s/m**2):\\n\"\n",
    "for xx in x:print\"%.4f \\t\"%(xx),\n",
    "print    \n",
    "print\"uc/(1/c-1/1200)\\nkg.sec/m**2:\\n\"\n",
    "for yy in y:print\"%.4f \\t\"%(yy),\n",
    "print    \n",
    "print\"1000*(1/c-1/cu)\\nm**3/kg*10**3\\n\"\n",
    "for xx in x:print\"%.3f \\t\"%(xx),\n",
    "print    \n",
    "print\"\\n\\n(1/c-1/1200)/uc\\n m**2.kg/sec\\n\"\n",
    "for zz in z:print\"%.1f \\t\"%(zz),\n",
    "print    \n",
    "m1=max([18.7, 20.1, 21.3, 22.7, 23.8, 26.0, 27.8, 30.3, 30.0, 29.2, 27.8, 25.0])\n",
    "print\"\\n\\nthe maximum value of (1/c-1/1200)/uc is %.1f m**2*kg/s\"%(m1)#\n",
    "A = 2*200*30.3/60#\n",
    "print\"\\n The area required is A = Qc[(1/c-1/cu)/uc]max = %dm**2\"%(A)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Page 275 Example 5.3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " concentration is:0.172\n",
      "\n",
      " The terminal falling velocity is 0.00872 m/sec\n",
      "\n",
      "The maximum value is 6.062  *10**(-4) m**3/m**2sec\n"
     ]
    }
   ],
   "source": [
    "from sympy import symbols,solve\n",
    "#Assumption: Resistance force F on an isolated sphere is given by Stoke's law:F = 3*pi(meu)d*u\n",
    "\n",
    "C = symbols('C')\n",
    "x=solve(-4.8*C+(1-C))[0]\n",
    "print\"\\n concentration is:%.3f\"%(x)\n",
    "\n",
    "#terminal falling velocity u can be calculated by force balance\n",
    "#u = d**2*g/(18*meu)*(ps-p)\n",
    "def terminal_velocity():\n",
    "    d = 10**(-4)#   #diameter is in meters\n",
    "    g = 9.81#      #acceleration due to gravity is in m/sec**2\n",
    "    meu = 10**(-3)# #viscosity is in N.s/m**2\n",
    "    ps = 2600#     #density is in kg/m**3\n",
    "    p = 1000#      #density is in kg/m**3\n",
    "    \n",
    "    u = (d**2)*g*(ps-p)/(18*meu)#\n",
    "    return u\n",
    "\n",
    "def si_max():\n",
    "    u=terminal_velocity()\n",
    "    print\"\\n The terminal falling velocity is %.5f m/sec\"%(u)#\n",
    "    si=u*x*(1-x)**(4.8)#\n",
    "    return si\n",
    "si = si_max()#\n",
    "print\"\\nThe maximum value is %.3f  *10**(-4) m**3/m**2sec\"%(si*10**4)\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
}
