{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Imports"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from jitcdde import jitcdde, y, t\n",
    "from parameters import *\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Define System"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# delays\n",
    "taus = [tau_c, tau_c_hx, tau_hx_c, tau_hx_r, tau_l, tau_r_hx]\n",
    "\n",
    "# dT/dt for radiator nodes\n",
    "T_out_rc = (W_rp/mn_rp)*(y(11,t-tau_hx_r)-y(0)) + (hA_rpn/mcp_rpn)*(y(1)-y(0))                  # T_out_rc: y(0)\n",
    "T_out_air = -((W_rs/mn_rs)+(hA_rsn/mcp_rsn))*y(1) + (hA_rsn/mcp_rsn)*y(0) + (W_rs/mn_rs)*Trs_in # T_out_air: y(1)\n",
    "\n",
    "# dT/dt for heat exchanger nodes\n",
    "T_hf1 = -((W_p/mn_p)+(hA_pn/mcp_pn))*y(2) + (hA_pn/mcp_pn)*y(6) + (W_p/mn_p)*y(21,t-tau_c_hx)  # T_hf1: y(2)\n",
    "T_hf2 = (W_p/mn_p)*(y(2)-y(3)) + (hA_pn/mcp_pn)*(y(6)-y(2))                                    # T_hf2: y(3)\n",
    "T_hf3 = -((W_p/mn_p)+(hA_pn/mcp_pn))*y(4) + (hA_pn/mcp_pn)*y(7) + (W_p/mn_p)*y(3)              # T_hf3: y(4)\n",
    "T_hf4 = (W_p/mn_p)*(y(4)-y(5)) + (hA_pn/mcp_pn)*(y(7)-y(4))                                    # T_hf4: y(5)\n",
    "T_ht1 = (2*hA_pn/mcp_tn)*(y(2)-y(6)) + (2*hA_sn/mcp_tn)*(y(10)-y(6))                           # T_ht1: y(6)\n",
    "T_ht2 = (2*hA_pn/mcp_tn)*(y(4)-y(7)) + (2*hA_sn/mcp_tn)*(y(8)-y(7))                            # T_ht2: y(7)\n",
    "T_hc1 = -((W_s/mn_s)+(hA_sn/mcp_sn))*y(8) + (hA_sn/mcp_sn)*y(7) + (W_s/mn_s)*y(0,t-tau_r_hx)   # T_hc1: y(8)\n",
    "T_hc2 = (W_s/mn_s)*(y(8)-y(9)) + (hA_sn/mcp_sn)*(y(7)-y(8))                                    # T_hc2: y(9)\n",
    "T_hc3 = -((W_s/mn_s)+(hA_sn/mcp_sn))*y(10) + (hA_sn/mcp_sn)*y(6) + (W_s/mn_s)*y(9)             # T_hc3: y(10)\n",
    "T_hc4 = (W_s/mn_s)*(y(10)-y(11)) + (hA_sn/mcp_sn)*(y(6)-y(10))                                 # T_hc4: y(11)\n",
    "\n",
    "# dn/dt\n",
    "n = (y(22)-beta_t)*y(12)/Lam+lam[0]*y(13)+lam[1]*y(14)+lam[2]*y(15)+lam[3]*y(16)+lam[4]*y(17)+lam[5]*y(18) # n (no source insertion): y(12)\n",
    "\n",
    "# dC_i/dt (precursor concentrations)\n",
    "C1 = y(12)*beta[0]/Lam-lam[0]*y(13)-y(13)/tau_c+y(13,t-tau_l)*np.exp(-lam[0]*tau_l)/tau_c  # C1: y(13)\n",
    "C2 = y(12)*beta[1]/Lam-lam[1]*y(14)-y(14)/tau_c+y(14,t-tau_l)*np.exp(-lam[1]*tau_l)/tau_c  # C2: y(14)\n",
    "C3 = y(12)*beta[2]/Lam-lam[2]*y(15)-y(15)/tau_c+y(15,t-tau_l)*np.exp(-lam[2]*tau_l)/tau_c  # C3: y(15)\n",
    "C4 = y(12)*beta[3]/Lam-lam[3]*y(16)-y(16)/tau_c+y(16,t-tau_l)*np.exp(-lam[3]*tau_l)/tau_c  # C4: y(16)\n",
    "C5 = y(12)*beta[4]/Lam-lam[4]*y(17)-y(17)/tau_c+y(17,t-tau_l)*np.exp(-lam[4]*tau_l)/tau_c  # C5: y(17)\n",
    "C6 = y(12)*beta[5]/Lam-lam[5]*y(18)-y(18)/tau_c+y(18,t-tau_l)*np.exp(-lam[5]*tau_l)/tau_c  # C6: y(18)\n",
    "\n",
    "# dT/dt core nodes\n",
    "T_cg = (hA_fg/mcp_g1)*(y(20)-y(19)) + k_g*P*y(12)/mcp_g1                                             # T_cg: y(19)\n",
    "T_cf1 = W_f/mn_f*(y(5,t-tau_hx_c)-y(20)) + (k_f1*P*y(12)/mcp_f1) + (hA_fg*k_1*(y(19)-y(20))/mcp_f1)  # T_cf1: y(20)\n",
    "T_cf2 = W_f/mn_f*(y(20)-y(21)) + (k_f2*P*y(12)/mcp_f2) + (hA_fg*k_2*(y(19)-y(20))/mcp_f2)            # T_cf2: y(21)\n",
    "\n",
    "# rho y(22)\n",
    "rho = (a_f/2)*(T_cf1 + T_cf2) + (a_g)*(T_cg)\n",
    "\n",
    "# initial reactivity \n",
    "rho_initial = 0.000"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solve with JiTCDDE"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Generating, compiling, and loading C code.\n",
      "Using default integration parameters.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/mnt/envs/thesis_env/lib/python3.9/site-packages/jitcdde/_jitcdde.py:795: UserWarning: You did not explicitly handle initial discontinuities. Proceed only if you know what you are doing. This is only fine if you somehow chose your initial past such that the derivative of the last anchor complies with the DDE. In this case, you can set the attribute `initial_discontinuities_handled` to `True` to suppress this warning. See https://jitcdde.rtfd.io/#discontinuities for details.\n",
      "  warn(\"You did not explicitly handle initial discontinuities. Proceed only if you know what you are doing. This is only fine if you somehow chose your initial past such that the derivative of the last anchor complies with the DDE. In this case, you can set the attribute `initial_discontinuities_handled` to `True` to suppress this warning. See https://jitcdde.rtfd.io/#discontinuities for details.\")\n",
      "/mnt/envs/thesis_env/lib/python3.9/site-packages/jitcdde/_jitcdde.py:795: UserWarning: You did not explicitly handle initial discontinuities. Proceed only if you know what you are doing. This is only fine if you somehow chose your initial past such that the derivative of the last anchor complies with the DDE. In this case, you can set the attribute `initial_discontinuities_handled` to `True` to suppress this warning. See https://jitcdde.rtfd.io/#discontinuities for details.\n",
      "  warn(\"You did not explicitly handle initial discontinuities. Proceed only if you know what you are doing. This is only fine if you somehow chose your initial past such that the derivative of the last anchor complies with the DDE. In this case, you can set the attribute `initial_discontinuities_handled` to `True` to suppress this warning. See https://jitcdde.rtfd.io/#discontinuities for details.\")\n",
      "/mnt/envs/thesis_env/lib/python3.9/site-packages/jitcdde/_jitcdde.py:792: UserWarning: The target time is smaller than the current time. No integration step will happen. The returned state will be extrapolated from the interpolating Hermite polynomial for the last integration step. You may see this because you try to integrate backwards in time, in which case you did something wrong. You may see this just because your sampling step is small, in which case there is no need to worry.\n",
      "  warn(\"The target time is smaller than the current time. No integration step will happen. The returned state will be extrapolated from the interpolating Hermite polynomial for the last integration step. You may see this because you try to integrate backwards in time, in which case you did something wrong. You may see this just because your sampling step is small, in which case there is no need to worry.\")\n"
     ]
    }
   ],
   "source": [
    "# instantiate jitcdde object\n",
    "DDE = jitcdde([T_out_rc,T_out_air,T_hf1,T_hf2,T_hf3,T_hf4,T_ht1,T_ht2,T_hc1,\n",
    "               T_hc2,T_hc3,T_hc4,n,C1,C2,C3,C4,C5,C6,T_cg,T_cf1,T_cf2,rho])\n",
    "\n",
    "# set initial conditions\n",
    "DDE.constant_past([T0_rp, T0_rs, T0_p1,T0_p2, T0_p3, T0_p4, T0_t1, T0_t2, T0_s1, T0_s2, \n",
    "          T0_s3, T0_s4, n_frac0, C0[0], C0[1], C0[2], C0[3], C0[4], C0[5], \n",
    "          T0_g1, T0_f1, T0_f2,rho_initial])\n",
    "\n",
    "# jitcdde solver parameters \n",
    "t0 = 0.0\n",
    "tf = 1000.00\n",
    "T = np.arange(t0,tf,0.01)\n",
    "\n",
    "sol_jit = []\n",
    "for t_x in T:\n",
    "    sol_jit.append(DDE.integrate(t_x))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Vary temeprature feedback coefficients"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Generating, compiling, and loading C code.\n",
      "Using default integration parameters.\n",
      "Generating, compiling, and loading C code.\n",
      "Using default integration parameters.\n",
      "Generating, compiling, and loading C code.\n",
      "Using default integration parameters.\n",
      "Generating, compiling, and loading C code.\n",
      "Using default integration parameters.\n"
     ]
    }
   ],
   "source": [
    "# solution vectors\n",
    "sols = []\n",
    "sols = [sol_jit]\n",
    "\n",
    "# feedbacks\n",
    "factors_f = [1/2, 1/4, 1/8, 0]\n",
    "factors_g = [1/2, 1/4, 1/8, 0]\n",
    "\n",
    "for i in range(len(factors_f)):\n",
    "\n",
    "    # reinstantiate jitcdde objects\n",
    "    import sys\n",
    "    sys.modules.pop('jitcdde')\n",
    "    from jitcdde import jitcdde, y, t\n",
    "\n",
    "    # rho y(22)\n",
    "    a_f_i = factors_f[i]\n",
    "    a_g_i = factors_g[i]\n",
    "    rho = a_f_i*(a_f/2)*(T_cf1 + T_cf2) + a_g_i*(a_g)*(T_cg)\n",
    "\n",
    "    # instantiate jitcdde object\n",
    "    DDE = jitcdde([T_out_rc,T_out_air,T_hf1,T_hf2,T_hf3,T_hf4,T_ht1,T_ht2,T_hc1,\n",
    "                T_hc2,T_hc3,T_hc4,n,C1,C2,C3,C4,C5,C6,T_cg,T_cf1,T_cf2,rho])\n",
    "\n",
    "    # set initial conditions\n",
    "    DDE.constant_past([T0_rp, T0_rs, T0_p1,T0_p2, T0_p3, T0_p4, T0_t1, T0_t2, T0_s1, T0_s2, \n",
    "            T0_s3, T0_s4, n_frac0, C0[0], C0[1], C0[2], C0[3], C0[4], C0[5], \n",
    "            T0_g1, T0_f1, T0_f2,rho_initial])\n",
    "    \n",
    "    sol_i = []\n",
    "    for t_x in T:\n",
    "        sol_i.append(DDE.integrate(t_x))\n",
    "    sols.append(sol_i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 1.0, '$\\\\rho$')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 182408 characters]",
      "text/plain": [
       "<Figure size 1800x1200 with 6 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig,axs = plt.subplots(2,3,figsize=(18,12))\n",
    "\n",
    "# fuel temps\n",
    "#axs[0,0].set_xlim([0,20])\n",
    "axs[0,0].plot(T,[s[20] for s in sols[0]],label=\"core 1\") \n",
    "axs[0,0].plot(T,[s[21] for s in sols[0]],label=\"core 2\") \n",
    "axs[0,0].plot(T,[s[2] for s in sols[0]],label=\"hx 1\")  \n",
    "axs[0,0].plot(T,[s[3] for s in sols[0]],label=\"hx 2\")\n",
    "axs[0,0].plot(T,[s[4] for s in sols[0]],label=\"hx 3\")\n",
    "axs[0,0].plot(T,[s[5] for s in sols[0]],label=\"hx 4\")  \n",
    "axs[0,0].legend()\n",
    "axs[0,0].set_title(\"Fuel Node Temperatures (C)\")\n",
    "axs[0,0].tick_params(\n",
    "    axis='x',          # changes apply to the x-axis\n",
    "    which='both',      # both major and minor ticks are affected\n",
    "    bottom=False,      # ticks along the bottom edge are off\n",
    "    top=False,         # ticks along the top edge are off\n",
    "    labelbottom=False) # labels along the bottom edge are off\n",
    "\n",
    "# coolant temps\n",
    "#axs[0,1].set_xlim([0,20])\n",
    "axs[0,1].plot(T,[s[8] for s in sols[0]],label=\"hx 1\") \n",
    "axs[0,1].plot(T,[s[9] for s in sols[0]],label=\"hx 2\") \n",
    "axs[0,1].plot(T,[s[10] for s in sols[0]],label=\"hx 3\")  \n",
    "axs[0,1].plot(T,[s[11] for s in sols[0]],label=\"hx 4\")\n",
    "axs[0,1].plot(T,[s[0] for s in sols[0]],label=\"r 1\")\n",
    "axs[0,1].legend()\n",
    "axs[0,1].set_title(\"Coolant Node Temperatures (C)\")\n",
    "axs[0,1].tick_params(\n",
    "    axis='x',          # changes apply to the x-axis\n",
    "    which='both',      # both major and minor ticks are affected\n",
    "    bottom=False,      # ticks along the bottom edge are off\n",
    "    top=False,         # ticks along the top edge are off\n",
    "    labelbottom=False) # labels along the bottom edge are off\n",
    "\n",
    "# tube node temps\n",
    "#axs[0,2].set_xlim([0,20])\n",
    "axs[0,2].plot(T,[s[6] for s in sols[0]],label=\"hx 1\") \n",
    "axs[0,2].plot(T,[s[7] for s in sols[0]],label=\"hx 2\") \n",
    "axs[0,2].legend()\n",
    "axs[0,2].set_title(\"Tube Node Temperatures (C)\")\n",
    "axs[0,2].tick_params(\n",
    "    axis='x',          # changes apply to the x-axis\n",
    "    which='both',      # both major and minor ticks are affected\n",
    "    bottom=False,      # ticks along the bottom edge are off\n",
    "    top=False,         # ticks along the top edge are off\n",
    "    labelbottom=False) # labels along the bottom edge are off\n",
    "\n",
    "# precursor concentrations\n",
    "#axs[1,2].set_xlim([0,20])\n",
    "axs[1,2].plot(T,[s[13] for s in sols[0]],label=\"C1\") \n",
    "axs[1,2].plot(T,[s[14] for s in sols[0]],label=\"C2\") \n",
    "axs[1,2].plot(T,[s[15] for s in sols[0]],label=\"C3\")  \n",
    "axs[1,2].plot(T,[s[16] for s in sols[0]],label=\"C4\")\n",
    "axs[1,2].plot(T,[s[17] for s in sols[0]],label=\"C5\")\n",
    "axs[1,2].plot(T,[s[18] for s in sols[0]],label=\"C6\")\n",
    "axs[1,2].legend()\n",
    "axs[1,2].set_xlabel(\"t (s)\")\n",
    "axs[1,2].set_yscale(\"log\")\n",
    "axs[1,2].set_ylabel(r\"concentration (1/cm$^3$)\")\n",
    "axs[1,2].legend(loc=\"right\")\n",
    "axs[1,2].set_title(\"Precursor Concentrations\")\n",
    "\n",
    "# multiplication factor temp\n",
    "#axs[1,0].set_xlim([0,20])\n",
    "axs[1,0].plot(T,[s[12] for s in sols[0]],label=\"n\") \n",
    "axs[1,0].set_xlabel(\"t (s)\")\n",
    "axs[1,0].set_title(r\"$n$\")\n",
    "axs[1,0].set_ylabel(r\"$\\frac{n}{n_0}$\")\n",
    "\n",
    "# reactivity\n",
    "#axs[1,1].set_xlim([0,20])\n",
    "axs[1,1].plot(T,[s[22] for s in sols[0]],label=\"n\") \n",
    "axs[1,1].set_xlabel(\"t (s)\")\n",
    "axs[1,1].set_title(r\"$\\rho$\")\n",
    "\n",
    "#plt.figure(figsize=(8,6))\n",
    "#plt.plot(T,[s[12] for s in sols[0]],label=r\"$(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\")\n",
    "#plt.plot(T,[s[12] for s in sols[1]],label=r\"$(\\alpha_f,\\alpha_g) = $ (-4.36,-3.33) pcm\")\n",
    "#plt.plot(T,[s[12] for s in sols[2]],label=r\"$(\\alpha_f,\\alpha_g) = $ (-2.18,-1.67) pcm\")\n",
    "#plt.plot(T,[s[12] for s in sols[3]],label=r\"$(\\alpha_f,\\alpha_g) = $ (-1.09,-0.83) pcm\")\n",
    "#plt.plot(T,[s[12] for s in sols[4]],label=r\"$(\\alpha_f,\\alpha_g) = $ (0.0,0.0) pcm\")\n",
    "#plt.xlabel(\"t (s)\")\n",
    "#plt.ylabel(r\"$n/n_0$\",rotation=0)\n",
    "#plt.legend()\n",
    "#plt.ylim([0,20])\n",
    "#plt.xlim([0,500])\n",
    "#plt.title(r\"Reactor Response vs $\\alpha$\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Feedback"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 1.0, '$\\\\rho$')"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 249152 characters]",
      "text/plain": [
       "<Figure size 1800x1200 with 6 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig,axs = plt.subplots(2,3,figsize=(18,12))\n",
    "\n",
    "t_stop = 125\n",
    "\n",
    "# fuel temps\n",
    "#axs[0,0].set_xlim([0, 500])\n",
    "#axs[0,0].set_ylim([600, 1000])\n",
    "axs[0,0].set_xlim([0,t_stop])\n",
    "axs[0,0].plot(T,[s[20] for s in sols[0]],label=r\"core 1: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\")\n",
    "axs[0,0].plot(T,[s[20] for s in sols[1]],label=r\"core 1: $(\\alpha_f,\\alpha_g) = $ (-4.36,-3.33) pcm\")\n",
    "axs[0,0].plot(T,[s[20] for s in sols[2]],label=r\"core 1: $(\\alpha_f,\\alpha_g) = $ (-2.18,-1.67) pcm\")\n",
    "axs[0,0].plot(T,[s[20] for s in sols[3]],label=r\"core 1: $(\\alpha_f,\\alpha_g) = $ (-1.09,-0.83) pcm\")\n",
    "axs[0,0].plot(T,[s[20] for s in sols[4]],label=r\"core 1: $(\\alpha_f,\\alpha_g) = $ (-0.00,-0.00) pcm\")\n",
    "axs[0,0].legend()\n",
    "axs[0,0].set_title(\"Fuel Node Temperatures (C)\")\n",
    "axs[0,0].tick_params(\n",
    "    axis='x',          # changes apply to the x-axis\n",
    "    which='both',      # both major and minor ticks are affected\n",
    "    bottom=False,      # ticks along the bottom edge are off\n",
    "    top=False,         # ticks along the top edge are off\n",
    "    labelbottom=False) # labels along the bottom edge are off\n",
    "\n",
    "# coolant temps\n",
    "#axs[0,1].set_xlim([0, 1000])\n",
    "#axs[0,1].set_ylim([500, 1000])\n",
    "axs[0,1].set_xlim([0,t_stop])\n",
    "axs[0,1].plot(T,[s[8] for s in sols[0]],label=r\"hx 1: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\")\n",
    "axs[0,1].plot(T,[s[8] for s in sols[1]],label=r\"hx 1: $(\\alpha_f,\\alpha_g) = $ (-4.36,-3.33) pcm\")\n",
    "axs[0,1].plot(T,[s[8] for s in sols[2]],label=r\"hx 1: $(\\alpha_f,\\alpha_g) = $ (-2.18,-1.67) pcm\")\n",
    "axs[0,1].plot(T,[s[8] for s in sols[3]],label=r\"hx 1: $(\\alpha_f,\\alpha_g) = $ (-1.09,-0.83) pcm\")\n",
    "axs[0,1].plot(T,[s[8] for s in sols[4]],label=r\"hx 1: $(\\alpha_f,\\alpha_g) = $ (-0.00,-0.00) pcm\")\n",
    "axs[0,1].legend()\n",
    "axs[0,1].set_title(\"Coolant Node Temperatures (C)\")\n",
    "axs[0,1].tick_params(\n",
    "    axis='x',          # changes apply to the x-axis\n",
    "    which='both',      # both major and minor ticks are affected\n",
    "    bottom=False,      # ticks along the bottom edge are off\n",
    "    top=False,         # ticks along the top edge are off\n",
    "    labelbottom=False) # labels along the bottom edge are off\n",
    "\n",
    "# tube node temps\n",
    "#axs[0,2].set_xlim([0, 500])\n",
    "#axs[0,2].set_ylim([500, 1000])\n",
    "axs[0,2].set_xlim([0,t_stop])\n",
    "axs[0,2].plot(T,[s[8] for s in sols[0]],label=r\"t1: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\")\n",
    "axs[0,2].plot(T,[s[8] for s in sols[1]],label=r\"t1: $(\\alpha_f,\\alpha_g) = $ (-4.36,-3.33) pcm\")\n",
    "axs[0,2].plot(T,[s[8] for s in sols[2]],label=r\"t1: $(\\alpha_f,\\alpha_g) = $ (-2.18,-1.67) pcm\")\n",
    "axs[0,2].plot(T,[s[8] for s in sols[3]],label=r\"t1: $(\\alpha_f,\\alpha_g) = $ (-1.09,-0.83) pcm\")\n",
    "axs[0,2].plot(T,[s[8] for s in sols[4]],label=r\"t1: $(\\alpha_f,\\alpha_g) = $ (-0.00,-0.00) pcm\")\n",
    "\n",
    "# tube node temps\n",
    "axs[0,2].plot(T,[s[9] for s in sols[0]],label=r\"t2: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\")\n",
    "axs[0,2].plot(T,[s[9] for s in sols[1]],label=r\"t2: $(\\alpha_f,\\alpha_g) = $ (-4.36,-3.33) pcm\")\n",
    "axs[0,2].plot(T,[s[9] for s in sols[2]],label=r\"t2: $(\\alpha_f,\\alpha_g) = $ (-2.18,-1.67) pcm\")\n",
    "axs[0,2].plot(T,[s[9] for s in sols[3]],label=r\"t2: $(\\alpha_f,\\alpha_g) = $ (-1.09,-0.83) pcm\")\n",
    "axs[0,2].plot(T,[s[9] for s in sols[4]],label=r\"t2: $(\\alpha_f,\\alpha_g) = $ (-0.00,-0.00) pcm\")\n",
    "\n",
    "axs[0,2].legend()\n",
    "axs[0,2].set_title(\"Tube Node Temperatures (C)\")\n",
    "axs[0,2].tick_params(\n",
    "    axis='x',          # changes apply to the x-axis\n",
    "    which='both',      # both major and minor ticks are affected\n",
    "    bottom=False,      # ticks along the bottom edge are off\n",
    "    top=False,         # ticks along the top edge are off\n",
    "    labelbottom=False) # labels along the bottom edge are off\n",
    "\n",
    "# precursor concentrations\n",
    "#axs[1,2].set_xlim([0, 500])\n",
    "#axs[1,2].set_ylim([1e1,1e3])\n",
    "axs[1,2].set_xlim([0,t_stop])\n",
    "axs[1,2].plot(T,[s[13] for s in sols[0]],label=r\"C1: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\")\n",
    "axs[1,2].plot(T,[s[13] for s in sols[1]],label=r\"C1: $(\\alpha_f,\\alpha_g) = $ (-4.36,-3.33) pcm\")\n",
    "axs[1,2].plot(T,[s[13] for s in sols[2]],label=r\"C1: $(\\alpha_f,\\alpha_g) = $ (-2.18,-1.67) pcm\")\n",
    "axs[1,2].plot(T,[s[13] for s in sols[3]],label=r\"C1: $(\\alpha_f,\\alpha_g) = $ (-1.09,-0.83) pcm\")\n",
    "axs[1,2].plot(T,[s[13] for s in sols[4]],label=r\"C1: $(\\alpha_f,\\alpha_g) = $ (-0.00,-0.00) pcm\")\n",
    "axs[1,2].legend()\n",
    "axs[1,2].set_xlabel(\"t (s)\")\n",
    "axs[1,2].set_yscale(\"log\")\n",
    "axs[1,2].legend(loc=\"right\")\n",
    "axs[1,2].set_title(\"Precursor Concentrations\")\n",
    "axs[1,2].set_ylabel(r\"concentration (1/cm$^3$)\")\n",
    "\n",
    "# multiplication factor \n",
    "#axs[1,0].set_ylim([0,20])\n",
    "#axs[1,0].set_xlim([0,500])\n",
    "axs[1,0].set_xlim([0,t_stop])\n",
    "axs[1,0].plot(T,[s[12] for s in sols[0]],label=r\"n: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\")\n",
    "axs[1,0].plot(T,[s[12] for s in sols[1]],label=r\"n: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\")\n",
    "axs[1,0].plot(T,[s[12] for s in sols[2]],label=r\"n: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\")\n",
    "axs[1,0].plot(T,[s[12] for s in sols[3]],label=r\"n: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\")\n",
    "axs[1,0].plot(T,[s[12] for s in sols[4]],label=r\"n: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\")\n",
    "axs[1,0].set_xlabel(\"t (s)\")\n",
    "axs[1,0].set_title(r\"$n$\")\n",
    "axs[1,0].set_ylabel(r\"$\\frac{n}{n_0}$\")\n",
    "\n",
    "# reactivity\n",
    "#axs[1,0].set_ylim([0,0])\n",
    "#axs[1,0].set_xlim([0,500])\n",
    "axs[1,1].set_xlim([0,t_stop])\n",
    "axs[1,1].plot(T,[s[22] for s in sols[0]],label=r\"$\\rho$: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\")\n",
    "axs[1,1].plot(T,[s[22] for s in sols[1]],label=r\"$\\rho$: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\")\n",
    "axs[1,1].plot(T,[s[22] for s in sols[2]],label=r\"$\\rho$: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\")\n",
    "axs[1,1].plot(T,[s[22] for s in sols[3]],label=r\"$\\rho$: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\")\n",
    "axs[1,1].plot(T,[s[22] for s in sols[4]],label=r\"$\\rho$: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\")\n",
    "axs[1,1].set_xlabel(\"t (s)\")\n",
    "axs[1,1].set_title(r\"$\\rho$\")\n",
    "\n",
    "#plt.figure(figsize=(8,6))\n",
    "#plt.plot(T,[s[12] for s in sols[0]],label=r\"$(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\")\n",
    "#plt.plot(T,[s[12] for s in sols[1]],label=r\"$(\\alpha_f,\\alpha_g) = $ (-4.36,-3.33) pcm\")\n",
    "#plt.plot(T,[s[12] for s in sols[2]],label=r\"$(\\alpha_f,\\alpha_g) = $ (-2.18,-1.67) pcm\")\n",
    "#plt.plot(T,[s[12] for s in sols[3]],label=r\"$(\\alpha_f,\\alpha_g) = $ (-1.09,-0.83) pcm\")\n",
    "#plt.plot(T,[s[12] for s in sols[4]],label=r\"$(\\alpha_f,\\alpha_g) = $ (0.0,0.0) pcm\")\n",
    "#plt.xlabel(\"t (s)\")\n",
    "#plt.ylabel(r\"$n/n_0$\",rotation=0)\n",
    "#plt.legend()\n",
    "#plt.ylim([0,20])\n",
    "#plt.xlim([0,500])\n",
    "#plt.title(r\"Reactor Response vs $\\alpha$\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Generating, compiling, and loading C code.\n",
      "Using default integration parameters.\n",
      "Generating, compiling, and loading C code.\n",
      "Using default integration parameters.\n",
      "Generating, compiling, and loading C code.\n",
      "Using default integration parameters.\n",
      "Generating, compiling, and loading C code.\n",
      "Using default integration parameters.\n",
      "Generating, compiling, and loading C code.\n",
      "Using default integration parameters.\n"
     ]
    }
   ],
   "source": [
    "# redefine system and get new solution set \n",
    "\n",
    "# delays\n",
    "taus = [tau_c, tau_c_hx, tau_hx_c, tau_hx_r, tau_l, tau_r_hx]\n",
    "\n",
    "# adjust delay term \n",
    "#tau_hx_c *= 0.5\n",
    "tau_c_hx *= 0.5\n",
    "#tau_r_hx *= 0.5\n",
    "\n",
    "# dT/dt for radiator nodes\n",
    "T_out_rc = (W_rp/mn_rp)*(y(11,t-tau_hx_r)-y(0)) + (hA_rpn/mcp_rpn)*(y(1)-y(0))                  # T_out_rc: y(0)\n",
    "T_out_air = -((W_rs/mn_rs)+(hA_rsn/mcp_rsn))*y(1) + (hA_rsn/mcp_rsn)*y(0) + (W_rs/mn_rs)*Trs_in # T_out_air: y(1)\n",
    "\n",
    "# dT/dt for heat exchanger nodes\n",
    "T_hf1 = -((W_p/mn_p)+(hA_pn/mcp_pn))*y(2) + (hA_pn/mcp_pn)*y(6) + (W_p/mn_p)*y(21,t-tau_c_hx)  # T_hf1: y(2)\n",
    "T_hf2 = (W_p/mn_p)*(y(2)-y(3)) + (hA_pn/mcp_pn)*(y(6)-y(2))                                    # T_hf2: y(3)\n",
    "T_hf3 = -((W_p/mn_p)+(hA_pn/mcp_pn))*y(4) + (hA_pn/mcp_pn)*y(7) + (W_p/mn_p)*y(3)              # T_hf3: y(4)\n",
    "T_hf4 = (W_p/mn_p)*(y(4)-y(5)) + (hA_pn/mcp_pn)*(y(7)-y(4))                                    # T_hf4: y(5)\n",
    "T_ht1 = (2*hA_pn/mcp_tn)*(y(2)-y(6)) + (2*hA_sn/mcp_tn)*(y(10)-y(6))                           # T_ht1: y(6)\n",
    "T_ht2 = (2*hA_pn/mcp_tn)*(y(4)-y(7)) + (2*hA_sn/mcp_tn)*(y(8)-y(7))                            # T_ht2: y(7)\n",
    "T_hc1 = -((W_s/mn_s)+(hA_sn/mcp_sn))*y(8) + (hA_sn/mcp_sn)*y(7) + (W_s/mn_s)*y(0,t-tau_r_hx)   # T_hc1: y(8)\n",
    "T_hc2 = (W_s/mn_s)*(y(8)-y(9)) + (hA_sn/mcp_sn)*(y(7)-y(8))                                    # T_hc2: y(9)\n",
    "T_hc3 = -((W_s/mn_s)+(hA_sn/mcp_sn))*y(10) + (hA_sn/mcp_sn)*y(6) + (W_s/mn_s)*y(9)             # T_hc3: y(10)\n",
    "T_hc4 = (W_s/mn_s)*(y(10)-y(11)) + (hA_sn/mcp_sn)*(y(6)-y(10))                                 # T_hc4: y(11)\n",
    "\n",
    "# dn/dt\n",
    "n = (y(22)-beta_t)*y(12)/Lam+lam[0]*y(13)+lam[1]*y(14)+lam[2]*y(15)+lam[3]*y(16)+lam[4]*y(17)+lam[5]*y(18) # n (no source insertion): y(12)\n",
    "\n",
    "# dC_i/dt (precursor concentrations)\n",
    "C1 = y(12)*beta[0]/Lam-lam[0]*y(13)-y(13)/tau_c+y(13,t-tau_l)*np.exp(-lam[0]*tau_l)/tau_c  # C1: y(13)\n",
    "C2 = y(12)*beta[1]/Lam-lam[1]*y(14)-y(14)/tau_c+y(14,t-tau_l)*np.exp(-lam[1]*tau_l)/tau_c  # C2: y(14)\n",
    "C3 = y(12)*beta[2]/Lam-lam[2]*y(15)-y(15)/tau_c+y(15,t-tau_l)*np.exp(-lam[2]*tau_l)/tau_c  # C3: y(15)\n",
    "C4 = y(12)*beta[3]/Lam-lam[3]*y(16)-y(16)/tau_c+y(16,t-tau_l)*np.exp(-lam[3]*tau_l)/tau_c  # C4: y(16)\n",
    "C5 = y(12)*beta[4]/Lam-lam[4]*y(17)-y(17)/tau_c+y(17,t-tau_l)*np.exp(-lam[4]*tau_l)/tau_c  # C5: y(17)\n",
    "C6 = y(12)*beta[5]/Lam-lam[5]*y(18)-y(18)/tau_c+y(18,t-tau_l)*np.exp(-lam[5]*tau_l)/tau_c  # C6: y(18)\n",
    "\n",
    "# dT/dt core nodes\n",
    "T_cg = (hA_fg/mcp_g1)*(y(20)-y(19)) + k_g*P*y(12)/mcp_g1                                             # T_cg: y(19)\n",
    "T_cf1 = W_f/mn_f*(y(5,t-tau_hx_c)-y(20)) + (k_f1*P*y(12)/mcp_f1) + (hA_fg*k_1*(y(19)-y(20))/mcp_f1)  # T_cf1: y(20)\n",
    "T_cf2 = W_f/mn_f*(y(20)-y(21)) + (k_f2*P*y(12)/mcp_f2) + (hA_fg*k_2*(y(19)-y(20))/mcp_f2)            # T_cf2: y(21)\n",
    "\n",
    "# rho y(22)\n",
    "rho = (a_f/2)*(T_cf1 + T_cf2) + (a_g)*(T_cg)\n",
    "\n",
    "# initial reactivity \n",
    "rho_initial = 0.000\n",
    "\n",
    "# instantiate jitcdde object\n",
    "DDE = jitcdde([T_out_rc,T_out_air,T_hf1,T_hf2,T_hf3,T_hf4,T_ht1,T_ht2,T_hc1,\n",
    "               T_hc2,T_hc3,T_hc4,n,C1,C2,C3,C4,C5,C6,T_cg,T_cf1,T_cf2,rho])\n",
    "\n",
    "# set initial conditions\n",
    "DDE.constant_past([T0_rp, T0_rs, T0_p1,T0_p2, T0_p3, T0_p4, T0_t1, T0_t2, T0_s1, T0_s2, \n",
    "          T0_s3, T0_s4, n_frac0, C0[0], C0[1], C0[2], C0[3], C0[4], C0[5], \n",
    "          T0_g1, T0_f1, T0_f2,rho_initial])\n",
    "\n",
    "# jitcdde solver parameters \n",
    "t0 = 0.0\n",
    "tf = 1000.00\n",
    "T = np.arange(t0,tf,0.01)\n",
    "\n",
    "sol_jit = []\n",
    "for t_x in T:\n",
    "    sol_jit.append(DDE.integrate(t_x))\n",
    "\n",
    "sols.append(sol_jit)\n",
    "\n",
    "# feedbacks\n",
    "factors_f = [1/2, 1/4, 1/8, 0]\n",
    "factors_g = [1/2, 1/4, 1/8, 0]\n",
    "\n",
    "for i in range(len(factors_f)):\n",
    "\n",
    "    # reinstantiate jitcdde objects\n",
    "    import sys\n",
    "    sys.modules.pop('jitcdde')\n",
    "    from jitcdde import jitcdde, y, t\n",
    "\n",
    "    # rho y(22)\n",
    "    a_f_i = factors_f[i]\n",
    "    a_g_i = factors_g[i]\n",
    "    rho = a_f_i*(a_f/2)*(T_cf1 + T_cf2) + a_g_i*(a_g)*(T_cg)\n",
    "\n",
    "    # instantiate jitcdde object\n",
    "    DDE = jitcdde([T_out_rc,T_out_air,T_hf1,T_hf2,T_hf3,T_hf4,T_ht1,T_ht2,T_hc1,\n",
    "                T_hc2,T_hc3,T_hc4,n,C1,C2,C3,C4,C5,C6,T_cg,T_cf1,T_cf2,rho])\n",
    "\n",
    "    # set initial conditions\n",
    "    DDE.constant_past([T0_rp, T0_rs, T0_p1,T0_p2, T0_p3, T0_p4, T0_t1, T0_t2, T0_s1, T0_s2, \n",
    "            T0_s3, T0_s4, n_frac0, C0[0], C0[1], C0[2], C0[3], C0[4], C0[5], \n",
    "            T0_g1, T0_f1, T0_f2,rho_initial])\n",
    "    \n",
    "    sol_i = []\n",
    "    for t_x in T:\n",
    "        sol_i.append(DDE.integrate(t_x))\n",
    "    sols.append(sol_i)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.lines.Line2D at 0xffff3c777e50>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 257940 characters]",
      "text/plain": [
       "<Figure size 1800x1200 with 6 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "ename": "",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31mThe Kernel crashed while executing code in the the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. View Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details."
     ]
    }
   ],
   "source": [
    "fig,axs = plt.subplots(2,3,figsize=(18,12))\n",
    "\n",
    "t_stop = 30\n",
    "vert = 10.555\n",
    "\n",
    "# fuel temps\n",
    "#axs[0,0].set_xlim([0, 500])\n",
    "#axs[0,0].set_ylim([600, 1000])\n",
    "axs[0,0].set_xlim([0,t_stop])\n",
    "axs[0,0].plot(T,[s[20] for s in sols[0]],label=r\"core 1: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\",color='b')\n",
    "axs[0,0].plot(T,[s[20] for s in sols[1]],label=r\"core 1: $(\\alpha_f,\\alpha_g) = $ (-4.36,-3.33) pcm\",color='g')\n",
    "axs[0,0].plot(T,[s[20] for s in sols[2]],label=r\"core 1: $(\\alpha_f,\\alpha_g) = $ (-2.18,-1.67) pcm\",color='r')\n",
    "axs[0,0].plot(T,[s[20] for s in sols[3]],label=r\"core 1: $(\\alpha_f,\\alpha_g) = $ (-1.09,-0.83) pcm\",color='y')\n",
    "axs[0,0].plot(T,[s[20] for s in sols[4]],label=r\"core 1: $(\\alpha_f,\\alpha_g) = $ (-0.00,-0.00) pcm\",color='m')\n",
    "axs[0,0].legend()\n",
    "axs[0,0].set_title(\"Fuel Node Temperatures (C)\")\n",
    "axs[0,0].tick_params(\n",
    "    axis='x',          # changes apply to the x-axis\n",
    "    which='both',      # both major and minor ticks are affected\n",
    "    bottom=False,      # ticks along the bottom edge are off\n",
    "    top=False,         # ticks along the top edge are off\n",
    "    labelbottom=False) # labels along the bottom edge are off\n",
    "\n",
    "# coolant temps\n",
    "#axs[0,1].set_xlim([0, 1000])\n",
    "#axs[0,1].set_ylim([500, 1000])\n",
    "axs[0,1].set_xlim([0,t_stop])\n",
    "axs[0,1].plot(T,[s[8] for s in sols[0]],label=r\"hx 1: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\",color='b')\n",
    "axs[0,1].plot(T,[s[8] for s in sols[1]],label=r\"hx 1: $(\\alpha_f,\\alpha_g) = $ (-4.36,-3.33) pcm\",color='g')\n",
    "axs[0,1].plot(T,[s[8] for s in sols[2]],label=r\"hx 1: $(\\alpha_f,\\alpha_g) = $ (-2.18,-1.67) pcm\",color='r')\n",
    "axs[0,1].plot(T,[s[8] for s in sols[3]],label=r\"hx 1: $(\\alpha_f,\\alpha_g) = $ (-1.09,-0.83) pcm\",color='y')\n",
    "axs[0,1].plot(T,[s[8] for s in sols[4]],label=r\"hx 1: $(\\alpha_f,\\alpha_g) = $ (-0.00,-0.00) pcm\",color='m')\n",
    "axs[0,1].legend()\n",
    "axs[0,1].set_title(\"Coolant Node Temperatures (C)\")\n",
    "axs[0,1].tick_params(\n",
    "    axis='x',          # changes apply to the x-axis\n",
    "    which='both',      # both major and minor ticks are affected\n",
    "    bottom=False,      # ticks along the bottom edge are off\n",
    "    top=False,         # ticks along the top edge are off\n",
    "    labelbottom=False) # labels along the bottom edge are off\n",
    "\n",
    "# tube node temps\n",
    "#axs[0,2].set_xlim([0, 500])\n",
    "#axs[0,2].set_ylim([500, 1000])\n",
    "axs[0,2].set_xlim([0,t_stop])\n",
    "axs[0,2].plot(T,[s[8] for s in sols[0]],label=r\"t1: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\",color='b')\n",
    "axs[0,2].plot(T,[s[8] for s in sols[1]],label=r\"t1: $(\\alpha_f,\\alpha_g) = $ (-4.36,-3.33) pcm\",color='g')\n",
    "axs[0,2].plot(T,[s[8] for s in sols[2]],label=r\"t1: $(\\alpha_f,\\alpha_g) = $ (-2.18,-1.67) pcm\",color='r')\n",
    "axs[0,2].plot(T,[s[8] for s in sols[3]],label=r\"t1: $(\\alpha_f,\\alpha_g) = $ (-1.09,-0.83) pcm\",color='y')\n",
    "axs[0,2].plot(T,[s[8] for s in sols[4]],label=r\"t1: $(\\alpha_f,\\alpha_g) = $ (-0.00,-0.00) pcm\",color='m')\n",
    "\n",
    "# tube node temps\n",
    "axs[0,2].plot(T,[s[9] for s in sols[0]],label=r\"t2: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\",color='b')\n",
    "axs[0,2].plot(T,[s[9] for s in sols[1]],label=r\"t2: $(\\alpha_f,\\alpha_g) = $ (-4.36,-3.33) pcm\",color='g')\n",
    "axs[0,2].plot(T,[s[9] for s in sols[2]],label=r\"t2: $(\\alpha_f,\\alpha_g) = $ (-2.18,-1.67) pcm\",color='r')\n",
    "axs[0,2].plot(T,[s[9] for s in sols[3]],label=r\"t2: $(\\alpha_f,\\alpha_g) = $ (-1.09,-0.83) pcm\",color='y')\n",
    "axs[0,2].plot(T,[s[9] for s in sols[4]],label=r\"t2: $(\\alpha_f,\\alpha_g) = $ (-0.00,-0.00) pcm\",color='m')\n",
    "\n",
    "axs[0,2].legend()\n",
    "axs[0,2].set_title(\"Tube Node Temperatures (C)\")\n",
    "axs[0,2].tick_params(\n",
    "    axis='x',          # changes apply to the x-axis\n",
    "    which='both',      # both major and minor ticks are affected\n",
    "    bottom=False,      # ticks along the bottom edge are off\n",
    "    top=False,         # ticks along the top edge are off\n",
    "    labelbottom=False) # labels along the bottom edge are off\n",
    "\n",
    "# precursor concentrations\n",
    "#axs[1,2].set_xlim([0, 500])\n",
    "#axs[1,2].set_ylim([1e1,1e3])\n",
    "axs[1,2].set_xlim([0,t_stop])\n",
    "axs[1,2].plot(T,[s[13] for s in sols[0]],label=r\"C1: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\",color='b')\n",
    "axs[1,2].plot(T,[s[13] for s in sols[1]],label=r\"C1: $(\\alpha_f,\\alpha_g) = $ (-4.36,-3.33) pcm\",color='g')\n",
    "axs[1,2].plot(T,[s[13] for s in sols[2]],label=r\"C1: $(\\alpha_f,\\alpha_g) = $ (-2.18,-1.67) pcm\",color='r')\n",
    "axs[1,2].plot(T,[s[13] for s in sols[3]],label=r\"C1: $(\\alpha_f,\\alpha_g) = $ (-1.09,-0.83) pcm\",color='y')\n",
    "axs[1,2].plot(T,[s[13] for s in sols[4]],label=r\"C1: $(\\alpha_f,\\alpha_g) = $ (-0.00,-0.00) pcm\",color='m')\n",
    "axs[1,2].legend()\n",
    "axs[1,2].set_xlabel(\"t (s)\")\n",
    "axs[1,2].set_yscale(\"log\")\n",
    "axs[1,2].legend(loc=\"right\")\n",
    "axs[1,2].set_title(\"Precursor Concentrations\")\n",
    "axs[1,2].set_ylabel(r\"concentration (1/cm$^3$)\")\n",
    "\n",
    "# multiplication factor \n",
    "#axs[1,0].set_ylim([0,20])\n",
    "#axs[1,0].set_xlim([0,500])\n",
    "axs[1,0].set_xlim([0,t_stop])\n",
    "axs[1,0].plot(T,[s[12] for s in sols[0]],label=r\"n: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\",color='b')\n",
    "axs[1,0].plot(T,[s[12] for s in sols[1]],label=r\"n: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\",color='g')\n",
    "axs[1,0].plot(T,[s[12] for s in sols[2]],label=r\"n: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\",color='r')\n",
    "axs[1,0].plot(T,[s[12] for s in sols[3]],label=r\"n: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\",color='y')\n",
    "axs[1,0].plot(T,[s[12] for s in sols[4]],label=r\"n: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\",color='m')\n",
    "axs[1,0].set_xlabel(\"t (s)\")\n",
    "axs[1,0].set_title(r\"$n$\")\n",
    "axs[1,0].set_ylabel(r\"$\\frac{n}{n_0}$\")\n",
    "axs[1,0].legend()\n",
    "\n",
    "# reactivity\n",
    "#axs[1,0].set_ylim([0,0])\n",
    "#axs[1,0].set_xlim([0,500])\n",
    "axs[1,1].set_xlim([0,t_stop])\n",
    "axs[1,1].plot(T,[s[22] for s in sols[0]],label=r\"$\\rho$: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\",color='b')\n",
    "axs[1,1].plot(T,[s[22] for s in sols[1]],label=r\"$\\rho$: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\",color='g')\n",
    "axs[1,1].plot(T,[s[22] for s in sols[2]],label=r\"$\\rho$: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\",color='r')\n",
    "axs[1,1].plot(T,[s[22] for s in sols[3]],label=r\"$\\rho$: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\",color='y')\n",
    "axs[1,1].plot(T,[s[22] for s in sols[4]],label=r\"$\\rho$: $(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\",color='m')\n",
    "axs[1,1].set_xlabel(\"t (s)\")\n",
    "axs[1,1].set_title(r\"$\\rho$\")\n",
    "axs[1,1].legend()\n",
    "\n",
    "#plt.figure(figsize=(8,6))\n",
    "#plt.plot(T,[s[12] for s in sols[0]],label=r\"$(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\")\n",
    "#plt.plot(T,[s[12] for s in sols[1]],label=r\"$(\\alpha_f,\\alpha_g) = $ (-4.36,-3.33) pcm\")\n",
    "#plt.plot(T,[s[12] for s in sols[2]],label=r\"$(\\alpha_f,\\alpha_g) = $ (-2.18,-1.67) pcm\")\n",
    "#plt.plot(T,[s[12] for s in sols[3]],label=r\"$(\\alpha_f,\\alpha_g) = $ (-1.09,-0.83) pcm\")\n",
    "#plt.plot(T,[s[12] for s in sols[4]],label=r\"$(\\alpha_f,\\alpha_g) = $ (0.0,0.0) pcm\")\n",
    "#plt.xlabel(\"t (s)\")\n",
    "#plt.ylabel(r\"$n/n_0$\",rotation=0)\n",
    "#plt.legend()\n",
    "#plt.ylim([0,20])\n",
    "#plt.xlim([0,500])\n",
    "#plt.title(r\"Reactor Response vs $\\alpha$\")\n",
    "\n",
    "\n",
    "#######################################################################################################\n",
    "\n",
    "# adjusted delay term \n",
    "\n",
    "# fuel temps\n",
    "#axs[0,0].set_xlim([0, 500])\n",
    "#axs[0,0].set_ylim([600, 1000])\n",
    "axs[0,0].set_xlim([0,t_stop])\n",
    "axs[0,0].plot(T,[s[20] for s in sols[5]],linestyle='-.',color='b')\n",
    "axs[0,0].plot(T,[s[20] for s in sols[6]],linestyle='-.',color='g')\n",
    "axs[0,0].plot(T,[s[20] for s in sols[7]],linestyle='-.',color='r')\n",
    "axs[0,0].plot(T,[s[20] for s in sols[8]],linestyle='-.',color='y')\n",
    "axs[0,0].plot(T,[s[20] for s in sols[9]],linestyle='-.',color='m')\n",
    "axs[0,0].legend()\n",
    "axs[0,0].set_title(\"Fuel Node Temperatures (C)\")\n",
    "axs[0,0].tick_params(\n",
    "    axis='x',          # changes apply to the x-axis\n",
    "    which='both',      # both major and minor ticks are affected\n",
    "    bottom=False,      # ticks along the bottom edge are off\n",
    "    top=False,         # ticks along the top edge are off\n",
    "    labelbottom=False) # labels along the bottom edge are off\n",
    "axs[0,0].axvline(x=vert, color='black', linestyle=':')\n",
    "# coolant temps\n",
    "#axs[0,1].set_xlim([0, 1000])\n",
    "#axs[0,1].set_ylim([500, 1000])\n",
    "axs[0,1].set_xlim([0,t_stop])\n",
    "axs[0,1].plot(T,[s[8] for s in sols[5]],linestyle='-.',color='b')\n",
    "axs[0,1].plot(T,[s[8] for s in sols[6]],linestyle='-.',color='g')\n",
    "axs[0,1].plot(T,[s[8] for s in sols[7]],linestyle='-.',color='r')\n",
    "axs[0,1].plot(T,[s[8] for s in sols[8]],linestyle='-.',color='y')\n",
    "axs[0,1].plot(T,[s[8] for s in sols[9]],linestyle='-.',color='m')\n",
    "axs[0,1].legend()\n",
    "axs[0,1].set_title(\"Coolant Node Temperatures (C)\")\n",
    "axs[0,1].tick_params(\n",
    "    axis='x',          # changes apply to the x-axis\n",
    "    which='both',      # both major and minor ticks are affected\n",
    "    bottom=False,      # ticks along the bottom edge are off\n",
    "    top=False,         # ticks along the top edge are off\n",
    "    labelbottom=False) # labels along the bottom edge are off\n",
    "\n",
    "# tube node temps\n",
    "#axs[0,2].set_xlim([0, 500])\n",
    "#axs[0,2].set_ylim([500, 1000])\n",
    "axs[0,2].set_xlim([0,t_stop])\n",
    "axs[0,2].plot(T,[s[8] for s in sols[5]],linestyle='-.',color='b')\n",
    "axs[0,2].plot(T,[s[8] for s in sols[6]],linestyle='-.',color='g')\n",
    "axs[0,2].plot(T,[s[8] for s in sols[7]],linestyle='-.',color='r')\n",
    "axs[0,2].plot(T,[s[8] for s in sols[8]],linestyle='-.',color='y')\n",
    "axs[0,2].plot(T,[s[8] for s in sols[9]],linestyle='-.',color='m')\n",
    "\n",
    "# tube node temps\n",
    "axs[0,2].plot(T,[s[9] for s in sols[5]],linestyle='-.',color='b')\n",
    "axs[0,2].plot(T,[s[9] for s in sols[6]],linestyle='-.',color='g')\n",
    "axs[0,2].plot(T,[s[9] for s in sols[7]],linestyle='-.',color='r')\n",
    "axs[0,2].plot(T,[s[9] for s in sols[8]],linestyle='-.',color='y')\n",
    "axs[0,2].plot(T,[s[9] for s in sols[9]],linestyle='-.',color='m')\n",
    "\n",
    "axs[0,2].legend()\n",
    "axs[0,2].set_title(\"Tube Node Temperatures (C)\")\n",
    "axs[0,2].tick_params(\n",
    "    axis='x',          # changes apply to the x-axis\n",
    "    which='both',      # both major and minor ticks are affected\n",
    "    bottom=False,      # ticks along the bottom edge are off\n",
    "    top=False,         # ticks along the top edge are off\n",
    "    labelbottom=False) # labels along the bottom edge are off\n",
    "\n",
    "# precursor concentrations\n",
    "#axs[1,2].set_xlim([0, 500])\n",
    "#axs[1,2].set_ylim([1e1,1e3])\n",
    "axs[1,2].set_xlim([0,t_stop])\n",
    "axs[1,2].plot(T,[s[13] for s in sols[5]],linestyle='-.',color='b')\n",
    "axs[1,2].plot(T,[s[13] for s in sols[6]],linestyle='-.',color='g')\n",
    "axs[1,2].plot(T,[s[13] for s in sols[7]],linestyle='-.',color='r')\n",
    "axs[1,2].plot(T,[s[13] for s in sols[8]],linestyle='-.',color='y')\n",
    "axs[1,2].plot(T,[s[13] for s in sols[9]],linestyle='-.',color='m')\n",
    "axs[1,2].legend()\n",
    "axs[1,2].set_xlabel(\"t (s)\")\n",
    "axs[1,2].set_yscale(\"log\")\n",
    "axs[1,2].legend(loc=\"right\")\n",
    "axs[1,2].set_title(\"Precursor Concentrations\")\n",
    "axs[1,2].set_ylabel(r\"concentration (1/cm$^3$)\")\n",
    "\n",
    "# multiplication factor \n",
    "#axs[1,0].set_ylim([0,20])\n",
    "#axs[1,0].set_xlim([0,500])\n",
    "axs[1,0].set_xlim([0,t_stop])\n",
    "axs[1,0].plot(T,[s[12] for s in sols[5]],linestyle='-.',color='b')\n",
    "axs[1,0].plot(T,[s[12] for s in sols[6]],linestyle='-.',color='g')\n",
    "axs[1,0].plot(T,[s[12] for s in sols[7]],linestyle='-.',color='r')\n",
    "axs[1,0].plot(T,[s[12] for s in sols[8]],linestyle='-.',color='y')\n",
    "axs[1,0].plot(T,[s[12] for s in sols[9]],linestyle='-.',color='m')\n",
    "axs[1,0].set_xlabel(\"t (s)\")\n",
    "axs[1,0].set_title(r\"$n$\")\n",
    "axs[1,0].set_ylabel(r\"$\\frac{n}{n_0}$\")\n",
    "axs[1,0].axvline(x=vert, color='black', linestyle=':')\n",
    "\n",
    "# reactivity\n",
    "#axs[1,0].set_ylim([0,0])\n",
    "#axs[1,0].set_xlim([0,500])\n",
    "axs[1,1].set_xlim([0,t_stop])\n",
    "axs[1,1].plot(T,[s[22] for s in sols[5]],linestyle='-.',color='b')\n",
    "axs[1,1].plot(T,[s[22] for s in sols[6]],linestyle='-.',color='g')\n",
    "axs[1,1].plot(T,[s[22] for s in sols[7]],linestyle='-.',color='r')\n",
    "axs[1,1].plot(T,[s[22] for s in sols[8]],linestyle='-.',color='y')\n",
    "axs[1,1].plot(T,[s[22] for s in sols[9]],linestyle='-.',color='m')\n",
    "axs[1,1].set_xlabel(\"t (s)\")\n",
    "axs[1,1].set_title(r\"$\\rho$\")\n",
    "axs[1,1].axvline(x=vert, color='black', linestyle=':')\n",
    "\n",
    "#plt.figure(figsize=(8,6))\n",
    "#plt.plot(T,[s[12] for s in sols[0]],label=r\"$(\\alpha_f,\\alpha_g) = $ (-8.71,-6.66) pcm\")\n",
    "#plt.plot(T,[s[12] for s in sols[1]],label=r\"$(\\alpha_f,\\alpha_g) = $ (-4.36,-3.33) pcm\")\n",
    "#plt.plot(T,[s[12] for s in sols[2]],label=r\"$(\\alpha_f,\\alpha_g) = $ (-2.18,-1.67) pcm\")\n",
    "#plt.plot(T,[s[12] for s in sols[3]],label=r\"$(\\alpha_f,\\alpha_g) = $ (-1.09,-0.83) pcm\")\n",
    "#plt.plot(T,[s[12] for s in sols[4]],label=r\"$(\\alpha_f,\\alpha_g) = $ (0.0,0.0) pcm\")\n",
    "#plt.xlabel(\"t (s)\")\n",
    "#plt.ylabel(r\"$n/n_0$\",rotation=0)\n",
    "#plt.legend()\n",
    "#plt.ylim([0,20])\n",
    "#plt.xlim([0,500])\n",
    "#plt.title(r\"Reactor Response vs $\\alpha$\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(sols)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "thesis_env",
   "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.9.2"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
