Add material density to properties.h5

This commit is contained in:
Paul Romano 2021-06-23 11:39:22 +07:00
parent 482848cadb
commit ef7b43d986
3 changed files with 46 additions and 2 deletions

View file

@ -69,6 +69,14 @@ public:
//! Write material data to HDF5
void to_hdf5(hid_t group) const;
//! Export physical properties to HDF5
//! \param[in] group HDF5 group to write to
void export_properties_hdf5(hid_t group) const;
//! Import physical properties from HDF5
//! \param[in] group HDF5 group to read from
void import_properties_hdf5(hid_t group);
//! Add nuclide to the material
//
//! \param[in] nuclide Name of the nuclide

View file

@ -1053,6 +1053,23 @@ void Material::to_hdf5(hid_t group) const
close_group(material_group);
}
void Material::export_properties_hdf5(hid_t group) const
{
hid_t material_group = create_group(group, "material " + std::to_string(id_));
write_attribute(material_group, "atom_density", density_);
write_attribute(material_group, "mass_density", density_gpcc_);
close_group(material_group);
}
void Material::import_properties_hdf5(hid_t group)
{
hid_t material_group = open_group(group, "material " + std::to_string(id_));
double density;
read_attribute(material_group, "atom_density", density);
this->set_density(density, "atom/b-cm");
close_group(material_group);
}
void Material::add_nuclide(const std::string& name, double density)
{
// Check if nuclide is already in material

View file

@ -152,10 +152,20 @@ extern "C" int openmc_properties_export(const char* filename)
auto geom_group = create_group(file, "geometry");
write_attribute(geom_group, "n_cells", model::cells.size());
auto cells_group = create_group(geom_group, "cells");
for (const auto& c : model::cells) c->export_properties_hdf5(cells_group);
for (const auto& c : model::cells) {
c->export_properties_hdf5(cells_group);
}
close_group(cells_group);
close_group(geom_group);
// Write material properties
hid_t materials_group = create_group(file, "materials");
write_attribute(materials_group, "n_materials", model::materials.size());
for (const auto& mat : model::materials) {
mat->export_properties_hdf5(materials_group);
}
close_group(materials_group);
// Terminate access to the file.
file_close(file);
return 0;
@ -177,10 +187,19 @@ extern "C" int openmc_properties_import(const char* filename)
// Read cell properties
auto geom_group = open_group(file, "geometry");
auto cells_group = open_group(geom_group, "cells");
for (const auto& c : model::cells) c->import_properties_hdf5(cells_group);
for (const auto& c : model::cells) {
c->import_properties_hdf5(cells_group);
}
close_group(cells_group);
close_group(geom_group);
// Read material properties
auto materials_group = open_group(file, "materials");
for (const auto& mat : model::materials) {
mat->import_properties_hdf5(materials_group);
}
close_group(materials_group);
// Terminate access to the file.
file_close(file);
return 0;