Skip to content

Commit 4484fd6

Browse files
committed
Add checks during Cell::import_properties_hdf5
1 parent 876bd92 commit 4484fd6

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

‎src/cell.cpp‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,18 @@ void Cell::import_properties_hdf5(hid_t group)
304304
vector<double> temps;
305305
read_dataset(cell_group, "temperature", temps);
306306

307+
// Ensure number of temperatures makes sense
308+
auto n_temps = temps.size();
309+
if (n_temps > 1 && n_temps != n_instances_) {
310+
throw std::runtime_error(fmt::format(
311+
"Number of temperatures for cell {} doesn't match number of instances", id_));
312+
}
313+
307314
// Modify temperatures for the cell
308-
sqrtkT_.resize(0);
309-
sqrtkT_.reserve(temps.size());
310-
for (auto T : temps) {
311-
sqrtkT_.push_back(std::sqrt(K_BOLTZMANN * T));
315+
sqrtkT_.clear();
316+
sqrtkT_.resize(temps.size());
317+
for (gsl::index i = 0; i < temps.size(); ++i) {
318+
this->set_temperature(temps[i], i);
312319
}
313320

314321
close_group(cell_group);

‎src/summary.cpp‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,13 @@ extern "C" int openmc_properties_import(const char* filename)
221221

222222
// Read cell properties
223223
auto cells_group = open_group(geom_group, "cells");
224-
for (const auto& c : model::cells) {
225-
c->import_properties_hdf5(cells_group);
224+
try {
225+
for (const auto& c : model::cells) {
226+
c->import_properties_hdf5(cells_group);
227+
}
228+
} catch (const std::exception& e) {
229+
set_errmsg(e.what());
230+
return OPENMC_E_UNASSIGNED;
226231
}
227232
close_group(cells_group);
228233
close_group(geom_group);

0 commit comments

Comments
 (0)