@@ -72,6 +72,10 @@ class Cell(IDManagerMixin):
7272 temperature : float or iterable of float
7373 Temperature of the cell in Kelvin. Multiple temperatures can be given
7474 to give each distributed cell instance a unique temperature.
75+ density : float or iterable of float
76+ Density of the cell in [g/cm3]. Multiple densities can be given to give
77+ each distributed cell instance a unique density. Densities set here will
78+ override the density set on materials used to fill the cell.
7579 translation : Iterable of float
7680 If the cell is filled with a universe, this array specifies a vector
7781 that is used to translate (shift) the universe.
@@ -109,6 +113,7 @@ def __init__(self, cell_id=None, name='', fill=None, region=None):
109113 self ._rotation = None
110114 self ._rotation_matrix = None
111115 self ._temperature = None
116+ self ._density = None
112117 self ._translation = None
113118 self ._paths = None
114119 self ._num_instances = None
@@ -141,6 +146,7 @@ def __repr__(self):
141146 if self .fill_type == 'material' :
142147 string += '\t {0: <15}=\t {1}\n ' .format ('Temperature' ,
143148 self .temperature )
149+ string += '\t {0: <15}=\t {1}\n ' .format ('Density' , self .density )
144150 string += '{: <16}=\t {}\n ' .format ('\t Translation' , self .translation )
145151 string += '{: <16}=\t {}\n ' .format ('\t Volume' , self .volume )
146152
@@ -257,6 +263,30 @@ def temperature(self, temperature):
257263 else :
258264 self ._temperature = temperature
259265
266+ @property
267+ def density (self ):
268+ return self ._density
269+
270+ @density .setter
271+ def density (self , density ):
272+ # Make sure densities are greater than zero
273+ cv .check_type ('cell density' , density , (Iterable , Real ), none_ok = True )
274+ if isinstance (density , Iterable ):
275+ cv .check_type ('cell density' , density , Iterable , Real )
276+ for rho in density :
277+ cv .check_greater_than ('cell density' , rho , 0.0 , True )
278+ elif isinstance (density , Real ):
279+ cv .check_greater_than ('cell density' , density , 0.0 , True )
280+
281+ # If this cell is filled with a universe or lattice, propagate
282+ # densities to all cells contained. Otherwise, simply assign it.
283+ if self .fill_type in ('universe' , 'lattice' ):
284+ for c in self .get_all_cells ().values ():
285+ if c .fill_type == 'material' :
286+ c ._density = density
287+ else :
288+ self ._density = density
289+
260290 @property
261291 def translation (self ):
262292 return self ._translation
@@ -525,6 +555,8 @@ def clone(self, clone_materials=True, clone_regions=True, memo=None):
525555 clone .volume = self .volume
526556 if self .temperature is not None :
527557 clone .temperature = self .temperature
558+ if self .density is not None :
559+ clone .density = self .density
528560 if self .translation is not None :
529561 clone .translation = self .translation
530562 if self .rotation is not None :
@@ -650,6 +682,12 @@ def create_surface_elements(node, element, memo=None):
650682 else :
651683 element .set ("temperature" , str (self .temperature ))
652684
685+ if self .density is not None :
686+ if isinstance (self .density , Iterable ):
687+ element .set ("density" , ' ' .join (str (t ) for t in self .density ))
688+ else :
689+ element .set ("density" , str (self .density ))
690+
653691 if self .translation is not None :
654692 element .set ("translation" , ' ' .join (map (str , self .translation )))
655693
@@ -711,10 +749,13 @@ def from_xml_element(cls, elem, surfaces, materials, get_universe):
711749 c .temperature = temperature
712750 else :
713751 c .temperature = temperature [0 ]
752+ density = get_elem_list (elem , 'density' , float )
753+ if density is not None :
754+ c .density = density if len (density ) > 1 else density [0 ]
714755 v = get_text (elem , 'volume' )
715756 if v is not None :
716757 c .volume = float (v )
717- for key in ('temperature' , 'rotation' , 'translation' ):
758+ for key in ('temperature' , 'density' , ' rotation' , 'translation' ):
718759 values = get_elem_list (elem , key , float )
719760 if values is not None :
720761 if key == 'rotation' and len (values ) == 9 :
0 commit comments