From 4f93f26d8136f4bcb1d28bb9301c6b4c690b4042 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 11 Aug 2022 06:41:23 -0500 Subject: [PATCH 1/3] Using valid entries of connectivity only --- openmc/mesh.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/openmc/mesh.py b/openmc/mesh.py index daff4dedcc..af830158cf 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -1476,7 +1476,7 @@ class UnstructuredMesh(MeshBase): Coordinates of the mesh vertices with array shape (n_elements, 3) .. versionadded:: 0.13.1 - connectivity : numpy.ndarray + connectivity : numpy.ndarray Connectivity of the elements with array shape (n_elements, 8) .. versionadded:: 0.13.1 @@ -1562,10 +1562,6 @@ class UnstructuredMesh(MeshBase): def total_volume(self): return np.sum(self.volumes) - @property - def centroids(self): - return self._centroids - @property def vertices(self): return self._vertices @@ -1628,8 +1624,8 @@ class UnstructuredMesh(MeshBase): Parameters ---------- bin : int - Bin ID for the returned centroid - + Bin ID for the returned centroid + Returns ------- numpy.ndarray @@ -1637,6 +1633,8 @@ class UnstructuredMesh(MeshBase): """ conn = self.connectivity[bin] + # remove invalid connectivity values + conn = conn[conn >= 0] coords = self.vertices[conn] return coords.mean(axis=0) From 8791c7212e0bbca9abebf3f786b06ba8e82e151d Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 11 Aug 2022 07:48:58 -0500 Subject: [PATCH 2/3] Adding check for first vertex and centroid --- .../unstructured_mesh/test.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/regression_tests/unstructured_mesh/test.py b/tests/regression_tests/unstructured_mesh/test.py index 090a475997..6146c1b1e2 100644 --- a/tests/regression_tests/unstructured_mesh/test.py +++ b/tests/regression_tests/unstructured_mesh/test.py @@ -37,6 +37,27 @@ class UnstructuredMeshTest(PyAPITestHarness): def _compare_results(self): with openmc.StatePoint(self._sp_name) as sp: + # check some properties of the unstructured mesh + umesh = None + for m in sp.meshes.values(): + if isinstance(m, openmc.UnstructuredMesh): + umesh = m + assert umesh is not None + + # check that the first element centroid is correct + # this will depend on whether the tet mesh or hex mesh + # file is being used in this test + if umesh.element_types[0] == umesh._LINEAR_TET: + exp_vertex = (-10.0, -10.0, -10.0) + exp_centroid = (-8.75, -9.75, -9.25) + else: + exp_vertex = (-10.0, -10.0, 10.0) + exp_centroid = (-9.0, -9.0, 9.0) + + np.testing.assert_array_equal(umesh.vertices[0], exp_vertex) + np.testing.assert_array_equal(umesh.centroid(0), exp_centroid) + + # loop over the tallies and get data for tally in sp.tallies.values(): # find the regular and unstructured meshes From ba72199df02061d2f0aeca00296ad3a474f5576d Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 11 Aug 2022 07:58:00 -0500 Subject: [PATCH 3/3] rm empty line --- tests/regression_tests/unstructured_mesh/test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/regression_tests/unstructured_mesh/test.py b/tests/regression_tests/unstructured_mesh/test.py index 6146c1b1e2..9ed36c69c0 100644 --- a/tests/regression_tests/unstructured_mesh/test.py +++ b/tests/regression_tests/unstructured_mesh/test.py @@ -57,7 +57,6 @@ class UnstructuredMeshTest(PyAPITestHarness): np.testing.assert_array_equal(umesh.vertices[0], exp_vertex) np.testing.assert_array_equal(umesh.centroid(0), exp_centroid) - # loop over the tallies and get data for tally in sp.tallies.values(): # find the regular and unstructured meshes