Skip to content
Open
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
9 changes: 7 additions & 2 deletions docs/source/usersguide/tallies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,13 @@ U238 (separately), we'd set::

tally.nuclides = ['U235', 'U238']

You can also list 'all' as a nuclide which will give you a separate reaction
rate for every nuclide in the model.
To get a separate reaction rate for every nuclide in a material, ask the
material for its nuclides::

tally.nuclides = material.get_nuclides()

Note that these are nuclide names; an element symbol such as 'Al' is not a valid
entry, even for photon tallies, whose data is tabulated per element.

The following tables show all valid scores:

Expand Down
6 changes: 4 additions & 2 deletions src/cross_sections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,10 @@ void read_ce_cross_sections(const vector<vector<double>>& nuc_temps,

const auto& temps = nuc_temps[i_nuc];
int err = openmc_load_nuclide(name.c_str(), temps.data(), temps.size());
if (err < 0)
throw std::runtime_error {get_errmsg()};
if (err < 0) {
// Nothing catches this either, so report it the same way
fatal_error(get_errmsg());
}

already_read.insert(name);
}
Expand Down
9 changes: 7 additions & 2 deletions src/tallies/tally.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,13 @@ void Tally::set_nuclides(const vector<std::string>& nuclides)
auto search = data::nuclide_map.find(nuc);
if (search == data::nuclide_map.end()) {
int err = openmc_load_nuclide(nuc.c_str(), nullptr, 0);
if (err < 0)
throw std::runtime_error {get_errmsg()};
if (err < 0) {
// Nothing catches this, so report it rather than terminating on an
// uncaught exception. Note that a tally bin names a nuclide, so an
// element symbol does not resolve even when the element is present.
fatal_error(fmt::format(
"Could not add nuclide '{}' to a tally: {}", nuc, get_errmsg()));
}
}
nuclides_.push_back(data::nuclide_map.at(nuc));
}
Expand Down
55 changes: 55 additions & 0 deletions tests/unit_tests/test_tally_nuclide_names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""A tally nuclide bin names a nuclide.

Anything else has to be reported rather than terminating on an uncaught
exception, which is what a name the data library cannot resolve used to do.
"""

import openmc
import pytest


def model_with_tally_nuclides(nuclides):
openmc.reset_auto_ids()

mat = openmc.Material()
mat.add_nuclide('U235', 1.0)
mat.set_density('g/cm3', 10.0)

sphere = openmc.Sphere(r=5.0, boundary_type='vacuum')
model = openmc.Model()
model.geometry = openmc.Geometry([openmc.Cell(fill=mat, region=-sphere)])
model.settings.run_mode = 'fixed source'
model.settings.particles = 100
model.settings.batches = 1
model.settings.source = openmc.IndependentSource(space=openmc.stats.Point())

tally = openmc.Tally()
tally.nuclides = nuclides
tally.scores = ['total']
model.tallies = openmc.Tallies([tally])
return model


@pytest.mark.parametrize('name', ['Al', 'U', 'all', 'not-a-nuclide'])
def test_unresolvable_nuclide_is_reported(run_in_tmpdir, name):
"""An element symbol is not a nuclide, and neither is a typo."""
model = model_with_tally_nuclides([name])
with pytest.raises(RuntimeError, match='Could not add nuclide'):
model.run()


def test_element_symbol_of_a_present_element(run_in_tmpdir):
"""Reported even when the element itself is in the material.

The bin is matched against nuclide names, so 'U' does not resolve in a
material made of U235.
"""
model = model_with_tally_nuclides(['U'])
with pytest.raises(RuntimeError, match='Could not add nuclide'):
model.run()


def test_total_and_nuclide_bins_together(run_in_tmpdir):
"""The total bin stays valid alongside real nuclides."""
model = model_with_tally_nuclides(['total', 'U235'])
model.run()
Loading