{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8f706b26-b1a0-4b76-ab48-61f31807a87d",
   "metadata": {},
   "source": [
    "Homework 9 - NUCE 2100\n",
    "\n",
    "**Dane Sabo**\n",
    "\n",
    "*November 19th, 2024*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "bc379333-d776-48b6-b3ff-03c2960d20e5",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import sympy as sm\n",
    "\n",
    "def answer_print(question,string):\n",
    "    print('\\n=========FINAL ANSWER=========')\n",
    "    print(question+':')\n",
    "    print(string)\n",
    "    print('=========FINAL ANSWER=========\\n')"
   ]
  },
  {
   "attachments": {
    "5343f1e9-0aa4-4410-bad6-8b774c055899.png": {
     "image/png": "[encoded data, 212268 characters]"
    }
   },
   "cell_type": "markdown",
   "id": "33a6836e-6019-43da-a06a-a03c645f17bc",
   "metadata": {},
   "source": [
    "![image.png](attachment:5343f1e9-0aa4-4410-bad6-8b774c055899.png)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "3aec147b-37b2-4938-9f33-db77c6836747",
   "metadata": {},
   "outputs": [],
   "source": [
    "N_rods = 204\n",
    "N_thimbles = 21\n",
    "\n",
    "rho_value = 44.81 #lbm/ft^3\n",
    "C_p = 1.322 #BTU/lbm/F\n",
    "k = 0.3188 #BTU/hr/ft/F\n",
    "mu = 0.2188 #lbm/ft/hr\n",
    "\n",
    "d_fuel = 0.422 #in\n",
    "pitch_rod = 0.563 #in\n",
    "d_guide = 0.533 #in\n",
    "pitch_assy = 8.446 #in\n",
    "\n",
    "P_i = 2250 #psia\n",
    "T_bulk = 580 #F\n",
    "G = 2.5e6 #lbm/hr/ft^2 rodded region\n",
    "G = G/60/60 #lbm/s/ft^2\n",
    "\n",
    "l_rod = 12 #ft\n",
    "l_nozzle = 6 #in\n",
    "epsilon_egg = 0.24\n",
    "epsilon_mix_grid = 0.23\n",
    "epsilon_mix_vane = 0.3\n",
    "\n",
    "k_inlet = 2.5\n",
    "k_exit = 2.0\n",
    "epsilon_nozzle = 0.6\n",
    "#smooth tube\n",
    "c_v = 6.5\n",
    "#Yao et al model\n",
    "\n",
    "g_c_value = 32.174 #lbm-ft/(lbf-s^2)\n",
    "g_value = 32.174 #ft/s^2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "84762061-373c-400d-ac32-654fb281eeaa",
   "metadata": {},
   "source": [
    "The general form of the pressure drop equation for incompressible flow with no shaft work is:\n",
    "\n",
    "$$ \\frac{V_f^2 - V_i^2}{2 g_c} + \\frac{g}{g_c}(z_f - z_i) + \\frac{P_f - P_i}{\\rho} + w_\\text{loss} = 0 $$\n",
    "\n",
    "We can find the pressure drop for the whole system by breaking it up into chunks. The first chunk is the inlet nozzle:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "27fe2439-e64e-48e7-a62b-62db8e37f4ca",
   "metadata": {},
   "outputs": [],
   "source": [
    "V_1, V_2, g_c, g, z_1, z_2, P_2, P_1, rho, w_loss = sm.symbols('V_1, V_2, g_c, g, z_1, z_2, P_2, P_1, rho, w_loss')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "9acf4d43-b27d-4019-9b13-b0e3539518bf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle 0 = \\frac{g \\left(- z_{1} + z_{2}\\right)}{g_{c}} + w_{loss} + \\frac{- P_{1} + P_{2}}{\\rho} + \\frac{- \\frac{V_{1}^{2}}{2} + \\frac{V_{2}^{2}}{2}}{g_{c}}$"
      ],
      "text/plain": [
       "Eq(0, g*(-z_1 + z_2)/g_c + w_loss + (-P_1 + P_2)/rho + (-V_1**2/2 + V_2**2/2)/g_c)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "P12 = sm.Eq(0, (V_2**2 - V_1**2)/2/g_c + g/g_c*(z_2 - z_1) + (P_2 - P_1)/rho + w_loss)\n",
    "P12"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4808c364-1f64-4333-9ead-d2e8958af1e5",
   "metadata": {},
   "source": [
    "But what are the losses in the nozzle?\n",
    "- We're given k\n",
    "- Need to find friction factor"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fdf1982f-b471-4286-8faf-63eb9d4157ab",
   "metadata": {},
   "source": [
    "We need to know the velocity of the fluid at the inlet. We know the velocity in the rodded section, and thus can go backwards with the mass flux to find the velocity at the inlet."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "06dd7077-b3a9-479b-a3fb-81b82cf7f4a0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Rodded Hydraulic Diameter: 2.750e-01 ft\n",
      "Nozzle Hydraulic Diameter: 1.014e+01 ft\n",
      "Nozzle Mass Flux: 5.112e-01 lbm/(s-ft^2)\n"
     ]
    }
   ],
   "source": [
    "D_rodded = 4*((pitch_assy*2)**2 - N_rods*np.pi*d_fuel**2/4 - N_thimbles*np.pi*d_guide**2/4)/(N_rods*np.pi*d_fuel + N_thimbles*np.pi*d_guide)/12 #ft\n",
    "print(f'Rodded Hydraulic Diameter: {D_rodded:.3e} ft')\n",
    "D_nozzle = epsilon_nozzle*4*pitch_assy**2/2/pitch_assy\n",
    "print(f'Nozzle Hydraulic Diameter: {D_nozzle:.3e} ft')\n",
    "G_nozzle = G*(np.pi*D_rodded**2/4)/(np.pi*D_nozzle**2/4)\n",
    "print(f'Nozzle Mass Flux: {G_nozzle:.3e} lbm/(s-ft^2)')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "7abbca89-f46b-407d-9e47-d8c4ceb1de83",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reynolds Number in Nozzle: 2.368e+01\n"
     ]
    }
   ],
   "source": [
    "Re_nozzle = G_nozzle*D_nozzle/mu\n",
    "print(f'Reynolds Number in Nozzle: {Re_nozzle:.3e}')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fa4eb242-b913-4cb2-a213-99be39a3997f",
   "metadata": {},
   "source": [
    "Now we can apply Blasius Friction Factor Formula:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "2fe8daf0-d0c3-47ef-996d-9178ddc29902",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Moody Friction Factor (Nozzle): 1.432e-01\n"
     ]
    }
   ],
   "source": [
    "f_m = 0.316*Re_nozzle**(-0.25)\n",
    "print(f'Moody Friction Factor (Nozzle): {f_m:.3e}')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dd28972d-574b-4d1c-919a-235f0a0486c6",
   "metadata": {},
   "source": [
    "And find the lost work from the inlet nozzle."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "35e3e19b-2bc0-4f59-9452-9b78506eab7d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Lost work is 5.071e-06 (lbf-ft/lbm)\n"
     ]
    }
   ],
   "source": [
    "w_loss_12 = f_m*(0.5)/D_nozzle*(G_nozzle/rho_value)**2/2/g_c_value + k_inlet*(G_nozzle/rho_value)**2/2/g_c_value #lbf-ft/lbm\n",
    "print(f'Lost work is {w_loss_12:.3e} (lbf-ft/lbm)')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "029b2ab0-59af-41fb-a97a-704f4dfccd8b",
   "metadata": {},
   "source": [
    "And now we can find the pressure loss of the whole inlet nozzle:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "134f9720-57e3-4038-87bc-c427fe27eafc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle - P_{1} + P_{2} = \\frac{\\rho \\left(V_{1}^{2} - V_{2}^{2} + 2 g z_{1} - 2 g z_{2} - 2 g_{c} w_{loss}\\right)}{2 g_{c}}$"
      ],
      "text/plain": [
       "Eq(-P_1 + P_2, rho*(V_1**2 - V_2**2 + 2*g*z_1 - 2*g*z_2 - 2*g_c*w_loss)/(2*g_c))"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sm.Eq(P_2-P_1,sm.solve(P12,P_2-P_1)[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "7cf0e686-49d3-4c65-a637-4c5244274c22",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The pressure drop from the inlet is -1.897e+02 psia\n"
     ]
    }
   ],
   "source": [
    "delta_P_inlet = rho_value*((G_nozzle/rho_value)**2 - (G/rho_value)**2 + 2*g_value*(-0.5) - 2*g_c_value*w_loss_12) \\\n",
    "    /2/g_c_value\n",
    "print(f'The pressure drop from the inlet is {delta_P_inlet:.3e} psia')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9e73546e-da52-43a5-b762-bda83a92da62",
   "metadata": {},
   "source": [
    "Now we can find the pressure drop from the spacers:\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "f27293d3-f93a-43e9-81ed-e89510c7e15d",
   "metadata": {},
   "outputs": [],
   "source": [
    "V_2, V_3, g_c, g, z_2, z_3, P_3, P_2, rho, w_loss = sm.symbols('V_2, V_3, g_c, g, z_2, z_3, P_3, P_2, rho, w_loss_23')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "48a692db-07f3-47cc-a678-143c36d5ba53",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle 0 = \\frac{g \\left(- z_{2} + z_{3}\\right)}{g_{c}} + w_{loss 23} + \\frac{- P_{2} + P_{3}}{\\rho} + \\frac{- \\frac{V_{2}^{2}}{2} + \\frac{V_{3}^{2}}{2}}{g_{c}}$"
      ],
      "text/plain": [
       "Eq(0, g*(-z_2 + z_3)/g_c + w_loss_23 + (-P_2 + P_3)/rho + (-V_2**2/2 + V_3**2/2)/g_c)"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "P23 = sm.Eq(0, (V_3**2 - V_2**2)/2/g_c + g/g_c*(z_3 - z_2) + (P_3 - P_2)/rho + w_loss)\n",
    "P23"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1b084d11-2065-4461-8ef7-1004c095132b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "attachments": {
    "3ca55df4-a8fd-4c4c-8631-0e07c941607b.png": {
     "image/png": "[encoded data, 166312 characters]"
    }
   },
   "cell_type": "markdown",
   "id": "5c277c94-37a7-4a0b-9a52-35d3bf38e519",
   "metadata": {},
   "source": [
    "![image.png](attachment:3ca55df4-a8fd-4c4c-8631-0e07c941607b.png)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
