{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7.36 Hydraulic Resistance of a Diverging Wye"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Given that 60 deg F water flows through a 6\" sched 80 45 degree wye with equal leg diameters, 250 gpm flows through the branch leg and 400 gpm flows through the straight leg.\n",
    "\n",
    "Find the loss coefficients for the straight leg, and the branch leg, as well as the loss coefficients for each flow path. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The combined velocity is 7.996972275001512 foot / second\n",
      "The branch loss coefficient is 0.46461592374032235 dimensionless\n",
      "The run loss coefficient is -0.06827492034592626 dimensionless\n",
      "The branch head loss is 0.4617528263268458 foot\n",
      "The run head loss is -0.06785419058213756 foot\n"
     ]
    }
   ],
   "source": [
    "from fluids.units import *\n",
    "from math import pi\n",
    "NPS, Di, Do, t = nearest_pipe(NPS=6, schedule='80')\n",
    "\n",
    "A = 0.25*pi*Di**2\n",
    "beta = 1 # same diameters\n",
    "\n",
    "rho = 998*u.kg/u.m**3\n",
    "\n",
    "Q_tot = (250+400)*u.gal/u.min\n",
    "Q_straight = 400*u.gal/u.min\n",
    "Q_branch = 250*u.gal/u.min\n",
    "\n",
    "v_combined = Q_tot/A\n",
    "print('The combined velocity is %s' %(v_combined.to(u.ft/u.s)))\n",
    "branch_flow_ratio = Q_branch/Q_tot\n",
    "\n",
    "v_main = Q_straight/A\n",
    "v_leg = Q_branch/A\n",
    "\n",
    "K_branch = K_branch_diverging_Crane(D_run=Di, D_branch=Di, Q_run=Q_straight, Q_branch=Q_branch, angle=45.0*u.degrees)\n",
    "print('The branch loss coefficient is %s' %(K_branch))\n",
    "K_run = K_run_diverging_Crane(D_run=Di, D_branch=Di, Q_run=Q_straight, Q_branch=Q_branch, angle=45.0*u.degrees)\n",
    "print('The run loss coefficient is %s' %(K_run))\n",
    "\n",
    "head_loss_branch = 0.5*rho*v_combined**2*K_branch/(1*u.gravity*rho)\n",
    "print('The branch head loss is %s' %(head_loss_branch.to(u.ft)))\n",
    "\n",
    "head_loss_run = 0.5*rho*v_combined**2*K_run/(1*u.gravity*rho)\n",
    "print('The run head loss is %s' %(head_loss_run.to(u.ft)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The values presented in crane match very nearly exactly; this type of a problem does not require any iteration, unless the density of the fluid is variable."
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
