Salome HOME
Update SMESH documentation
[modules/smesh.git] / doc / salome / gui / SMESH / input / tui_defining_hypotheses.doc
1 /*!
2
3 \page tui_defining_hypotheses_page Defining Hypotheses and Algorithms
4
5 <h2>Defining 1D Hypotheses</h2>
6
7 <br>
8 \anchor tui_1d_arithmetic
9 <h3>1D Arithmetic</h3>
10
11 \code
12 import geompy
13 import smesh
14
15 # create a box
16 box = geompy.MakeBoxDXDYDZ(10., 10., 10.)
17 geompy.addToStudy(box, "Box")
18
19 # create a hexahedral mesh on the box
20 hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
21
22 # create a Regular 1D algorithm for edges
23 algo1D = hexa.Segment()
24
25 # define "Arithmetic1D" hypothesis to cut all edges in several segments with increasing arithmetic length 
26 algo1D.Arithmetic1D(1, 4)
27
28 # create a quadrangle 2D algorithm for faces
29 hexa.Quadrangle()
30
31 # create a hexahedron 3D algorithm for solids
32 hexa.Hexahedron()
33
34 # compute the mesh
35 hexa.Compute()
36 \endcode
37
38 <br>
39 \anchor tui_deflection_1d
40 <h3>Deflection 1D and Number of Segments</h3>
41
42 \code
43 import geompy
44 import smesh
45
46 # create a face from arc and straight segment
47 px = geompy.MakeVertex(100., 0.  , 0.  )
48 py = geompy.MakeVertex(0.  , 100., 0.  )
49 pz = geompy.MakeVertex(0.  , 0.  , 100.)
50
51 exy = geompy.MakeEdge(px, py)
52 arc = geompy.MakeArc(py, pz, px)
53
54 wire = geompy.MakeWire([exy, arc])
55
56 isPlanarFace = 1
57 face1 = geompy.MakeFace(wire, isPlanarFace)
58 geompy.addToStudy(face1,"Face1")
59
60 # get edges from the face
61 e_straight,e_arc = geompy.SubShapeAll(face1, geompy.ShapeType["EDGE"])
62 geompy.addToStudyInFather(face1, e_arc, "Arc Edge")
63
64 # create hexahedral mesh
65 hexa = smesh.Mesh(face1, "Face : triangle mesh")
66
67 # define "NumberOfSegments" hypothesis to cut a straight edge in a fixed number of segments
68 algo1D = hexa.Segment()
69 algo1D.NumberOfSegments(6)
70
71 # define "MaxElementArea" hypothesis
72 algo2D = hexa.Triangle()
73 algo2D.MaxElementArea(70.0)
74
75 # define a local "Deflection1D" hypothesis on the arc
76 algo_local = hexa.Segment(e_arc)
77 algo_local.Deflection1D(1.0)
78
79 # compute the mesh
80 hexa.Compute()
81 \endcode
82
83 <br>
84 \anchor tui_start_and_end_length
85 <h3>Start and End Length</h3>
86
87 \code
88 from geompy import *
89 import smesh
90
91 # create a box
92 box = MakeBoxDXDYDZ(10., 10., 10.)
93 addToStudy(box, "Box")
94
95 # get one edge of the box to put local hypothesis on
96 p5 = MakeVertex(5., 0., 0.)
97 EdgeX = GetEdgeNearPoint(box, p5)
98 addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
99
100 # create a hexahedral mesh on the box
101 hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
102
103 # set algorithms
104 algo1D = hexa.Segment()
105 hexa.Quadrangle()
106 hexa.Hexahedron()
107
108 # define "NumberOfSegments" hypothesis to cut an edge in a fixed number of segments
109 algo1D.NumberOfSegments(4)
110
111 # create a local hypothesis
112 algo_local = hexa.Segment(EdgeX)
113
114 # define "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
115 algo_local.StartEndLength(1, 6)
116
117 # define "Propagation" hypothesis that propagates all other hypothesis
118 # on all edges on the opposite side in case of quadrangular faces
119 algo_local.Propagation()
120
121 # compute the mesh
122 hexa.Compute()
123 \endcode
124
125 <br>
126 \anchor tui_average_length
127 <h3>Average Length</h3>
128
129 \code
130 from geompy import *
131 import smesh
132
133 # create a box
134 box = MakeBoxDXDYDZ(10., 10., 10.)
135 addToStudy(box, "Box")
136
137 # get one edge of the box to put local hypothesis on
138 p5 = MakeVertex(5., 0., 0.)
139 EdgeX = GetEdgeNearPoint(box, p5)
140 addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
141
142 # create a hexahedral mesh on the box
143 hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
144
145 # set algorithms
146 algo1D = hexa.Segment()
147 hexa.Quadrangle()
148 hexa.Hexahedron()
149
150 # define "NumberOfSegments" hypothesis to cut all edges in a fixed number of segments
151 algo1D.NumberOfSegments(4)
152
153 # create a sub-mesh
154 algo_local = hexa.Segment(EdgeX)
155
156 # define "LocalLength" hypothesis to cut an edge in several segments with the same length
157 algo_local.LocalLength(2.)
158
159 # define "Propagation" hypothesis that propagates all other hypothesis
160 # on all edges on the opposite side in case of quadrangular faces
161 algo_local.Propagation()
162
163 # compute the mesh
164 hexa.Compute()
165 \endcode
166
167 <br><h2>Defining 2D and 3D hypotheses</h2>
168
169 <br>
170 \anchor tui_max_element_area
171 <h3>Maximum Element Area</h3>
172
173 \code
174 import geompy
175 import smesh
176 import salome 
177
178 # create a face
179 px   = geompy.MakeVertex(100., 0.  , 0.  )
180 py   = geompy.MakeVertex(0.  , 100., 0.  )
181 pz   = geompy.MakeVertex(0.  , 0.  , 100.)
182
183 vxy = geompy.MakeVector(px, py)
184 arc = geompy.MakeArc(py, pz, px)
185 wire = geompy.MakeWire([vxy, arc])
186
187 isPlanarFace = 1
188 face = geompy.MakeFace(wire, isPlanarFace)
189
190 # add the face in the study
191 id_face = geompy.addToStudy(face, "Face to be meshed")
192
193 # create a mesh
194 tria_mesh = smesh.Mesh(face, "Face : triangulation")
195
196 # define 1D meshing:
197 algo = tria_mesh.Segment()
198 algo.NumberOfSegments(20)
199
200 # define 2D meshing:
201
202 # assign triangulation algorithm
203 algo = tria_mesh.Triangle()
204
205 # apply "Max Element Area" hypothesis to each triangle
206 algo.MaxElementArea(100)
207
208 # compute the mesh
209 tria_mesh.Compute()
210 \endcode
211
212 <br>
213 \anchor tui_max_element_volume
214 <h3>Maximum Element Volume</h3>
215
216 \code
217 import geompy
218 import smesh
219
220 # create a cylinder
221 cyl = geompy.MakeCylinderRH(30., 50.)
222 geompy.addToStudy(cyl, "cyl")
223
224 # create a mesh on the cylinder
225 tetra = smesh.Mesh(cyl, "Cylinder : tetrahedrical mesh")
226
227 # assign algorithms
228 algo1D = tetra.Segment()
229 algo2D = tetra.Triangle()
230 algo3D = tetra.Tetrahedron(smesh.NETGEN)
231
232 # assign 1D and 2D hypotheses
233 algo1D.NumberOfSegments(7)
234 algo2D.MaxElementArea(150.)
235
236 # assign Max Element Volume hypothesis
237 algo3D.MaxElementVolume(200.)
238
239 # compute the mesh
240 ret = tetra.Compute()
241 if ret == 0:
242     print "probleme when computing the mesh"
243 else:
244     print "Computation succeded"
245 \endcode
246
247 <br>
248 \anchor tui_length_from_edges
249 <h3>Length from Edges</h3>
250
251 \code
252 import geompy
253 import smesh
254
255 # create sketchers
256 sketcher1 = geompy.MakeSketcher("Sketcher:F 0 0:TT 70 0:TT 70 70:TT 0 70:WW")
257 sketcher2 = geompy.MakeSketcher("Sketcher:F 20 20:TT 50 20:TT 50 50:TT 20 50:WW")
258
259 # create a face from two wires
260 isPlanarFace = 1
261 face1 = geompy.MakeFaces([sketcher1, sketcher2], isPlanarFace)
262 geompy.addToStudy(face1, "Face1")
263
264 # create a mesh
265 tria = smesh.Mesh(face1, "Face : triangle 2D mesh")
266
267 # Define 1D meshing
268 algo1D = tria.Segment()
269 algo1D.NumberOfSegments(2)
270
271 # create and assign the algorithm for 2D meshing with triangles
272 algo2D = tria.Triangle()
273
274 # create and assign "LengthFromEdges" hypothesis to build triangles based on the length of the edges taken from the wire
275 algo2D.LengthFromEdges()
276
277 # compute the mesh
278 tria.Compute()
279 \endcode
280
281 <br><h2>Defining Additional Hypotheses</h2>
282
283 <br>
284 \anchor tui_propagation
285 <h3>Propagation</h3>
286
287 \code
288 from geompy import *
289 import smesh
290
291 # create a box
292 box = MakeBoxDXDYDZ(10., 10., 10.)
293 addToStudy(box, "Box")
294
295 # get one edge of the box to put local hypothesis on
296 p5 = MakeVertex(5., 0., 0.)
297 EdgeX = GetEdgeNearPoint(box, p5)
298 addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
299
300 # create a hexahedral mesh on the box
301 hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
302
303 # set global algorithms and hypotheses
304 algo1D = hexa.Segment()
305 hexa.Quadrangle()
306 hexa.Hexahedron()
307 algo1D.NumberOfSegments(4)
308
309 # create a sub-mesh with local 1D hypothesis and propagation
310 algo_local = hexa.Segment(EdgeX)
311
312 # define "Arithmetic1D" hypothesis to cut an edge in several segments with increasing length
313 algo_local.Arithmetic1D(1, 4)
314
315 # define "Propagation" hypothesis that propagates all other 1D hypotheses
316 # from all edges on the opposite side of a face in case of quadrangular faces
317 algo_local.Propagation()
318
319 # compute the mesh
320 hexa.Compute()
321 \endcode
322
323 <br>
324 \anchor tui_defining_meshing_algos
325 <h2>Defining Meshing Algorithms</h2>
326
327 \code
328 import geompy
329 import smesh
330
331 # create a box
332 box = geompy.MakeBoxDXDYDZ(10., 10., 10.)
333 geompy.addToStudy(box, "Box")
334
335 # 1. Create a hexahedral mesh on the box
336 hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
337
338 # create a Regular 1D algorithm for edges
339 algo1D = hexa.Segment()
340
341 # create a quadrangle 2D algorithm for faces
342 algo2D = hexa.Quadrangle()
343
344 # create a hexahedron 3D algorithm for solids
345 algo3D = hexa.Hexahedron()
346
347 # define hypotheses
348 algo1D.Arithmetic1D(1, 4)
349
350 # compute the mesh
351 hexa.Compute()
352
353 # 2. Create a tetrahedral mesh on the box
354 tetra = smesh.Mesh(box, "Box : tetrahedrical mesh")
355
356 # create a Regular 1D algorithm for edges
357 algo1D = tetra.Segment()
358
359 # create a Mefisto 2D algorithm for faces
360 algo2D = tetra.Triangle()
361
362 # create a Netgen 3D algorithm for solids
363 algo3D = tetra.Tetrahedron(smesh.NETGEN)
364
365 # define hypotheses
366 algo1D.Arithmetic1D(1, 4)
367 algo2D.LengthFromEdges()
368
369 # compute the mesh
370 tetra.Compute()
371
372 # 3. Create a tetrahedral mesh on the box with NETGEN_2D3D algorithm
373 tetraN = smesh.Mesh(box, "Box : tetrahedrical mesh by NETGEN_2D3D")
374
375 # create a Netgen_2D3D algorithm for solids
376 algo3D = tetraN.Tetrahedron(smesh.FULL_NETGEN) 
377
378 # define hypotheses
379 n23_params = algo3D.Parameters()
380
381 # compute the mesh
382 tetraN.Compute()
383 \endcode
384
385 */