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

[Gmsh] GMSH to OPenFOAM - What am I doing wrong?

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 20, 2020, 06:33
Default GMSH to OPenFOAM - What am I doing wrong?
  #1
Member
 
Join Date: Nov 2011
Posts: 30
Rep Power: 10
Gimlas is on a distinguished road
Ok, so I've tried to make a simulation of a complex geometry however I've failed to import GMSH .msh file into OpenFOAM. Therefore I've decide to practice a little bit on a very simple geometry. Yet, still I cannot import the mesh using gmshToFoam command. I'll try to describe step by step what I am doing. Please help me with that issue. I think I am making a basic mistake but I have no idea what is it.

1. I've created a simple geometry of mixing tee using GMSH and saved it as geo file:

Quote:
// Gmsh project created on Fri Mar 20 11:50:21 2020
//+
SetFactory("OpenCASCADE");
Cylinder(1) = {0, 0, 0, 0, 0, 0.872, 0.023, 2*Pi};
//+
Cylinder(2) = {0, 0, 0.272, 0, 0.05, 0, 0.003, 2*Pi};
//+
BooleanUnion{ Volume{1}; Delete; }{ Volume{2}; Delete; }
//+
Physical Surface("inlet1") = {2};
//+
Physical Surface("inlet2") = {5};
//+
Physical Surface("outlet") = {3};
//+
Physical Surface("wall") = {1, 4};
2. Next I've generated 3D mesh. The file was saved as ASCII ver. 2. All elements were saved (including 3D).

3. I've copied the mesh file which looks like that:

Quote:
$MeshFormat
2.2 0 8
$EndMeshFormat
$PhysicalNames
4
2 1 "inlet1"
2 2 "inlet2"
2 3 "outlet"
2 4 "wall"
$EndPhysicalNames
$Nodes
16670
1 0.023 -5.633189227582935e-018 0.872
2 0.023 -5.633189227582935e-018 0
3 -7.347638122934188e-019 0.023 0.275
4 -7.347638122934188e-019 0.05 0.275
5 0.023 -5.633189227582935e-018 0.00435999999999999
6 0.023 -5.633189227582935e-018 0.00871999999999998
7 0.023 -5.633189227582935e-018 0.01307999999999997

.... (long string of coordinates)


90091 4 2 0 1 8290 13964 12401 9427
90092 4 2 0 1 7640 6541 2897 15768
90093 4 2 0 1 5859 7077 7424 15940
90094 4 2 0 1 14104 15684 11005 16172
90095 4 2 0 1 15259 7788 658 698
$EndElements
4. The mesh file was saved in a working directory. The constant directory is empty.

5. I've run gmshToFoam with the following result:

Quote:

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 7
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
Build : 7-1ff648926f77
Exec : gmshToFoam test1a.msh
Date : Mar 20 2020
Time : 12:04:01
Host : "DESKTOP-OAOLPVN"
PID : 258
I/O : uncollated
Case : /home/marcin/OpenFOAM/marcin-7/run/moja1
nProcs : 1
sigFpe : Enabling floating point exception trapping (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:4
Surface 1 inlet1
Surface 2 inlet2
Surface 3 outlet
Surface 4 wall

Starting to read points at line 12
Vertices to be read:16670
Vertices read:16670

Starting to read cells at line 16685
Cells to be read:90095

Unhandled element 15 at line 16687
Unhandled element 15 at line 16688
Unhandled element 15 at line 16689
Unhandled element 15 at line 16690
Unhandled element 1 at line 16691


.... (long list of elements)...

Unhandled element 1 at line 16970
Unhandled element 1 at line 16971
Unhandled element 1 at line 16972
Unhandled element 1 at line 16973
Unhandled element 1 at line 16974
Unhandled element 1 at line 16975
Mapping region 0 to Foam patch 0
Mapping region 0 to Foam cellZone 0
Cells:
total:73354
hex :0
prism:0
pyr :0
tet :73354

CellZones:
Zone Size
0 73354

Skipping tag at line 106783
Patch 0 gets name patch0

--> FOAM Warning :
From function Foam::polyMesh::polyMesh(const Foam::IOobject&, Foam::pointField&&, const cellShapeList&, const faceListList&, const wordList&, const wordList&, const Foam::word&, const Foam::word&, const wordList&, bool)
in file meshes/polyMesh/polyMeshFromShapeMesh.C at line 595
Found 16452 undefined faces in mesh; adding to default patch.
Finding faces of patch 0

FaceZones:
Zone Size

Writing zone 0 to cellZone cellZone_0 and cellSet
End
6. Exactly the same situation occurs when I try gmshToFoam the geo file.

So, what am I doing wrong? It looks so extremly simple on any of tutorials.

The situation is identical for GMSH (4.5.4) for windows (Win 10) and BlueCFD OpenFOAM (OF 5.x) as well as for GMSH (4.5.4) for Linux (Ubuntu) and OpenFoam 7.x.

Big thanks for help!
Gimlas is offline   Reply With Quote

Old   March 20, 2020, 10:51
Default
  #2
Member
 
Join Date: Mar 2014
Posts: 67
Rep Power: 8
mzzmrt is on a distinguished road
You have forgotten to define the volume, so just add this line to your script:

Physical Volume("air") = {1};
mzzmrt is offline   Reply With Quote

Old   March 21, 2020, 14:00
Default
  #3
Member
 
Join Date: Nov 2011
Posts: 30
Rep Power: 10
Gimlas is on a distinguished road
Dear mzzmrt,

The volume did not solve the problem:

Quote:
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 7
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
Build : 7-1ff648926f77
Exec : gmshToFoam test1b.msh
Date : Mar 21 2020
Time : 19:54:22
Host : "DESKTOP-OAOLPVN"
PID : 942
I/O : uncollated
Case : /home/marcin/OpenFOAM/marcin-7/run/moja1
nProcs : 1
sigFpe : Enabling floating point exception trapping (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:5
Surface 1 inlet1
Surface 2 inlet2
Surface 3 outlet
Surface 4 wall
Volume 5 fluid

Starting to read points at line 13
Vertices to be read:16670
Vertices read:16670

Starting to read cells at line 16686
Cells to be read:90095

Unhandled element 15 at line 16688
Unhandled element 15 at line 16689
Unhandled element 15 at line 16690
Unhandled element 15 at line 16691
Unhandled element 1 at line 16692
Unhandled element 1 at line 16693
Unhandled element 1 at line 16694
Unhandled element 1 at line 16695
Unhandled element 1 at line 16696

.... (string of coordinates)...

Unhandled element 1 at line 16968
Unhandled element 1 at line 16969
Unhandled element 1 at line 16970
Unhandled element 1 at line 16971
Unhandled element 1 at line 16972
Unhandled element 1 at line 16973
Unhandled element 1 at line 16974
Unhandled element 1 at line 16975
Unhandled element 1 at line 16976
Mapping region 0 to Foam patch 0
Mapping region 0 to Foam cellZone 0
Cells:
total:73354
hex :0
prism:0
pyr :0
tet :73354

CellZones:
Zone Size
0 73354

Skipping tag at line 106784
Patch 0 gets name patch0

--> FOAM Warning :
From function Foam::polyMesh::polyMesh(const Foam::IOobject&, Foam::pointField&&, const cellShapeList&, const faceListList&, const wordList&, const wordList&, const Foam::word&, const Foam::word&, const wordList&, bool)
in file meshes/polyMesh/polyMeshFromShapeMesh.C at line 595
Found 16452 undefined faces in mesh; adding to default patch.
Finding faces of patch 0

FaceZones:
Zone Size

Writing zone 0 to cellZone cellZone_0 and cellSet
End
Gimlas is offline   Reply With Quote

Old   March 22, 2020, 03:17
Default
  #4
Member
 
Join Date: Mar 2014
Posts: 67
Rep Power: 8
mzzmrt is on a distinguished road
Interesting! I have tried this with Gmsh 3.0.6 and OpenFOAM 4.1 on Linux and works as usual.


Here is the geo script:



// Gmsh project created on Fri Mar 20 11:50:21 2020
//+
SetFactory("OpenCASCADE");
Cylinder(1) = {0, 0, 0, 0, 0, 0.872, 0.023, 2*Pi};
//+
Cylinder(2) = {0, 0, 0.272, 0, 0.05, 0, 0.003, 2*Pi};
//+
BooleanUnion{ Volume{1}; Delete; }{ Volume{2}; Delete; }
//+
Physical Surface("inlet1") = {2};
//+
Physical Surface("inlet2") = {5};
//+
Physical Surface("outlet") = {3};
//+
Physical Surface("wall") = {1, 4};
//+
Physical Volume("air") = {1};





Here is the gmshToFoam result:


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:5
Surface 1 inlet1
Surface 2 inlet2
Surface 3 outlet
Surface 4 wall
Volume 5 air

Starting to read points at line 13
Vertices to be read:77
Vertices read:77

Starting to read cells at line 93
Cells to be read:264

Mapping region 4 to Foam patch 0
Mapping region 1 to Foam patch 1
Mapping region 3 to Foam patch 2
Mapping region 2 to Foam patch 3
Mapping region 5 to Foam cellZone 0
Cells:
total:114
hex :0
prism:0
pyr :0
tet :114

CellZones:
Zone Size
0 114

Skipping tag at line 360
Patch 0 gets name wall
Patch 1 gets name inlet1
Patch 2 gets name outlet
Patch 3 gets name inlet2

--> FOAM Warning :
From function Foam:olyMesh:olyMesh(const Foam::IOobject&, const Foam::Xfer<Foam::Field<Foam::Vector<double> > >&, const cellShapeList&, const faceListList&, const wordList&, const wordList&, const Foam::word&, const Foam::word&, const wordList&, bool)
in file meshes/polyMesh/polyMeshFromShapeMesh.C at line 595
Found 150 undefined faces in mesh; adding to default patch.
Finding faces of patch 0
Finding faces of patch 1
Finding faces of patch 2
Finding faces of patch 3

FaceZones:
Zone Size

Writing zone 0 to cellZone air and cellSet
End
mzzmrt is offline   Reply With Quote

Old   March 22, 2020, 09:57
Default
  #5
Member
 
Join Date: Nov 2011
Posts: 30
Rep Power: 10
Gimlas is on a distinguished road
Could it be an issue with the GMSH 4.5.4? I've tried to walk around this problem. I've exported the mesh into nastran file, then it was imported to fluent. In fluent also no boundaries were visible (inlet, outlet, wall) but the mesh was ok. But I've named the surfaces and exported cas file. The cas file was imported to OpenFoam correctly.

I've attached the geo file with mesh generated for element size factor = 0.25. Dear mzzmrt I would be gratefull if you could take a look at them. Could you try to import the msh file into OpenFoam? Could you generate such msh file for me and I'll try to import it.
Attached Files
File Type: zip test1d.zip (30.2 KB, 1 views)
Gimlas is offline   Reply With Quote

Old   March 23, 2020, 09:44
Default
  #6
Member
 
Join Date: Mar 2014
Posts: 67
Rep Power: 8
mzzmrt is on a distinguished road
I have tried your *.msh file but there is a problem with it.


I have made and exported the mesh with gmsh 4.5.4 (named as x.msh) and imported it to the OpenFOAM 7, no problem at all. You can get this mesh and the secreen capture at


http://www.fileconvoy.com/dfl.php?id...1e93d59e5657b1
mzzmrt is offline   Reply With Quote

Old   March 23, 2020, 20:26
Default
  #7
Member
 
Join Date: Nov 2011
Posts: 30
Rep Power: 10
Gimlas is on a distinguished road
Thank you for your answer. The mesh also works for me.

Concluding the problem is at the stage of mesh export. I've asked my colleague to download gmsh and generate a simple mesh of any random geometry. He has encountered exactly the same issue. All surfaces stitched into patch0.
The same proble appears in GMSH 4.5.5.

One of the difference between your mesh and my mesh is the elements notation. In your mesh it is:
$Elements
73952
1 2 2 4 1 1 1231 83

In my mesh:
$Elements
2120
1 15 2 0 1 1

(7 parameters vs. 5 parameters)

I've attached the step by step screens presenting the mesh export process. What am I doing wrong?
Attached Images
File Type: jpg 1.jpg (37.6 KB, 3 views)
File Type: jpg 2.jpg (76.0 KB, 2 views)
File Type: jpg 3.jpg (59.7 KB, 1 views)
File Type: jpg 4.jpg (88.0 KB, 3 views)
File Type: jpg 5.jpg (64.7 KB, 4 views)
Gimlas is offline   Reply With Quote

Old   March 24, 2020, 00:58
Default
  #8
Member
 
Join Date: Mar 2014
Posts: 67
Rep Power: 8
mzzmrt is on a distinguished road
Just do NOT use "save all elements" while exporting!
mzzmrt is offline   Reply With Quote

Old   March 24, 2020, 16:58
Default
  #9
Member
 
Join Date: Nov 2011
Posts: 30
Rep Power: 10
Gimlas is on a distinguished road
Your advise works as long as I am using geometry generated in GMSH. Then, everything works fine. But when I've exported a step file another problem appeard. Take a look on the screenshots. When the mesh is saved without "all elements" option GMSH saves only the surface mesh of patches (although a physical patch of volume is also made). When I try to import such mesh to OpenFoam the following error appears:

Quote:
$ gmshToFoam MESH3.msh
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 5.x |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
/* Windows 32 and 64 bit porting by blueCAPE: http://www.bluecape.com.pt *\
| Based on Windows porting (2.0.x v4) by Symscape: http://www.symscape.com |
\*---------------------------------------------------------------------------*/
Build : 5.x-963176928289
Exec : C:/PROGRA~1/BLUECF~1/OpenFOAM-5.x/platforms/mingw_w64GccDPInt32Opt/bin/gmshToFoam.exe MESH3.msh
Date : Mar 24 2020
Time : 22:46:20
Host : "DESKTOP-OAOLPVN"
PID : 4924
I/O : uncollated
Case : C:/PROGRA~1/BLUECF~1/ofuser-of5/run/elbow
nProcs : 1
SigFpe : Enabling floating point exception trapping (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:4
Surface 1 inlet1
Surface 2 inlet2
Surface 3 outlet
Volume 4 fluid

Starting to read points at line 12
Vertices to be read:57
Vertices read:57

Starting to read cells at line 72
Cells to be read:79

Mapping region 2 to Foam patch 0
Mapping region 3 to Foam patch 1
Mapping region 1 to Foam patch 2
Cells:
total:0
hex :0
prism:0
pyr :0
tet :0



--> FOAM FATAL IO ERROR:
No cells read from file "MESH3.msh"
Does your file specify any 3D elements (hex=5, prism=6, pyramid=7, tet=4)?
Perhaps you have not exported the 3D elements?

file: MESH3.msh at line 153.

From function void readCells(Foam::scalar, bool, const pointField&, const Foam::Map<int>&, Foam::IFstream&, Foam::cellShapeList&, Foam::labelList&, Foam::List<Foam::DynamicList<Foam::face> >&, Foam::labelList&, Foam::List<Foam::DynamicList<int> >&)
in file gmshToFoam.C at line 726.

FOAM exiting
If the mesh is exported with "all elements" option then it is imported to openfoam but a significant number of unhandled elements appears and the surfaces are combined into patch0.
Attached Images
File Type: jpg 1.jpg (51.4 KB, 4 views)
File Type: jpg 2.jpg (33.9 KB, 2 views)
Gimlas is offline   Reply With Quote

Old   March 26, 2020, 04:41
Default
  #10
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,922
Rep Power: 34
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

1. gmshToFoam converts MSH files, not GEO.
2. gmshToFoam converts version 2 MSH files (-format msh2 command line switch). Though if you files are version 4, usually error is different.
3. gmshToFoam can handle only these types of elements:
Code:
static label MSHTRI   = 2;
static label MSHQUAD  = 3;
static label MSHTET   = 4;
static label MSHPYR   = 7;
static label MSHPRISM = 6;
static label MSHHEX   = 5;
It is not clear what mesh elements Gmsh generates for you.
alexeym is offline   Reply With Quote

Old   March 27, 2020, 02:15
Default
  #11
Member
 
Join Date: Nov 2011
Posts: 30
Rep Power: 10
Gimlas is on a distinguished road
Hi alexeym,

The problem appears only when the geometry is created via stp file import. In all other cases everything works fine. And the stp file is ok - it was used in ANSYS MESH and in Salome mesh module without any issues.

I guess I'll have to switch to other software.

Best regards
Gimlas is offline   Reply With Quote

Old   March 27, 2020, 02:21
Default
  #12
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,922
Rep Power: 34
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

If you have Ansys or Salome mesh, why not just import it into OpenFOAM?

If you have STP, you can convert it to STL and then use snappyHexMesh to create mesh.

Guess, since you are ready to switch to another software, utilitsation of Gmsh for meshing is not your aim.
alexeym is offline   Reply With Quote

Old   March 27, 2020, 11:31
Default
  #13
Member
 
Join Date: Nov 2011
Posts: 30
Rep Power: 10
Gimlas is on a distinguished road
I was forced to use the open-license sotwere (I have some experience using ANSYS Fluent but it could not be used in this case). When I asked for advice for the best meshing software everyone told me to try GMSH. Unfortunately, it did not work form me. I switched to Salome and it works.

Well, thank you all for your help.
Gimlas is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
[Gmsh] Trying to convert an already generated gmsh to OpenFOAM syavash OpenFOAM Meshing & Mesh Conversion 3 March 11, 2020 10:15
OpenFOAM Training Jan-Jul 2017, Virtual, London, Houston, Berlin CFDFoundation OpenFOAM Announcements from Other Sources 0 January 4, 2017 06:15
udf error srihari FLUENT 1 October 31, 2016 14:18
[Gmsh] gmsh to openFoam Artex85 OpenFOAM Meshing & Mesh Conversion 1 December 2, 2011 03:31
New OpenFOAM Forum Structure jola OpenFOAM 2 October 19, 2011 06:55


All times are GMT -4. The time now is 01:13.