diff --git a/include/openmc/cell.h b/include/openmc/cell.h index 172839295..9e977bc93 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -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; diff --git a/include/openmc/dagmc.h b/include/openmc/dagmc.h index f2cc1ee2a..6a71e6170 100644 --- a/include/openmc/dagmc.h +++ b/include/openmc/dagmc.h @@ -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 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 diff --git a/openmc/geometry.py b/openmc/geometry.py index 13113338a..1ae0015b2 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -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(): diff --git a/openmc/summary.py b/openmc/summary.py index 0af45b770..6e6412061 100644 --- a/openmc/summary.py +++ b/openmc/summary.py @@ -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): diff --git a/openmc/universe.py b/openmc/universe.py index 6f27148ea..bf7481cab 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -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 + `` element + + Returns + ------- + openmc.DAGMCUniverse + DAGMCUniverse instance + + """ id = int(get_text(elem, 'id')) fname = get_text(elem, 'filename') diff --git a/src/cell.cpp b/src/cell.cpp index 4de98aadd..4ae5177fa 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -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) { diff --git a/src/dagmc.cpp b/src/dagmc.cpp index bde33157f..630f665fa 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -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(adjust_geometry_ids_)); + write_attribute(group, "auto_mat_ids", static_cast(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