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