<jupyter_start><jupyter_text>STL Voxelization with PyVista<jupyter_code>import pyvista as pv
import numpy as np
filename = 'HalfDonut.stl';
mesh = pv.read(filename);
cpos = mesh.plot(jupyter_backend='ipygany');
dir(mesh)
voxels = pv.voxelize(mesh,density = mesh.length/150)

p = pv.Plotter()
p.add_mesh(voxels,color=True,show_edges=True,opacity=0.5)
#p.add_mesh(mesh,color="lightblue",opacity=0.5)
p.show(jupyter_backend='ipygany')
voxels
dir(voxels)
voxels.number_of_cells
type(voxels.cell_centers)
voxels.cell_centers()<jupyter_output><empty_output><jupyter_text>get the voxel data into a form that may be used by FluidChannel<jupyter_code># get mesh bounds
mesh.rotate_x(90);
mesh.rotate_y(180);
mesh.translate([3.5, 3.5, 4.5]);
mesh.save('HalfDonut_moved.stl');
x_min, x_max, y_min, y_max, z_min, z_max = mesh.bounds
print('x_min = %g' % x_min)
print('x_max = %g' % x_max)
print('y_min = %g' % y_min)
print('y_max = %g' % y_max)
print('z_min = %g' % z_min)
print('z_max = %g' % z_max)
# to see if this will work, let's expand the domain

aL_x = x_max - x_min; print(f'{"Lx = %g"}' % aL_x)
aL_y = y_max - y_min; print(f'{"Ly = %g"}' % aL_y)
aL_z = z_max - z_min; print(f'{"Lz = %g"}' % aL_z)
mesh.length
Lo = np.max([aL_x,aL_y,aL_z])
N_divs = 201
Ny = np.ceil((N_divs-1)*(aL_y/Lo))+1; Ny=int(Ny);
Nx = np.ceil((N_divs-1)*(aL_x/Lo))+1; Nx=int(Nx);
Nz = np.ceil((N_divs-1)*(aL_z/Lo))+1; Nz=int(Nz);
nnodes = Nx*Ny*Nz
x_space = np.linspace(x_min,x_max,Nx)
y_space = np.linspace(y_min,y_max,Ny)
z_space = np.linspace(z_min,z_max,Nz)

Y,Z,X=np.meshgrid(y_space,z_space,x_space)
x = np.reshape(X,int(nnodes))
y = np.reshape(Y,int(nnodes))
z = np.reshape(Z,int(nnodes))

grid = pv.StructuredGrid(X,Y,Z)
ugrid = pv.UnstructuredGrid(grid)
selection = ugrid.select_enclosed_points(mesh.extract_surface(),
                                        tolerance=0.0,
                                        check_surface=False)
mask = selection.point_arrays['SelectedPoints'].view(bool)
mask = mask.reshape(X.shape)

pv.plot(grid.points,opacity=0.2,scalars=mask,jupyter_backend='ipygany')<jupyter_output>/home/sblair/anaconda3/envs/tlbm/lib/python3.8/site-packages/traittypes/traittypes.py:97: UserWarning: Given trait value dtype "float64" does not match required type "float64". A coerced copy has been created.
  warnings.warn(
{'fraction_non_alphanumeric': 0.16796200345423143, 'fraction_numerical': 0.017271157167530225, 'mean_word_length': 5.1786666666666665, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '253902', 'license': 'MIT', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1043, 'n_words': 166, 'path': 'python/tlbm/stl_utils/Voxelize_with_PyVista.ipynb', 'repo_name': 'stu314159/HPC_Introduction_with_LBM', 'size': '2316'}