mckit_meshes package¶
Subpackages¶
- mckit_meshes.cli package
- mckit_meshes.mesh package
- Submodules
- mckit_meshes.mesh.geometry_spec module
AbstractGeometrySpecAbstractGeometrySpec.bins_shapeAbstractGeometrySpec.bins_sizeAbstractGeometrySpec.boundariesAbstractGeometrySpec.boundaries_shapeAbstractGeometrySpec.calc_cell_centers()AbstractGeometrySpec.cylinderAbstractGeometrySpec.get_mean_square_distance_weights()AbstractGeometrySpec.get_origin()AbstractGeometrySpec.local_coordinates()AbstractGeometrySpec.print_geom()AbstractGeometrySpec.print_specification()AbstractGeometrySpec.select_indexes()AbstractGeometrySpec.surrounds_point()
AbstractGeometrySpecDataCartesianGeometrySpecCartesianGeometrySpec.calc_cell_centers()CartesianGeometrySpec.cylinderCartesianGeometrySpec.get_mean_square_distance_weights()CartesianGeometrySpec.get_origin()CartesianGeometrySpec.local_coordinates()CartesianGeometrySpec.originCartesianGeometrySpec.print_geom()CartesianGeometrySpec.xCartesianGeometrySpec.yCartesianGeometrySpec.z
CylinderGeometrySpecCylinderGeometrySpec.axsCylinderGeometrySpec.vecCylinderGeometrySpec.__init__()CylinderGeometrySpec.adjust_axs_vec_for_mcnp()CylinderGeometrySpec.axsCylinderGeometrySpec.binsCylinderGeometrySpec.calc_cell_centers()CylinderGeometrySpec.cylinderCylinderGeometrySpec.get_mean_square_distance_weights()CylinderGeometrySpec.get_origin()CylinderGeometrySpec.local_coordinates()CylinderGeometrySpec.originCylinderGeometrySpec.print_geom()CylinderGeometrySpec.rCylinderGeometrySpec.thetaCylinderGeometrySpec.vecCylinderGeometrySpec.z
arrays_equal()as_float_array()compute_intervals_and_coarse_bins()format_floats()select_indexes()
- Module contents
- mckit_meshes.utils package
Submodules¶
mckit_meshes.fmesh module¶
Classes and functions for operations with fmesh tallies.
- class mckit_meshes.fmesh.FMesh[source]¶
Bases:
objectFmesh tally.
Class to load MCNP FMESH output file, process and write in various formats. Processing includes normalization, merging and conversion to weights mesh.
- Attrs:
- NPZ_MARK: Signature to be stored in the of meta entry in a npz file.
This is used to check that the file is for FMesh object.
NPZ_FORMAT: Identifies version of format of data stored in npz file.
- exception FMeshError[source]¶
Bases:
RuntimeErrorFMesh class specific exception.
- NPZ_FORMAT = np.int16(4)¶
- NPZ_MARK = np.int16(5445)¶
- __init__(name, kind, geometry_spec, ebins, data, errors, totals=None, totals_err=None, comment=None)[source]¶
Construct FMesh instance object.
- Parameters:
name (
int) – FMESH tally numberkind (
int|ParticleKind) – neutron, photon or generic number if not a particle kindgeometry_spec (
AbstractGeometrySpec) – mesh geometry specificationebins (
Union[Buffer,_SupportsArray[dtype[Any]],_NestedSequence[_SupportsArray[dtype[Any]]],complex,bytes,str,_NestedSequence[complex|bytes|str]]) – Energy bin boundaries.data (
Union[Buffer,_SupportsArray[dtype[Any]],_NestedSequence[_SupportsArray[dtype[Any]]],complex,bytes,str,_NestedSequence[complex|bytes|str]]) – Data values at centers of mesh cells. Shape (Ne-1)x(Nx-1)x(Ny-1)x(Nz-1), where Ne, Nx, Ny and Nz - the number of corresponding bin boundaries.errors (
Union[Buffer,_SupportsArray[dtype[Any]],_NestedSequence[_SupportsArray[dtype[Any]]],complex,bytes,str,_NestedSequence[complex|bytes|str]]) – Relative errors of corresponding data values. Shape (Ne-1)x(Nx-1)x(Ny-1)x(Nz-1), where Ne, Nx, Ny and Nz - the number of corresponding bin boundaries.totals (
Union[Buffer,_SupportsArray[dtype[Any]],_NestedSequence[_SupportsArray[dtype[Any]]],complex,bytes,str,_NestedSequence[complex|bytes|str],None]) – Can be provided with ‘Total’ data from mesh file, if there are more than 1 energy bin, optional.totals_err (
Union[Buffer,_SupportsArray[dtype[Any]],_NestedSequence[_SupportsArray[dtype[Any]]],complex,bytes,str,_NestedSequence[complex|bytes|str],None]) – Can be provided with data from mesh file, if there are more than 1 energy bin, optional.comment (
str|None) – Comment from a meshtal file (content of FC card in MCNP model).
- Return type:
None
- format_cylinder_origin_and_axis_label()[source]¶
Format the first string for cylinder mesh.
- Return type:
- property geometry_spec: CartesianGeometrySpec | CylinderGeometrySpec | AbstractGeometrySpec¶
- get_spectrum(x, y, z)[source]¶
Gets energy spectrum at the specified point.
- Parameters:
- Return type:
tuple[Union[Buffer,_SupportsArray[dtype[Any]],_NestedSequence[_SupportsArray[dtype[Any]]],complex,bytes,str,_NestedSequence[complex|bytes|str]],Union[Buffer,_SupportsArray[dtype[Any]],_NestedSequence[_SupportsArray[dtype[Any]]],complex,bytes,str,_NestedSequence[complex|bytes|str]],Union[Buffer,_SupportsArray[dtype[Any]],_NestedSequence[_SupportsArray[dtype[Any]]],complex,bytes,str,_NestedSequence[complex|bytes|str]]] |None- Returns:
- ebins, data, err or None
Energy bin boundaries, group energy spectrum and relative errors.
- get_totals(*, x=None, y=None, z=None)[source]¶
Get total values for specified grid points.
If a coordinate is not specified, then all the points along this coordinate.
- Parameters:
x (
Union[Buffer,_SupportsArray[dtype[Any]],_NestedSequence[_SupportsArray[dtype[Any]]],complex,bytes,str,_NestedSequence[complex|bytes|str]]) – (Default value = None)y (
Union[Buffer,_SupportsArray[dtype[Any]],_NestedSequence[_SupportsArray[dtype[Any]]],complex,bytes,str,_NestedSequence[complex|bytes|str]]) – (Default value = None)z (
Union[Buffer,_SupportsArray[dtype[Any]],_NestedSequence[_SupportsArray[dtype[Any]]],complex,bytes,str,_NestedSequence[complex|bytes|str]]) – (Default value = None)
- Return type:
- Returns:
totals, total_err for the specified coordinates
- property has_multiple_energy_bins: bool¶
Check if there’s more than 1 energy bin.
If True, then totals and totals err should present.
- Returns:
True if there are more than one energy bins.
- property is_cylinder: bool¶
Is this mesh cylinder?
Note
MCNP uses origin on mesh tally specification, both rectilinear and cylinder, but outputs origin only for cylinder mesh.
- Returns:
True if this is a cylinder mesh.
- property kbins: ndarray¶
Synonym to geometry kbins (z or Theta).
- Returns:
kbins from the geometry spec
- rebin(new_x, new_y, new_z, new_name=-1, extra_process_threshold=1000000)[source]¶
Extract data for a new spatial grid.
- Parameters:
- Return type:
- Returns:
New FMesh object with the rebinned data.
- rebin_single(new_x, new_y, new_z, new_name=-1)[source]¶
Create FMesh object corresponding to this one by fluxes, but over new mesh.
- Ags:
new_x: A new binning over X axis. new_y: A new binning over Y axis. new_z: A new binning over Z axis. new_name: name for the rebinned mesh to be created.
- save2vtk(filename=None, data_name=None)[source]¶
Saves this fmesh data to vtk file.
Data is saved for every energy bin and, if there are multiple energy bins, for total values (sum across energy axis).
- Parameters:
- Return type:
- Returns:
Full path to saved VTK file.
- save_2_mcnp_mesh(stream)[source]¶
Saves the mesh in a file in a format similar to mcnp mesh tally textual representation.
- save_2_npz(filename, check_existing_file_strategy=<function raise_error_when_file_exists_strategy>)[source]¶
Writes this object to numpy npz file.
- Parameters:
filename (
Path) – Filename to which the object is saved. If file is a file-object, then the filename is unchanged. If file is a string, a .npz extension will be appended to the file name if it does not already have one. By default, the name of file is the tally name.check_existing_file_strategy – what to do if an output file already exists
- Return type:
- select_indexes(*, x=None, y=None, z=None)[source]¶
Select indexes in spatial bins corresponding to given coordinates.
If coordinate is not specified, then return all the points along this coordinate.
- Parameters:
x (
Union[Buffer,_SupportsArray[dtype[Any]],_NestedSequence[_SupportsArray[dtype[Any]]],complex,bytes,str,_NestedSequence[complex|bytes|str],None]) – (Default value = None)y (
Union[Buffer,_SupportsArray[dtype[Any]],_NestedSequence[_SupportsArray[dtype[Any]]],complex,bytes,str,_NestedSequence[complex|bytes|str],None]) – (Default value = None)z (
Union[Buffer,_SupportsArray[dtype[Any]],_NestedSequence[_SupportsArray[dtype[Any]]],complex,bytes,str,_NestedSequence[complex|bytes|str],None]) – (Default value = None)
- Return type:
tuple[int|slice|ndarray,int|slice|ndarray,int|slice|ndarray]- Returns:
tuple of indexes along the coordinates
- shrink(emin=None, emax=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, new_name=-1)[source]¶
Select subset of e-voxels within given geometry and energy limits.
- Parameters:
emin – limits for new bins
emax – (Default value = None)
xmin – (Default value = None)
xmax – (Default value = None)
ymin – (Default value = None)
ymax – (Default value = None)
zmin – (Default value = None)
zmax – (Default value = None)
new_name – name for mesh to be created, default -1.
- Return type:
- Returns:
A new FMesh with reduced bins.
- surrounds_point(x, y, z, *, local=True)[source]¶
Check if a point x,y,z is within the mesh spatial grid.
- mckit_meshes.fmesh.check_ebins(fid, keys)[source]¶
Check if energy bins present in a mesh tally output values.
If next nonempty line starts with a word keys[0] (i.e. “Energy”), then the energy bins present. Also check that the remaining keys correspond to the nonempty line.
- Parameters:
- Return type:
- Returns:
True if energy bins are present, False otherwise.
- Raises:
ValueError – if keys don’t correspond to the nonempty line.
- mckit_meshes.fmesh.fix_mesh_comment(mesh_no, comment)[source]¶
Remove digits from an FMESH comment.
MCNP error: prints digits in front of comment when the tally number takes more than 3 digits.
- mckit_meshes.fmesh.iter_meshtal(fid, name_select=None, tally_select=None)[source]¶
Iterates fmesh tallies from fid.
- Parameters:
- Yields:
Mesh tallies filtered.
- Return type:
- mckit_meshes.fmesh.m_2_npz(stream, prefix, *, name_select=<function <lambda>>, tally_select=<function <lambda>>, suffix='', mesh_file_info=None, check_existing_file_strategy=<function raise_error_when_file_exists_strategy>)[source]¶
Splits the tallies from the mesh file into separate npz files.
- Parameters:
stream (
TextIO) – File with MCNP mesh tallies to readprefix (
Path) – Prefix for separate mesh files namesname_select – Filter fmesh by names (default: no filter)
tally_select – function(FMesh)->bool Filter fmesh by content. (default: no filter)
suffix (
str) – Prefix for separate mesh files namesmesh_file_info – structure to store meshtal file header info: nps.
check_existing_file_strategy – what to do if an output file already exists
stream – TextIO:
prefix – Path:
suffix – str: (Default value = “”)
- Return type:
- Returns:
Total number of files created
- mckit_meshes.fmesh.merge_tallies(name, kind, *tally_weight, comment=None)[source]¶
Makes superposition of tallies with specific weights.
- Parameters:
- Return type:
- Returns:
The merged FMesh.
- mckit_meshes.fmesh.meshes_to_vtk(*meshes, out_dir=None, get_mesh_description_strategy)[source]¶
Export FMesh objects to VTK files.
mckit_meshes.m_file_iterator module¶
mckit_meshes.mesh2com module¶
mckit_meshes.particle_kind module¶
Particle kinds enumeration and methods.
- class mckit_meshes.particle_kind.ParticleKind[source]¶
Bases:
IntEnumParticle kinds enumeration and methods.
- __new__(value)¶
- e = 3¶
- electron = 3¶
- property heating_reactions: str¶
MCNP specified heating reactions for neutrons and photons.
- Returns:
reaction specification for neutron or photon particle
- Raises:
ValueError – if there’s no specification for the particle
- n = 1¶
- neutron = 1¶
- p = 2¶
- photon = 2¶
mckit_meshes.version module¶
The meta information on the mckit_meshes package.
mckit_meshes.wgtmesh module¶
Weight mesh class and functions.
- class mckit_meshes.wgtmesh.Particles[source]¶
Bases:
IntEnumParticle kind enum.
- __new__(value)¶
- n = 0¶
- neutron = 0¶
- p = 1¶
- photon = 1¶
- class mckit_meshes.wgtmesh.WgtMesh[source]¶
Bases:
objectClass to work with MCNP weight window files.
- class MergeSpec[source]¶
Bases:
NamedTupleMergeSpec(wm, nps)
- __init__(geometry_spec, energies, weights)[source]¶
- Parameters:
geometry_spec (CartesianGeometrySpec | CylinderGeometrySpec)
- property energies: list[Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]]¶
- property geometry_spec: CartesianGeometrySpec | CylinderGeometrySpec¶
- property ibins: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]¶
- invert(normalization_point, normalized_value=1.0)[source]¶
Get reciprocal of self weights and normalize to 1 at given point.
Important
A caller specifies normalization_point in local coordinates. See
GeometrySpec.local_coordinates.
- property jbins: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]¶
- property kbins: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]¶
- classmethod merge(*merge_specs)[source]¶
Combine weight meshes produced from different runs with weighting factor.
Note
Importance of a mesh voxel i is $1/w_i$ and is proportional to average portion $p_i$ of passing particle weight W to a tally, for which the weight mesh is computed. To obtain combined weight on merging two meshes, we will combine the probabilities using weighting factors and use reciprocal of a result as a resulting weight of mesh voxel. The weighting factors are usually NPS (Number particles sampled) from a run on which a mesh was produced.
The combined probability in resulting voxel i is:
\[ \begin{align}\begin{aligned}w_ij - weight in voxel i of mesh j n_j - nps - weighting factor on combining of mesh j\\p_ij = 1/w_ij - probability for voxel i of mesh j\\p_i = \frac{ \sum_j{n_j*p_ij} { \sum_j{n_j} }\end{aligned}\end{align} \]So, the resulting voxel i weight level is:
\[w_i = \frac{1} {p_i}\]- Parameters:
merge_specs (MergeSpec | tuple[WgtMesh, int]) – iterable of pairs (WgtMesh, nps), where nps is weighting factor
- Returns:
merged weights and total nps (or sum of weighting factors)
- Return type:
- normalize(normalization_point, normalized_value=1.0, energy_bin=-1)[source]¶
Scale weights to have value value at normalisation_point.
All other voxels are scaled proportionally.
- Parameters:
- Return type:
- Returns:
New normalized weights.
- property origin: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]¶
- classmethod read(f)[source]¶
Read an MCNP weights file.
See format description at MCNP User Manual, Version 5 (p.489 or Appendix J, p. J-1)
- mckit_meshes.wgtmesh.make_geometry_spec(ibins, jbins, kbins, origin=None, axs=None, vec=None)[source]¶
Make Cartesian or Cylinder geometry specification from with given parameters.
The parameters are converted to numpy arrays.
- Parameters:
ibins – X or R bins
jbins – Y or Z bins
kbins – Z or Theta bins
origin – origin point
axs – Cylinder mesh axis
vec – Cylinder mesh angle reference vector
- Return type:
- Returns:
spec - new geometry specification
Module contents¶
Code to manipulate MCNP weight and tally meshes.