Salome HOME
8c93ca2e38fee16a22b7a7d616afc25f24ae53f6
[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 # optionally reverse node distribution on certain edges
26 allEdges = geompy.SubShapeAllSortedIDs( box, geompy.ShapeType["EDGE"])
27 reversedEdges = [ allEdges[0], allEdges[4] ]
28
29 # define "Arithmetic1D" hypothesis to cut all edges in several segments with increasing arithmetic length 
30 algo1D.Arithmetic1D(1, 4, reversedEdges)
31
32 # create a quadrangle 2D algorithm for faces
33 hexa.Quadrangle()
34
35 # create a hexahedron 3D algorithm for solids
36 hexa.Hexahedron()
37
38 # compute the mesh
39 hexa.Compute()
40 \endcode
41
42 <br>
43 \anchor tui_deflection_1d
44 <h3>Deflection 1D and Number of Segments</h3>
45
46 \code
47 import geompy
48 import smesh
49
50 # create a face from arc and straight segment
51 px = geompy.MakeVertex(100., 0.  , 0.  )
52 py = geompy.MakeVertex(0.  , 100., 0.  )
53 pz = geompy.MakeVertex(0.  , 0.  , 100.)
54
55 exy = geompy.MakeEdge(px, py)
56 arc = geompy.MakeArc(py, pz, px)
57
58 wire = geompy.MakeWire([exy, arc])
59
60 isPlanarFace = 1
61 face1 = geompy.MakeFace(wire, isPlanarFace)
62 geompy.addToStudy(face1,"Face1")
63
64 # get edges from the face
65 e_straight,e_arc = geompy.SubShapeAll(face1, geompy.ShapeType["EDGE"])
66 geompy.addToStudyInFather(face1, e_arc, "Arc Edge")
67
68 # create hexahedral mesh
69 hexa = smesh.Mesh(face1, "Face : triangle mesh")
70
71 # define "NumberOfSegments" hypothesis to cut a straight edge in a fixed number of segments
72 algo1D = hexa.Segment()
73 algo1D.NumberOfSegments(6)
74
75 # define "MaxElementArea" hypothesis
76 algo2D = hexa.Triangle()
77 algo2D.MaxElementArea(70.0)
78
79 # define a local "Deflection1D" hypothesis on the arc
80 algo_local = hexa.Segment(e_arc)
81 algo_local.Deflection1D(1.0)
82
83 # compute the mesh
84 hexa.Compute()
85 \endcode
86
87 <br>
88 \anchor tui_start_and_end_length
89 <h3>Start and End Length</h3>
90
91 \code
92 from geompy import *
93 import smesh
94
95 # create a box
96 box = MakeBoxDXDYDZ(10., 10., 10.)
97 addToStudy(box, "Box")
98
99 # get one edge of the box to put local hypothesis on
100 p5 = MakeVertex(5., 0., 0.)
101 EdgeX = GetEdgeNearPoint(box, p5)
102 addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
103
104 # create a hexahedral mesh on the box
105 hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
106
107 # set algorithms
108 algo1D = hexa.Segment()
109 hexa.Quadrangle()
110 hexa.Hexahedron()
111
112 # define "NumberOfSegments" hypothesis to cut an edge in a fixed number of segments
113 algo1D.NumberOfSegments(4)
114
115 # create a local hypothesis
116 algo_local = hexa.Segment(EdgeX)
117
118 # define "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
119 algo_local.StartEndLength(1, 6)
120
121 # define "Propagation" hypothesis that propagates all other hypothesis
122 # on all edges on the opposite side in case of quadrangular faces
123 algo_local.Propagation()
124
125 # compute the mesh
126 hexa.Compute()
127 \endcode
128
129 <br>
130 \anchor tui_average_length
131 <h3>Average Length</h3>
132
133 \code
134 from geompy import *
135 import smesh
136
137 # create a box
138 box = MakeBoxDXDYDZ(10., 10., 10.)
139 addToStudy(box, "Box")
140
141 # get one edge of the box to put local hypothesis on
142 p5 = MakeVertex(5., 0., 0.)
143 EdgeX = GetEdgeNearPoint(box, p5)
144 addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
145
146 # create a hexahedral mesh on the box
147 hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
148
149 # set algorithms
150 algo1D = hexa.Segment()
151 hexa.Quadrangle()
152 hexa.Hexahedron()
153
154 # define "NumberOfSegments" hypothesis to cut all edges in a fixed number of segments
155 algo1D.NumberOfSegments(4)
156
157 # create a sub-mesh
158 algo_local = hexa.Segment(EdgeX)
159
160 # define "LocalLength" hypothesis to cut an edge in several segments with the same length
161 algo_local.LocalLength(2.)
162
163 # define "Propagation" hypothesis that propagates all other hypothesis
164 # on all edges on the opposite side in case of quadrangular faces
165 algo_local.Propagation()
166
167 # compute the mesh
168 hexa.Compute()
169 \endcode
170
171 <br><h2>Defining 2D and 3D hypotheses</h2>
172
173 <br>
174 \anchor tui_max_element_area
175 <h3>Maximum Element Area</h3>
176
177 \code
178 import geompy
179 import smesh
180 import salome 
181
182 # create a face
183 px   = geompy.MakeVertex(100., 0.  , 0.  )
184 py   = geompy.MakeVertex(0.  , 100., 0.  )
185 pz   = geompy.MakeVertex(0.  , 0.  , 100.)
186
187 vxy = geompy.MakeVector(px, py)
188 arc = geompy.MakeArc(py, pz, px)
189 wire = geompy.MakeWire([vxy, arc])
190
191 isPlanarFace = 1
192 face = geompy.MakeFace(wire, isPlanarFace)
193
194 # add the face in the study
195 id_face = geompy.addToStudy(face, "Face to be meshed")
196
197 # create a mesh
198 tria_mesh = smesh.Mesh(face, "Face : triangulation")
199
200 # define 1D meshing:
201 algo = tria_mesh.Segment()
202 algo.NumberOfSegments(20)
203
204 # define 2D meshing:
205
206 # assign triangulation algorithm
207 algo = tria_mesh.Triangle()
208
209 # apply "Max Element Area" hypothesis to each triangle
210 algo.MaxElementArea(100)
211
212 # compute the mesh
213 tria_mesh.Compute()
214 \endcode
215
216 <br>
217 \anchor tui_max_element_volume
218 <h3>Maximum Element Volume</h3>
219
220 \code
221 import geompy
222 import smesh
223
224 # create a cylinder
225 cyl = geompy.MakeCylinderRH(30., 50.)
226 geompy.addToStudy(cyl, "cyl")
227
228 # create a mesh on the cylinder
229 tetra = smesh.Mesh(cyl, "Cylinder : tetrahedrical mesh")
230
231 # assign algorithms
232 algo1D = tetra.Segment()
233 algo2D = tetra.Triangle()
234 algo3D = tetra.Tetrahedron(smesh.NETGEN)
235
236 # assign 1D and 2D hypotheses
237 algo1D.NumberOfSegments(7)
238 algo2D.MaxElementArea(150.)
239
240 # assign Max Element Volume hypothesis
241 algo3D.MaxElementVolume(200.)
242
243 # compute the mesh
244 ret = tetra.Compute()
245 if ret == 0:
246     print "probleme when computing the mesh"
247 else:
248     print "Computation succeded"
249 \endcode
250
251 <br>
252 \anchor tui_length_from_edges
253 <h3>Length from Edges</h3>
254
255 \code
256 import geompy
257 import smesh
258
259 # create sketchers
260 sketcher1 = geompy.MakeSketcher("Sketcher:F 0 0:TT 70 0:TT 70 70:TT 0 70:WW")
261 sketcher2 = geompy.MakeSketcher("Sketcher:F 20 20:TT 50 20:TT 50 50:TT 20 50:WW")
262
263 # create a face from two wires
264 isPlanarFace = 1
265 face1 = geompy.MakeFaces([sketcher1, sketcher2], isPlanarFace)
266 geompy.addToStudy(face1, "Face1")
267
268 # create a mesh
269 tria = smesh.Mesh(face1, "Face : triangle 2D mesh")
270
271 # Define 1D meshing
272 algo1D = tria.Segment()
273 algo1D.NumberOfSegments(2)
274
275 # create and assign the algorithm for 2D meshing with triangles
276 algo2D = tria.Triangle()
277
278 # create and assign "LengthFromEdges" hypothesis to build triangles based on the length of the edges taken from the wire
279 algo2D.LengthFromEdges()
280
281 # compute the mesh
282 tria.Compute()
283 \endcode
284
285 <br><h2>Defining Additional Hypotheses</h2>
286
287 <br>
288 \anchor tui_propagation
289 <h3>Propagation</h3>
290
291 \code
292 from geompy import *
293 import smesh
294
295 # create a box
296 box = MakeBoxDXDYDZ(10., 10., 10.)
297 addToStudy(box, "Box")
298
299 # get one edge of the box to put local hypothesis on
300 p5 = MakeVertex(5., 0., 0.)
301 EdgeX = GetEdgeNearPoint(box, p5)
302 addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
303
304 # create a hexahedral mesh on the box
305 hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
306
307 # set global algorithms and hypotheses
308 algo1D = hexa.Segment()
309 hexa.Quadrangle()
310 hexa.Hexahedron()
311 algo1D.NumberOfSegments(4)
312
313 # create a sub-mesh with local 1D hypothesis and propagation
314 algo_local = hexa.Segment(EdgeX)
315
316 # define "Arithmetic1D" hypothesis to cut an edge in several segments with increasing length
317 algo_local.Arithmetic1D(1, 4)
318
319 # define "Propagation" hypothesis that propagates all other 1D hypotheses
320 # from all edges on the opposite side of a face in case of quadrangular faces
321 algo_local.Propagation()
322
323 # compute the mesh
324 hexa.Compute()
325 \endcode
326
327 <br>
328 \anchor tui_defining_meshing_algos
329 <h2>Defining Meshing Algorithms</h2>
330
331 \code
332 import geompy
333 import smesh
334
335 # create a box
336 box = geompy.MakeBoxDXDYDZ(10., 10., 10.)
337 geompy.addToStudy(box, "Box")
338
339 # 1. Create a hexahedral mesh on the box
340 hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
341
342 # create a Regular 1D algorithm for edges
343 algo1D = hexa.Segment()
344
345 # create a quadrangle 2D algorithm for faces
346 algo2D = hexa.Quadrangle()
347
348 # create a hexahedron 3D algorithm for solids
349 algo3D = hexa.Hexahedron()
350
351 # define hypotheses
352 algo1D.Arithmetic1D(1, 4)
353
354 # compute the mesh
355 hexa.Compute()
356
357 # 2. Create a tetrahedral mesh on the box
358 tetra = smesh.Mesh(box, "Box : tetrahedrical mesh")
359
360 # create a Regular 1D algorithm for edges
361 algo1D = tetra.Segment()
362
363 # create a Mefisto 2D algorithm for faces
364 algo2D = tetra.Triangle()
365
366 # create a Netgen 3D algorithm for solids
367 algo3D = tetra.Tetrahedron(smesh.NETGEN)
368
369 # define hypotheses
370 algo1D.Arithmetic1D(1, 4)
371 algo2D.LengthFromEdges()
372
373 # compute the mesh
374 tetra.Compute()
375
376 # 3. Create a tetrahedral mesh on the box with NETGEN_2D3D algorithm
377 tetraN = smesh.Mesh(box, "Box : tetrahedrical mesh by NETGEN_2D3D")
378
379 # create a Netgen_2D3D algorithm for solids
380 algo3D = tetraN.Tetrahedron(smesh.FULL_NETGEN) 
381
382 # define hypotheses
383 n23_params = algo3D.Parameters()
384
385 # compute the mesh
386 tetraN.Compute()
387 \endcode
388
389 <br>
390 \anchor tui_projection
391 <h3>Projection Algorithms</h3>
392
393 \code
394 # Project prisms from one meshed box to another mesh on the same box
395
396 from smesh import *
397
398 # Prepare geometry
399
400 # Create a parallelepiped
401 box = geompy.MakeBoxDXDYDZ(200, 100, 70)
402 geompy.addToStudy( box, "box" )
403
404 # Get geom faces to mesh with triangles in the 1ts and 2nd meshes
405 faces = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])
406 # 2 adjacent faces of the box
407 f1 = faces[2]
408 f2 = faces[0]
409 # face opposite to f2
410 f2opp = faces[1]
411
412 # Get vertices used to specify how to associate sides of faces at projection
413 [v1F1, v2F1] = geompy.SubShapeAll(f1, geompy.ShapeType["VERTEX"])[:2]
414 [v1F2, v2F2] = geompy.SubShapeAll(f2, geompy.ShapeType["VERTEX"])[:2]
415 geompy.addToStudyInFather( box, v1F1, "v1F1" )
416 geompy.addToStudyInFather( box, v2F1, "v2F1" )
417 geompy.addToStudyInFather( box, v1F2, "v1F2" )
418 geompy.addToStudyInFather( box, v2F2, "v2F2" )
419
420 # Make group of 3 edges of f1 and f2
421 edgesF1 = geompy.CreateGroup(f1, geompy.ShapeType["EDGE"])
422 geompy.UnionList( edgesF1, geompy.SubShapeAll(f1, geompy.ShapeType["EDGE"])[:3])
423 edgesF2 = geompy.CreateGroup(f2, geompy.ShapeType["EDGE"])
424 geompy.UnionList( edgesF2, geompy.SubShapeAll(f2, geompy.ShapeType["EDGE"])[:3])
425 geompy.addToStudyInFather( box, edgesF1, "edgesF1" )
426 geompy.addToStudyInFather( box, edgesF2, "edgesF2" )
427
428
429 # Make the source mesh with prisms
430 src_mesh = Mesh(box, "Source mesh")
431 src_mesh.Segment().NumberOfSegments(9,10)
432 src_mesh.Quadrangle()
433 src_mesh.Hexahedron()
434 src_mesh.Triangle(f1) # triangular sumbesh 
435 src_mesh.Compute()
436
437
438 # Mesh the box using projection algoritms
439
440 # Define the same global 1D and 2D hypotheses
441 tgt_mesh = Mesh(box, "Target mesh")
442 tgt_mesh.Segment().NumberOfSegments(9,10,UseExisting=True)
443 tgt_mesh.Quadrangle()
444
445 # Define Projection 1D algorithm to project 1d mesh elements from group edgesF2 to edgesF1
446 # It is actually not needed, just a demonstration
447 proj1D = tgt_mesh.Projection1D( edgesF1 )
448 # each vertex must be at the end of a connected group of edges (or a sole edge)
449 proj1D.SourceEdge( edgesF2, src_mesh, v2F1, v2F2 )
450
451 # Define 2D hypotheses to project triangles from f1 face of the source mesh to
452 # f2 face in the target mesh. Vertices specify how to associate sides of faces
453 proj2D = tgt_mesh.Projection2D( f2 )
454 proj2D.SourceFace( f1, src_mesh, v1F1, v1F2, v2F1, v2F2 )
455
456 # 2D hypotheses to project triangles from f2 of target mesh to the face opposite to f2.
457 # Association of face sides is default
458 proj2D = tgt_mesh.Projection2D( f2opp )
459 proj2D.SourceFace( f2 )
460
461 # 3D hypotheses to project prisms from the source to the target mesh
462 proj3D = tgt_mesh.Projection3D()
463 proj3D.SourceShape3D( box, src_mesh, v1F1, v1F2, v2F1, v2F2 )
464 tgt_mesh.Compute()
465
466 # Move the source mesh to visualy compare the two meshes
467 src_mesh.TranslateObject( src_mesh, MakeDirStruct( 210, 0, 0 ), Copy=False)
468
469 \endcode
470
471 \n Other meshing algorithms:
472
473 <ul>
474 <li>\subpage tui_defining_blsurf_hypotheses_page</li>
475 </ul>
476 */