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