projects links |
Tutorials / SurfaceToMesh
From 3D surfaces to CFD meshesThis tutorial demonstrates how to process a surface model (obtained like in this tutorial or with other techniques) to generate a computational mesh for use in CFD. We start off by assuming you have a 3D surface model of a vascular segment with blobby closed ends, like the ones generated using level sets or Lagrangian deformable models. If you already have a model with open inlets and outlets, just skip the Smoothing the surfaceImage segmentation can result in bumpy surfaces, especially if the image quality is not high and one didn't use any curvature term in level sets evolution. Since artifactual bumps in the surface can result in spurious flow features and affect wall shear stress distributions, one may want to increase surface smoothness prior to building the mesh.
By typing
For typical vessels, the following should be ok vmtksurfacesmoothing -ifile foo.vtp -passband 0.1 -iterations 30 -ofile foo_sm.vtp If you want more smoothing, try using a passband of 0.01. Be careful not to kill surface features by smoothing too much. Also, watch out the apex of bifurcations, since its curvature may decrease resulting in a shallower apex and affecting the simulated hemodynamics. If you want to compare the smoothed and original versions, to make sure that no shrinking occured and the main surface features were preserved, try this vmtksurfacereader -ifile foo.vtp --pipe vmtksurfacesmoothing -iterations 30 -passband 0.1 --pipe vmtkrenderer --pipe vmtksurfaceviewer -display 0 --pipe vmtksurfaceviewer -i @vmtksurfacereader.o -color 1 0 0 -display 1 You'll see the original surface in red and the smoothed surface in gray. A potential side effect of the filter is that it slightly shifts the position of the surface in space. If this occurs, try increasing Opening the surfaceUnder the assumption that you generated the surface using a deformable model, it's likely that your surface is closed at inlets and outlets, with a blobby appearance. We'll now proceed by opening the surface by clipping the blobby endcaps. You have at least three options. The first option is to use vmtksurfaceclipper -ifile foo.vtp -ofile foo_cl.vtp a rendering window will show up. Press Press the Press The second option is to use Paraview. The procedure is not dramatically different from what you do with The third option is to clip endcaps automatically. No 3D interaction involved. Endcap clipping can be performed using vmtksurfacereader -ifile foo.vtp --pipe vmtkcenterlines --pipe vmtkendpointextractor --pipe vmtkbranchclipper --pipe vmtksurfaceconnectivity -cleanoutput 1 --pipe vmtksurfacewriter -ofile foo_ct.vtp When prompted, select one source point on one inlet or outlet and press If you look at the output file, you'll see that the endcaps have been removed. If you want to clip a larger extent of the endcaps, just use the Increasing the number of surface triangles (optional)Sometimes, with low-resolution images, small vessels or stenoses, the number of triangles defining the surface can be low. This can cause potential problems to some mesh generation algorithms. The solution to this is to subdivide the mesh using a smooth subdivision scheme like Butterfly (the original points are preserved and new ones are added in such a way that at the limit it would produce a C1-continuous surface) or Loop (the original points are displaced but the limit surface is C2 continuous). If you need to subdivide your surface, do the following vmtksurfacesubdivision -ifile foo.vtp -ofile foo_sb.vtp -method butterfly Adding flow extensionsFlow extensions are cylindrical extensions added to the inlets and outlets of a model. They are important for ensuring that the flow entering and leaving the computational domain is fully developed, so that fully developed boundary conditions aren't forcing the solution in the actual vessel. Adding flow extensions is a typical problem in CFD modeling. Stitching cylindrical flow extension to an inlet or outlet of a realistic vessel is not a trivial task, and may result in worsening the reproducibility and adding operator-dependence to the modeling procedure. A fully automatic procedure can solve this often overlooked problem preserving reproducibility and speeding up the modeling phase considerably. Once again, adding flow extensions relies on centerlines. This time centerlines can use open inlet and outlet profiles for the definition of seed and targets. Let's see how this is done vmtksurfacereader -ifile foo.vtp --pipe vmtkcenterlines -seedselector openprofiles --pipe vmtkflowextensions -adaptivelength 1 -extensionratio 20 -normalestimationratio 1 -interactive 0 --pipe vmtksurfacewriter -ofile foo_ex.vtp The In the previous line, the flag Generating the mesh
Both are bundled in Uniform element meshvmtkmeshgenerator -ifile foo.vtp -ofile foo.vtu -edgelength 0.5 where Radius-adaptive element meshvmtksurfacereader -ifile foo.vtp --pipe vmtkcenterlines -endpoints 1 -seedselector openprofiles Converting mesh elements to quadraticvmtklineartoquadratic -ifile foo.vtu -ofile foo_q.vtu -rfile foo.vtp -entityidsarray CellEntityIds Scaling the meshMedical images are often in mm. Typically you want your computations and results to be either in cgs or SI systems, which means scaling the model in cm (1e-1) or in m (1e-3). Let's scale our mesh in cm and store it in the usual vtu format. vmtkmeshscaling -ifile foo.vtu -scale 0.1 -ofile foo_scaled.vtu Inspecting the mesh entitiesvmtkmeshboundaryinspector -ifile foo.vtu -entityidsarray CellEntityids Exporting the mesh for your solverFluent: vmtkmeshwriter -ifile foo.vtu -entityidsarray CellEntityIds -ofile foo.msh Dolfin: vmtkmeshwriter -ifile foo.vtu -entityidsarray CellEntityIds -ofile foo.xml libMesh: vmtkmeshwriter -ifile foo.vtu -entityidsarray CellEntityIds -ofile foo.xda LifeV: vmtkmeshwriter -ifile foo.vtu -entityidsarray CellEntityIds -ofile foo.lifev The Netgen wayCapping the surfaceBefore meshing we may need to generate flat circular endcaps at the open inlet/outlet profiles. This depends on the meshing tool we use. Netgen requires it. vmtksurfacecapper -ifile foo.vtp -ofile foo_cp.vtp -interactive 0 Again, Exporting the surfaceWe can now export our surface in vmtksurfacereader -ifile foo.vtp --pipe vmtksurfacewriter -ofile foo.stl or equivalently vmtksurfacewriter -ifile foo.vtp -ofile foo.stl (there's usually more than one way to perform tasks). Remember that using PypeS you can pipe the previous steps and perform them in one shot without writing and reading the intermediate files each time. Meshing with NetgenNetgen is a great open source mesh generation tool. With Netgen you can generate high-quality meshes from stl files in a matter of minutes. In the following I'll give you some advice on how to get started with Netgen. First of all download Netgen and follow the instructions for installing it on your system. When you're done, fire it up with A nice tkInter-style GUI will pop up. You're encouraged to read the manual, in order to be able to explore the capabilities of this mesh generation tool. For now, let's go straight to the point. Click on Do inspect feature edges, click on We're ready to mesh now. Click on At this point, click on the As the mesh gets generated, you'll notice a very nice feature of Netgen: element density is related to the curvature radius, which is very useful since smaller vessels will be meshed with a denser mesh. Let's take care of defining the boundary entities now. Click on Well, that's what you need to know to get started. Netgen offers a lot of more advanced features, but you can explore them once you get accustomed with the basics. The last step is to export the mesh. Netgen offers several possibilities of exporting the mesh for particular solver packages. Click on Once you're done selecting the solver package, click on Scaling the meshMedical images are often in mm. Typically you want your computations and results to be either in cgs or SI systems, which means scaling the model in cm (1e-1) or in m (1e-3). Let's scale our mesh in cm and store it in the usual vtkXML format. This way you can also see how to read a mesh in Netgen neutral format mesh with vmtk vmtkmeshscaling -ifile foo.neu -scale 0.1 -ofile foo.vtu Generating an input file for a CFD solverThis step greatly depends on the solver you use. I've got a vmtk script that
generates an input file to the solver I use ( As reported above, Netgen will export the mesh for a number of solver packages out there. Otherwise, contact me for information on how to write an input file generator for a particular solver to include in vmtk. Writing mesh I/O stuff is one of the most boring activities I know, so any help would be greatly appreciated... |