{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7.20 Steam at Sonic Velocity"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Given: A header contains 170 psi saturated steam which feeds a pulp stock digester through 30 feet of 2\" schedule 40 pipe. It includes 1 standard 90 degree elbow, a fully open conventional plug type disc global valve. The initial pressure in the digester is atmospheric.\n",
    "\n",
    "Find the initial flow rate in pounds/hour."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2022-08-22T01:18:51.867905Z",
     "iopub.status.busy": "2022-08-22T01:18:51.867250Z",
     "iopub.status.idle": "2022-08-22T01:18:52.661019Z",
     "shell.execute_reply": "2022-08-22T01:18:52.659973Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The mass flow rate is found to be 11626.328806003183 pound / hour\n"
     ]
    }
   ],
   "source": [
    "from fluids.units import *\n",
    "from math import pi\n",
    "from CoolProp.CoolProp import PropsSI\n",
    "P1 = 170*u.psi\n",
    "P2_spec = P2 = 1*u.atm\n",
    "L = 30*u.foot\n",
    "NPS, D_pipe, Do_pipe, t = nearest_pipe(NPS=2, schedule=40)\n",
    "A = 0.25*pi*D_pipe**2\n",
    "\n",
    "fd = 0.019 # assumed, initial guess\n",
    "Re = 1e6 # also assumed\n",
    "mu = 1.8e-8*u.Pa*u.s\n",
    "\n",
    "rho = 5.988612037578836*u.kg/u.m**3 # Density at inlet from steam tables\n",
    "roughness = 0.0018*u.inch\n",
    "\n",
    "for i in range(5):\n",
    "    K = K_from_f(fd=fd, L=L, D=D_pipe)\n",
    "    K += entrance_sharp()\n",
    "    K += exit_normal()\n",
    "    K += K_globe_valve_Crane(D1=D_pipe, D2=D_pipe)\n",
    "    K += bend_rounded(Di=D_pipe, angle=90*u.degrees, fd=fd, \n",
    "                 Re=Re, roughness=roughness, method='Crane')\n",
    "    \n",
    "    # lump the losses together for the `isothermal_gas` function\n",
    "    fd_tot = f_from_K(L=L, D=D_pipe, K=K)\n",
    "    \n",
    "    P2_choke = P_isothermal_critical_flow(P=P1, fd=fd_tot, D=D_pipe, L=L)\n",
    "    if P2_choke.to_base_units().magnitude > P2_spec.to_base_units().magnitude:\n",
    "        P2 = P2_choke\n",
    "    else:\n",
    "        P2 = P2_spec\n",
    "    \n",
    "    m = isothermal_gas(rho=rho, fd=fd_tot, P1=P1, P2=P2, L=L, D=D_pipe)\n",
    "    Q = m/rho\n",
    "    v = Q/A\n",
    "    # update friction factor\n",
    "    Re = Reynolds(D=D_pipe, rho=rho, mu=mu, V=v)\n",
    "    fd = friction_factor(Re=Re, eD=roughness/D_pipe)\n",
    "\n",
    "# choke pressure found to be 3 bar instead of 2.5 in Crane example\n",
    "print('The mass flow rate is found to be %s' %(m.to(u.lb/u.hour)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The values given in Crane are 11770 and 11160 lb/hour for the Darcy and the Sonic Velocity and Continuity equations."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
