mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-22 06:55:35 -04:00
799 lines
24 KiB
Text
799 lines
24 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"This notebook demonstrates some basic post-processing tasks that can be performed with the Python API, such as plotting a 2D mesh tally and plotting neutron source sites from an eigenvalue calculation. The problem we will use is a simple reflected pin-cell."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"from IPython.display import Image\n",
|
|
"import numpy as np\n",
|
|
"import matplotlib.pyplot as plt\n",
|
|
"\n",
|
|
"import openmc\n",
|
|
"from openmc.statepoint import StatePoint\n",
|
|
"\n",
|
|
"%matplotlib inline"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Generate Input Files"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"First we need to define materials that will be used in the problem. Before defining a material, we must create nuclides that are used in the material."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {
|
|
"collapsed": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Instantiate some Nuclides\n",
|
|
"h1 = openmc.Nuclide('H-1')\n",
|
|
"b10 = openmc.Nuclide('B-10')\n",
|
|
"o16 = openmc.Nuclide('O-16')\n",
|
|
"u235 = openmc.Nuclide('U-235')\n",
|
|
"u238 = openmc.Nuclide('U-238')\n",
|
|
"zr90 = openmc.Nuclide('Zr-90')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"With the nuclides we defined, we will now create three materials for the fuel, water, and cladding of the fuel pin."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# 1.6 enriched fuel\n",
|
|
"fuel = openmc.Material(name='1.6% Fuel')\n",
|
|
"fuel.set_density('g/cm3', 10.31341)\n",
|
|
"fuel.add_nuclide(u235, 3.7503e-4)\n",
|
|
"fuel.add_nuclide(u238, 2.2625e-2)\n",
|
|
"fuel.add_nuclide(o16, 4.6007e-2)\n",
|
|
"\n",
|
|
"# borated water\n",
|
|
"water = openmc.Material(name='Borated Water')\n",
|
|
"water.set_density('g/cm3', 0.740582)\n",
|
|
"water.add_nuclide(h1, 4.9457e-2)\n",
|
|
"water.add_nuclide(o16, 2.4732e-2)\n",
|
|
"water.add_nuclide(b10, 8.0042e-6)\n",
|
|
"\n",
|
|
"# zircaloy\n",
|
|
"zircaloy = openmc.Material(name='Zircaloy')\n",
|
|
"zircaloy.set_density('g/cm3', 6.55)\n",
|
|
"zircaloy.add_nuclide(zr90, 7.2758e-3)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"With our three materials, we can now create a materials file object that can be exported to an actual XML file."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Instantiate a MaterialsFile, add Materials\n",
|
|
"materials_file = openmc.MaterialsFile()\n",
|
|
"materials_file.add_material(fuel)\n",
|
|
"materials_file.add_material(water)\n",
|
|
"materials_file.add_material(zircaloy)\n",
|
|
"materials_file.default_xs = '71c'\n",
|
|
"\n",
|
|
"# Export to \"materials.xml\"\n",
|
|
"materials_file.export_to_xml()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Now let's move on to the geometry. Our problem will have three regions for the fuel, the clad, and the surrounding coolant. The first step is to create the bounding surfaces -- in this case two cylinders and six reflective planes."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Create cylinders for the fuel and clad\n",
|
|
"fuel_outer_radius = openmc.ZCylinder(x0=0.0, y0=0.0, R=0.39218)\n",
|
|
"clad_outer_radius = openmc.ZCylinder(x0=0.0, y0=0.0, R=0.45720)\n",
|
|
"\n",
|
|
"# Create boundary planes to surround the geometry\n",
|
|
"# Use both reflective and vacuum boundaries to make life interesting\n",
|
|
"min_x = openmc.XPlane(x0=-0.63, boundary_type='reflective')\n",
|
|
"max_x = openmc.XPlane(x0=+0.63, boundary_type='reflective')\n",
|
|
"min_y = openmc.YPlane(y0=-0.63, boundary_type='reflective')\n",
|
|
"max_y = openmc.YPlane(y0=+0.63, boundary_type='reflective')\n",
|
|
"min_z = openmc.ZPlane(z0=-0.63, boundary_type='reflective')\n",
|
|
"max_z = openmc.ZPlane(z0=+0.63, boundary_type='reflective')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"With the surfaces defined, we can now create cells that are defined by intersections of half-spaces created by the surfaces."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Create a Universe to encapsulate a fuel pin\n",
|
|
"pin_cell_universe = openmc.Universe(name='1.6% Fuel Pin')\n",
|
|
"\n",
|
|
"# Create fuel Cell\n",
|
|
"fuel_cell = openmc.Cell(name='1.6% Fuel')\n",
|
|
"fuel_cell.fill = fuel\n",
|
|
"fuel_cell.region = -fuel_outer_radius\n",
|
|
"pin_cell_universe.add_cell(fuel_cell)\n",
|
|
"\n",
|
|
"# Create a clad Cell\n",
|
|
"clad_cell = openmc.Cell(name='1.6% Clad')\n",
|
|
"clad_cell.fill = zircaloy\n",
|
|
"clad_cell.region = +fuel_outer_radius & -clad_outer_radius\n",
|
|
"pin_cell_universe.add_cell(clad_cell)\n",
|
|
"\n",
|
|
"# Create a moderator Cell\n",
|
|
"moderator_cell = openmc.Cell(name='1.6% Moderator')\n",
|
|
"moderator_cell.fill = water\n",
|
|
"moderator_cell.region = +clad_outer_radius\n",
|
|
"pin_cell_universe.add_cell(moderator_cell)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"OpenMC requires that there is a \"root\" universe. Let us create a root cell that is filled by the pin cell universe and then assign it to the root universe."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Create root Cell\n",
|
|
"root_cell = openmc.Cell(name='root cell')\n",
|
|
"root_cell.fill = pin_cell_universe\n",
|
|
"\n",
|
|
"# Add boundary planes\n",
|
|
"root_cell.region = +min_x & -max_x & +min_y & -max_y & +min_z & -max_z\n",
|
|
"\n",
|
|
"# Create root Universe\n",
|
|
"root_universe = openmc.Universe(universe_id=0, name='root universe')\n",
|
|
"root_universe.add_cell(root_cell)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"We now must create a geometry that is assigned a root universe, put the geometry into a geometry file, and export it to XML."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Create Geometry and set root Universe\n",
|
|
"geometry = openmc.Geometry()\n",
|
|
"geometry.root_universe = root_universe"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Instantiate a GeometryFile\n",
|
|
"geometry_file = openmc.GeometryFile()\n",
|
|
"geometry_file.geometry = geometry\n",
|
|
"\n",
|
|
"# Export to \"geometry.xml\"\n",
|
|
"geometry_file.export_to_xml()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"With the geometry and materials finished, we now just need to define simulation parameters. In this case, we will use 10 inactive batches and 90 active batches each with 5000 particles."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"metadata": {
|
|
"collapsed": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# OpenMC simulation parameters\n",
|
|
"batches = 100\n",
|
|
"inactive = 10\n",
|
|
"particles = 5000\n",
|
|
"\n",
|
|
"# Instantiate a SettingsFile\n",
|
|
"settings_file = openmc.SettingsFile()\n",
|
|
"settings_file.batches = batches\n",
|
|
"settings_file.inactive = inactive\n",
|
|
"settings_file.particles = particles\n",
|
|
"source_bounds = [-0.63, -0.63, -0.63, 0.63, 0.63, 0.63]\n",
|
|
"settings_file.set_source_space('box', source_bounds)\n",
|
|
"\n",
|
|
"# Export to \"settings.xml\"\n",
|
|
"settings_file.export_to_xml()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Let us also create a plot file that we can use to verify that our pin cell geometry was created successfully."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Instantiate a Plot\n",
|
|
"plot = openmc.Plot(plot_id=1)\n",
|
|
"plot.filename = 'materials-xy'\n",
|
|
"plot.origin = [0, 0, 0]\n",
|
|
"plot.width = [1.26, 1.26]\n",
|
|
"plot.pixels = [250, 250]\n",
|
|
"plot.color = 'mat'\n",
|
|
"\n",
|
|
"# Instantiate a PlotsFile, add Plot, and export to \"plots.xml\"\n",
|
|
"plot_file = openmc.PlotsFile()\n",
|
|
"plot_file.add_plot(plot)\n",
|
|
"plot_file.export_to_xml()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"With the plots.xml file, we can now generate and view the plot. OpenMC outputs plots in .ppm format, which can be converted into a compressed format like .png with the convert utility."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 12,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"0"
|
|
]
|
|
},
|
|
"execution_count": 12,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"# Run openmc in plotting mode\n",
|
|
"executor = openmc.Executor()\n",
|
|
"executor.plot_geometry(output=False)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPoAAAD6AgMAAAD1grKuAAAABGdBTUEAALGPC/xhBQAAAAFzUkdC\nAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAxQTFRF\n////chIS6YCRTb/E6kGE+wAAAAFiS0dEAIgFHUgAAAAJcEhZcwAAAEgAAABIAEbJaz4AAALKSURB\nVGje7dpLcqQwDAbgHHE2YeEj+D4cwQucBUfo+3CEXoSp8OhuhF70T4qpKXmdr21LogK2Pj7A8QmN\nP+HDhw8fPnz48Kf6VH9G+66vy+je8k19jnf8C5dXIPv86ms56lPdjvaYbyodx3ze+XLE76cXFiD4\nzPji99z0/AJ4n1lfvJ6fnl0A6x+578efMSg1wPr172/jPO5yFXM+Ef78gdblM+WPHyguP//t1/g6\npA0wfln+ho/fwgYYn19C/xwDvwHGc9OvC+hs37DTrwuwfWanXxdQTC9Mvyygs3wjTL8uwPJpn/tN\nDbSGz7T0SBEWw4vLXzbQ6b6RoveIoO6TvPxlA63qs7z8ZQPF9F+SH22vbX8OQKf5Rtv+EgDNJ3X5\n8wZaxWd1+fMGiuFvir8bvjp8J/tGy/6jAmRvhW8fwL3vVT+o3grfPoB7r/IpALI3tz8FoJN84/NV\n873hB8UnM3xzANtf8nb4dwmg3grfFEDJO8JPE0i9Ff4pAYL3pI8mkHor/HMCeO9JH00g9SafEsh7\nT/ppARBvp48UwJnelT5SACd7O31TAlnvKx9SQCd7B58KgPO+8iMFuPWe9E8F8BveWX7bAjzX9y4/\n/Jve+fhsH6Ctv7n8PTzjvY/v9gEOHz58+PBX+6v/f/wPvnd54f3j6venE/yl769Xv7+j3x/o98/V\n32/o9+fl389Xnx+g5x/o+Qt6/oOeP6HnX+j5G3z+h54/ouefV5/foufP6Pk3ev4On/+j9w/o/Qd6\n/4Le/6D3T/D9V67Y/ZsVQBq+s+8f0ftP+P41axXguP9NWgDuu/Cdfv+N3r/D9/9TAID+A7T/Ae2/\ngPs/0P4TtP8F7r9J3AIO9P+g/Udw/9Oygbf7r9D+L7j/DO1/Q/vv4P4/tP8Q7n9E+y/h/k+0/xTu\nf4X7b+H+X7T/+BPuf3aM8OHDhw8fPnz4w/4vzcvgeY10sY0AAAAldEVYdGRhdGU6Y3JlYXRlADIw\nMTUtMTAtMTJUMjM6NTE6MDAtMDQ6MDDPm2Y8AAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE1LTEwLTEy\nVDIzOjUxOjAwLTA0OjAwvsbegAAAAABJRU5ErkJggg==\n",
|
|
"text/plain": [
|
|
"<IPython.core.display.Image object>"
|
|
]
|
|
},
|
|
"execution_count": 13,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"# Convert OpenMC's funky ppm to png\n",
|
|
"!convert materials-xy.ppm materials-xy.png\n",
|
|
"\n",
|
|
"# Display the materials plot inline\n",
|
|
"Image(filename='materials-xy.png')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"As we can see from the plot, we have a nice pin cell with fuel, cladding, and water! Before we run our simulation, we need to tell the code what we want to tally. The following code shows how to create a 2D mesh tally."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 14,
|
|
"metadata": {
|
|
"collapsed": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Instantiate an empty TalliesFile\n",
|
|
"tallies_file = openmc.TalliesFile()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 15,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Create mesh which will be used for tally\n",
|
|
"mesh = openmc.Mesh()\n",
|
|
"mesh.dimension = [100, 100]\n",
|
|
"mesh.lower_left = [-0.63, -0.63]\n",
|
|
"mesh.upper_right = [0.63, 0.63]\n",
|
|
"tallies_file.add_mesh(mesh)\n",
|
|
"\n",
|
|
"# Create mesh filter for tally\n",
|
|
"mesh_filter = openmc.Filter(type='mesh', bins=[1])\n",
|
|
"mesh_filter.mesh = mesh\n",
|
|
"\n",
|
|
"# Create mesh tally to score flux and fission rate\n",
|
|
"tally = openmc.Tally(name='flux')\n",
|
|
"tally.add_filter(mesh_filter)\n",
|
|
"tally.add_score('flux')\n",
|
|
"tally.add_score('fission')\n",
|
|
"tallies_file.add_tally(tally)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Export to \"tallies.xml\"\n",
|
|
"tallies_file.export_to_xml()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Now we a have a complete set of inputs, so we can go ahead and run our simulation."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": false,
|
|
"scrolled": true
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\n",
|
|
" .d88888b. 888b d888 .d8888b.\n",
|
|
" d88P\" \"Y88b 8888b d8888 d88P Y88b\n",
|
|
" 888 888 88888b.d88888 888 888\n",
|
|
" 888 888 88888b. .d88b. 88888b. 888Y88888P888 888 \n",
|
|
" 888 888 888 \"88b d8P Y8b 888 \"88b 888 Y888P 888 888 \n",
|
|
" 888 888 888 888 88888888 888 888 888 Y8P 888 888 888\n",
|
|
" Y88b. .d88P 888 d88P Y8b. 888 888 888 \" 888 Y88b d88P\n",
|
|
" \"Y88888P\" 88888P\" \"Y8888 888 888 888 888 \"Y8888P\"\n",
|
|
"__________________888______________________________________________________\n",
|
|
" 888\n",
|
|
" 888\n",
|
|
"\n",
|
|
" Copyright: 2011-2015 Massachusetts Institute of Technology\n",
|
|
" License: http://mit-crpg.github.io/openmc/license.html\n",
|
|
" Version: 0.7.0\n",
|
|
" Git SHA1: 170155e8d7935b57fad57bfad6aff1034a80206e\n",
|
|
" Date/Time: 2015-10-12 23:51:01\n",
|
|
" MPI Processes: 1\n",
|
|
"\n",
|
|
" ===========================================================================\n",
|
|
" ========================> INITIALIZATION <=========================\n",
|
|
" ===========================================================================\n",
|
|
"\n",
|
|
" Reading settings XML file...\n",
|
|
" Reading cross sections XML file...\n",
|
|
" Reading geometry XML file...\n",
|
|
" Reading materials XML file...\n",
|
|
" Reading tallies XML file...\n",
|
|
" Building neighboring cells lists for each surface...\n",
|
|
" Loading ACE cross section table: 92235.71c\n",
|
|
" Loading ACE cross section table: 92238.71c\n",
|
|
" Loading ACE cross section table: 8016.71c\n",
|
|
" Loading ACE cross section table: 1001.71c\n",
|
|
" Loading ACE cross section table: 5010.71c\n",
|
|
" Loading ACE cross section table: 40090.71c\n",
|
|
" Initializing source particles...\n",
|
|
"\n",
|
|
" ===========================================================================\n",
|
|
" ====================> K EIGENVALUE SIMULATION <====================\n",
|
|
" ===========================================================================\n",
|
|
"\n",
|
|
" Bat./Gen. k Average k \n",
|
|
" ========= ======== ==================== \n",
|
|
" 1/1 1.04894 \n",
|
|
" 2/1 1.01711 \n",
|
|
" 3/1 1.05357 \n",
|
|
" 4/1 1.03052 \n",
|
|
" 5/1 1.06523 \n",
|
|
" 6/1 1.06806 \n",
|
|
" 7/1 1.05161 \n",
|
|
" 8/1 1.04199 \n",
|
|
" 9/1 1.05010 \n",
|
|
" 10/1 1.04617 \n",
|
|
" 11/1 1.04894 \n",
|
|
" 12/1 1.06806 1.05850 +/- 0.00956\n",
|
|
" 13/1 1.05002 1.05567 +/- 0.00620\n",
|
|
" 14/1 1.03471 1.05043 +/- 0.00683\n",
|
|
" 15/1 1.01803 1.04395 +/- 0.00837\n",
|
|
" 16/1 1.05588 1.04594 +/- 0.00712\n",
|
|
" 17/1 1.07503 1.05010 +/- 0.00731\n",
|
|
" 18/1 1.02786 1.04732 +/- 0.00691\n",
|
|
" 19/1 1.00071 1.04214 +/- 0.00800\n",
|
|
" 20/1 1.05587 1.04351 +/- 0.00729\n",
|
|
" 21/1 1.03886 1.04309 +/- 0.00660\n",
|
|
" 22/1 1.04335 1.04311 +/- 0.00603\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# Run OpenMC!\n",
|
|
"executor.run_simulation()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Tally Data Processing"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Our simulation ran successfully and created a statepoint file with all the tally data in it. We begin our analysis here loading the statepoint file and 'reading' the results. By default, data from the statepoint file is only read into memory when it is requested. This helps keep the memory use to a minimum even when a statepoint file may be huge."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": false,
|
|
"scrolled": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Load the statepoint file\n",
|
|
"sp = StatePoint('statepoint.100.h5')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Next we need to get the tally, which can be done with the ``StatePoint.get_tally(...)`` method."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"tally = sp.get_tally(scores=['flux'])\n",
|
|
"print(tally)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"The statepoint file actually stores the sum and sum-of-squares for each tally bin from which the mean and variance can be calculated as described [here](http://mit-crpg.github.io/openmc/methods/tallies.html#variance). The sum and sum-of-squares can be accessed using the ``sum`` and ``sum_sq`` properties:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"tally.sum"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"However, the mean and standard deviation of the mean are usually what you are more interested in. The Tally class also has properties ``mean`` and ``std_dev`` which automatically calculate these statistics on-the-fly."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"print(tally.mean.shape)\n",
|
|
"(tally.mean, tally.std_dev)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"The tally data has three dimensions: one for filter combinations, one for nuclides, and one for scores. We see that there are 10000 filter combinations (corresponding to the 100 x 100 mesh bins), a single nuclide (since none was specified), and two scores. If we only want to look at a single score, we can use the ``get_slice(...)`` method as follows."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"flux = tally.get_slice(scores=['flux'])\n",
|
|
"fission = tally.get_slice(scores=['fission'])\n",
|
|
"print(flux)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"To get the bins into a form that we can plot, we can simply change the shape of the array since it is a numpy array."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"flux.std_dev.shape = (100, 100)\n",
|
|
"flux.mean.shape = (100, 100)\n",
|
|
"fission.std_dev.shape = (100, 100)\n",
|
|
"fission.mean.shape = (100, 100)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"fig = plt.subplot(121)\n",
|
|
"fig.imshow(flux.mean)\n",
|
|
"fig2 = plt.subplot(122)\n",
|
|
"fig2.imshow(fission.mean)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Now let's say we want to look at the distribution of relative errors of our tally bins for flux. First we create a new variable called ``relative_error`` and set it to the ratio of the standard deviation and the mean, being careful not to divide by zero in case some bins were never scored to."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Determine relative error\n",
|
|
"relative_error = np.zeros_like(flux.std_dev)\n",
|
|
"nonzero = flux.mean > 0\n",
|
|
"relative_error[nonzero] = flux.std_dev[nonzero] / flux.mean[nonzero]\n",
|
|
"\n",
|
|
"# distribution of relative errors\n",
|
|
"ret = plt.hist(relative_error[nonzero], bins=50)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Source Sites"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Source sites can be accessed from the ``source`` property. As shown below, the source sites are represented as a numpy array with a structured datatype."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"sp.source"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"If we want, say, only the energies from the source sites, we can simply index the source array with the name of the field:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"sp.source['E']"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Now, we can look at things like the energy distribution of source sites. Note that we don't directly use the ``matplotlib.pyplot.hist`` method since our binning is logarithmic."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Create log-spaced energy bins from 1 keV to 100 MeV\n",
|
|
"energy_bins = np.logspace(-3,1)\n",
|
|
"\n",
|
|
"# Calculate pdf for source energies\n",
|
|
"probability, bin_edges = np.histogram(sp.source['E'], energy_bins, density=True)\n",
|
|
"\n",
|
|
"# Make sure integrating the PDF gives us unity\n",
|
|
"print(sum(probability*np.diff(energy_bins)))\n",
|
|
"\n",
|
|
"# Plot source energy PDF\n",
|
|
"plt.semilogx(energy_bins[:-1], probability*np.diff(energy_bins), linestyle='steps')\n",
|
|
"plt.xlabel('Energy (MeV)')\n",
|
|
"plt.ylabel('Probability/MeV')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Let's also look at the spatial distribution of the sites. To make the plot a little more interesting, we can also include the direction of the particle emitted from the source and color each source by the logarithm of its energy."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"plt.quiver(sp.source['xyz'][:,0], sp.source['xyz'][:,1],\n",
|
|
" sp.source['uvw'][:,0], sp.source['uvw'][:,1],\n",
|
|
" np.log(sp.source['E']), cmap='jet', scale=20.0)\n",
|
|
"plt.colorbar()\n",
|
|
"plt.xlim((-0.5,0.5))\n",
|
|
"plt.ylim((-0.5,0.5))"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 2",
|
|
"language": "python",
|
|
"name": "python2"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 2
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython2",
|
|
"version": "2.7.6"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 0
|
|
}
|