{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7.6 Reduced Port Ball Valve"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Water is discharged at 15 degrees Celsius from a tank with 7 m of head to atmosphere through:\n",
    "\n",
    "* 60 meters of 80 mm schedule 40 pipe\n",
    "* Six 80 mm standard 90 degree threaded elbows\n",
    "* One 80 mm flanged ball valve, with a 60 mm diameter seat, 16 degree conical inlet and 30 degree conical outlet.\n",
    "* The entrance is sharp-edged and flush with the tank"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2022-08-22T01:20:33.275308Z",
     "iopub.status.busy": "2022-08-22T01:20:33.274803Z",
     "iopub.status.idle": "2022-08-22T01:20:34.692212Z",
     "shell.execute_reply": "2022-08-22T01:20:34.691311Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Velocity = 2.770041323755228 meter / second\n",
      "Flow rate = 792.5474399133158 liter / minute\n"
     ]
    }
   ],
   "source": [
    "from thermo.units import Chemical\n",
    "from fluids.units import *\n",
    "from math import pi\n",
    "water = Chemical('water', T=15*u.degC)\n",
    "rho = water.rho\n",
    "mu = water.mu\n",
    "\n",
    "H = 7*u.m\n",
    "L = 60*u.m\n",
    "fd = 0.017 # assumed in their example\n",
    "NPS, D_pipe, Do_pipe, t = nearest_pipe(Do=80*u.mm)\n",
    "\n",
    "K = K_from_f(fd=fd, L=L, D=D_pipe)\n",
    "K += entrance_sharp()\n",
    "K += exit_normal()\n",
    "K += 6*bend_rounded(D_pipe, angle=90*u.degrees, fd=fd, bend_diameters=0.65)\n",
    "ball_valve_angle = 0.5*(15+30)*u.degrees # use the average angle\n",
    "K += K_ball_valve_Crane(D1=D_pipe, D2=60*u.mm, angle=ball_valve_angle, fd=fd)\n",
    "\n",
    "v = (2*u.gravity*H/K)**0.5\n",
    "print('Velocity = %s' %v.to_base_units())\n",
    "Q = v*pi/4*D_pipe**2\n",
    "print('Flow rate = %s' %Q.to(u.L/u.min))\n",
    "Re = Reynolds(D=D_pipe, rho=rho, mu=mu, V=v)\n",
    "fd = friction_factor(Re=Re, eD=0.0018*u.inch/D_pipe)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The radius of curvature of the elbows was not specified; 0.65 bend diameters matches their results most closely. They modified the ball valve equation to support both an inlet and an outlet angle; the average value is used here.\n",
    "\n",
    "Their calculated values are 2.74 m/s and flow rate of 781 L/min.\n",
    "\n",
    "The calculation can be performed more accurately by iterating; a naive approach is shown below. A very different flow rate is obtained when the roughness of the pipe is considered in the friction factor calculation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2022-08-22T01:20:34.719257Z",
     "iopub.status.busy": "2022-08-22T01:20:34.718466Z",
     "iopub.status.idle": "2022-08-22T01:20:34.737229Z",
     "shell.execute_reply": "2022-08-22T01:20:34.736310Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Flow rate = 792.5474399133158 liter / minute\n",
      "Flow rate = 748.2664116002655 liter / minute\n",
      "Flow rate = 746.5628913428789 liter / minute\n",
      "Flow rate = 746.4941928055326 liter / minute\n",
      "Flow rate = 746.4914172120895 liter / minute\n",
      "Flow rate = 746.491305062719 liter / minute\n",
      "Flow rate = 746.4913005312487 liter / minute\n"
     ]
    }
   ],
   "source": [
    "fd = 0.017\n",
    "for i in range(7):\n",
    "    K = K_from_f(fd=fd, L=L, D=D_pipe)\n",
    "    K += entrance_sharp()\n",
    "    K += exit_normal()\n",
    "    K += 6*bend_rounded(D_pipe, angle=90*u.degrees, fd=fd, bend_diameters=0.65)\n",
    "    ball_valve_angle = 0.5*(15+30)*u.degrees # use the average angle\n",
    "    K += K_ball_valve_Crane(D1=D_pipe, D2=60*u.mm, angle=ball_valve_angle, fd=fd)\n",
    "\n",
    "    v = (2*u.gravity*H/K)**0.5\n",
    "    Q = v*pi/4*D_pipe**2\n",
    "    print('Flow rate = %s' %Q.to(u.L/u.min))\n",
    "    Re = Reynolds(D=D_pipe, rho=rho, mu=mu, V=v)\n",
    "    fd = friction_factor(Re=Re, eD=0.0018*u.inch/D_pipe)"
   ]
  }
 ],
 "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
}
