AttributeError: can't set attribute When Creating HexLattice

Hi,

I’m trying to create 3d hexagonal lattice but it shows “AttributeError: can’t set attribute” is there anyone who can help me solve this?


Thanks,
Kristina

Hi Kristina,

The ‘num_axial’ attribute is inferred from what universes you assign to the hexlat.universes attribute. To have a 2D hexagonal lattice, you would assign a list of lists, where each element in the outer list corresponds to a ring and each element in an inner list corresponds to have position within a ring. For a 3D lattice with multiple axial levels, you have one additional level of nesting, where each element in the outermost list would then correspond to a single axial level.

Best regards,
Paul

Hi Paul,

I have create a 2d lattice with this script :

When i plot with ‘xy’ basis, the lattice works and filled the region i want, like this :

But when i plot with ‘xz’ or ‘yz’ basis it only show one row of my lattice universe:

I want to create a 3d hexlat to fill my ‘xz’ or ‘yz’ plot with this script :

It shows the error like i shared before. You said that for a 3D lattice with multiple axial levels, i need one additional level of nesting, where each element in the outermost list would then correspond to a single axial level. But i don’t know how to have one additional level of nesting. Can you tell me more about it?

Thanks,
Kristina

Sorry before, the ‘xy’ basis show this:

Hi Kristina,

What I mean by one additional level of nesting is something like the following:

level1 = [ring15, ring14, ring13, …]
level2 = [ring15, ring14, ring13, …]

hexlat.universes = [level1, level2, …]

You can see in this case that each element in hexlat.universes is now a list of rings, and each element in a ring is a list of universes. Of course, in your geometry the levels can have different arrangements of universes in the rings if needed (rather than being the same as shown above).

Best regards,
Paul

Hi Paul,

It works, thank you so much for your explanation!

Thanks,
Kristina

Love reviving a 2018 thread in 2024.

I’m currently working on a 3D hexagonal lattice. The explanation for nesting universes for different levels makes sense. I’m hoping to make my 3D lattice have different openmc.HexLattice.outer at different axial levels. What the best way to accomplish this?

For example, say I have three axial levels (lower reflector, core, upper reflector). My reflector outer should be BeO, and my core outer should be graphite. I tried to do the following

hex_lattice = openmc.HexLattice()

# imagine the rings are properly defined as a list of pin universes 
level_1 = [l_refl_ring_3, l_refl_ring_2,l_refl_ring_1]
level_2 = [core_ring_3, core_ring_2, core_ring_1]
level_3 = [u_refl_ring_3, u_refl_ring_2,u_refl_ring_1]

outer_graphite_univ = openmc.Universe(cells = (openmc.Cell(fill=graphite),))
outer_BeO_univ = openmc.Universe(cells = (openmc.Cell(fill=BeO),))

hex_lattice.universes = [level_1, level_2, level_3]
hex_lattice.outer = [outer_BeO_univ, outer_graphite_univ, outer_BeO_univ]

But it failed

TypeError: Unable to set "outer universe" to "[Universe
        ID             =        445
        Name           =
        Geom           =        CSG
        Cells          =        [267368]
, Universe
        ID             =        444
        Name           =
        Geom           =        CSG
        Cells          =        [267367]
, Universe
        ID             =        445
        Name           =
        Geom           =        CSG
        Cells          =        [267368]
]" which is not of type "Universe"

According to the documentation, I think this makes sense since openmc.HexLattice.outer

outer (openmc.UniverseBase) – A universe to fill all space outside the lattice

is of type openmc.UniverseBase, not Iterable of openmc.UniverseBase. Based on this, I think currently, one outer per lattice is allowed. If I want something as described above, do I need three lattices? It would be nice to make a single “heterogeneous” 3D lattice (varying the outer) as opposed to 3 stacked lattices, but I’m not sure this is currently supported.

As you suspected, only a single outer universe can be assigned to a lattice. To achieve what you described, you would need to have a separate 2D lattice for each axial layer and then stack them between planes manually to recreate the 3D lattice.

1 Like