From bbb5690a003f33cc0e21ea22299a081be67bc0c0 Mon Sep 17 00:00:00 2001 From: jingang Date: Mon, 9 May 2016 19:27:29 -0400 Subject: [PATCH 1/2] fix errors of setting material density using 'sum' --- docs/source/usersguide/input.rst | 8 ++++---- openmc/material.py | 26 ++++++++++++++++---------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/docs/source/usersguide/input.rst b/docs/source/usersguide/input.rst index 2158e1d8c..37b441ef2 100644 --- a/docs/source/usersguide/input.rst +++ b/docs/source/usersguide/input.rst @@ -1215,11 +1215,11 @@ Each ``material`` element can have the following attributes or sub-elements: An element with attributes/sub-elements called ``value`` and ``units``. The ``value`` attribute is the numeric value of the density while the ``units`` can be "g/cm3", "kg/m3", "atom/b-cm", "atom/cm3", or "sum". The "sum" unit - indicates that values appearing in ``ao`` attributes for ```` and - ```` sub-elements are to be interpreted as nuclide/element - densities in atom/b-cm, and the total density of the material is taken as + indicates that values appearing in ``ao`` or ``wo`` attributes for ```` and + ```` sub-elements are to be interpreted as absolute nuclide/element + densities in atom/b-cm or g/cm3, and the total density of the material is taken as the sum of all nuclides/elements. The "sum" option cannot be used in - conjunction with weight percents. The "macro" unit is used with + conjunction with atom or weight percents. The "macro" unit is used with a ``macroscopic`` quantity to indicate that the density is already included in the library and thus not needed here. However, if a value is provided for the ``value``, then this is treated as a number density multiplier on diff --git a/openmc/material.py b/openmc/material.py index ff690aa9a..c74f8f1cd 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -245,19 +245,25 @@ class Material(object): """ - cv.check_type('the density for Material ID="{0}"'.format(self._id), - density, Real) cv.check_value('density units', units, DENSITY_UNITS) - - if density is None and units is not 'sum': - msg = 'Unable to set the density for Material ID="{0}" ' \ - 'because a density must be set when not using ' \ - 'sum unit'.format(self._id) - raise ValueError(msg) - - self._density = density self._density_units = units + if units is 'sum': + if density is not None: + msg = 'Density "{0}" for Material ID="{1}" is ignored ' \ + 'because the unit is "sum"'.format(density, self._id) + warnings.warn(msg) + else: + if density is None: + msg = 'Unable to set the density for Material ID="{0}" ' \ + 'because a density must be set when not using ' \ + '"sum" unit'.format(self._id) + raise ValueError(msg) + + cv.check_type('the density for Material ID="{0}"'.format(self._id), + density, Real) + self._density = density + @distrib_otf_file.setter def distrib_otf_file(self, filename): # TODO: remove this when distributed materials are merged From 95406d52fcc0541dc039b1a99db3b4d6056ff1c8 Mon Sep 17 00:00:00 2001 From: liangjg Date: Mon, 9 May 2016 22:34:18 -0400 Subject: [PATCH 2/2] update description according to comments --- docs/source/usersguide/input.rst | 9 ++++----- openmc/material.py | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/source/usersguide/input.rst b/docs/source/usersguide/input.rst index 37b441ef2..775407d70 100644 --- a/docs/source/usersguide/input.rst +++ b/docs/source/usersguide/input.rst @@ -1215,11 +1215,10 @@ Each ``material`` element can have the following attributes or sub-elements: An element with attributes/sub-elements called ``value`` and ``units``. The ``value`` attribute is the numeric value of the density while the ``units`` can be "g/cm3", "kg/m3", "atom/b-cm", "atom/cm3", or "sum". The "sum" unit - indicates that values appearing in ``ao`` or ``wo`` attributes for ```` and - ```` sub-elements are to be interpreted as absolute nuclide/element - densities in atom/b-cm or g/cm3, and the total density of the material is taken as - the sum of all nuclides/elements. The "sum" option cannot be used in - conjunction with atom or weight percents. The "macro" unit is used with + indicates that values appearing in ``ao`` or ``wo`` attributes for ```` + and ```` sub-elements are to be interpreted as absolute nuclide/element + densities in atom/b-cm or g/cm3, and the total density of the material is + taken as the sum of all nuclides/elements. The "macro" unit is used with a ``macroscopic`` quantity to indicate that the density is already included in the library and thus not needed here. However, if a value is provided for the ``value``, then this is treated as a number density multiplier on diff --git a/openmc/material.py b/openmc/material.py index c74f8f1cd..e9a74f1e7 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -251,16 +251,16 @@ class Material(object): if units is 'sum': if density is not None: msg = 'Density "{0}" for Material ID="{1}" is ignored ' \ - 'because the unit is "sum"'.format(density, self._id) + 'because the unit is "sum"'.format(density, self.id) warnings.warn(msg) else: if density is None: msg = 'Unable to set the density for Material ID="{0}" ' \ - 'because a density must be set when not using ' \ - '"sum" unit'.format(self._id) + 'because a density value must be given when not using ' \ + '"sum" unit'.format(self.id) raise ValueError(msg) - cv.check_type('the density for Material ID="{0}"'.format(self._id), + cv.check_type('the density for Material ID="{0}"'.format(self.id), density, Real) self._density = density