# Scripted Mesh Generation Software

I'm looking for a mesh generation software that

• is free and open source,
• provides a sane scripting interface for domain specification,
• works for complex geometries,
• can generate 2D and 3D meshes,

What options do I have?

I would recommend you look at gmsh. It has both text and CAD-like input, capable of 2D and 3D, higher order meshes. It is licensed under the GPL, so there are some restrictions on integrating it into closed source software, but is otherwise completely free/open-source.

• Unfortunately, the scripting language is insane. ;) – Nico Schlömer Jun 4 '13 at 18:11
• In what way? Are you refering to the text file inputs, or some other interface? – Godric Seer Jun 4 '13 at 18:17
• I have only used gmsh in someone simple-ish geometries since my problems are almost always complicated by factors other than geometry. While I have only worked on these simpler geometries, I definitely found gmsh to be the most intuitive and easiest to learn. I won't argue with you though about trying to do more complicated procedures since I don't have experience with them. – Godric Seer Jun 4 '13 at 18:28
• You can always write your scripts in whatever language you like and simply create files as a result of your script that are then fed as inputs to gmsh. – Wolfgang Bangerth Jun 5 '13 at 10:34
• @WolfgangBangerth I actually started a little toy project in Python on github.com/nschloe/python4gmsh. – Nico Schlömer Oct 3 '13 at 21:53

I usually use tetgen for 3D (MIT license for research/non-commercial) and triangle for 2D (Custom license free for non-commercial). To script them, you write a input file and call the command line.

• "Please note that TetGen is free for research and non-commercial uses. For any commercial utilization, a commercial license is available upon request." -- This is not a free or open source software license (under OSI or FSF definition), let alone an MIT license. – Jed Brown Jun 5 '13 at 4:25
• Yes I just read the first bit of the License file. Most people are not as strict in their meaning of Free as the OSI or FSF. – aterrel Jun 5 '13 at 13:41
• I was about to ask a similar question. Is tetgen compatible with FEniCS? – seb Jun 5 '13 at 14:10
• @aterrel Read the LICENSE file: "This means that TetGen is no free software, but for private, research, and educational purposes it can be used at absolutely no cost and without further arrangements." – Jed Brown Jun 5 '13 at 14:16
• Yes, @JedBrown, I agreed with you and edited the response. But to the laymen, free usually means "I don't have to pay for it" not the RMS legalize. I would also argue that GPL is not "free" but that is probably not an appropriate discussion for this forum. – aterrel Jun 5 '13 at 14:55

MeshPy can be used for obtaining triangular and tetrahedral meshes. It provides an easy means of scripted mesh generation.

MeshPy provides Python interfaces to Triangle and TetGen mentioned by aterrel.

In the meantime, I created

• pygmsh as a Python front end for gmsh and
• pygalmesh as a Python front end for CGAL's 3D meshing capabilities.

Both are fairly well received, so I'm guessing they are helpful to others as well.

I have found Salome to be very flexible, with a much better environment than gmsh. It has a much more professional feel IMHO. Moreover, it can generate also hexahedral meshes. It is really worth a try!

• I don't like the fact that nothing in the geometry model is editable from either UI or Python console. Basically if you want to do changes you need to delete and recreate. That adds a lot of overhead during design – lurscher Dec 4 '13 at 17:49
• This is true if you import a geometry given to you in a STEP file for example. But if I am not mistaken, this is also true for the other programs mentioned here! Moreover, if you have the HDF file or the python dump script, you can surely change anything. – FlatronL1917 Jan 7 '14 at 13:14

OpenSCAD fits all points except volume meshing. It is based on input scripts and generates STL surface meshes.

Why not Blender? It is a powerful, free and open-source software with python scripting support too.

In Blender 2.79 you need to choose Scripting as Screen layout.

In the top-left Text Editor press + to create a new text data-block; start it with import bpy and then insert the python commands relative to each operation that you can do from the GUI, reading the relative command putting your mouse over the GUI item.

In the attached screenshot are shown the commands to triangulate a circle, starting from the default scene with a cube:

In this way, you can use Blender in scripting mode, without its GUI to export, for example, an output file, running your python script in a terminal:

blender --background --python myscript.py