From ec102212193ca5fa683dd736ca52452e8fb0923d Mon Sep 17 00:00:00 2001 From: Mikolaj Adam Kowalski Date: Thu, 19 Mar 2020 12:04:44 +0000 Subject: [PATCH] Address comments by @pshriwise --- docs/source/usersguide/geometry.rst | 4 ++-- openmc/cell.py | 19 +++++-------------- .../distribmat/results_true.dat | 1 + .../multipole/results_true.dat | 1 + tests/unit_tests/test_cell.py | 10 +++++----- 5 files changed, 14 insertions(+), 21 deletions(-) diff --git a/docs/source/usersguide/geometry.rst b/docs/source/usersguide/geometry.rst index 4b925c448a..f95a1ff1cf 100644 --- a/docs/source/usersguide/geometry.rst +++ b/docs/source/usersguide/geometry.rst @@ -188,8 +188,8 @@ the :class:`openmc.Cell` class:: In this example, an instance of :class:`openmc.Material` is assigned to the :attr:`Cell.fill` attribute. One can also fill a cell with a :ref:`universe -` or :ref:`lattice `. If you provide -no fill to a cell, it will be filled with void on export to XML. +` or :ref:`lattice `. If no fill +is provided to a cell, it will be filled with void by default. The classes :class:`Halfspace`, :class:`Intersection`, :class:`Union`, and :class:`Complement` and all instances of :class:`openmc.Region` and can be diff --git a/openmc/cell.py b/openmc/cell.py index 0173ac4955..0b6bd4427a 100644 --- a/openmc/cell.py +++ b/openmc/cell.py @@ -89,9 +89,9 @@ class Cell(IDManagerMixin): :meth:`Cell.add_volume_information` method. For 'distribmat' cells it is the total volume of all instances. atoms : collections.OrderedDict - Mapping of nuclides to the total number of atoms for each nuclide present - in the cell, or in all of its instances for a 'distribmat' fill. For example, - {'U235': 1.0e22, 'U238': 5.0e22, ...}. + Mapping of nuclides to the total number of atoms for each nuclide + present in the cell, or in all of its instances for a 'distribmat' + fill. For example, {'U235': 1.0e22, 'U238': 5.0e22, ...}. """ @@ -140,10 +140,7 @@ class Cell(IDManagerMixin): string += '\t{0: <15}=\t{1}\n'.format('Temperature', self.temperature) string += '{: <16}=\t{}\n'.format('\tTranslation', self.translation) - - # Print volume only when it is set to avoid breaking regression - if self._volume is not None: - string += '{: <16}=\t{}\n'.format('\tVolume', self.volume) + string += '{: <16}=\t{}\n'.format('\tVolume', self.volume) return string @@ -364,13 +361,7 @@ class Cell(IDManagerMixin): def volume(self, volume): if volume is not None: cv.check_type('cell volume', volume, (Real, UFloat)) - - # Note that ufloat(0.0, 0.1) >= 0.0 is False - # We need special treatment for UFloat input - val = volume - if isinstance(val, UFloat): - val = volume.nominal_value - cv.check_greater_than('cell volume', val, 0.0) + cv.check_greater_than('cell volume', volume, 0.0, equality=True) self._volume = volume diff --git a/tests/regression_tests/distribmat/results_true.dat b/tests/regression_tests/distribmat/results_true.dat index e0143f0fff..5cf99d6ba9 100644 --- a/tests/regression_tests/distribmat/results_true.dat +++ b/tests/regression_tests/distribmat/results_true.dat @@ -7,3 +7,4 @@ Cell Region = -9 Rotation = None Translation = None + Volume = None diff --git a/tests/regression_tests/multipole/results_true.dat b/tests/regression_tests/multipole/results_true.dat index 890e47efd9..2273c03fde 100644 --- a/tests/regression_tests/multipole/results_true.dat +++ b/tests/regression_tests/multipole/results_true.dat @@ -39,3 +39,4 @@ Cell Rotation = None Temperature = [500. 700. 0. 800.] Translation = None + Volume = None diff --git a/tests/unit_tests/test_cell.py b/tests/unit_tests/test_cell.py index e5ab582016..4ab5962503 100644 --- a/tests/unit_tests/test_cell.py +++ b/tests/unit_tests/test_cell.py @@ -130,13 +130,13 @@ def test_volume_setting(): c.volume = 3 c.volume = u.ufloat(3, 0.7) - # Test errors for -ve and 0 volume - with pytest.raises(ValueError): - c.volume = 0.0 + # Allow volume to be set to 0.0 + c.volume = 0.0 + c.volume = u.ufloat(0.0, 0.1) + + # Test errors for -ve volume with pytest.raises(ValueError): c.volume = -1.0 - with pytest.raises(ValueError): - c.volume = u.ufloat(0.0, 0.1) with pytest.raises(ValueError): c.volume = u.ufloat(-0.05, 0.1)