Skip to content

Instantly share code, notes, and snippets.

@scopatz
Created March 5, 2018 23:43
Show Gist options
  • Save scopatz/67e1e44851b8e6dfbdbb773096c707bf to your computer and use it in GitHub Desktop.
Save scopatz/67e1e44851b8e6dfbdbb773096c707bf to your computer and use it in GitHub Desktop.
openmc extra material segfault
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Small Lattice\n",
"\n",
"Using the the tools so far, simulate a small 3x3 lattice where the center rod is a control rod made of boron carbide (B$_4$C).\n",
"\n",
"Compute the flux in each rod, including the control rod."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/scopatz/miniconda/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
" from ._conv import register_converters as _register_converters\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.10.0\n"
]
}
],
"source": [
"import openmc\n",
"print(openmc.__version__)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Materials"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"b4c = openmc.Material(name=\"b4c\")\n",
"b4c.set_density('g/cm3', 2.52)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"b4c.add_element('B', 4.0)\n",
"b4c.add_element('C', 1.0)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Material\n",
"\tID =\t1\n",
"\tName =\tb4c\n",
"\tTemperature =\tNone\n",
"\tDensity =\t2.52 [g/cm3]\n",
"\tS(a,b) Tables \n",
"\tNuclides \n",
"\tB10 =\t0.7928 [ao]\n",
"\tB11 =\t3.2072 [ao]\n",
"\tC0 =\t1.0 [ao]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"b4c"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"uo2 = openmc.Material(name=\"uo2\")\n",
"uo2.set_density('g/cm3', 10.7)\n",
"uo2.add_nuclide('U235', 0.03)\n",
"uo2.add_nuclide('U238', 0.97)\n",
"uo2.add_element('O', 2.0)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"clad = openmc.Material(name=\"cladding\")\n",
"clad.set_density('g/cm3', 6.6)\n",
"clad.add_element('Zr', 1.0)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"cool = openmc.Material(name=\"coolant\")\n",
"cool.set_density('g/cm3', 1.0)\n",
"cool.add_element('H', 2.0)\n",
"cool.add_element('O', 1.0)\n",
"cool.add_s_alpha_beta('c_H_in_H2O')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# !!! NOTE If b4c is removed from the mats list, since it is unused, the segfault will disappear"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"mats = openmc.Materials([b4c, uo2, clad, cool])"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"mats.export_to_xml()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Surfaces"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"r_fuel = 0.39\n",
"r_clad_in = 0.4\n",
"r_clad_out = 0.46\n",
"pitch = 1.26"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"# top left\n",
"rod1_fuel = openmc.ZCylinder(R=r_fuel, x0=-pitch, y0=pitch)\n",
"rod1_clad_in = openmc.ZCylinder(R=r_clad_in, x0=-pitch, y0=pitch)\n",
"rod1_clad_out = openmc.ZCylinder(R=r_clad_out, x0=-pitch, y0=pitch)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# top center\n",
"rod2_fuel = openmc.ZCylinder(R=r_fuel, x0=0.0, y0=pitch)\n",
"rod2_clad_in = openmc.ZCylinder(R=r_clad_in, x0=0.0, y0=pitch)\n",
"rod2_clad_out = openmc.ZCylinder(R=r_clad_out, x0=0.0, y0=pitch)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"# top right\n",
"rod3_fuel = openmc.ZCylinder(R=r_fuel, x0=pitch, y0=pitch)\n",
"rod3_clad_in = openmc.ZCylinder(R=r_clad_in, x0=pitch, y0=pitch)\n",
"rod3_clad_out = openmc.ZCylinder(R=r_clad_out, x0=pitch, y0=pitch)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"# center left\n",
"rod4_fuel = openmc.ZCylinder(R=r_fuel, x0=-pitch, y0=0.0)\n",
"rod4_clad_in = openmc.ZCylinder(R=r_clad_in, x0=-pitch, y0=0.0)\n",
"rod4_clad_out = openmc.ZCylinder(R=r_clad_out, x0=-pitch, y0=0.0)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"# center center\n",
"rod5_fuel = openmc.ZCylinder(R=r_fuel, x0=0.0, y0=0.0)\n",
"rod5_clad_in = openmc.ZCylinder(R=r_clad_in, x0=0.0, y0=0.0)\n",
"rod5_clad_out = openmc.ZCylinder(R=r_clad_out, x0=0.0, y0=0.0)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"# center right\n",
"rod6_fuel = openmc.ZCylinder(R=r_fuel, x0=pitch, y0=0.0)\n",
"rod6_clad_in = openmc.ZCylinder(R=r_clad_in, x0=pitch, y0=0.0)\n",
"rod6_clad_out = openmc.ZCylinder(R=r_clad_out, x0=pitch, y0=0.0)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"# bottom left\n",
"rod7_fuel = openmc.ZCylinder(R=r_fuel, x0=-pitch, y0=-pitch)\n",
"rod7_clad_in = openmc.ZCylinder(R=r_clad_in, x0=-pitch, y0=-pitch)\n",
"rod7_clad_out = openmc.ZCylinder(R=r_clad_out, x0=-pitch, y0=-pitch)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"# bottom center\n",
"rod8_fuel = openmc.ZCylinder(R=r_fuel, x0=0.0, y0=-pitch)\n",
"rod8_clad_in = openmc.ZCylinder(R=r_clad_in, x0=0.0, y0=-pitch)\n",
"rod8_clad_out = openmc.ZCylinder(R=r_clad_out, x0=0.0, y0=-pitch)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"# bottom right\n",
"rod9_fuel = openmc.ZCylinder(R=r_fuel, x0=pitch, y0=-pitch)\n",
"rod9_clad_in = openmc.ZCylinder(R=r_clad_in, x0=pitch, y0=-pitch)\n",
"rod9_clad_out = openmc.ZCylinder(R=r_clad_out, x0=pitch, y0=-pitch)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"box = openmc.get_rectangular_prism(width=3*pitch, height=3*pitch, \n",
" boundary_type='reflective')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Cells"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"fuel_rods = (rod1_fuel, rod2_fuel, rod3_fuel, rod4_fuel, \n",
" rod6_fuel, rod7_fuel, rod8_fuel, rod9_fuel)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"fuel_region = -rod1_fuel\n",
"for fuel_rod in fuel_rods[1:]:\n",
" fuel_region = fuel_region | -fuel_rod"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"control_region = -rod5_fuel"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"gap_region = (+rod1_fuel & -rod1_clad_in)\n",
"gap_region = gap_region | (+rod2_fuel & -rod2_clad_in)\n",
"gap_region = gap_region | (+rod3_fuel & -rod3_clad_in)\n",
"gap_region = gap_region | (+rod4_fuel & -rod4_clad_in)\n",
"gap_region = gap_region | (+rod5_fuel & -rod5_clad_in)\n",
"gap_region = gap_region | (+rod6_fuel & -rod6_clad_in)\n",
"gap_region = gap_region | (+rod7_fuel & -rod7_clad_in)\n",
"gap_region = gap_region | (+rod8_fuel & -rod8_clad_in)\n",
"gap_region = gap_region | (+rod9_fuel & -rod9_clad_in)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"clad_region = (+rod1_clad_in & -rod1_clad_out)\n",
"clad_region = clad_region | (+rod2_clad_in & -rod2_clad_out)\n",
"clad_region = clad_region | (+rod3_clad_in & -rod3_clad_out)\n",
"clad_region = clad_region | (+rod4_clad_in & -rod4_clad_out)\n",
"clad_region = clad_region | (+rod5_clad_in & -rod5_clad_out)\n",
"clad_region = clad_region | (+rod6_clad_in & -rod6_clad_out)\n",
"clad_region = clad_region | (+rod7_clad_in & -rod7_clad_out)\n",
"clad_region = clad_region | (+rod8_clad_in & -rod8_clad_out)\n",
"clad_region = clad_region | (+rod9_clad_in & -rod9_clad_out)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"cool_region = box & +rod1_clad_out & +rod2_clad_out & +rod3_clad_out \\\n",
" & +rod4_clad_out & +rod5_clad_out & +rod6_clad_out \\\n",
" & +rod7_clad_out & +rod8_clad_out & +rod9_clad_out"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Cells"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"fuel_cell = openmc.Cell(name=\"Fuel\", fill=uo2, region=fuel_region)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# !!! Note that using a material other than b4c in the control rod cell causes a segfault, presumably due to an unused material"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
"control_cell = openmc.Cell(name=\"Control\", fill=clad, region=control_region)"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
"gap_cell = openmc.Cell(name=\"Gap\", region=gap_region)\n",
"clad_cell = openmc.Cell(name=\"Cladding\", fill=clad, region=clad_region)\n",
"cool_cell = openmc.Cell(name=\"Coolant\", fill=cool, region=cool_region)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Universies and Geomtery"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"root = openmc.Universe(cells=(fuel_cell, control_cell, gap_cell, \n",
" clad_cell, cool_cell))"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"geom = openmc.Geometry(root)\n",
"geom.export_to_xml()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Stats and Sources"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"src1 = openmc.Source(space=openmc.stats.Point((-pitch, pitch, 0)))\n",
"src2 = openmc.Source(space=openmc.stats.Point((0.0, pitch, 0)))\n",
"src3 = openmc.Source(space=openmc.stats.Point((pitch, pitch, 0)))\n",
"src4 = openmc.Source(space=openmc.stats.Point((-pitch, 0, 0)))\n",
"# no source in center\n",
"src6 = openmc.Source(space=openmc.stats.Point((pitch, 0, 0)))\n",
"src7 = openmc.Source(space=openmc.stats.Point((-pitch, -pitch, 0)))\n",
"src8 = openmc.Source(space=openmc.stats.Point((0.0, -pitch, 0)))\n",
"src9 = openmc.Source(space=openmc.stats.Point((pitch, -pitch, 0)))"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"settings = openmc.Settings()\n",
"settings.source = [src1, src2, src3, src4, src6, src7, src8, src9]\n",
"settings.batches = 1000\n",
"settings.inactive = 10\n",
"settings.particles = 1000"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
"settings.export_to_xml()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Tallies"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
"cell_filter = openmc.CellFilter(fuel_cell)\n",
"t = openmc.Tally()\n",
"t.filters = [cell_filter]\n",
"t.scores = ['flux']"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
"control_filter = openmc.CellFilter(control_cell)\n",
"u = openmc.Tally()\n",
"u.filters = [control_filter]\n",
"u.scores = ['flux']"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
"tallies = openmc.Tallies([t, u])\n",
"tallies.export_to_xml()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Execute!"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {
"scrolled": false
},
"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",
"\n",
" | The OpenMC Monte Carlo Code\n",
" Copyright | 2011-2018 Massachusetts Institute of Technology\n",
" License | http://openmc.readthedocs.io/en/latest/license.html\n",
" Version | 0.10.0\n",
" Git SHA1 | 9ecf2df9b520b632394f4071b14188f07336e6be\n",
" Date/Time | 2018-03-05 18:40:08\n",
" OpenMP Threads | 4\n",
"\n",
" Reading settings XML file...\n",
" Reading cross sections XML file...\n",
" Reading materials XML file...\n",
" Reading geometry XML file...\n",
" Building neighboring cells lists for each surface...\n",
" Reading B10 from /home/scopatz/nndc_hdf5/B10.h5\n",
" Reading B11 from /home/scopatz/nndc_hdf5/B11.h5\n",
" Reading C0 from /home/scopatz/nndc_hdf5/C0.h5\n",
" Reading U235 from /home/scopatz/nndc_hdf5/U235.h5\n",
" Reading U238 from /home/scopatz/nndc_hdf5/U238.h5\n",
" Reading O16 from /home/scopatz/nndc_hdf5/O16.h5\n",
" Reading O17 from /home/scopatz/nndc_hdf5/O17.h5\n",
" Reading Zr90 from /home/scopatz/nndc_hdf5/Zr90.h5\n",
" Reading Zr91 from /home/scopatz/nndc_hdf5/Zr91.h5\n",
" Reading Zr92 from /home/scopatz/nndc_hdf5/Zr92.h5\n",
" Reading Zr94 from /home/scopatz/nndc_hdf5/Zr94.h5\n",
" Reading Zr96 from /home/scopatz/nndc_hdf5/Zr96.h5\n",
" Reading H1 from /home/scopatz/nndc_hdf5/H1.h5\n",
" Reading H2 from /home/scopatz/nndc_hdf5/H2.h5\n",
" Reading c_H_in_H2O from /home/scopatz/nndc_hdf5/c_H_in_H2O.h5\n",
"\n",
"Program received signal SIGSEGV: Segmentation fault - invalid memory reference.\n",
"\n",
"Backtrace for this error:\n",
"#0 0x7F4711F36407\n",
"#1 0x7F4711F36A0E\n",
"#2 0x7F4710EA713F\n",
"#3 0x7F4713660D55\n",
"#4 0x7F471367C78A\n",
"#5 0x7F471365C37A\n"
]
},
{
"data": {
"text/plain": [
"-11"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"openmc.run()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment