CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Meshing & Mesh Conversion (https://www.cfd-online.com/Forums/openfoam-meshing/)
-   -   [Gmsh] GMSH to OPenFOAM - What am I doing wrong? (https://www.cfd-online.com/Forums/openfoam-meshing/225255-gmsh-openfoam-what-am-i-doing-wrong.html)

Gimlas March 20, 2020 06:33

GMSH to OPenFOAM - What am I doing wrong?
 
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!

mzzmrt March 20, 2020 10:51

You have forgotten to define the volume, so just add this line to your script:

Physical Volume("air") = {1};

Gimlas March 21, 2020 14:00

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


mzzmrt March 22, 2020 03:17

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::polyMesh::polyMesh(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

Gimlas March 22, 2020 09:57

1 Attachment(s)
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.

mzzmrt March 23, 2020 09:44

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

Gimlas March 23, 2020 20:26

5 Attachment(s)
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?

mzzmrt March 24, 2020 00:58

Just do NOT use "save all elements" while exporting!

Gimlas March 24, 2020 16:58

2 Attachment(s)
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.

alexeym March 26, 2020 04:41

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.

Gimlas March 27, 2020 02:15

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

alexeym March 27, 2020 02:21

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.

Gimlas March 27, 2020 11:31

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.

thskretting December 3, 2021 10:21

I'm having the same problem. It seems like element 15 and 1 correspond to the points and lines, respectively, found in: gmsh - Tools - Statistics - Mesh. Haven't found a solution yet when using gmsh, however.

thskretting December 6, 2021 14:03

Fix
 
Things I found out when trying to fix this issue exporting from SOLIDWORKS to gmsh, and then to OpenFOAM:

If you're importing STEP file from SOLIDWORKS, you should add the command SetFactory("OpenCASCADE") in your .geo file. If I didn't do this, I could not extrude my mesh/fluid domain. I had to extrude it since OpenFOAM requires the mesh to be 3-dimensional. Extrude the mesh with one layer, where the size of this layer does not matter.

To add on this, I had to use 3D mesh when generating the mesh before importing into OpenFOAM.

Not only did I need to define physical surfaces, the physical volume also had to be defined before I could import it properly into OpenFOAM.

When exporting the mesh from gmsh, I went to File - Export, and used the .msh format. I then chose version 2 ASCII, and left both the "Save all elements" and "Save parametric coordinates" unchecked. If "Save all elements" was checked, I would get the "Unhandled element 1" and "Unhandled element 15" errors, since it saves the points (15) and lines (1) as well.

I hope someone found this helpful :D


All times are GMT -4. The time now is 20:05.