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
- fcallable object
The function that performs the computation.
- meshMesh, optional
The PyNE mesh to tag.
- namestr, optional
The name of the tag.
- docstr, optional
Documentation string for the tag.
-
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
- meshMesh, optional
The PyNE mesh to tag.
- namestr, optional
The name of the tag.
- docstr, 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
- meshMesh, optional
The PyNE mesh to tag.
- namestr, optional
The name of the tag.
- docstr, 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 a PyMOAB core instance and contains methods for various mesh operations. Special methods exploit the properties of structured mesh.
- Attributes
- meshPyMOAB core instance
- structuredbool
True for structured mesh.
- structured_coordslist of lists
A list containing lists of x_points, y_points and z_points that make up a structured mesh.
- structured_orderingstr
A three character string denoting the iteration order of the mesh (e.g. ‘xyz’, meaning z changest fastest, then y, then x.)
- Parameters
- meshPyMOAB core instance or str, optional
Either a PyMOAB core instance or a file name of a PyMOAB mesh file.
- structuredbool, optional
True for structured mesh.
- structured_coordslist of lists, optional
A list containing lists of x_points, y_points and z_points that make up a structured mesh.
- structured_setPyMOAB entity set handle, optional
A preexisting structured entity set on an PyMOAB core instance with a “BOX_DIMS” tag.
- structured_orderingstr, optional
A three character string denoting the iteration order of the mesh (e.g. ‘xyz’, meaning z changest fastest, then y, then x.)
- matsMaterialLibrary 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 PyMOAB core instance by specifying: <mesh>
From mesh file by specifying: <mesh_file>
- Structured mesh instantiation:
From PyMOAB core 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 a PyMOAB instance with multiple entity sets by specifying <mesh>, <structured_set>, structured=True.
From coordinates by specifying <structured_coords>, structured=True, and optional pre-existing PyMOAB core instance <mesh>
The “BOX_DIMS” tag on PyMOAB core instances containing structured mesh is a vector of floats in 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
(self, 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_fracsstructured 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_matsdict
Maps geometry cell numbers to Material objects that represent what material each cell is made of.
Returns the volume element tags in common between self and other.
-
elem_volume
(self, ve)[source]¶ Get the volume of a hexahedral or tetrahedral volume element
Approaches are adapted from MOAB’s measure.cpp.
- Parameters
- vePyMOAB EntitySet handle
A volume element
- Returns
- ..float
Element’s volume. Returns None if volume is not a hex or tet.
-
iter_structured_idx
(self, 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
- orderstr, optional
The requested iteration order (e.g. ‘zyx’).
-
structured_get_divisions
(self, 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
(self, i, j, k)[source]¶ Return the handle for the (i,j,k)’th hexahedron in the mesh
-
structured_hex_volume
(self, i, j, k)[source]¶ Return the volume of the (i,j,k)’th hexahedron in the mesh
-
structured_iterate_hex
(self, 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 mehset_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
(self, 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
(self, 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
(self, 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
- namestr
The tag name
- valueoptional
The value to initialize the tag with, skipped if None.
- tagtypeTag or str, optional
The type of tag this should be any of the following classes or strings are accepted: NativeMeshTag, MetadataTag, ComputedTag, ‘nat_mesh’, ‘metadata’, or ‘computed’.
- docstr, optional
The tag documentation string.
- sizeint, optional
The size of the tag. This only applies to NativeMeshTags.
- dtypenumpy dtype, optional
The data type of the tag. This only applies to NativeMeshTags. See PyMOAB for more details.
-
tag_cell_fracs
(self, cell_fracs)[source]¶ This function uses the output from dagmc.discretize_geom() and a mapping of geometry cells to set the cell_fracs_tag.
- Parameters
- cell_fracsstructured 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.
-
class
pyne.mesh.
MeshTally
[source]¶ This class stores all information from a single mesh tally that exists within some meshtal or state point file. Header information is stored as attributes and the “mesh” attribute is a PyNE mesh object tagged with all result and relative error data. This class inherits from StatMesh, exposing all statistical mesh manipulation methods.
Notes
All Mesh/StatMesh attributes are also present via a super() call to StatMesh.__init__().
- Attributes
- tally_numberint
The tally number. For mesh tally from MCNP, it must end with 4 (e.g. 4, 14, 214). For mesh tally from OpenMC, it could be any int.
- particlestring
Either “neutron” for a neutron mesh tally or “photon” for a photon mesh tally.
- dose_responsebool
True if the tally is modified by a dose response function.
- x_boundstuple of floats
The locations of mesh vertices in the x direction.
- y_boundstuple of floats
The locations of mesh vertices in the y direction.
- z_boundstuple of floats
The locations of mesh vertices in the z direction.
- dimslist
Dimensions of the mesh.
- num_vesint
Number of volume elements.
- e_boundstuple of floats
The minimum and maximum bounds for energy bins.
- num_e_groups: int
Number of energy groups.
- mesh :
An PyMOAB core instance tagged with all results and relative errors.
- tag_namesiterable
Four strs that specify the tag names for the results, relative errors, total results, and total relative error.
Create an empty MeshTally object and set default values.
-
tag_flux_error_from_tally_results
(self, result, rel_err, res_tot, rel_err_tot)[source]¶ This function uses the output tally result, rel_err, res_tot and the rel_err_tot to set the flux and error tags.
- Parameters
- resultnumpy array
This numpy array contains the flux data read from MCNP meshtal or OpenMC state point file. The shape of this numpy array is (ves, num_e_groups).
- rel_errnumpy array
This numpy array contains the relative error data read from MCNP meshtal or OpenMC state point file. The shape of this numpy array is (num_ves, num_e_groups).
- res_totlist
The total results.
- rel_err_totlist
Relative error of total results.
-
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
- meshMesh, optional
The PyNE mesh to tag.
- namestr, optional
The name of the tag.
- docstr, optional
Documentation string for the tag.
-
class
pyne.mesh.
NativeMeshTag
(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 a PyMOAB core instance. This makes the following expressions equivalent for a given PyNE/PyNE Mesh tag name:
mesh.tag_name[i] == mesh.mesh.tag_get_data(mesh.mesh.tag_get_handle(name), mesh.mesh.get_entities_by_type( mesh.mesh.get_root_set(), types.MBHEX))[i]
It also adds slicing, fancy indexing, boolean masking, and broadcasting features to this process.
- Parameters
- sizeint, optional
The number of elements of type dtype that this tag stores.
- dtypenp.dtype or similar, optional
The data type of this tag from int, float, and byte. See PyMOAB tags for more details.
- defaultdtype or None, optional
The default value to fill this tag with upon creation. If None, then the tag is created empty.
- meshMesh, optional
The PyNE mesh to tag.
- namestr, optional
The name of the tag.
- docstr, optional
Documentation string for the tag.
-
class
pyne.mesh.
StatMesh
(mesh=None, structured=False, structured_coords=None, structured_set=None, mats=())[source]¶ This class extends the basic Mesh class by modifying the standard mathematical operations that are performed on multiple meshes.
A StatMesh assumes that each value being operated upon also has a statistical error associaed with it, and forces operations on the statistical error as well. For any tag with name tag_name the StatMesh assumes that there is also a tag with name tag_name_rel_error.
For example, when to quantities are added together, c = a + b, the statistical error of c is found by combining the statistical errors of a and b.
- Parameters
- meshPyMOAB core instance or str, optional
Either a PyMOAB core instance or a file name of a PyMOAB mesh file.
- structuredbool, optional
True for structured mesh.
- structured_coordslist of lists, optional
A list containing lists of x_points, y_points and z_points that make up a structured mesh.
- structured_setPyMOAB entity set handle, optional
A preexisting structured entity set on an PyMOAB core instance with a “BOX_DIMS” tag.
- structured_orderingstr, optional
A three character string denoting the iteration order of the mesh (e.g. ‘xyz’, meaning z changest fastest, then y, then x.)
- matsMaterialLibrary 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 PyMOAB core instance by specifying: <mesh>
From mesh file by specifying: <mesh_file>
- Structured mesh instantiation:
From PyMOAB core 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 a PyMOAB instance with multiple entity sets by specifying <mesh>, <structured_set>, structured=True.
From coordinates by specifying <structured_coords>, structured=True, and optional pre-existing PyMOAB core instance <mesh>
The “BOX_DIMS” tag on PyMOAB core instances containing structured mesh is a vector of floats in 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.
-
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, PyMOAB tags, and material metadata attributes.
- Parameters
- meshMesh, optional
The PyNE mesh to tag.
- namestr, optional
The name of the tag.
- docstr, optional
Documentation string for the tag.