3 \page tui_defining_hypotheses_page Defining Hypotheses and Algorithms
5 <h2>Defining 1D Hypotheses</h2>
8 \anchor tui_1d_arithmetic
16 box = geompy.MakeBoxDXDYDZ(10., 10., 10.)
17 geompy.addToStudy(box, "Box")
19 # create a hexahedral mesh on the box
20 hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
22 # create a Regular 1D algorithm for edges
23 algo1D = hexa.Segment()
25 # optionally reverse node distribution on certain edges
26 allEdges = geompy.SubShapeAllSortedIDs( box, geompy.ShapeType["EDGE"])
27 reversedEdges = [ allEdges[0], allEdges[4] ]
29 # define "Arithmetic1D" hypothesis to cut all edges in several segments with increasing arithmetic length
30 algo1D.Arithmetic1D(1, 4, reversedEdges)
32 # create a quadrangle 2D algorithm for faces
35 # create a hexahedron 3D algorithm for solids
43 \anchor tui_deflection_1d
44 <h3>Deflection 1D and Number of Segments</h3>
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.)
55 exy = geompy.MakeEdge(px, py)
56 arc = geompy.MakeArc(py, pz, px)
58 wire = geompy.MakeWire([exy, arc])
61 face1 = geompy.MakeFace(wire, isPlanarFace)
62 geompy.addToStudy(face1,"Face1")
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")
68 # create hexahedral mesh
69 hexa = smesh.Mesh(face1, "Face : triangle mesh")
71 # define "NumberOfSegments" hypothesis to cut a straight edge in a fixed number of segments
72 algo1D = hexa.Segment()
73 algo1D.NumberOfSegments(6)
75 # define "MaxElementArea" hypothesis
76 algo2D = hexa.Triangle()
77 algo2D.MaxElementArea(70.0)
79 # define a local "Deflection1D" hypothesis on the arc
80 algo_local = hexa.Segment(e_arc)
81 algo_local.Deflection1D(1.0)
88 \anchor tui_start_and_end_length
89 <h3>Start and End Length</h3>
96 box = MakeBoxDXDYDZ(10., 10., 10.)
97 addToStudy(box, "Box")
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]")
104 # create a hexahedral mesh on the box
105 hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
108 algo1D = hexa.Segment()
112 # define "NumberOfSegments" hypothesis to cut an edge in a fixed number of segments
113 algo1D.NumberOfSegments(4)
115 # create a local hypothesis
116 algo_local = hexa.Segment(EdgeX)
118 # define "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
119 algo_local.StartEndLength(1, 6)
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()
130 \anchor tui_average_length
131 <h3>Local Length</h3>
138 box = MakeBoxDXDYDZ(10., 10., 10.)
139 addToStudy(box, "Box")
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]")
146 # create a hexahedral mesh on the box
147 hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
150 algo1D = hexa.Segment()
154 # define "NumberOfSegments" hypothesis to cut all edges in a fixed number of segments
155 algo1D.NumberOfSegments(4)
158 algo_local = hexa.Segment(EdgeX)
160 # define "LocalLength" hypothesis to cut an edge in several segments with the same length
161 algo_local.LocalLength(2.)
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()
171 <br><h2>Defining 2D and 3D hypotheses</h2>
174 \anchor tui_max_element_area
175 <h3>Maximum Element Area</h3>
183 px = geompy.MakeVertex(100., 0. , 0. )
184 py = geompy.MakeVertex(0. , 100., 0. )
185 pz = geompy.MakeVertex(0. , 0. , 100.)
187 vxy = geompy.MakeVector(px, py)
188 arc = geompy.MakeArc(py, pz, px)
189 wire = geompy.MakeWire([vxy, arc])
192 face = geompy.MakeFace(wire, isPlanarFace)
194 # add the face in the study
195 id_face = geompy.addToStudy(face, "Face to be meshed")
198 tria_mesh = smesh.Mesh(face, "Face : triangulation")
201 algo = tria_mesh.Segment()
202 algo.NumberOfSegments(20)
206 # assign triangulation algorithm
207 algo = tria_mesh.Triangle()
209 # apply "Max Element Area" hypothesis to each triangle
210 algo.MaxElementArea(100)
217 \anchor tui_max_element_volume
218 <h3>Maximum Element Volume</h3>
225 cyl = geompy.MakeCylinderRH(30., 50.)
226 geompy.addToStudy(cyl, "cyl")
228 # create a mesh on the cylinder
229 tetra = smesh.Mesh(cyl, "Cylinder : tetrahedrical mesh")
232 algo1D = tetra.Segment()
233 algo2D = tetra.Triangle()
234 algo3D = tetra.Tetrahedron()
236 # assign 1D and 2D hypotheses
237 algo1D.NumberOfSegments(7)
238 algo2D.MaxElementArea(150.)
240 # assign Max Element Volume hypothesis
241 algo3D.MaxElementVolume(200.)
244 ret = tetra.Compute()
246 print "probleme when computing the mesh"
248 print "Computation succeded"
252 \anchor tui_length_from_edges
253 <h3>Length from Edges</h3>
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")
263 # create a face from two wires
265 face1 = geompy.MakeFaces([sketcher1, sketcher2], isPlanarFace)
266 geompy.addToStudy(face1, "Face1")
269 tria = smesh.Mesh(face1, "Face : triangle 2D mesh")
272 algo1D = tria.Segment()
273 algo1D.NumberOfSegments(2)
275 # create and assign the algorithm for 2D meshing with triangles
276 algo2D = tria.Triangle()
278 # create and assign "LengthFromEdges" hypothesis to build triangles based on the length of the edges taken from the wire
279 algo2D.LengthFromEdges()
285 <br><h2>Defining Additional Hypotheses</h2>
288 \anchor tui_propagation
296 box = MakeBoxDXDYDZ(10., 10., 10.)
297 addToStudy(box, "Box")
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]")
304 # create a hexahedral mesh on the box
305 hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
307 # set global algorithms and hypotheses
308 algo1D = hexa.Segment()
311 algo1D.NumberOfSegments(4)
313 # create a sub-mesh with local 1D hypothesis and propagation
314 algo_local = hexa.Segment(EdgeX)
316 # define "Arithmetic1D" hypothesis to cut an edge in several segments with increasing length
317 algo_local.Arithmetic1D(1, 4)
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()
328 \anchor tui_defining_meshing_algos
329 <h2>Defining Meshing Algorithms</h2>
336 box = geompy.MakeBoxDXDYDZ(10., 10., 10.)
337 geompy.addToStudy(box, "Box")
339 # 1. Create a hexahedral mesh on the box
340 hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
342 # create a Regular 1D algorithm for edges
343 algo1D = hexa.Segment()
345 # create a quadrangle 2D algorithm for faces
346 algo2D = hexa.Quadrangle()
348 # create a hexahedron 3D algorithm for solids
349 algo3D = hexa.Hexahedron()
352 algo1D.Arithmetic1D(1, 4)
357 # 2. Create a tetrahedral mesh on the box
358 tetra = smesh.Mesh(box, "Box : tetrahedrical mesh")
360 # create a Regular 1D algorithm for edges
361 algo1D = tetra.Segment()
363 # create a Mefisto 2D algorithm for faces
364 algo2D = tetra.Triangle()
366 # create a 3D algorithm for solids
367 algo3D = tetra.Tetrahedron()
370 algo1D.Arithmetic1D(1, 4)
371 algo2D.LengthFromEdges()
379 \anchor tui_projection
380 <h3>Projection Algorithms</h3>
383 # Project prisms from one meshed box to another mesh on the same box
389 # Create a parallelepiped
390 box = geompy.MakeBoxDXDYDZ(200, 100, 70)
391 geompy.addToStudy( box, "box" )
393 # Get geom faces to mesh with triangles in the 1ts and 2nd meshes
394 faces = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])
395 # 2 adjacent faces of the box
398 # face opposite to f2
401 # Get vertices used to specify how to associate sides of faces at projection
402 [v1F1, v2F1] = geompy.SubShapeAll(f1, geompy.ShapeType["VERTEX"])[:2]
403 [v1F2, v2F2] = geompy.SubShapeAll(f2, geompy.ShapeType["VERTEX"])[:2]
404 geompy.addToStudyInFather( box, v1F1, "v1F1" )
405 geompy.addToStudyInFather( box, v2F1, "v2F1" )
406 geompy.addToStudyInFather( box, v1F2, "v1F2" )
407 geompy.addToStudyInFather( box, v2F2, "v2F2" )
409 # Make group of 3 edges of f1 and f2
410 edgesF1 = geompy.CreateGroup(f1, geompy.ShapeType["EDGE"])
411 geompy.UnionList( edgesF1, geompy.SubShapeAll(f1, geompy.ShapeType["EDGE"])[:3])
412 edgesF2 = geompy.CreateGroup(f2, geompy.ShapeType["EDGE"])
413 geompy.UnionList( edgesF2, geompy.SubShapeAll(f2, geompy.ShapeType["EDGE"])[:3])
414 geompy.addToStudyInFather( box, edgesF1, "edgesF1" )
415 geompy.addToStudyInFather( box, edgesF2, "edgesF2" )
418 # Make the source mesh with prisms
419 src_mesh = Mesh(box, "Source mesh")
420 src_mesh.Segment().NumberOfSegments(9,10)
421 src_mesh.Quadrangle()
422 src_mesh.Hexahedron()
423 src_mesh.Triangle(f1) # triangular sumbesh
427 # Mesh the box using projection algoritms
429 # Define the same global 1D and 2D hypotheses
430 tgt_mesh = Mesh(box, "Target mesh")
431 tgt_mesh.Segment().NumberOfSegments(9,10,UseExisting=True)
432 tgt_mesh.Quadrangle()
434 # Define Projection 1D algorithm to project 1d mesh elements from group edgesF2 to edgesF1
435 # It is actually not needed, just a demonstration
436 proj1D = tgt_mesh.Projection1D( edgesF1 )
437 # each vertex must be at the end of a connected group of edges (or a sole edge)
438 proj1D.SourceEdge( edgesF2, src_mesh, v2F1, v2F2 )
440 # Define 2D hypotheses to project triangles from f1 face of the source mesh to
441 # f2 face in the target mesh. Vertices specify how to associate sides of faces
442 proj2D = tgt_mesh.Projection2D( f2 )
443 proj2D.SourceFace( f1, src_mesh, v1F1, v1F2, v2F1, v2F2 )
445 # 2D hypotheses to project triangles from f2 of target mesh to the face opposite to f2.
446 # Association of face sides is default
447 proj2D = tgt_mesh.Projection2D( f2opp )
448 proj2D.SourceFace( f2 )
450 # 3D hypotheses to project prisms from the source to the target mesh
451 proj3D = tgt_mesh.Projection3D()
452 proj3D.SourceShape3D( box, src_mesh, v1F1, v1F2, v2F1, v2F2 )
455 # Move the source mesh to visualy compare the two meshes
456 src_mesh.TranslateObject( src_mesh, MakeDirStruct( 210, 0, 0 ), Copy=False)
462 \anchor tui_fixed_points
464 <h2>1D Mesh with Fixed Points example</h2>
472 # Create face and explode it on edges
473 face = geompy.MakeFaceHW(100, 100, 1)
474 edges = geompy.SubShapeAllSorted(face, geompy.ShapeType["EDGE"])
475 geompy.addToStudy( face, "Face" )
477 # get the first edge from exploded result
478 edge1 = geompy.GetSubShapeID(face, edges[0])
480 # Define Mesh on previously created face
481 Mesh_1 = smesh.Mesh(face)
483 # Create Fixed Point 1D hypothesis and define parameters.
484 # Note: values greater than 1.0 and less than 0.0 are not taken into account;
485 # duplicated values are removed. Also, if not specified explicitly, values 0.0 and 1.0
486 # add added automatically.
487 # The number of segments should correspond to the number of points (NbSeg = NbPnt-1);
488 # extra values of segments splitting parameter are not taken into account,
489 # while missing values are considered to be equal to 1.
490 Fixed_points_1D_1 = smesh.CreateHypothesis('FixedPoints1D')
491 Fixed_points_1D_1.SetPoints( [ 1.1, 0.9, 0.5, 0.0, 0.5, -0.3 ] )
492 Fixed_points_1D_1.SetNbSegments( [ 3, 1, 2 ] )
493 Fixed_points_1D_1.SetReversedEdges( [edge1] )
495 # Add hypothesis to mesh and define 2D parameters
496 Mesh_1.AddHypothesis(Fixed_points_1D_1)
497 Regular_1D = Mesh_1.Segment()
498 Quadrangle_2D = Mesh_1.Quadrangle()
503 \anchor tui_radial_quadrangle
504 <h2> Radial Quadrangle 1D2D example </h2>
508 SetCurrentStudy(salome.myStudy)
510 # Create face from the wire and add to study
511 Face = geompy.MakeSketcher("Sketcher:F 0 0:TT 20 0:R 90:C 20 90:WF", [0, 0, 0, 1, 0, 0, 0, 0, 1])
512 geompy.addToStudy(Face,"Face")
513 edges = geompy.SubShapeAllSorted(Face, geompy.ShapeType["EDGE"])
514 circle, radius1, radius2 = edges
515 geompy.addToStudyInFather(Face, radius1,"radius1")
516 geompy.addToStudyInFather(Face, radius2,"radius2")
517 geompy.addToStudyInFather(Face, circle,"circle")
520 # Define geometry for mesh, and Radial Quadrange algorithm
521 mesh = smesh.Mesh(Face)
522 radial_Quad_algo = mesh.Quadrangle(algo=RADIAL_QUAD)
524 # The Radial Quadrange algorithm can work without any hypothesis
525 # In this case it uses "Default Nb of Segments" preferences parameter to discretize edges
528 # The Radial Quadrange uses global or local 1d hypotheses if it does
529 # not have its own hypotheses.
530 # Define global hypotheses to discretize radial edges and a local one for circular edge
531 global_Nb_Segments = mesh.Segment().NumberOfSegments(5)
532 local_Nb_Segments = mesh.Segment(circle).NumberOfSegments(10)
535 # Define own parameters of Radial Quadrange algorithm
536 radial_Quad_algo.NumberOfLayers( 4 )
540 \anchor tui_quadrangle_parameters
541 <h2>Quadrangle Parameters example 1 (meshing a face with 3 edges) </h2>
544 SetCurrentStudy(salome.myStudy)
546 # Get 1/4 part from the disk face.
547 Box_1 = geompy.MakeBoxDXDYDZ(100, 100, 100)
548 Disk_1 = geompy.MakeDiskR(100, 1)
549 Common_1 = geompy.MakeCommon(Disk_1, Box_1)
550 geompy.addToStudy( Disk_1, "Disk_1" )
551 geompy.addToStudy( Box_1, "Box_1" )
552 geompy.addToStudy( Common_1, "Common_1" )
554 # Set the Geometry for meshing
555 Mesh_1 = smesh.Mesh(Common_1)
558 # Define 1D hypothesis and compute the mesh
559 Regular_1D = Mesh_1.Segment()
560 Nb_Segments_1 = Regular_1D.NumberOfSegments(10)
561 Nb_Segments_1.SetDistrType( 0 )
563 # Create Quadrangle parameters and define the Base Vertex.
564 Quadrangle_2D = Mesh_1.Quadrangle().TriangleVertex( 8 )
569 <h2>Quadrangle Parameters example 2 (using different types) </h2>
575 # Make quadrangle face and explode it on edges.
576 Vertex_1 = geompy.MakeVertex(0, 0, 0)
577 Vertex_2 = geompy.MakeVertex(40, 0, 0)
578 Vertex_3 = geompy.MakeVertex(40, 30, 0)
579 Vertex_4 = geompy.MakeVertex(0, 30, 0)
580 Quadrangle_Face_1 = geompy.MakeQuad4Vertices(Vertex_1, Vertex_4, Vertex_3, Vertex_2)
581 [Edge_1,Edge_2,Edge_3,Edge_4] = geompy.SubShapeAllSorted(Quadrangle_Face_1, geompy.ShapeType["EDGE"])
582 geompy.addToStudy( Vertex_1, "Vertex_1" )
583 geompy.addToStudy( Vertex_2, "Vertex_2" )
584 geompy.addToStudy( Vertex_3, "Vertex_3" )
585 geompy.addToStudy( Vertex_4, "Vertex_4" )
586 geompy.addToStudy( Quadrangle_Face_1, "Quadrangle Face_1" )
587 geompy.addToStudyInFather( Quadrangle_Face_1, Edge_2, "Edge_2" )
589 # Set the Geometry for meshing
590 Mesh_1 = smesh.Mesh(Quadrangle_Face_1)
592 # Create Quadrangle parameters and
593 # define the Type as Quadrangle Preference
594 Quadrangle_Parameters_1 = smesh.CreateHypothesis('QuadrangleParams')
595 Quadrangle_Parameters_1.SetQuadType( StdMeshers.QUAD_QUADRANGLE_PREF )
597 # Define other hypotheses and algorithms
598 Regular_1D = Mesh_1.Segment()
599 Nb_Segments_1 = Regular_1D.NumberOfSegments(4)
600 Nb_Segments_1.SetDistrType( 0 )
601 status = Mesh_1.AddHypothesis(Quadrangle_Parameters_1)
602 Quadrangle_2D = Mesh_1.Quadrangle()
604 # Define submesh on one edge to provide different number of segments
605 Regular_1D_1 = Mesh_1.Segment(geom=Edge_2)
606 Nb_Segments_2 = Regular_1D_1.NumberOfSegments(10)
607 Nb_Segments_2.SetDistrType( 0 )
608 SubMesh_1 = Regular_1D_1.GetSubMesh()
610 # Compute mesh (with Quadrangle Preference type)
611 isDone = Mesh_1.Compute()
613 # Change type to Reduced and compute again
614 Quadrangle_Parameters_1.SetQuadType( StdMeshers.QUAD_REDUCED )
615 isDone = Mesh_1.Compute()
619 <h2>"Use Existing Elements" example </h2>
623 SetCurrentStudy(salome.myStudy)
625 # Make a patritioned box
627 box = geompy.MakeBoxDXDYDZ(100,100,100)
629 N = geompy.MakeVectorDXDYDZ( 1,0,0 )
630 O = geompy.MakeVertex( 50,0,0 )
631 plane = geompy.MakePlane( O, N, 200 ) # plane YOZ
633 shape2boxes = geompy.MakeHalfPartition( box, plane )
634 boxes = geompy.SubShapeAllSorted(shape2boxes, geompy.ShapeType["SOLID"])
636 geompy.addToStudy( boxes[0], "boxes[0]")
637 geompy.addToStudy( boxes[1], "boxes[1]")
638 midFace0 = geompy.SubShapeAllSorted(boxes[0], geompy.ShapeType["FACE"])[5]
639 geompy.addToStudyInFather( boxes[0], midFace0, "middle Face")
640 midFace1 = geompy.SubShapeAllSorted(boxes[1], geompy.ShapeType["FACE"])[0]
641 geompy.addToStudyInFather( boxes[1], midFace1, "middle Face")
643 # Mesh one of boxes with quadrangles. It is a source mesh
645 srcMesh = Mesh(boxes[0], "source mesh") # box coloser to CS origin
646 nSeg1 = srcMesh.Segment().NumberOfSegments(4)
649 srcFaceGroup = srcMesh.GroupOnGeom( midFace0, "src faces", FACE )
651 # Import faces from midFace0 to the target mesh
653 tgtMesh = Mesh(boxes[1], "target mesh")
654 importAlgo = tgtMesh.UseExisting2DElements(midFace1)
655 import2hyp = importAlgo.SourceFaces( [srcFaceGroup] )
656 tgtMesh.Segment().NumberOfSegments(3)
660 # Import the whole source mesh with groups
661 import2hyp.SetCopySourceMesh(True,True)
665 \anchor tui_viscous_layers
666 <h2>Viscous layers construction</h2>
670 SetCurrentStudy(salome.myStudy)
672 X = geompy.MakeVectorDXDYDZ( 1,0,0 )
673 O = geompy.MakeVertex( 100,50,50 )
674 plane = geompy.MakePlane( O, X, 200 ) # plane YZ
676 box = geompy.MakeBoxDXDYDZ(200,100,100)
678 shape = geompy.MakeHalfPartition( box, plane )
680 faces = geompy.SubShapeAllSorted(shape, geompy.ShapeType["FACE"])
682 ignoreFaces = [ faces[0], faces[-1]]
684 geompy.addToStudy( shape, "shape" )
685 geompy.addToStudyInFather( shape, face1, "face1")
688 mesh = Mesh(shape, "CFD")
690 mesh.Segment().NumberOfSegments( 4 )
693 mesh.Quadrangle(face1)
695 algo3D = mesh.Tetrahedron()
700 layersHyp = algo3D.ViscousLayers(thickness,numberOfLayers,stretchFactor,ignoreFaces)
704 mesh.MakeGroup("Tetras",VOLUME,FT_ElemGeomType,"=",Geom_TETRA)
705 mesh.MakeGroup("Pyras",VOLUME,FT_ElemGeomType,"=",Geom_PYRAMID)
706 mesh.MakeGroup("Prims",VOLUME,FT_ElemGeomType,"=",Geom_PENTA)