How to Create a Mesh using Gmsh
Gmsh is a free mesh generator available on the net. The Gmsh website can be found at: http://www.geuz.org/gmsh/
We will describe here the procedure for installing, creating a simple mesh and exporting it to use it with COOLFluiD.
Note that this Tutorial takes the version 1.65 as example.
The actual Gmsh version will depend from the code status, however, this tutorial should be fairly standard.
Start downloading the binaries from the website (the user manual can also be useful).
We will assume here that you are running Linux.
Having the binary package http://www.geuz.org/gmsh/bin/Linux/gmsh-1.65.0-Linux.tgz you should:
1. Install Gmsh
tar -xzvf gmsh-1.65.0-Linux.tgz cd gmsh-1.65.0/ ./gmsh
This will unpack the surce code into the gmsh-1.65.0 directory and allow you to check that you can run Gmsh.
2. Create a geometry
For this part, we will not use the graphical interface of Gmsh, but we will rather use files to build our geometry (according to me, it is easier this way).
So you can leave Gmsh and create a file in your favorite editor.
We will make a simple I beam mesh as an example. The Gmsh approach is a bottom to top approach... which means that you:
- define points,
- then you define lines by linking the points,
- then you define faces linking the lines,
- finally you define the volumes linking the faces
We should first create the points that we will use. In the mesh file, we start by writing:
Point(1) = {0, 0, 0, 0.065};
Point(2) = {1, 0, 0, 0.065};
Point(3) = {1, 0.2, 0, 0.065};
Point(4) = {0.6, 0.2, 0, 0.065};
Point(5) = {0.4, 0.2, 0, 0.065};
Point(6) = {0, 0.2, 0, 0.065};
Point(7) = {0, 0.8, 0, 0.065};
Point(8) = {0.4, 0.8, 0, 0.065};
Point(9) = {0.6, 0.8, 0, 0.065};
Point(10) = {1, 0.8, 0, 0.065};
Point(11) = {0, 1, 0, 0.065};
Point(12) = {1, 1, 0, 0.065};
Point(13) = {0, 0, 10, 0.065};
Point(14) = {1, 0, 10, 0.065};
Point(15) = {1, 0.2, 10, 0.065};
Point(16) = {0.6, 0.2, 10, 0.065};
Point(17) = {0.4, 0.2, 10, 0.065};
Point(18) = {0, 0.2, 10, 0.065};
Point(19) = {0, 0.8, 10, 0.065};
Point(20) = {0.4, 0.8, 10, 0.065};
Point(21) = {0.6, 0.8, 10, 0.065};
Point(22) = {1, 0.8, 10, 0.065};
Point(23) = {0, 1, 10, 0.065};
Point(24) = {1, 1, 10, 0.065};
Then we create the edges, or lines
Line (1) = {24, 12};
Line (2) = {22, 10};
Line (3) = {15, 3};
Line (4) = {14, 2};
Line (5) = {2, 3};
Line (6) = {10, 12};
Line (7) = {24, 22};
Line (8) = {15, 14};
Line (9) = {21, 9};
Line (10) = {4, 16};
Line (11) = {15, 16};
Line (12) = {21, 16};
Line (13) = {21, 22};
Line (14) = {24, 23};
Line (15) = {23, 19};
Line (16) = {19, 20};
Line (17) = {20, 17};
Line (18) = {17, 18};
Line (19) = {18, 13};
Line (20) = {13, 14};
Line (21) = {12, 11};
Line (22) = {11, 7};
Line (23) = {7, 8};
Line (24) = {8, 5};
Line (25) = {5, 6};
Line (26) = {6, 1};
Line (27) = {1, 2};
Line (28) = {4, 3};
Line (30) = {9, 10};
Line (31) = {9, 4};
Line (32) = {11, 23};
Line (33) = {19, 7};
Line (34) = {6, 18};
Line (35) = {13, 1};
Line (36) = {8, 20};
Line (47) = {17, 5};
Note that for each of these lines or points (and later surfaces), we can assign a density in order to adjust the mesh density)by using the command:
Characteristic Length {23} = 0.1;
Then we can create the surfaces from a sequence of lines.
For each surface, we will create a lineloop and we will use it to define the surface.
Line Loop (1000038) = {32, -14, 1, 21};
Plane Surface (38) = {1000038};
Line Loop (1000040) = {3, -5, -4, -8};
Plane Surface (40) = {1000040};
Line Loop (1000042) = {3, -28, 10, -11};
Plane Surface (42) = {1000042};
Line Loop (1000044) = {11, -12, 13, -7, 14, 15, 16, 17, 18, 19, 20, -8};
Plane Surface (44) = {1000044};
Line Loop (1000046) = {34, 19, 35, -26};
Plane Surface (46) = {1000046};
Line Loop (1000049) = {18, -34, -25, -47};
Plane Surface (49) = {1000049};
Line Loop (1000051) = {24, -47, -17, -36};
Plane Surface (51) = {1000051};
Line Loop (1000053) = {33, 23, 36, -16};
Plane Surface (53) = {1000053};
Line Loop (1000055) = {22, -33, -15, -32};
Plane Surface (55) = {1000055};
Line Loop (1000057) = {1, -6, -2, -7};
Plane Surface (57) = {1000057};
Line Loop (1000059) = {13, 2, -30, -9};
Plane Surface (59) = {1000059};
Line Loop (1000061) = {9, 31, 10, -12};
Plane Surface (61) = {1000061};
Line Loop (1000063) = {20, 4, -27, -35};
Plane Surface (63) = {1000063};
Line Loop (1000065) = {21, 22, 23, 24, 25, 26, 27, 5, -28, -31, 30, 6};
Plane Surface (65) = {1000065};
We now have the surfaces describing the geometry, but we still need to define the volumes:
Surface Loop(1000066) = {53,55,-65,38,44,42,-40,-63,-46,-49,51,-61,-59,-57};
Volume(1000067) = {1000066};
3. Create a mesh using Gmsh
Assume you have named the file we have just created ibeam.geo, you can now import it into Gmsh to create a mesh or even to modify it.
cd gmsh-1.65.0/ ./gmsh ibeam.geo
You should see your I-beam appearing in the graphical interface window.
You can:
- rotate the view using the mouse left-button.
- zoom/unzoom using the mouse center button.
- move the view using the right-button.
Now, if you click in the small menu window, you should change the option from
Geometry to Mesh.
There, you can just click on the 3D button to mesh the volume and you are done, you have your mesh!!!
Remember that the definition of the mesh density is done in the file using characteristic length command.
Click on save to save the mesh as ibeam.msh.
You now have a mesh file for a I-beam.
Let's see how to use it in COOLFluiD.
4. Using a Gmsh file in COOLFluiD
In COOLFluiD, there exist a Gmsh2CFmesh converter that will convert your ibeam.msh into a ibeam.CFmesh file.
However, we still need to give some informations to execute that conversion.
Therefore, we will have to create a file called ibeam.SP that will contain
information about the boundaries of the mesh and the names that we want to asign to them. These names will be the future TRS names.
The InField
We first have to define the entity that will be exported as InField in the CFmesh file.
In a 3D case, the InField corresponds to a 3D mesh.
In our case, the InField corresponds to the only volume, to which we had assigned the number 1000067 (in the .geo file)
We will put the following code in the SP file:
InField 1000067
Note that the name asoociated to the InField can only be named InField (case sensistive)
The Boundaries
We then have to define the entities that will be exported as TRS's in the CFmesh file.
We have to associate a surface (or a series of surfaces) to a TRS name.
In Gmsh, surfaces are identified by a physical region ID.
But the physical ID of a surface is however NOT the ID that we assigned in the .geo file!!!
In order to check the ID of the surfaces, we will use the Visibility tool of Gmsh.
- In the small menu window, click on Tools
- In the Tools submenu, click on Visibility. This tool allows you to see part of the mesh.
- First start by unselecting everything in the Elementary/Physical/Partitions.
- Click on Apply. You should not see anything anymore in the Main Window.
- Now select the menu Physical and Mesh and select one surface.
- Click on Apply. You should now see only one surface. It is the surface corresponding to the Physical region selected.
Now that we can check the Physical Region ID of each surface, we can associate the surfaces with a TRS by inserting the following lines into the SP file:
Boundary 1 44
These lines mean that you assign the name Boundary to one surface. and that this surface PhysicalRegion ID is 44.
Consider now the case in whcihc you would like to define a common TRS Boundary for the two surfaces 44 and 65.
You should now write:
Boundary 2 44 65
Etc...for all the TRS's you may want to export.
In the I-Beam case, if we only need to export the two I-sections of the beam, represented by the surfaces ID 44 and 65.
The ibeam.SP file will be written:
3 InField 1000067 Bound1 1 44 Bound2 1 65
in which the first line indicates the number of TRS + InField to convert.
In this case, we have:
- One InField (for the moment, only one InField is accepted)
- Two Boundaries: Bound1 and Bound2
So, the first line indicates 3
5. Gmsh and the CFcase
In the CFcase, you should now just use the Gmsh2CFmesh converter, using Bound1 and Bound2 as TRS's names
