{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7.23 Flow Through Orifice Meters"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A square edged orifice of 2\" diameter is installed in a 4\" schedule 40 pipe. A mercury manometer is connected between standard taps 1D upstream and 0.5D downstream.\n",
    "\n",
    "a) Find the theoretical calibration constant for the meter when 60 deg F water flows through the pipe in the fully turbulent region. \n",
    "\n",
    "b) Find the flow rate of 60 deg F water when the mercury deflection is 4.4\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2022-08-22T01:19:10.017200Z",
     "iopub.status.busy": "2022-08-22T01:19:10.016665Z",
     "iopub.status.idle": "2022-08-22T01:19:10.767440Z",
     "shell.execute_reply": "2022-08-22T01:19:10.766514Z"
    }
   },
   "outputs": [],
   "source": [
    "from fluids.units import *\n",
    "P1 = 2*u.bar # assumed\n",
    "T = 60*u.degF\n",
    "NPS, D_pipe, Do_pipe, t = nearest_pipe(NPS=4, schedule=40)\n",
    "mu = 1.1e-3*u.Pa*u.s # viscosity of water\n",
    "rho = 62.364*u.lb/u.ft**3 # density of water\n",
    "Do = 2*u.inch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2022-08-22T01:19:10.773014Z",
     "iopub.status.busy": "2022-08-22T01:19:10.772327Z",
     "iopub.status.idle": "2022-08-22T01:19:10.794033Z",
     "shell.execute_reply": "2022-08-22T01:19:10.792966Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "105.73900650508152 gallon/minute"
      ],
      "text/latex": [
       "$105.73900650508152\\ \\frac{\\mathrm{gallon}}{\\mathrm{minute}}$"
      ],
      "text/plain": [
       "105.73900650508152 <Unit('gallon / minute')>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# b)\n",
    "dP = (4.4*u.inch_Hg - 4.4*u.inch_H2O_60F)\n",
    "P2 = P1 - dP\n",
    "m =  differential_pressure_meter_solver(D=D_pipe, rho=rho, mu=mu, k=1e20, D2=Do, P1=P1, P2=P2, \n",
    "                                       meter_type='ISO 5167 orifice', taps='D and D/2')\n",
    "Q = (m/rho).to(u.gal/u.min)\n",
    "Q"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2022-08-22T01:19:10.816112Z",
     "iopub.status.busy": "2022-08-22T01:19:10.815722Z",
     "iopub.status.idle": "2022-08-22T01:19:10.823909Z",
     "shell.execute_reply": "2022-08-22T01:19:10.822460Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.6067029339232126 <Unit('dimensionless')>,\n",
       " 0.6260667537160854 <Unit('dimensionless')>)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# a)\n",
    "C, _ = differential_pressure_meter_C_epsilon(D=D_pipe, rho=rho, m=m, mu=mu, k=1e20, D2=Do, P1=P1, P2=P2,\n",
    "                                       meter_type='ISO 5167 orifice', taps='D and D/2')\n",
    "C, flow_coefficient(D_pipe, Do, C)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Crane TP 410 reports a flow coefficient of 0.625 and a flow rate of 106 gal/min, indicating the problem benefited from the iteration little."
   ]
  }
 ],
 "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
}
