Skip to content

added openmc.Material.mean_free_path function #3469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions openmc/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,36 @@ def from_xml_element(cls, elem: ET.Element) -> Material:
return mat


def mean_free_path(self, energy: float) -> float:
"""Calculate the mean free path of neutrons in the material at a given
energy.

.. versionadded:: 0.15.3

Parameters
----------
energy : float
Neutron energy in eV

Returns
-------
float
Mean free path in cm

"""
from openmc.plotter import _calculate_cexs_elem_mat

energy_grid, cexs = _calculate_cexs_elem_mat(
this=self,
types=["total"],
)
total_cexs = cexs[0]

interpolated_cexs = float(np.interp(energy, energy_grid, total_cexs))

return 1.0 / interpolated_cexs


class Materials(cv.CheckedList):
"""Collection of Materials used for an OpenMC simulation.

Expand Down
13 changes: 13 additions & 0 deletions tests/unit_tests/test_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,3 +710,16 @@ def test_avoid_subnormal(run_in_tmpdir):
# When read back in, the density should be zero
mats = openmc.Materials.from_xml()
assert mats[0].get_nuclide_atom_densities()['H2'] == 0.0


def test_mean_free_path():

mat1 = openmc.Material()
mat1.add_nuclide('Si28', 1.0)
mat1.set_density('g/cm3', 2.32)
assert mat1.mean_free_path(energy=14e6) == pytest.approx(11.41, abs=1e-2)

mat2 = openmc.Material()
mat2.add_nuclide('Pb208', 1.0)
mat2.set_density('g/cm3', 11.34)
assert mat2.mean_free_path(energy=14e6) == pytest.approx(5.65, abs=1e-2)