1 <!doctype HTML public "-//W3C//DTD HTML 4.0 Frameset//EN">
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">
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; }
18 </style><script type="text/javascript" language="JavaScript">
20 if ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) == 4))
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; }";
31 document.write(strNSS);
35 <script type="text/javascript" language="JavaScript" title="WebHelpInlineScript">
38 if (innerWidth != origWidth || innerHeight != origHeight)
41 if ((parseInt(navigator.appVersion) == 4) && (navigator.appName == "Netscape")) {
42 origWidth = innerWidth;
43 origHeight = innerHeight;
49 <style type="text/css">
51 div.WebHelpPopupMenu { position:absolute; left:0px; top:0px; z-index:4; visibility:hidden; }
52 p.WebHelpNavBar { text-align:right; }
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">
63 if (window.setRelStartPage)
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");
72 if (window.setRelStartPage)
74 setRelStartPage("index.htm");
84 document.location.reload();
88 <body><script type="text/javascript" language="javascript1.2">
90 if (window.writeIntopicBar)
94 <h1>Creating Meshes</h1>
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
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>
104 <h3><a name=bookmark>Construction of a Mesh</a></h3>
106 <p class="whs2"><span style="font-family: 'Lucida Console', monospace;">import
109 <p class="whs2">import smesh</p>
111 <p class="whs2"> </p>
113 <p class="whs3"># create a box</p>
115 <p class="whs2">box = geompy.MakeBox(0.,
116 0., 0., 100., 200., 300.)</p>
118 <p class="whs2">idbox = geompy.addToStudy(box,
121 <p class="whs2"> </p>
123 <p class="whs3"># create a mesh</p>
125 <p class="whs2">tetra = smesh.Mesh(box,
126 "MeshBox")</p>
128 <p class="whs2"> </p>
130 <p class="whs2">algo1D = tetra.Segment()</p>
132 <p class="whs2">algo1D.NumberOfSegments(7)</p>
134 <p class="whs2"> </p>
136 <p class="whs2">algo2D = tetra.Triangle()</p>
138 <p class="whs2">algo2D.MaxElementArea(800.)</p>
140 <p class="whs2"> </p>
142 <p class="whs2">algo3D = tetra.Tetrahedron(smesh.NETGEN)</p>
144 <p class="whs2">algo3D.MaxElementVolume(900.)</p>
146 <p class="whs2"> </p>
148 <p class="whs3"># compute the mesh</p>
150 <p class="whs2">ret = tetra.Compute()</p>
152 <p class="whs2">if ret == 0:</p>
154 <p class="whs2"> print
155 "problem when computing the mesh"</p>
157 <p class="whs2">else:</p>
159 <p class="whs2"> print
160 "mesh computed"</p>
162 <p class="whs2"> pass
165 <p class="whs2"> </p>
167 <p class="whs2"> </p>
169 <h3><a name=bookmark1>Construction of a Submesh</a></h3>
171 <p class="whs4"><span style="font-family: 'Lucida Console', monospace;">from
172 geompy import *</span></p>
174 <p class="whs4">import smesh</p>
176 <p class="whs4"> </p>
178 <p class="whs5"># create a box</p>
180 <p class="whs4">box = MakeBoxDXDYDZ(10., 10., 10.)</p>
182 <p class="whs4">addToStudy(box, "Box")</p>
184 <p class="whs4"> </p>
186 <p class="whs5"># select one edge of
187 the box for definition of a local hypothesis</p>
189 <p class="whs4">p5 = MakeVertex(5., 0., 0.)</p>
191 <p class="whs4">EdgeX = GetEdgeNearPoint(box, p5)</p>
193 <p class="whs4">addToStudyInFather(box, EdgeX, "Edge
194 [0,0,0 - 10,0,0]")</p>
196 <p class="whs4"> </p>
198 <p class="whs5"># create a hexahedral
201 <p class="whs4">quadra = smesh.Mesh(box, "Box : quadrangle
204 <p class="whs4"> </p>
206 <p class="whs5"># create a regular
207 1D algorithm for the faces</p>
209 <p class="whs4">algo1D = quadra.Segment()</p>
211 <p class="whs4"> </p>
213 <p class="whs5"># define "NumberOfSegments"
214 hypothesis to cut</p>
216 <p class="whs5"># all the edges in
217 a fixed number of segments</p>
219 <p class="whs4">algo1D.NumberOfSegments(4)</p>
221 <p class="whs4"> </p>
223 <p class="whs5"># create a quadrangle
224 2D algorithm for the faces</p>
226 <p class="whs4">quadra.Quadrangle()</p>
228 <p class="whs4"> </p>
230 <p class="whs5"># construct a submesh
231 on the edge with a local hypothesis</p>
233 <p class="whs4">algo_local = quadra.Segment(EdgeX)</p>
235 <p class="whs4"> </p>
237 <p class="whs5"># define "Arithmetic1D"
238 hypothesis to cut the edge<span style="margin-top: 0px;
240 font-family: 'Times New Roman', serif;">
241 in several segments with increasing arithmetic length</span></p>
243 <p class="whs4">algo_local.Arithmetic1D(1, 4)</p>
245 <p class="whs4"> </p>
247 <p class="whs5"># define "Propagation"
248 hypothesis that propagates all other hypotheses</p>
250 <p class="whs5"># on all edges of the
251 opposite side in case of quadrangular faces</p>
253 <p class="whs4">algo_local.Propagation()</p>
255 <p class="whs4"> </p>
257 <p class="whs5"># compute the mesh</p>
259 <p class="whs4">quadra.Compute() </p>
261 <p class="whs4"> </p>
263 <h3><a name=bookmark2>Editing of a mesh</a></h3>
265 <p class="whs4"><span style="font-family: 'Lucida Console', monospace;">import
268 <p class="whs4">import smesh</p>
270 <p class="whs4"> </p>
272 <p class="whs4">def PrintMeshInfo(theMesh):</p>
274 <p class="whs4"> aMesh
275 = theMesh.GetMesh()</p>
277 <p class="whs4"> print
278 "Information about mesh:"</p>
280 <p class="whs4"> print
281 "Number of nodes :
282 ", aMesh.NbNodes()</p>
284 <p class="whs4"> print
285 "Number of edges :
286 ", aMesh.NbEdges()</p>
288 <p class="whs4"> print
289 "Number of faces :
290 ", aMesh.NbFaces()</p>
292 <p class="whs4"> print
293 "Number of volumes :
294 ", aMesh.NbVolumes()</p>
296 <p class="whs4"> pass</p>
298 <p class="whs4"> </p>
300 <p class="whs5"># create a box</p>
302 <p class="whs4">box = geompy.MakeBox(0., 0., 0., 20.,
305 <p class="whs4">geompy.addToStudy(box, "box")</p>
307 <p class="whs4"> </p>
309 <p class="whs5"># select one edge of
310 the box for definition of a local hypothesis</p>
312 <p class="whs4">subShapeList = geompy.SubShapeAll(box,
313 geompy.ShapeType["EDGE"])</p>
315 <p class="whs4">edge = subShapeList[0]</p>
317 <p class="whs4">name = geompy.SubShapeName(edge, box)</p>
319 <p class="whs4">geompy.addToStudyInFather(box, edge, name)</p>
321 <p class="whs4"> </p>
323 <p class="whs5"># create a mesh</p>
325 <p class="whs4">tria = smesh.Mesh(box, "Mesh 2D")</p>
327 <p class="whs4">algo1D = tria.Segment()</p>
329 <p class="whs4">hyp1 = algo1D.NumberOfSegments(3)</p>
331 <p class="whs4">algo2D = tria.Triangle()</p>
333 <p class="whs4">hyp2 = algo2D.MaxElementArea(10.)</p>
335 <p class="whs4"> </p>
337 <p class="whs5"># create a sub-mesh</p>
339 <p class="whs4">algo_local = tria.Segment(edge)</p>
341 <p class="whs4">hyp3 = algo_local.Arithmetic1D(1, 6)</p>
343 <p class="whs4">hyp4 = algo_local.Propagation()</p>
345 <p class="whs4"> </p>
347 <p class="whs5"># compute the mesh</p>
349 <p class="whs4">tria.Compute()</p>
351 <p class="whs4">PrintMeshInfo(tria)</p>
353 <p class="whs4"> </p>
355 <p class="whs5"># remove a local hypothesis</p>
357 <p class="whs4">mesh = tria.GetMesh()</p>
359 <p class="whs4">mesh.RemoveHypothesis(edge, hyp4)</p>
361 <p class="whs4"> </p>
363 <p class="whs5"># compute the mesh</p>
365 <p class="whs4">tria.Compute()</p>
367 <p class="whs4">PrintMeshInfo(tria)</p>
369 <p class="whs4"> </p>
371 <p class="whs5"># change the value
372 of the 2D hypothesis</p>
374 <p class="whs4">hyp2.SetMaxElementArea(2.)</p>
376 <p class="whs4"> </p>
378 <p class="whs5"># compute the mesh</p>
380 <p class="whs4">tria.Compute()</p>
382 <p class="whs4">PrintMeshInfo(tria) </p>
384 <p class="whs6"> </p>
386 <h3><a name=bookmark3>Export of a Mesh</a></h3>
388 <p class="whs7">import geompy</p>
390 <p class="whs7">import smesh</p>
392 <p class="whs6"> </p>
394 <p class="whs6"># create a box</p>
396 <p class="whs7">box = geompy.MakeBox(0.,
397 0., 0., 100., 200., 300.)</p>
399 <p class="whs7">idbox = geompy.addToStudy(box,
402 <p class="whs6"> </p>
404 <p class="whs6"># create a mesh</p>
406 <p class="whs7">tetra = smesh.Mesh(box,
407 "MeshBox")</p>
409 <p class="whs6"> </p>
411 <p class="whs7">algo1D = tetra.Segment()</p>
413 <p class="whs7">algo1D.NumberOfSegments(7)</p>
415 <p class="whs7"> </p>
417 <p class="whs7">algo2D = tetra.Triangle()</p>
419 <p class="whs7">algo2D.MaxElementArea(800.)</p>
421 <p class="whs7"> </p>
423 <p class="whs7">algo3D = tetra.Tetrahedron(smesh.NETGEN)</p>
425 <p class="whs7">algo3D.MaxElementVolume(900.)</p>
427 <p class="whs6"> </p>
429 <p class="whs6"># compute the mesh</p>
431 <p class="whs7">tetra.Compute()</p>
433 <p class="whs6"> </p>
435 <p class="whs6"># export the mesh in a
438 <p class="whs7">tetra.ExportMED("/tmp/meshMED.med",
441 <script type="text/javascript" language="javascript1.2">
443 if (window.writeIntopicBar)