Universes#
MontePy supports MCNP universes as well.
problem.universes will contain all universes in a problem.
These are stored in Universes as Universe instances.
If a cell is not assigned to any universe it will be assigned to Universe 0, not None, while reading in the input file.
To change what cells are in a universe you can set this at the cell level.
This is done to prevent a cell from being assigned to multiple universes
problem = montepy.read_input("tests/inputs/test.imcnp")
universe = problem.universes[350]
for cell in problem.cells[1:5]:
cell.universe = universe
We can confirm this worked with the generator universe.cells:
>>> [cell.number for cell in universe.cells]
[1, 2, 3, 5]
Claiming Cells#
The Universe class also has the method: claim().
This is a shortcut to do the above code.
For all cells passed (either as a single Cell, a list of cells, or a Cells instance)
will be removed from their current universe, and moved to this universe.
This simplifies the above code to just being:
universe = problem.universes[350]
universe.claim(problem.cells[1:5])
Creating a New Universe#
Creating a new universe is very straight forward. You just need to initialize it with a new number, and then add it to the problem:
universe = montepy.Universe(333)
problem.universes.append(universe)
Now you can add cells to this universe as you normally would.
Note
A universe with no cells assigned will not be written out to the MCNP input file, and will “disappear”.
Note
Universe number collisions are not checked for when a universe is created,
but only when it is added to the problem.
Make sure to plan accordingly, and consider using request_number().
Filling Cells#
What’s the point of creating a universe if you can’t fill a cell with it, and therefore use it?
Filling is handled by the Fill object in cell.fill.
To fill a cell with a specific universe you can just run:
cell = problem.cells[2]
cell.fill.universe = universe
This will then fill the cell with a single universe with no transform. You can also easy apply a transform to the filling universe with:
import numpy as np
transform = montepy.data_inputs.transform.Transform(number=5)
transform.displacement_vector = np.array([1, 2, 0])
cell.fill.transform = transform
Note
MCNP supports some rather complicated cell filling systems. Mainly the ability to fill a cell with different universes for every lattice site, and to create an “anonymous transform” in the fill card.
MontePy can understand and manipulate fills with these features in the input. However, generating these from scratch may be cumbersome. If you use this feature, and have input on how to make it more user friendly, please reach out to the developers.
References#
See the following cell properties for more details: