Skip to content

Commit 6e003c2

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

File tree

5 files changed

+39
-29
lines changed

5 files changed

+39
-29
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: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ double Cell::density_mult(int32_t instance) const
114114

115115
double Cell::density(int32_t instance) const
116116
{
117+
if (instance >= material_.size() && material_.size() != 1)
118+
fatal_error(fmt::format("Instances and materials don't match! {} {}", instance, material_.size()));
119+
117120
const int32_t mat_index = material(instance);
118121
if (mat_index == MATERIAL_VOID)
119122
return 0.0;
@@ -123,7 +126,7 @@ double Cell::density(int32_t instance) const
123126
rho_mult_.size() == 1 ? rho_mult_.at(0) : rho_mult_.at(instance);
124127
return rho * model::materials[mat_index]->density_gpcc();
125128
} else {
126-
return rho_mult_[0];
129+
return rho_mult_[0] * model::materials[mat_index]->density_gpcc();
127130
}
128131
}
129132

@@ -229,8 +232,14 @@ void Cell::export_properties_hdf5(hid_t group) const
229232
temps.push_back(sqrtkT_val * sqrtkT_val / K_BOLTZMANN);
230233
write_dataset(cell_group, "temperature", temps);
231234

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

235244
close_group(cell_group);
236245
}
@@ -258,17 +267,22 @@ void Cell::import_properties_hdf5(hid_t group)
258267
this->set_temperature(temps[i], i);
259268
}
260269

261-
// Read density multipliers
262-
if (object_exists(cell_group, "density_mult")) {
263-
read_dataset(cell_group, "density_mult", rho_mult_);
270+
// Read densities
271+
if (object_exists(cell_group, "density")) {
272+
vector<double> rho;
273+
read_dataset(cell_group, "density", rho);
264274

265-
// Ensure number of density multipliers makes sense
266-
auto n_rho = rho_mult_.size();
275+
// Ensure number of densities makes sense
276+
auto n_rho = rho.size();
267277
if (n_rho > 1 && n_rho != n_instances()) {
268-
fatal_error(fmt::format("Number of density multipliers for cell {} "
278+
fatal_error(fmt::format("Number of densities for cell {} "
269279
"doesn't match number of instances",
270280
id_));
271281
}
282+
283+
// Set densities.
284+
for (int32_t i = 0; i < n_rho; ++i)
285+
set_density(rho[i], i);
272286
}
273287

274288
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)