mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 05:35:49 -04:00
Enhancing to/from hdf5 methods so that DAGMC universes can be reproduced and exported to XML from a summary file.
This commit is contained in:
parent
e2826fa57b
commit
ef70e12142
7 changed files with 70 additions and 15 deletions
|
|
@ -68,7 +68,7 @@ public:
|
|||
|
||||
//! \brief Write universe information to an HDF5 group.
|
||||
//! \param group_id An HDF5 group id.
|
||||
void to_hdf5(hid_t group_id) const;
|
||||
virtual void to_hdf5(hid_t group_id) const;
|
||||
|
||||
virtual bool find_cell(Particle &p) const;
|
||||
|
||||
|
|
|
|||
|
|
@ -122,6 +122,8 @@ public:
|
|||
|
||||
bool find_cell(Particle &p) const override;
|
||||
|
||||
void to_hdf5(hid_t universes_group) const override;
|
||||
|
||||
// Data Members
|
||||
std::shared_ptr<moab::DagMC> dagmc_instance_; //!< DAGMC Instance for this universe
|
||||
int32_t cell_idx_offset_; //!< An offset to the start of the cells in this universe in OpenMC's cell vector
|
||||
|
|
|
|||
|
|
@ -159,6 +159,11 @@ class Geometry:
|
|||
for s1, s2 in periodic.items():
|
||||
surfaces[s1].periodic_surface = surfaces[s2]
|
||||
|
||||
# Add any DAGMC universes
|
||||
for elem in root.findall('dagmc_universe'):
|
||||
dag_univ = openmc.DAGMCUniverse.from_xml(elem)
|
||||
universes[dag_univ.id] = dag_univ
|
||||
|
||||
# Dictionary that maps each universe to a list of cells/lattices that
|
||||
# contain it (needed to determine which universe is the root)
|
||||
child_of = defaultdict(list)
|
||||
|
|
@ -198,11 +203,6 @@ class Geometry:
|
|||
if c.fill_type in ('universe', 'lattice'):
|
||||
child_of[c.fill].append(c)
|
||||
|
||||
# Add any DAGMC universes
|
||||
for elem in root.findall('dagmc_universe'):
|
||||
dag_univ = openmc.DAGMCUniverse.from_xml(elem)
|
||||
universes[dag_univ.id] = dag_univ
|
||||
|
||||
# Determine which universe is the root by finding one which is not a
|
||||
# child of any other object
|
||||
for u in universes.values():
|
||||
|
|
|
|||
|
|
@ -178,7 +178,11 @@ class Summary:
|
|||
|
||||
def _read_universes(self):
|
||||
for group in self._f['geometry/universes'].values():
|
||||
universe = openmc.Universe.from_hdf5(group, self._fast_cells)
|
||||
geom_type = group.get('geom_type')
|
||||
if geom_type and geom_type[()].decode() == 'dagmc':
|
||||
universe = openmc.DAGMCUniverse.from_hdf5(group)
|
||||
else:
|
||||
universe = openmc.Universe.from_hdf5(group, self._fast_cells)
|
||||
self._fast_universes[universe.id] = universe
|
||||
|
||||
def _read_lattices(self):
|
||||
|
|
|
|||
|
|
@ -731,8 +731,47 @@ class DAGMCUniverse(UniverseBase):
|
|||
dagmc_element.set('filename', self.filename)
|
||||
xml_element.append(dagmc_element)
|
||||
|
||||
@classmethod
|
||||
def from_hdf5(cls, group):
|
||||
"""Create DAGMC universe from HDF5 group
|
||||
|
||||
Parameters
|
||||
----------
|
||||
group : h5py.Group
|
||||
Group in HDF5 file
|
||||
|
||||
Returns
|
||||
-------
|
||||
openmc.DAGMCUniverse
|
||||
DAGMCUniverse instance
|
||||
|
||||
"""
|
||||
id = int(group.name.split('/')[-1].lstrip('universe '))
|
||||
fname = group['filename'][()].decode()
|
||||
name = group['name'][()].decode() if 'name' in group else None
|
||||
|
||||
out = cls(fname, universe_id=id, name=name)
|
||||
|
||||
out.auto_geom_ids = bool(group.attrs['auto_geom_ids'])
|
||||
out.auto_mat_ids = bool(group.attrs['auto_mat_ids'])
|
||||
|
||||
return out
|
||||
|
||||
@classmethod
|
||||
def from_xml(cls, elem):
|
||||
"""Generate DAGMC universe from XML element
|
||||
|
||||
Parameters
|
||||
----------
|
||||
elem : xml.etree.ElementTree.Element
|
||||
`<dagmc_universe>` element
|
||||
|
||||
Returns
|
||||
-------
|
||||
openmc.DAGMCUniverse
|
||||
DAGMCUniverse instance
|
||||
|
||||
"""
|
||||
id = int(get_text(elem, 'id'))
|
||||
fname = get_text(elem, 'filename')
|
||||
|
||||
|
|
|
|||
|
|
@ -194,14 +194,7 @@ Universe::to_hdf5(hid_t universes_group) const
|
|||
auto group = create_group(universes_group, fmt::format("universe {}", id_));
|
||||
|
||||
// Write the geometry representation type.
|
||||
switch(geom_type_) {
|
||||
case GeometryType::CSG :
|
||||
write_string(group, "geom_type", "csg", false);
|
||||
break;
|
||||
case GeometryType::DAG :
|
||||
write_string(group, "geom_type", "dagmc", false);
|
||||
break;
|
||||
}
|
||||
write_string(group, "geom_type", "csg", false);
|
||||
|
||||
// Write the contained cells.
|
||||
if (cells_.size() > 0) {
|
||||
|
|
|
|||
|
|
@ -354,6 +354,22 @@ DAGUniverse::find_cell(Particle &p) const {
|
|||
return found;
|
||||
}
|
||||
|
||||
void
|
||||
DAGUniverse::to_hdf5(hid_t universes_group) const {
|
||||
// Create a group for this universe.
|
||||
auto group = create_group(universes_group, fmt::format("universe {}", id_));
|
||||
|
||||
// Write the geometry representation type.
|
||||
write_string(group, "geom_type", "dagmc", false);
|
||||
|
||||
// Write other properties of the DAGMC Universe
|
||||
write_string(group, "filename", filename_, false);
|
||||
write_attribute(group, "auto_geom_ids", static_cast<int>(adjust_geometry_ids_));
|
||||
write_attribute(group, "auto_mat_ids", static_cast<int>(adjust_material_ids_));
|
||||
|
||||
close_group(group);
|
||||
}
|
||||
|
||||
bool
|
||||
DAGUniverse::uses_uwuw() const
|
||||
{
|
||||
|
|
@ -546,6 +562,7 @@ DAGCell::contains(Position r, Direction u, int32_t on_surface) const
|
|||
void
|
||||
DAGCell::to_hdf5_inner(hid_t group_id) const {
|
||||
write_string(group_id, "geom_type", "dagmc", false);
|
||||
|
||||
}
|
||||
|
||||
BoundingBox
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue