This tutorial is intended to explain how to generated meshes using Gmsh, convert them to the dolfin xml mesh format, and read them in for your simulation. The attached archive GmshStokesInflow.tar.bz2 will produce the following simulation:
Using Gmsh
For this example, I am using Gmsh. To install it in on you can download a prebuilt binary.
-bash-3.00$ wget http://www.geuz.org/gmsh/bin/Linux/gmsh-2.0.7-Linux.tgz
-bash-3.00$ tar -xzf gmsh-2.0.7-Linux.tgz
Gmsh is neat, it comes with a mesh editor and a command line interface for scripting. It can do a lot of stuff but we will use if for just some very simple things. Here I will go through meshing up a rectangle with an ellipse in the top and bottom, with the command line interface.
Defining a geometry
There are several elementary mesh entities in the Gmsh format. These include Points, Lines, Surfaces, etc. To make a 2D plot we will define points, then lines based on those points, and finally a surface based on the lines. The geometry specification is written to a .geo file, that will be input to Gmsh for meshing.
First we define our points. For each line segment we need to end points. For the ellipsis, we need two end points, a center point and a point on the major axis (for this example it can be the center points). Also when we define the points, we must specify a length scale that will be used for determining the size of elements in the mesh.
lc = 1.0/128.0;
Point(1) = {0.0, 0.0, 0, lc};
Point(2) = {0.1, 0.0, 0, lc};
Point(3) = {0.5, -0.1, 0, lc} ; //Ellipse center point
Point(4) = {0.5, 0.1, 0, lc} ; // Ellipse top point
Point(5) = {0.9, 0.0, 0, lc};
Point(6) = {1.0, 0.0, 0, lc} ;
Point(7) = {1.0, 0.3, 0, lc};
Point(8) = {0.9, 0.3, 0, lc} ;
Point(9) = {0.5, 0.2, 0, lc} ; //Ellipse top point
Point(10) = {0.5, 0.4, 0, lc} ; //Ellipse center point
Point(11) = {0.1, 0.3, 0, lc};
Point(12) = {0.0, 0.3, 0, lc} ;
Now using the points we define our line segments. For circles and ellipsis, they cannot have an arc greater than $\Pi$ (or else Gmsh doesn't know which way to orient them), so for our mesh we chop our ellipsis into two parts.
Line(1) = {1,2};
Ellipse(2) = {4,3,3,2} ;
Ellipse(3)={4,3,3,5} ;
Line(4) = {5,6} ;
Line(5) = {6,7};
Line(6) = {7,8};
Ellipse(7) = {9,10,10,8} ;
Ellipse(8) = {9,10,10,11} ;
Line(9) = {11,12};
Line(10) = {12,1} ;
Now we need to define our surface. To do this we make a line loop (orientation matters) on the lines we made above and then define the surface on this loop. For our simple geometry, this will be the surface that is meshed in 2D, for more complicated problems see Gmsh's tutorials.
Line Loop(11) = {1,-2,3,4,5,6,-7,8,9,10} ;
Plane Surface(12) = {11} ;
Generating and view the mesh
To generate the mesh on the command line, one just needs to execute the binary we unpacked with -2 option and the test.geo file.
-bash-3.00$ gmsh-2.0.7-Linux/gmsh -2 test.geo
If you are on a computer with a display, you can use the gui to see/edit the mesh.
-bash-3.00$ gmsh-2.0.7-Linux/gmsh test.msh
Using the mesh in Dolfin
To use the mesh we must first convert the test.msh to test.xml, use the dolfin-convert script included in attached archive.
-bash-3.00$ python dolfin-convert test.msh test.xml
Then we change our Stokes example to read the mesh instead of using the UnitSquare.
Mesh mesh("test.xml");
We also need to change our NoSlip boundary condition, since it is no longer just when the y values are 0 or 1. Here we make it so that all points on the boundary but not on the left or right edge.
class NoslipBoundary : public SubDomain { bool inside(const real* x, bool on_boundary) { return on_boundary && x[0] > DOLFIN_EPS && x[0] < 1.0 - DOLFIN_EPS; } };
Now we have the Stokes simulation with a different geometry.
Commands for Example
-bash-3.00$ cd GmshStokesInflow
-bash-3.00$ gmsh -2 test.geo
...
-bash-3.00$ python dolfin-convert test.msh test.xml
...
-bash-3.00$ make
...
-bash-3.00$ ./dolfin-stokes-demo








