openmc.Universe

class openmc.Universe(universe_id=None, name='', cells=None)[source]

A collection of cells that can be repeated.

Parameters
  • universe_id (int, optional) – Unique identifier of the universe. If not specified, an identifier will automatically be assigned

  • name (str, optional) – Name of the universe. If not specified, the name is the empty string.

  • cells (Iterable of openmc.Cell, optional) – Cells to add to the universe. By default no cells are added.

Variables
  • id (int) – Unique identifier of the universe

  • name (str) – Name of the universe

  • cells (collections.OrderedDict) – Dictionary whose keys are cell IDs and values are Cell instances

  • volume (float) – Volume of the universe in cm^3. This can either be set manually or calculated in a stochastic volume calculation and added via the Universe.add_volume_information() method.

  • bounding_box (2-tuple of numpy.array) – Lower-left and upper-right coordinates of an axis-aligned bounding box of the universe.

add_cell(cell)[source]

Add a cell to the universe.

Parameters

cell (openmc.Cell) – Cell to add

add_cells(cells)[source]

Add multiple cells to the universe.

Parameters

cells (Iterable of openmc.Cell) – Cells to add

clear_cells()[source]

Remove all cells from the universe.

create_xml_subelement(xml_element, memo=None)[source]

Add the universe xml representation to an incoming xml element

Parameters
  • xml_element (xml.etree.ElementTree.Element) – XML element to be added to

  • memo (set or None) – A set of object id’s representing geometry entities already written to the xml_element. This parameter is used internally and should not be specified by users.

Returns

Return type

None

find(point)[source]

Find cells/universes/lattices which contain a given point

Parameters

point (3-tuple of float) – Cartesian coordinates of the point

Returns

Sequence of universes, cells, and lattices which are traversed to find the given point

Return type

list

classmethod from_hdf5(group, cells)[source]

Create universe from HDF5 group

Parameters
  • group (h5py.Group) – Group in HDF5 file

  • cells (dict) – Dictionary mapping cell IDs to instances of openmc.Cell.

Returns

Universe instance

Return type

openmc.Universe

get_all_cells(memo=None)[source]

Return all cells that are contained within the universe

Returns

cells – Dictionary whose keys are cell IDs and values are Cell instances

Return type

collections.OrderedDict

get_all_materials(memo=None)[source]

Return all materials that are contained within the universe

Returns

materials – Dictionary whose keys are material IDs and values are Material instances

Return type

collections.OrderedDict

get_all_universes()[source]

Return all universes that are contained within this one.

Returns

universes – Dictionary whose keys are universe IDs and values are Universe instances

Return type

collections.OrderedDict

get_nuclide_densities()[source]

Return all nuclides contained in the universe

Returns

nuclides – Dictionary whose keys are nuclide names and values are 2-tuples of (nuclide, density)

Return type

collections.OrderedDict

get_nuclides()[source]

Returns all nuclides in the universe

Returns

nuclides – List of nuclide names

Return type

list of str

plot(origin=(0.0, 0.0, 0.0), width=(1.0, 1.0), pixels=(200, 200), basis='xy', color_by='cell', colors=None, seed=None, openmc_exec='openmc', **kwargs)[source]

Display a slice plot of the universe.

Parameters
  • origin (Iterable of float) – Coordinates at the origin of the plot

  • width (Iterable of float) – Width of the plot in each basis direction

  • pixels (Iterable of int) – Number of pixels to use in each basis direction

  • basis ({'xy', 'xz', 'yz'}) – The basis directions for the plot

  • color_by ({'cell', 'material'}) – Indicate whether the plot should be colored by cell or by material

  • colors (dict) –

    Assigns colors to specific materials or cells. Keys are instances of Cell or Material and values are RGB 3-tuples, RGBA 4-tuples, or strings indicating SVG color names. Red, green, blue, and alpha should all be floats in the range [0.0, 1.0], for example:

    # Make water blue
    water = openmc.Cell(fill=h2o)
    universe.plot(..., colors={water: (0., 0., 1.))
    

  • seed (int) – Seed for the random number generator

  • openmc_exec (str) –

    Path to OpenMC executable.

    New in version 0.13.1.

  • **kwargs – Keyword arguments passed to matplotlib.pyplot.imshow()

Returns

Resulting image

Return type

matplotlib.image.AxesImage

remove_cell(cell)[source]

Remove a cell from the universe.

Parameters

cell (openmc.Cell) – Cell to remove