Skip to content

Commit

Permalink
Merge pull request #23 from fusion-energy/develop
Browse files Browse the repository at this point in the history
reproducing basic plots
  • Loading branch information
shimwell committed Sep 2, 2022
2 parents 1ed7a86 + bcfb99e commit 4c73696
Show file tree
Hide file tree
Showing 15 changed files with 659 additions and 594 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI

on:
pull_request:
branches:
- develop
- main


jobs:
testing:
runs-on: ubuntu-latest
container:
image: openmc/openmc:v0.13.1
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: install package
run: |
pip install .
python -c "import openmc_depletion_plotter"
- name: run examples
run: |
python examples/plot_activity_vs_time.py
python examples/plot_isotope_charts.py
python examples/plot_multiple_isotope_charts.py
python examples/plot_pulse_schedule.py
- name: run tests
run: |
pip install .[tests]
pytest tests -v
57 changes: 55 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,55 @@
# openmc_depletion_plotter
Plot the atoms present during depletion steps on an isotope chart.
Extends OpenMC to provides convienent plotting methods.
This is done by Monkey Patching OpenMC to provide additional functionality to the base classes.
One benefit of this is the user can continue to work with the familiar OpenMC classes and they simply get additional functionality.
Another benefit is that if any of these functions ever become popular enough to include in OpenMC then it could be done with a simple copy paste into the existing class structure.
Plotly figures or MatPlotLib figures are returned for user customization.

# Plotting pulse schedule

All the Integrator classes have been extended to include a ```.plot_pulse_schedule()``` method.

This method plots the source rate as a function of time.

This is useful when wanting to visually display a pulse schedule used in an depletion / activation study.

Additional methods provided

```python
openmc.deplete.PredictorIntegrator.plot_pulse_schedule()
openmc.deplete.CECMIntegrator.plot_pulse_schedule()
openmc.deplete.CF4Integrator.plot_pulse_schedule()
openmc.deplete.CELIIntegrator.plot_pulse_schedule()
openmc.deplete.EPCRK4Integrator.plot_pulse_schedule()
openmc.deplete.LEQIIntegrator.plot_pulse_schedule()
openmc.deplete.SICELIIntegrator.plot_pulse_schedule()
openmc.deplete.SILEQIIntegrator.plot_pulse_schedule()
```

# Plotting activation or atoms as a function of time

The ```openmc.deplete.Results()``` class has been extended to include a ```plot_atoms_vs_time()``` method and a ```plot_activity_vs_time``` method.

These methods plot atoms or activity as a function of time.
These plots optionally include a breakdown of the dominant nuclides.

Additional methods provided

```python
openmc.deplete.Results.plot_atoms_vs_time()
openmc.deplete.Results.plot_activity_vs_time()
```

# Plotting activation or atoms on an isotope chart

The ```openmc.Material()``` class has been extended to include a ```plot_isotope_chart_of_activity()``` method and ```plot_isotope_chart_of_atoms()``` method.

This method plots the material atoms or the material activity on an isotope chart.

I started making isotope plots back in 2010 so nice to finally distribute this :smile:

Additional methods provided

```python
openmc.Material.plot_isotope_chart_of_atoms()
openmc.Material.plot_isotope_chart_of_activity()
```
35 changes: 35 additions & 0 deletions examples/plot_activity_vs_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import openmc
import openmc.deplete
import openmc_depletion_plotter
from pathlib import Path


output_dir = "/home/jshimwell/activation_example/outputs_Aluminum_maintenance"
results = openmc.deplete.Results.from_hdf5(Path(output_dir) / "depletion_results.h5")

# plot = results.plot_activity_vs_time()
# plot.show()
plot = results.plot_atoms_vs_time()
plot.show()


# def load_data(output_dir, time_units="d"):

# results = openmc.deplete.Results.from_hdf5(Path(output_dir) / "depletion_results.h5")
# time_steps = results.get_times(time_units=time_units)

# unirradiated_material = openmc.Summary(str(Path(output_dir) / "summary.h5")).materials[0]

# all_materials = []
# for counter, step in enumerate(time_steps):
# materials = results.export_to_materials(counter)[
# 0
# ] # zero index as one material in problem
# all_materials.append(materials)
# openmc_materials = openmc.Materials(all_materials)

# return openmc_materials, time_steps, unirradiated_material

# openmc_materials, time_steps, unirradiated_material = load_data("/home/jshimwell/activation_example/outputs_Aluminum_maintenance")

# openmc_materials[0].plot_isotope_atom_chart()
26 changes: 26 additions & 0 deletions examples/plot_isotope_charts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import openmc
import openmc_depletion_plotter # adds plotting methods to the material class

my_mat = openmc.Material()
my_mat.add_element("Fe", 1)
my_mat.add_element("Li", 0.5)
my_mat.add_element("Be", 0.5)
my_mat.add_element("Al", 0.5)
my_mat.add_element("B", 0.5)
my_mat.add_element("Co", 0.5)
my_mat.add_element("Cs", 0.5)
my_mat.add_nuclide("Fe60", 0.1)
my_mat.add_nuclide("Fe61", 0.2)
my_mat.add_nuclide("Fe62", 0.3)
my_mat.set_density("g/cm3", 7.7)
my_mat.volume = 1

plotly_figure = my_mat.plot_isotope_chart_of_activity(my_mat)
plotly_figure.write_html("my_mat_activity_on_isotope_chart.html")
plotly_figure.write_image("my_mat_activity_on_isotope_chart.png")
plotly_figure.show()

plotly_figure_2 = my_mat.plot_isotope_chart_of_atoms(my_mat)
plotly_figure_2.write_html("my_mat_atoms_on_isotope_chart.html")
plotly_figure_2.write_image("my_mat_atoms_on_isotope_chart.png")
plotly_figure_2.show()
26 changes: 26 additions & 0 deletions examples/plot_multiple_isotope_charts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import openmc
import openmc_depletion_plotter # adds plotting methods to the material class

my_mat = openmc.Material()
my_mat.add_element("Fe", 1)
my_mat.add_element("Li", 0.5)
my_mat.add_element("Be", 0.5)
my_mat.add_element("Al", 0.5)
my_mat.add_element("B", 0.5)
my_mat.add_element("Co", 0.5)
my_mat.set_density("g/cm3", 7.7)
my_mat.volume = 1

my_mat_2 = openmc.Material()
my_mat_2.add_element("Fe", 1)
my_mat_2.add_element("Li", 0.5)
my_mat_2.add_element("C", 0.5)
my_mat_2.add_element("Al", 0.5)
my_mat_2.add_element("Ni", 0.5)
my_mat_2.add_element("Co", 0.5)
my_mat_2.set_density("g/cm3", 7.7)
my_mat_2.volume = 1

for mat, filename in zip([my_mat, my_mat_2], ["my_mat_1.png", "my_mat_2.png"]):
plotly_figure = mat.plot_isotope_chart_of_atoms()
plotly_figure.write_image(filename)
28 changes: 0 additions & 28 deletions examples/plot_multiple_materials.py

This file was deleted.

22 changes: 10 additions & 12 deletions examples/plot_pulse_schedule.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

import openmc
import openmc.deplete
from openmc_depletion_plotter import IntegratorWithPlotting # class extends openmc depletion classes
import openmc_depletion_plotter
import matplotlib.pyplot as plt


# a minimal material is needed to pass to the model
material = openmc.Material()
material.add_nuclide('Fe59', 1)
material.add_nuclide("Fe59", 1)
material.volume = 100
material.depletable = True
materials = openmc.Materials([material])
Expand All @@ -18,21 +17,20 @@

# a minimal operator is needed to pass to the integrator
operator = openmc.deplete.Operator(
model=model,
chain_file="chain-nndc-b7.1.xml",
normalization_mode="source-rate"
)
model=model, chain_file="chain-nndc-b7.1.xml", normalization_mode="source-rate"
)


# arbitrary lists provided here, but this would be defined by the the pulse schedule (maintenance, waste, single shot)
source_rates = [1e21] + [0] * 24 # single pulse followed by 0 neutrons
time_steps = [1] + [3600] * 24 # one second followed by 1 hour periods for 24 hours
time_steps = [1] + [3600] * 24 # one second followed by 1 hour periods for 24 hours

integrator = IntegratorWithPlotting(
integrator = openmc.deplete.PredictorIntegrator(
operator=operator,
timesteps=time_steps,
source_rates=source_rates,
timestep_units='d',
timestep_units="d",
)
integrator.plot()
plt.savefig('pulse_single_shot.png')
integrator.plot_pulse_schedule()
plt.savefig("pulse_single_shot.png")
plt.show()
22 changes: 0 additions & 22 deletions examples/plot_single_material.py

This file was deleted.

15 changes: 9 additions & 6 deletions openmc_depletion_plotter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

__all__ = ["__version__"]

from .core import plot_isotope_chart_of_atoms
from .core import plot_isotope_chart_of_activity
from .core import plot_activity_vs_time
from .core import plot_specific_activity_vs_time
from .core import plot_atoms_vs_time
# from .core import plot_isotope_chart_of_atoms
# from .core import plot_isotope_chart_of_activity
# from .core import plot_activity_vs_time
# from .core import plot_specific_activity_vs_time
# from .core import plot_atoms_vs_time
from .utils import get_atoms_activity_from_material
from .utils import find_most_abundant_nuclides_in_material
from .utils import find_most_abundant_nuclides_in_materials
Expand All @@ -32,4 +32,7 @@
from .utils import update_axis_range_full_chart
from .utils import add_scale_buttons

from .integrators import IntegratorWithPlotting

from .materials import *
from .integrators import *
from .results import *
Loading

0 comments on commit 4c73696

Please sign in to comment.