openmc-dev / openmc

OpenMC Monte Carlo Code
https://docs.openmc.org
Other
699 stars 444 forks source link

Number collisions between different object types for fill can cause hard to understand errors #2960

Open MicahGale opened 2 weeks ago

MicahGale commented 2 weeks ago

Bug Description

It appears that fill is based solely on object identifier irrespective of object type (e.g., Material, Universe, Lattice). This can sometimes cause unintended behavior, and cause false-alarm errors with circular dependencies. In the following example a cell and

Steps to Reproduce

MWE:

OD = 0.08
WALL = 0.005
LENGTH = 0.5
CAVITY_LENGTH = 0.3
R_SEED = 0.03
R_CAVITY = OD/2 - WALL
END_L = LENGTH - CAVITY_LENGTH
def generate_brach_problem():
    outer_cyl = openmc.model.RightCircularCylinder((0,0,0), LENGTH, OD / 2)
    inner_cyl = openmc.model.RightCircularCylinder((0,0,END_L/2),CAVITY_LENGTH, R_CAVITY)
    titanium = openmc.Material()
    titanium.add_element("Ti", 1.0)
    titanium.set_density("g/cm3", 4.5)
    capsule = openmc.Cell(region = -outer_cyl & +inner_cyl, fill = titanium)
    pallad = openmc.Material()
    pallad.add_element("Pd", 1.0)
    pallad.set_density("g/cm3", 12)
    seed_sp = openmc.Sphere(r=R_SEED)
    air = openmc.Material()
    air.add_element("N", 0.8)
    air.add_element("O", 0.2)
    air.set_density("g/cm3", 0.0012)

    seed = openmc.Universe( cells = [openmc.Cell(region = -seed_sp, fill = pallad),
                openmc.Cell(region = + seed_sp, fill = air)]
    )
    lattice = openmc.RectLattice()
    lattice.pitch = (1, 1, R_SEED * 2)
    lattice.universes = [[[seed]*5]]
    lattice.lower_left = (0,0, END_L /2)
    filler = openmc.Cell(region = -inner_cyl, fill = lattice)
    print(capsule, seed, lattice, filler)
    filler.plot()
    model = openmc.Model()
    model.geometry.root_universe = openmc.Universe(cells = [capsule, filler])
    model.geometry.plot(basis="xz")
    plt.show()

generate_brach_problem()

this Prints:

Cell
    ID             =    9
    Name           =    
    Fill           =    Material 7
    Region         =    (-15 16 -17 (18 | -19 | 20))
    Rotation       =    None
    Temperature    =    None
    Translation    =    None
    Volume         =    None
 Universe
    ID             =    3
    Name           =    
    Geom           =    CSG
    Cells          =    [10, 11]
 RectLattice
    ID             =    4
    Name           =    
    Shape          =    (5, 1, 1)
    Lower Left     =    (0, 0, 0.1)
    Pitch          =    (1, 1, 0.06)
    Outer          =    None
    Universes      
3 3 3 3 3  Cell
    ID             =    12
    Name           =    
    Fill           =    4
    Region         =    (-18 19 -20)
    Rotation       =    None
    Translation    =    None
    Volume         =    None

This leads to the error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[5], line 39
     36     model.geometry.plot(basis="xz")
     37     plt.show()
---> 39 generate_brach_problem()

Cell In[5], line 33, in generate_brach_problem()
     31 filler = openmc.Cell(region = -inner_cyl, fill = lattice)
     32 print(capsule, seed, lattice, filler)
---> 33 filler.plot()
     34 model = openmc.Model()
     35 model.geometry.root_universe = openmc.Universe(cells = [capsule, filler])

File /usr/local/lib/python3.9/dist-packages/openmc/cell.py:624, in Cell.plot(self, *args, **kwargs)
    622 u = openmc.Universe(cells=[self], universe_id=openmc.Universe.next_id + 1)
    623 openmc.Universe.used_ids.remove(u.id)
--> 624 return u.plot(*args, **kwargs)

File /usr/local/lib/python3.9/dist-packages/openmc/universe.py:446, in Universe.plot(self, origin, width, pixels, basis, color_by, colors, seed, openmc_exec, axes, legend, axis_units, legend_kwargs, outline, **kwargs)
    443 model.plots.append(plot)
    445 # Run OpenMC in geometry plotting mode
--> 446 model.plot_geometry(False, cwd=tmpdir, openmc_exec=openmc_exec)
    448 # Read image from file
    449 img_path = Path(tmpdir) / f'plot_{plot.id}.png'

File /usr/local/lib/python3.9/dist-packages/openmc/model/model.py:828, in Model.plot_geometry(self, output, cwd, openmc_exec)
    826 else:
    827     self.export_to_xml()
--> 828     openmc.plot_geometry(output=output, openmc_exec=openmc_exec)

File /usr/local/lib/python3.9/dist-packages/openmc/executor.py:154, in plot_geometry(output, openmc_exec, cwd, path_input)
    152 if path_input is not None:
    153     args += [path_input]
--> 154 _run(args, output, cwd)

File /usr/local/lib/python3.9/dist-packages/openmc/executor.py:125, in _run(args, output, cwd)
    122     error_msg = 'OpenMC aborted unexpectedly.'
    123 error_msg = ' '.join(error_msg.split())
--> 125 raise RuntimeError(error_msg)

RuntimeError: Cell 12 is filled with the same universe that it is contained in. application called MPI_Abort(MPI_COMM_WORLD, -1) - process 0 [unset]: write_line error; fd=-1 buf=:cmd=abort exitcode=-1 : system msg for write_line failure : Bad file descriptor

Environment

Openmc: v0.14.0