Salome HOME
Update copyrights 2014.
[plugins/ghs3dplugin.git] / doc / salome / examples / ghs3d_enfmesh.py
1 # Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 # It is possible to constrain GHS3D with another mesh or group.
21 # The constraint can refer to the nodes, edges or faces.
22 # This feature is available only on 2D meshes without geometry.
23 # The constraining elements are called enforced elements for the mesh.
24 # They can be recovered using groups if necessary.
25
26 # In the following examples, a box and a cylinder are meshed in 2D.
27 # The mesh of the cylinder will be used as a constraint for the 
28 # 3D mesh of the box.
29
30 import salome
31 salome.salome_init()
32 import GEOM
33 from salome.geom import geomBuilder
34 geompy = geomBuilder.New(salome.myStudy)
35
36 import SMESH, SALOMEDS
37 from salome.smesh import smeshBuilder
38 smesh =  smeshBuilder.New(salome.myStudy)
39
40 box = geompy.MakeBoxDXDYDZ(200, 200, 200)
41 geompy.addToStudy( box, "box" )
42 cylindre = geompy.MakeCylinderRH(50, 50)
43 geompy.TranslateDXDYDZ(cylindre, 100, 100, 30)
44 face_cyl = geompy.ExtractShapes(cylindre, geompy.ShapeType["FACE"], True)[1]
45 geompy.addToStudy( cylindre, 'cylindre' )
46 geompy.addToStudyInFather( cylindre, face_cyl, 'face_cyl' )
47 p1 = geompy.MakeVertex(20, 20, 20)
48 p2 = geompy.MakeVertex(180, 180, 20)
49 c = geompy.MakeCompound([p1,p2])
50 geompy.addToStudy( p1, "p1" )
51 geompy.addToStudy( p2, "p2" )
52 geompy.addToStudy( c, "c" )
53
54 # Create the 2D algorithm and hypothesis
55 BLSURF = smesh.CreateHypothesis('BLSURF', 'BLSURFEngine')
56 # For the box
57 BLSURF_Parameters = smesh.CreateHypothesis('BLSURF_Parameters', 'BLSURFEngine')
58 BLSURF_Parameters.SetPhysicalMesh( 1 )
59 BLSURF_Parameters.SetPhySize( 200 )
60 # For the cylinder
61 BLSURF_Parameters2 = smesh.CreateHypothesis('BLSURF_Parameters', 'BLSURFEngine')
62 BLSURF_Parameters2.SetGeometricMesh( 1 )
63
64 # Create the 3D algorithm and hypothesis
65 GHS3D = smesh.CreateHypothesis('GHS3D_3D', 'GHS3DEngine')
66 GHS3D_Parameters_node = smesh.CreateHypothesis('GHS3D_Parameters', 'GHS3DEngine')
67 #GHS3D_Parameters_node.SetToMeshHoles( 1 )
68 GHS3D_Parameters_edge = smesh.CreateHypothesis('GHS3D_Parameters', 'GHS3DEngine')
69 #GHS3D_Parameters_edge.SetToMeshHoles( 1 )
70 GHS3D_Parameters_face = smesh.CreateHypothesis('GHS3D_Parameters', 'GHS3DEngine')
71 GHS3D_Parameters_face.SetToMeshHoles( 1 ) # to mesh inside the cylinder
72 GHS3D_Parameters_mesh = smesh.CreateHypothesis('GHS3D_Parameters', 'GHS3DEngine')
73 GHS3D_Parameters_mesh.SetToMeshHoles( 1 ) # to mesh inside the cylinder
74
75 # Create the mesh on the cylinder
76 Mesh_cylindre = smesh.Mesh(cylindre)
77 smesh.SetName(Mesh_cylindre,"Mesh_cylindre")
78 Mesh_cylindre.AddHypothesis( BLSURF )
79 Mesh_cylindre.AddHypothesis( BLSURF_Parameters2 )
80 # Create some groups
81 face_cyl_faces = Mesh_cylindre.GroupOnGeom(face_cyl,'group_face_cyl', SMESH.FACE)
82 face_cyl_edges = Mesh_cylindre.GroupOnGeom(face_cyl,'group_edge_cyl', SMESH.EDGE)
83 face_cyl_nodes = Mesh_cylindre.GroupOnGeom(face_cyl,'group_node_cyl', SMESH.NODE)
84 Mesh_cylindre.Compute()
85
86 # Create the mesh on the cylinder
87 Mesh_box_tri = smesh.Mesh(box)
88 smesh.SetName(Mesh_box_tri,"Mesh_box_tri")
89 Mesh_box_tri.AddHypothesis( BLSURF )
90 Mesh_box_tri.AddHypothesis( BLSURF_Parameters )
91 Mesh_box_tri.Compute()
92
93 # Create 4 copies of the 2D mesh to test the 3 types of contraints (NODE, EDGE, FACE)
94 # from the whole mesh and from groups of elements.
95 # Then the 3D algo and hypothesis are assigned to them.
96
97 mesh_mesh = smesh.CopyMesh( Mesh_box_tri, 'Enforced by faces of mesh', 0, 0)
98 mesh_mesh.AddHypothesis( GHS3D )
99 mesh_mesh.AddHypothesis( GHS3D_Parameters_mesh)
100
101 mesh_node = smesh.CopyMesh( Mesh_box_tri, 'Enforced by group of nodes', 0, 0)
102 mesh_node.AddHypothesis( GHS3D )
103 mesh_node.AddHypothesis( GHS3D_Parameters_node)
104
105 mesh_edge = smesh.CopyMesh( Mesh_box_tri, 'Enforced by group of edges', 0, 0)
106 mesh_edge.AddHypothesis( GHS3D )
107 mesh_edge.AddHypothesis( GHS3D_Parameters_edge)
108
109 mesh_face = smesh.CopyMesh( Mesh_box_tri, 'Enforced by group of faces', 0, 0)
110 mesh_face.AddHypothesis( GHS3D )
111 mesh_face.AddHypothesis( GHS3D_Parameters_face)
112
113 # Add the enforced elements
114 GHS3D_Parameters_mesh.SetEnforcedMeshWithGroup(Mesh_cylindre.GetMesh(),SMESH.FACE,"faces from cylinder")
115 GHS3D_Parameters_node.SetEnforcedMeshWithGroup(face_cyl_nodes,SMESH.NODE,"nodes from face_cyl_nodes")
116 GHS3D_Parameters_edge.SetEnforcedMeshWithGroup(face_cyl_edges,SMESH.EDGE,"edges from face_cyl_edges")
117 GHS3D_Parameters_face.SetEnforcedMeshWithGroup(face_cyl_faces,SMESH.FACE,"faces from face_cyl_faces")
118
119 #Compute the meshes
120 mesh_node.Compute()
121 mesh_edge.Compute()
122 mesh_face.Compute()
123 mesh_mesh.Compute()
124
125 # End of script