Merge pull request #2280 from pshriwise/dagmc-missing-mat

Improve DAGMC messages for missing materials
This commit is contained in:
Paul Romano 2022-11-04 20:12:06 -05:00 committed by GitHub
commit cd843fc351
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View file

@ -486,13 +486,21 @@ void DAGUniverse::legacy_assign_material(
// if no material was set using a name, assign by id
if (!mat_found_by_name) {
bool found_by_id = true;
try {
auto id = std::stoi(mat_string);
if (model::material_map.find(id) == model::material_map.end())
found_by_id = false;
c->material_.emplace_back(id);
} catch (const std::invalid_argument&) {
fatal_error(fmt::format(
"No material '{}' found for volume (cell) {}", mat_string, c->id_));
found_by_id = false;
}
// report failure for failed int conversion or missing material
if (!found_by_id)
fatal_error(
fmt::format("Material with name/ID '{}' not found for volume (cell) {}",
mat_string, c->id_));
}
if (settings::verbosity >= 10) {

View file

@ -11,6 +11,7 @@ pytestmark = pytest.mark.skipif(
@pytest.fixture
def model():
openmc.reset_auto_ids()
model = openmc.model.Model()
@ -56,6 +57,24 @@ def model():
return model
def test_missing_material_id(model):
# remove the last material, which is identified by ID in the DAGMC file
model.materials = model.materials[:-1]
with pytest.raises(RuntimeError) as exec_info:
model.run()
exp_error_msg = "Material with name/ID '41' not found for volume (cell) 3"
assert exp_error_msg in str(exec_info.value)
def test_missing_material_name(model):
# remove the first material, which is identified by name in the DAGMC file
model.materials = model.materials[1:]
with pytest.raises(RuntimeError) as exec_info:
model.run()
exp_error_msg = "Material with name/ID 'no-void fuel' not found for volume (cell) 1"
assert exp_error_msg in str(exec_info.value)
def test_dagmc(model):
harness = PyAPITestHarness('statepoint.5.h5', model)
harness.main()