import numpy
from ._structured_grid import structured_grid
__all__ = [
"voxelize",
]
[docs]def voxelize(points, material="dfalt"):
"""
Generate a 1D hexahedral mesh from 1D point coordinates.
Parameters
----------
points : array_like (n_points,)
Cooordinates of points.
material : str, optional, default 'dfalt'
Default material name.
Returns
-------
toughio.Mesh
Output hexahedral mesh.
"""
if not isinstance(points, (list, tuple, numpy.ndarray)):
raise TypeError()
if numpy.ndim(points) != 1:
raise ValueError()
points = numpy.asarray(points)
idx = numpy.argsort(points)
dx = 0.5 * (points[idx[1:]] - points[idx[:-1]])
dx = numpy.insert(dx, 0, dx[0])
dy = [0.05 * (points.max() - points.min())]
dz = dy
origin = -0.5 * numpy.array([dx[0], dy[0], dz[0]])
mesh = structured_grid(dx, dy, dz, origin)
mesh.cells[0].data[:] = mesh.cells[0].data[numpy.argsort(idx)]
return mesh