Skip to content

Commit

Permalink
Merge pull request #123 from fusion-energy/develop
Browse files Browse the repository at this point in the history
general updates
  • Loading branch information
shimwell authored Aug 10, 2022
2 parents 3be6665 + f8c7d9c commit 4a09a45
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 63 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ jobs:
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: base build and push Docker image
uses: docker/build-push-action@v2
with:
push: true
target: base
tags: ghcr.io/fusion-energy/neutronics-workshop:base
build-args: |
include_avx=false
build_double_down=OFF
compile_cores=2
- name: default build and push Docker image
uses: docker/build-push-action@v2
with:
Expand Down
4 changes: 2 additions & 2 deletions tasks/task_01_cross_sections/1_isotope_xs_plot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"\n",
"In this first part of the task we are plotting the <b>microscopic</b> cross-section \"<b>σ</b>\".\n",
"\n",
"Microscopic cross section is the effective target area in m$^2$ presented by a single nucleus to an incident neutron beam.\n",
"Microscopic cross section is the effective target area in $\\mathrm{m}^2$ presented by a single nucleus to an incident neutron beam.\n",
"\n",
"This is used to characterize the probability of reaction between a neutron and an individual nucleus.\n",
"\n",
"Microscopic is often stated in units of barns where 1 barn is equal to 10$^{−28}$ m$^2$ "
"Microscopic is often stated in units of barns where 1 barn is equal to $10^{−28}$ $\\mathrm{m}^2$ "
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions tasks/task_01_cross_sections/3_material_xs_plot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"\n",
"Σ=σ.N\n",
"\n",
"Where N is the number density of nuclei in units of nuclei / m$^3$.\n",
"Where N is the number density of nuclei in units of nuclei / $\\mathrm{m}^3$.\n",
"\n",
"The units of Macroscopic cross section are therefore m$^{-1}$."
"The units of Macroscopic cross section are therefore $\\mathrm{m}^{-1}$."
]
},
{
Expand Down
123 changes: 64 additions & 59 deletions tasks/task_07_CSG_cell_tally_spectra/1_example_neutron_spectra.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Part 1 - Plotting neutron energy spectra in a histogram form\n",
"\n",
"This example creates a simple sphere of water and tallies the neutrons in two different ways:\n",
"\n",
"- Neutron flux averaged across the cell.\n",
"- Neutron current on the rear surface."
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": 8,
"source": [
"from IPython.display import HTML\n",
"HTML('<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/qHqAuqMLYPA\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>')"
],
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"output_type": "stream",
"text": [
"/home/jshimwell/miniconda3/envs/openmc-dagmc/lib/python3.8/site-packages/IPython/core/display.py:724: UserWarning:\n",
"\n",
Expand All @@ -31,31 +28,36 @@
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<IPython.core.display.HTML object>"
],
"text/html": [
"<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/qHqAuqMLYPA\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 8,
"metadata": {},
"execution_count": 8
"output_type": "execute_result"
}
],
"metadata": {}
"source": [
"from IPython.display import HTML\n",
"HTML('<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/qHqAuqMLYPA\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This section creates a simple material, geometry and settings. This model is used in both the neutron current tally and the neutron flux tally."
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import openmc\n",
"\n",
Expand Down Expand Up @@ -107,27 +109,38 @@
"source.angle = openmc.stats.Isotropic()\n",
"source.energy = openmc.stats.Discrete([14e6], [1])\n",
"sett.source = source"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This section section adds a tally for the average neutron flux across a cell."
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"#creates an empty tally object\n",
"tallies = openmc.Tallies()\n",
"\n",
"# sets up filters for the tallies\n",
"neutron_particle_filter = openmc.ParticleFilter(['neutron'])\n",
"energy_filter = openmc.EnergyFilter.from_group_structure('CCFE-709')\n",
"\n",
"# creates an array of 200 linear spaced energy bins from 0MeV to 15MeV\n",
"# our source is 14MeV so this should capture all the neutron energies in the simulation\n",
"energy_filter = openmc.EnergyFilter(np.linspace(0,15e6,200))\n",
"\n",
"# alternatively you could use one of the inbuilt energy group structures\n",
"# these are not linearly spaced as they have extra bins in key energy ranges\n",
"# A full list of energy structures is available here\n",
"# https://github.com/openmc-dev/openmc/blob/6254be37582e09acff038f5656332b89e53e4eae/openmc/mgxs/__init__.py#L50-L420\n",
"# energy_filter = openmc.EnergyFilter.from_group_structure('CCFE-709')\n",
"\n",
"\n",
"# setup the filters for the cell tally\n",
Expand All @@ -138,24 +151,23 @@
"cell_spectra_tally.scores = ['flux']\n",
"cell_spectra_tally.filters = [cell_filter, neutron_particle_filter, energy_filter]\n",
"tallies.append(cell_spectra_tally)"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This section adds two surface current tallies - one on the inner sphere surface and one on the outer sphere surface."
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# sets up filters for the tallies\n",
"neutron_particle_filter = openmc.ParticleFilter(['neutron'])\n",
"energy_filter = openmc.EnergyFilter.from_group_structure('CCFE-709')\n",
"# neutron_particle_filter and energy_filter are used from the previous cell\n",
"\n",
"# setup the filters for the surface tally\n",
"front_surface_filter = openmc.SurfaceFilter(vessel_inner_surface)\n",
Expand All @@ -171,49 +183,49 @@
"back_surface_spectra_tally.scores = ['current']\n",
"back_surface_spectra_tally.filters = [back_surface_filter, neutron_particle_filter, energy_filter]\n",
"tallies.append(back_surface_spectra_tally)"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This section runs the simulation."
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# combine all the required parts to make a model\n",
"model = openmc.model.Model(geom, mats, sett, tallies)\n",
"\n",
"# remove old files and runs OpenMC\n",
"!rm *.h5\n",
"results_filename = model.run()"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This section extracts the cell tally data from the results file and plots neutron flux across the cell."
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# open the results file\n",
"results = openmc.StatePoint(results_filename)\n",
"\n",
"#extracts the tally values from the simulation results\n",
"cell_tally = results.get_tally(name='cell_spectra_tally')\n",
"\n",
"# imports a convenient plotting package\n",
"# imports a convenient plotting package, but you can extract the raw results from cell_tally directly\n",
"from spectrum_plotter import plot_spectrum_from_tally\n",
"\n",
"plot_spectrum_from_tally(\n",
Expand All @@ -222,20 +234,20 @@
" y_label = \"flux [neutrons centimeter / source neutron]\",\n",
" plotting_package=\"plotly\", # matplotlib is another option, but plotly option provides a dropdown menu for changing axis scale\n",
")"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This section extracts the surface tally data from the results file and plots neutron current through the inner and outer surfaces."
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# open the results file\n",
"results = openmc.StatePoint(results_filename)\n",
Expand All @@ -244,11 +256,6 @@
"back_surface_tally = results.get_tally(name='back_surface_spectra_tally')\n",
"front_surface_tally = results.get_tally(name='front_surface_spectra_tally')\n",
"\n",
"# imports a convenient plotting package\n",
"from spectrum_plotter import plot_spectrum_from_tally\n",
"\n",
"# import openmc_post_processor as opp\n",
"# opp.get_tally_units(front_surface_tally)\n",
"\n",
"plot_spectrum_from_tally(\n",
" spectrum={'back_surface_tally': back_surface_tally, 'front_surface_tally':front_surface_tally},\n",
Expand All @@ -257,12 +264,11 @@
" plotting_package=\"plotly\", # matplotlib is another option, but plotly option provides a dropdown menu for changing axis scale\n",
" required_units = 'neutrons / source_particle'\n",
")"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Additional notes\n",
"\n",
Expand All @@ -271,25 +277,24 @@
"- When comparing these results with other codes it might be necessary to scale them:\n",
" - The OpenMC surface current needs to be divided by the surface area when comparing with MCNP.\n",
" - The OpenMC cell flux needs to be divided by the cell volume when comparing with MCNP.\n"
],
"metadata": {}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Learning Outcomes for Part 1:**\n",
"\n",
"- Neutron spectra can be tallied in OpenMC using flux or current tallies, and energy bins.\n",
"- Neutron spectra tend to be different on different surfaces and cells in the geometry."
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"source": [],
"metadata": {},
"outputs": [],
"metadata": {}
"source": []
}
],
"metadata": {
Expand All @@ -316,4 +321,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}

0 comments on commit 4a09a45

Please sign in to comment.