Chi-Tech
GmshStructuredTutorial1.h
Go to the documentation of this file.
1/** \page GmshExample_01 Mesh Tutorial 5: Example using gmsh to create a structured mesh
2
3This tutorial demonstrates creating a structured mesh using gmsh: https://gmsh.info/
4
5The geometry to be created and meshed with a structured mesh is shown below. The tutorial will describe how to build the geometry in steps.
6
7 \image html Meshing/gmsh_tutorials/mesh.png "The geometry to be created and meshed with a structured mesh" width=600px
8
9Gmsh can be used soley from the terminal or it can be used through the gmsh graphical user interface (GUI). In this tutorial, the mesh will be created by entering text into a file and then having the GUI read the file and display the mesh. Instead of manually adding text to the input file, the GUI can also be used to create the mesh, although that is not done here. First, create a new file and open it with the gui so that text can be entered. The sample file in this tutorial will be called structured_ex.geo Note that the kernel option "Built-in" is used for this tutorial. If a different kernel is used, the general idea of this tutorial will still apply, but some details may be different. Additionally, gmsh version 4.0.6 is being used. Other versions of gmsh should also be usable with this tutorial, but some details may not apply.
10
11\image html Meshing/gmsh_tutorials/new_file.gif "Create a new file" width=800px
12
13The first step in creating a mesh is to create some shape that will be meshed. The shape to be meshed will be created by specifying points and then connecting these points with lines. For this tutorial, a square shape is first created. To create the square, four points are speficied and these are connected by four lines. The gmsh input is shown below and this is the first text to put into the structured_ex.geo file. Notice the points are specified with the syntax Point(i)={x,y,z} where "i" is the tag that identifies that point and "{x,y,z}". The tag identifying each point must be unique and tags must not be 0. For simplicity, sequentially increasing integers are used as tags in this tutorial. There is a fourth optional argument that can be used when building a point "Point(i)={x,y,z,d}" where "d" specifies how fine the mesh should be at that point. A lower number will result in a finer mesh. This optional argument is not used in this tutorial. In the input file, you can also define variables and use some common functions defined in gmsh. This is demonstrated below where variables pitch, circle_r, and bottom_left_cirle are deinfed and will be used later. In later input, the function Cos(x) is used.
14
15 \verbatim
16pitch = 0.0126;
17circle_r = 0.0108/2;
18bottom_left_circle = pitch/2;
19
20Point(1) = {0, 0, 0};
21Point(2) = {pitch, 0, 0};
22Point(3) = {pitch, pitch, 0};
23Point(4) = {0, pitch, 0};
24//
25// Outer Box domain
26//
27Line(1) = {1, 2};
28Line(2) = {2, 3};
29Line(3) = {3, 4};
30Line(4) = {4, 1};
31 \endverbatim
32
33\image html Meshing/gmsh_tutorials/first_square.gif "Add the text shown above to your input text file, save, and then click \"Reload script\" after which gmsh will read your input and display the result." width=1200px
34
35At this point, gmsh does not know that the four lines defined form a closed surface. In fact, we will not use the square directly, but instead break it into multiple several shapes. Next, a circle is created in the middle of the existing square. The variables defined previously as well as the Cos function is used in the example below. Point(5) is the center of the circle. The next 4 points are evenly spaced along the perimeter of the circle. The reason for the points being placed at locations that intersect the diagonals of the bounding square will be apparent in the next step.
36
37Note the new syntax "Line Loop(1) = {-5,-6,-7,-8};" and "Surface(1) = {1};" which specifies to gmsh that the four lines 5,6,7,8 are meant to be connected into a loop and that this loop, given tag 1, defines a surface, also given the tag 1. The tag does not need to be the same, but in this case the surface and line loops are seperate entities and so can have the same tag. Note that when defining the line loops, some of the line tags start with negative numbers. The line loop must have a certain orientation. That is, the points which make up the lines and thus the line loop must be ordered. All loops are clockwise in this tutorial. You can mouse over the lines in the GUI to see the ording of the points. For example, Line Loop(1) consists of lines made up of points (6,7); (7,8); (8,9); (9,6). But this is backward with respect to clockwise orientation. The negative sign flips ordering of the points making up the line thus to be (6,7) becomes (7,6) etc.
38
39 \verbatim
40// Points that make up the circle
41Point(5) = {bottom_left_circle,bottom_left_circle,0.0};
42Point(6) = {bottom_left_circle-circle_r*Cos(Pi/4.)/2.,bottom_left_circle+circle_r*Cos(Pi/4.)/2.,0.0};
43Point(7) = {bottom_left_circle-circle_r*Cos(Pi/4.)/2.,bottom_left_circle-circle_r*Cos(Pi/4.)/2.,0.0};
44Point(8) = {bottom_left_circle+circle_r*Cos(Pi/4.)/2.,bottom_left_circle-circle_r*Cos(Pi/4.)/2.,0.0};
45Point(9) = {bottom_left_circle+circle_r*Cos(Pi/4.)/2.,bottom_left_circle+circle_r*Cos(Pi/4.)/2.,0.0};
46
47// Curves that connect points defining circle
48Circle(5) = {6,5,7};
49Circle(6) = {7,5,8};
50Circle(7) = {8,5,9};
51Circle(8) = {9,5,6};
52// specify closed loop to make surface
53Curve Loop(1) = {-5,-8,-7,-6};
54Surface(1) = {1};
55\endverbatim
56
57\image html Meshing/gmsh_tutorials/circle_in_square.png "Add a circular surface to the center of the square" width=600px
58
59To make a structured mesh in gmsh, shapes with four sides are needed. At this point, the circular shape can be meshed with a structured algorithm, but the region outside of the circle can't. This region is next broken into four sided shapes as shown in the input below.
60
61 \verbatim
62// break area outside circle into four surfaces
63// First define lines, the line loops, then the
64// surfaces
65Line(9) = {1,7};
66Line(10) = {8,2};
67Line(11) = {9,3};
68Line(12) = {6,4};
69
70Curve Loop(3) = {9,6,10,-1};
71Curve Loop(4) = {-10,7,11,-2};
72Curve Loop(5) = {-11,8,12,-3};
73Curve Loop(6) = {-12,5,-9,-4};
74
75Surface(2) = {3};
76Surface(3) = {4};
77Surface(4) = {5};
78Surface(5) = {6};
79 \endverbatim
80
81\image html Meshing/gmsh_tutorials/cell1.png "Add a circular surface to the center of the square" width=600px
82
83The single cell now created is copied four times and translated. The input for this is shown below. The variable "pitch" defined at the top of the file is used. Notice the "Coherence;" commant. This command removes repeated items such as repeated points and line. Some of the copied eneties overlap and without this command (test this out), several lines and points will overlap. The image below shows how to use the gui to see the new lines and points created by the duplication process. The tags for these new lines are needed for the next steps. It is possible that a different gmsh version may lead to different numbering, so the input in this tutorial may need to be adjusted.
84
85\verbatim
86Translate{ pitch, 0.0, 0.0} { Duplicata{Surface{1};} }
87Translate{ 0.0, pitch, 0.0} { Duplicata{Surface{1};} }
88Translate{ pitch, pitch, 0.0} { Duplicata{Surface{1};} }
89
90Translate{ pitch, 0.0, 0.0} { Duplicata{Surface{2};} }
91Translate{ 0.0, pitch, 0.0} { Duplicata{Surface{2};} }
92Translate{ pitch, pitch, 0.0} { Duplicata{Surface{2};} }
93
94Translate{ pitch, 0.0, 0.0} { Duplicata{Surface{3};} }
95Translate{ 0.0, pitch, 0.0} { Duplicata{Surface{3};} }
96Translate{ pitch, pitch, 0.0} { Duplicata{Surface{3};} }
97
98Translate{ pitch, 0.0, 0.0} { Duplicata{Surface{4};} }
99Translate{ 0.0, pitch, 0.0} { Duplicata{Surface{4};} }
100Translate{ pitch, pitch, 0.0} { Duplicata{Surface{4};} }
101
102Translate{ pitch, 0.0, 0.0} { Duplicata{Surface{5};} }
103Translate{ 0.0, pitch, 0.0} { Duplicata{Surface{5};} }
104Translate{ pitch, pitch, 0.0} { Duplicata{Surface{5};} }
105
106Coherence;
107\endverbatim
108
109\image html Meshing/gmsh_tutorials/visibility.gif "Copy some repeated geometry and use the gui to see the tags for the new lines and surfaces." width=1200px
110
111Next, the additional four sided shapes are created as shown in the first image at the top of the page. These five surfaces will be specified as being one physical surface in later input.
112
113\verbatim
114Point(104) = {0, 4*pitch, 0};
115Point(105) = {pitch, 4*pitch, 0};
116Point(106) = {2*pitch, 4*pitch, 0};
117Point(107) = {4*pitch, 4*pitch, 0};
118
119Point(108) = {4*pitch , 2*pitch, 0};
120Point(109) = {4*pitch , pitch, 0};
121Point(110) = {4*pitch , 0, 0};
122
123
124Line(77) = {103,104};
125Line(78) = {104,105};
126Line(79) = {105,81};
127
128Line(80) = {105,106};
129Line(81) = {106,92};
130
131Line(82) = {106,107};
132Line(83) = {107,108};
133Line(84) = {108,92};
134
135Line(85) = {108,109};
136Line(86) = {109,70};
137
138Line(87) = {109,110};
139Line(88) = {110,59};
140
141Curve Loop(100) = {77,78,79,-65};
142Curve Loop(101) = {81,-70,-79,80};
143Curve Loop(102) = {82,83,84,-81};
144Curve Loop(103) = {85,86,-56,-84};
145Curve Loop(104) = {87,88,-46,-86};
146
147Surface(100) = {100};
148Surface(101) = {101};
149Surface(102) = {102};
150Surface(103) = {103};
151Surface(104) = {104};
152\endverbatim
153
154\image html Meshing/gmsh_tutorials/full_geo.png "All of the four sided shapes are completed" width=600
155
156The surfaces created thus far are for construction purposes. We now specify the surfaces and lines that are physical. The physical lines are those defining a problem boundary. There are two types of surfaces in this mesh being created, those inside a cylinder and those outside a cylinder. Currently, the physical surface tags must start at 0 and increase sequentially to be used with chi-tech. The physical surface tag will serve as an array index for the stack of materials defined in a chi-tech input.
157
158 \verbatim
159Physical Line(0) = {1,32,88};
160Physical Line(1) = {87,85,83};
161Physical Line(2) = {78,80,82};
162Physical Line(3) = {4,76,77};
163Physical Surface(0) = {1,13,18,23};
164Physical Surface(1) = {2,3,4,5,28,42,57,71,37,52,66,77,33,47,61,72,100,101,102,103,104};
165\endverbatim
166
167Next, a structured mesh will be defined. The "Transfinite Line" command is used. This command specifies opposing faces of the four sided shapes we will apply a structured mesh to and also how many grid points will be used when drawing mesh lines between the two defined faces. "Using Progression 1" indicates that the structured mesh should have uniform grading. Note that in the outer region of the geometry, "Using Progression 0.85" is used. This causes the meshing to be graded. Also note the input "Transfinite Line {-77, 79}" where the negative sign ensures that both lines have the same orientation which is required when using a grading. Test the input without this and see that the grading is flipped on one side.
168
169After the transfinite lines are specified, each surface is specified to be mesh with a structured mesh by the syntax "Transfinite Surface {i}". Lastly, "Recombine Surface "*";" is included to specify that the mesh be made up of quadrilaterials. If this input is not included, then gmsh will create a mesh of structured triangles.
170
171 \verbatim
172// bottom left cell
173Transfinite Line {5, 7} = 10 Using Progression 1;
174Transfinite Line {6, 8} = 10 Using Progression 1;
175//
176Transfinite Line {9, 10} = 15 Using Progression 1;
177Transfinite Line {6, 1} = 10 Using Progression 1;
178//
179Transfinite Line {10, 11} = 15 Using Progression 1;
180Transfinite Line {7, 2} = 10 Using Progression 1;
181//
182Transfinite Line {12, 11} = 15 Using Progression 1;
183Transfinite Line {3, 8} = 10 Using Progression 1;
184//
185Transfinite Line {12, 9} = 15 Using Progression 1;
186Transfinite Line {4, 5} = 10 Using Progression 1;
187//
188Transfinite Surface {1};
189Transfinite Surface {2};
190Transfinite Surface {3};
191Transfinite Surface {4};
192Transfinite Surface {5};
193
194
195// bottom right cell
196Transfinite Line {14, 16} = 10 Using Progression 1;
197Transfinite Line {17, 15} = 10 Using Progression 1;
198//
199Transfinite Line {29, 31} = 15 Using Progression 1;
200Transfinite Line {17, 32} = 10 Using Progression 1;
201//
202Transfinite Line {31, 45} = 15 Using Progression 1;
203Transfinite Line {16, 46} = 10 Using Progression 1;
204//
205Transfinite Line {45, 60} = 15 Using Progression 1;
206Transfinite Line {15, 41} = 10 Using Progression 1;
207//
208Transfinite Line {60, 29} = 15 Using Progression 1;
209Transfinite Line {2, 14} = 10 Using Progression 1;
210//
211Transfinite Surface {28};
212Transfinite Surface {42};
213Transfinite Surface {57};
214Transfinite Surface {71};
215Transfinite Surface {13};
216
217// top right cell
218Transfinite Line {24, 26} = 10 Using Progression 1;
219Transfinite Line {25, 27} = 10 Using Progression 1;
220//
221Transfinite Line {38, 40} = 15 Using Progression 1;
222Transfinite Line {27, 41} = 10 Using Progression 1;
223//
224Transfinite Line {40, 55} = 15 Using Progression 1;
225Transfinite Line {26, 56} = 10 Using Progression 1;
226//
227Transfinite Line {55, 69} = 15 Using Progression 1;
228Transfinite Line {25, 70} = 10 Using Progression 1;
229//
230Transfinite Line {69, 38} = 15 Using Progression 1;
231Transfinite Line {51, 24} = 10 Using Progression 1;
232//
233Transfinite Surface {37};
234Transfinite Surface {52};
235Transfinite Surface {66};
236Transfinite Surface {77};
237Transfinite Surface {23};
238
239// top left cell
240Transfinite Line {19, 21} = 10 Using Progression 1;
241Transfinite Line {20, 22} = 10 Using Progression 1;
242//
243Transfinite Line {34, 36} = 15 Using Progression 1;
244Transfinite Line {22, 3} = 10 Using Progression 1;
245//
246Transfinite Line {36, 50} = 15 Using Progression 1;
247Transfinite Line {21, 51} = 10 Using Progression 1;
248//
249Transfinite Line {50, 64} = 15 Using Progression 1;
250Transfinite Line {20, 65} = 10 Using Progression 1;
251//
252Transfinite Line {64, 34} = 15 Using Progression 1;
253Transfinite Line {19, 76} = 10 Using Progression 1;
254//
255Transfinite Surface {33};
256Transfinite Surface {47};
257Transfinite Surface {61};
258Transfinite Surface {72};
259Transfinite Surface {18};
260
261
262//outside region
263
264Transfinite Line {65, 78} = 10 Using Progression 1;
265Transfinite Line {-77, 79} = 20 Using Progression 0.85;
266//
267Transfinite Line {70, 80} = 10 Using Progression 1;
268Transfinite Line {79, 81} = 20 Using Progression 0.85;
269//
270Transfinite Line {81, 83} = 20 Using Progression 0.85;
271Transfinite Line {-82, 84} = 20 Using Progression 0.85;
272//
273Transfinite Line {84, 86} = 20 Using Progression 0.85;
274Transfinite Line {56, 85} = 10 Using Progression 1;
275//
276Transfinite Line {86, 88} = 20 Using Progression 0.85;
277Transfinite Line {46, 87} = 10 Using Progression 1;
278
279Transfinite Surface {100};
280Transfinite Surface {101};
281Transfinite Surface {102};
282Transfinite Surface {103};
283Transfinite Surface {104};
284
285Recombine Surface "*";
286 \endverbatim
287
288Note that currently only msh file format 2.2 in asci format is read by chi-tech.
289
290\image html Meshing/gmsh_tutorials/meshing.gif "Use the gui to create the mesh, examine it, and save the msh file." width=1200px
291
292*/