v0.14.0
Using Gmsh

In this tutorial, the use of Gmsh is explained as an alternative pre-processor. The version of the Gmsh used for this tutorial is 4.0.6 (MacOSX). A step-by-step procedure is given here to solve a linear-elastic cantilever beam problem subjected to uniform pressure.

Creating geometry

A new geometry file is created in Gmsh using the following procedure:

File -> New -> Choose location -> chose name, e.g. gmesh_beam.geo -> Save -> OpenCASCADE

Subsequently, the beam geometry is created using the following steps:

Module -> Geometry -> Elementary entities -> Add -> Box

and use, e.g. the following inputs: X=0, Y=0, Z=0, DX=10, DY=1, DZ=1 then click "add" and subsequently press "q" to abort. The output beam geometry is shown in following Figure:

Beam geometry

Creating physical groups

Physical groups, i.e. physical volumes and physical surfaces are used to define material blocks and boundary conditions. For the beam problem, "Volume 1" is used for assigning material properties including Young's modulus and Poisson's ratio. Similarly, surfaces "Plane 1" and "Plane 4" are used to define displacement and pressure boundary conditions. The following procedure are used to define the physical volume:

Module -> Physical groups -> Add -> Volume

give it a name, e.g. ElasticBlock and select "Volume 1" and press "e" to end and "q" to abort. Similarly, for the displacement boundary condition use the following procedure:

Module -> Geometry -> Physical groups -> Add -> Surface

give it a name, e.g. DispBC and select "Plane 1" and press "e" to end "q" to abort. Finally, for the pressure boundary conditions use the following procedure:

Module -> Physical groups -> Add -> Surface

give it a name, e.g. PressureBC and select "Plane 4" and press "e" to end "q" to abort. These physical group can be seen in the Visibility dialog box by using:

Tools -> Visibility -> Physical groups

For the beam problem, "Visibility" dialog box with three physical groups are shown in the following figure.

Physical groups view in the Visibility dialog box

Alternatively, these physical groups can also be seen by switching on "Surface labels" and "Volume labels" in the "Option" dialog box, which can be open using:

Tools -> Option -> Geometry

For the beam problem, the "Option" dialog box is shown as following figure:

Physical groups view using Option dialog box

These gmesh_beam.geo file can be open in any text editor and provide alternative way to change the geometry. The gemsh_beam.geo file is shown as follows:

// Gmsh project created on Thu Dec 20 09:20:14 2018
SetFactory("OpenCASCADE");
Box(1) = {0, 0, 0, 10, 1, 1};
Physical Volume("ElasticBlock") = {1};
Physical Surface("DispBC") = {1};
Physical Surface("PressureBC") = {4};

Meshing

The beam geometry can be meshed using the following procedure

Module -> Mesh -> 1D -> 2D -> 3D

The generated tetrahedral mesh is shown in the following Figure:

Gmsh beam geometry

The generated mesh file needs to be saved in a specific format by following the procedure:

File -> Export... -> select name, e.g. gmesh_beam.msh and select Mesh - Gmsh MSH (*.msh) -> select format as Version 2 ASCII -> OK

The gmesh_beam.msh file, consisting of 86 nodes and 247 elements are given as follows:

$MeshFormat
2.2 0 8
$EndMeshFormat
$PhysicalNames
3
2 2 "DispBC"
2 3 "PressureBC"
3 1 "ElasticBlock"
$EndPhysicalNames
$Nodes
91
1 0 0 1
2 0 0 0
3 0 1 1
4 0 1 0
5 10 0 1
6 10 0 0
7 10 1 1
8 10 1 0
9 1.000000000000002 0 0
10 2.000000000000006 0 0
11 3.000000000000009 0 0
12 4.000000000000013 0 0
13 5.000000000000011 0 0
14 6.000000000000009 0 0
15 7.000000000000006 0 0
16 8.000000000000004 0 0
17 9.000000000000002 0 0
18 1.000000000000002 0 1
19 2.000000000000006 0 1
20 3.000000000000009 0 1
21 4.000000000000013 0 1
22 5.000000000000011 0 1
23 6.000000000000009 0 1
24 7.000000000000006 0 1
25 8.000000000000004 0 1
26 9.000000000000002 0 1
27 1.000000000000002 1 0
28 2.000000000000006 1 0
29 3.000000000000009 1 0
30 4.000000000000013 1 0
31 5.000000000000011 1 0
32 6.000000000000009 1 0
33 7.000000000000006 1 0
34 8.000000000000004 1 0
35 9.000000000000002 1 0
36 1.000000000000002 1 1
37 2.000000000000006 1 1
38 3.000000000000009 1 1
39 4.000000000000013 1 1
40 5.000000000000011 1 1
41 6.000000000000009 1 1
42 7.000000000000006 1 1
43 8.000000000000004 1 1
44 9.000000000000002 1 1
45 0 0.5 0.5
46 10 0.5 0.5
47 3.500000000000012 0 0.5
48 8.5 0 0.5
49 9.5 0 0.5
50 1.500000000000004 0 0.5
51 2.500000000000008 0 0.5
52 5.50000000000001 0 0.5
53 6.500000000000007 0 0.5
54 7.500000000000005 0 0.5
55 0.5000000000000011 0 0.5
56 4.500000000000012 0 0.4999999999999996
57 3.500000000000011 1 0.5
58 8.5 1 0.5
59 9.5 1 0.5
60 1.500000000000004 1 0.5
61 2.500000000000008 1 0.5
62 4.500000000000012 1 0.5000000000000004
63 5.50000000000001 1 0.5
64 6.500000000000007 1 0.5
65 7.500000000000005 1 0.5
66 0.5000000000000011 1 0.5
67 3.500000000000012 0.5 0
68 8.5 0.5 0
69 5.50000000000001 0.5 0
70 1.500000000000004 0.5 0
71 2.500000000000008 0.5 0
72 4.500000000000012 0.5000000000000004 0
73 7.500000000000004 0.5 0
74 0.5000000000000011 0.5 0
75 6.500000000000007 0.5 0
76 9.5 0.5 0
77 3.500000000000012 0.5 1
78 8.5 0.5 1
79 9.5 0.5 1
80 1.500000000000004 0.5 1
81 2.500000000000008 0.5 1
82 4.500000000000012 0.5 1
83 5.50000000000001 0.5 1
84 7.500000000000005 0.5 1
85 0.5000000000000011 0.5 1
86 6.500000000000007 0.5 1
87 4.898604413415018 0.7189847025203557 0.6013955865849921
88 3.000000000000009 0.5833333333333333 0.4999999999999999
89 7.898604413412082 0.2810152974824323 0.3986044134120781
90 4.976416255236775 0.427154606657296 0.5167583310649866
91 7.976416255236875 0.5728453933430228 0.4832416689351284
$EndNodes
$Elements
267
1 2 2 2 1 2 1 45
2 2 2 2 1 1 3 45
3 2 2 2 1 4 2 45
4 2 2 2 1 3 4 45
5 2 2 3 4 3 66 4
6 2 2 3 4 36 66 3
7 2 2 3 4 4 66 27
8 2 2 3 4 8 59 7
9 2 2 3 4 7 59 44
10 2 2 3 4 35 59 8
11 2 2 3 4 27 60 28
12 2 2 3 4 36 60 27
13 2 2 3 4 27 66 36
14 2 2 3 4 28 61 29
15 2 2 3 4 28 60 37
16 2 2 3 4 37 61 28
17 2 2 3 4 29 57 30
18 2 2 3 4 38 57 29
19 2 2 3 4 29 61 38
20 2 2 3 4 30 62 31
21 2 2 3 4 30 57 39
22 2 2 3 4 39 62 30
23 2 2 3 4 31 63 32
24 2 2 3 4 62 63 31
25 2 2 3 4 32 64 33
26 2 2 3 4 63 64 32
27 2 2 3 4 33 65 34
28 2 2 3 4 64 65 33
29 2 2 3 4 34 58 35
30 2 2 3 4 34 65 58
31 2 2 3 4 35 58 44
32 2 2 3 4 44 59 35
33 2 2 3 4 37 60 36
34 2 2 3 4 38 61 37
35 2 2 3 4 39 57 38
36 2 2 3 4 40 62 39
37 2 2 3 4 41 63 40
38 2 2 3 4 40 63 62
39 2 2 3 4 42 64 41
40 2 2 3 4 41 64 63
41 2 2 3 4 43 65 42
42 2 2 3 4 42 65 64
43 2 2 3 4 44 58 43
44 2 2 3 4 58 65 43
45 4 2 1 1 36 60 50 85
46 4 2 1 1 59 79 44 76
47 4 2 1 1 76 79 26 49
48 4 2 1 1 60 27 50 85
49 4 2 1 1 27 74 55 66
50 4 2 1 1 66 55 27 85
51 4 2 1 1 57 67 12 77
52 4 2 1 1 51 71 19 81
53 4 2 1 1 27 50 70 60
54 4 2 1 1 60 50 28 80
55 4 2 1 1 50 60 28 70
56 4 2 1 1 36 50 60 80
57 4 2 1 1 61 28 71 81
58 4 2 1 1 51 11 71 81
59 4 2 1 1 61 11 81 71
60 4 2 1 1 77 67 47 20
61 4 2 1 1 47 12 67 77
62 4 2 1 1 57 20 67 77
63 4 2 1 1 18 9 85 50
64 4 2 1 1 27 60 36 85
65 4 2 1 1 18 36 50 85
66 4 2 1 1 26 17 76 49
67 4 2 1 1 44 26 76 79
68 4 2 1 1 44 76 35 59
69 4 2 1 1 9 85 50 27
70 4 2 1 1 55 9 74 27
71 4 2 1 1 30 67 12 57
72 4 2 1 1 36 66 27 85
73 4 2 1 1 9 18 85 55
74 4 2 1 1 57 39 77 21
75 4 2 1 1 9 85 27 55
76 4 2 1 1 77 12 57 21
77 4 2 1 1 36 18 50 80
78 4 2 1 1 70 50 10 28
79 4 2 1 1 19 71 28 81
80 4 2 1 1 70 9 50 27
81 4 2 1 1 37 60 28 80
82 4 2 1 1 28 61 37 81
83 4 2 1 1 19 10 71 51
84 4 2 1 1 50 28 80 19
85 4 2 1 1 29 11 61 71
86 4 2 1 1 11 51 20 81
87 4 2 1 1 67 11 47 20
88 4 2 1 1 47 12 77 21
89 4 2 1 1 38 20 57 77
90 4 2 1 1 26 78 76 48
91 4 2 1 1 35 48 76 78
92 4 2 1 1 26 44 76 78
93 4 2 1 1 78 76 35 44
94 4 2 1 1 17 35 48 76
95 4 2 1 1 26 17 48 76
96 4 2 1 1 30 12 72 57
97 4 2 1 1 39 30 72 57
98 4 2 1 1 12 72 57 39
99 4 2 1 1 19 28 37 81
100 4 2 1 1 80 28 37 19
101 4 2 1 1 28 50 10 19
102 4 2 1 1 10 71 28 19
103 4 2 1 1 39 57 12 21
104 4 2 1 1 35 78 58 68
105 4 2 1 1 35 48 78 68
106 4 2 1 1 69 75 63 14
107 4 2 1 1 35 78 44 58
108 4 2 1 1 52 86 14 83
109 4 2 1 1 63 64 41 75
110 4 2 1 1 15 42 75 53
111 4 2 1 1 15 42 84 73
112 4 2 1 1 69 63 83 14
113 4 2 1 1 83 52 69 14
114 4 2 1 1 35 17 48 68
115 4 2 1 1 84 53 42 15
116 4 2 1 1 75 86 42 64
117 4 2 1 1 86 75 42 53
118 4 2 1 1 75 73 42 15
119 4 2 1 1 86 41 64 75
120 4 2 1 1 86 84 53 42
121 4 2 1 1 54 53 84 15
122 4 2 1 1 64 73 42 75
123 4 2 1 1 75 86 14 53
124 4 2 1 1 84 42 65 73
125 4 2 1 1 84 15 73 54
126 4 2 1 1 53 52 86 14
127 4 2 1 1 65 64 73 42
128 4 2 1 1 72 62 39 82
129 4 2 1 1 63 41 83 75
130 4 2 1 1 75 83 63 14
131 4 2 1 1 41 86 83 75
132 4 2 1 1 75 86 83 14
133 4 2 1 1 84 86 53 24
134 4 2 1 1 53 54 84 24
135 4 2 1 1 63 32 75 69
136 4 2 1 1 76 46 79 49
137 4 2 1 1 59 46 79 76
138 4 2 1 1 52 86 83 23
139 4 2 1 1 52 53 86 23
140 4 2 1 1 64 65 73 33
141 4 2 1 1 72 12 56 21
142 4 2 1 1 21 72 39 82
143 4 2 1 1 30 39 72 62
144 4 2 1 1 64 73 75 33
145 4 2 1 1 66 55 45 74
146 4 2 1 1 55 66 45 85
147 4 2 1 1 64 63 32 75
148 4 2 1 1 12 72 39 21
149 4 2 1 1 78 48 25 91
150 4 2 1 1 31 69 63 90
151 4 2 1 1 84 78 25 91
152 4 2 1 1 58 68 78 91
153 4 2 1 1 68 48 78 91
154 4 2 1 1 78 84 43 91
155 4 2 1 1 69 31 72 90
156 4 2 1 1 83 69 52 90
157 4 2 1 1 63 69 83 90
158 4 2 1 1 72 13 69 90
159 4 2 1 1 78 43 58 91
160 4 2 1 1 69 13 52 90
161 4 2 1 1 65 43 84 91
162 4 2 1 1 58 34 68 91
163 4 2 1 1 56 13 72 90
164 4 2 1 1 22 83 52 90
165 4 2 1 1 65 58 43 91
166 4 2 1 1 84 73 65 91
167 4 2 1 1 84 54 73 91
168 4 2 1 1 65 34 58 91
169 4 2 1 1 73 68 34 91
170 4 2 1 1 83 82 40 90
171 4 2 1 1 56 52 13 90
172 4 2 1 1 22 82 83 90
173 4 2 1 1 22 52 56 90
174 4 2 1 1 10 9 50 70
175 4 2 1 1 18 50 80 19
176 4 2 1 1 70 28 27 60
177 4 2 1 1 60 37 36 80
178 4 2 1 1 20 51 19 81
179 4 2 1 1 10 11 71 51
180 4 2 1 1 47 12 11 67
181 4 2 1 1 71 29 28 61
182 4 2 1 1 67 30 29 57
183 4 2 1 1 38 37 61 81
184 4 2 1 1 21 77 47 20
185 4 2 1 1 55 9 2 74
186 4 2 1 1 27 4 74 66
187 4 2 1 1 39 38 57 77
188 4 2 1 1 3 66 36 85
189 4 2 1 1 85 1 55 18
190 4 2 1 1 7 79 44 59
191 4 2 1 1 7 5 79 46
192 4 2 1 1 46 7 8 59
193 4 2 1 1 46 8 6 76
194 4 2 1 1 6 5 46 49
195 4 2 1 1 2 4 45 74
196 4 2 1 1 2 1 55 45
197 4 2 1 1 45 4 3 66
198 4 2 1 1 45 3 1 85
199 4 2 1 1 79 5 26 49
200 4 2 1 1 76 6 49 17
201 4 2 1 1 35 8 59 76
202 4 2 1 1 29 67 57 88
203 4 2 1 1 61 38 81 88
204 4 2 1 1 46 5 79 49
205 4 2 1 1 76 6 46 49
206 4 2 1 1 79 7 46 59
207 4 2 1 1 8 46 59 76
208 4 2 1 1 45 55 2 74
209 4 2 1 1 66 3 45 85
210 4 2 1 1 4 45 74 66
211 4 2 1 1 1 55 45 85
212 4 2 1 1 43 44 78 58
213 4 2 1 1 34 35 58 68
214 4 2 1 1 78 26 25 48
215 4 2 1 1 22 83 23 52
216 4 2 1 1 41 83 40 63
217 4 2 1 1 69 52 13 14
218 4 2 1 1 63 31 32 69
219 4 2 1 1 24 23 86 53
220 4 2 1 1 54 15 73 16
221 4 2 1 1 84 42 43 65
222 4 2 1 1 17 48 68 16
223 4 2 1 1 84 25 24 54
224 4 2 1 1 32 33 64 75
225 4 2 1 1 14 15 75 53
226 4 2 1 1 41 42 86 64
227 4 2 1 1 72 30 62 31
228 4 2 1 1 62 40 39 82
229 4 2 1 1 13 12 56 72
230 4 2 1 1 48 16 54 89
231 4 2 1 1 54 25 48 89
232 4 2 1 1 61 29 38 88
233 4 2 1 1 57 38 29 88
234 4 2 1 1 40 62 63 87
235 4 2 1 1 63 62 31 87
236 4 2 1 1 25 48 89 91
237 4 2 1 1 22 56 21 90
238 4 2 1 1 22 21 82 90
239 4 2 1 1 63 87 31 90
240 4 2 1 1 91 54 25 84
241 4 2 1 1 91 25 54 89
242 4 2 1 1 90 40 63 87
243 4 2 1 1 90 63 40 83
244 4 2 1 1 89 54 73 16
245 4 2 1 1 89 73 54 91
246 4 2 1 1 68 89 73 16
247 4 2 1 1 68 73 89 91
248 4 2 1 1 48 89 68 16
249 4 2 1 1 48 68 89 91
250 4 2 1 1 40 87 82 62
251 4 2 1 1 40 82 87 90
252 4 2 1 1 82 87 72 62
253 4 2 1 1 82 72 87 90
254 4 2 1 1 72 87 31 62
255 4 2 1 1 72 31 87 90
256 4 2 1 1 73 65 34 33
257 4 2 1 1 73 34 65 91
258 4 2 1 1 90 21 72 56
259 4 2 1 1 90 72 21 82
260 4 2 1 1 38 88 20 81
261 4 2 1 1 38 20 88 57
262 4 2 1 1 67 88 20 57
263 4 2 1 1 29 88 11 67
264 4 2 1 1 29 11 88 61
265 4 2 1 1 81 88 11 61
266 4 2 1 1 88 20 11 67
267 4 2 1 1 88 11 20 81
$EndElements

Solution

The gmesh_beam.msh file is ready to be used with MoFEM. The next step is to convert the gmesh_beam.msh file to out.h5m file using configuration file gmesh_beam.cfg with the following command:

../../tools/add_meshsets -my_file gmesh_beam.msh -meshsets_config gmesh_beam.cfg

The associated gmesh_beam.cfg file is given as:

[block_1]
id=1001
add=BLOCKSET
name=MAT_ELASTIC
young=10
poisson=0.25
thermalexpansion=0
[block_2]
id=1002
add=NODESET
disp_flag1=1 # Setting constrains in x- dir ection
disp_flag2=1 # Setting constrains in y- direction
disp_flag3=1 # Setting constrains in z- direction
disp_flag4=0
disp_flag5=0
disp_flag6=0
disp_ux=0
disp_uy=0
disp_uz=0
disp_rx=0
disp_ry=0
disp_rz=0
[block_3]
id=1003
add=SIDESET
pressure_flag2=0
pressure_magnitude=1

The use of gmesh_beam.cfg file with the above command will convert the physical groups in gmesh_beam.msh in to associated BLOCKSET, NODESET and SIDESET, understandable to MoFEM. The first block, i.e. block_1 will convert to BLOCKSET with id=1001. Which is used as MAT_ELASTIC with assigned material properties. Similarly, block_2 and block_3 are converted to NODESET (id=1002) and SIDESET (id=1003) and are used for displacement and pressure boundary conditions. Subsequently, the following command is used to run the elastic analysis on the beam problem:

mpirun -np 1 ./elasticity -my_file out.h5m -my_order 1

This will create out.h5m file, which is then converted to out.vtk file using

mbconvert out.h5m out.vtk

Post-processing

The out.vtk file can be viewed in Paraview. For the beam problem, the output is shown in the following figure.

Beam post-process result
ReactionDiffusionEquation::D
const double D
diffusivity
Definition: reaction_diffusion.cpp:20