From 876bd925a32c75a553a8b65c81b7debf21b59407 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 12 Jul 2021 06:58:04 -0500 Subject: [PATCH] Add check on num cells/materials for Model.import_properties --- openmc/model/model.py | 17 +++++++++++++++-- src/summary.cpp | 1 - 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/openmc/model/model.py b/openmc/model/model.py index 84650767af..ca33a96acd 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -241,16 +241,29 @@ class Model: materials = self.geometry.get_all_materials() with h5py.File(filename, 'r') as fh: - # Update temperatures for cells filled with materials cells_group = fh['geometry/cells'] + + # Make sure number of cells matches + n_cells = fh['geometry'].attrs['n_cells'] + if n_cells != len(cells): + raise ValueError("Number of cells in properties file doesn't " + "match current model.") + + # Update temperatures for cells filled with materials for name, group in cells_group.items(): cell_id = int(name.split()[1]) cell = cells[cell_id] if cell.fill_type in ('material', 'distribmat'): cell.temperature = group['temperature'][()] - # Update material densities + # Make sure number of materials matches mats_group = fh['materials'] + n_cells = mats_group.attrs['n_materials'] + if n_cells != len(materials): + raise ValueError("Number of materials in properties file doesn't " + "match current model.") + + # Update material densities for name, group in mats_group.items(): mat_id = int(name.split()[1]) atom_density = group.attrs['atom_density'] diff --git a/src/summary.cpp b/src/summary.cpp index 64d9a63629..4e6e876ad0 100644 --- a/src/summary.cpp +++ b/src/summary.cpp @@ -163,7 +163,6 @@ extern "C" int openmc_properties_export(const char* filename) write_attribute(file, "date_and_time", time_stamp()); write_attribute(file, "path", settings::path_input); - // Write cell properties auto geom_group = create_group(file, "geometry"); write_attribute(geom_group, "n_cells", model::cells.size());