CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Meshing & Mesh Conversion

[Gmsh] Issue converting mesh from gmsh to openFoam

Register Blogs Community New Posts Updated Threads Search

Like Tree9Likes
  • 7 Post By mzzmrt
  • 1 Post By Talder
  • 1 Post By Talder

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 1, 2018, 19:09
Default Issue converting mesh from gmsh to openFoam
  #1
New Member
 
Victor Carlos Teixeira
Join Date: Sep 2018
Posts: 3
Rep Power: 7
victorbelenense is on a distinguished road
Hi everyone,


I've been learning how to use openFoam for couple of months and recently I have started to study a simple airfoil case. I have done the mesh with Gmsh and followed the steps to produce the .msh file but when I finally try to import the .msh file to openFoam format with the command gmshToFoam I get the following message:

--> FOAM FATAL IO ERROR:
wrong token type - expected word, found on line 0 the label 99

file: IStringStream.sourceFile at line 0.

From function Foam::Istream& Foam:perator>>(Foam::Istream&, Foam::word&)
in file primitives/strings/word/wordIO.C at line 74.

FOAM exiting


Here is the .geo file:


//+
Point(1) = {0.08436612, 0.1027103, 0, 1.0};
//+
Point(2) = {0.08467859, 0.1005296, 0, 1.0};
//+
Point(3) = {0.08499106, 0.1053271, 0, 1.0};
//+
Point(4) = {0.08561599, 0.09834891, 0, 1.0};
//+
Point(5) = {0.08608469, 0.1075078, 0, 1.0};
//+
Point(6) = {0.08717833, 0.09660436, 0, 1.0};
//+
Point(7) = {0.08764703, 0.1092523, 0, 1.0};
//+
Point(8) = {0.08905313, 0.09529595, 0, 1.0};
//+
Point(9) = {0.0893656, 0.1107788, 0, 1.0};
//+
Point(10) = {0.09139663, 0.09420561, 0, 1.0};
//+
Point(11) = {0.09155287, 0.1118692, 0, 1.0};
//+
Point(12) = {0.0935839, 0.09333333, 0, 1.0};
//+
Point(13) = {0.09374014, 0.1129595, 0, 1.0};
//+
Point(14) = {0.09655234, 0.1140498, 0, 1.0};
//+
Point(15) = {0.09670857, 0.09246106, 0, 1.0};
//+
Point(16) = {0.09936454, 0.09202492, 0, 1.0};
//+
Point(17) = {0.09967701, 0.1149221, 0, 1.0};
//+
Point(18) = {0.1040516, 0.09158879, 0, 1.0};
//+
Point(19) = {0.104989, 0.1157944, 0, 1.0};
//+
Point(20) = {0.1081136, 0.09137072, 0, 1.0};
//+
Point(21) = {0.1098322, 0.1162305, 0, 1.0};
//+
Point(22) = {0.1131131, 0.09115265, 0, 1.0};
//+
Point(23) = {0.114363, 0.1164486, 0, 1.0};
//+
Point(24) = {0.1188937, 0.09115265, 0, 1.0};
//+
Point(25) = {0.1198311, 0.1162305, 0, 1.0};
//+
Point(26) = {0.1243619, 0.09115265, 0, 1.0};
//+
Point(27) = {0.1252993, 0.1155763, 0, 1.0};
//+
Point(28) = {0.1301426, 0.09115265, 0, 1.0};
//+
Point(29) = {0.13108, 0.114486, 0, 1.0};
//+
Point(30) = {0.1359232, 0.09115265, 0, 1.0};
//+
Point(31) = {0.1370168, 0.1133956, 0, 1.0};
//+
Point(32) = {0.1402977, 0.09093458, 0, 1.0};
//+
Point(33) = {0.1418601, 0.1123053, 0, 1.0};
//+
Point(34) = {0.1462346, 0.09093458, 0, 1.0};
//+
Point(35) = {0.1476407, 0.1105607, 0, 1.0};
//+
Point(36) = {0.1527964, 0.09049844, 0, 1.0};
//+
Point(37) = {0.1537338, 0.1085981, 0, 1.0};
//+
Point(38) = {0.1588895, 0.09006231, 0, 1.0};
//+
Point(39) = {0.1606081, 0.1059813, 0, 1.0};
//+
Point(40) = {0.1654513, 0.08919003, 0, 1.0};
//+
Point(41) = {0.1670137, 0.1033645, 0, 1.0};
//+
Point(42) = {0.1726381, 0.08809969, 0, 1.0};
//+
Point(43) = {0.173888, 0.1003115, 0, 1.0};
//+
Point(44) = {0.1813872, 0.08613707, 0, 1.0};
//+
Point(45) = {0.1823246, 0.09595016, 0, 1.0};
//+
Point(46) = {0.1891988, 0.08417445, 0, 1.0};
//+
Point(47) = {0.1902925, 0.09115265, 0, 1.0};
//+
Point(48) = {0.197323, 0.08133956, 0, 1.0};
//+
Point(49) = {0.1982604, 0.08657321, 0, 1.0};
//+
Point(50) = {0.204666, 0.0782866, 0, 1.0};
//+
Point(51) = {0.2054471, 0.08199377, 0, 1.0};
//+
Point(52) = {0.2127901, 0.07436137, 0, 1.0};
//+
Point(53) = {0.2132588, 0.07676012, 0, 1.0};
//+
Point(54) = {0.2198206, 0.07021807, 0, 1.0};
//+
Point(55) = {0.2204456, 0.07196262, 0, 1.0};
//+
Point(56) = {0.2259137, 0.06629283, 0, 1.0};
//+
Point(57) = {0.2263824, 0.06760125, 0, 1.0};
//+
Point(58) = {0.2296633, 0.06433022, 0, 1.0};
//+
Point(59) = {-1, -1, 0, 1.0};
//+
Point(60) = {-1, 1, 0, 1.0};
//+
Point(61) = {1, 1, 0, 1.0};
//+
Point(62) = {1, -1, 0, 1.0};
//+
Point(63) = {1, -1, 0, 1.0};
//+
Line(1) = {5, 3};
//+
Line(2) = {3, 1};
//+
Line(3) = {1, 2};
//+
Line(4) = {2, 2};
//+
Line(5) = {4, 2};
//+
Line(6) = {4, 6};
//+
Line(7) = {6, 8};
//+
Line(8) = {8, 10};
//+
Line(9) = {10, 12};
//+
Line(10) = {12, 15};
//+
Line(11) = {15, 16};
//+
Line(12) = {16, 18};
//+
Line(13) = {18, 20};
//+
Line(14) = {20, 22};
//+
Line(15) = {22, 24};
//+
Line(16) = {24, 26};
//+
Line(17) = {26, 28};
//+
Line(18) = {28, 30};
//+
Line(19) = {30, 32};
//+
Line(20) = {32, 34};
//+
Line(21) = {34, 36};
//+
Line(22) = {36, 38};
//+
Line(23) = {38, 40};
//+
Line(24) = {40, 42};
//+
Line(25) = {42, 44};
//+
Line(26) = {44, 46};
//+
Line(27) = {46, 48};
//+
Line(28) = {48, 50};
//+
Line(29) = {50, 52};
//+
Line(30) = {52, 54};
//+
Line(31) = {54, 56};
//+
Line(32) = {56, 58};
//+
Line(33) = {58, 57};
//+
Line(34) = {57, 55};
//+
Line(35) = {55, 53};
//+
Line(36) = {53, 51};
//+
Line(37) = {51, 49};
//+
Line(38) = {49, 47};
//+
Line(39) = {47, 45};
//+
Line(40) = {45, 43};
//+
Line(41) = {43, 41};
//+
Line(42) = {41, 39};
//+
Line(43) = {39, 37};
//+
Line(44) = {37, 35};
//+
Line(45) = {35, 33};
//+
Line(46) = {33, 31};
//+
Line(47) = {31, 29};
//+
Line(48) = {29, 27};
//+
Line(49) = {27, 25};
//+
Line(50) = {25, 23};
//+
Line(51) = {23, 21};
//+
Line(52) = {21, 19};
//+
Line(53) = {19, 17};
//+
Line(54) = {17, 14};
//+
Line(55) = {14, 13};
//+
Line(56) = {13, 11};
//+
Line(57) = {11, 9};
//+
Line(58) = {9, 7};
//+
Line(59) = {7, 5};
//+
Line(60) = {60, 59};
//+
Line(61) = {59, 62};
//+
Line(62) = {62, 61};
//+
Line(63) = {61, 60};
//+
Line Loop(1) = {63, 60, 61, 62};
//+
Line Loop(2) = {53, 54, 55, 56, 57, 58, 59, 1, 2, 3, -5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52};
//+
Plane Surface(1) = {1, 2};
//+
Physical Volume("internal") = {1};
Extrude {0,0,0.05}
{
Surface{1};
Layers{1};
Recombine;
}
//+
Physical Surface("walls") = {150, 146, 374, 370, 366, 362, 1, 358, 354, 350, 346, 342, 338, 334, 330, 326, 322, 318, 314, 310, 306, 302, 298, 294, 290, 286, 282, 278, 274, 270, 266, 262, 258, 254, 250, 246, 242, 238, 234, 230, 226, 222, 375, 218, 214, 210, 206, 202, 198, 194, 190, 186, 182, 178, 174, 170, 166, 162, 158, 154};

//+
Physical Surface("inlet") = {130,134,138};
//+
Physical Surface("frontAndBack") = {375, 1};
//+
Physical Surface("outlet") = {142};
//+
Characteristic Length {60, 59, 62, 61} = 0.1;
//+
Characteristic Length {17, 14, 13, 11, 9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 12, 15} = 0.01;





I already read several tutorials and I am still stuck at the same issue.
I humbly ask for some help.
victorbelenense is offline   Reply With Quote

Old   September 2, 2018, 03:36
Default
  #2
Senior Member
 
Join Date: Mar 2014
Posts: 112
Rep Power: 12
mzzmrt is on a distinguished road
I have tested your "x.geo" script with gmsh 3.0.6, made a 3D "x.msh" with it and imported to OpenFOAM (4.1) as "gmshToFoam x.geo"


Well, it is working as expected.



If you are on windows this may be a reason....
mzzmrt is offline   Reply With Quote

Old   September 2, 2018, 11:26
Default
  #3
New Member
 
Victor Carlos Teixeira
Join Date: Sep 2018
Posts: 3
Rep Power: 7
victorbelenense is on a distinguished road
Hi mzzmrt,

Thank you for the reply. I am using Ubuntu 16.04, Gmsh 4.0.0 and OpenFoam 5.
I got a new error message now when using gmshToFoam:

FOAM FATAL IO ERROR:
Attempt to get back from bad stream

file: IStringStream.sourceFile at line 0.

From function bool Foam::Istream::getBack(Foam::token&)


I have no idea why it is not working for me. Could you show me the .msh file?
victorbelenense is offline   Reply With Quote

Old   September 2, 2018, 13:29
Default
  #4
Senior Member
 
Join Date: Mar 2014
Posts: 112
Rep Power: 12
mzzmrt is on a distinguished road
I got it. The default *.msh format of the latest gmsh (4.0) has been updated to v4 but gmshToFoam needs v2.


So while exporting the mesh from gmsh use >file>export>*.msh and choose v2 ascii. Then it will work.


Second line in the *.msh also shows the version...
koray, randolph, tonnykz and 4 others like this.
mzzmrt is offline   Reply With Quote

Old   September 2, 2018, 15:14
Thumbs up Problem solved
  #5
New Member
 
Victor Carlos Teixeira
Join Date: Sep 2018
Posts: 3
Rep Power: 7
victorbelenense is on a distinguished road
It worked! It was the v2 ascii format as you said.

Thank you mzzmrt!
victorbelenense is offline   Reply With Quote

Old   October 25, 2018, 12:47
Default
  #6
New Member
 
Joseph Gonzalez
Join Date: Oct 2018
Posts: 1
Rep Power: 0
jaggonz is on a distinguished road
THANK YOU!! I wasted a tremendous amount of time trying to figure out the problem. Selecting v2 ASCII solved it!!!
jaggonz is offline   Reply With Quote

Old   February 8, 2019, 12:17
Default V2 ascii version OK, but still "bad token" error
  #7
New Member
 
Tom Alderweireldt
Join Date: Jan 2015
Location: Schilde, Belgium
Posts: 14
Rep Power: 11
Talder is on a distinguished road
I'm running OpenFoam v1812+ on Fedora 28, with gmsh 4.0.7 (all recent versions)
My gmsh file>export> doesn't allow me to indicate V2 ASCII or something like that.

However, looking at the header of the saved testmesh (4 connected cubes), that seems OK, it's version 2.2 ASCII, but gmshToFoam still gives me a 'bad token' error.



Any suggestion what else I can try, apart from editing the .msh file ?



(this used to work properly with GMSH 2 and OpenFoam 2.x versions)


$MeshFormat
2.2 0 8
$EndMeshFormat
$PhysicalNames
10
2 1 "inlet"
2 2 "outlet"
2 3 "leftwall"
2 4 "rightwall"
2 5 "top"
2 6 "bottom"
3 7 "V1"
3 8 "V2"
3 9 "V3"
3 10 "V4"
$EndPhysicalNames
$Nodes
7381
1 -0 -0 0
2 1 -0 0
3 0 0.5 0






[tom@localhost meshtest]$ gmshToFoam test2.msh
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v1812 |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
Build : v1812 OPENFOAM=1812
Arch : "LSB;label=32;scalar=64"
Exec : gmshToFoam test2.msh
Date : Feb 08 2019
Time : 17:54:19
Host : localhost.localdomain
PID : 9194
I/O : uncollated
Case : /home/tom/OpenFOAM/tom-v1812/run/meshtest
nProcs : 1
trapFpe: Floating point exception trapping enabled (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster (fileModificationSkew 10)
allowSystemOperations : Allowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Starting to read mesh format at line 2
Read format version 2.2 ascii 0

Starting to read physical names at line 5
Physical names:10
Surface 1 inlet
Surface 2 outlet
Surface 3 leftwall
Surface 4 rightwall
Surface 5 top
Surface 6 bottom
Volume 7 V1
Volume 8 V2
Volume 9 V3
Volume 10 V4

Starting to read points at line 18
Vertices to be read:7381
Vertices read:7381

Starting to read cells at line 7402
Cells to be read:8600

Mapping region 3 to Foam patch 0
Mapping region 6 to Foam patch 1
Mapping region 5 to Foam patch 2
Mapping region 1 to Foam patch 3
Mapping region 4 to Foam patch 4
Mapping region 2 to Foam patch 5
Mapping region 7 to Foam cellZone 0
Mapping region 8 to Foam cellZone 1
Mapping region 9 to Foam cellZone 2
Mapping region 10 to Foam cellZone 3
Cells:
total:6000
hex :6000
prism:0
pyr :0
tet :0

CellZones:
Zone Size
0 2000
1 1000
2 1000
3 2000



--> FOAM FATAL IO ERROR:
Bad token - could not get word

file: input at line 0.

From function Foam::Istream& Foam:perator>>(Foam::Istream&, Foam::word&)
in file primitives/strings/word/wordIO.C at line 45.

FOAM exiting
Talder is offline   Reply With Quote

Old   February 9, 2019, 06:35
Default gmshToFoam : bad token - could not find word : progress
  #8
New Member
 
Tom Alderweireldt
Join Date: Jan 2015
Location: Schilde, Belgium
Posts: 14
Rep Power: 11
Talder is on a distinguished road
I made a really simple gmsh testcube.geo in 3D. (4 x 4 x 4 ) 64-cell volume.

The file>export> *.msh V2 ASCII is OK.
Since the foam error wants a word, I just added "$end" at the end of the msh file.
Now gmshToFoam makes a polymesh. I do see the cube in paraFoam, but the internal mesh is missing.



So it is clear that gmshToFoam expects some more definition about 3D-internal mesh, not sure what else you can save after generating the 3D mesh in gmsh.


Hope someone sees what's missing
Tom.



Below is a view of the testcube.geo and testcube in paraFoam result. (and geo file)


testcube.geo:


//+
dim=1.0;

hz=1.0;
gridx=5;
gridy=5;
gridz=5;

Point(1) = {0.0, 0.0, 0.0, dim};
Point(2) = {0.0, 1.0, 0.0, dim};
Point(3) = {1.0, 1.0, 0.0, dim};
Point(4) = {1.0, 0.0, 0.0, dim};
Point(5) = {0.0, 0.0, hz, dim};
Point(6) = {0.0, 1.0, hz, dim};
Point(7) = {1.0, 1.0, hz, dim};
Point(8) = {1.0, 0.0, hz, dim};

Line(1) = {1,2};
Line(2) = {2,3};
Line(3) = {3,4};
Line(4) = {4,1};
Line(5) = {5,6};
Line(6) = {6,7};
Line(7) = {7,8};
Line(8) = {8,5};
Line(9) = {1,5};
Line(10) = {2,6};
Line(11) = {3,7};
Line(12) = {4,8};

// inlet box 1 surface loops
Line Loop(201) = {1,2,3,4};
Line Loop(202) = {5,6,7,8};
Line Loop(203) = {1,10,-5,-9};
Line Loop(204) = {2,11,-6,-10};
Line Loop(205) = {3,12,-7,-11};
Line Loop(206) = {4,9,-8,-12};

// define surface inlet box 1
Plane Surface(201) = {201};
Plane Surface(202) = {202};
Plane Surface(203) = {203};
Plane Surface(204) = {204};
Plane Surface(205) = {205};
Plane Surface(206) = {206};

//Make surfaces structured. Box 1
Transfinite Line{2,-4,6,-8} = gridx;
Transfinite Line{1,-3,5,-7} = gridy;
Transfinite Line{9,10,11,12} = gridz;

// define surface loops box1
Surface Loop(301) = {201,202,203,204,205,206};

Volume(301) = {301};

Transfinite Surface "*";
Recombine Surface "*";
Transfinite Volume "*";

//+
Physical Surface("inlet") = {203};
Physical Surface("outlet") = {205};
Physical Surface("walls") = {204, 206};
Physical Surface("top") = {202};
Physical Surface("bottom") = {201};

//+
Physical Volume("internalvolume") = {301};

//+
Attached Images
File Type: jpg testcube.jpg (74.5 KB, 22 views)
File Type: jpg cubeFoam.jpg (40.6 KB, 18 views)
Saleh Abuhanieh likes this.
Talder is offline   Reply With Quote

Old   February 9, 2019, 11:50
Default gmshToFoam : bad token resolved
  #9
New Member
 
Tom Alderweireldt
Join Date: Jan 2015
Location: Schilde, Belgium
Posts: 14
Rep Power: 11
Talder is on a distinguished road
Problem resolved, if useful for others.
The cube problem above is OK, paraFoam doesn't show internal wireframe cells.


The weird point is that gmshToFoam expects another word at the end of the .msh file.
If I add 1 line with "$end" to any old or new msh file from gmsh, it converts properly.



Tom.
Jost K likes this.
Talder is offline   Reply With Quote

Old   February 20, 2019, 05:17
Default
  #10
New Member
 
Paul Riesen
Join Date: Sep 2018
Posts: 1
Rep Power: 0
segelpaul is on a distinguished road
$End


works for me as well... Thank!!!
segelpaul is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Other] Converting 2D openFoam mesh to .msh miro2000 ANSYS Meshing & Geometry 1 January 14, 2022 13:03
Converting Salome hybrid mesh to OpenFOAM Arnoldinho OpenFOAM 4 March 28, 2012 10:24
[Gmsh] 2D Mesh Generation Tutorial for GMSH aeroslacker OpenFOAM Meshing & Mesh Conversion 12 January 19, 2012 03:52
[Gmsh] problem converting mesh from gmsh Fried OpenFOAM Meshing & Mesh Conversion 8 October 18, 2011 08:53
[Gmsh] gmshToFoam problem: not the same mesh in Gmsh vs. paraview zhernadi OpenFOAM Meshing & Mesh Conversion 8 July 7, 2011 02:28


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