Skip to content

Commit

Permalink
Merge pull request #45 from fusion-energy/develop
Browse files Browse the repository at this point in the history
Adding heating-local and tests for new feature
  • Loading branch information
shimwell authored Jan 23, 2022
2 parents 15fb69a + 7afdcfa commit 3f53a6e
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_with_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: |
python tests/create_statepoint_file_for_testing.py --batches 2 --particles 100
python tests/create_statepoint_file_for_testing.py --batches 1 --particles 100
pytest tests/ -v --cov=openmc_tally_unit_converter --cov-append --cov-report term --cov-report xml
pytest tests -v --cov=openmc_tally_unit_converter --cov-append --cov-report term --cov-report xml
- name: Run examples
run: |
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ OpenMC tally results are save into a statepoint h5 file without units.
This package ascertains the base units of common tallies by inspecting their
tally filters and scores.

The following worked example is for a heating tally. Flux, effective dose and
DPA / damage-energy tallies are also supported.
The following worked example is for a heating tally. Other supported tallies
are heating-local, flux, effective dose and damage-energy (used to find DPA)
tallies are also supported.

```python
import openmc_tally_unit_converter as otuc
Expand Down
4 changes: 2 additions & 2 deletions examples/processing_2d_mesh_heating_tally.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@


# returns the tally with base units
result = otuc.get_tally_units(
result, error = otuc.process_tally(
tally=my_tally,
)
# the tally result with base units which should be eV per simulated particle
print(f"The base tally units for this heating tally are {result}")
print(f"The base tally units for this heating tally are {result.units} \n")


# scaled from picosievert to sievert
Expand Down
4 changes: 2 additions & 2 deletions examples/processing_3d_mesh_heating_tally.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@


# returns the tally with base units
result = otuc.get_tally_units(
result, error = otuc.process_tally(
tally=my_tally,
)
# the tally result with base units which should be eV per simulated particle
print(f"The base tally units for this heating tally are {result}")
print(f"The base tally units for this heating tally are {result.units}\n")

# this finds the number of neutrons emitted per second by a 1GW fusion DT plasma
source_strength = otuc.find_source_strength(
Expand Down
11 changes: 9 additions & 2 deletions openmc_tally_unit_converter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ def scale_tally(


def compute_volume_of_voxels(tally):
"""Finds the volume of the rectangular voxels that make up a Regular mesh
tally."""
if tally.contains_filter(openmc.MeshFilter):
tally_filter = tally.find_filter(filter_type=openmc.MeshFilter)

Expand Down Expand Up @@ -578,7 +580,8 @@ def check_for_energy_function_filter(tally):


def get_score_units(tally):
""" """
"""Finds the tally score from the supported scores. Then finds the units
that the score results in"""

if tally.scores == ["current"]:
units = get_particles_from_tally_filters(tally, ureg)
Expand All @@ -594,6 +597,10 @@ def get_score_units(tally):
# heating units are eV / source_particle
units = ureg.electron_volt / ureg.source_particle

elif tally.scores == ["heating-local"]:
# heating-local units are eV / source_particle
units = ureg.electron_volt / ureg.source_particle

elif tally.scores == ["damage-energy"]:
# damage-energy units are eV / source_particle
units = ureg.electron_volt / ureg.source_particle
Expand All @@ -602,7 +609,7 @@ def get_score_units(tally):
msg = (
"units for tally can't be found. Tallies that are supported "
"by get_score_units function are those with scores of current, "
"flux, heating, damage-energy"
"flux, heating, heating-local, damage-energy"
)
raise ValueError(msg)

Expand Down
14 changes: 10 additions & 4 deletions tests/create_statepoint_file_for_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,20 @@
target=2,
)

tally15 = odw.MeshTally2D(
tally15 = odw.CellTally(
tally_type="heating-local",
target=2,
)

tally16 = odw.MeshTally2D(
tally_type="neutron_effective_dose",
plane="xy",
mesh_resolution=(10, 5),
mesh_resolution=(2, 3),
bounding_box=[(-500, -500, 0), (500, 500, 1)],
)

tally16 = odw.MeshTally3D(
mesh_resolution=(500, 500, 500),
tally17 = odw.MeshTally3D(
mesh_resolution=(2, 3, 4),
bounding_box=[(-500, -500, 0), (500, 500, 1)],
tally_type="neutron_effective_dose",
)
Expand All @@ -163,6 +168,7 @@
tally14,
tally15,
tally16,
tally17,
]
)

Expand Down
10 changes: 8 additions & 2 deletions tests/create_statepoint_file_for_testing_using_dagmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,19 @@
target=1,
)

tally15 = odw.MeshTally2D(
tally15 = odw.CellTally(
tally_type="heating-local",
target=2,
)

tally16 = odw.MeshTally2D(
tally_type="neutron_effective_dose",
plane="xy",
mesh_resolution=(10, 5),
bounding_box=[(-500, -500, 0), (500, 500, 1)],
)

tally16 = odw.MeshTally3D(
tally17 = odw.MeshTally3D(
mesh_resolution=(500, 500, 500),
bounding_box=[(-500, -500, 0), (500, 500, 1)],
tally_type="neutron_effective_dose",
Expand All @@ -137,6 +142,7 @@
tally14,
tally15,
tally16,
tally17,
]
)

Expand Down
145 changes: 78 additions & 67 deletions tests/test_cell_heating.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,44 @@ def setUp(self):

# loads in the statepoint file containing tallies
statepoint = openmc.StatePoint(filepath="statepoint.2.h5")
self.my_tally = statepoint.get_tally(name="2_heating")
self.my_tally_heat = statepoint.get_tally(name="2_heating")
self.my_tally_heat_local = statepoint.get_tally(name="2_heating-local")

def test_cell_tally_heating_base_units(self):
# returns the tally with base units
result = otuc.process_tally(tally=self.my_tally)

assert len(result) == 2
assert result[0].units == "electron_volt / source_particle"
assert result[1].units == "electron_volt / source_particle"
assert isinstance(result[0][0].magnitude, float)
assert isinstance(result[1][0].magnitude, float)
for my_tally in [self.my_tally_heat, self.my_tally_heat_local]:
# returns the tally with base units
result = otuc.process_tally(tally=my_tally)

assert len(result) == 2
assert result[0].units == "electron_volt / source_particle"
assert result[1].units == "electron_volt / source_particle"
assert isinstance(result[0][0].magnitude, float)
assert isinstance(result[1][0].magnitude, float)

def test_cell_tally_heating_no_processing(self):
# returns the tally with base units
result = otuc.process_tally(
tally=self.my_tally, required_units="eV / source_particle"
)

assert len(result) == 2
assert result[0].units == "electron_volt / source_particle"
assert result[1].units == "electron_volt / source_particle"
assert isinstance(result[0][0].magnitude, float)
assert isinstance(result[1][0].magnitude, float)
for my_tally in [self.my_tally_heat, self.my_tally_heat_local]:
# returns the tally with base units
result = otuc.process_tally(
tally=my_tally, required_units="eV / source_particle"
)

assert len(result) == 2
assert result[0].units == "electron_volt / source_particle"
assert result[1].units == "electron_volt / source_particle"
assert isinstance(result[0][0].magnitude, float)
assert isinstance(result[1][0].magnitude, float)

def test_cell_tally_heating_fusion_power_processing(self):

# returns the tally with scalled based units (MeV instead of eV)
result = otuc.process_tally(
source_strength=4.6e17, # neutrons per 1.3MJ pulse
tally=self.my_tally,
required_units="eV / second",
)
for my_tally in [self.my_tally_heat, self.my_tally_heat_local]:
# returns the tally with scalled based units (MeV instead of eV)
result = otuc.process_tally(
source_strength=4.6e17, # neutrons per 1.3MJ pulse
tally=my_tally,
required_units="eV / second",
)

assert len(result) == 2
assert result[0].units == "electron_volt / second"
Expand All @@ -51,66 +57,71 @@ def test_cell_tally_heating_fusion_power_processing(self):

def test_cell_tally_heating_pulse_processing(self):

# returns the tally with scalled based units (MeV instead of eV)
result = otuc.process_tally(
source_strength=4.6e17, # neutrons per 1.3MJ pulse
tally=self.my_tally,
required_units="eV / pulse",
)
for my_tally in [self.my_tally_heat, self.my_tally_heat_local]:
# returns the tally with scaled based units (MeV instead of eV)
result = otuc.process_tally(
source_strength=4.6e17, # neutrons per 1.3MJ pulse
tally=my_tally,
required_units="eV / pulse",
)

assert len(result) == 2
assert result[0].units == "electron_volt / pulse"
assert result[1].units == "electron_volt / pulse"
assert len(result) == 2
assert result[0].units == "electron_volt / pulse"
assert result[1].units == "electron_volt / pulse"

def test_cell_tally_heating_pulse_processing_and_scaling(self):

# returns the tally with scalled based units (MeV instead of eV)
result = otuc.process_tally(
source_strength=4.6e17, # neutrons per 1.3MJ pulse
tally=self.my_tally,
required_units="MeV / pulse",
)
for my_tally in [self.my_tally_heat, self.my_tally_heat_local]:
# returns the tally with scaled based units (MeV instead of eV)
result = otuc.process_tally(
source_strength=4.6e17, # neutrons per 1.3MJ pulse
tally=my_tally,
required_units="MeV / pulse",
)

assert len(result) == 2
assert result[0].units == "megaelectron_volt / pulse"
assert result[1].units == "megaelectron_volt / pulse"
assert len(result) == 2
assert result[0].units == "megaelectron_volt / pulse"
assert result[1].units == "megaelectron_volt / pulse"

def test_cell_tally_heating_fusion_power_processing_and_scaling(self):

# returns the tally with scalled based units (MeV instead of eV)
result = otuc.process_tally(
source_strength=4.6e17, # neutrons per 1.3MJ pulse
tally=self.my_tally,
required_units="MeV / second",
)
for my_tally in [self.my_tally_heat, self.my_tally_heat_local]:
# returns the tally with scalled based units (MeV instead of eV)
result = otuc.process_tally(
source_strength=4.6e17, # neutrons per 1.3MJ pulse
tally=my_tally,
required_units="MeV / second",
)

assert len(result) == 2
assert result[0].units == "megaelectron_volt / second"
assert result[1].units == "megaelectron_volt / second"
assert len(result) == 2
assert result[0].units == "megaelectron_volt / second"
assert result[1].units == "megaelectron_volt / second"

def test_cell_tally_heating_fusion_power_processing_and_conversion(self):

# returns the tally with normalisation per pulse and conversion to joules
result = otuc.process_tally(
source_strength=1.3e6, tally=self.my_tally, required_units="joule / second"
)
for my_tally in [self.my_tally_heat, self.my_tally_heat_local]:
# returns the tally with normalisation per pulse and conversion to joules
result = otuc.process_tally(
source_strength=1.3e6, tally=my_tally, required_units="joule / second"
)

assert len(result) == 2
assert result[0].units == "joule / second"
assert result[1].units == "joule / second"
assert len(result) == 2
assert result[0].units == "joule / second"
assert result[1].units == "joule / second"

def test_cell_tally_heating_pulse_processing_and_conversion(self):

# returns the tally with normalisation per pulse and conversion to joules
result = otuc.process_tally(
source_strength=1.3e6,
tally=self.my_tally,
required_units="joules / pulse", # joules or joule can be requested
)

assert len(result) == 2
assert result[0].units == "joule / pulse"
assert result[1].units == "joule / pulse"
for my_tally in [self.my_tally_heat, self.my_tally_heat_local]:
# returns the tally with normalisation per pulse and conversion to joules
result = otuc.process_tally(
source_strength=1.3e6,
tally=my_tally,
required_units="joules / pulse", # joules or joule can be requested
)

assert len(result) == 2
assert result[0].units == "joule / pulse"
assert result[1].units == "joule / pulse"


if __name__ == "__main__":
Expand Down

0 comments on commit 3f53a6e

Please sign in to comment.