From a3bb85c35896866b9ace72f8b0bc97fea1e10143 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 23 Oct 2019 08:55:34 -0500 Subject: [PATCH] Updating Python mesh class string representations. --- openmc/mesh.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/openmc/mesh.py b/openmc/mesh.py index 0a8b51c5f..e6bd96754 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -53,6 +53,12 @@ class MeshBase(IDManagerMixin, metaclass=ABCMeta): else: self._name = '' + def __repr__(self): + string = type(self).__name__ + '\n' + string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id) + string += '{0: <16}{1}{2}\n'.format('\tName', '=\t', self._name) + return string + @classmethod def from_hdf5(cls, group): """Create mesh from HDF5 group @@ -126,7 +132,10 @@ class RegularMesh(MeshBase): @property def n_dimension(self): - return len(self._dimension) + if self._dimension is not None: + return len(self._dimension) + else: + return None @property def lower_left(self): @@ -187,11 +196,9 @@ class RegularMesh(MeshBase): self._width = width def __repr__(self): - string = 'RegularMesh\n' - string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id) - string += '{0: <16}{1}{2}\n'.format('\tName', '=\t', self._name) - string += '{0: <16}{1}{2}\n'.format('\tType', '=\t', self._type) - string += '{0: <16}{1}{2}\n'.format('\tBasis', '=\t', self._dimension) + 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) @@ -522,6 +529,17 @@ class RectilinearMesh(MeshBase): cv.check_type('mesh z_grid', grid, Iterable, Real) self._z_grid = grid + def __repr__(self): + string = super().__repr__() + string += '{0: <16}{1}{2}\n'.format('\tDimensions', '=\t', self.n_dimension) + x_grid_str = str(self._x_grid) if not self._x_grid else len(self._x_grid) + y_grid_str = str(self._y_grid) if not self._y_grid else len(self._y_grid) + z_grid_str = str(self._z_grid) if not self._z_grid else len(self._z_grid) + string += '{0: <16}{1}{2}\n'.format('\tx pnts:', '=\t', x_grid_str) + string += '{0: <16}{1}{2}\n'.format('\ty pnts:', '=\t', y_grid_str) + string += '{0: <16}{1}{2}\n'.format('\tz pnts:', '=\t', z_grid_str) + return string + @classmethod def from_hdf5(cls, group): mesh_id = int(group.name.split('/')[-1].lstrip('mesh '))