PyNE Mesh – pyne.mesh

exception pyne.mesh.MeshError[source]

Errors related to instantiating mesh objects and utilizing their methods.

class pyne.mesh.ComputedTag(f, mesh=None, name=None, doc=None)[source]

A mesh tag which looks itself up by calling a function (or other callable) with the following signature:

def f(mesh, i):
    """mesh is a pyne.mesh.Mesh() object and i is the volume element
    index to compute.
    """
    # ... do some work ...
    return anything_you_want

This makes the following expressions equivalent for a given computed tag name:

mesh.name[i] == f(mesh, i)

It also adds slicing, fancy indexing, boolean masking, and broadcasting features to this process.

Notes

The results of computed tags are not stored and the function object itself is also not persisted. Therefore, you must manually re-tag the mesh with the desired functions each session.

Parameters:

f : callable object

The function that performs the computation.

mesh : Mesh, optional

The PyNE mesh to tag.

name : str, optional

The name of the tag.

doc : str, optional

Documentation string for the tag.

class pyne.mesh.IMeshTag(size=1, dtype=’f8’, default=0.0, mesh=None, name=None, doc=None)[source]

A mesh tag which looks itself up as a tag on the iMesh.Mesh instance. This makes the following expressions equivalent for a given iMesh.Mesh tag name:

mesh.name[i] == mesh.mesh.getTagHandle(name)[list(mesh.mesh.iterate(
                        iBase.Type.region, iMesh.Topology.all))[i]]

It also adds slicing, fancy indexing, boolean masking, and broadcasting features to this process.

Parameters:

size : int, optional

The number of elements of type dtype that this tag stores.

dtype : np.dtype or similar, optional

The data type of this tag from int, float, and byte. See PyTAPS tags for more details.

default : dtype or None, optional

The default value to fill this tag with upon creation. If None, then the tag is created empty.

mesh : Mesh, optional

The PyNE mesh to tag.

name : str, optional

The name of the tag.

doc : str, optional

Documentation string for the tag.

expand()[source]

This function creates a group of scalar tags from a vector tag. For a vector tag named <tag_name> of length N, scalar tags in the form:

<tag_name>_000, <tag_name>_001, <tag_name>_002… <tag_name>_N

are created and the data is tagged accordingly.

class pyne.mesh.MaterialMethodTag(mesh=None, name=None, doc=None)[source]

A mesh tag which looks itself up by calling a material method which takes no arguments. This makes the following expressions equivalent for a given material method name:

mesh.name[i] == mesh.mats[i].name()

It also adds slicing, fancy indexing, boolean masking, and broadcasting features to this process.

Parameters:

mesh : Mesh, optional

The PyNE mesh to tag.

name : str, optional

The name of the tag.

doc : str, optional

Documentation string for the tag.

class pyne.mesh.MaterialPropertyTag(mesh=None, name=None, doc=None)[source]

A mesh tag which looks itself up as a material property (attribute). This makes the following expressions equivalent for a given material property name:

mesh.name[i] == mesh.mats[i].name

It also adds slicing, fancy indexing, boolean masking, and broadcasting features to this process.

Parameters:

mesh : Mesh, optional

The PyNE mesh to tag.

name : str, optional

The name of the tag.

doc : str, optional

Documentation string for the tag.

class pyne.mesh.Mesh(mesh=None, structured=False, structured_coords=None, structured_set=None, structured_ordering=’xyz’, mats=())[source]

This class houses an iMesh instance and contains methods for various mesh operations. Special methods exploit the properties of structured mesh.

Attributes

mesh (iMesh instance)
structured (bool) True for structured mesh.
structured_coords (list of lists) A list containing lists of x_points, y_points and z_points that make up a structured mesh.
structured_ordering (str) A three character string denoting the iteration order of the mesh (e.g. ‘xyz’, meaning z changest fastest, then y, then x.)
Parameters:

mesh : iMesh instance or str, optional

Either an iMesh instance or a file name of file containing an iMesh instance.

structured : bool, optional

True for structured mesh.

structured_coords : list of lists, optional

A list containing lists of x_points, y_points and z_points that make up a structured mesh.

structured_set : iMesh entity set handle, optional

A preexisting structured entity set on an iMesh instance with a “BOX_DIMS” tag.

structured_ordering : str, optional

A three character string denoting the iteration order of the mesh (e.g. ‘xyz’, meaning z changest fastest, then y, then x.)

mats : MaterialLibrary or dict or Materials or None, optional

This is a mapping of volume element handles to Material objects. If mats is None, then no empty materials are created for the mesh.

Unstructured mesh instantiation:
  • From iMesh instance by specifying: <mesh>
  • From mesh file by specifying: <mesh_file>
Structured mesh instantiation:
  • From iMesh instance with exactly 1 entity set (with BOX_DIMS tag) by specifying <mesh> and structured = True.
  • From mesh file with exactly 1 entity set (with BOX_DIMS tag) by specifying <mesh_file> and structured = True.
  • From an imesh instance with multiple entity sets by specifying <mesh>, <structured_set>, structured=True.
  • From coordinates by specifying <structured_coords>, structured=True, and optional preexisting iMesh instance <mesh>

The “BOX_DIMS” tag on iMesh instances containing structured mesh is a vector of floats it the following form: [i_min, j_min, k_min, i_max, j_max, k_max] where each value is a volume element index number. Typically volume elements should be indexed from 0. The “BOX_DIMS” information is stored in self.dims.

cell_fracs_to_mats(cell_fracs, cell_mats)[source]

This function uses the output from dagmc.discretize_geom() and a mapping of geometry cells to Materials to assign materials to each mesh volume element.

Parameters:

cell_fracs : structured array

The output from dagmc.discretize_geom(). A sorted, one dimensional array, each entry containing the following fields:

idx:int The volume element index.
cell:int The geometry cell number.
vol_frac:float The volume fraction of the cell withing the mesh ve.
rel_error:float The relative error associated with the volume fraction.

The array must be sorted with respect to both idx and cell, with cell changing fastest.

cell_mats : dict

Maps geometry cell numbers to Material objects that represent what material each cell is made of.

common_ve_tags(other)[source]

Returns the volume element tags in common between self and other.

elem_volume(ve)[source]

Get the volume of a hexahedral or tetrahedral volume element

Approaches are adapted from MOAB’s measure.cpp.

Parameters:

ve : iMesh.Mesh.EntitySet

A volume element

Returns:

.. : float

Element’s volume. Returns None if volume is not a hex or tet.

iter_structured_idx(order=None)[source]

Return an iterater object of volume element indexes (idx) for any iteration order. Note that idx is assigned upon instantiation in the order of the structured_ordering attribute. This method is meant to be used when the order argument is different from structured_ordering. When they are the same, the iterator (0, 1, 2, … N-1) is returned.

Parameters:

order : str, optional

The requested iteration order (e.g. ‘zyx’).

iter_ve()[source]

Returns an iterator that yields on the volume elements.

structured_get_divisions(dim)[source]

Get the mesh divisions on a given dimension

Given a dimension “x”, “y”, or “z”, return a list of the mesh vertices along that dimension.

structured_get_hex(i, j, k)[source]

Return the handle for the (i,j,k)’th hexahedron in the mesh

structured_get_vertex(i, j, k)[source]

Return the handle for (i,j,k)’th vertex in the mesh

structured_hex_volume(i, j, k)[source]

Return the volume of the (i,j,k)’th hexahedron in the mesh

structured_iterate_hex(order=’zyx’, **kw)[source]

Get an iterator over the hexahedra of the mesh

The order argument specifies the iteration order. It must be a string of 1-3 letters from the set (x,y,z). The rightmost letter is the axis along which the iteration will advance the most quickly. Thus “zyx” – x coordinates changing fastest, z coordinates changing least fast– is the default, and is identical to the order that would be given by the structured_set.iterate() function.

When a dimension is absent from the order, iteration will proceed over only the column in the mesh that has the lowest corresonding (i/j/k) coordinate. Thus, with order “xy,” iteration proceeds over the i/j plane of the structured mesh with the smallest k coordinate.

Specific slices can be specified with keyword arguments:

Keyword args:

x: specify one or more i-coordinates to iterate over.
y: specify one or more j-coordinates to iterate over.
z: specify one or more k-coordinates to iterate over.

Examples:

structured_iterate_hex(): equivalent to iMesh iterator over hexes
                          in mesh
structured_iterate_hex("xyz"): iterate over entire mesh, with
                               k-coordinates changing fastest,
                               i-coordinates least fast.
structured_iterate_hex("yz", x=3): Iterate over the j-k plane of the
                                   mesh whose i-coordinate is 3, with
                                   k values changing fastest.
structured_iterate_hex("z"): Iterate over k-coordinates, with
                             i=dims.imin and j=dims.jmin
structured_iterate_hex("yxz", y=(3,4)): Iterate over all hexes with
                              j-coordinate = 3 or 4.  k-coordinate
                              values change fastest, j-values least
                              fast.
structured_iterate_hex_volumes(order=’zyx’, **kw)[source]

Get an iterator over the volumes of the mesh hexahedra

See structured_iterate_hex() for an explanation of the order argument and the available keyword arguments.

structured_iterate_vertex(order=’zyx’, **kw)[source]

Get an iterator over the vertices of the mesh

See structured_iterate_hex() for an explanation of the order argument and the available keyword arguments.

tag(name, value=None, tagtype=None, doc=None, size=None, dtype=None)[source]

Adds a new tag to the mesh, guessing the approriate place to store the data.

Parameters:

name : str

The tag name

value : optional

The value to initialize the tag with, skipped if None.

tagtype : Tag or str, optional

The type of tag this should be any of the following classes or strings are accepted: IMeshTag, MetadataTag, ComputedTag, ‘imesh’, ‘metadata’, or ‘computed’.

doc : str, optional

The tag documentation string.

size : int, optional

The size of the tag. This only applies to IMeshTags.

dtype : numpy dtype, optional

The data type of the tag. This only applies to IMeshTags. See PyTAPS for more details.

ve_center(ve)[source]

Finds the point at the center of any tetrahedral or hexahedral mesh volume element.

Parameters:

ve : iMesh entity handle

Any mesh volume element.

Returns:

center : tuple

The (x, y, z) coordinates of the center of the mesh volume element.

write_hdf5(filename)[source]

Writes the mesh to an hdf5 file.

class pyne.mesh.MetadataTag(mesh=None, name=None, doc=None)[source]

A mesh tag which looks itself up as a material metadata attribute. Tags of this are untyped and may have any size. Use this for catch-all tags. This makes the following expressions equivalent for a given material property.

name:

mesh.name[i] == mesh.mats[i].metadata['name']

It also adds slicing, fancy indexing, boolean masking, and broadcasting features to this process.

Parameters:

mesh : Mesh, optional

The PyNE mesh to tag.

name : str, optional

The name of the tag.

doc : str, optional

Documentation string for the tag.

class pyne.mesh.Tag(mesh=None, name=None, doc=None)[source]

A mesh tag, which acts as a descriptor on the mesh. This dispatches access to intrinsic material properties, the iMesh.Mesh tags, and material metadata attributes.

Parameters:

mesh : Mesh, optional

The PyNE mesh to tag.

name : str, optional

The name of the tag.

doc : str, optional

Documentation string for the tag.