Salome HOME
Porting GUI documentation on Doxygen tool.
[modules/smesh.git] / doc / salome / gui / SMESH / constructing_meshes.htm
1 <!doctype HTML public "-//W3C//DTD HTML 4.0 Frameset//EN">
2
3 <html>
4
5 <head>
6 <title>Constructing Meshes</title>
7 <meta http-equiv="content-type" content="text/html; charset=windows-1252">
8 <meta name="generator" content="RoboHelp by eHelp Corporation www.ehelp.com"><style type="text/css">
9 <!--
10 p.whs1 { margin-top:0pt; margin-bottom:0pt; }
11 p.whs2 { margin-top:0pt; margin-bottom:0pt; font-family:'Lucida Console' , monospace; }
12 p.whs3 { margin-top:0pt; margin-bottom:0pt; font-family:'Times New Roman' , serif; }
13 p.whs4 { font-family:'Lucida Console' , monospace; margin-top:0px; margin-bottom:0px; }
14 p.whs5 { margin-top:0px; margin-bottom:0px; font-family:'Times New Roman' , serif; }
15 p.whs6 { margin-top:0px; margin-bottom:0px; }
16 p.whs7 { margin-top:0px; margin-bottom:0px; font-family:'Lucida Console' , monospace; }
17 -->
18 </style><script type="text/javascript" language="JavaScript">
19 <!--
20 if ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) == 4))
21 {
22   var strNSS = "<style type='text/css'>";
23   strNSS += "p.whs1 {margin-top:1pt;margin-bottom:1pt; }";
24   strNSS += "p.whs2 {margin-top:1pt;margin-bottom:1pt; }";
25   strNSS += "p.whs3 {margin-top:1pt;margin-bottom:1pt; }";
26   strNSS += "p.whs4 {margin-top:1pt;margin-bottom:1pt; }";
27   strNSS += "p.whs5 {margin-top:1pt;margin-bottom:1pt; }";
28   strNSS += "p.whs6 {margin-top:1pt;margin-bottom:1pt; }";
29   strNSS += "p.whs7 {margin-top:1pt;margin-bottom:1pt; }";
30   strNSS +="</style>";
31   document.write(strNSS);
32 }
33 //-->
34 </script>
35 <script type="text/javascript" language="JavaScript" title="WebHelpInlineScript">
36 <!--
37 function reDo() {
38   if (innerWidth != origWidth || innerHeight != origHeight)
39      location.reload();
40 }
41 if ((parseInt(navigator.appVersion) == 4) && (navigator.appName == "Netscape")) {
42         origWidth = innerWidth;
43         origHeight = innerHeight;
44         onresize = reDo;
45 }
46 onerror = null; 
47 //-->
48 </script>
49 <style type="text/css">
50 <!--
51 div.WebHelpPopupMenu { position:absolute; left:0px; top:0px; z-index:4; visibility:hidden; }
52 p.WebHelpNavBar { text-align:right; }
53 -->
54 </style><script type="text/javascript" language="javascript1.2" src="whmsg.js"></script>
55 <script type="text/javascript" language="javascript" src="whver.js"></script>
56 <script type="text/javascript" language="javascript1.2" src="whproxy.js"></script>
57 <script type="text/javascript" language="javascript1.2" src="whutils.js"></script>
58 <script type="text/javascript" language="javascript1.2" src="whtopic.js"></script>
59 <script type="text/javascript" language="javascript1.2">
60 <!--
61 if (window.gbWhTopic)
62 {
63         if (window.setRelStartPage)
64         {
65         addTocInfo("MESH module\nTUI Scripts\nCreating Meshes");
66 addButton("show",BTN_IMG,"Show","","","","",0,0,"whd_show0.gif","whd_show2.gif","whd_show1.gif");
67 addButton("hide",BTN_IMG,"Hide","","","","",0,0,"whd_hide0.gif","whd_hide2.gif","whd_hide1.gif");
68
69         }
70
71
72         if (window.setRelStartPage)
73         {
74         setRelStartPage("index.htm");
75
76                 autoSync(1);
77                 sendSyncInfo();
78                 sendAveInfoOut();
79         }
80
81 }
82 else
83         if (window.gbIE4)
84                 document.location.reload();
85 //-->
86 </script>
87 </head>
88 <body><script type="text/javascript" language="javascript1.2">
89 <!--
90 if (window.writeIntopicBar)
91         writeIntopicBar(4);
92 //-->
93 </script>
94 <h1>Creating Meshes</h1>
95
96 <p class="whs1">First of all see <a href="smesh.py_introduction.htm">Example 
97  of 3d mesh generation</a>, which is an example of good python script style 
98  for Mesh module. </p>
99
100 <p class="whs1">Other examples of python 
101  scripts will be also updated soon to use smesh package instead of direct 
102  usage of idl interface. </p>
103
104 <h3><a name=bookmark>Construction of a Mesh</a></h3>
105
106 <p class="whs2"><span style="font-family: 'Lucida Console', monospace;">import 
107  geompy</span></p>
108
109 <p class="whs2">import smesh</p>
110
111 <p class="whs2">&nbsp;</p>
112
113 <p class="whs3"># create a box</p>
114
115 <p class="whs2">box = geompy.MakeBox(0., 
116  0., 0., 100., 200., 300.)</p>
117
118 <p class="whs2">idbox = geompy.addToStudy(box, 
119  &quot;box&quot;)</p>
120
121 <p class="whs2">&nbsp;</p>
122
123 <p class="whs3"># create a mesh</p>
124
125 <p class="whs2">tetra = smesh.Mesh(box, 
126  &quot;MeshBox&quot;)</p>
127
128 <p class="whs2">&nbsp;</p>
129
130 <p class="whs2">algo1D = tetra.Segment()</p>
131
132 <p class="whs2">algo1D.NumberOfSegments(7)</p>
133
134 <p class="whs2">&nbsp;</p>
135
136 <p class="whs2">algo2D = tetra.Triangle()</p>
137
138 <p class="whs2">algo2D.MaxElementArea(800.)</p>
139
140 <p class="whs2">&nbsp;</p>
141
142 <p class="whs2">algo3D = tetra.Tetrahedron(smesh.NETGEN)</p>
143
144 <p class="whs2">algo3D.MaxElementVolume(900.)</p>
145
146 <p class="whs2">&nbsp;</p>
147
148 <p class="whs3"># compute the mesh</p>
149
150 <p class="whs2">ret = tetra.Compute()</p>
151
152 <p class="whs2">if ret == 0:</p>
153
154 <p class="whs2">&nbsp;&nbsp;&nbsp;&nbsp;print 
155  &quot;problem when computing the mesh&quot;</p>
156
157 <p class="whs2">else:</p>
158
159 <p class="whs2">&nbsp;&nbsp;&nbsp;&nbsp;print 
160  &quot;mesh computed&quot;</p>
161
162 <p class="whs2">&nbsp;&nbsp;&nbsp;&nbsp;pass 
163  </p>
164
165 <p class="whs2">&nbsp;</p>
166
167 <p class="whs2">&nbsp;</p>
168
169 <h3><a name=bookmark1>Construction of a Submesh</a></h3>
170
171 <p class="whs4"><span style="font-family: 'Lucida Console', monospace;">from 
172  geompy import *</span></p>
173
174 <p class="whs4">import smesh</p>
175
176 <p class="whs4">&nbsp;</p>
177
178 <p class="whs5"># create a box</p>
179
180 <p class="whs4">box = MakeBoxDXDYDZ(10., 10., 10.)</p>
181
182 <p class="whs4">addToStudy(box, &quot;Box&quot;)</p>
183
184 <p class="whs4">&nbsp;</p>
185
186 <p class="whs5"># select one edge of 
187  the box for definition of a local hypothesis</p>
188
189 <p class="whs4">p5 = MakeVertex(5., 0., 0.)</p>
190
191 <p class="whs4">EdgeX = GetEdgeNearPoint(box, p5)</p>
192
193 <p class="whs4">addToStudyInFather(box, EdgeX, &quot;Edge 
194  [0,0,0 - 10,0,0]&quot;)</p>
195
196 <p class="whs4">&nbsp;</p>
197
198 <p class="whs5"># create a hexahedral 
199  mesh on the box</p>
200
201 <p class="whs4">quadra = smesh.Mesh(box, &quot;Box : quadrangle 
202  2D mesh&quot;)</p>
203
204 <p class="whs4">&nbsp;</p>
205
206 <p class="whs5"># create a regular 
207  1D algorithm for the faces</p>
208
209 <p class="whs4">algo1D = quadra.Segment()</p>
210
211 <p class="whs4">&nbsp;</p>
212
213 <p class="whs5"># define &quot;NumberOfSegments&quot; 
214  hypothesis to cut</p>
215
216 <p class="whs5"># all the edges in 
217  a fixed number of segments</p>
218
219 <p class="whs4">algo1D.NumberOfSegments(4)</p>
220
221 <p class="whs4">&nbsp;</p>
222
223 <p class="whs5"># create a quadrangle 
224  2D algorithm for the faces</p>
225
226 <p class="whs4">quadra.Quadrangle()</p>
227
228 <p class="whs4">&nbsp;</p>
229
230 <p class="whs5"># construct a submesh 
231  on the edge with a local hypothesis</p>
232
233 <p class="whs4">algo_local = quadra.Segment(EdgeX)</p>
234
235 <p class="whs4">&nbsp;</p>
236
237 <p class="whs5"># define &quot;Arithmetic1D&quot; 
238  hypothesis to cut the edge<span style="margin-top: 0px;
239                                                                                 margin-bottom: 0px;
240                                                                                 font-family: 'Times New Roman', serif;"> 
241  in several segments with increasing arithmetic length</span></p>
242
243 <p class="whs4">algo_local.Arithmetic1D(1, 4)</p>
244
245 <p class="whs4">&nbsp;</p>
246
247 <p class="whs5"># define &quot;Propagation&quot; 
248  hypothesis that propagates all other hypotheses</p>
249
250 <p class="whs5"># on all edges of the 
251  opposite side in case of quadrangular faces</p>
252
253 <p class="whs4">algo_local.Propagation()</p>
254
255 <p class="whs4">&nbsp;</p>
256
257 <p class="whs5"># compute the mesh</p>
258
259 <p class="whs4">quadra.Compute() </p>
260
261 <p class="whs4">&nbsp;</p>
262
263 <h3><a name=bookmark2>Editing of a mesh</a></h3>
264
265 <p class="whs4"><span style="font-family: 'Lucida Console', monospace;">import 
266  geompy</span></p>
267
268 <p class="whs4">import smesh</p>
269
270 <p class="whs4">&nbsp;</p>
271
272 <p class="whs4">def PrintMeshInfo(theMesh):</p>
273
274 <p class="whs4">&nbsp;&nbsp;&nbsp;&nbsp;aMesh 
275  = theMesh.GetMesh()</p>
276
277 <p class="whs4">&nbsp;&nbsp;&nbsp;&nbsp;print 
278  &quot;Information about mesh:&quot;</p>
279
280 <p class="whs4">&nbsp;&nbsp;&nbsp;&nbsp;print 
281  &quot;Number of nodes &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: 
282  &quot;, aMesh.NbNodes()</p>
283
284 <p class="whs4">&nbsp;&nbsp;&nbsp;&nbsp;print 
285  &quot;Number of edges &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: 
286  &quot;, aMesh.NbEdges()</p>
287
288 <p class="whs4">&nbsp;&nbsp;&nbsp;&nbsp;print 
289  &quot;Number of faces &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: 
290  &quot;, aMesh.NbFaces()</p>
291
292 <p class="whs4">&nbsp;&nbsp;&nbsp;&nbsp;print 
293  &quot;Number of volumes &nbsp;&nbsp;&nbsp;&nbsp;: 
294  &quot;, aMesh.NbVolumes()</p>
295
296 <p class="whs4">&nbsp;&nbsp;&nbsp;&nbsp;pass</p>
297
298 <p class="whs4">&nbsp;</p>
299
300 <p class="whs5"># create a box</p>
301
302 <p class="whs4">box = geompy.MakeBox(0., 0., 0., 20., 
303  20., 20.)</p>
304
305 <p class="whs4">geompy.addToStudy(box, &quot;box&quot;)</p>
306
307 <p class="whs4">&nbsp;</p>
308
309 <p class="whs5"># select one edge of 
310  the box for definition of a local hypothesis</p>
311
312 <p class="whs4">subShapeList = geompy.SubShapeAll(box, 
313  geompy.ShapeType[&quot;EDGE&quot;])</p>
314
315 <p class="whs4">edge = subShapeList[0]</p>
316
317 <p class="whs4">name = geompy.SubShapeName(edge, box)</p>
318
319 <p class="whs4">geompy.addToStudyInFather(box, edge, name)</p>
320
321 <p class="whs4">&nbsp;</p>
322
323 <p class="whs5"># create a mesh</p>
324
325 <p class="whs4">tria = smesh.Mesh(box, &quot;Mesh 2D&quot;)</p>
326
327 <p class="whs4">algo1D = tria.Segment()</p>
328
329 <p class="whs4">hyp1 = algo1D.NumberOfSegments(3)</p>
330
331 <p class="whs4">algo2D = tria.Triangle()</p>
332
333 <p class="whs4">hyp2 = algo2D.MaxElementArea(10.)</p>
334
335 <p class="whs4">&nbsp;</p>
336
337 <p class="whs5"># create a sub-mesh</p>
338
339 <p class="whs4">algo_local = tria.Segment(edge)</p>
340
341 <p class="whs4">hyp3 = algo_local.Arithmetic1D(1, 6)</p>
342
343 <p class="whs4">hyp4 = algo_local.Propagation()</p>
344
345 <p class="whs4">&nbsp;</p>
346
347 <p class="whs5"># compute the mesh</p>
348
349 <p class="whs4">tria.Compute()</p>
350
351 <p class="whs4">PrintMeshInfo(tria)</p>
352
353 <p class="whs4">&nbsp;</p>
354
355 <p class="whs5"># remove a local hypothesis</p>
356
357 <p class="whs4">mesh = tria.GetMesh()</p>
358
359 <p class="whs4">mesh.RemoveHypothesis(edge, hyp4)</p>
360
361 <p class="whs4">&nbsp;</p>
362
363 <p class="whs5"># compute the mesh</p>
364
365 <p class="whs4">tria.Compute()</p>
366
367 <p class="whs4">PrintMeshInfo(tria)</p>
368
369 <p class="whs4">&nbsp;</p>
370
371 <p class="whs5"># change the value 
372  of the 2D hypothesis</p>
373
374 <p class="whs4">hyp2.SetMaxElementArea(2.)</p>
375
376 <p class="whs4">&nbsp;</p>
377
378 <p class="whs5"># compute the mesh</p>
379
380 <p class="whs4">tria.Compute()</p>
381
382 <p class="whs4">PrintMeshInfo(tria) </p>
383
384 <p class="whs6">&nbsp;</p>
385
386 <h3><a name=bookmark3>Export of a Mesh</a></h3>
387
388 <p class="whs7">import geompy</p>
389
390 <p class="whs7">import smesh</p>
391
392 <p class="whs6">&nbsp;</p>
393
394 <p class="whs6"># create a box</p>
395
396 <p class="whs7">box = geompy.MakeBox(0., 
397  0., 0., 100., 200., 300.)</p>
398
399 <p class="whs7">idbox = geompy.addToStudy(box, 
400  &quot;box&quot;)</p>
401
402 <p class="whs6">&nbsp;</p>
403
404 <p class="whs6"># create a mesh</p>
405
406 <p class="whs7">tetra = smesh.Mesh(box, 
407  &quot;MeshBox&quot;)</p>
408
409 <p class="whs6">&nbsp;</p>
410
411 <p class="whs7">algo1D = tetra.Segment()</p>
412
413 <p class="whs7">algo1D.NumberOfSegments(7)</p>
414
415 <p class="whs7">&nbsp;</p>
416
417 <p class="whs7">algo2D = tetra.Triangle()</p>
418
419 <p class="whs7">algo2D.MaxElementArea(800.)</p>
420
421 <p class="whs7">&nbsp;</p>
422
423 <p class="whs7">algo3D = tetra.Tetrahedron(smesh.NETGEN)</p>
424
425 <p class="whs7">algo3D.MaxElementVolume(900.)</p>
426
427 <p class="whs6">&nbsp;</p>
428
429 <p class="whs6"># compute the mesh</p>
430
431 <p class="whs7">tetra.Compute()</p>
432
433 <p class="whs6">&nbsp;</p>
434
435 <p class="whs6"># export the mesh in a 
436  MED file</p>
437
438 <p class="whs7">tetra.ExportMED(&quot;/tmp/meshMED.med&quot;, 
439  0) </p>
440
441 <script type="text/javascript" language="javascript1.2">
442 <!--
443 if (window.writeIntopicBar)
444         writeIntopicBar(0);
445 //-->
446 </script>
447 </body>
448 </html>