{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7.27 Sizing Control Valves for Liquid Service"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Given 250 gpm of condensate from a pressurized condensate tank, is cooled from 225 deg F to 160 deg F in a heat exchanger, then pumped to a 50 psig heater.\n",
    "\n",
    "The inlet and outlet pipe of the control valve is schedule 40, with no valves or fittings near the control valve. \n",
    "The system is located in a facility near sea level.\n",
    "\n",
    "A single port globe style valve is to be added.\n",
    "\n",
    "Find an appropriate size valve for the level control.\n",
    "\n",
    "The valve options are 2\", 2.5\", 3\", or 4\"; with Cvs of 41, 73, 114, and 175 respectively."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2022-08-22T01:19:30.737504Z",
     "iopub.status.busy": "2022-08-22T01:19:30.736215Z",
     "iopub.status.idle": "2022-08-22T01:19:31.417719Z",
     "shell.execute_reply": "2022-08-22T01:19:31.417117Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Minimum size is 3.0 inch\n",
      "Calculated Cv is 80.00778994084568 gallon / minute\n"
     ]
    }
   ],
   "source": [
    "from fluids.units import *\n",
    "\n",
    "rho = 60.998*u.lb/u.ft**3\n",
    "mu = 0.39*u.cP\n",
    "Psat = 4.75*u.psi\n",
    "Pc = 3198*u.psi\n",
    "\n",
    "Q = 250*u.gal/u.min\n",
    "P1 = 80.6*u.psi\n",
    "P2 = 70.8*u.psi\n",
    "\n",
    "NPS, D_pipe, Do_pipe, t = nearest_pipe(NPS=4, schedule=40)\n",
    "\n",
    "Cvs = [41*u.gal/u.min, 73*u.gal/u.min, 114*u.gal/u.min, 175*u.gal/u.min]\n",
    "D_valves = [2*u.inch, 2.5*u.inch, 3.0*u.inch, 4*u.inch]\n",
    "\n",
    "for d, Cv in zip(D_valves, Cvs):\n",
    "    Kv = size_control_valve_l(rho=rho, Psat=Psat, Pc=Pc, mu=mu, P1=P1, P2=P2, Q=Q, D1=D_pipe, D2=D_pipe,\n",
    "                             d=d, FL=0.9, Fd=1, allow_choked=True, \n",
    "                             allow_laminar=True, full_output=False)\n",
    "    Cv_calc = Kv_to_Cv(Kv)\n",
    "    if Cv > Cv_calc:\n",
    "        print('Minimum size is %s' %d)\n",
    "        break\n",
    "print('Calculated Cv is %s' %(Cv_calc))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Crane reports a Cv of 79.94. No iteration is required in this problem,\n",
    "except in the control valve sizing function itself."
   ]
  }
 ],
 "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
}
