{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7.26 Pipe Partially Filled with Flowing Water"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Given a cast iron pipe is 2/3 filled with a steady, uniform flow of water at 60 deg F. \n",
    "The pipe has an inside diameter of 24\" and a slope of .75\"/foot\n",
    "\n",
    "Find the flow rate in gallons/minute."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from fluids.units import *\n",
    "from math import pi\n",
    "Di = 24*u.inch\n",
    "depth = 2/3*Di\n",
    "S = 0.75*u.inch/u.ft\n",
    "rho = 62.364*u.lb/u.ft**3\n",
    "mu = 1.1*u.cP\n",
    "eD = 0.00036 # roughness not given in problem, only relative roughness"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.20670024467339204 <Unit('meter ** 2')>,\n",
       " 1.1647220208174018 <Unit('meter')>,\n",
       " 0.1774674480081778 <Unit('meter')>,\n",
       " 0.7098697920327112 <Unit('meter')>)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Use the TANK class to make the geometry easier\n",
    "tank = TANK(D=Di, L=1e-100*u.m, horizontal=True)\n",
    "A = tank.SA_from_h(depth)/2 # wetted surface area of a paper thin tank - divide by two as there is only one side\n",
    "\n",
    "tank = TANK(D=Di, L=1e100*u.m, horizontal=True)\n",
    "P = tank.SA_from_h(depth)/tank.L\n",
    "\n",
    "Rh = A/P\n",
    "Dh = 4*Rh\n",
    "A, P, Rh, Dh"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "24410.948055443227 gallon/minute"
      ],
      "text/latex": [
       "$24410.948055443227\\ \\frac{\\mathrm{gallon}}{\\mathrm{minute}}$"
      ],
      "text/plain": [
       "24410.948055443227 <Unit('gallon / minute')>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 10 meter length basis assumed\n",
    "L = 10.0*u.m\n",
    "dH = L*S\n",
    "dP = dH*rho*u.gravity\n",
    "\n",
    "fd = .0155 # initial guess\n",
    "for i in range(5):\n",
    "    K = K_from_f(fd=fd, L=L, D=Dh)\n",
    "    v = (2*dP/(K*rho))**0.5\n",
    "    Q = A*v\n",
    "    # update friction factor\n",
    "    Re = Reynolds(D=Dh, rho=rho, mu=mu, V=v)\n",
    "    fd = friction_factor(Re=Re, eD=eD)\n",
    "Q.to(u.gal/u.min)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The solution given in Crane is 24500 gpm without iteration."
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
