{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7.16 Air Lines"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Air at 65 psig and 115 deg F flows through 75 feet of 1\" schedule 40 pipe at a rate of 100 cubic feet/minute.\n",
    "\n",
    "Find the pressure drop in psi and the velocity in feet per minute at the inlet and the outlet."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from fluids.units import *\n",
    "from math import pi\n",
    "P1 = 65*u.psi + 1*u.standard_atmosphere"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ratio of actual to standard flow: 0.20407676712438672\n"
     ]
    }
   ],
   "source": [
    "# Take nitrogen-oxygen as air\n",
    "from thermo import PRMIX\n",
    "zs = [0.79, 0.21]\n",
    "Tcs = [126.2, 154.58]\n",
    "Pcs = [3394387.5, 5042945.25]\n",
    "omegas = [0.04, 0.021]\n",
    "\n",
    "eos_flowing = PRMIX(T=(115*u.degF).to(u.K).magnitude, P=P1.to(u.Pa).magnitude, zs=zs, Tcs=Tcs, Pcs=Pcs, omegas=omegas)\n",
    "eos_std = PRMIX(T=288.15, P=101325.0, zs=zs, Tcs=Tcs, Pcs=Pcs, omegas=omegas)\n",
    "V_ratio = eos_flowing.V_g/eos_std.V_g\n",
    "print('Ratio of actual to standard flow: %s' %(V_ratio))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pressure drop = 2.714842967501866 pound_force_per_square_inch\n",
      "upstream speed = 3401.458438219272 foot / minute\n"
     ]
    }
   ],
   "source": [
    "NPS, Di, Do, t = nearest_pipe(NPS=1, schedule='40')\n",
    "Q = V_ratio*100*u.ft**3/u.min\n",
    "L = 75*u.ft\n",
    "\n",
    "MW = 28.958*u.g/u.mol\n",
    "Vm = eos_flowing.V_g*u.m**3/u.mol\n",
    "rho = (Vm)**-1*MW\n",
    "\n",
    "mu = 1.93e-5*u.Pa\n",
    "\n",
    "A = 0.25*pi*Di**2\n",
    "\n",
    "v0 = Q/A\n",
    "m = v0*A*rho\n",
    "\n",
    "Re = rho*v0*Di/mu\n",
    "fd = friction_factor(Re=Re, eD=0.0018*u.inch/Di)\n",
    "P2 = isothermal_gas(rho=rho, fd=fd, P1=P1, P2=None, L=L, D=Di, m=m)\n",
    "\n",
    "print('pressure drop = %s' %(P1-P2))\n",
    "print('upstream speed = %s' %(v0.to(u.ft/u.min)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "downstream speed = 3521.6227060753677 foot / minute\n"
     ]
    }
   ],
   "source": [
    "eos_end = PRMIX(T=(115*u.degF).to(u.K).magnitude, P=P2.to(u.Pa).magnitude, zs=zs, Tcs=Tcs, Pcs=Pcs, omegas=omegas)\n",
    "Vm2 = eos_end.V_g*u.m**3/u.mol\n",
    "rho2 = (Vm2)**-1*MW\n",
    "print('downstream speed = %s' %((v0*rho/rho2).to(u.ft/u.min)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The answers given in Crane are 2.61 psi; and 3367 and 3484 ft/min respectively. A tabular method is used there of limited accuracy.\n",
    "\n",
    "For compressible fluids, there is a benefit to breaking the problem up into sections and performing the calculation to each of them, preferably while including the JT effect and heat loss/gain."
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
