{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7.9 Laminar Flow in Valves, Fittings, and Pipe"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "SAE 30 oil at 100 deg F flows through a 5\" schedule 40 pipe at 400 gal/min.\n",
    "\n",
    "There is a sketch in the Crane document of the system.\n",
    "\n",
    "Find the velocity in feet/second and the pressure drop."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2022-08-22T01:20:48.306868Z",
     "iopub.status.busy": "2022-08-22T01:20:48.306396Z",
     "iopub.status.idle": "2022-08-22T01:20:48.975802Z",
     "shell.execute_reply": "2022-08-22T01:20:48.975070Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(26.063989664869815 <Unit('pound_force_per_square_inch')>,\n",
       " 6.414177533606955 <Unit('foot / second')>)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from fluids.units import *\n",
    "from math import pi\n",
    "from fluids.constants import g\n",
    "g = g*u.m/u.s**2\n",
    "\n",
    "dH = 50*u.foot\n",
    "L = (175+50+75)*u.foot\n",
    "mu = 130*u.cP\n",
    "rho = (62.364*0.87)*u.lb/u.ft**3\n",
    "NPS, Di, Do, t = nearest_pipe(Do=5*u.inch, schedule='40')\n",
    "\n",
    "Q = 400*u.gallon/u.min\n",
    "A = 0.25*pi*Di**2\n",
    "\n",
    "v = Q/A\n",
    "Re = rho*v*Di/mu\n",
    "fd = friction_factor(Re=Re, eD=0.0018*u.inch/Di)\n",
    "ft = ft_Crane(Di)\n",
    "\n",
    "K_gate = K_gate_valve_Crane(D1=Di, D2=Di, fd=ft, angle=0.0*u.degrees)\n",
    "K_angle = K_angle_valve_Crane(D1=Di, D2=Di, fd=ft, style=1)\n",
    "K_elbow = bend_rounded(Di=Di, bend_diameters=1, angle=90*u.degrees, Re=Re, method='Crane')\n",
    "\n",
    "K_tot = K_elbow + K_gate + K_angle\n",
    "K_tot += K_from_f(fd=fd, L=L, D=Di)\n",
    "\n",
    "dP = dP_from_K(K=K_tot, rho=rho, V=v) + rho*g*dH\n",
    "dP.to(u.psi), v.to(u.foot/u.s)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "## Intermediate calculations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2022-08-22T01:20:49.006598Z",
     "iopub.status.busy": "2022-08-22T01:20:49.006170Z",
     "iopub.status.idle": "2022-08-22T01:20:49.013479Z",
     "shell.execute_reply": "2022-08-22T01:20:49.012478Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(8.0 <Unit('dimensionless')>,\n",
       " 150.0 <Unit('dimensionless')>,\n",
       " 20.00000000000006 <Unit('dimensionless')>)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "K_gate/ft, K_angle/ft, K_elbow/ft"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2022-08-22T01:20:49.018125Z",
     "iopub.status.busy": "2022-08-22T01:20:49.017841Z",
     "iopub.status.idle": "2022-08-22T01:20:49.023493Z",
     "shell.execute_reply": "2022-08-22T01:20:49.022652Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "29.991124449003742 dimensionless"
      ],
      "text/latex": [
       "$29.991124449003742\\ dimensionless$"
      ],
      "text/plain": [
       "29.991124449003742 <Unit('dimensionless')>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "K_tot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2022-08-22T01:20:49.027410Z",
     "iopub.status.busy": "2022-08-22T01:20:49.027056Z",
     "iopub.status.idle": "2022-08-22T01:20:49.033174Z",
     "shell.execute_reply": "2022-08-22T01:20:49.032192Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "6.414177533606955 foot/second"
      ],
      "text/latex": [
       "$6.414177533606955\\ \\frac{\\mathrm{foot}}{\\mathrm{second}}$"
      ],
      "text/plain": [
       "6.414177533606955 <Unit('foot / second')>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v.to(u.ft/u.s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2022-08-22T01:20:49.037646Z",
     "iopub.status.busy": "2022-08-22T01:20:49.037220Z",
     "iopub.status.idle": "2022-08-22T01:20:49.042976Z",
     "shell.execute_reply": "2022-08-22T01:20:49.042234Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.0381948926809522 <Unit('dimensionless')>,\n",
       " 0.01543941031464228 <Unit('dimensionless')>)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fd, ft"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Proof system is laminar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2022-08-22T01:20:49.047286Z",
     "iopub.status.busy": "2022-08-22T01:20:49.046947Z",
     "iopub.status.idle": "2022-08-22T01:20:49.053514Z",
     "shell.execute_reply": "2022-08-22T01:20:49.052570Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "1675.616699190696 dimensionless"
      ],
      "text/latex": [
       "$1675.616699190696\\ dimensionless$"
      ],
      "text/plain": [
       "1675.616699190696 <Unit('dimensionless')>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Re.to(u.dimensionless)"
   ]
  }
 ],
 "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
}
