Salome HOME
Merge from V6_3_BR 06/06/2011
[modules/smesh.git] / doc / salome / gui / SMESH / input / tui_defining_ghs3d_hypotheses.doc
1 /*!
2
3 \page tui_defining_ghs3d_hypotheses_page Defining Hypotheses for Ghs3D Algorithm
4
5 \anchor tui_ghs3d
6 <h2>Construction of Mesh using Ghs3D algorithm</h2>
7
8 \code
9 import geompy
10 import smesh
11 import BLSURFPlugin
12 import GHS3DPlugin
13
14 # create a box
15 box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
16 geompy.addToStudy(box, "box")
17
18 # create a mesh on the box
19 ghs3dMesh = smesh.Mesh(box,"box: Ghs3D and BLSurf mesh")
20
21 # create a BLSurf algorithm for faces
22 BLSURF = ghs3dMesh.Triangle(algo=smesh.BLSURF)
23 GHS3D = ghs3dMesh.Tetrahedron(algo=smesh.GHS3D)
24
25 # compute the mesh
26 ghs3dMesh.Compute()
27
28 # End of script
29 \endcode
30
31 \image html ghs3d_screenshot.png Ghs3d mesh withtout hypothesis
32
33 <h2>Adding enforced vertices</h2>
34
35 \code
36
37 # An enforced vertex can be added via:
38 # - the coordinates x,y,z
39 # - a GEOM vertex or compound (No geometry, TUI only)
40 #
41 # The enforced nodes created can also be stored in
42 # a group (No geometry, TUI only).
43
44 # Ex1: Add 1 enforced vertices by coords at (50,50,100) 
45 #      with a physical size of 2
46
47 import geompy
48 import smesh
49 import BLSURFPlugin
50 import GHS3DPlugin
51
52 # create a box
53 box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
54 geompy.addToStudy(box, "box")
55 # create a mesh on the box
56 ghs3dMesh = smesh.Mesh(box,"box: Ghs3D and BLSurf mesh")
57 # create a BLSurf algorithm for faces
58 ghs3dMesh.Triangle(algo=smesh.BLSURF)
59 # compute the mesh
60 ghs3dMesh.Compute()
61
62 # Make a copy of the 2D mesh
63 ghs3dMesh_wo_geometry = smesh.CopyMesh( ghs3dMesh, 'Ghs3D wo geometry', 0, 0)
64
65 # create a Ghs3D algorithm and hypothesis and assign them to the mesh
66 GHS3D = smesh.CreateHypothesis('GHS3D_3D', 'GHS3DEngine')
67 GHS3D_Parameters = smesh.CreateHypothesis('GHS3D_Parameters', 'GHS3DEngine')
68 ghs3dMesh.AddHypothesis( GHS3D )
69 ghs3dMesh.AddHypothesis( GHS3D_Parameters )
70 # Create the enforced vertex
71 GHS3D_Parameters.SetEnforcedVertex( 50, 50, 100, 2) # no group
72 # Compute the mesh
73 ghs3dMesh.Compute()
74
75
76 # Ex2: Add 1 enforced vertices by GEOM vertex at (50,50,100) 
77 #      with a physical size of 5 and add it to a group called "My special nodes"
78
79 # Create another GHS3D hypothesis and assign it to the mesh wo geometry
80 GHS3D_Parameters_wo_geometry = smesh.CreateHypothesis('GHS3D_Parameters', 'GHS3DEngine')
81 ghs3dMesh_wo_geometry.AddHypothesis( GHS3D )
82 ghs3dMesh_wo_geometry.AddHypothesis( GHS3D_Parameters_wo_geometry )
83
84 # Create the enforced vertex
85 p1 = geompy.MakeVertex(150, 150, 100)
86 geompy.addToStudy(p1, "p1")
87 GHS3D_Parameters_wo_geometry.SetEnforcedVertexGeomWithGroup( p1, 5 , "My special nodes")
88 #GHS3D_Parameters.SetEnforcedVertexGeom( p1, 5 ) # no group
89
90 # compute the mesh
91 ghs3dMesh_wo_geometry.Compute()
92
93 # Erase all enforced vertices
94 GHS3D_Parameters.ClearEnforcedVertices()
95
96 # End of script
97
98 \endcode
99
100 \image html ghs3d_screenshot_enf1.png Ghs3d mesh with enforced vertex
101 \image html ghs3d_screenshot_enf2.png Ghs3d mesh with enforced vertex from GEOM vertex
102
103 <h2>Adding enforced mesh</h2>
104
105 \code
106
107 # It is possible to constraint GHS3D with another mesh or group.
108 # The constraint can be the nodes, edges or faces.
109 # This feature is available only in TUI, on meshes without geometry.
110 # The constraining elements are called enforced elements for the mesh.
111 # They can be recovered using groups if necessary.
112
113 # In the following examples, a box and a cylinder are meshed.
114 # The mesh of the cylinder will be used as a constraint for the 
115 # 3D mesh of the box.
116
117 import geompy
118 import smesh
119 import BLSURFPlugin
120 import GHS3DPlugin
121
122 box = geompy.MakeBoxDXDYDZ(200, 200, 200)
123 geompy.addToStudy( box, "box" )
124 cylindre = geompy.MakeCylinderRH(50, 50)
125 geompy.TranslateDXDYDZ(cylindre, 100, 100, 30)
126 face_cyl = geompy.ExtractShapes(cylindre, geompy.ShapeType["FACE"], True)[1]
127 geompy.addToStudy( cylindre, 'cylindre' )
128 geompy.addToStudyInFather( cylindre, face_cyl, 'face_cyl' )
129 p1 = geompy.MakeVertex(20, 20, 20)
130 p2 = geompy.MakeVertex(180, 180, 20)
131 c = geompy.MakeCompound([p1,p2])
132 geompy.addToStudy( p1, "p1" )
133 geompy.addToStudy( p2, "p2" )
134 geompy.addToStudy( c, "c" )
135
136 # Create the 2D algo and hypothesis
137 BLSURF = smesh.CreateHypothesis('BLSURF', 'BLSURFEngine')
138 # For the box
139 BLSURF_Parameters = smesh.CreateHypothesis('BLSURF_Parameters', 'BLSURFEngine')
140 BLSURF_Parameters.SetPhysicalMesh( 1 )
141 BLSURF_Parameters.SetPhySize( 200 )
142 # For the cylinder
143 BLSURF_Parameters2 = smesh.CreateHypothesis('BLSURF_Parameters', 'BLSURFEngine')
144 BLSURF_Parameters2.SetGeometricMesh( 1 )
145
146 # Create the 3D algo and hypothesis
147 GHS3D = smesh.CreateHypothesis('GHS3D_3D', 'GHS3DEngine')
148 GHS3D_Parameters_node = smesh.CreateHypothesis('GHS3D_Parameters', 'GHS3DEngine')
149 #GHS3D_Parameters_node.SetToMeshHoles( 1 )
150 GHS3D_Parameters_edge = smesh.CreateHypothesis('GHS3D_Parameters', 'GHS3DEngine')
151 #GHS3D_Parameters_edge.SetToMeshHoles( 1 )
152 GHS3D_Parameters_face = smesh.CreateHypothesis('GHS3D_Parameters', 'GHS3DEngine')
153 GHS3D_Parameters_face.SetToMeshHoles( 1 ) # to mesh inside the cylinder
154 GHS3D_Parameters_mesh = smesh.CreateHypothesis('GHS3D_Parameters', 'GHS3DEngine')
155 GHS3D_Parameters_mesh.SetToMeshHoles( 1 ) # to mesh inside the cylinder
156
157 # Create the mesh on the cylinder
158 Mesh_cylindre = smesh.Mesh(cylindre)
159 SetName(Mesh_cylindre,"Mesh_cylindre")
160 Mesh_cylindre.AddHypothesis( BLSURF )
161 Mesh_cylindre.AddHypothesis( BLSURF_Parameters2 )
162 # Create some groups
163 face_cyl_faces = Mesh_cylindre.GroupOnGeom(face_cyl,'group_face_cyl', smesh.FACE)
164 face_cyl_edges = Mesh_cylindre.GroupOnGeom(face_cyl,'group_edge_cyl', smesh.EDGE)
165 face_cyl_nodes = Mesh_cylindre.GroupOnGeom(face_cyl,'group_node_cyl', smesh.NODE)
166 Mesh_cyl_tri.Compute()
167
168 # Create the mesh on the cylinder
169 Mesh_box_tri = smesh.Mesh(box)
170 SetName(Mesh_box_tri,"Mesh_box_tri")
171 Mesh_box_tri.AddHypothesis( BLSURF )
172 Mesh_box_tri.AddHypothesis( BLSURF_Parameters )
173 Mesh_box_tri.Compute()
174
175 # Create 4 copies of the 2D mesh to test the 3 types of contraints (NODE, EDGE, FACE)
176 # from a whole mesh and from groups of elements.
177 # Then the 3D algo and hypothesis are assigned to them.
178
179 mesh_mesh = smesh.CopyMesh( Mesh_box_tri, 'Enforced by faces of mesh', 0, 0)
180 mesh_mesh.AddHypothesis( GHS3D_3D )
181 mesh_mesh.AddHypothesis( GHS3D_Parameters_mesh)
182
183 mesh_node = smesh.CopyMesh( Mesh_box_tri, 'Enforced by group of nodes', 0, 0)
184 mesh_node.AddHypothesis( GHS3D_3D )
185 mesh_node.AddHypothesis( GHS3D_Parameters_node)
186
187 mesh_edge = smesh.CopyMesh( Mesh_box_tri, 'Enforced by group of edges', 0, 0)
188 mesh_edge.AddHypothesis( GHS3D_3D )
189 mesh_edge.AddHypothesis( GHS3D_Parameters_edge)
190
191 mesh_face = smesh.CopyMesh( Mesh_box_tri, 'Enforced by group of faces', 0, 0)
192 mesh_face.AddHypothesis( GHS3D_3D )
193 mesh_face.AddHypothesis( GHS3D_Parameters_face)
194
195 # Add the enforced elements
196 GHS3D_Parameters_mesh.SetEnforcedMeshWithGroup(Mesh_cylindre.GetMesh(),smesh.FACE,"faces from cylinder")
197 GHS3D_Parameters_node.SetEnforcedMeshWithGroup(face_cyl_nodes,smesh.NODE,"nodes from face_cyl_nodes")
198 GHS3D_Parameters_edge.SetEnforcedMeshWithGroup(face_cyl_edges,smesh.EDGE,"edges from face_cyl_edges")
199 GHS3D_Parameters_face.SetEnforcedMeshWithGroup(face_cyl_faces,smesh.FACE,"faces from face_cyl_faces")
200
201 #Compute the meshes
202 mesh_node.Compute()
203 mesh_edge.Compute()
204 mesh_face.Compute()
205 mesh_mesh.Compute()
206
207 # End of script
208
209 \endcode
210
211 \image html ghs3d_screenshot_enf3.png
212 \image html ghs3d_screenshot_enf4.png
213 \image html ghs3d_screenshot_enf5.png
214 \image html ghs3d_screenshot_enf6.png
215
216 */