Command-line TetGen meshing and preparing the mesh-complete directory

Provides a system for patient-specific cardiovascular modeling and simulation.
User avatar
Rok Oblak
Posts: 33
Joined: Sat Jul 02, 2016 7:15 am

Re: Command-line TetGen meshing and preparing the mesh-complete directory

Post by Rok Oblak » Mon Jul 17, 2017 1:42 pm

Hi,

one more question: what is the .tgs flag to use “Radius-Based Meshing”? Also, in one of the examples I saw the option "UseMMG", which seems to speed up the meshing, what exactly is this, is this the same as the "Use fast meshing" option in the GUI?

Thanks,
Rok

User avatar
Adam Updegrove
Posts: 236
Joined: Fri Aug 30, 2013 4:11 pm

Re: Command-line TetGen meshing and preparing the mesh-complete directory

Post by Adam Updegrove » Thu Jul 20, 2017 8:38 am

Hi Rok,

The radius-based meshing generates centerlines of the model, and then based on the radius of the vessel from the centerline at each point on the surface of the mesh, a scaled mesh size is generated. It is useful for creating a mesh when you have vessels of very different size scales and you don't want to have to prescribe a very small mesh size everywhere.

The UseMMG flag is in fact the "Use fast meshing" option in the GUI. It uses a tool called mesh modification and generation (mmg) to perform a surface meshing: https://www.mmgtools.org. The interior is still populated with tetrahedral elements using tetgen.

Thanks!

SimVascular Development Team

User avatar
Rok Oblak
Posts: 33
Joined: Sat Jul 02, 2016 7:15 am

Re: Command-line TetGen meshing and preparing the mesh-complete directory

Post by Rok Oblak » Thu Jul 20, 2017 12:08 pm

Hi,

sorry, I was unclear. I was wondering what line (flag) I should put in my .tgs script to use the radius-based meshing.
Thanks for the info though. MMG seems fast and good enough.

Cheers,
Rok

User avatar
Adam Updegrove
Posts: 236
Joined: Fri Aug 30, 2013 4:11 pm

Re: Command-line TetGen meshing and preparing the mesh-complete directory

Post by Adam Updegrove » Fri Jul 21, 2017 6:47 am

Hi Rok,

Scripting of using the centerline is tricky because a model operation must be called prior to meshing to extract the centerlines. Three things must be done.

The "option UseMMG" flag must be set to 0. MMG cannot handle a different mesh size metric on every cell.

The .tgs flag to use is then "useCenterlineRadius".

But you also need to provide a flag after that to make sure that tetgen uses a function based mesh, "functionBasedMeshing <max edge size> DistanceToCenterlines". "DistanceToCenterlines" is the name of the function that the mesh will be based on.

These flags also need to be called near the top of the script.

I recommend that if you want to find out a flag or have a good script for meshing, to do the mesh in the GUI. Then take a look at the output mesh script. That is the easies way to make sure you get the script right.

Thanks!

SimVascular Development Team

User avatar
Rok Oblak
Posts: 33
Joined: Sat Jul 02, 2016 7:15 am

Re: Command-line TetGen meshing and preparing the mesh-complete directory

Post by Rok Oblak » Fri Jul 21, 2017 12:24 pm

Hi Adam,

thanks again. I did as you suggested and those three lines seem to work. Just a suggestion - it would be useful if one could somehow specify the maximum adapted edge size of larger caps/tubes (as in how much larger they can be than the provided edge size), especially in cases where there is a big discrepancy between radii - see the first attached screenshot, the subsequent simulation is very very sparse in some areas because the adapted edge size was so large.
Screen Shot 2017-07-21 at 8.57.27 PM.png
Screen Shot 2017-07-21 at 8.57.27 PM.png (100.89 KiB) Viewed 1347 times
I have one other issue though: the simvascular_startup.tcl script seems to contain some lines that open the GUI on themselves. One of them seems to be 'catch {package require Plotchart}'. If I start simvascular and then enter this line, a window opens. See the attached screenshot - I entered the "simvascular test.tcl" command where test.tcl only contained a single line of "catch {package require Plotchart}" and the GUI was opened.
Screen Shot 2017-07-21 at 9.12.07 PM.png
Screen Shot 2017-07-21 at 9.12.07 PM.png (639.58 KiB) Viewed 1347 times
Does this have anything about my SV_PLUGIN_PATH variable not being set? Hopefully this is easy to reproduce.
I have my SV_BATCH_MODE set to 1 so when I just enter "simvascular" it does indeed start in batch mode.


Thanks,
Rok

User avatar
Adam Updegrove
Posts: 236
Joined: Fri Aug 30, 2013 4:11 pm

Re: Command-line TetGen meshing and preparing the mesh-complete directory

Post by Adam Updegrove » Fri Jul 21, 2017 3:55 pm

Hi Rok,

In addition to using centerline-based meshing, you should be able to prescribe a local mesh size per face which should override the centerline-based mesh size, and give you a desired size at those locations. Let me know if that doesn't work.

Don't worry about the SV_PLUGIN_PATH, that is something else and not the issue. If you source simvascular_startup.tcl in its entirety, its likely that parts of the GUI will start up because that is what is used to launch the tcl GUI. I would make sure you are only sourcing things you want to source, so copy the contents of things you would like out of simvascular_startup.tcl to a separate file and use that.

Thanks!

SimVascular Development Team

User avatar
Rok Oblak
Posts: 33
Joined: Sat Jul 02, 2016 7:15 am

Re: Command-line TetGen meshing and preparing the mesh-complete directory

Post by Rok Oblak » Sat Jul 22, 2017 7:54 am

Hi,

yes, local size meshing does work, but you would need the model walls to be separated in separate faces (as opposed to just a single face for all the walls and the faces for the caps). But I presume if I set a smaller local edge size just for the cap faces, the resulting simulation density will correspond to that (even if the walls are still very roughly meshed).

Regarding the other issue: the problem I am having is that even if I simply run "simvascular catch {package require Plotchart}" the "require Plotchart" command will open up the GUI on its own. Likewise, there are several other imports that seem to be necessary for all the commands to work, which also open up the GUI, one of them is "source [file join $env(SV_HOME) Tcl SimVascular_2.0 simvascular_vtk_init.tcl]". Do you know what seems to be the issue here?
(If I comment these lines out not all the commands I need are available (mesh_readTGS, mesh_writeCompleteMesh))

Thanks,
Rok

User avatar
Adam Updegrove
Posts: 236
Joined: Fri Aug 30, 2013 4:11 pm

Re: Command-line TetGen meshing and preparing the mesh-complete directory

Post by Adam Updegrove » Mon Jul 24, 2017 7:47 am

Hi Rok,

Yes, you are correct, you would need to have the walls separated by branches to do that effectively. Alternatively, you could use the local sphere refinement to try to select a region to have a smaller mesh size. You could try just setting the cap to a smaller size, but I fear that will give you a weird mesh that transitions very quickly from small elements at the cap to larger elements in the interior. You can definitely give it a try though!

The catch command simply just catches errors that might be thrown from the command. So, even with catch, everything in that command will be processed as usual. You would just want to remove that command.

So, what I recommend for running in tcl batch mode instead of sourcing the simvascular_startup.tcl, is source the other tcl files. If you are using the prebuilt version, you will source files like Core-code.tcl and Plugins-code.tcl. I would do a grep of the Tcl directory first to find what file your function lies in:

"grep -r 'proc mesh_readTGS' ./"

Then make sure that file is one of the files you source. Also, I'm not sure if this is what you were saying, but source simvascular_vtk_init.tcl should not start part of the GUI.

Thanks!

SimVascular Development Team

User avatar
Rok Oblak
Posts: 33
Joined: Sat Jul 02, 2016 7:15 am

Re: Command-line TetGen meshing and preparing the mesh-complete directory

Post by Rok Oblak » Tue Jul 25, 2017 11:09 pm

Hi Adam,

one of the imports I need is "package require vtk". This one is needed for writing the mesh-complete directory at the last step.

However, when I simply enter this command inside the simvascular environment, a 'small' GUI window opens (but not the full GUI, for some reason) (see screenshot). This does not happen on an older version (2.0.20404). Similarly, just starting simvascular and providing any other command (such as "simvascular source test.tcl" where test.tcl is an empty file), a full GUI opens.
Screen Shot 2017-07-26 at 8.02.36 AM.png
Screen Shot 2017-07-26 at 8.02.36 AM.png (67.07 KiB) Viewed 1320 times
Can anybody else on a Mac replicate this?

Thanks,
Rok

User avatar
Adam Updegrove
Posts: 236
Joined: Fri Aug 30, 2013 4:11 pm

Re: Command-line TetGen meshing and preparing the mesh-complete directory

Post by Adam Updegrove » Wed Jul 26, 2017 7:57 am

Hi Rok,

I see this as well. Does the small GUI hinder you from doing anything? The tcl command line still works correct?

'package require vtk' pulls in many of vtk's TCL libraries, most likely including visualization stuff.

Alternatively, you can load each needed vtk library using TCL's load command, and this way you will only get what you need.

catch {load /path/to/vtk/libraries/vtk"LIB_NAME"TCL.dylib} msg

It should only be .dylib on mac. The vtk libs are under the sv_externals/lib directory in the released binary simvascular. And you can get a bunch of the LIB_NAMEs from simvascular_vtk_init.tcl.

Let me know if that helps.

Thanks!

SimVascular Development Team

POST REPLY