Skip to content

Commit

Permalink
Merge pull request #276 from fusion-energy/updating_openmc_source_plo…
Browse files Browse the repository at this point in the history
…tter_api_usage

Update to work with openmc-source-plotter 0.7.0
  • Loading branch information
shimwell authored Mar 8, 2024
2 parents 1911ed0 + 3c9c077 commit 067fed4
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 19 deletions.
2 changes: 0 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ FROM ghcr.io/fusion-energy/neutronics-workshop:base as base
# local image
# FROM neutronics-workshop:base as base

RUN pip install openmc_source_plotter==0.6.6

# Copy over the local repository files
COPY tasks tasks/
COPY tests tests/
Expand Down
25 changes: 19 additions & 6 deletions tasks/task_04_make_sources/1_point_source_plots.ipynb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -28,10 +29,15 @@
"outputs": [],
"source": [
"import openmc\n",
"import openmc_source_plotter # extends the openmc.IndependentSource class to include plotting functions"
"\n",
"# provides simple source plotting functions\n",
"# for more details here is a link to the package repository\n",
"# https://github.com/fusion-energy/openmc_source_plotter\n",
"from openmc_source_plotter import plot_source_energy, plot_source_position, plot_source_direction"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -58,6 +64,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -70,10 +77,11 @@
"metadata": {},
"outputs": [],
"source": [
"my_source.plot_source_energy()"
"plot_source_energy(my_source)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -94,10 +102,11 @@
"# https://docs.openmc.org/en/stable/pythonapi/generated/openmc.data.WattEnergy.html\n",
"my_source_2.energy = openmc.stats.Watt(a=988000.0, b=2.249e-06)\n",
"\n",
"my_source_2.plot_source_energy()"
"plot_source_energy(my_source_2)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -118,10 +127,11 @@
"# https://docs.openmc.org/en/stable/pythonapi/generated/openmc.stats.muir.html\n",
"my_source_3.energy = openmc.stats.muir(e0=14080000.0, m_rat=5.0, kt=20000.0)\n",
"\n",
"my_source_3.plot_source_energy()"
"plot_source_energy(my_source_3)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -140,10 +150,11 @@
"my_source_4.angle = openmc.stats.Isotropic()\n",
"my_source_4.energy = openmc.stats.Discrete([14e6], [1])\n",
"\n",
"my_source_4.plot_source_position()"
"plot_source_position(my_source_4)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -162,10 +173,11 @@
"my_source_5.angle = openmc.stats.Isotropic()\n",
"my_source_5.energy = openmc.stats.Discrete([14e6], [1])\n",
"\n",
"my_source_5.plot_source_direction()"
"plot_source_direction(my_source_5)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -174,6 +186,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down
28 changes: 24 additions & 4 deletions tasks/task_04_make_sources/2_ring_source.ipynb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -10,6 +11,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -25,6 +27,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -42,7 +45,20 @@
"outputs": [],
"source": [
"import openmc\n",
"import openmc_source_plotter # extends the openmc.IndependentSource class to include plotting functions\n",
"\n",
"# provides simple source plotting functions\n",
"# for more details here is a link to the package repository\n",
"# https://github.com/fusion-energy/openmc_source_plotter\n",
"from openmc_source_plotter import plot_source_position\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"# initialises a new source object\n",
"my_source = openmc.IndependentSource()\n",
Expand All @@ -67,6 +83,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -79,10 +96,11 @@
"metadata": {},
"outputs": [],
"source": [
"my_source.plot_source_position()"
"plot_source_position(my_source)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -96,11 +114,13 @@
"outputs": [],
"source": [
"# these plotting methods can also be run if you are interested in energy or direction\n",
"# my_source.plot_source_energy()\n",
"# my_source.plot_source_direction()"
"# they will need importing from the openmc_source_plotter package\n",
"# plot_source_energy(my_source)\n",
"# plot_source_direction(my_source)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down
17 changes: 14 additions & 3 deletions tasks/task_04_make_sources/3_plasma_source_plots.ipynb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -20,10 +21,16 @@
"outputs": [],
"source": [
"import openmc\n",
"import openmc_source_plotter # extends the openmc.IndependentSource class to include plotting functions"
"\n",
"\n",
"# provides simple source plotting functions\n",
"# for more details here is a link to the package repository\n",
"# https://github.com/fusion-energy/openmc_source_plotter\n",
"from openmc_source_plotter import plot_source_direction, plot_source_position"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -61,6 +68,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -85,6 +93,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -97,11 +106,12 @@
"metadata": {},
"outputs": [],
"source": [
"plot = model.plot_source_position(n_samples=2000)\n",
"plot = plot_source_position(this=model, n_samples=2000)\n",
"plot.show()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -114,11 +124,12 @@
"metadata": {},
"outputs": [],
"source": [
"plot = model.plot_source_direction(n_samples=500)\n",
"plot = plot_source_direction(this=model, n_samples=500)\n",
"plot.show()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down
23 changes: 19 additions & 4 deletions tasks/task_04_make_sources/5_gamma_source_example.ipynb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -20,10 +21,17 @@
"outputs": [],
"source": [
"import openmc\n",
"import openmc_source_plotter # extends the openmc.IndependentSource class to include plotting functions"
"\n",
"import numpy as np\n",
"\n",
"# provides simple source plotting functions\n",
"# for more details here is a link to the package repository\n",
"# https://github.com/fusion-energy/openmc_source_plotter\n",
"from openmc_source_plotter import plot_source_energy"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -33,6 +41,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -42,6 +51,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -70,6 +80,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -87,15 +98,18 @@
"# remove any other xml files so that openmc reads the correct xml files\n",
"!rm *.xml\n",
"\n",
"import numpy as np\n",
"\n",
"# number_of_particles can be increased to sample more particles and the histogram resoluton can be changed\n",
"my_source.plot_source_energy(n_samples=1000,energy_bins=np.linspace(0, 2e6, 100))\n",
"plot_source_energy(\n",
" this=my_source,\n",
" n_samples=1000,\n",
" energy_bins=np.linspace(0, 2e6, 100)\n",
")\n",
"\n",
"# this time we are setting the number of energy bins for the plot"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -105,6 +119,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down

0 comments on commit 067fed4

Please sign in to comment.