openmc.DAGMCUniverse

class openmc.DAGMCUniverse(filename: str | PathLike, universe_id=None, name='', auto_geom_ids=False, auto_mat_ids=False, material_overrides=None)[source]

A reference to a DAGMC file to be used in the model.

Added in version 0.13.0.

Parameters:
  • filename (str) – Path to the DAGMC file used to represent this universe.

  • 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.

  • auto_geom_ids (bool) – Set IDs automatically on initialization (True) or report overlaps in ID space between CSG and DAGMC (False)

  • auto_mat_ids (bool) – Set IDs automatically on initialization (True) or report overlaps in ID space between OpenMC and UWUW materials (False)

  • material_overrides (dict, optional) – A dictionary of material overrides. The keys are material name strings and the values are Iterables of openmc.Material objects. If a material name is found in the DAGMC file, the material will be replaced with the openmc.Material object in the value.

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

  • name (str) – Name of the universe

  • filename (str) – Path to the DAGMC file used to represent this universe.

  • auto_geom_ids (bool) – Set IDs automatically on initialization (True) or report overlaps in ID space between CSG and DAGMC (False)

  • auto_mat_ids (bool) – Set IDs automatically on initialization (True) or report overlaps in ID space between OpenMC and UWUW materials (False)

  • bounding_box (openmc.BoundingBox) –

    Lower-left and upper-right coordinates of an axis-aligned bounding box of the universe.

    Added in version 0.13.1.

  • material_names (list of str) –

    Return a sorted list of materials names that are contained within the DAGMC h5m file. This is useful when naming openmc.Material() objects as each material name present in the DAGMC h5m file must have a matching openmc.Material() with the same name.

    Added in version 0.13.2.

  • n_cells (int) –

    The number of cells in the DAGMC model. This is the number of cells at runtime and accounts for the implicit complement whether or not is it present in the DAGMC file.

    Added in version 0.13.2.

  • n_surfaces (int) –

    The number of surfaces in the model.

    Added in version 0.13.2.

  • material_overrides (dict) –

    A dictionary of material overrides. Keys are cell IDs; values are iterables of openmc.Material objects. The material assignment of each DAGMC cell ID key will be replaced with the Material object in the value. If the value contains multiple Material objects, each Material in the list will be assigned to the corresponding instance of the cell.

    Added in version 0.15.1.

add_cell(cell)[source]

Add a cell to the universe.

Parameters:

cell (openmc.DAGMCCell) – Cell to add

add_material_override(key, overrides=None)[source]

Add a material override to the universe.

Added in version 0.15.

Parameters:
  • key (openmc.DAGMCCell or int) – Cell object or ID of the Cell to override

  • value (openmc.Material or Iterable of openmc.Material) – Material(s) to be applied to the Cell passed as the key

bounded_universe(bounding_cell_id=10000, **kwargs)[source]

Returns an openmc.Universe filled with this DAGMCUniverse and bounded with a cell. Defaults to a box cell with a vacuum surface however this can be changed using the kwargs which are passed directly to DAGMCUniverse.bounding_region().

Parameters:

bounding_cell_id (int) – The cell ID number to use for the bounding cell, defaults to 10000 to reduce the chance of overlapping ID numbers with the DAGMC geometry.

Returns:

Universe instance

Return type:

openmc.Universe

bounding_region(bounded_type: str = 'box', boundary_type: str = 'vacuum', starting_id: int = 10000, padding_distance: float = 0.0)[source]

Creates a either a spherical or box shaped bounding region around the DAGMC geometry.

Added in version 0.13.1.

Parameters:
  • bounded_type (str) – The type of bounding surface(s) to use when constructing the region. Options include a single spherical surface (sphere) or a rectangle made from six planes (box).

  • boundary_type (str) – Boundary condition that defines the behavior for particles hitting the surface. Defaults to vacuum boundary condition. Passed into the surface construction.

  • starting_id (int) – Starting ID of the surface(s) used in the region. For bounded_type ‘box’, the next 5 IDs will also be used. Defaults to 10000 to reduce the chance of an overlap of surface IDs with the DAGMC geometry.

  • padding_distance (float) – Distance between the bounding region surfaces and the minimal bounding box. Allows for the region to be larger than the DAGMC geometry.

Returns:

Region instance

Return type:

openmc.Region

create_xml_subelement(xml_element, memo=None)[source]

Add the universe xml representation to an incoming xml element

Parameters:
  • xml_element (lxml.etree._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.

Return type:

None

classmethod from_hdf5(group)[source]

Create DAGMC universe from HDF5 group

Parameters:

group (h5py.Group) – Group in HDF5 file

Returns:

DAGMCUniverse instance

Return type:

openmc.DAGMCUniverse

classmethod from_xml_element(elem, mats=None)[source]

Generate DAGMC universe from XML element

Parameters:
Returns:

DAGMCUniverse instance

Return type:

openmc.DAGMCUniverse

plot(*args, **kwargs)[source]

Display a slice plot of the DAGMCUniverse.

Parameters:
  • origin (iterable of float) – Coordinates at the origin of the plot. If left as None, the center of the bounding box will be used to attempt to ascertain the origin with infinite values being replaced by 0.

  • width (iterable of float) – Width of the plot in each basis direction. If left as none then the width of the bounding box will be used to attempt to ascertain the plot width. Defaults to (10, 10) if the bounding box contains inf values.

  • pixels (Iterable of int or int) – If an iterable of ints is provided then this directly sets the number of pixels to use in each basis direction. If a single int is provided then this sets the total number of pixels in the plot and the number of pixels in each basis direction is calculated from this total and the image aspect ratio based on the width argument.

  • 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 integers in the range [0, 255], for example:

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

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

  • openmc_exec (str) – Path to OpenMC executable.

  • axes (matplotlib.Axes) –

    Axes to draw to

    Added in version 0.13.1.

  • legend (bool) –

    Whether a legend showing material or cell names should be drawn

    Added in version 0.14.0.

  • axis_units ({'km', 'm', 'cm', 'mm'}) –

    Units used on the plot axis

    Added in version 0.14.0.

  • outline (bool or str) –

    Whether outlines between color boundaries should be drawn. If set to ‘only’, only outlines will be drawn.

    Added in version 0.14.0.

  • show_overlaps (bool) – Indicate whether or not overlapping regions are shown. Default is False.

  • overlap_color (Iterable of int or str) – Color to apply to overlapping regions. Default is red.

  • n_samples (int, optional) – The number of source particles to sample and add to plot. Defaults to None which doesn’t plot any particles on the plot.

  • plane_tolerance (float) – When plotting a plane the source locations within the plane +/- the plane_tolerance will be included and those outside of the plane_tolerance will not be shown

  • legend_kwargs (dict) –

    Keyword arguments passed to matplotlib.pyplot.legend().

    Added in version 0.14.0.

  • source_kwargs (dict, optional) – Keyword arguments passed to matplotlib.pyplot.scatter().

  • contour_kwargs (dict, optional) – Keyword arguments passed to matplotlib.pyplot.contour().

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

Returns:

Axes containing resulting image

Return type:

matplotlib.axes.Axes

remove_cell(cell)[source]

Remove a cell from the universe.

Parameters:

cell (openmc.Cell) – Cell to remove

replace_material_assignment(material_name: str, material: Material)[source]

Replace a material assignment within the DAGMC universe.

Replace the material assignment of all cells filled with a material in the DAGMC universe. The universe must be synchronized in an initialized Model (see sync_dagmc_cells()) before calling this method.

Added in version 0.15.1.

Parameters:
  • material_name (str) – Material name to replace

  • material (openmc.Material) – Material to replace the material_name with

sync_dagmc_cells(mats: Iterable[Material])[source]

Synchronize DAGMC cell information between Python and C API

Added in version 0.15.1.

Parameters:

mats (iterable of openmc.Material) – Iterable of materials to assign to the DAGMC cells