openmc.RegularMesh

class openmc.RegularMesh(mesh_id: int | None = None, name: str = '')[source]

A regular Cartesian mesh in one, two, or three dimensions

Parameters:
  • mesh_id (int) – Unique identifier for the mesh

  • name (str) – Name of the mesh

Variables:
  • id (int) – Unique identifier for the mesh

  • name (str) – Name of the mesh

  • dimension (Iterable of int) – The number of mesh cells in each direction (x, y, z).

  • n_dimension (int) – Number of mesh dimensions.

  • lower_left (Iterable of float) – The lower-left corner of the structured mesh. If only two coordinate are given, it is assumed that the mesh is an x-y mesh.

  • upper_right (Iterable of float) – The upper-right corner of the structured mesh. If only two coordinate are given, it is assumed that the mesh is an x-y mesh.

  • bounding_box (openmc.BoundingBox) – Axis-aligned bounding box of the mesh as defined by the upper-right and lower-left coordinates.

  • width (Iterable of float) – The width of mesh cells in each direction.

  • indices (Iterable of tuple) – An iterable of mesh indices for each mesh element, e.g. [(1, 1, 1), (2, 1, 1), …]

build_cells(bc: str | None = None)[source]

Generates a lattice of universes with the same dimensionality as the mesh object. The individual cells/universes produced will not have material definitions applied and so downstream code will have to apply that information.

Parameters:

bc (iterable of {'reflective', 'periodic', 'transmission', 'vacuum', or 'white'}) – Boundary conditions for each of the four faces of a rectangle (if applying to a 2D mesh) or six faces of a parallelepiped (if applying to a 3D mesh) provided in the following order: [x min, x max, y min, y max, z min, z max]. 2-D cells do not contain the z min and z max entries. Defaults to ‘reflective’ for all faces.

Returns:

  • root_cell (openmc.Cell) – The cell containing the lattice representing the mesh geometry; this cell is a single parallelepiped with boundaries matching the outermost mesh boundary with the boundary conditions from bc applied.

  • cells (iterable of openmc.Cell) – The list of cells within each lattice position mimicking the mesh geometry.

property centroids

Return coordinates of mesh element centroids.

Returns:

centroids – Returns a numpy.ndarray representing the mesh element centroid coordinates with a shape equal to (dim1, …, dimn, ndim). X, Y, Z values can be unpacked with xx, yy, zz = np.rollaxis(mesh.centroids, -1).

Return type:

numpy.ndarray

classmethod from_domain(domain: HasBoundingBox, dimension: Sequence[int] | int = 1000, mesh_id: int | None = None, name: str = '')[source]

Create RegularMesh from a domain using its bounding box.

Parameters:
  • domain (HasBoundingBox) – The object passed in will be used as a template for this mesh. The bounding box of the property of the object passed will be used to set the lower_left and upper_right and of the mesh instance

  • dimension (Iterable of int | int) – The number of mesh cells in total or number of mesh cells in each direction (x, y, z). If a single integer is provided, the domain will will be divided into that many mesh cells with roughly equal lengths in each direction (cubes).

  • mesh_id (int) – Unique identifier for the mesh

  • name (str) – Name of the mesh

Returns:

RegularMesh instance

Return type:

openmc.RegularMesh

classmethod from_hdf5(group: Group, mesh_id: int, name: str)[source]

Create mesh from HDF5 group

Parameters:

group (h5py.Group) – Group in HDF5 file

Returns:

Instance of a MeshBase subclass

Return type:

openmc.MeshBase

classmethod from_rect_lattice(lattice: RectLattice, division: int = 1, mesh_id: int | None = None, name: str = '')[source]

Create mesh from an existing rectangular lattice

Parameters:
  • lattice (openmc.RectLattice) – Rectangular lattice used as a template for this mesh

  • division (int) – Number of mesh cells per lattice cell. If not specified, there will be 1 mesh cell per lattice cell.

  • mesh_id (int) – Unique identifier for the mesh

  • name (str) – Name of the mesh

Returns:

RegularMesh instance

Return type:

openmc.RegularMesh

classmethod from_xml_element(elem: Element)[source]

Generate mesh from an XML element

Parameters:

elem (lxml.etree._Element) – XML element

Returns:

Mesh generated from XML element

Return type:

openmc.Mesh

get_homogenized_materials(model: Model, n_samples: int | tuple[int, int, int] = 10000, include_void: bool = True, material_volumes: MeshMaterialVolumes | None = None, **kwargs) list[Material]

Generate homogenized materials over each element in a mesh.

Added in version 0.15.0.

Parameters:
  • model (openmc.Model) – Model containing materials to be homogenized and the associated geometry.

  • n_samples (int or 2-tuple of int) – Total number of rays to sample. The number of rays in each direction is determined by the aspect ratio of the mesh bounding box. When specified as a 3-tuple, it is interpreted as the number of rays in the x, y, and z dimensions.

  • include_void (bool, optional) – Whether homogenization should include voids.

  • material_volumes (MeshMaterialVolumes, optional) – Previously computed mesh material volumes to use for homogenization. If not provided, they will be computed by calling material_volumes().

  • **kwargs – Keyword-arguments passed to material_volumes().

Returns:

Homogenized material in each mesh element

Return type:

list of openmc.Material

material_volumes(model: Model, n_samples: int | tuple[int, int, int] = 10000, max_materials: int = 4, **kwargs) MeshMaterialVolumes

Determine volume of materials in each mesh element.

This method works by raytracing repeatedly through the mesh to count the estimated volume of each material in all mesh elements. Three sets of rays are used: one set parallel to the x-axis, one parallel to the y-axis, and one parallel to the z-axis.

Added in version 0.15.1.

Parameters:
  • model (openmc.Model) – Model containing materials.

  • n_samples (int or 3-tuple of int) – Total number of rays to sample. The number of rays in each direction is determined by the aspect ratio of the mesh bounding box. When specified as a 3-tuple, it is interpreted as the number of rays in the x, y, and z dimensions.

  • max_materials (int, optional) – Estimated maximum number of materials in any given mesh element.

  • **kwargs (dict) – Keyword arguments passed to openmc.lib.init()

Returns:

  • Dictionary-like object that maps material IDs to an array of volumes

  • equal in size to the number of mesh elements.

property midpoint_vertices

Create vertices that lie on the midpoint of element edges

classmethod reset_ids()

Reset counters

to_xml_element()[source]

Return XML representation of the mesh

Returns:

element – XML element containing mesh data

Return type:

lxml.etree._Element

property vertices
Return coordinates of mesh vertices in Cartesian coordinates. Also

see CylindricalMesh.vertices_cylindrical() and SphericalMesh.vertices_spherical() for coordinates in other coordinate systems.

Returns:

vertices – Returns a numpy.ndarray representing the coordinates of the mesh vertices with a shape equal to (dim1 + 1, …, dimn + 1, ndim). X, Y, Z values can be unpacked with xx, yy, zz = np.rollaxis(mesh.vertices, -1).

Return type:

numpy.ndarray

property volumes

Return Volumes for every mesh cell

Returns:

volumes – Volumes

Return type:

numpy.ndarray

write_data_to_vtk(filename: str | PathLike, datasets: dict | None = None, volume_normalization: bool = True, curvilinear: bool = False)

Creates a VTK object of the mesh

Parameters:
  • filename (str) – Name of the VTK file to write.

  • datasets (dict) – Dictionary whose keys are the data labels and values are the data sets. 1D datasets are expected to be extracted directly from statepoint data without reordering/reshaping. Multidimensional datasets are expected to have the same dimensions as the mesh itself with structured indexing in “C” ordering. See the “expand_dims” flag of get_reshaped_data() on reshaping tally data when using MeshFilter’s.

  • volume_normalization (bool, optional) – Whether or not to normalize the data by the volume of the mesh elements.

  • curvilinear (bool) – Whether or not to write curvilinear elements. Only applies to SphericalMesh and CylindricalMesh.

Raises:

ValueError – When the size of a dataset doesn’t match the number of mesh cells

Returns:

a VTK grid object representing the mesh

Return type:

vtk.StructuredGrid or vtk.UnstructuredGrid

Examples

1D data from a tally with only a mesh filter and heating score:

# pass the tally mean property of shape (N, 1, 1) directly to this # method; dimensions of size 1 will automatically removed >>> heating = tally.mean >>> mesh.write_data_to_vtk({‘heating’: heating})

Multidimensional data from a tally with only a mesh

# retrieve a data array with the mesh filter expanded into three # dimensions, ijk; additional dimensions of size one will # automatically be removed >>> heating = tally.get_reshaped_data(expand_dims=True) >>> mesh.write_data_to_vtk({‘heating’: heating})