gmsh gui tutorial i: how to create a simple 2d...

51
Gmsh GUI Tutorial I: How to Create a Simple 2D Model? Christophe Geuzaine and Jean-Fran¸ cois Remacle January 4, 2006 http://geuz.org/gmsh/doc/gui_tutorial/

Upload: lythuy

Post on 03-May-2018

225 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

Gmsh GUI Tutorial I: How to Create a Simple 2D Model?

Christophe Geuzaine and Jean-Francois Remacle

January 4, 2006

http://geuz.org/gmsh/doc/gui_tutorial/

Page 2: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

This tutorial shows all the steps involved in the creation of a simple two-dimensional ge-ometry using Gmsh’s graphical user interface.

We start by launching Gmsh, then we click on ‘Elementary’ to create new elementarygeometrical entities.

2

Page 3: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We click on ‘Add’ to add an entity. This is the only sensible choice since there are no otherelementary entities to manipulate at the moment.

3

Page 4: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We click on ‘New’ to add a new entity. If other entities were present, we could transformthem using the ‘Translate’, ‘Rotate’, ..., buttons.

4

Page 5: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

Gmsh’s CAD modeler works by using boundary representations of geometrical entities, soif we want to define a 2D model (i.e., surfaces) we first need to create points and curves.

So we start by clicking on ‘Point’ to add new points.

5

Page 6: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

A contextual dialog appears, where we can directly enter the X, Y, Z coordinates of a newpoint (as well as the target mesh size at this point).

Later we will see that, instead of entering the point coordinates by hand, we can also createpoints using the mouse.

6

Page 7: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We want to create our first point at the position (0.4, 0.0, 0.0), with a target mesh charac-teristic length of 0.1.

So we enter X=0.4, Y=0.0 and Z=0.0 and we click on ‘Add’: this creates our first point.

If we opened the project file (‘untitled.geo’) with a text editor, we would see that Gmshhas added the line

Point(1) = {0.4,0.0,0.0,0.1};

at the end of the file.

7

Page 8: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We add a second point at (X,Y,Z) = (0.6,0.0,0.0).

8

Page 9: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We add a third point at (X,Y,Z) = (0.6,0.2,0.0).

9

Page 10: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We add a fourth point at (X,Y,Z) = (0.4,0.2,0.0).

10

Page 11: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

Instead of entering the point coordinates in the dialog window, we can also create pointsdirectly with the mouse.

For this, we just position the mouse at the desired location in the graphic window, and wepress ‘e’ when we are done. This adds the fifth point in our model.

11

Page 12: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We also add the sixth point using the mouse. To fine-tune the position, we can hold the‘Shift’ key and edit the value in the dialog.

We add the points 7, 8, 9 and 10 in the same way, then press ‘q’.

12

Page 13: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

If we opened the project file with a text editor, we would see that the file now contains thedefinition of all ten points:

Point(1) = {0.4,0.0,0.0,0.1};Point(2) = {0.6,0.0,0.0,0.1};Point(3) = {0.6,0.2,0.0,0.1};Point(4) = {0.4,0.2,0,0.1};Point(5) = {0.412935,0.0211087,0,0.1};Point(6) = {0.546553,0.0374556,0,0.1};Point(7) = {0.445629,0.151173,0,0.1};Point(8) = {0.484009,0.151173,0,0.1};Point(9) = {0.444208,0.120611,0,0.1};Point(10) = {0.490405,0.1199,0,0.1};

We are done dealing with points for now, so we can close the dialog.

13

Page 14: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

Now we need to create some curves, and we start by creating a series of straight linesegments.

In order to create straight lines, we click on the ‘Straight line’ button.

14

Page 15: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

A straight line segment is defined by a start point and an end point. We select the startpoint by clicking on it (here we click on point 9).

15

Page 16: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

The start point is now highlighted (and we could undo our selection by pressing ‘u’).

To complete the first line segment, we select the end point (point 10) by clicking on it.

16

Page 17: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

This has the effect to create a new line segment (the first line) that joins the points 9 and10.

If we opened the project file with a text editor, we would see that Gmsh has added the line

Line(1)={9,10};

at the end of the file.

17

Page 18: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We proceed by creating other line segments in exactly the same way, first selecting the startpoint, then the end point.

18

Page 19: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

The second line segment is created, joining the points 10 and 8.

We proceed by creating seven more line segments, joining the points 8 and 7, 7 and 9, 5and 6, 1 and 2, 2 and 6, 1 and 5 and, finally, 6 and 3.

19

Page 20: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We now have 9 straight lines.

If we opened the project file with a text editor, we would see that the file now contains thedefinition of all ten points and all nine lines:

Point(1) = {0.4,0.0,0.0,0.1};Point(2) = {0.6,0.0,0.0,0.1};Point(3) = {0.6,0.2,0.0,0.1};Point(4) = {0.4,0.2,0,0.1};Point(5) = {0.412935,0.0211087,0,0.1};Point(6) = {0.546553,0.0374556,0,0.1};Point(7) = {0.445629,0.151173,0,0.1};Point(8) = {0.484009,0.151173,0,0.1};Point(9) = {0.444208,0.120611,0,0.1};Point(10) = {0.490405,0.1199,0,0.1};Line(1) = {9,10};Line(2) = {10,8};Line(3) = {8,7};Line(4) = {7,9};Line(5) = {5,6};Line(6) = {1,2};Line(7) = {2,6};Line(8) = {1,5};Line(9) = {6,3};

20

Page 21: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

Since we are done with the straight lines, we can press ‘q’.

21

Page 22: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

The last curve we want to create is a spline. So we click on the ‘Spline’ button in the menu.

22

Page 23: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We select the first control point by clicking on it.

23

Page 24: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We do the same for the second control point.

24

Page 25: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

And we finally also select the third control point by clicking on it.

25

Page 26: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

All the control points being selected, we can end the spline definition by pressing ‘e’.

26

Page 27: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

This creates the spline.

If we opened the project file with a text editor, we would see that Gmsh has added thefollowing line at the end of the file:

CatmullRom(10) = {3,4,5};

27

Page 28: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

Since we are done with the spline definition, we press ‘q’.

28

Page 29: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We are now ready to create some surfaces. Since this is a planar 2D geometry, we click onthe ‘Plane surface’ button in the menu to create some planar surfaces.

29

Page 30: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

In Gmsh surfaces are defined by their boundaries, so we start by selecting the exteriorboundary of our first surface (the “small one”) by clicking on one of the segments on itsboundary.

30

Page 31: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

Gmsh completes the line loop automatically. And since there are no holes in this firstsurface, we press ‘e’.

31

Page 32: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

This has the effect to create the first surface in our model. The surface is represented onscreen by the dashed cross.

If we opened the project file with a text editor, we would see that Gmsh has added the twolines

Line Loop(11) = {3,4,1,2};Plane Surface(12) = {11};

at the end of the file. The first line defines the line loop (a closed path representing theexterior boundary of the surface) and the second line defines the surface as being composedof this single line loop.

32

Page 33: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We proceed in the same manner to define our second surface, by selecting one curve on itsexterior boundary. This time, Gmsh cannot close the line loop automatically.

33

Page 34: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We select the missing line in order to close the loop. But we are not done yet: this newsurface has a hole in the middle, which we need to select, too.

34

Page 35: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We select the hole boundary by clicking on one of the segments on its boundary. Then wecan press ‘e’ to end the surface definition.

35

Page 36: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

And we have our second surface (with a hole inside).

If we opened the project file with a text editor, we would see that Gmsh has added the twolines

Line Loop(13) = {10,5,9};Plane Surface(14) = {13,11};

at the end of the file. The first line defines the exterior line loop and the second line definesthe surface by a list of two line loops: the exterior boundary first, then the boundary ofthe hole.

36

Page 37: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We finally select the boundary of the third surface by clicking on the line segment 5.

37

Page 38: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

And we close the loop by selecting one of the remaining segments in the loop.

38

Page 39: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

As with the other two, the third and last surface is displayed using a dashed cross.

39

Page 40: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We are done creating surfaces, so we can press ‘q’.

Our geometrical model is complete: ‘untitled.geo’.

40

Page 41: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We now want to mesh our model, so we go to the module menu.

41

Page 42: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We select ‘Mesh’ in the module menu.

42

Page 43: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We then click on ‘2D’ to generate the 2D mesh.

Since we asked for characteristic lengths of 0.1 and the model’s width and height are about0.2, the resulting mesh is very coarse.

43

Page 44: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

In order to generate a more refined mesh, we could edit the project file (‘untitled.geo’) andchange the characteristic lengths associated with the points.

But we can also change the characteristic length globally in the graphical interface. Inorder to do so, we open the ‘Tools’ menu, and select ‘Options’.

44

Page 45: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

The option dialog pops up.

45

Page 46: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We select ‘Mesh’ to access the mesh options.

46

Page 47: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We select the ‘General’ mesh options panel, and we specify a global mesh characteristiclength factor of 0.1.

47

Page 48: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We apply the change by clicking on ‘Apply’.

48

Page 49: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We can then for example remesh the lines with the new characteristic length by pressingon ‘1D’, which results in a much finer grid (about 20 points per side, instead of 2).

49

Page 50: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

We then remesh the surfaces with the new characteristic length by pressing the ‘2D’ button.

50

Page 51: Gmsh GUI Tutorial I: How to Create a Simple 2D Model?home.cc.umanitoba.ca/~lovetrij/cECE4390/Labs/Lab 4/GMSH_tutorial.… · This tutorial shows all the steps involved in the creation

Finally, since this mesh suits our needs, we can save it by clicking on the ‘Save’ button.This creates the following file: ‘untitled.msh’.

To choose a different file format, we could open the ‘File’ menu, choose ‘Save As’, and selectthe appropriate format in the dialog.

That’s all, folks!

51