openmc.Geometry
- class openmc.Geometry(root: UniverseBase | Iterable[Cell] | None = None, merge_surfaces: bool = False, surface_precision: int = 10)[source]
Geometry representing a collection of surfaces, cells, and universes.
- Parameters:
root (openmc.UniverseBase or Iterable of openmc.Cell, optional) – Root universe which contains all others, or an iterable of cells that should be used to create a root universe.
- Variables:
root_universe (openmc.UniverseBase) – Root universe which contains all others
bounding_box (openmc.BoundingBox) – Lower-left and upper-right coordinates of an axis-aligned bounding box of the universe.
merge_surfaces (bool) – Whether to remove redundant surfaces when the geometry is exported.
surface_precision (int) – Number of decimal places to round to for comparing the coefficients of surfaces for considering them topologically equivalent.
- add_volume_information(volume_calc)[source]
Add volume information from a stochastic volume calculation.
- Parameters:
volume_calc (openmc.VolumeCalculation) – Results from a stochastic volume calculation
- clone() Geometry[source]
Create a copy of this geometry with new unique IDs for all of its enclosed materials, surfaces, cells, universes and lattices.
- determine_paths(instances_only=False)[source]
Determine paths through CSG tree for cells and materials.
This method recursively traverses the CSG tree to determine each unique path that reaches every cell and material. The paths are stored in the
Cell.pathsandMaterial.pathsattributes.- Parameters:
instances_only (bool, optional) – If true, this method will only determine the number of instances of each cell and material.
- classmethod from_xml(path: PathLike = 'geometry.xml', materials: PathLike | 'openmc.Materials' | None = 'materials.xml') Geometry[source]
Generate geometry from XML file
- Parameters:
path (PathLike, optional) – Path to geometry XML file
materials (openmc.Materials or PathLike) – Materials used to assign to cells. If PathLike, an attempt is made to generate materials from the provided xml file.
- Returns:
Geometry object
- Return type:
- classmethod from_xml_element(elem, materials=None) Geometry[source]
Generate geometry from an XML element
- Parameters:
elem (lxml.etree._Element) – XML element
materials (openmc.Materials or None) – Materials used to assign to cells. If None, an attempt is made to generate it from the materials.xml file.
- Returns:
Geometry object
- Return type:
- get_all_cells() dict[int, Cell][source]
Return all cells in the geometry.
- Returns:
Dictionary mapping cell IDs to
openmc.Cellinstances- Return type:
- get_all_lattices() dict[int, Lattice][source]
Return all lattices defined
- Returns:
Dictionary mapping lattice IDs to
openmc.Latticeinstances- Return type:
- get_all_material_cells() dict[int, Cell][source]
Return all cells filled by a material
- Returns:
Dictionary mapping cell IDs to
openmc.Cellinstances that are filled with materials or distributed materials.- Return type:
- get_all_material_universes() dict[int, Universe][source]
Return all universes having at least one material-filled cell.
This method can be used to find universes that have at least one cell that is filled with a material or is void.
- Returns:
Dictionary mapping universe IDs to
openmc.Universeinstances with at least one material-filled cell- Return type:
- get_all_materials() dict[int, Material][source]
Return all materials within the geometry.
- Returns:
Dictionary mapping material IDs to
openmc.Materialinstances- Return type:
- get_all_nuclides() list[str][source]
Return all nuclides within the geometry.
- Returns:
Sorted list of all nuclides in materials appearing in the geometry
- Return type:
- get_all_surfaces() dict[int, Surface][source]
Return all surfaces used in the geometry
- Returns:
Dictionary mapping surface IDs to
openmc.Surfaceinstances- Return type:
- get_all_universes() dict[int, Universe][source]
Return all universes in the geometry.
- Returns:
Dictionary mapping universe IDs to
openmc.Universeinstances- Return type:
- get_cells_by_fill_name(name, case_sensitive=False, matching=False) list[Cell][source]
Return a list of cells with fills with matching names.
- Parameters:
- Returns:
Cells with fills matching the queried name
- Return type:
list of openmc.Cell
- get_cells_by_name(name, case_sensitive=False, matching=False) list[Cell][source]
Return a list of cells with matching names.
- Parameters:
- Returns:
Cells matching the queried name
- Return type:
list of openmc.Cell
- get_instances(paths) int | list[int][source]
Return the instance number(s) for a cell/material in a geometry path.
The instance numbers are used as indices into distributed material/temperature arrays and tally distribcell filter arrays.
- Parameters:
paths (str or iterable of str) – The path traversed through the CSG tree to reach a cell or material instance. For example, ‘u0->c10->l20(2,2,1)->u5->c5’ would indicate the cell instance whose first level is universe 0 and cell 10, second level is lattice 20 position (2,2,1), and third level is universe 5 and cell 5.
- Returns:
Instance number(s) for the given path(s)
- Return type:
- get_lattices_by_name(name, case_sensitive=False, matching=False) list[Lattice][source]
Return a list of lattices with matching names.
- Parameters:
- Returns:
Lattices matching the queried name
- Return type:
- get_materials_by_name(name, case_sensitive=False, matching=False) list[Material][source]
Return a list of materials with matching names.
- Parameters:
- Returns:
Materials matching the queried name
- Return type:
- get_surfaces_by_name(name, case_sensitive=False, matching=False) list[Surface][source]
Return a list of surfaces with matching names.
Added in version 0.13.3.
- Parameters:
- Returns:
Surfaces matching the queried name
- Return type:
- get_universes_by_name(name, case_sensitive=False, matching=False) list[Universe][source]
Return a list of universes with matching names.
- Parameters:
- Returns:
Universes matching the queried name
- Return type:
- plot(*args, **kwargs)[source]
Display a slice plot of the geometry.
Added in version 0.14.0.
- 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
CellorMaterialand 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.
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.
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:
- remove_redundant_surfaces() dict[int, Surface][source]
Remove and return all of the redundant surfaces.
Uses surface_precision attribute of Geometry instance for rounding and comparing surface coefficients.
Added in version 0.12.
- Returns:
Dictionary whose keys are the ID of a redundant surface and whose values are the topologically equivalent
openmc.Surfacethat should replace it.- Return type:
redundant_surfaces