Salome HOME
Merge from V6_main 28/02/2013
[modules/smesh.git] / doc / salome / examples / defining_hypotheses_ex10.py
1 # Projection Algorithms
2
3 # Project prisms from one meshed box to another mesh on the same box
4
5 from smesh import *
6
7 # Prepare geometry
8
9 # Create a parallelepiped
10 box = geompy.MakeBoxDXDYDZ(200, 100, 70)
11 geompy.addToStudy( box, "box" )
12
13 # Get geom faces to mesh with triangles in the 1ts and 2nd meshes
14 faces = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])
15 # 2 adjacent faces of the box
16 f1 = faces[2]
17 f2 = faces[0]
18 # face opposite to f2
19 f2opp = faces[1]
20
21 # Get vertices used to specify how to associate sides of faces at projection
22 [v1F1, v2F1] = geompy.SubShapeAll(f1, geompy.ShapeType["VERTEX"])[:2]
23 [v1F2, v2F2] = geompy.SubShapeAll(f2, geompy.ShapeType["VERTEX"])[:2]
24 geompy.addToStudyInFather( box, v1F1, "v1F1" )
25 geompy.addToStudyInFather( box, v2F1, "v2F1" )
26 geompy.addToStudyInFather( box, v1F2, "v1F2" )
27 geompy.addToStudyInFather( box, v2F2, "v2F2" )
28
29 # Make group of 3 edges of f1 and f2
30 edgesF1 = geompy.CreateGroup(f1, geompy.ShapeType["EDGE"])
31 geompy.UnionList( edgesF1, geompy.SubShapeAll(f1, geompy.ShapeType["EDGE"])[:3])
32 edgesF2 = geompy.CreateGroup(f2, geompy.ShapeType["EDGE"])
33 geompy.UnionList( edgesF2, geompy.SubShapeAll(f2, geompy.ShapeType["EDGE"])[:3])
34 geompy.addToStudyInFather( box, edgesF1, "edgesF1" )
35 geompy.addToStudyInFather( box, edgesF2, "edgesF2" )
36
37
38 # Make the source mesh with prisms
39 src_mesh = Mesh(box, "Source mesh")
40 src_mesh.Segment().NumberOfSegments(9,10)
41 src_mesh.Quadrangle()
42 src_mesh.Hexahedron()
43 src_mesh.Triangle(f1) # triangular sumbesh 
44 src_mesh.Compute()
45
46
47 # Mesh the box using projection algoritms
48
49 # Define the same global 1D and 2D hypotheses
50 tgt_mesh = Mesh(box, "Target mesh")
51 tgt_mesh.Segment().NumberOfSegments(9,10,UseExisting=True)
52 tgt_mesh.Quadrangle()
53
54 # Define Projection 1D algorithm to project 1d mesh elements from group edgesF2 to edgesF1
55 # It is actually not needed, just a demonstration
56 proj1D = tgt_mesh.Projection1D( edgesF1 )
57 # each vertex must be at the end of a connected group of edges (or a sole edge)
58 proj1D.SourceEdge( edgesF2, src_mesh, v2F1, v2F2 )
59
60 # Define 2D hypotheses to project triangles from f1 face of the source mesh to
61 # f2 face in the target mesh. Vertices specify how to associate sides of faces
62 proj2D = tgt_mesh.Projection2D( f2 )
63 proj2D.SourceFace( f1, src_mesh, v1F1, v1F2, v2F1, v2F2 )
64
65 # 2D hypotheses to project triangles from f2 of target mesh to the face opposite to f2.
66 # Association of face sides is default
67 proj2D = tgt_mesh.Projection2D( f2opp )
68 proj2D.SourceFace( f2 )
69
70 # 3D hypotheses to project prisms from the source to the target mesh
71 proj3D = tgt_mesh.Projection3D()
72 proj3D.SourceShape3D( box, src_mesh, v1F1, v1F2, v2F1, v2F2 )
73 tgt_mesh.Compute()
74
75 # Move the source mesh to visualy compare the two meshes
76 src_mesh.TranslateObject( src_mesh, MakeDirStruct( 210, 0, 0 ), Copy=False)