CFD Online Discussion Forums

CFD Online Discussion Forums (
-   Open Source Meshers: Gmsh, Netgen, CGNS, ... (
-   -   Recommended way of generating mesh from cad (

Tobias Prousa (Prousa) February 2, 2005 11:44

Hi, is there a open source so
Hi, is there a open source soloution you can recommend to generate a openFOAM compatible mesh from cad objects. A compatible open source cad program would interest me as well. Any suggestions? What programs do you use to generate your meshes? Thanks, Tobi

Mattijs Janssens (Mattijs) February 2, 2005 13:08

Anybody? We haven't come a

We haven't come across any really good public domain meshing program (but we haven't looked too hard).

If you are really not interested in accuracy there are some really good tet meshers: tetgen, netgen.

For multiblock hex and lots more: gmsh.

All these generate meshes that can be converted to OpenFoam.

Most of these interface with cad data through an stl file.

There are various public domain cad packages (Open-Cascade, Orcan, Brl-CAD). I have used AC3D (not really cad, more polygon editor).

We haven't generated many meshes in house. Lots of blockMesh, some AC3D in combination with extrudeMesh (not trivial). There is some experimental undocumented hex-refinement stuff in meshing/advanced: autoRefineMesh, selectCells, snapMesh.

I'm really interesed in what other people use / have used.


Wolfgang Fuetterer (Fuetterer) February 8, 2005 06:32

Hi, I'm trying to use netgen
Hi, I'm trying to use netgen to generate my meshes.
Everything works fine. My CAD-Data areimported very well and the mesh generation also works fine.
(I use a fluent Mesh)

But I have a little problem:
How can I get different boundary conditions to my boundary faces?
I only get a wall patch type for all boundary faces, when converting the fluent mesh to Openfoam with fluentMeshToFoam.

Can anyone help me?
thanks, Wolfgang

Mattijs Janssens (Mattijs) February 8, 2005 07:02

Hello Wolfgang, I had a si
Hello Wolfgang,

I had a similar problem and noticed that the boundary info is not exported in the fluent file. I wrote another converter that reads the Netgen neutral format which does not have this problem.

If you want it send me an email (m.janssens at and I'll pack it up and send it.


Hrvoje Jasak (Hjasak) February 8, 2005 08:50

Surely, you can open FoamX an
Surely, you can open FoamX and change the boundary conditions there, right? Or, even better, edit the boundary file by hand and change the type of boundary that way. Also, there should be a re-patching tool that will even allow you to move faces from one patch to the other (and add new patches?).

The issue is that Fluent defines boundary conditions as "flow conditions" and some of them have absolutely no reasonable mapping to"physical" conditions in the boundary file - note that things like symmetry planes and empty patches are grabbed properly. Foam specifies the flow boundary condition on a per-field basis (with the help of FoamX).

As an illustration, please consider what to do with a boundary type defined in Fluent as a rotational fan when I'm trying to do interface tracking: does not make sense, right?

The main purpose of the mesh converters is to get the mesh into the Foam format and then you can massage it to your heart's content with the Foam manipulation tools.



stefan May 4, 2005 13:09

Hello! I'm trying to genera

I'm trying to generate a mesh with tetgen1.3.3 and it doesn't work.
In tetgenToFoam.C there is an example cube.smesh file.

tetgen -pqAz cube.smesh RET

this produces cube.1.ele, .node, .face

tetgenToFoam -startAt0 <root> <case> cube.1

produces a seg.fault

In tetgenToFoam.C there is also mentioned that one should use the -f switch, but tetgen1.3.3 doesn't have an -f switch (although it should have, according to the output of "tetgen -h").

Can anybody help me?

stefan May 5, 2005 11:59

The segmentation fault occured
The segmentation fault occured because I used the -startAt0 option. I did this, because without this option there was a FatalError referring to a wrong numbering of nodes.

This happend although the nodes where numbered from 1, and I did not use the -startAt0 option.

I am a beginner of C++, but I think there is a typo in line 201. It's an "if" condition that always evaluates to TRUE.

Shouldn't it be
(startAt1 && nodeI != pointI+1)
|| (startAt1 && nodeI-1 != pointI)


stefan May 5, 2005 12:35

Ok, to get this straight, my f
Ok, to get this straight, my first post doesn't really have to do with the problem, since the -z switch in "tetgen -pqAz cube.smesh" shouldn't be used for a .smesh file that starts numbering at 1 anyways.
See the Bug Report page for a proper description of the Problem.

imano November 29, 2005 09:53

Hi! Is there any example inpu
Is there any example input files for autoRefineMesh utility in mesh/advanced?


imano December 26, 2005 10:49

Hello! I succeed in generat

I succeed in generating a body-fitted cartesian mesh automatically from a geometry file in STL format as far as the geomety is very simple.

I took the following steps.

1. Use blockMesh to generate an initial base mesh.

2. Refine the base mesh with autoRefineMesh until the mesh fits the geometry.
In this step I didn't remove inside cells, i.e. nCutLayers was set to be 0 in autoRefineMeshDict.

3. Use insideCells to pick up cells inside the surface of the geometry.

4. Use cellSet to remove the inside cells.

In order to make a body-fitted cartesian mesh from a more complex geomety, I would have to project cell's face onto surfaces of the geometry as suggested in autoRefineMeshDict, but I could not find the way to do that.

Can anybody help me?


christian67 December 31, 2005 07:09

Hi everybody, maybe somebody
Hi everybody,
maybe somebody might be interested:

There is a 3D CAD software called GraphiteOne 3D CAD which is free for non-commercial use.

With this CAD you can export stl and step files (e.g. for netgen).
It's also possible to export 3D dxf files (e.g. to make wireframes for dxf3geo ==> gmsh).

They seem to use the OpenCascade libraries, but there are pre-compiled binaries for some distributions, that can be installed by normal human beeings.

Good luck,


unoder January 2, 2006 14:27

So you import the geometry to
So you import the geometry to foam from netgen?

christian67 January 4, 2006 13:50

Normally I prefer to use hex m
Normally I prefer to use hex meshes made with gmsh.

Therefore you can use GraphiteOne to create points,lines and arcs in 3D (as a preprocessor to gmsh), as the geometry editing is more comfortable for me.

But yes - I admit- sometimes I create netgen tet-meshes for foam.

billy January 4, 2006 18:09

Hi, I tried to donwload Gra

I tried to donwload GraphiteOne but all the links are broken.

terrybarnaby May 5, 2008 05:15

Is autoRefineMesh working in O
Is autoRefineMesh working in OpenFOAM 1.4.1 ?
I am trying to use it to create a "wind tunnel" mesh
around an STL defined object.
I have tried various options in blockMeshDict and
autoRefineMeshDict but the program always seems to crash with me with various segment fault errors.

mattijs May 6, 2008 17:06

Haven't used it for a while. W
Haven't used it for a while. What errors? What is your blockMeshDict? What your autoRefineDict?

terrybarnaby May 7, 2008 04:20

Thanks for the reply. The err
Thanks for the reply.
The error I get from OpenFOAM 1.4.1 is:

#0 Foam::error::printStack(Foam: in "/home/terry/OpenFOAM/OpenFOAM-1.4.1/lib/linuxGccDPOpt/"
#1 Foam::sigSegv::sigSegvHandler(int) in "/home/terry/OpenFOAM/OpenFOAM-1.4.1/lib/linuxGccDPOpt/"
#2 Uninterpreted: [0x110420]
#3 doRefinement(Foam::polyMesh&, Foam::dictionary const&, Foam::HashSet<int,> > const&, Foam::List<int>&) in "/home/terry/OpenFOAM/OpenFOAM-1.4.1/applications/bin/linuxGccDPOpt/autoRefineMe sh"
#4 main in "/home/terry/OpenFOAM/OpenFOAM-1.4.1/applications/bin/linuxGccDPOpt/autoRefineMe sh"
#5 __libc_start_main in "/lib/"
#6 Foam::regIOobject::readIfModified() in "/home/terry/OpenFOAM/OpenFOAM-1.4.1/applications/bin/linuxGccDPOpt/autoRefineMe sh"
make: *** [mesh2] Segmentation fault

I have put my test case at:

If you do "make clean mesh2" it attempts to create a mesh using autoRefineMesh to improve it near the
imported CAD object.

Using OpenFOAM 1.4.1_patch from SVN I get the error:

--> FOAM FATAL ERROR : face:1283 centre -0.8 0.75) verts:5(533 764 2597 765 534) point levels:5{0} own:448 ownLevel:0#0 Foam::error::printStack(Foam: in "/home/terry/OpenFOAM/OpenFOAM-1.4.1/lib/linuxGccDPOpt/"
#1 Foam::error::abort() in "/home/terry/OpenFOAM/OpenFOAM-1.4.1/lib/linuxGccDPOpt/"
#2 Foam::hexRef8::getAnchorLevel(int) const in "/home/terry/OpenFOAM/OpenFOAM-1.4.1/lib/linuxGccDPOpt/"
#3 Foam::hexRef8::setRefinement(Foam::List<int> const&, Foam::polyTopoChange&) in "/home/terry/OpenFOAM/OpenFOAM-1.4.1/lib/linuxGccDPOpt/"
#4 Foam::multiDirRefinement::refineHex8(Foam::polyMes h&, Foam::List<int> const&, bool) in "/home/terry/OpenFOAM/OpenFOAM-1.4.1/lib/linuxGccDPOpt/"
#5 Foam::multiDirRefinement::multiDirRefinement(Foam: :polyMesh&, Foam::List<int> const&, Foam::dictionary const&) in "/home/terry/OpenFOAM/OpenFOAM-1.4.1/lib/linuxGccDPOpt/"
#6 doRefinement(Foam::polyMesh&, Foam::dictionary const&, Foam::HashSet<int,> > const&, Foam::List<int>&) in "/home/terry/OpenFOAM/OpenFOAM-1.4.1/applications/bin/linuxGccDPOpt/autoRefineMe sh"
#7 main in "/home/terry/OpenFOAM/OpenFOAM-1.4.1/applications/bin/linuxGccDPOpt/autoRefineMe sh"
#8 __libc_start_main in "/lib/"
#9 Foam::regIOobject::readIfModified() in "/home/terry/OpenFOAM/OpenFOAM-1.4.1/applications/bin/linuxGccDPOpt/autoRefineMe sh"

From function hexRef8::getAnchorLevel(const label) const
in file polyTopoChange/polyTopoChange/hexRef8.C at line 580.

FOAM aborting


Any pointers or other help would be appreciated.
My setup is: Fedora 8, OpenFOAM 1.4.1 and OpenFOAM 1.4.1_patch, paraview 3.2.1 with updated FOAM extensions for 1.4.1.



mattijs May 8, 2008 16:50

I backported some stuff but au
I backported some stuff but autoRefineMesh now seems to run through till the end. (Had to move the 0/ directory to 1/ to have foamToVTK pick it up but that is a different issue) autoRefineMesh.tgz

terrybarnaby May 9, 2008 01:48

Thank you very much for this,
Thank you very much for this, I was not expecting updated code !
You state that you have back ported the code. Is this from an SVN source development tree and if so would it be worth me using that tree in the future ?

I will have a go with the updated autoRefineMesh,

Thanks again


gschaider May 9, 2008 04:30

Hi Terry! As Eugene pointed
Hi Terry!

As Eugene pointed out in another thread the SVN-dev-version is NOT what is going to be OF 1.5.

I'll include the new version in the branch at the SVN that collects all the bugfixes if that is alright with Mattijs?


All times are GMT -4. The time now is 16:58.