1+ // Gmsh project created on Wed Dec 4 14:27:19 2024
2+ // -----------------------------------------------------------------------------
3+ //
4+ // Gmsh GEO tutorial 1
5+ //
6+ // Geometry basics, elementary entities, physical groups
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-1 ;
14+
15+ // This variable can then be used in the definition of Gmsh's simplest
16+ // `elementary entity', a `Point'. A Point is uniquely identified by a tag (a
17+ // strictly positive integer; here `1') and defined by a list of four numbers:
18+ // three coordinates (X, Y and Z) and the target mesh size (lc) close to the
19+ // point:
20+
21+
22+
23+ // The distribution of the mesh element sizes will then be obtained by
24+ // interpolation of these mesh sizes throughout the geometry. Another method to
25+ // specify mesh sizes is to use general mesh size Fields (see `t10.geo'). A
26+ // particular case is the use of a background mesh (see `t7.geo').
27+
28+ // If no target mesh size of provided, a default uniform coarse size will be
29+ // used for the model, based on the overall model size.
30+
31+ // We can then define some additional points. All points should have different
32+ // tags:
33+
34+ Point(1 ) = {0 , - 1.0000 , 0 , lc};
35+ Point(2 ) = {0 , 1.0000 , 0 , lc};
36+ Point(3 ) = {1.9015 , 1.6190 , 0 , lc};
37+ Point(4 ) = {3.0777 , 0 , 0 , lc};
38+ Point(5 ) = {1.9015 , - 1.6190 , 0 , lc};
39+
40+ // Point(1) = {0.8507, 0, 0, lc};
41+ // Point(2) = {0.2629, 0.8090, 0, lc};
42+ // Point(3) = {-0.6882, 0.5000, 0, lc};
43+ // Point(4) = {-0.6882, -0.5000, 0, lc};
44+ // Point(5) = {0.2629, -0.8090, 0, lc};
45+
46+ // Curves are Gmsh's second type of elementary entities, and, amongst curves,
47+ // straight lines are the simplest. A straight line is identified by a tag and
48+ // is defined by a list of two point tags. In the commands below, for example,
49+ // the line 1 starts at point 1 and ends at point 2.
50+ //
51+ // Note that curve tags are separate from point tags - hence we can reuse tag
52+ // `1' for our first curve. And as a general rule, elementary entity tags in
53+ // Gmsh have to be unique per geometrical dimension.
54+
55+ Line(1 ) = {1 , 2 };
56+ Line(2 ) = {2 , 3 };
57+ Line(3 ) = {3 , 4 };
58+ Line(4 ) = {4 , 5 };
59+ Line(5 ) = {5 , 1 };
60+
61+ // The third elementary entity is the surface. In order to define a simple
62+ // rectangular surface from the four curves defined above, a curve loop has
63+ // first to be defined. A curve loop is also identified by a tag (unique amongst
64+ // curve loops) and defined by an ordered list of connected curves, a sign being
65+ // associated with each curve (depending on the orientation of the curve to form
66+ // a loop):
67+
68+ Curve Loop(1 ) = {1 , 2 , 3 , 4 , 5 };
69+
70+ // We can then define the surface as a list of curve loops (only one here,
71+ // representing the external contour, since there are no holes--see `t4.geo' for
72+ // an example of a surface with a hole):
73+
74+ Plane Surface(1 ) = {1 };
75+
76+ // At this level, Gmsh knows everything to display the rectangular surface 1 and
77+ // to mesh it. An optional step is needed if we want to group elementary
78+ // geometrical entities into more meaningful groups, e.g. to define some
79+ // mathematical ("domain", "boundary"), functional ("left wing", "fuselage") or
80+ // material ("steel", "carbon") properties.
81+ //
82+ // Such groups are called "Physical Groups" in Gmsh. By default, if physical
83+ // groups are defined, Gmsh will export in output files only mesh elements that
84+ // belong to at least one physical group. (To force Gmsh to save all elements,
85+ // whether they belong to physical groups or not, set `Mesh.SaveAll=1;', or
86+ // specify `-save_all' on the command line.) Physical groups are also identified
87+ // by tags, i.e. strictly positive integers, that should be unique per dimension
88+ // (0D, 1D, 2D or 3D). Physical groups can also be given names.
89+ //
90+ // Here we define a physical curve that groups the left, bottom and right curves
91+ // in a single group (with prescribed tag 5); and a physical surface with name
92+ // "My surface" (with an automatic tag) containing the geometrical surface 1:
93+
94+ Physical Line("l1") = {1 };
95+ Physical Line("l2") = {2 };
96+ Physical Line("l3") = {3 };
97+ Physical Line("l4") = {4 };
98+ Physical Line("l5") = {5 };
99+
100+ Physical Curve(“b1”) = {1 , 2 , 4 };
101+ Physical Curve("b2") = {3 };
102+
103+ Physical Surface("My surface") = {1 };
104+
105+ // Now that the geometry is complete, you can
106+ // - either open this file with Gmsh and select `2D' in the `Mesh' module to
107+ // create a mesh; then select `Save' to save it to disk in the default format
108+ // (or use `File->Export' to export in other formats);
109+ // - or run `gmsh t1.geo -2` to mesh in batch mode on the command line.
110+
111+ // You could also uncomment the following lines in this script:
112+ //
113+ Mesh 2 ;
114+ Save "pentagon_mesh.msh";
115+ //
116+ // which would lead Gmsh to mesh and save the mesh every time the file is
117+ // parsed. (To simply parse the file from the command line, you can use `gmsh
118+ // t1.geo -')
119+
120+ // By default, Gmsh saves meshes in the latest version of the Gmsh mesh file
121+ // format (the `MSH' format). You can save meshes in other mesh formats by
122+ // specifying a filename with a different extension in the GUI, on the command
123+ // line or in scripts. For example
124+ //
125+ // Save "t1.unv";
126+ //
127+ // will save the mesh in the UNV format. You can also save the mesh in older
128+ // versions of the MSH format:
129+ //
130+ // - In the GUI: open `File->Export', enter your `filename.msh' and then pick
131+ // the version in the dropdown menu.
132+ // - On the command line: use the `-format' option (e.g. `gmsh file.geo -format
133+ // msh2 -2').
134+ // - In a `.geo' script: add `Mesh.MshFileVersion = x.y;' for any version
135+ // number `x.y'.
136+ // - As an alternative method, you can also not specify the format explicitly,
137+ // and just choose a filename with the `.msh2' or `.msh4' extension.
138+
139+ // Note that starting with Gmsh 3.0, models can be built using other geometry
140+ // kernels than the default built-in kernel. By specifying
141+ //
142+ // SetFactory("OpenCASCADE");
143+ //
144+ // any subsequent command in the `.geo' file would be handled by the OpenCASCADE
145+ // geometry kernel instead of the built-in kernel. Different geometry kernels
146+ // have different features. With OpenCASCADE, instead of defining the surface by
147+ // successively defining 4 points, 4 curves and 1 curve loop, one can define the
148+ // rectangular surface directly with
149+ //
150+ // Rectangle(2) = {.2, 0, 0, .1, .3};
151+ //
152+ // The underlying curves and points could be accessed with the `Boundary' or
153+ // `CombinedBoundary' operators.
154+ //
155+ // See e.g. `t16.geo', `t18.geo', `t19.geo' or `t20.geo' for complete examples
156+ // based on OpenCASCADE, and `examples/boolean' for more.
0 commit comments