{
 "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": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Density = 11.98501086830739 kilogram / meter ** 3\n",
      "Viscosity = 2.6514617050585646e-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": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Crane elbow term = 0.63; calculated = 0.6059161440546141 dimensionless\n",
      "Crane globe valve term = 1.44; calculated = 7.971314885893429 dimensionless\n",
      "Crane gate valve term = 1.22; calculated = 1.171521564942793 dimensionless\n",
      "Crane friction term = 12.3; calculated = 12.522683061833051 dimensionless\n",
      "Darcy friction factor = 0.015273499107749047 dimensionless\n",
      "Pressure drop = 405252.2181183786 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": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Crane elbow term = 0.63; calculated = 0.5988647407128814 dimensionless\n",
      "Crane globe valve term = 1.44; calculated = 1.44\n",
      "Crane gate valve term = 1.22; calculated = 1.1614815235317342 dimensionless\n",
      "Crane friction term = 12.3; calculated = 12.29844219732167 dimensionless\n",
      "Darcy friction factor = 0.015\n",
      "Pressure drop = 282016.77247066115 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": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
