marcomusy / vedo

A python module for scientific analysis of 3D data based on VTK and Numpy
https://vedo.embl.es
MIT License
2.03k stars 264 forks source link

How to maninpulate mesh? #790

Open zhang-qiang-github opened 1 year ago

zhang-qiang-github commented 1 year ago

I want to implement a computer fluid dynamic (CFD) simulation, and a mesh is required.

Firstly, I use Tube as the vessel model:

from vedo import *

ln = [[sin(x), cos(x), x / 2] for x in np.arange(0,9, 0.1)]
N = len(ln)

rads = [0.3*(cos(6.0*ir/N))**2+0.1 for ir in range(N)]
t2 = Tube(ln, r=rads, c="tomato", res=24, cap=False).wireframe().triangulate()
cap = t2.cap(return_cap=True).c('y').wireframe().triangulate()
show(t2, cap).close()

The result is:

image

The yellow color indicates the inlet and outlet of vessel, and red color indicates the vessel wall

Question 1: The yellow part is generated by Tube().cap(), and I can not distinguish which is inlet and which is outlet. How can I seperate the yellow polydata into two polydata inlet/outlet?

Then, the CFD need a tetrahedron mesh, which should provide the point id and cell connection. The tetrahedron can be generated by:

tet = t2.tetralize()
show(tet).close()

Question 2: In the tet, how can I know the cell id and point id for the polydata of inlet/outlet/wall? The inlet/outlet is generated from Tube().cap(), and wall is the polydata of t2.

Hopes your suggestions~~~

marcomusy commented 1 year ago

At the moment the mesh pointdata is not passed to the tetmesh so the only way I can think is to loop over all mesh points to find the closest point in the output tetmesh and manually associate the desired info to the tetmesh points. In this way you can separate inlet and outlet too - but I think there is no way to do it "automatically", you still need to inform the system about what is what.

Adding pointdata from the original mesh including the original pointID could be an interesting feature so I add the "enhancement" tag but I cannot promise on when this could be implemented.

zhang-qiang-github commented 1 year ago

Thanks for kindly reply. And I find pygmsh may be a solution. My test code is:

import pygmsh
from vedo import *

with pygmsh.geo.Geometry() as geom:
    box = geom.add_ball(x0=[0, 0, 0], radius=5)
    mesh = geom.generate_mesh()
    points = mesh.points
    elem = mesh.cells_dict['tetra']
    triangle = mesh.cells_dict['triangle']

    msh1 = Mesh([points, elem]).wireframe() ############################ tetrahedron
    msh2 = Mesh([points, triangle]).alpha(0.2).c('b')  ###################### surface
    show(msh1, msh2)

image

But, I still need a solution to distinguish inlet/outlet.