{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7.10 Piping Systems - Steam"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "40 bar steam, 450 degrees Celsius flows though a 120 m long horizontal 150mm schedule 80 pipe at a rate of\n",
    "40000 kg/hr. \n",
    "\n",
    "There are three 90 degree weld elbows with rc=1.5, \n",
    "1 fully open class 600 150mm x 100mm venturi class gate valve, one class 600 150 mm class y pattern globe valve with a seat diameter of 90% the inside pipe diameter (disc fully lifted).\n",
    "\n",
    "Calculate the pressure drop through the system."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Density = 12.5195049457 kilogram / meter ** 3\n",
      "Viscosity = 2.65571609065e-05 pascal * second\n"
     ]
    }
   ],
   "source": [
    "from math import *\n",
    "from fluids.units import *\n",
    "from thermo.units import Stream\n",
    "\n",
    "m = 40000*u.kg/u.hr\n",
    "T = 450*u.degC\n",
    "P = 40*u.bar\n",
    "\n",
    "steam = Stream('water', T=T, P=P, m=m)\n",
    "\n",
    "rho = steam.rho\n",
    "mu = steam.mu\n",
    "print('Density = %s' %rho)\n",
    "print('Viscosity = %s' %mu)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Crane elbow term = 0.63; calculated = 1.26189256438 dimensionless\n",
      "Crane globe valve term = 1.44; calculated = 21.1562338391 dimensionless\n",
      "Crane gate valve term = 1.22; calculated = 2.10552435922 dimensionless\n",
      "Crane friction term = 12.3; calculated = 33.3833135584 dimensionless\n",
      "Darcy friction factor = 0.04071651477 dimensionless\n",
      "Pressure drop = 1008693.59173 pascal\n"
     ]
    }
   ],
   "source": [
    "L = 120*u.m\n",
    "NPS, D_pipe, Do_pipe, t = nearest_pipe(Do=150*u.mm, schedule='80')\n",
    "Q = m/rho\n",
    "v = Q/(pi/4*D_pipe**2)\n",
    "Re = Reynolds(rho=rho, mu=mu, D=D_pipe, V=v)\n",
    "fd = friction_factor(Re=Re, eD=0.0018*u.inch/D_pipe)\n",
    "K_elbow = bend_rounded(Di=D_pipe, angle=90*u.degrees, fd=fd, bend_diameters=1.5)\n",
    "K_friction = K_from_f(fd=fd, L=L, D=D_pipe)\n",
    "K_globe_valve = K_globe_valve_Crane(D1=0.9*D_pipe, D2=D_pipe, fd=fd)\n",
    "# Angle and inside diameter are taken from example 7.4,\n",
    "K_gate_valve = K_gate_valve_Crane(D1=100*u.mm, D2=D_pipe, angle=13.115*u.degrees, fd=fd)\n",
    "\n",
    "K_tot = K_gate_valve + K_globe_valve + 3*K_elbow + K_friction\n",
    "dP = dP_from_K(K=K_tot, rho=rho, V=v)\n",
    "\n",
    "print('Crane elbow term = 0.63; calculated = %s' % (3*K_elbow))\n",
    "print('Crane globe valve term = 1.44; calculated = %s' % (K_globe_valve))\n",
    "print('Crane gate valve term = 1.22; calculated = %s' % (K_gate_valve))\n",
    "print('Crane friction term = 12.3; calculated = %s' % (K_friction))\n",
    "print('Darcy friction factor = %s' %fd)\n",
    "print('Pressure drop = %s' %dP.to(u.Pa))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "This compares terribly to the example, which calculates a pressure drop of 274800 Pa!\n",
    "\n",
    "Two errors are apparent - their example uses a different coefficient (55) in the globe valve pressure drop equation than that shown in their appendix (340); and they re-use their prior calculated gate valve, despite the friction factor being different in this example.\n",
    "This, plus their use of a constant 0.015 friction factor, explains the difference. \n",
    "\n",
    "The example below uses their calculated globe valve pressure drop and their friction factor. The result (268500 Pa) compares well with their calculation; the additional decimals and better physical properties explain the rest. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Crane elbow term = 0.63; calculated = 0.598864740713 dimensionless\n",
      "Crane globe valve term = 1.44; calculated = 1.44\n",
      "Crane gate valve term = 1.22; calculated = 1.16148152353 dimensionless\n",
      "Crane friction term = 12.3; calculated = 12.2984421973 dimensionless\n",
      "Darcy friction factor = 0.015\n",
      "Pressure drop = 269976.656247 pascal\n"
     ]
    }
   ],
   "source": [
    "L = 120*u.m\n",
    "NPS, D_pipe, Do_pipe, t = nearest_pipe(Do=150*u.mm, schedule='80')\n",
    "Q = m/rho\n",
    "v = Q/(pi/4*D_pipe**2)\n",
    "Re = Reynolds(rho=rho, mu=mu, D=D_pipe, V=v)\n",
    "fd = 0.015\n",
    "K_elbow = bend_rounded(Di=D_pipe, angle=90*u.degrees, fd=fd, bend_diameters=1.5)\n",
    "K_friction = K_from_f(fd=fd, L=L, D=D_pipe)\n",
    "K_globe_valve = 1.44\n",
    "# Angle and inside diameter are taken from example 7.4,\n",
    "K_gate_valve = K_gate_valve_Crane(D1=100*u.mm, D2=D_pipe, angle=13.115*u.degrees, fd=fd)\n",
    "\n",
    "K_tot = K_gate_valve + K_globe_valve + 3*K_elbow + K_friction\n",
    "dP = dP_from_K(K=K_tot, rho=rho, V=v)\n",
    "\n",
    "print('Crane elbow term = 0.63; calculated = %s' % (3*K_elbow))\n",
    "print('Crane globe valve term = 1.44; calculated = %s' % (K_globe_valve))\n",
    "print('Crane gate valve term = 1.22; calculated = %s' % (K_gate_valve))\n",
    "print('Crane friction term = 12.3; calculated = %s' % (K_friction))\n",
    "print('Darcy friction factor = %s' %fd)\n",
    "print('Pressure drop = %s' %dP.to(u.Pa))"
   ]
  }
 ],
 "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.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
