Salome HOME
Merge from BR_plugins_pbyacs 03/04/2013
[plugins/ghs3dplugin.git] / doc / salome / examples / ghs3d_enfmesh.py
1
2 # It is possible to constrain GHS3D with another mesh or group.
3 # The constraint can refer to the nodes, edges or faces.
4 # This feature is available only on 2D meshes without geometry.
5 # The constraining elements are called enforced elements for the mesh.
6 # They can be recovered using groups if necessary.
7
8 # In the following examples, a box and a cylinder are meshed in 2D.
9 # The mesh of the cylinder will be used as a constraint for the 
10 # 3D mesh of the box.
11
12 import salome
13 salome.salome_init()
14 import GEOM
15 from salome.geom import geomBuilder
16 geompy = geomBuilder.New(salome.myStudy)
17
18 import SMESH, SALOMEDS
19 from salome.smesh import smeshBuilder
20 smesh =  smeshBuilder.New(salome.myStudy)
21
22 box = geompy.MakeBoxDXDYDZ(200, 200, 200)
23 geompy.addToStudy( box, "box" )
24 cylindre = geompy.MakeCylinderRH(50, 50)
25 geompy.TranslateDXDYDZ(cylindre, 100, 100, 30)
26 face_cyl = geompy.ExtractShapes(cylindre, geompy.ShapeType["FACE"], True)[1]
27 geompy.addToStudy( cylindre, 'cylindre' )
28 geompy.addToStudyInFather( cylindre, face_cyl, 'face_cyl' )
29 p1 = geompy.MakeVertex(20, 20, 20)
30 p2 = geompy.MakeVertex(180, 180, 20)
31 c = geompy.MakeCompound([p1,p2])
32 geompy.addToStudy( p1, "p1" )
33 geompy.addToStudy( p2, "p2" )
34 geompy.addToStudy( c, "c" )
35
36 # Create the 2D algorithm and hypothesis
37 BLSURF = smesh.CreateHypothesis('BLSURF', 'BLSURFEngine')
38 # For the box
39 BLSURF_Parameters = smesh.CreateHypothesis('BLSURF_Parameters', 'BLSURFEngine')
40 BLSURF_Parameters.SetPhysicalMesh( 1 )
41 BLSURF_Parameters.SetPhySize( 200 )
42 # For the cylinder
43 BLSURF_Parameters2 = smesh.CreateHypothesis('BLSURF_Parameters', 'BLSURFEngine')
44 BLSURF_Parameters2.SetGeometricMesh( 1 )
45
46 # Create the 3D algorithm and hypothesis
47 GHS3D = smesh.CreateHypothesis('GHS3D_3D', 'GHS3DEngine')
48 GHS3D_Parameters_node = smesh.CreateHypothesis('GHS3D_Parameters', 'GHS3DEngine')
49 #GHS3D_Parameters_node.SetToMeshHoles( 1 )
50 GHS3D_Parameters_edge = smesh.CreateHypothesis('GHS3D_Parameters', 'GHS3DEngine')
51 #GHS3D_Parameters_edge.SetToMeshHoles( 1 )
52 GHS3D_Parameters_face = smesh.CreateHypothesis('GHS3D_Parameters', 'GHS3DEngine')
53 GHS3D_Parameters_face.SetToMeshHoles( 1 ) # to mesh inside the cylinder
54 GHS3D_Parameters_mesh = smesh.CreateHypothesis('GHS3D_Parameters', 'GHS3DEngine')
55 GHS3D_Parameters_mesh.SetToMeshHoles( 1 ) # to mesh inside the cylinder
56
57 # Create the mesh on the cylinder
58 Mesh_cylindre = smesh.Mesh(cylindre)
59 smesh.SetName(Mesh_cylindre,"Mesh_cylindre")
60 Mesh_cylindre.AddHypothesis( BLSURF )
61 Mesh_cylindre.AddHypothesis( BLSURF_Parameters2 )
62 # Create some groups
63 face_cyl_faces = Mesh_cylindre.GroupOnGeom(face_cyl,'group_face_cyl', SMESH.FACE)
64 face_cyl_edges = Mesh_cylindre.GroupOnGeom(face_cyl,'group_edge_cyl', SMESH.EDGE)
65 face_cyl_nodes = Mesh_cylindre.GroupOnGeom(face_cyl,'group_node_cyl', SMESH.NODE)
66 Mesh_cylindre.Compute()
67
68 # Create the mesh on the cylinder
69 Mesh_box_tri = smesh.Mesh(box)
70 smesh.SetName(Mesh_box_tri,"Mesh_box_tri")
71 Mesh_box_tri.AddHypothesis( BLSURF )
72 Mesh_box_tri.AddHypothesis( BLSURF_Parameters )
73 Mesh_box_tri.Compute()
74
75 # Create 4 copies of the 2D mesh to test the 3 types of contraints (NODE, EDGE, FACE)
76 # from the whole mesh and from groups of elements.
77 # Then the 3D algo and hypothesis are assigned to them.
78
79 mesh_mesh = smesh.CopyMesh( Mesh_box_tri, 'Enforced by faces of mesh', 0, 0)
80 mesh_mesh.AddHypothesis( GHS3D )
81 mesh_mesh.AddHypothesis( GHS3D_Parameters_mesh)
82
83 mesh_node = smesh.CopyMesh( Mesh_box_tri, 'Enforced by group of nodes', 0, 0)
84 mesh_node.AddHypothesis( GHS3D )
85 mesh_node.AddHypothesis( GHS3D_Parameters_node)
86
87 mesh_edge = smesh.CopyMesh( Mesh_box_tri, 'Enforced by group of edges', 0, 0)
88 mesh_edge.AddHypothesis( GHS3D )
89 mesh_edge.AddHypothesis( GHS3D_Parameters_edge)
90
91 mesh_face = smesh.CopyMesh( Mesh_box_tri, 'Enforced by group of faces', 0, 0)
92 mesh_face.AddHypothesis( GHS3D )
93 mesh_face.AddHypothesis( GHS3D_Parameters_face)
94
95 # Add the enforced elements
96 GHS3D_Parameters_mesh.SetEnforcedMeshWithGroup(Mesh_cylindre.GetMesh(),SMESH.FACE,"faces from cylinder")
97 GHS3D_Parameters_node.SetEnforcedMeshWithGroup(face_cyl_nodes,SMESH.NODE,"nodes from face_cyl_nodes")
98 GHS3D_Parameters_edge.SetEnforcedMeshWithGroup(face_cyl_edges,SMESH.EDGE,"edges from face_cyl_edges")
99 GHS3D_Parameters_face.SetEnforcedMeshWithGroup(face_cyl_faces,SMESH.FACE,"faces from face_cyl_faces")
100
101 #Compute the meshes
102 mesh_node.Compute()
103 mesh_edge.Compute()
104 mesh_face.Compute()
105 mesh_mesh.Compute()
106
107 # End of script