{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7.29 Orifice Flow Rate Calculation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "0.07366 meter"
      ],
      "text/latex": [
       "$0.07366\\ \\mathrm{meter}$"
      ],
      "text/plain": [
       "<Quantity(0.07366, 'meter')>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from fluids.units import *\n",
    "from thermo.units import Chemical\n",
    "\n",
    "P1 = 2*u.bar # The full set of equations requires actual pressures not just the pressure difference, so an initial pressure of 2 bar is assumed.\n",
    "P2 = P1 -  17*u.kPa\n",
    "taps = 'D'\n",
    "meter_type = 'ISO 5167 orifice'\n",
    "Do = 50*u.mm\n",
    "\n",
    "NPS, D, _, t_pipe = nearest_pipe(Do=80*u.mm, schedule=80)\n",
    "\n",
    "D"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(<Quantity(999.149354395, 'kilogram / meter ** 3')>,\n",
       " <Quantity(0.00113751328021, 'pascal * second')>,\n",
       " <Quantity(1.32952939555, 'dimensionless')>)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "water = Chemical('water', T=15*u.degC, P=P1)\n",
    "rho = water.rho\n",
    "mu = water.mu\n",
    "k = water.isentropic_exponent\n",
    "rho, mu, k"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7.70427741167 kilogram / second\n",
      "462.650196056 liter / minute\n"
     ]
    }
   ],
   "source": [
    "m = differential_pressure_meter_solver(D=D, D2=Do, P1=P1, P2=P2, rho=rho, mu=mu, k=k, meter_type=meter_type, taps=taps)\n",
    "print(m)\n",
    "Q = m/rho\n",
    "print(Q.to('L/min'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The answer given in TP410M is 478 gallons/minute; however the errata\n",
    "specifies this value is in units of liters/minute insteead.\n",
    "\n",
    "This calculation matches their result well, given they did not include expansivity in their calculations and read a value of C from a graph.\n",
    "\n",
    "A calculator at flow of fluids, which also does not include expansivity, gives an answer of 476.777 L/min, along with 7.93916 kg/s  (http://www.flowoffluids.com/calculators/flow-through-orifices.aspx)."
   ]
  }
 ],
 "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": 1
}
