mckit_meshes.mesh package

Submodules

mckit_meshes.mesh.geometry_spec module

Common for weight and tally meshes geometry specification classes and functions.

## Relative or absolute coordinates

There are variations when coordinates are presented as relative to origin or absolute. This depends on: 1) is the output is for MCNP specification or input/output to Weight of Meshtal files 2) is it cartesian or cylinder mesh.

Cartesian:

| wwinp | meshtal |
===== | ======= | ======== |
spec | relative | absolute (but origin is extracted to separate item) |
—– | ——- | ——– |
file | relative | absolute |

Cylinder:

| wwinp | meshtal |
===== | ======= | ======== |
spec | relative | relative |
—– | ——- | ——– |
file | relative | relative |

The new callers are to use local_coordinates converter to avoid difficulties. For the old callers we will use ZERO_ORIGIN for Geometry Specification being used in FMesh.

class mckit_meshes.mesh.geometry_spec.AbstractGeometrySpec[source]

Bases: AbstractGeometrySpecData, ABC

Common base for rectilinear and cylinder mesh specifications.

property bins_shape: tuple[int, int, int]

Shape of data corresponding to spatial bins.

Returns:

Tuple with the data shape.

property bins_size: int

Size of data corresponding to spatial bins.

Returns:

number of voxels

Return type:

int

property boundaries: ndarray

Corners or min, max values of bins.

property boundaries_shape: tuple[int, int, int]

Bins (boundaries) shape.

abstractmethod calc_cell_centers()[source]

Calculate cell (voxel) centers.

Return type:

ndarray[tuple[Any, ...], dtype[floating]]

abstract property cylinder: bool

Is this an instance of a cylinder mesh specification?

abstractmethod get_mean_square_distance_weights(point)[source]

Estimate weights as a voxel mean square distance from the point.

Parameters:

point (ndarray[tuple[Any, ...], dtype[floating]]) – … from where to compute distance

Return type:

ndarray[tuple[Any, ...], dtype[floating]]

abstractmethod get_origin()[source]

Get origin coordinates.

Return type:

ndarray[tuple[Any, ...], dtype[floating]]

abstractmethod local_coordinates(points)[source]

Convert points coordinates to local system.

Parameters:

points (ndarray[tuple[Any, ...], dtype[floating]]) – … with global coordinates

Return type:

ndarray[tuple[Any, ...], dtype[floating]]

abstractmethod print_geom(io, indent)[source]

Print geometry specification.

Parameters:
  • io (TextIO) – stream to print to

  • indent (str) – indent to insert before lines

Return type:

None

print_specification(io, columns=6)[source]
Return type:

None

Parameters:
select_indexes(*, i_values=None, j_values=None, k_values=None)[source]

Select indices for data corresponding to given spatial values.

Parameters:
  • i_values – indices along i (X or R) dimension

  • j_values – … along j (Y or Z)

  • k_values – … along k (Z or Theta)

Return type:

tuple[int | slice | ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]], int | slice | ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]], int | slice | ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]

Returns:

see select_indexes()

surrounds_point(x, y, z, *, local=True)[source]

Check if the point (x,y,z) is within the volume of mesh.

By default, assumes that the point is given in local coordinates.

Return type:

bool

Parameters:
class mckit_meshes.mesh.geometry_spec.AbstractGeometrySpecData[source]

Bases: object

Data mixin for AbstractGeometrySpec.

Provides reusable data fields.

Notes

The meaning of origin is different for cartesian and cylindrical meshes

In cartesian mesh origin means most negative coordinates, all the coordinates (ibins, jbins, kbins) are absolute (or in coordinate system given with transformation).

In cylindrical mesh origin is a center of a cylinder bottom, the coordinates are relative to the coordinate system given with origin, axs and vec. Plus, if specified, in coordinate system given with transformation.

__init__(ibins, jbins, kbins)
Parameters:
Return type:

None

__post_init__()[source]

Force a caller provided data as numpy arrays.

Raises:

TypeError – if any of the fields is not a numpy array.

Return type:

None

property bins: tuple[ndarray[tuple[Any, ...], dtype[floating]], ...]

Pack the fields to tuple.

Returns:

tuple of bins.

ibins: ndarray[tuple[Any, ...], dtype[floating]]
jbins: ndarray[tuple[Any, ...], dtype[floating]]
kbins: ndarray[tuple[Any, ...], dtype[floating]]
class mckit_meshes.mesh.geometry_spec.CartesianGeometrySpec[source]

Bases: AbstractGeometrySpec

calc_cell_centers()[source]

Calculate cell (voxel) centers.

property cylinder: bool

Is this an instance of a cylinder mesh specification?

get_mean_square_distance_weights(point)[source]

Estimate weights as a voxel mean square distance from the point.

Parameters:

point – … from where to compute distance

get_origin()[source]

Get origin coordinates.

Return type:

ndarray[tuple[Any, ...], dtype[floating]]

local_coordinates(points)[source]

Convert points coordinates to local system.

Parameters:

points (ndarray[tuple[Any, ...], dtype[floating]]) – … with global coordinates

Return type:

ndarray[tuple[Any, ...], dtype[floating]]

property origin: ndarray[tuple[Any, ...], dtype[floating]]

Get origin coordinates.

print_geom(io, indent)[source]

Print geometry specification.

Parameters:
  • io (TextIO) – stream to print to

  • indent (str) – indent to insert before lines

Return type:

None

property x: ndarray[tuple[Any, ...], dtype[floating]]
property y: ndarray[tuple[Any, ...], dtype[floating]]
property z: ndarray[tuple[Any, ...], dtype[floating]]
class mckit_meshes.mesh.geometry_spec.CylinderGeometrySpec[source]

Bases: AbstractGeometrySpec

Cylinder spec.

axs

cylinder axis

vec

vector to measure angle (theta) from

__init__(ibins, jbins, kbins, origin, axs=<factory>, vec=<factory>)
Parameters:
Return type:

None

adjust_axs_vec_for_mcnp()[source]

Set axs and vec attributes to the values, which MCNP considers orthogonal.

Return type:

CylinderGeometrySpec

Assumptions

Cylinder mesh is not tilted:
  • self.vec is in PY=0 plane

  • self.axs is vertical

Returns:

: gs:

new CylinderGeometrySpec with adjusted axs and vec attributes.

axs: ndarray
property bins: tuple[ndarray[tuple[Any, ...], dtype[floating]], ...]

Pack the fields to tuple.

Returns:

tuple of bins.

calc_cell_centers()[source]

Calculate cell (voxel) centers.

Return type:

ndarray

property cylinder: bool

Is this an instance of a cylinder mesh specification?

get_mean_square_distance_weights(point)[source]

Estimate weights as a voxel mean square distance from the point.

Parameters:

point (ndarray) – … from where to compute distance

Return type:

ndarray

get_origin()[source]

Get origin coordinates.

Return type:

ndarray[tuple[Any, ...], dtype[floating]]

local_coordinates(points)[source]

Convert points coordinates to local system.

Parameters:

points (ndarray) – … with global coordinates

Return type:

ndarray

origin: ndarray[tuple[Any, ...], dtype[floating]]
print_geom(io, indent)[source]

Print geometry specification.

Parameters:
  • io (TextIO) – stream to print to

  • indent (str) – indent to insert before lines

Return type:

None

property r: ndarray
property theta: ndarray
vec: ndarray
property z: ndarray
mckit_meshes.mesh.geometry_spec.arrays_equal(arrays)[source]
Return type:

bool

Parameters:

arrays (Iterable[tuple[ndarray, ndarray]])

mckit_meshes.mesh.geometry_spec.as_float_array(array)[source]

Convert any sequence of numbers to numpy array of floats.

Note

We rely on unified representation all the ‘floats’ with Python float.

Parameters:

array (Union[Buffer, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], complex, bytes, str, _NestedSequence[complex | bytes | str]]) – Anything that can be converted to numpy ndarray.

Returns:

either original or conversion.

Return type:

np.ndarray

mckit_meshes.mesh.geometry_spec.compute_intervals_and_coarse_bins(arr, tolerance=0.0001)[source]

Compute fine intervals and coarse binning.

Examples: Find equidistant bins and report as intervals >>> arry = np.array([1, 2, 3, 4], dtype=float) >>> arry array([1., 2., 3., 4.]) >>> intervals, coarse = compute_intervals_and_coarse_bins(arry) >>> intervals [3] >>> coarse [np.float64(1.0), np.float64(4.0)]

A bins with two interval values. >>> arry = np.array([1, 2, 3, 6, 8, 10], dtype=float) >>> intervals, coarse = compute_intervals_and_coarse_bins(arry) >>> intervals [2, 1, 2] >>> coarse [np.float64(1.0), np.float64(3.0), np.float64(6.0), np.float64(10.0)]

On zero (or negative tolerance) just use intervals filled with ones and return original array. >>> intervals, coarse = compute_intervals_and_coarse_bins(arry, tolerance=0.0) >>> intervals [1, 1, 1, 1, 1] >>> coarse is arry True

Parameters:
  • arr (Sequence[float]) – actual bins

  • tolerance (float) – precision to distinguish intervals with

Returns:

numbers of fine intervals between coarse bins, coarse binning

Return type:

Tuple

mckit_meshes.mesh.geometry_spec.format_floats(floats, _format='{:.6g}')[source]
Return type:

Generator[str]

Parameters:
mckit_meshes.mesh.geometry_spec.select_indexes(a, x)[source]

Find indexes for a mesh bin, corresponding given coordinates.

Assumes that a is sorted.

Examples

>>> r = np.arange(5)
>>> r
array([0, 1, 2, 3, 4])

For x is None return slice over all a indexes.

>>> select_indexes(r, None)
slice(0, 5, None)

For none specified x, if input array represents just one bin, then return index 0 to squeeze results. >>> select_indexes(np.array([10, 20]), None) 0

For x = 1.5, we have 1 < 1.5 < 2, so the bin index is to be 1 >>> select_indexes(r, 1.5) 1

For x = 0, it’s the first bin, and index is to be 0 >>> select_indexes(r, 0) 0

For coordinates below r[0] return -1. >>> select_indexes(r, -1) -1

For coordinates above r[-1] return a.size-1. >>> select_indexes(r, 5) 4

And for array of coordinates >>> select_indexes(r, np.array([1.5, 0, -1, 5])) array([ 1, 0, -1, 4])

Parameters:
Return type:

int | slice | ndarray[tuple[Any, ...], dtype[integer]]

Returns:

index or indices for each given coordinate

Module contents