{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Pincell Depletion\n",
    "This notebook is intended to introduce the reader to the depletion interface contained in OpenMC. It is recommended that you are moderately familiar with building models using the OpenMC Python API. The earlier examples are excellent starting points, as this notebook will not focus heavily on model building.\n",
    "\n",
    "If you have a real power reactor, the fuel composition is constantly changing as fission events produce energy, remove some fissile isotopes, and produce fission products. Other reactions, like $(n, \\alpha)$ and $(n, \\gamma)$ will alter the composition as well. Furthermore, some nuclides undergo spontaneous decay with widely ranging frequencies. Depletion is the process of modeling this behavior.\n",
    "\n",
    "In this notebook, we will model a simple fuel pin in an infinite lattice using the Python API. We will then build and examine some of the necessary components for performing depletion analysis. Then, we will use the depletion interface in OpenMC to simulate the fuel pin producing power over several months. Lastly, we will wrap up with some helpful tips to improve the fidelity of depletion simulations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import math\n",
    "import openmc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Build the Geometry\n",
    "\n",
    "Much of this section is borrowed from the \"Modeling a Pin-Cell\" example. If you find yourself not understanding some aspects of this section, feel free to refer to that example, as some details may be glossed over for brevity.\n",
    "\n",
    "First, we will create our fuel, cladding, and water materials to represent a typical PWR."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "fuel = openmc.Material(name=\"uo2\")\n",
    "fuel.add_element(\"U\", 1, percent_type=\"ao\", enrichment=4.25)\n",
    "fuel.add_element(\"O\", 2)\n",
    "fuel.set_density(\"g/cc\", 10.4)\n",
    "\n",
    "clad = openmc.Material(name=\"clad\")\n",
    "clad.add_element(\"Zr\", 1)\n",
    "clad.set_density(\"g/cc\", 6)\n",
    "\n",
    "water = openmc.Material(name=\"water\")\n",
    "water.add_element(\"O\", 1)\n",
    "water.add_element(\"H\", 2)\n",
    "water.set_density(\"g/cc\", 1.0)\n",
    "water.add_s_alpha_beta(\"c_H_in_H2O\")\n",
    "materials = openmc.Materials([fuel, clad, water])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here, we are going to use the `openmc.model.pin` function to build our pin cell. The `pin` function anticipates concentric cylinders and materials to fill the inner regions. One additional material is needed than the number of cylinders to cover the domain outside the final ring. \n",
    "\n",
    "To do this, we define two radii for the outer radius of our fuel pin, and the outer radius of the cladding."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "radii = [0.42, 0.45]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using these radii, we define concentric `ZCylinder` objects. So long as the cylinders are concentric and increasing in radius, any orientation can be used. We also take advantage of the fact that the `openmc.Materials` object is a subclass of the `list` object to assign materials to the regions defined by the surfaces."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "pin_surfaces = [openmc.ZCylinder(r=r) for r in radii]\n",
    "pin_univ = openmc.model.pin(pin_surfaces, materials)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The first material, in our case `fuel`, is placed inside the first cylinder in the inner-most region. The second material, `clad`, fills the space between our cylinders, while `water` is placed outside the last ring. The `pin` function returns an `openmc.Universe` object, and has some additional features we will mention later. Finally, we need to place the fuel pin universe in a bounding cell."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "bound_box = openmc.model.RectangularPrism(1.24, 1.24, boundary_type=\"reflective\")\n",
    "root_cell = openmc.Cell(fill=pin_univ, region=bound_box)\n",
    "geometry = openmc.Geometry([root_cell])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To ensure our geometry looks right, let's plot it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f78e7d2a890>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 9964 characters]",
      "text/plain": [
       "<Figure size 258.065x259.74 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "geometry.root_universe.plot()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Lastly we construct our settings. For the sake of time, a relatively low number of particles will be used."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "settings = openmc.Settings()\n",
    "settings.particles = 1000\n",
    "settings.inactive = 10\n",
    "settings.batches = 50"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The depletion interface relies on `OpenMC` to perform the transport simulation and obtain reaction rates and other important information. Normally, we would need to export XML files before running OpenMC, but the depletion interface takes care of this for us."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "However, we must first add one bit of information: the volume of our fuel. In order to translate the reaction rates obtained by `openmc` to meaningful units for depletion, we have to normalize them to a correct power. This requires us to know, or be able to calculate, how much fuel is in our problem. Correctly setting the volumes is a critical step, and can lead to incorrect answers, as the fuel is over- or under-depleted due to poor normalization.\n",
    "\n",
    "For our problem, we can assign the \"volume\" to be the cross-sectional area of our fuel. This is identical to modeling our fuel pin inside a box with height of 1 cm."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "fuel.volume = math.pi * radii[0] ** 2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Setting up for depletion\n",
    "\n",
    "The OpenMC depletion interface can be accessed from the `openmc.deplete` module, and has a variety of classes that will help us."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "import openmc.deplete"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In order to run the depletion calculation we need the following information:\n",
    "\n",
    "1. Nuclide decay, fission yield, and reaction data\n",
    "2. Operational power or power density\n",
    "3. Desired depletion schedule\n",
    "4. Desired time integration scheme\n",
    "\n",
    "The first item is necessary to determine the paths by which nuclides transmute over the depletion simulation. This includes spontaneous decay, fission product yield distributions, and nuclides produced through neutron-reactions. For example,\n",
    "* Te129 decays to I129 with a half life of ~70 minutes\n",
    "* A fission event for U-235 produces fission products like Xe135 according to a distribution\n",
    "* For thermal problems, Am241 will produce metastable Am242 about 8% of the time during an $(n,\\gamma)$ reaction. The other 92% of capture reactions will produce ground state Am242\n",
    "\n",
    "These data are often distributed with other nuclear data, like incident neutron cross sections with ENDF/B-VII.\n",
    "OpenMC uses the [`openmc.deplete.Chain`](https://docs.openmc.org/en/latest/pythonapi/generated/openmc.deplete.Chain.html#openmc.deplete.Chain) to collect represent the various decay and transmutation pathways in a single object.\n",
    "While a complete `Chain` can be created using nuclear data files, users may prefer to download pre-generated XML-representations instead.\n",
    "Such files can be found at https://openmc.org/depletion-chains/ and include full and compressed chains, with capture branching ratios derived using PWR- or SFR-spectra.\n",
    "\n",
    "For this problem, we will be using a much smaller depletion chain that contains very few nuclides. In a realistic problem, over 1000 isotopes may be included in the depletion chain."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "OrderedDict([('I135', 0),\n",
       "             ('Xe135', 1),\n",
       "             ('Xe136', 2),\n",
       "             ('Cs135', 3),\n",
       "             ('Gd157', 4),\n",
       "             ('Gd156', 5),\n",
       "             ('U234', 6),\n",
       "             ('U235', 7),\n",
       "             ('U238', 8)])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chain = openmc.deplete.Chain.from_xml(\"./chain_simple.xml\")\n",
    "chain.nuclide_dict"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The primary entry point for depletion is the `openmc.deplete.Operator`. It relies on the `openmc.deplete.Chain` and helper classes to run `openmc`, retrieve and normalize reaction rates, and other perform other tasks. For a thorough description, please see the full API documentation."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We will create our Operator using the geometry and settings from above, and our simple chain file. The materials are read in automatically using the `materials.xml` file."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "model = openmc.Model(geometry=geometry, settings=settings)\n",
    "operator = openmc.deplete.CoupledOperator(model, \"./chain_simple.xml\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We will then simulate our fuel pin operating at linear power of 174 W/cm, or 174 W given a unit height for our problem."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "power = 174"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For this problem, we will take depletion step sizes of 30 days, and instruct OpenMC to re-run a transport simulation every 30 days until we have modeled the problem over a six month cycle. The depletion interface expects the time to be given in seconds, so we will have to convert. Note that these values are not cumulative."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "time_steps = [30] * 6"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And lastly, we will use the basic predictor, or forward Euler, time integration scheme. Other, more advanced methods are provided to the user through `openmc.deplete`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "integrator = openmc.deplete.PredictorIntegrator(operator, time_steps, power, timestep_units='d')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To perform the simulation, we use the `integrate` method, and let `openmc` take care of the rest."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                                %%%%%%%%%%%%%%%\n",
      "                           %%%%%%%%%%%%%%%%%%%%%%%%\n",
      "                        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n",
      "                      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n",
      "                    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n",
      "                   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n",
      "                                    %%%%%%%%%%%%%%%%%%%%%%%%\n",
      "                                     %%%%%%%%%%%%%%%%%%%%%%%%\n",
      "                 ###############      %%%%%%%%%%%%%%%%%%%%%%%%\n",
      "                ##################     %%%%%%%%%%%%%%%%%%%%%%%\n",
      "                ###################     %%%%%%%%%%%%%%%%%%%%%%%\n",
      "                ####################     %%%%%%%%%%%%%%%%%%%%%%\n",
      "                #####################     %%%%%%%%%%%%%%%%%%%%%\n",
      "                ######################     %%%%%%%%%%%%%%%%%%%%\n",
      "                #######################     %%%%%%%%%%%%%%%%%%\n",
      "                 #######################     %%%%%%%%%%%%%%%%%\n",
      "                 ######################     %%%%%%%%%%%%%%%%%\n",
      "                  ####################     %%%%%%%%%%%%%%%%%\n",
      "                    #################     %%%%%%%%%%%%%%%%%\n",
      "                     ###############     %%%%%%%%%%%%%%%%\n",
      "                       ############     %%%%%%%%%%%%%%%\n",
      "                          ########     %%%%%%%%%%%%%%\n",
      "                                      %%%%%%%%%%%\n",
      "\n",
      "                 | The OpenMC Monte Carlo Code\n",
      "       Copyright | 2011-2023 MIT, UChicago Argonne LLC, and contributors\n",
      "         License | https://docs.openmc.org/en/latest/license.html\n",
      "         Version | 0.13.3\n",
      "        Git SHA1 | 50e39a4e20dc9e0f3d7ccf07333f6a5e6c797c8c\n",
      "       Date/Time | 2023-10-26 01:26:50\n",
      "  OpenMP Threads | 32\n",
      "\n",
      " Reading settings XML file...\n",
      " Reading cross sections XML file...\n",
      " Reading materials XML file...\n",
      " Reading geometry XML file...\n",
      " Reading U234 from /opt/xdata/endfb-vii.1-hdf5/neutron/U234.h5\n",
      " Reading U235 from /opt/xdata/endfb-vii.1-hdf5/neutron/U235.h5\n",
      " Reading U238 from /opt/xdata/endfb-vii.1-hdf5/neutron/U238.h5\n",
      " Reading O16 from /opt/xdata/endfb-vii.1-hdf5/neutron/O16.h5\n",
      " Reading O17 from /opt/xdata/endfb-vii.1-hdf5/neutron/O17.h5\n",
      " Reading U236 from /opt/xdata/endfb-vii.1-hdf5/neutron/U236.h5\n",
      " Reading Zr90 from /opt/xdata/endfb-vii.1-hdf5/neutron/Zr90.h5\n",
      " Reading Zr91 from /opt/xdata/endfb-vii.1-hdf5/neutron/Zr91.h5\n",
      " Reading Zr92 from /opt/xdata/endfb-vii.1-hdf5/neutron/Zr92.h5\n",
      " Reading Zr94 from /opt/xdata/endfb-vii.1-hdf5/neutron/Zr94.h5\n",
      " Reading Zr96 from /opt/xdata/endfb-vii.1-hdf5/neutron/Zr96.h5\n",
      " Reading H1 from /opt/xdata/endfb-vii.1-hdf5/neutron/H1.h5\n",
      " Reading H2 from /opt/xdata/endfb-vii.1-hdf5/neutron/H2.h5\n",
      " Reading c_H_in_H2O from /opt/xdata/endfb-vii.1-hdf5/neutron/c_H_in_H2O.h5\n",
      " Minimum neutron data temperature: 294 K\n",
      " Maximum neutron data temperature: 294 K\n",
      " Preparing distributed cell instances...\n",
      " Reading plot XML file...\n",
      " Writing summary.h5 file...\n",
      "[openmc.deplete] t=0.0 s, dt=2592000 s, source=174\n",
      " Reading I135 from /opt/xdata/endfb-vii.1-hdf5/neutron/I135.h5\n",
      " Reading Xe135 from /opt/xdata/endfb-vii.1-hdf5/neutron/Xe135.h5\n",
      " Reading Xe136 from /opt/xdata/endfb-vii.1-hdf5/neutron/Xe136.h5\n",
      " Reading Cs135 from /opt/xdata/endfb-vii.1-hdf5/neutron/Cs135.h5\n",
      " Reading Gd157 from /opt/xdata/endfb-vii.1-hdf5/neutron/Gd157.h5\n",
      " Reading Gd156 from /opt/xdata/endfb-vii.1-hdf5/neutron/Gd156.h5\n",
      " Maximum neutron transport energy: 20000000 eV for U235\n",
      " Initializing source particles...\n",
      "\n",
      " ====================>     K EIGENVALUE SIMULATION     <====================\n",
      "\n",
      "  Bat./Gen.      k            Average k\n",
      "  =========   ========   ====================\n",
      "        1/1    1.53702\n",
      "        2/1    1.43876\n",
      "        3/1    1.43346\n",
      "        4/1    1.44635\n",
      "        5/1    1.61133\n",
      "        6/1    1.49998\n",
      "        7/1    1.44172\n",
      "        8/1    1.47214\n",
      "        9/1    1.43927\n",
      "       10/1    1.45062\n",
      "       11/1    1.36761\n",
      "       12/1    1.47828    1.42295 +/- 0.05533\n",
      "       13/1    1.49637    1.44742 +/- 0.04024\n",
      "       14/1    1.42753    1.44245 +/- 0.02889\n",
      "       15/1    1.45598    1.44516 +/- 0.02254\n",
      "       16/1    1.45223    1.44634 +/- 0.01844\n",
      "       17/1    1.39662    1.43923 +/- 0.01713\n",
      "       18/1    1.43137    1.43825 +/- 0.01487\n",
      "       19/1    1.45607    1.44023 +/- 0.01326\n",
      "       20/1    1.37620    1.43383 +/- 0.01348\n",
      "       21/1    1.45783    1.43601 +/- 0.01238\n",
      "       22/1    1.50132    1.44145 +/- 0.01255\n",
      "       23/1    1.48660    1.44493 +/- 0.01205\n",
      "       24/1    1.46315    1.44623 +/- 0.01123\n",
      "       25/1    1.38739    1.44231 +/- 0.01117\n",
      "       26/1    1.38844    1.43894 +/- 0.01098\n",
      "       27/1    1.50351    1.44274 +/- 0.01099\n",
      "       28/1    1.44082    1.44263 +/- 0.01036\n",
      "       29/1    1.56234    1.44893 +/- 0.01165\n",
      "       30/1    1.39650    1.44631 +/- 0.01136\n",
      "       31/1    1.40645    1.44441 +/- 0.01097\n",
      "       32/1    1.45086    1.44471 +/- 0.01046\n",
      "       33/1    1.41487    1.44341 +/- 0.01008\n",
      "       34/1    1.41254    1.44212 +/- 0.00974\n",
      "       35/1    1.44422    1.44221 +/- 0.00934\n",
      "       36/1    1.51714    1.44509 +/- 0.00943\n",
      "       37/1    1.38374    1.44282 +/- 0.00935\n",
      "       38/1    1.43018    1.44236 +/- 0.00902\n",
      "       39/1    1.45851    1.44292 +/- 0.00872\n",
      "       40/1    1.54850    1.44644 +/- 0.00913\n",
      "       41/1    1.38747    1.44454 +/- 0.00904\n",
      "       42/1    1.46092    1.44505 +/- 0.00876\n",
      "       43/1    1.48960    1.44640 +/- 0.00860\n",
      "       44/1    1.39648    1.44493 +/- 0.00847\n",
      "       45/1    1.54765    1.44787 +/- 0.00873\n",
      "       46/1    1.42142    1.44713 +/- 0.00852\n",
      "       47/1    1.49596    1.44845 +/- 0.00839\n",
      "       48/1    1.46689    1.44894 +/- 0.00818\n",
      "       49/1    1.43829    1.44866 +/- 0.00797\n",
      "       50/1    1.47259    1.44926 +/- 0.00779\n",
      " Creating state point statepoint.50.h5...\n",
      "\n",
      " =======================>     TIMING STATISTICS     <=======================\n",
      "\n",
      " Total time for initialization     = 9.6620e-01 seconds\n",
      "   Reading cross sections          = 9.5103e-01 seconds\n",
      " Total time in simulation          = 1.9522e+00 seconds\n",
      "   Time in transport only          = 1.9279e+00 seconds\n",
      "   Time in inactive batches        = 3.6865e-01 seconds\n",
      "   Time in active batches          = 1.5836e+00 seconds\n",
      "   Time synchronizing fission bank = 4.2209e-03 seconds\n",
      "     Sampling source sites         = 3.7456e-03 seconds\n",
      "     SEND/RECV source sites        = 4.5376e-04 seconds\n",
      "   Time accumulating tallies       = 9.2936e-03 seconds\n",
      "   Time writing statepoints        = 5.0476e-03 seconds\n",
      " Total time for finalization       = 1.2903e-04 seconds\n",
      " Total time elapsed                = 2.9312e+00 seconds\n",
      " Calculation Rate (inactive)       = 27126.1 particles/second\n",
      " Calculation Rate (active)         = 25259 particles/second\n",
      "\n",
      " ============================>     RESULTS     <============================\n",
      "\n",
      " k-effective (Collision)     = 1.45079 +/- 0.00728\n",
      " k-effective (Track-length)  = 1.44926 +/- 0.00779\n",
      " k-effective (Absorption)    = 1.45541 +/- 0.00477\n",
      " Combined k-effective        = 1.45490 +/- 0.00474\n",
      " Leakage Fraction            = 0.00000 +/- 0.00000\n",
      "\n",
      " Creating state point openmc_simulation_n0.h5...\n",
      "[openmc.deplete] t=2592000.0 s, dt=2592000 s, source=174\n",
      " Maximum neutron transport energy: 20000000 eV for U235\n",
      " Initializing source particles...\n",
      "\n",
      " ====================>     K EIGENVALUE SIMULATION     <====================\n",
      "\n",
      "  Bat./Gen.      k            Average k\n",
      "  =========   ========   ====================\n",
      "        1/1    1.38610\n",
      "        2/1    1.48168\n",
      "        3/1    1.50267\n",
      "        4/1    1.47834\n",
      "        5/1    1.45348\n",
      "        6/1    1.38505\n",
      "        7/1    1.36547\n",
      "        8/1    1.42814\n",
      "        9/1    1.44743\n",
      "       10/1    1.43416\n",
      "       11/1    1.45512\n",
      "       12/1    1.34085    1.39798 +/- 0.05714\n",
      "       13/1    1.43011    1.40869 +/- 0.03468\n",
      "       14/1    1.47060    1.42417 +/- 0.02900\n",
      "       15/1    1.43763    1.42686 +/- 0.02262\n",
      "       16/1    1.39925    1.42226 +/- 0.01904\n",
      "       17/1    1.50656    1.43430 +/- 0.02010\n",
      "       18/1    1.42710    1.43340 +/- 0.01743\n",
      "       19/1    1.44105    1.43425 +/- 0.01539\n",
      "       20/1    1.31871    1.42270 +/- 0.01797\n",
      "       21/1    1.44718    1.42492 +/- 0.01641\n",
      "       22/1    1.42535    1.42496 +/- 0.01498\n",
      "       23/1    1.56508    1.43574 +/- 0.01749\n",
      "       24/1    1.43354    1.43558 +/- 0.01620\n",
      "       25/1    1.38408    1.43215 +/- 0.01547\n",
      "       26/1    1.47748    1.43498 +/- 0.01474\n",
      "       27/1    1.51403    1.43963 +/- 0.01461\n",
      "       28/1    1.41745    1.43840 +/- 0.01383\n",
      "       29/1    1.43331    1.43813 +/- 0.01308\n",
      "       30/1    1.39084    1.43577 +/- 0.01263\n",
      "       31/1    1.47378    1.43758 +/- 0.01215\n",
      "       32/1    1.42902    1.43719 +/- 0.01159\n",
      "       33/1    1.43219    1.43697 +/- 0.01108\n",
      "       34/1    1.46083    1.43796 +/- 0.01065\n",
      "       35/1    1.49512    1.44025 +/- 0.01047\n",
      "       36/1    1.41634    1.43933 +/- 0.01010\n",
      "       37/1    1.36758    1.43667 +/- 0.01008\n",
      "       38/1    1.47189    1.43793 +/- 0.00979\n",
      "       39/1    1.41503    1.43714 +/- 0.00948\n",
      "       40/1    1.41165    1.43629 +/- 0.00920\n",
      "       41/1    1.40983    1.43544 +/- 0.00894\n",
      "       42/1    1.40339    1.43444 +/- 0.00871\n",
      "       43/1    1.38040    1.43280 +/- 0.00860\n",
      "       44/1    1.44208    1.43307 +/- 0.00835\n",
      "       45/1    1.48910    1.43467 +/- 0.00826\n",
      "       46/1    1.36484    1.43273 +/- 0.00826\n",
      "       47/1    1.44490    1.43306 +/- 0.00804\n",
      "       48/1    1.45630    1.43367 +/- 0.00785\n",
      "       49/1    1.43474    1.43370 +/- 0.00765\n",
      "       50/1    1.46575    1.43450 +/- 0.00750\n",
      " Creating state point statepoint.50.h5...\n",
      "\n",
      " =======================>     TIMING STATISTICS     <=======================\n",
      "\n",
      " Total time for initialization     = 0.0000e+00 seconds\n",
      "   Reading cross sections          = 0.0000e+00 seconds\n",
      " Total time in simulation          = 2.1220e+00 seconds\n",
      "   Time in transport only          = 2.0960e+00 seconds\n",
      "   Time in inactive batches        = 4.0429e-01 seconds\n",
      "   Time in active batches          = 1.7177e+00 seconds\n",
      "   Time synchronizing fission bank = 4.2377e-03 seconds\n",
      "     Sampling source sites         = 3.7539e-03 seconds\n",
      "     SEND/RECV source sites        = 4.6137e-04 seconds\n",
      "   Time accumulating tallies       = 7.6969e-03 seconds\n",
      "   Time writing statepoints        = 1.1371e-02 seconds\n",
      " Total time for finalization       = 1.3024e-04 seconds\n",
      " Total time elapsed                = 2.1331e+00 seconds\n",
      " Calculation Rate (inactive)       = 24734.9 particles/second\n",
      " Calculation Rate (active)         = 23286.3 particles/second\n",
      "\n",
      " ============================>     RESULTS     <============================\n",
      "\n",
      " k-effective (Collision)     = 1.42726 +/- 0.00588\n",
      " k-effective (Track-length)  = 1.43450 +/- 0.00750\n",
      " k-effective (Absorption)    = 1.44447 +/- 0.00447\n",
      " Combined k-effective        = 1.43943 +/- 0.00475\n",
      " Leakage Fraction            = 0.00000 +/- 0.00000\n",
      "\n",
      " Creating state point openmc_simulation_n1.h5...\n",
      "[openmc.deplete] t=5184000.0 s, dt=2592000 s, source=174\n",
      " Maximum neutron transport energy: 20000000 eV for U235\n",
      " Initializing source particles...\n",
      "\n",
      " ====================>     K EIGENVALUE SIMULATION     <====================\n",
      "\n",
      "  Bat./Gen.      k            Average k\n",
      "  =========   ========   ====================\n",
      "        1/1    1.50898\n",
      "        2/1    1.55378\n",
      "        3/1    1.48344\n",
      "        4/1    1.41734\n",
      "        5/1    1.45680\n",
      "        6/1    1.42132\n",
      "        7/1    1.45812\n",
      "        8/1    1.62452\n",
      "        9/1    1.45545\n",
      "       10/1    1.47973\n",
      "       11/1    1.45058\n",
      "       12/1    1.38818    1.41938 +/- 0.03120\n",
      "       13/1    1.42619    1.42165 +/- 0.01816\n",
      "       14/1    1.41350    1.41961 +/- 0.01300\n",
      "       15/1    1.52301    1.44029 +/- 0.02300\n",
      "       16/1    1.45366    1.44252 +/- 0.01891\n",
      "       17/1    1.46955    1.44638 +/- 0.01644\n",
      "       18/1    1.44131    1.44575 +/- 0.01425\n",
      "       19/1    1.48535    1.45015 +/- 0.01332\n",
      "       20/1    1.40243    1.44538 +/- 0.01283\n",
      "       21/1    1.43354    1.44430 +/- 0.01166\n",
      "       22/1    1.42089    1.44235 +/- 0.01082\n",
      "       23/1    1.48037    1.44527 +/- 0.01037\n",
      "       24/1    1.38331    1.44085 +/- 0.01057\n",
      "       25/1    1.43077    1.44018 +/- 0.00987\n",
      "       26/1    1.42727    1.43937 +/- 0.00927\n",
      "       27/1    1.47006    1.44117 +/- 0.00889\n",
      "       28/1    1.43249    1.44069 +/- 0.00839\n",
      "       29/1    1.40403    1.43876 +/- 0.00817\n",
      "       30/1    1.41033    1.43734 +/- 0.00788\n",
      "       31/1    1.48052    1.43940 +/- 0.00777\n",
      "       32/1    1.48062    1.44127 +/- 0.00764\n",
      "       33/1    1.47116    1.44257 +/- 0.00742\n",
      "       34/1    1.39372    1.44054 +/- 0.00739\n",
      "       35/1    1.44398    1.44067 +/- 0.00709\n",
      "       36/1    1.49633    1.44281 +/- 0.00714\n",
      "       37/1    1.49206    1.44464 +/- 0.00711\n",
      "       38/1    1.42788    1.44404 +/- 0.00688\n",
      "       39/1    1.41317    1.44297 +/- 0.00672\n",
      "       40/1    1.46586    1.44374 +/- 0.00654\n",
      "       41/1    1.37584    1.44155 +/- 0.00669\n",
      "       42/1    1.42766    1.44111 +/- 0.00649\n",
      "       43/1    1.43667    1.44098 +/- 0.00629\n",
      "       44/1    1.46639    1.44173 +/- 0.00615\n",
      "       45/1    1.38801    1.44019 +/- 0.00617\n",
      "       46/1    1.42058    1.43965 +/- 0.00602\n",
      "       47/1    1.39808    1.43852 +/- 0.00596\n",
      "       48/1    1.40581    1.43766 +/- 0.00586\n",
      "       49/1    1.42390    1.43731 +/- 0.00572\n",
      "       50/1    1.34860    1.43509 +/- 0.00600\n",
      " Creating state point statepoint.50.h5...\n",
      "\n",
      " =======================>     TIMING STATISTICS     <=======================\n",
      "\n",
      " Total time for initialization     = 0.0000e+00 seconds\n",
      "   Reading cross sections          = 0.0000e+00 seconds\n",
      " Total time in simulation          = 2.2633e+00 seconds\n",
      "   Time in transport only          = 2.2198e+00 seconds\n",
      "   Time in inactive batches        = 3.6496e-01 seconds\n",
      "   Time in active batches          = 1.8983e+00 seconds\n",
      "   Time synchronizing fission bank = 4.3325e-03 seconds\n",
      "     Sampling source sites         = 3.8357e-03 seconds\n",
      "     SEND/RECV source sites        = 4.7343e-04 seconds\n",
      "   Time accumulating tallies       = 2.5058e-02 seconds\n",
      "   Time writing statepoints        = 8.2730e-03 seconds\n",
      " Total time for finalization       = 1.3693e-04 seconds\n",
      " Total time elapsed                = 2.2745e+00 seconds\n",
      " Calculation Rate (inactive)       = 27399.9 particles/second\n",
      " Calculation Rate (active)         = 21071.1 particles/second\n",
      "\n",
      " ============================>     RESULTS     <============================\n",
      "\n",
      " k-effective (Collision)     = 1.43309 +/- 0.00659\n",
      " k-effective (Track-length)  = 1.43509 +/- 0.00600\n",
      " k-effective (Absorption)    = 1.42600 +/- 0.00359\n",
      " Combined k-effective        = 1.42781 +/- 0.00354\n",
      " Leakage Fraction            = 0.00000 +/- 0.00000\n",
      "\n",
      " Creating state point openmc_simulation_n2.h5...\n",
      "[openmc.deplete] t=7776000.0 s, dt=2592000 s, source=174\n",
      " Maximum neutron transport energy: 20000000 eV for U235\n",
      " Initializing source particles...\n",
      "\n",
      " ====================>     K EIGENVALUE SIMULATION     <====================\n",
      "\n",
      "  Bat./Gen.      k            Average k\n",
      "  =========   ========   ====================\n",
      "        1/1    1.44203\n",
      "        2/1    1.37132\n",
      "        3/1    1.42001\n",
      "        4/1    1.42945\n",
      "        5/1    1.44713\n",
      "        6/1    1.46065\n",
      "        7/1    1.44657\n",
      "        8/1    1.38157\n",
      "        9/1    1.46971\n",
      "       10/1    1.55415\n",
      "       11/1    1.34500\n",
      "       12/1    1.40011    1.37255 +/- 0.02756\n",
      "       13/1    1.47993    1.40834 +/- 0.03917\n",
      "       14/1    1.48390    1.42723 +/- 0.03352\n",
      "       15/1    1.45548    1.43288 +/- 0.02658\n",
      "       16/1    1.44571    1.43502 +/- 0.02180\n",
      "       17/1    1.43232    1.43463 +/- 0.01843\n",
      "       18/1    1.50338    1.44323 +/- 0.01813\n",
      "       19/1    1.53546    1.45348 +/- 0.01899\n",
      "       20/1    1.41146    1.44927 +/- 0.01750\n",
      "       21/1    1.39360    1.44421 +/- 0.01662\n",
      "       22/1    1.46111    1.44562 +/- 0.01523\n",
      "       23/1    1.53882    1.45279 +/- 0.01574\n",
      "       24/1    1.39733    1.44883 +/- 0.01510\n",
      "       25/1    1.42802    1.44744 +/- 0.01413\n",
      "       26/1    1.39609    1.44423 +/- 0.01360\n",
      "       27/1    1.43661    1.44378 +/- 0.01278\n",
      "       28/1    1.38011    1.44025 +/- 0.01256\n",
      "       29/1    1.41518    1.43893 +/- 0.01195\n",
      "       30/1    1.45954    1.43996 +/- 0.01139\n",
      "       31/1    1.44620    1.44025 +/- 0.01083\n",
      "       32/1    1.50544    1.44322 +/- 0.01075\n",
      "       33/1    1.47331    1.44453 +/- 0.01035\n",
      "       34/1    1.38227    1.44193 +/- 0.01025\n",
      "       35/1    1.43997    1.44185 +/- 0.00983\n",
      "       36/1    1.39731    1.44014 +/- 0.00960\n",
      "       37/1    1.49595    1.44221 +/- 0.00946\n",
      "       38/1    1.40348    1.44082 +/- 0.00922\n",
      "       39/1    1.33228    1.43708 +/- 0.00965\n",
      "       40/1    1.40644    1.43606 +/- 0.00938\n",
      "       41/1    1.41400    1.43535 +/- 0.00910\n",
      "       42/1    1.38516    1.43378 +/- 0.00895\n",
      "       43/1    1.38802    1.43239 +/- 0.00879\n",
      "       44/1    1.39526    1.43130 +/- 0.00859\n",
      "       45/1    1.30116    1.42758 +/- 0.00914\n",
      "       46/1    1.43647    1.42783 +/- 0.00888\n",
      "       47/1    1.38574    1.42669 +/- 0.00871\n",
      "       48/1    1.38079    1.42549 +/- 0.00857\n",
      "       49/1    1.45147    1.42615 +/- 0.00837\n",
      "       50/1    1.41959    1.42599 +/- 0.00816\n",
      " Creating state point statepoint.50.h5...\n",
      "\n",
      " =======================>     TIMING STATISTICS     <=======================\n",
      "\n",
      " Total time for initialization     = 0.0000e+00 seconds\n",
      "   Reading cross sections          = 0.0000e+00 seconds\n",
      " Total time in simulation          = 2.1898e+00 seconds\n",
      "   Time in transport only          = 2.1562e+00 seconds\n",
      "   Time in inactive batches        = 3.8682e-01 seconds\n",
      "   Time in active batches          = 1.8030e+00 seconds\n",
      "   Time synchronizing fission bank = 5.1998e-03 seconds\n",
      "     Sampling source sites         = 4.5969e-03 seconds\n",
      "     SEND/RECV source sites        = 5.7608e-04 seconds\n",
      "   Time accumulating tallies       = 7.0743e-03 seconds\n",
      "   Time writing statepoints        = 9.8496e-03 seconds\n",
      " Total time for finalization       = 1.5070e-04 seconds\n",
      " Total time elapsed                = 2.2008e+00 seconds\n",
      " Calculation Rate (inactive)       = 25851.7 particles/second\n",
      " Calculation Rate (active)         = 22185.4 particles/second\n",
      "\n",
      " ============================>     RESULTS     <============================\n",
      "\n",
      " k-effective (Collision)     = 1.43114 +/- 0.00639\n",
      " k-effective (Track-length)  = 1.42599 +/- 0.00816\n",
      " k-effective (Absorption)    = 1.42830 +/- 0.00470\n",
      " Combined k-effective        = 1.42849 +/- 0.00451\n",
      " Leakage Fraction            = 0.00000 +/- 0.00000\n",
      "\n",
      " Creating state point openmc_simulation_n3.h5...\n",
      "[openmc.deplete] t=10368000.0 s, dt=2592000 s, source=174\n",
      " Maximum neutron transport energy: 20000000 eV for U235\n",
      " Initializing source particles...\n",
      "\n",
      " ====================>     K EIGENVALUE SIMULATION     <====================\n",
      "\n",
      "  Bat./Gen.      k            Average k\n",
      "  =========   ========   ====================\n",
      "        1/1    1.37033\n",
      "        2/1    1.37110\n",
      "        3/1    1.38802\n",
      "        4/1    1.36630\n",
      "        5/1    1.46033\n",
      "        6/1    1.38151\n",
      "        7/1    1.47543\n",
      "        8/1    1.27561\n",
      "        9/1    1.43995\n",
      "       10/1    1.47347\n",
      "       11/1    1.44212\n",
      "       12/1    1.43502    1.43857 +/- 0.00355\n",
      "       13/1    1.33714    1.40476 +/- 0.03387\n",
      "       14/1    1.39828    1.40314 +/- 0.02401\n",
      "       15/1    1.39016    1.40055 +/- 0.01877\n",
      "       16/1    1.52402    1.42112 +/- 0.02566\n",
      "       17/1    1.39956    1.41804 +/- 0.02191\n",
      "       18/1    1.43515    1.42018 +/- 0.01909\n",
      "       19/1    1.42497    1.42071 +/- 0.01684\n",
      "       20/1    1.39614    1.41826 +/- 0.01527\n",
      "       21/1    1.43771    1.42003 +/- 0.01392\n",
      "       22/1    1.47738    1.42480 +/- 0.01358\n",
      "       23/1    1.48097    1.42913 +/- 0.01322\n",
      "       24/1    1.37766    1.42545 +/- 0.01278\n",
      "       25/1    1.40317    1.42396 +/- 0.01199\n",
      "       26/1    1.41995    1.42371 +/- 0.01121\n",
      "       27/1    1.41925    1.42345 +/- 0.01054\n",
      "       28/1    1.51134    1.42833 +/- 0.01107\n",
      "       29/1    1.43506    1.42869 +/- 0.01048\n",
      "       30/1    1.43915    1.42921 +/- 0.00995\n",
      "       31/1    1.47963    1.43161 +/- 0.00977\n",
      "       32/1    1.38891    1.42967 +/- 0.00951\n",
      "       33/1    1.44461    1.43032 +/- 0.00911\n",
      "       34/1    1.39490    1.42884 +/- 0.00885\n",
      "       35/1    1.39509    1.42749 +/- 0.00859\n",
      "       36/1    1.33191    1.42382 +/- 0.00904\n",
      "       37/1    1.43944    1.42440 +/- 0.00872\n",
      "       38/1    1.38917    1.42314 +/- 0.00849\n",
      "       39/1    1.30703    1.41913 +/- 0.00912\n",
      "       40/1    1.40722    1.41874 +/- 0.00882\n",
      "       41/1    1.42532    1.41895 +/- 0.00853\n",
      "       42/1    1.40705    1.41858 +/- 0.00827\n",
      "       43/1    1.43005    1.41893 +/- 0.00802\n",
      "       44/1    1.53167    1.42224 +/- 0.00846\n",
      "       45/1    1.43357    1.42257 +/- 0.00822\n",
      "       46/1    1.42545    1.42265 +/- 0.00799\n",
      "       47/1    1.35218    1.42074 +/- 0.00800\n",
      "       48/1    1.38210    1.41972 +/- 0.00785\n",
      "       49/1    1.37741    1.41864 +/- 0.00773\n",
      "       50/1    1.36010    1.41718 +/- 0.00767\n",
      " Creating state point statepoint.50.h5...\n",
      "\n",
      " =======================>     TIMING STATISTICS     <=======================\n",
      "\n",
      " Total time for initialization     = 0.0000e+00 seconds\n",
      "   Reading cross sections          = 0.0000e+00 seconds\n",
      " Total time in simulation          = 2.1741e+00 seconds\n",
      "   Time in transport only          = 2.1341e+00 seconds\n",
      "   Time in inactive batches        = 3.8098e-01 seconds\n",
      "   Time in active batches          = 1.7932e+00 seconds\n",
      "   Time synchronizing fission bank = 4.3005e-03 seconds\n",
      "     Sampling source sites         = 3.8080e-03 seconds\n",
      "     SEND/RECV source sites        = 4.6940e-04 seconds\n",
      "   Time accumulating tallies       = 1.6604e-02 seconds\n",
      "   Time writing statepoints        = 8.4289e-03 seconds\n",
      " Total time for finalization       = 1.1203e-04 seconds\n",
      " Total time elapsed                = 2.1851e+00 seconds\n",
      " Calculation Rate (inactive)       = 26248.3 particles/second\n",
      " Calculation Rate (active)         = 22307 particles/second\n",
      "\n",
      " ============================>     RESULTS     <============================\n",
      "\n",
      " k-effective (Collision)     = 1.41664 +/- 0.00557\n",
      " k-effective (Track-length)  = 1.41718 +/- 0.00767\n",
      " k-effective (Absorption)    = 1.41504 +/- 0.00530\n",
      " Combined k-effective        = 1.41572 +/- 0.00495\n",
      " Leakage Fraction            = 0.00000 +/- 0.00000\n",
      "\n",
      " Creating state point openmc_simulation_n4.h5...\n",
      "[openmc.deplete] t=12960000.0 s, dt=2592000 s, source=174\n",
      " Maximum neutron transport energy: 20000000 eV for U235\n",
      " Initializing source particles...\n",
      "\n",
      " ====================>     K EIGENVALUE SIMULATION     <====================\n",
      "\n",
      "  Bat./Gen.      k            Average k\n",
      "  =========   ========   ====================\n",
      "        1/1    1.46306\n",
      "        2/1    1.40413\n",
      "        3/1    1.38221\n",
      "        4/1    1.39894\n",
      "        5/1    1.41542\n",
      "        6/1    1.39772\n",
      "        7/1    1.45022\n",
      "        8/1    1.44785\n",
      "        9/1    1.48213\n",
      "       10/1    1.46955\n",
      "       11/1    1.42723\n",
      "       12/1    1.34964    1.38843 +/- 0.03879\n",
      "       13/1    1.42135    1.39940 +/- 0.02494\n",
      "       14/1    1.37438    1.39315 +/- 0.01871\n",
      "       15/1    1.38311    1.39114 +/- 0.01463\n",
      "       16/1    1.41977    1.39591 +/- 0.01286\n",
      "       17/1    1.33150    1.38671 +/- 0.01424\n",
      "       18/1    1.42436    1.39142 +/- 0.01320\n",
      "       19/1    1.38779    1.39101 +/- 0.01165\n",
      "       20/1    1.38721    1.39063 +/- 0.01043\n",
      "       21/1    1.36568    1.38837 +/- 0.00970\n",
      "       22/1    1.46070    1.39439 +/- 0.01071\n",
      "       23/1    1.33710    1.38999 +/- 0.01080\n",
      "       24/1    1.36294    1.38805 +/- 0.01018\n",
      "       25/1    1.42953    1.39082 +/- 0.00987\n",
      "       26/1    1.38685    1.39057 +/- 0.00924\n",
      "       27/1    1.38880    1.39047 +/- 0.00868\n",
      "       28/1    1.40920    1.39151 +/- 0.00825\n",
      "       29/1    1.42561    1.39330 +/- 0.00800\n",
      "       30/1    1.37126    1.39220 +/- 0.00767\n",
      "       31/1    1.41916    1.39348 +/- 0.00741\n",
      "       32/1    1.43876    1.39554 +/- 0.00736\n",
      "       33/1    1.46095    1.39839 +/- 0.00759\n",
      "       34/1    1.45793    1.40087 +/- 0.00767\n",
      "       35/1    1.50240    1.40493 +/- 0.00841\n",
      "       36/1    1.48791    1.40812 +/- 0.00869\n",
      "       37/1    1.48119    1.41083 +/- 0.00878\n",
      "       38/1    1.41484    1.41097 +/- 0.00847\n",
      "       39/1    1.37848    1.40985 +/- 0.00825\n",
      "       40/1    1.44824    1.41113 +/- 0.00807\n",
      "       41/1    1.39708    1.41068 +/- 0.00782\n",
      "       42/1    1.53692    1.41462 +/- 0.00854\n",
      "       43/1    1.46509    1.41615 +/- 0.00841\n",
      "       44/1    1.37780    1.41502 +/- 0.00824\n",
      "       45/1    1.38167    1.41407 +/- 0.00806\n",
      "       46/1    1.37516    1.41299 +/- 0.00790\n",
      "       47/1    1.35518    1.41143 +/- 0.00784\n",
      "       48/1    1.43825    1.41213 +/- 0.00767\n",
      "       49/1    1.47710    1.41380 +/- 0.00765\n",
      "       50/1    1.29075    1.41072 +/- 0.00807\n",
      " Creating state point statepoint.50.h5...\n",
      "\n",
      " =======================>     TIMING STATISTICS     <=======================\n",
      "\n",
      " Total time for initialization     = 0.0000e+00 seconds\n",
      "   Reading cross sections          = 0.0000e+00 seconds\n",
      " Total time in simulation          = 2.2692e+00 seconds\n",
      "   Time in transport only          = 2.2311e+00 seconds\n",
      "   Time in inactive batches        = 3.7992e-01 seconds\n",
      "   Time in active batches          = 1.8893e+00 seconds\n",
      "   Time synchronizing fission bank = 4.1443e-03 seconds\n",
      "     Sampling source sites         = 3.6657e-03 seconds\n",
      "     SEND/RECV source sites        = 4.5581e-04 seconds\n",
      "   Time accumulating tallies       = 1.1112e-02 seconds\n",
      "   Time writing statepoints        = 9.1483e-03 seconds\n",
      " Total time for finalization       = 1.8265e-04 seconds\n",
      " Total time elapsed                = 2.2804e+00 seconds\n",
      " Calculation Rate (inactive)       = 26321.7 particles/second\n",
      " Calculation Rate (active)         = 21172.1 particles/second\n",
      "\n",
      " ============================>     RESULTS     <============================\n",
      "\n",
      " k-effective (Collision)     = 1.41804 +/- 0.00536\n",
      " k-effective (Track-length)  = 1.41072 +/- 0.00807\n",
      " k-effective (Absorption)    = 1.41232 +/- 0.00474\n",
      " Combined k-effective        = 1.41568 +/- 0.00449\n",
      " Leakage Fraction            = 0.00000 +/- 0.00000\n",
      "\n",
      " Creating state point openmc_simulation_n5.h5...\n",
      "[openmc.deplete] t=15552000.0 (final operator evaluation)\n",
      " Maximum neutron transport energy: 20000000 eV for U235\n",
      " Initializing source particles...\n",
      "\n",
      " ====================>     K EIGENVALUE SIMULATION     <====================\n",
      "\n",
      "  Bat./Gen.      k            Average k\n",
      "  =========   ========   ====================\n",
      "        1/1    1.44678\n",
      "        2/1    1.34716\n",
      "        3/1    1.36739\n",
      "        4/1    1.39101\n",
      "        5/1    1.49718\n",
      "        6/1    1.51489\n",
      "        7/1    1.44260\n",
      "        8/1    1.46439\n",
      "        9/1    1.44700\n",
      "       10/1    1.38851\n",
      "       11/1    1.46101\n",
      "       12/1    1.47356    1.46728 +/- 0.00627\n",
      "       13/1    1.40065    1.44507 +/- 0.02251\n",
      "       14/1    1.35718    1.42310 +/- 0.02713\n",
      "       15/1    1.38017    1.41451 +/- 0.02270\n",
      "       16/1    1.37180    1.40739 +/- 0.01986\n",
      "       17/1    1.52455    1.42413 +/- 0.02370\n",
      "       18/1    1.45525    1.42802 +/- 0.02089\n",
      "       19/1    1.44822    1.43026 +/- 0.01856\n",
      "       20/1    1.37248    1.42449 +/- 0.01758\n",
      "       21/1    1.42099    1.42417 +/- 0.01590\n",
      "       22/1    1.42216    1.42400 +/- 0.01452\n",
      "       23/1    1.45655    1.42650 +/- 0.01359\n",
      "       24/1    1.36976    1.42245 +/- 0.01322\n",
      "       25/1    1.44990    1.42428 +/- 0.01244\n",
      "       26/1    1.32784    1.41825 +/- 0.01310\n",
      "       27/1    1.41348    1.41797 +/- 0.01231\n",
      "       28/1    1.34169    1.41374 +/- 0.01236\n",
      "       29/1    1.41758    1.41394 +/- 0.01169\n",
      "       30/1    1.36275    1.41138 +/- 0.01138\n",
      "       31/1    1.49931    1.41557 +/- 0.01161\n",
      "       32/1    1.45097    1.41717 +/- 0.01118\n",
      "       33/1    1.51481    1.42142 +/- 0.01150\n",
      "       34/1    1.37432    1.41946 +/- 0.01118\n",
      "       35/1    1.48161    1.42194 +/- 0.01101\n",
      "       36/1    1.40184    1.42117 +/- 0.01061\n",
      "       37/1    1.29647    1.41655 +/- 0.01120\n",
      "       38/1    1.45697    1.41800 +/- 0.01089\n",
      "       39/1    1.38990    1.41703 +/- 0.01055\n",
      "       40/1    1.40550    1.41664 +/- 0.01020\n",
      "       41/1    1.46331    1.41815 +/- 0.00998\n",
      "       42/1    1.43932    1.41881 +/- 0.00969\n",
      "       43/1    1.38469    1.41777 +/- 0.00945\n",
      "       44/1    1.42941    1.41812 +/- 0.00917\n",
      "       45/1    1.35216    1.41623 +/- 0.00910\n",
      "       46/1    1.36468    1.41480 +/- 0.00896\n",
      "       47/1    1.38988    1.41413 +/- 0.00874\n",
      "       48/1    1.58585    1.41865 +/- 0.00963\n",
      "       49/1    1.30513    1.41574 +/- 0.00982\n",
      "       50/1    1.33485    1.41371 +/- 0.00979\n",
      " Creating state point statepoint.50.h5...\n",
      "\n",
      " =======================>     TIMING STATISTICS     <=======================\n",
      "\n",
      " Total time for initialization     = 0.0000e+00 seconds\n",
      "   Reading cross sections          = 0.0000e+00 seconds\n",
      " Total time in simulation          = 2.2627e+00 seconds\n",
      "   Time in transport only          = 2.2212e+00 seconds\n",
      "   Time in inactive batches        = 3.7561e-01 seconds\n",
      "   Time in active batches          = 1.8871e+00 seconds\n",
      "   Time synchronizing fission bank = 4.1635e-03 seconds\n",
      "     Sampling source sites         = 3.6738e-03 seconds\n",
      "     SEND/RECV source sites        = 4.6676e-04 seconds\n",
      "   Time accumulating tallies       = 1.9553e-02 seconds\n",
      "   Time writing statepoints        = 9.2177e-03 seconds\n",
      " Total time for finalization       = 1.9956e-04 seconds\n",
      " Total time elapsed                = 2.2739e+00 seconds\n",
      " Calculation Rate (inactive)       = 26623.6 particles/second\n",
      " Calculation Rate (active)         = 21196.5 particles/second\n",
      "\n",
      " ============================>     RESULTS     <============================\n",
      "\n",
      " k-effective (Collision)     = 1.41716 +/- 0.00736\n",
      " k-effective (Track-length)  = 1.41371 +/- 0.00979\n",
      " k-effective (Absorption)    = 1.42694 +/- 0.00479\n",
      " Combined k-effective        = 1.42526 +/- 0.00491\n",
      " Leakage Fraction            = 0.00000 +/- 0.00000\n",
      "\n",
      " Creating state point openmc_simulation_n6.h5...\n"
     ]
    }
   ],
   "source": [
    "integrator.integrate()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Processing the outputs\n",
    "\n",
    "The depletion simulation produces a few output files. First, the statepoint files from each individual transport simulation are written to `openmc_simulation_n<N>.h5`, where `<N>` indicates the current depletion step. Any tallies that we defined in `tallies.xml` will be included in these files across our simulations. We have 7 such files, one for each our of 6 depletion steps and the initial state."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "depletion_results.h5\t openmc_simulation_n3.h5  statepoint.50.h5\n",
      "openmc_simulation_n0.h5  openmc_simulation_n4.h5  summary.h5\n",
      "openmc_simulation_n1.h5  openmc_simulation_n5.h5\n",
      "openmc_simulation_n2.h5  openmc_simulation_n6.h5\n"
     ]
    }
   ],
   "source": [
    "!ls *.h5"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `depletion_results.h5` file contains information that is aggregated over all time steps through depletion. This includes the multiplication factor, as well as concentrations. We can process this file using the `openmc.deplete.Results` object"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "results = openmc.deplete.Results(\"./depletion_results.h5\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "time, k = results.get_keff()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "time /= (24 * 60 * 60)  # convert back to days from seconds"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1.45490147, 0.00474236],\n",
       "       [1.43943243, 0.00475038],\n",
       "       [1.42781404, 0.0035448 ],\n",
       "       [1.42849313, 0.00451031],\n",
       "       [1.41571572, 0.00495453],\n",
       "       [1.41567621, 0.00449157],\n",
       "       [1.42525626, 0.00491492]])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "k"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The first column of `k` is the value of `k-combined` at each point in our simulation, while the second column contains the associated uncertainty. We can plot this using `matplotlib`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "from matplotlib import pyplot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 24908 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pyplot.errorbar(time, k[:, 0], yerr=k[:, 1])\n",
    "pyplot.xlabel(\"Time [d]\")\n",
    "pyplot.ylabel(\"$k_{eff}\\pm \\sigma$\");"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Due to the low number of particles selected, the uncertainty on each value is rather high. However, we can still see the decline in `k` over time due to fuel consumption."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can then examine concentrations of atoms in each of our materials. This requires knowing the material ID, which can be obtained from the `materials.xml` file."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "_, u235 = results.get_atoms(\"1\", \"U235\")\n",
    "_, xe135 = results.get_atoms(\"1\", \"Xe135\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 29112 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pyplot.plot(time, u235, label=\"U235\")\n",
    "pyplot.xlabel(\"Time [d]\")\n",
    "pyplot.ylabel(\"Number of atoms - U235\");"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 25332 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pyplot.plot(time, xe135, label=\"Xe135\")\n",
    "pyplot.xlabel(\"Time [d]\")\n",
    "pyplot.ylabel(\"Number of atoms - Xe135\");"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can also examine reaction rates over time using the `Results` object."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "_, u235_fission = results.get_reaction_rate(\"1\", \"U235\", \"fission\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 36308 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pyplot.plot(time, u235_fission)\n",
    "pyplot.xlabel(\"Time [d]\")\n",
    "pyplot.ylabel(\"Fission reactions / s\");"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Helpful tips\n",
    "\n",
    "Depletion is a tricky task to get correct. Use too short of a time step, and you will incur a steep cost in computational time due to excessive transport simulations. Use too long of a time step, and you may miss physics happening on shorter timescales, leading to incorrect answers. Consider the xenon plot from above. Xenon-135 is a fission product with a thermal absorption cross section on the order of millions of barns, but it has a half life of ~9 hours. Taking smaller time steps at the beginning of your simulation to build up some equilibrium in your fission products is highly recommended.\n",
    "\n",
    "When possible, differentiate materials that reappear in multiple places. If we had built an entire core with the single `fuel` material, every pin would be depleted using the same averaged spectrum and reaction rates, which is incorrect. Pins experiencing different flux will deplete at different rates. The `Operator` can differentiate these materials using the `diff_burnable_mats` argument, but note that the volumes will be copied from the original material.\n",
    "\n",
    "Using higher-order integrators, like the `CECMIntegrator`, `EPCRK4Integrator` with a fourth order Runge-Kutta, or the `LEQIIntegrator`, can improve the accuracy of a simulation, or at least allow you to take longer depletion steps between transport simulations with similar accuracy.\n",
    "\n",
    "Fuel pins with integrated burnable absorbers, like gadolinia, experience strong flux gradients until the absorbers are mostly burned away. This means that the spectrum and magnitude of the flux at the edge of the fuel pin can be vastly different than that in the interior. The helper `pin` function can be used to subdivide regions into equal volume segments, as follows."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "div_surfs_1 = [openmc.ZCylinder(r=1)]\n",
    "div_1 = openmc.model.pin(div_surfs_1, [fuel, water], subdivisions={0: 10})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7fb9dfe7a7c0>"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 12524 characters]",
      "text/plain": [
       "<Figure size 258.065x259.74 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "div_1.plot(width=(2.0, 2.0))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The innermost region has been divided into 10 equal volume regions. We can pass additional arguments to divide multiple regions, except for the region outside the last cylinder."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Register depletion chain\n",
    "\n",
    "The depletion chain we created can be registered into the OpenMC `cross_sections.xml` file, so we don't have to always pass the `chain_file` argument to the `Operator`. To do this, we create a `DataLibrary` using `openmc.data`. Without any arguments, the `from_xml` method will look for the file located at `OPENMC_CROSS_SECTIONS`. For this example, we will just create a bare library."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_lib = openmc.data.DataLibrary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_lib.register_file(\"./chain_simple.xml\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_lib.export_to_xml()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<?xml version='1.0' encoding='utf-8'?>\n",
      "<cross_sections>\n",
      "  <depletion_chain path=\"chain_simple.xml\" type=\"depletion_chain\" />\n",
      "</cross_sections>\n"
     ]
    }
   ],
   "source": [
    "!cat cross_sections.xml"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This allows us to make an `Operator` simply with the geometry and settings arguments, provided we exported our library to `OPENMC_CROSS_SECTIONS`. For a problem where we built and registered a `Chain` using all the available nuclear data, we might see something like the following."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "model = openmc.Model(geometry=geometry, settings=settings)\n",
    "new_op = openmc.deplete.CoupledOperator(model, \"./chain_simple.xml\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(new_op.chain.nuclide_dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['I135', 'Xe135', 'Xe136', 'Cs135', 'Gd157', 'Gd156', 'U234', 'U235', 'U238']"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[nuc.name for nuc in new_op.chain.nuclides[:10]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['I135', 'Xe135', 'Xe136', 'Cs135', 'Gd157', 'Gd156', 'U234', 'U235', 'U238']"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[nuc.name for nuc in new_op.chain.nuclides[-10:]]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Choice of depletion step size\n",
    "\n",
    "A general rule of thumb is to use depletion step sizes around 2 MWd/kgHM, where kgHM is really the initial heavy metal mass in kg. If your problem includes integral burnable absorbers, these typically require shorter time steps at or below 1 MWd/kgHM. These are typically valid for the predictor scheme, as the point of recent schemes is to extend this step size. A good convergence study, where the step size is decreased until some convergence metric is satisfied, is a beneficial exercise.\n",
    "\n",
    "We can use the `Operator` to determine our maximum step size using this recommendation. The `heavy_metal` attribute returns the mass of initial heavy metal in g, which, using our power, can be used to compute this step size. $$\\frac{2\\,MWd}{kgHM} = \\frac{P\\times\\Delta}{hm_{op}}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5.080339195444219"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "operator.heavy_metal"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "max_step = 2 * operator.heavy_metal / power * 1E3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\"Maximum\" depletion step:  58.4 [d]\n"
     ]
    }
   ],
   "source": [
    "print(\"\\\"Maximum\\\" depletion step: {:5.3} [d]\".format(max_step))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Alternatively, if we were provided the power density of our problem, we can provide this directly with `openmc.deplete.PredictorIntegrator(operator, time_steps, power_density=pdens)`. The values of `power` and `power_density` do not have to be scalars. For problems with variable power, we can provide an iterable with the same number of elements as `time_steps`."
   ]
  }
 ],
 "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.11.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
