From 8cdbedf6743f156ad1c22ac14c2426c00b3d4236 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 28 Nov 2019 09:06:35 -0600 Subject: [PATCH] Can read unstructured mesh from statepoint now. --- openmc/mesh.py | 24 ++++++++++++++++++++++-- src/mesh.cpp | 5 ++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/openmc/mesh.py b/openmc/mesh.py index ef46695f5f..41d6beae4e 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -605,8 +605,12 @@ class UnstructuredMesh(MeshBase): Unique identifier for the mesh name : str Name of the mesh - filename : str + mesh_file : str Name of the file containing the unstructured mesh + volumes : Iterable of float + Volumes of the unstructured mesh elements + total_volume : float + Volume of the unstructured mesh in total """ def __init__(self, mesh_id=None, name='', filename=''): @@ -626,6 +630,19 @@ class UnstructuredMesh(MeshBase): else: self.filename = '' + @property + def volumes(self): + return self._volumes + + @volumes.setter + def volumes(self, volumes): + cv.check_type("Unstructured mesh volumes", volumes, Iterable, Real) + self._volumes = volumes + + @property + def total_volume(self): + return np.sum(self.volumes) + def __repr__(self): string = super().__repr__() string += '{0: <16}{1}{2}\n'.format('\tFilename', '=\t', self.filename) @@ -636,7 +653,10 @@ class UnstructuredMesh(MeshBase): mesh_id = int(group.name.split('/')[-1].lstrip('mesh ')) mesh = cls(mesh_id) - mesh = group['filename'] + mesh.filename = group['filename'][()].decode() + mesh.volumes = group['volumes'][()] + + return mesh def to_xml_element(self): """Return XML representation of the mesh diff --git a/src/mesh.cpp b/src/mesh.cpp index d3c32cd5cb..f421f23001 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -1864,15 +1864,14 @@ UnstructuredMesh::to_hdf5(hid_t group) const hid_t mesh_group = create_group(group, "mesh " + std::to_string(id_)); write_dataset(mesh_group, "type", "unstructured"); + write_dataset(mesh_group, "filename", filename_); + // write volume of each tet std::vector tet_vols; for (const auto& eh : ehs_) { tet_vols.emplace_back(tet_volume(eh)); } write_dataset(mesh_group, "volumes", tet_vols); - // and the total volume of the mesh - auto total_vol = std::accumulate(tet_vols.begin(), tet_vols.end(), 0.0); - write_dataset(mesh_group, "total_volume", total_vol); close_group(mesh_group); }