Skip to content

Commit

Permalink
Merge pull request #11 from fusion-energy/develop
Browse files Browse the repository at this point in the history
removing class usage and moving to functions
  • Loading branch information
shimwell authored Oct 20, 2021
2 parents 87da9cf + 38e55aa commit fa3d0b5
Show file tree
Hide file tree
Showing 18 changed files with 341 additions and 301 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci_with_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,15 @@ jobs:
python tests/create_statepoint_file_for_testing.py
pytest tests/ -v --cov=openmc_post_processor --cov-append --cov-report term --cov-report xml
- name: Run examples
run: |
cd examples
python processing_2d_mesh_effective_dose_tally.py
python processing_cell_effective_dose_tally.py
python processing_cell_flux_tally.py
python processing_cell_heating_tally.py
python processing_cell_spectra_tally.py
python processing_mutliple_cell_spectra_tally.py
- name: Upload to codecov
uses: codecov/codecov-action@v2
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,5 @@ dmypy.json
*.out
*.stl
*.xml
*.vscode/
*.vscode/
*.png
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@

This Python package aims to help convert OpenMC tallies to user specified units.

OpenMC tallies are recorded save saved without units.
OpenMC tally results are save into at statepoint.h5 file without units.

This package ascertains the units of common tallies using the tally filters and scores.

The Pint Python package to scale the base tally units to different units. For example Pint can easily convert cm to meters or electron volts to joules.
The package then allows users to scale the base tally units to different units. For example the package can easily convert cm to meters or electron volts to joules.

Additional inputs can be applied to normalise the the tallies by the source strength of the source. For example if ```neutrons_per_second``` is provided then tallies can be scaled and the base units of tallies can be converted to more user friendly units. For example heating tallies are recorded in electron volts per source particle. However this can be converted to Watt.
Additional inputs can be applied to normalise the the tallies. by the source strength of the source. For example if ```strength_strength``` is provided then tallies can converted from the base units to user friendly units. For example heating tallies are recorded in electron volts per source particle. However this can be converted to Watts.

Scaling by the volume of the cell or mesh is also possible by ```volume``` and requesting units that require normalising with volume. Follow on from the previous example with would allow converion of heating tallies in thier base units of electron volts per source particle to be converted to Watts per cm3.

:point_right: [Examples](https://github.com/fusion-energy/openmc_post_processor/tree/main/examples)
56 changes: 10 additions & 46 deletions examples/processing_2d_mesh_effective_dose_tally.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,24 @@
import openmc
import openmc_post_processor as opp
from regular_mesh_plotter import plot_mesh, plot_stl_slice, plot_mesh_tally
from matplotlib.colors import LogNorm


# loads in the statepoint file containing tallies
statepoint = opp.StatePoint(filepath="statepoint.2.h5")
statepoint = openmc.StatePoint(filepath="statepoint.2.h5")
my_tally = statepoint.get_tally(name="neutron_effective_dose_on_2D_mesh_xy")


# returns the tally with base units
result = statepoint.process_tally(
result = opp.process_dose_tally(
tally=my_tally,
)
# the tally result with required units
print(result)

# opp.plot_2d_mesh_tally(result, "unprocessed_image.png")

# scaled from picosievert to sievert
result = statepoint.process_tally(
tally=my_tally, required_units="sievert cm **2 / simulated_particle"
)

# opp.plot_2d_mesh_tally(result, "scaled_image.png")

result = statepoint.process_tally(
source_strength=1.3e6, tally=my_tally, required_units="sievert cm **2 / pulse"
)
# opp.plot_2d_mesh_tally(result, "scaled_per_pulse_image.png")


result = statepoint.process_tally(
source_strength=1.3e6,
result = opp.process_dose_tally(
tally=my_tally,
required_units="picosievert / cm / pulse",
required_units="sievert cm **2 / simulated_particle"
)


stl_slice = plot_stl_slice(
stl_or_mesh='steel.stl',
plane_origin = None,
plane_normal = [0, 0, 1],
rotate_plot = 0,
filename='slice.png'
)


plot_mesh(
# extent=[-200,200, -200,200],
values= result,
scale=None, # LogNorm(),
vmin=None,
label="picosievert / cm / pulse",
base_plt=stl_slice,
filename= 'test.png',
# vmin=1e6,
)

mesh_filter = plot_mesh_tally(my_tally)

# print(result)
# print(result.shape)
# the tally result with required units
print(result)
31 changes: 6 additions & 25 deletions examples/processing_cell_effective_dose_tally.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,34 @@
import openmc
import openmc_post_processor as opp


# loads in the statepoint file containing tallies
statepoint = opp.StatePoint(filepath="statepoint.2.h5")
statepoint = openmc.StatePoint(filepath="statepoint.2.h5")

# gets one tally from the available tallies
my_tally = statepoint.get_tally(name="2_neutron_effective_dose")


# returns the tally with base units
result = statepoint.process_tally(tally=my_tally)
result = opp.process_dose_tally(tally=my_tally)
print(f"effective dose base units = {result}", end="\n\n")


# returns the tally with scalled based units (MeV instead of eV)
result = statepoint.process_tally(
result = opp.process_dose_tally(
tally=my_tally, required_units="sievert cm **2 / simulated_particle"
)
print(f"effective dose scaled base units = {result}", end="\n\n")


# returns the tally with normalisation per pulse
result = statepoint.process_tally(
result = opp.process_dose_tally(
source_strength=1.3e6, tally=my_tally, required_units="sievert cm **2 / pulse"
)
print(f"effective dose per pulse = {result}", end="\n\n")


# returns the tally with normalisation for source strength
statepoint.process_tally(
opp.process_dose_tally(
source_strength=1.3e6, tally=my_tally, required_units="Sv cm **2 / second"
)
print(f"effective dose per second = {result}", end="\n\n")


# # returns the tally with normalisation per pulse and conversion to joules
# result = statepoint.process_tally(
# source_strength=1e9,
# volume=100,
# tally=my_tally,
# required_units='joules / pulse'
# )
# print(f'effective dose per pulse = {result}', end='\n\n')


# # returns the tally with normalisation for source strength and conversion to joules
# result = statepoint.process_tally(
# fusion_power=1e9,
# tally=my_tally,
# required_units='joules / second'
# )
# print(f'effective dose per second = {result}', end='\n\n')
15 changes: 8 additions & 7 deletions examples/processing_cell_flux_tally.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import openmc_post_processor as opp
import openmc

# loads in the statepoint file containing tallies
statepoint = opp.StatePoint(filepath="statepoint.2.h5")
statepoint = openmc.StatePoint(filepath="statepoint.2.h5")

# gets one tally from the available tallies
my_tally = statepoint.get_tally(name="2_flux")
Expand All @@ -11,19 +12,19 @@
print(opp.find_source_strength(fusion_energy_per_second_or_per_pulse=1.3e6))

# returns the tally with base units
result = statepoint.process_tally(tally=my_tally)
result = opp.process_tally(tally=my_tally)
print(f"flux base units = {result}", end="\n\n")


# returns the tally with scalled based units (m instead of cm)
result = statepoint.process_tally(
result = opp.process_tally(
tally=my_tally, required_units="meter / simulated_particle"
)
print(f"flux scaled base units = {result}", end="\n\n")


# returns the tally with normalisation per pulse
result = statepoint.process_tally(
result = opp.process_tally(
source_strength=4.6e17, # neutrons per 1.3MJ pulse
tally=my_tally,
required_units="centimeter / pulse",
Expand All @@ -32,23 +33,23 @@


# returns the tally with normalisation for source strength
result = statepoint.process_tally(
result = opp.process_tally(
source_strength=5, # neutrons per second 1e9Gw
tally=my_tally,
required_units="centimeter / second",
)
print(f"flux per second = {result}", end="\n\n")

# returns the tally with normalisation for source strength
result = statepoint.process_tally(
result = opp.process_tally(
source_strength=5, # neutrons per 1.3MJ pulse
tally=my_tally,
required_units="centimeter / pulse",
)
print(f"flux per pulse = {result}", end="\n\n")

# returns the tally with normalisation for volume
result = statepoint.process_tally(
result = opp.process_tally(
volume=100,
tally=my_tally,
required_units="1 / centimeter ** 2",
Expand Down
16 changes: 8 additions & 8 deletions examples/processing_cell_heating_tally.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
import openmc_post_processor as opp

import openmc

# loads in the statepoint file containing tallies
statepoint = opp.StatePoint(filepath="statepoint.2.h5")
statepoint = openmc.StatePoint(filepath="statepoint.2.h5")

# gets one tally from the available tallies
my_tally = statepoint.get_tally(name="2_heating")


# returns the tally with base units
result = statepoint.process_tally(tally=my_tally)
result = opp.process_tally(tally=my_tally)
print(f"heating base units = {result}", end="\n\n")


# returns the tally with scalled based units (MeV instead of eV)
result = statepoint.process_tally(tally=my_tally, required_units="MeV / simulated_particle")
result = opp.process_tally(tally=my_tally, required_units="MeV / simulated_particle")
print(f"heating scalled base units = {result}", end="\n\n")


# returns the tally with normalisation per pulse
result = statepoint.process_tally(
result = opp.process_tally(
source_strength=1.3e6, tally=my_tally, required_units="MeV / pulse"
)
print(f"heating per pulse = {result}", end="\n\n")


# returns the tally with normalisation for source strength
statepoint.process_tally(source_strength=1e9, tally=my_tally, required_units="MeV / second")
opp.process_tally(source_strength=1e9, tally=my_tally, required_units="MeV / second")
print(f"heating per second = {result}", end="\n\n")


# returns the tally with normalisation per pulse and conversion to joules
result = statepoint.process_tally(
result = opp.process_tally(
source_strength=1.3e6, tally=my_tally, required_units="joules / pulse"
)
print(f"heating per pulse = {result}", end="\n\n")


# returns the tally with normalisation for source strength and conversion to joules
result = statepoint.process_tally(
result = opp.process_tally(
source_strength=1e9, tally=my_tally, required_units="joules / second"
)
print(f"heating per second = {result}", end="\n\n")
21 changes: 6 additions & 15 deletions examples/processing_cell_spectra_tally.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,32 @@
import openmc
import openmc_post_processor as opp
from spectrum_plotter import plot_spectrum # a convenient plotting package


# loads in the statepoint file containing tallies
statepoint = opp.StatePoint(filepath="statepoint.2.h5")
statepoint = openmc.StatePoint(filepath="statepoint.2.h5")

# gets one tally from the available tallies
my_tally = statepoint.get_tally(name="2_neutron_spectra")


# returns the tally with base units
result = statepoint.process_tally(
result = opp.process_spectra_tally(
tally=my_tally,
)
print(f"spectra with base units = {result}", end="\n\n")


# returns the tally with normalisation per pulse
result = statepoint.process_tally(
result = opp.process_spectra_tally(
tally=my_tally, required_units=["eV", "centimeter / pulse"], source_strength=1.3e6
)
print(f"spectra per pulse = {result}", end="\n\n")


# returns the tally scalled and normalisation for source strength
print(f"spectra per second = {result}", end="\n\n")
result = statepoint.process_tally(
result = opp.process_spectra_tally(
tally=my_tally, required_units=["MeV", "centimeter / second"], source_strength=1e9
)
print(f"spectra per pulse = {result}", end="\n\n")

# plots a graph of the results
plot_spectrum(
spectrum={"legend": (result[0], result[1])},
x_label="Energy [MeV]",
y_label="neutron flux [centimeter / second]",
x_scale="log",
y_scale="log",
# trim_zeros=False,
filename="step_line_graph.png",
)
1 change: 1 addition & 0 deletions examples/run_all.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
python processing_2d_mesh_effective_dose_tally.py
python processing_cell_effective_dose_tally.py
python processing_cell_flux_tally.py
python processing_cell_heating_tally.py
Expand Down
8 changes: 6 additions & 2 deletions openmc_post_processor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
get_tally_units,
check_for_dimentionality_difference,
find_source_strength,
compute_volume_of_voxels
compute_volume_of_voxels,
process_tally,
process_dose_tally,
process_spectra_tally,
convert_units,
scale_tally
)
from .core import StatePoint
Loading

0 comments on commit fa3d0b5

Please sign in to comment.