Add check on num cells/materials for Model.import_properties

This commit is contained in:
Paul Romano 2021-07-12 06:58:04 -05:00
parent 803f17500c
commit 876bd925a3
2 changed files with 15 additions and 3 deletions

View file

@ -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']

View file

@ -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());