mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 13:45:36 -04:00
Merge pull request #2001 from paulromano/lattice-unset-message
Improve error message if user doesn't set lattice universes
This commit is contained in:
commit
e807c26436
2 changed files with 23 additions and 1 deletions
|
|
@ -852,6 +852,10 @@ class RectLattice(Lattice):
|
|||
if memo is not None:
|
||||
memo.add(self)
|
||||
|
||||
# Make sure universes have been assigned
|
||||
if self.universes is None:
|
||||
raise ValueError(f"Lattice {self.id} does not have universes assigned.")
|
||||
|
||||
lattice_subelement = ET.Element("lattice")
|
||||
lattice_subelement.set("id", str(self._id))
|
||||
|
||||
|
|
@ -876,7 +880,7 @@ class RectLattice(Lattice):
|
|||
lower_left = ET.SubElement(lattice_subelement, "lower_left")
|
||||
lower_left.text = ' '.join(map(str, self._lower_left))
|
||||
|
||||
# Export the Lattice nested Universe IDs - column major for Fortran
|
||||
# Export the Lattice nested Universe IDs
|
||||
universe_ids = '\n'
|
||||
|
||||
# 3D Lattices
|
||||
|
|
@ -1448,6 +1452,8 @@ class HexLattice(Lattice):
|
|||
center.text = ' '.join(map(str, self._center))
|
||||
|
||||
# Export the Lattice nested Universe IDs.
|
||||
if self.universes is None:
|
||||
raise ValueError(f"Lattice {self.id} does not have universes assigned.")
|
||||
|
||||
# 3D Lattices
|
||||
if self._num_axial is not None:
|
||||
|
|
|
|||
|
|
@ -361,3 +361,19 @@ def test_show_indices():
|
|||
assert len(lines) == 4*i - 3
|
||||
lines_x = openmc.HexLattice.show_indices(i, 'x').split('\n')
|
||||
assert len(lines) == 4*i - 3
|
||||
|
||||
|
||||
def test_unset_universes():
|
||||
elem = ET.Element("dummy")
|
||||
|
||||
lattice = openmc.RectLattice()
|
||||
lattice.lower_left = (-1., -1.)
|
||||
lattice.pitch = (1., 1.)
|
||||
with pytest.raises(ValueError):
|
||||
lattice.create_xml_subelement(elem)
|
||||
|
||||
hex_lattice = openmc.HexLattice()
|
||||
hex_lattice.center = (0., 0.)
|
||||
hex_lattice.pitch = (1.,)
|
||||
with pytest.raises(ValueError):
|
||||
hex_lattice.create_xml_subelement(elem)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue