From beff025b23b65cbd7462dc0bddea8ecf02b57c57 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 9 Dec 2021 15:27:04 -0600 Subject: [PATCH 1/5] Fixing RegularMesh repr string. --- openmc/mesh.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/openmc/mesh.py b/openmc/mesh.py index 4e1e9565a9..0fa53698e3 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -199,10 +199,10 @@ class RegularMesh(MeshBase): def __repr__(self): string = super().__repr__() string += '{0: <16}{1}{2}\n'.format('\tDimensions', '=\t', self.n_dimension) - string += '{0: <16}{1}{2}\n'.format('\tMesh Cells', '=\t', self._dimension) - string += '{0: <16}{1}{2}\n'.format('\tWidth', '=\t', self._lower_left) - string += '{0: <16}{1}{2}\n'.format('\tOrigin', '=\t', self._upper_right) - string += '{0: <16}{1}{2}\n'.format('\tPixels', '=\t', self._width) + string += '{0: <16}{1}{2}\n'.format('\tVoxels', '=\t', self._dimension) + string += '{0: <16}{1}{2}\n'.format('\tLower left', '=\t', self._lower_left) + string += '{0: <16}{1}{2}\n'.format('\tUpper Right', '=\t', self._upper_right) + string += '{0: <16}{1}{2}\n'.format('\tWidth', '=\t', self._width) return string @classmethod @@ -727,7 +727,7 @@ class UnstructuredMesh(MeshBase): @length_multiplier.setter def length_multiplier(self, length_multiplier): - cv.check_type("Unstructured mesh length multiplier", + cv.check_type("Unstructured mesh length multiplier", length_multiplier, Real) self._length_multiplier = length_multiplier From 5f9357c341c638972b4c8362b83e14db599f2051 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 9 Dec 2021 16:23:37 -0600 Subject: [PATCH 2/5] Correcting some comments in mesh.cpp --- src/mesh.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mesh.cpp b/src/mesh.cpp index 1dc7d34022..cabdd6b3e3 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -749,7 +749,7 @@ RegularMesh::RegularMesh(pugi::xml_node node) : StructuredMesh {node} } if (check_for_node(node, "width")) { - // Make sure both upper-right or width were specified + // Make sure one of upper-right or width were specified if (check_for_node(node, "upper_right")) { fatal_error("Cannot specify both and on a mesh."); } @@ -790,7 +790,7 @@ RegularMesh::RegularMesh(pugi::xml_node node) : StructuredMesh {node} // Set width width_ = xt::eval((upper_right_ - lower_left_) / shape_); } else { - fatal_error("Must specify either and on a mesh."); + fatal_error("Must specify either or on a mesh."); } // Set volume fraction From 2afa90a1dd53470dd287f378773973ce987f3963 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 9 Dec 2021 16:24:49 -0600 Subject: [PATCH 3/5] Resolving upper_right and width conflicts. --- openmc/mesh.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/openmc/mesh.py b/openmc/mesh.py index 0fa53698e3..4d315e63f7 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -144,11 +144,19 @@ class RegularMesh(MeshBase): @property def upper_right(self): - return self._upper_right + if self._upper_right is not None: + return self._upper_right + elif self._width is not None: + if self._lower_left is not None and self._dimension is not None: + return self._lower_left + self._width * self._dimension @property def width(self): - return self._width + if self._width is not None: + return self._width + elif self._upper_right is not None: + if self._lower_left is not None and self._dimension is not None: + return (self._upper_right - self._lower_left)/self._dimension @property def num_mesh_cells(self): @@ -188,13 +196,21 @@ class RegularMesh(MeshBase): def upper_right(self, upper_right): cv.check_type('mesh upper_right', upper_right, Iterable, Real) cv.check_length('mesh upper_right', upper_right, 1, 3) - self._upper_right = upper_right + self._upper_right = np.asarray(upper_right) + + if self._width is not None: + self._width = None + raise Warning("Unsetting width attribute.") @width.setter def width(self, width): cv.check_type('mesh width', width, Iterable, Real) cv.check_length('mesh width', width, 1, 3) - self._width = width + self._width = np.asarray(width) + + if self._upper_right is not None: + self._upper_right = None + raise Warning("Unsetting upper_right attribute.") def __repr__(self): string = super().__repr__() @@ -213,8 +229,12 @@ class RegularMesh(MeshBase): mesh = cls(mesh_id) mesh.dimension = group['dimension'][()] mesh.lower_left = group['lower_left'][()] - mesh.upper_right = group['upper_right'][()] - mesh.width = group['width'][()] + if 'width' in group: + mesh.width = group['width'][()] + elif 'upper_right' in group: + mesh.upper_right = group['upper_right'][()] + else: + raise IOError('Invalid mesh: must have one of "upper_right" or "width"') return mesh From 1a1db91bd2c42107e987d2bbe736b06fe5a607ad Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 9 Dec 2021 21:57:26 -0600 Subject: [PATCH 4/5] Using list instead of numpy array. --- openmc/mesh.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/openmc/mesh.py b/openmc/mesh.py index 4d315e63f7..1264f71887 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -148,7 +148,10 @@ class RegularMesh(MeshBase): return self._upper_right elif self._width is not None: if self._lower_left is not None and self._dimension is not None: - return self._lower_left + self._width * self._dimension + ls = self._lower_left + ws = self._width + dims = self._dimension + return [l + w * d for l, w, d in zip(ls, ws, dims)] @property def width(self): @@ -156,7 +159,10 @@ class RegularMesh(MeshBase): return self._width elif self._upper_right is not None: if self._lower_left is not None and self._dimension is not None: - return (self._upper_right - self._lower_left)/self._dimension + us = self._upper_right + ls = self._lower_left + dims = self._dimension + return [(u - l) / d for u, l, d in zip(us, ls, dims)] @property def num_mesh_cells(self): @@ -196,7 +202,7 @@ class RegularMesh(MeshBase): def upper_right(self, upper_right): cv.check_type('mesh upper_right', upper_right, Iterable, Real) cv.check_length('mesh upper_right', upper_right, 1, 3) - self._upper_right = np.asarray(upper_right) + self._upper_right = upper_right if self._width is not None: self._width = None @@ -206,7 +212,7 @@ class RegularMesh(MeshBase): def width(self, width): cv.check_type('mesh width', width, Iterable, Real) cv.check_length('mesh width', width, 1, 3) - self._width = np.asarray(width) + self._width = width if self._upper_right is not None: self._upper_right = None From 66fabffc38a940dee4390aab57ccabb71e1909b2 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 13 Dec 2021 07:36:12 -0600 Subject: [PATCH 5/5] Updating warning output. --- openmc/mesh.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openmc/mesh.py b/openmc/mesh.py index 1264f71887..9aacdac283 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -206,7 +206,7 @@ class RegularMesh(MeshBase): if self._width is not None: self._width = None - raise Warning("Unsetting width attribute.") + warnings.warn("Unsetting width attribute.") @width.setter def width(self, width): @@ -216,7 +216,7 @@ class RegularMesh(MeshBase): if self._upper_right is not None: self._upper_right = None - raise Warning("Unsetting upper_right attribute.") + warnings.warn("Unsetting upper_right attribute.") def __repr__(self): string = super().__repr__()