I am trying to understand the structure of a msh file, in order to be able to extract the nodes coordinates and their connectivity (for use in a plot with pgf/tikz). To do so I decided to make the first tutorial (t1.py) with a coarse mesh. When the file is generated, some info are written in the terminal and I can see the right number of nodes. But for elements, it is not the same. And I also can't understand a lot of things in the msh file.
Below is the script I use (t1 with some modified parameters):
import gmsh
import sys
gmsh.initialize()
gmsh.model.add("t1")
lc = 10
gmsh.model.geo.addPoint(0, 0, 0, lc, 1)
gmsh.model.geo.addPoint(10, 0, 0, lc, 2)
gmsh.model.geo.addPoint(10, 10, 0, lc, 3)
p4 = gmsh.model.geo.addPoint(0, 10, 0, lc)
gmsh.model.geo.addLine(1, 2, 1)
gmsh.model.geo.addLine(3, 2, 2)
gmsh.model.geo.addLine(3, p4, 3)
gmsh.model.geo.addLine(4, 1, p4)
gmsh.model.geo.addCurveLoop([4, 1, -2, 3], 1)
gmsh.model.geo.addPlaneSurface([1], 1)
gmsh.model.geo.synchronize()
gmsh.model.addPhysicalGroup(1, [1, 2, 4], 5)
gmsh.model.addPhysicalGroup(2, [1], name="My surface")
gmsh.model.mesh.generate(2)
gmsh.write("t1.msh")
if '-nopopup' not in sys.argv:
gmsh.fltk.run()
gmsh.finalize()
When I launch the script, the info in the terminal says 5 nodes (ok) and 12 elements (how is that ?). But when I open the file, now gmsh counts 7 elements. But I count 5 nodes, 8 lines, and 4 faces (see mesh.png). So I do not understand what "elements" means.
Then for the msh file. I just would like to know how to decode it. It is written below:
$MeshFormat
4.1 0 8
$EndMeshFormat
$PhysicalNames
1
2 6 "My surface"
$EndPhysicalNames
$Entities
4 4 1 0
1 0 0 0 0
2 10 0 0 0
3 10 10 0 0
4 0 10 0 0
1 0 0 0 10 0 0 1 5 2 1 -2
2 10 0 0 10 10 0 1 5 2 3 -2
3 0 10 0 10 10 0 0 2 3 -4
4 0 0 0 0 10 0 1 5 2 4 -1
1 0 0 0 10 10 0 1 6 4 4 1 -2 3
$EndEntities
$Nodes
8 5 1 5
0 1 0 1
1
0 0 0
0 2 0 1
2
10 0 0
0 3 0 1
3
10 10 0
0 4 0 1
4
0 10 0
1 1 0 0
1 2 0 0
1 4 0 0
2 1 0 1
5
5 5 0
$EndNodes
$Elements
4 7 1 7
1 1 1 1
1 1 2
1 2 1 1
2 3 2
1 4 1 1
3 4 1
2 1 2 4
4 1 2 5
5 4 1 5
6 2 3 5
7 3 4 5
$EndElements
For example, with the Nodes
section. I don't know (except that there are 5 nodes) what the first line 8 5 1 5
means. The second line is a mystery to me also. But then I have 1
, followed by 0 0 0
. As I understand it, those two lines stand for the point number, and its coordinates (x, y, z). So following this logic, every line with 1 or 3 numbers I can understand. But the ones with 4 numbers are not clear for me. Can anyone tell me what they mean ?
For the Elements
part it is worse, only thing I can make logic is the number 4
, I suppose it refers to the number of faces... But I have no clue what the rest is.
For the lines with 4 numbers, I suppose the first number of each line is a label, and then the next three numbers refers to my nodes, as the numbers range from 1 to 5.
Anyway, I just would like to have an explanation about this file. It is not very large so I assume the explanation should be quite easy, but I can't find it.