CFD Online Discussion Forums

CFD Online Discussion Forums (
-   Open Source Meshers: Gmsh, Netgen, CGNS, ... (
-   -   gmshToFoam : problem with patch (

jmf October 4, 2009 05:28

gmshToFoam : problem with patch
1 Attachment(s)
Hello everybody

I try to use gmshToFoam (from 1.6 binaries) to convert meshes with patches from gmsh 2.4.2.

I get following error message:


Found $MeshFormat tag; assuming version 2 file format.
Starting to read physical names at line 5
Physical names:3
wrong token type - expected string found on line 0 the label 1
file: IStringStream.sourceFile at line 0.
    From function operator>>(Istream&, string&)
    in file primitives/strings/string/stringIO.C at line 57.
FOAM exiting

I assumed that gmshToFoam supports now .msh version 2
Does anybody know how to solve that ? Here attached one mesh sample

Thanks in advance


philippose October 4, 2009 06:43

Hello Michel,

A Good Day to you!

I was looking through the GMSH "msh" file that you have posted. It looks like there was a change in the "msh" file format when GMSH 2.4.0 (22 Aug 2009) was released.

The older "msh" versions had the following format for the patch names:
<length of list>
<number> <patch name>

The current "msh" has the following format:
<length of list>
<physical dimension> <number> <patch name>

gmshToFoam parses the mesh file using the first format, and hence, aborts with an error because the current format has an additional number in each row.

This is a change which has to be made by the maintainers of the "gmshToFoam" code.

The other option is that you make the change to the file "gmshToFoam.C" at line number 316:

lineStr >> regionI >> regionName;


lineStr >> physDim >> regionI >> regionName;

and just ignore the variable "physDim" in the rest of the code. If this works fine, you can submit the change to the "bugs" section of the forum, and get it integrated into the OpenFOAM code base.

I am not sure why this change was made in GMSH, but here is the change log entry which mentions this change:

2.4.0 (Aug 22, 2009): switched build system to CMake; optionally copy
transfinite mesh contraints during geometry transformations; bumped
mesh version format to 2.1 (small change in the $PhysicalNames
section, where the group dimension is now required); ported most
plugins to the new post-processing API; switched from MathEval to
MathEx and Flu_Tree_Browser to Fl_Tree; small bug fixes and
improvements all over the place.

Hope this helps...!

Have a nice day!


7islands October 4, 2009 09:22

Hi guys,
Mattijs says the fix is already in 1.6.x:


jmf October 4, 2009 16:27

gmshToFoam : 1.6 version may not handle .msh version 2.0
Dear Philippose and Takuya

Thanks for the time you spend to help me.

The cause of the problem is indeed the new dimension field in patches list.
gmeshToFoam works again after removing this field in each patch line at the beginning of .msh file.

Apparently my OF1.6 did not include up to date gmeshToFoam.
I followed the link given by Takuya, and compiled gmeshToFoam.C.gz archive posted by Etienne. Now it works.

Many thanks to all of you



All times are GMT -4. The time now is 06:14.