Manual For GMSH V2.0

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 3

Manual of Using Gmsh to generate 2D meshes

By Zhiqiu Li, Sep 6 2007

Intro
Gmsh is a software package that can create 2D/3D finite element meshes very easily. It
is developed by Prof. Christophe Geuzaine at Dept. of Electrical Engineering and
Computer Science, University of Lige. Download link is:
http://www.geuz.org/gmsh/doc/texinfo/
Since there is a step-by-step tutorial about how to generating a 2D mesh using Gmsh on
its website (http://geuz.org/gmsh/doc/gui_tutorial/), here I will just describe the general
idea and process of creating a 2D mesh, and how to get the nodes and elements data
from the resulting file.

General Process
The mesh of Gmsh is described by 3 levels, points, lines, and surface. You first create
several points on the plane and specify their coordinates, then connect those points into
lines. This will give you a general portrait of the mesh. The 3 rd step is to specify a
surface by combining several adjacent lines to form a close region, and you can also
specify a hole in this region by combining other lines in the similar way. The region in
that surface but not in the hole will use the setting of that surface to generate mesh,
while the hole doesnt. A hole is a region that will not generate mesh nodes in it. To set
different node density in this region, you have to specify the hole as another surface in
the same method mentioned before, then the Gmsh will create mesh nodes in this area
as well.

Menu Operation
To create points:
Set Geometry, choose Elementary entities -> Add -> New -> Point.
To create lines:
Set Geometry, choose Elementary entities -> Add -> New.
You can choose to create a straight line, or circle arc, or other shapes as you need.
You have to specify which points should be used to create this line.
To create surface:
Set Geometry, choose Elementary entities -> Add -> New -> Plane surface.
You have to specify which lines should be used to create this surface. And after that
you will be asked automatically if you want to create a hole in this surface.

To generate 2D meshes:
Set Mesh, and then press 2D. The resolution of the mesh is controlled by the
Notes; when you specifying points or lines, press e means to confirm and end this
selection, press q means quit and make no selection.

Read the File


The geometry of the mesh, which means the points, lines and surfaces of your mesh,
should be stored in extension of *.geo. The mesh file, which contains the coordinates
of all the nodes, and the elements, should be stored in extension of *.msh. Both file
types can be opened and edited easily using WordPad.

1. Understand the *.geo file

(1)
{50,
0,For
0,each
1};point, the first 3 parameters are the X-Y-Z coordinates, the last parameter specify the resolution aroun
Specify 4Point
points of
the =
outer
circle.
Point (2) = {0, 50, 0, 1};
Point (3) = {-50, 0, 0, 1};
Point (4) = {0, -50, 0, 1};
Point
Point
Point
Point

(5)
(6)
(7)
(8)

=
=
=
=

{40, 0, 0, 5};
{0, 40, 0, 5};
{-40, 0, 0, 5};
{0, -40, 0, 5};

Specify 4 points of the inner circle


Specify the center of 2 concentraic circles

Point (9) = {0, 0, 0, 1};


=
=
=
=

{1,
{2,
{3,
{4,

9,
9,
9,
9,

2};
3};
4};
1};

Specify 3 points to create a circle arc. Connect 4 circle arcs to form an entire outer circle

Circle
Circle
Circle
Circle

(1)
(2)
(3)
(4)

Circle
Circle
Circle
Circle

The similar way to form an entire inner circle


(5) = {5, 9, 6};
(6) = {6, 9, 7};
(7) = {7, 9, 8};
(8)
= {8,
9, to5};
Use lines
2,3,4,1
form a close outer boundary of the surface, use lines 5,8,6,7 to dig a hole in the surface. These 2 boundar

Line Loop (11) = {2, 3, 4, 1, -5, -8, -7, -6};

Using the Line Loop 11, which is the boundary defined above, to create a surface
Plane Surface (11) = {11};

Similar as above. Redefine the hole above into another surface. Then you can generate a mesh with different resolutio
Line Loop (12) = {6, 7, 8, 5};
Plane Surface (12) = {12};

2. Understand the *.msh file


The detail about the format of *.msh file can be found at
http://www.geuz.org/gmsh/doc/texinfo/gmsh_10.html#SEC65
I will only introduce the V2.0.8 we are using on Windows, and focus on the important
information we need in NIRFAST.
The general format of the *.msh file is as follows:
------------------------------------------------$MeshFormat
2.0 file-type data-size
$EndMeshFormat
$Nodes
number-of-nodes
node-number x-coord y-coord z-coord
...
$EndNodes
$Elements
number-of-elements
elm-number elm-type number-of-tags < tag > ... node-number-list
...
$EndElements
------------------------------------------------The number of nodes in the resulting mesh can be found on the 5th row, followed by the
complete list of nodes with their index and X-Y-Z coordinates.
The element part locates below the line written $Elements, the element number right
below it is NOT the right number of triangles in the mesh. The elements below include all
kinds of relations. You can find 19 kinds of relations on the official website, from 1-node
point to 27-node second order hexahedron (who knows what it is) But whats
important for us is the elements of triangles, which include ele-type 2 and 9. We only
need to find these 2 kinds of elements in the list.
For ele-type 2, the last three numbers are the elements of the triangle;
For ele-type 9, only the first 3 of the last 6 numbers are the elements of the triangle.
The total number of these two kinds of triangle elements should be the number of
triangles in the mesh. You can find this number by loading the *.msh file, and choose
Tools -> Statistics -> Mesh, and check the number before Triangles.
Now you have nodes and elements of the mesh, you can use it in NIRFast immediately!

You might also like