'float' not iterable when creating .xml

We I try to create my geometry.xml file, I get an error saying, after a long call of functions, that ‘float’ is not iterable. It seems to be an issue with my universe. I am sorry if this is a simple question, but I can’t seem to see why I’m suddenly getting this error. I had not worked on this program for a few weeks, and came back and it wouldn’t compile which is odd. Any help is appreciated! Thanks!

Geometry for Beryllium Reflector (Source)

# Create concentric inner and outer cylinders
innerCylinder = openmc.XCylinder(y0=0, z0=0, r=25, boundary_type='transmission',
                                 surface_id=9, name='InnerCylinder')
outerCylinder = openmc.XCylinder(y0=0, z0=0, r=55, boundary_type='transmission',
                                 surface_id=10, name='OuterCylinder')


# Create cutoff planes for cylinders
rightOuter = openmc.XPlane(x0=-10, boundary_type='transmission',
                         surface_id=11, name='rightOuter') #p1
rightInner = openmc.XPlane(x0=-20, boundary_type='transmission',
                         surface_id=12, name='rightInner') #p2
leftInner = openmc.XPlane(x0=-90, boundary_type='transmission',
                            surface_id=13, name='leftInner') #p3
leftOuter = openmc.XPlane(x0=-100, boundary_type='transmission',
                            surface_id=14, name='leftOuter') # p4

Create reflector material (Beryllium Oxide)


# Reflector Side region
reflectorSideRegion = +innerCylinder & -outerCylinder & -rightInner & +leftInner

# Reflector Top region
reflectorRightRegion = -outerCylinder & +rightInner & -rightOuter

# Reflector Bottom Region
reflectorLeftRegion = -outerCylinder & -leftInner & +leftOuter

# Total Reflector Region
totalReflectorRegion = reflectorSideRegion | reflectorRightRegion | reflectorLeftRegion

# Reflector Internal Void Region
internalSourceVoidRegion = -innerCylinder & -rightInner & +leftInner

# Reflector Cell
reflectorCell = openmc.Cell(region=totalReflectorRegion, fill=reflectorMat)

# Inner Void Cell
voidSourceCell = openmc.Cell(region=internalSourceVoidRegion)

# Add to Universe
universe.add_cell(reflectorCell)
universe.add_cell(voidSourceCell)

Vacuum sphere behind shield to measure dose

doseSphere = openmc.Sphere(x0=total_thickness+1000, y0=0, z0=0, r=100, boundary_type='vacuum',
                           surface_id=15, name='dose sphere')
sphere_region = -doseSphere
doseSphereCell=openmc.Cell(region=sphere_region)
universe.add_cell(doseSphereCell)

Everything else (void land)


# Region around source cylinder (before shield)
back_plane = openmc.XPlane(x0=-101, boundary_type='vacuum', surface_id=16)
vacuum_region1 = +outerCylinder & +back_plane & -entry_surface 

# Extra region for troubleshooting
trouble1 = +rightOuter & -entry_surface
trouble2 = -leftOuter & +back_plane

# Region between shield exit and back boundary plane
far_plane = openmc.XPlane(x0= (total_thickness + 1101), surface_id=17, 
                          boundary_type='vacuum')
vacuum_region2 = +exit_surface & -far_plane & +doseSphere

if (fallCone == "y"):
    # Region above and below shield
    vacuum_region3 = +coneShadow & +entry_surface & -coneIntersect
    vacuum_region4 = +coneCutoff & +coneIntersect & -exit_surface
    void_region = vacuum_region1 | vacuum_region2 | vacuum_region3 | vacuum_region4 | trouble1 | trouble2
else:
    # Region above and below shield
    vacuum_region3 = +coneShadow & +entry_surface & -exit_surface
    void_region = vacuum_region1 | vacuum_region2 | vacuum_region3 | trouble1 | trouble2
    
void_cell=openmc.Cell(region=void_region)
universe.add_cell(void_cell)

# Kill region, out of bounds
kill_region1 = +far_plane
kill_cell1 = openmc.Cell(region=kill_region1)
universe.add_cell(kill_cell1)

kill_region2 = -back_plane
kill_cell2 = openmc.Cell(region=kill_region2)
universe.add_cell(kill_cell2)

OpenMC requires a “root” universe. Create root universe with shield

root_cell = openmc.Cell(name='root cell')
root_cell.fill = universe

root_universe = openmc.Universe(universe_id=0, name='root universe')
root_universe.add_cell(root_cell)

Create geometry and set root universe

# geometry = openmc.Geometry(root_universe)
geometry = openmc.Geometry()

geometry.root_universe = root_universe

Export to a geometry.xml file

geometry.export_to_xml()

TypeError                                 Traceback (most recent call last)
Input In [19], in <module>
      5 geometry.root_universe = root_universe
      7 # Export to a geometry.xml file
----> 8 geometry.export_to_xml()
     10 get_ipython().system('cat geometry.xml')

File /opt/anaconda3/envs/openmc-env/lib/python3.10/site-packages/openmc/geometry.py:98, in Geometry.export_to_xml(self, path, remove_surfs)
     96 # Create XML representation
     97 root_element = ET.Element("geometry")
---> 98 self.root_universe.create_xml_subelement(root_element, memo=set())
    100 # Sort the elements in the file
    101 root_element[:] = sorted(root_element, key=lambda x: (
    102     x.tag, int(x.get('id'))))

File /opt/anaconda3/envs/openmc-env/lib/python3.10/site-packages/openmc/universe.py:578, in Universe.create_xml_subelement(self, xml_element, memo)
    575     memo.add(cell)
    577 # Create XML subelement for this Cell
--> 578 cell_element = cell.create_xml_subelement(xml_element, memo)
    580 # Append the Universe ID to the subelement and add to Element
    581 cell_element.set("universe", str(self._id))

File /opt/anaconda3/envs/openmc-env/lib/python3.10/site-packages/openmc/cell.py:591, in Cell.create_xml_subelement(self, xml_element, memo)
    589 elif self.fill_type in ('universe', 'lattice'):
    590     element.set("fill", str(self.fill.id))
--> 591     self.fill.create_xml_subelement(xml_element, memo)
    593 if self.region is not None:
    594     # Set the region attribute with the region specification
    595     region = str(self.region)

File /opt/anaconda3/envs/openmc-env/lib/python3.10/site-packages/openmc/universe.py:578, in Universe.create_xml_subelement(self, xml_element, memo)
    575     memo.add(cell)
    577 # Create XML subelement for this Cell
--> 578 cell_element = cell.create_xml_subelement(xml_element, memo)
    580 # Append the Universe ID to the subelement and add to Element
    581 cell_element.set("universe", str(self._id))

File /opt/anaconda3/envs/openmc-env/lib/python3.10/site-packages/openmc/cell.py:622, in Cell.create_xml_subelement(self, xml_element, memo)
    619                 create_surface_elements(subnode, element, memo)
    621     # Call the recursive function from the top node
--> 622     create_surface_elements(self.region, xml_element, memo)
    624 if self.temperature is not None:
    625     if isinstance(self.temperature, Iterable):

File /opt/anaconda3/envs/openmc-env/lib/python3.10/site-packages/openmc/cell.py:619, in Cell.create_xml_subelement.<locals>.create_surface_elements(node, element, memo)
    617 else:
    618     for subnode in node:
--> 619         create_surface_elements(subnode, element, memo)

File /opt/anaconda3/envs/openmc-env/lib/python3.10/site-packages/openmc/cell.py:619, in Cell.create_xml_subelement.<locals>.create_surface_elements(node, element, memo)
    617 else:
    618     for subnode in node:
--> 619         create_surface_elements(subnode, element, memo)

File /opt/anaconda3/envs/openmc-env/lib/python3.10/site-packages/openmc/cell.py:618, in Cell.create_xml_subelement.<locals>.create_surface_elements(node, element, memo)
    616     create_surface_elements(node.node, element, memo)
    617 else:
--> 618     for subnode in node:
    619         create_surface_elements(subnode, element, memo)

TypeError: 'float' object is not iterable

@madhofs I don’t know if you ever got to the bottom of this. I tried running the code you put above but there are some pieces missing so I couldn’t quite get to the geometry export where the error occurs. If you can attach your .py file, I’ll give it another go.

I got this error today and it also made me very confused. I was able to narrow it down to a singular assembly and eventually found the issue was in defining cell regions. I had accidentally used a float variable instead of a surface, which is why it says ‘float is not iterable’.

Luckily, due to rounding in the computer, I was able to spot it (the float values were 11 automatically generated and evenly spaced values between -75 and 75, so 45.000000000001 should really be 45).

image

So I’d suggest double checking regions and material definitions.