From 92589048d8f2994462987cc94e805069d1658e3d Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 17 Mar 2020 15:18:20 -0500 Subject: [PATCH] Adding centroids attribute. --- openmc/mesh.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/openmc/mesh.py b/openmc/mesh.py index 1117116e1d..94bcf947b0 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -611,12 +611,16 @@ class UnstructuredMesh(MeshBase): Volumes of the unstructured mesh elements total_volume : float Volume of the unstructured mesh in total + centroids : Iterable of tuple + An iterable of element centroid coordinates, e.g. [(0.0, 0.0, 0.0), + (1.0, 1.0, 1.0), ...] """ def __init__(self, mesh_id=None, name='', filename=''): super().__init__(mesh_id, name) self._filename = filename self._volumes = [] + self._centroids = [] @property def filename(self): @@ -644,6 +648,15 @@ class UnstructuredMesh(MeshBase): def total_volume(self): return np.sum(self.volumes) + @property + def centroids(self): + return self._centroids + + @centroids.setter + def centroids(self, centroids): + cv.check_type("Unstructured mesh centroids", centroids, Iterable, Iterable) + self._centroids = centroids + def __repr__(self): string = super().__repr__() string += '{0: <16}{1}{2}\n'.format('\tFilename', '=\t', self.filename) @@ -656,7 +669,9 @@ class UnstructuredMesh(MeshBase): mesh = cls(mesh_id) mesh.filename = group['filename'][()].decode() vol_data = group['volumes'][()] + centroids = group['centroids'][()] mesh.volumes = np.reshape(vol_data, (vol_data.shape[0], 1)) + mesh.centroids = np.reshape(centroids, (vol_data.shape[0], 3)) return mesh