You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While trying to use a lattice in a geometry that isn't fully specified (not having set lower_left) the errors produced during export are very non-intuitive and not user friendly.
Prior to exporting an object possibly some state enforcement should be done. In MontePy we have a validate function that is meant to do basically sanity checking (e.g., checking there is a density set for a non-void cell, etc.), and raise an IllegalStateException that explains what properties are causing the issue.
This leads to the following error, which is caused by not setting latt.lower_left:
---------------------------------------------------------------------------TypeErrorTraceback (mostrecentcalllast)
CellIn[14], line1310#latt.lower_left=None12parent_cell=openmc.Cell(fill=latt)
--->13parent_cell.plot()
14plt.show()
File/usr/local/lib/python3.9/dist-packages/openmc/cell.py:624, inCell.plot(self, *args, **kwargs)
622u=openmc.Universe(cells=[self], universe_id=openmc.Universe.next_id+1)
623openmc.Universe.used_ids.remove(u.id)
-->624returnu.plot(*args, **kwargs)
File/usr/local/lib/python3.9/dist-packages/openmc/universe.py:446, inUniverse.plot(self, origin, width, pixels, basis, color_by, colors, seed, openmc_exec, axes, legend, axis_units, legend_kwargs, outline, **kwargs)
443model.plots.append(plot)
445# Run OpenMC in geometry plotting mode-->446model.plot_geometry(False, cwd=tmpdir, openmc_exec=openmc_exec)
448# Read image from file449img_path=Path(tmpdir) /f'plot_{plot.id}.png'File/usr/local/lib/python3.9/dist-packages/openmc/model/model.py:827, inModel.plot_geometry(self, output, cwd, openmc_exec)
825openmc.lib.plot_geometry(output)
826else:
-->827self.export_to_xml()
828openmc.plot_geometry(output=output, openmc_exec=openmc_exec)
File/usr/local/lib/python3.9/dist-packages/openmc/model/model.py:454, inModel.export_to_xml(self, directory, remove_surfs)
451d.mkdir(parents=True)
453self.settings.export_to_xml(d)
-->454self.geometry.export_to_xml(d, remove_surfs=remove_surfs)
456# If a materials collection was specified, export it. Otherwise, look457# for all materials in the geometry and use that to automatically build458# a collection.459ifself.materials:
File/usr/local/lib/python3.9/dist-packages/openmc/geometry.py:163, inGeometry.export_to_xml(self, path, remove_surfs)
149defexport_to_xml(self, path='geometry.xml', remove_surfs=False):
150"""Export geometry to an XML file. 151 152 Parameters (...) 161 162 """-->163root_element=self.to_xml_element(remove_surfs)
165# Check if path is a directory166p=Path(path)
File/usr/local/lib/python3.9/dist-packages/openmc/geometry.py:137, inGeometry.to_xml_element(self, remove_surfs)
135# Create XML representation136element=ET.Element("geometry")
-->137self.root_universe.create_xml_subelement(element, memo=set())
139# Sort the elements in the file140element[:] =sorted(element, key=lambdax: (
141x.tag, int(x.get('id'))))
File/usr/local/lib/python3.9/dist-packages/openmc/universe.py:695, inUniverse.create_xml_subelement(self, xml_element, memo)
692memo.add(cell)
694# Create XML subelement for this Cell-->695cell_element=cell.create_xml_subelement(xml_element, memo)
697# Append the Universe ID to the subelement and add to Element698cell_element.set("universe", str(self._id))
File/usr/local/lib/python3.9/dist-packages/openmc/cell.py:662, inCell.create_xml_subelement(self, xml_element, memo)
660elifself.fill_typein ('universe', 'lattice'):
661element.set("fill", str(self.fill.id))
-->662self.fill.create_xml_subelement(xml_element, memo)
664ifself.regionisnotNone:
665# Set the region attribute with the region specification666region=str(self.region)
File/usr/local/lib/python3.9/dist-packages/openmc/lattice.py:880, inRectLattice.create_xml_subelement(self, xml_element, memo)
878# Export Lattice lower left879lower_left=ET.SubElement(lattice_subelement, "lower_left")
-->880lower_left.text=' '.join(map(str, self._lower_left))
882# Export the Lattice nested Universe IDs883universe_ids='\n'TypeError: 'NoneType'objectisnotiterable
Yikes, I agree! This hearkens back to your comment a while ago about slots. For instance if you put mylat.lower_letf this same error would pop up, and that can be a real pain to figure out what's going wrong in a big input script.
Bug Description
While trying to use a lattice in a geometry that isn't fully specified (not having set
lower_left
) the errors produced during export are very non-intuitive and not user friendly.Prior to exporting an object possibly some state enforcement should be done. In MontePy we have a
validate
function that is meant to do basically sanity checking (e.g., checking there is a density set for a non-void cell, etc.), and raise anIllegalStateException
that explains what properties are causing the issue.Steps to Reproduce
This leads to the following error, which is caused by not setting
latt.lower_left
:Environment
@pshriwise's CAE environment at UW-Madison.
The text was updated successfully, but these errors were encountered: