t1.geo 4.09 KB
Newer Older
Christophe Geuzaine committed
1
/*********************************************************************
2 3
 *
 *  Gmsh tutorial 1
Christophe Geuzaine committed
4
 *
5
 *  Variables, elementary entities (points, lines, surfaces), physical
6
 *  entities (points, lines, surfaces)
7 8 9
 *
 *********************************************************************/

10
// The simplest construction in Gmsh's scripting language is the
11
// `affectation'. The following command defines a new variable `lc':
12

13
lc = 1e-2;
14

15
// This variable can then be used in the definition of Gmsh's simplest
16 17 18
// `elementary entity', a `Point'. A Point is defined by a list of four numbers:
// three coordinates (X, Y and Z), and a characteristic length (lc) that sets
// the target element size at the point:
19

20
Point(1) = {0, 0, 0, lc};
21

22 23
// The distribution of the mesh element sizes is then obtained by interpolation
// of these characteristic lengths throughout the geometry. Another method to
24 25
// specify characteristic lengths is to use general mesh size Fields (see
// `t10.geo'). A particular case is the use of a background mesh (see `t7.geo').
26

27 28 29 30 31
// We can then define some additional points as well as our first curve.  Curves
// are Gmsh's second type of elementery entities, and, amongst curves, straight
// lines are the simplest. A straight line is defined by a list of point
// numbers. In the commands below, for example, the line 1 starts at point 1 and
// ends at point 2:
32 33 34 35 36 37 38 39 40 41

Point(2) = {.1, 0,  0, lc} ;
Point(3) = {.1, .3, 0, lc} ;
Point(4) = {0,  .3, 0, lc} ;

Line(1) = {1,2} ;
Line(2) = {3,2} ;
Line(3) = {3,4} ;
Line(4) = {4,1} ;

42 43 44 45
// The third elementary entity is the surface. In order to define a simple
// rectangular surface from the four lines defined above, a line loop has first
// to be defined. A line loop is a list of connected lines, a sign being
// associated with each line (depending on the orientation of the line):
46

47
Line Loop(1) = {4,1,-2,3} ;
48

49 50
// We can then define the surface as a list of line loops (only one here, since
// there are no holes--see `t4.geo'):
51

52
Plane Surface(1) = {1} ;
53

54 55 56
// At this level, Gmsh knows everything to display the rectangular surface 6 and
// to mesh it. An optional step is needed if we want to associate specific
// region numbers to the various elements in the mesh (e.g. to the line segments
57
// discretizing lines 1 to 4 or to the triangles discretizing surface 1). This
58 59
// is achieved by the definition of `physical entities'. Physical entities will
// group elements belonging to several elementary entities by giving them a
60
// common number (a region number).
61

62
// We can for example group the points 1 and 2 into the physical entity 1:
63 64 65

Physical Point(1) = {1,2} ;

66 67 68 69
// Consequently, two punctual elements will be saved in the output mesh file,
// both with the region number 1. The mechanism is identical for line or surface
// elements:

Christophe Geuzaine committed
70 71
MY_LINE = 2;
Physical Line(MY_LINE) = {1,2} ;
Christophe Geuzaine committed
72
Physical Line("My second line (automatic physical id)") = {3} ;
Christophe Geuzaine committed
73
Physical Line("My third line (physical id 5)", 5) = {4} ;
74
Physical Surface("My surface") = {1} ;
75 76

// All the line elements created during the meshing of lines 1 and 2 will be
Christophe Geuzaine committed
77
// saved in the output mesh file with the physical id 2. The elements from line
78
// 3 will be saved in the output mesh file with an automatic physical id,
Christophe Geuzaine committed
79 80 81 82 83
// associated with the label "My second line (automatic physical id)". The
// elements from line 4 will be saved with physical id 5, associated with the
// label "My third line (physical id 5)". And finally, all the triangular
// elements resulting from the discretization of surface 6 will be given an
// automatic physical id associated with the label "My surface").
84
//
85 86
// Note that if no physical entities are defined, then all the elements in the
// mesh will be saved "as is", with their default orientation.
87 88 89 90 91 92 93 94 95 96 97 98 99

// Starting with Gmsh 3.0, models can also be built using constructive solid
// geometry. Instead of the built-in geometry kernel, you need to use the
// OpenCASCADE kernel:
//
//   SetFactory("OpenCASCADE");
//
// In addition to the "bottom-up" geometry commands, you can now use "top-down"
// commands, like e.g.
//
//   Rectangle(2) = {.2, 0, 0, 0.1, 0.3};
//
// See tutorial/t16.geo for an example, and demos/boolean for more.