-
I'm new to OpenPNM and I would like to test it for PTL/GDL (porous transport layer/gas diffusion layer) characterization. Usually one will use µCT scan to build the p-network. I'm wondering if it is method to import a PTL structure defined by CAD geometry or STL/STEP file? This is interesting for a specific kind of the PTL/GDL that have a relatively coarse deterministic structure like metal net and could be easily defined/modeled with CAD and exported as STL or STEP file. I copy here the answer by @jgostick
I'm more interested in first thing/topic you mentioned - "generate a voxel image out of a CAD file so that a network can be extracted" With the Online Voxelizer I converted a stl file I found im web to this voxel-model. something-inside20210314-23024-1w6tujn.zip My goal is to take STL or STEP --> transfer to any voxel format OpenPNM supports --> conduct simulations Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
maybe it's possible to utilizes this package? - p-hofmann/PyVoxelizer |
Beta Was this translation helpful? Give feedback.
-
OK, here is a script that works. I had to play a bit because the import porespy as ps
from skimage.measure import marching_cubes
import scipy.ndimage as spim
import trimesh
import numpy as np
# Generate a basic image for testing
im1 = np.zeros(shape=[60, 60, 60], dtype=bool)
im1[tuple((slice(20, 40, None), slice(20, 40, None), slice(20, 40, None)))] = 1
im1[tuple((slice(30, 50, None), slice(30, 50, None), slice(30, 50, None)))] = 1
# Obtain a mesh from the boolean image.
im1 = np.pad(im1, 3, mode='constant', constant_values=0)
im2 = spim.convolve(im1*1.0, weights=ps.tools.ps_round(1, im1.ndim, smooth=False))
im2 = im2/im2.max()
verts, faces, normals, values = marching_cubes(im2, level=0.5,
gradient_direction='ascent')
m = trimesh.Trimesh(vertices=verts, faces=faces, vertex_normals=normals)
# If you have an stl file already, you could use:
# m = trimesh.load('filename.stl', file_type='stl')
# Finally, use the contains method of the mesh to see which points land within it
s = 1 # Increase this spacing to reduce image resolution
args = [range(0, im1.shape[i], s) for i in range(im1.ndim)]
pts = np.meshgrid(*args)
coords = np.vstack([pts[i].flatten() for i in range(im1.ndim)]).T
b = m.contains(coords) # This step is not fast!!
b = b.reshape((np.array(im1.shape)/s).astype(int)) |
Beta Was this translation helpful? Give feedback.
OK, here is a script that works. I had to play a bit because the
m.voxelized
method of themesh
objects intrimesh
only do the 'surface' mesh not the total volume.