Skip to content

Commit f7f37cd

Browse files
committed
Read/write densities instead of density multipliers in properties.h5
1 parent 06a113d commit f7f37cd

File tree

5 files changed

+45
-39
lines changed

5 files changed

+45
-39
lines changed

docs/source/io_formats/properties.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ The current version of the properties file format is 1.0.
2525
**/geometry/cells/cell <uid>/**
2626

2727
:Datasets: - **temperature** (*double[]*) -- Temperature of the cell in [K].
28-
- **density_mult** (*double[]*) -- Unitless density multipliers for
29-
the cell. The cell density is equal to the density multiplier
30-
times the density of the material filling the cell.
28+
- **density** (*double[]*) -- Density of the cell in [g/cm3].
3129

3230
**/materials/**
3331

docs/source/io_formats/summary.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ The current version of the summary file format is 6.0.
3838
is an array if the cell uses distributed materials, otherwise it is
3939
a scalar.
4040
- **temperature** (*double[]*) -- Temperature of the cell in Kelvin.
41-
- **density_mult** (*double[]*) -- Unitless density multipliers for the cell.
42-
The cell density is equal to the density multiplier times the density of the
43-
material filling the cell.
41+
- **density** (*double[]*) -- Density of the cell in [g/cm3].
4442
- **translation** (*double[3]*) -- Translation applied to the fill
4543
universe. This dataset is present only if fill_type is set to
4644
'universe'.

openmc/model/model.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -648,19 +648,19 @@ def import_properties(self, filename: PathLike):
648648
else:
649649
lib_cell.set_temperature(temperature[0])
650650

651-
density_mult = group['density_mult'][()]
652-
mat_density = cell.fill.get_mass_density()
653-
if density_mult.size > 1:
654-
cell.density = [mat_density * m for m in density_mult]
655-
else:
656-
cell.density = density_mult * mat_density
657-
if self.is_initialized:
658-
lib_cell = openmc.lib.cells[cell_id]
659-
if density_mult.size > 1:
660-
for i, rho_mult in enumerate(density_mult):
661-
lib_cell.set_density(rho_mult * mat_density, i)
662-
else:
663-
lib_cell.set_density(density_mult[0] * mat_density)
651+
if group['density']:
652+
density = group['density'][()]
653+
if density.size > 1:
654+
cell.density = [rho for rho in density]
655+
else:
656+
cell.density = density
657+
if self.is_initialized:
658+
lib_cell = openmc.lib.cells[cell_id]
659+
if density.size > 1:
660+
for i, rho in enumerate(density):
661+
lib_cell.set_density(rho, i)
662+
else:
663+
lib_cell.set_density(density[0])
664664

665665
# Make sure number of materials matches
666666
mats_group = fh['materials']

src/cell.cpp

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,17 @@ double Cell::density_mult(int32_t instance) const
113113
}
114114

115115
double Cell::density(int32_t instance) const
116-
{
117-
const int32_t mat_index = material(instance);
118-
if (mat_index == MATERIAL_VOID)
119-
return 0.0;
120116

121-
if (instance >= 0) {
122-
double rho =
123-
rho_mult_.size() == 1 ? rho_mult_.at(0) : rho_mult_.at(instance);
124-
return rho * model::materials[mat_index]->density_gpcc();
125-
} else {
126-
return rho_mult_[0];
127-
}
117+
const int32_t mat_index = material(instance);
118+
if (mat_index == MATERIAL_VOID)
119+
return 0.0;
120+
121+
if (instance >= 0) {
122+
double rho = rho_mult_.size() == 1 ? rho_mult_.at(0) : rho_mult_.at(instance);
123+
return rho * model::materials[mat_index]->density_gpcc();
124+
} else {
125+
return rho_mult_[0] * model::materials[mat_index]->density_gpcc();
126+
}
128127
}
129128

130129
void Cell::set_temperature(double T, int32_t instance, bool set_contained)
@@ -229,8 +228,14 @@ void Cell::export_properties_hdf5(hid_t group) const
229228
temps.push_back(sqrtkT_val * sqrtkT_val / K_BOLTZMANN);
230229
write_dataset(cell_group, "temperature", temps);
231230

232-
// Write density multipliers for one or more cell instances
233-
write_dataset(cell_group, "density_mult", rho_mult_);
231+
// Write density for one or more cell instances
232+
if (type_ == Fill::MATERIAL && material_.size() > 0) {
233+
vector<double> rho;
234+
for (int32_t i = 0; i < rho_mult_.size(); ++i)
235+
rho.push_back(density(i));
236+
237+
write_dataset(cell_group, "density", rho);
238+
}
234239

235240
close_group(cell_group);
236241
}
@@ -258,17 +263,22 @@ void Cell::import_properties_hdf5(hid_t group)
258263
this->set_temperature(temps[i], i);
259264
}
260265

261-
// Read density multipliers
262-
if (object_exists(cell_group, "density_mult")) {
263-
read_dataset(cell_group, "density_mult", rho_mult_);
266+
// Read densities
267+
if (object_exists(cell_group, "density")) {
268+
vector<double> rho;
269+
read_dataset(cell_group, "density", rho);
264270

265-
// Ensure number of density multipliers makes sense
266-
auto n_rho = rho_mult_.size();
271+
// Ensure number of densities makes sense
272+
auto n_rho = rho.size();
267273
if (n_rho > 1 && n_rho != n_instances()) {
268-
fatal_error(fmt::format("Number of density multipliers for cell {} "
274+
fatal_error(fmt::format("Number of densities for cell {} "
269275
"doesn't match number of instances",
270276
id_));
271277
}
278+
279+
// Set densities.
280+
for (int32_t i = 0; i < n_rho; ++i)
281+
set_density(rho[i], i);
272282
}
273283

274284
close_group(cell_group);

tests/unit_tests/test_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ def test_import_properties(run_in_tmpdir, mpi_intracomm):
254254
# Change cell fuel temperature, density, material density and export properties
255255
cell = openmc.lib.cells[1]
256256
cell.set_temperature(600.0)
257-
cell.set_density(10.0)
258257
cell.fill.set_density(5.0, 'g/cm3')
258+
cell.set_density(10.0)
259259
openmc.lib.export_properties(output=False)
260260

261261
# Import properties to existing model

0 commit comments

Comments
 (0)