Salome HOME
Deleted Study parameter
[plugins/ghs3dplugin.git] / doc / salome / examples / ghs3d_enfmesh.py
1 # Copyright (C) 2007-2016  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 MG-Tetra 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()
35
36 import SMESH, SALOMEDS
37 from salome.smesh import smeshBuilder
38 smesh =  smeshBuilder.New()
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 MG_CADSurf = smesh.CreateHypothesis('MG-CADSurf', 'BLSURFEngine')
56 # For the box
57 MG_CADSurf_Parameters = smesh.CreateHypothesis('MG-CADSurf Parameters', 'BLSURFEngine')
58 MG_CADSurf_Parameters.SetPhysicalMesh( 1 )
59 MG_CADSurf_Parameters.SetPhySize( 200 )
60 # For the cylinder
61 MG_CADSurf_Parameters2 = smesh.CreateHypothesis('MG-CADSurf Parameters', 'BLSURFEngine')
62 MG_CADSurf_Parameters2.SetGeometricMesh( 1 )
63
64 # Create the 3D algorithm and hypothesis
65 MG_Tetra = smesh.CreateHypothesis('MG-Tetra', 'GHS3DEngine')
66 MG_Tetra_Parameters_node = smesh.CreateHypothesis('MG-Tetra Parameters', 'GHS3DEngine')
67 #MG_Tetra_Parameters_node.SetToMeshHoles( 1 )
68 MG_Tetra_Parameters_edge = smesh.CreateHypothesis('MG-Tetra Parameters', 'GHS3DEngine')
69 #MG_Tetra_Parameters_edge.SetToMeshHoles( 1 )
70 MG_Tetra_Parameters_face = smesh.CreateHypothesis('MG-Tetra Parameters', 'GHS3DEngine')
71 MG_Tetra_Parameters_face.SetToMeshHoles( 1 ) # to mesh inside the cylinder
72 MG_Tetra_Parameters_mesh = smesh.CreateHypothesis('MG-Tetra Parameters', 'GHS3DEngine')
73 MG_Tetra_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( MG_CADSurf )
79 Mesh_cylindre.AddHypothesis( MG_CADSurf_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,"Mesh_box_tri")
88 Mesh_box_tri.AddHypothesis( MG_CADSurf )
89 Mesh_box_tri.AddHypothesis( MG_CADSurf_Parameters )
90 Mesh_box_tri.Compute()
91
92 # Create 4 copies of the 2D mesh to test the 3 types of contraints (NODE, EDGE, FACE)
93 # from the whole mesh and from groups of elements.
94 # Then the 3D algo and hypothesis are assigned to them.
95
96 mesh_mesh = smesh.CopyMesh( Mesh_box_tri, 'Enforced by faces of mesh', 0, 0)
97 mesh_mesh.AddHypothesis( MG_Tetra )
98 mesh_mesh.AddHypothesis( MG_Tetra_Parameters_mesh)
99
100 mesh_node = smesh.CopyMesh( Mesh_box_tri, 'Enforced by group of nodes', 0, 0)
101 mesh_node.AddHypothesis( MG_Tetra )
102 mesh_node.AddHypothesis( MG_Tetra_Parameters_node)
103
104 mesh_edge = smesh.CopyMesh( Mesh_box_tri, 'Enforced by group of edges', 0, 0)
105 mesh_edge.AddHypothesis( MG_Tetra )
106 mesh_edge.AddHypothesis( MG_Tetra_Parameters_edge)
107
108 mesh_face = smesh.CopyMesh( Mesh_box_tri, 'Enforced by group of faces', 0, 0)
109 mesh_face.AddHypothesis( MG_Tetra )
110 mesh_face.AddHypothesis( MG_Tetra_Parameters_face)
111
112 # Add the enforced elements
113 MG_Tetra_Parameters_mesh.SetEnforcedMeshWithGroup(Mesh_cylindre.GetMesh(),SMESH.FACE,"faces from cylinder")
114 MG_Tetra_Parameters_node.SetEnforcedMeshWithGroup(face_cyl_nodes,SMESH.NODE,"nodes from face_cyl_nodes")
115 MG_Tetra_Parameters_edge.SetEnforcedMeshWithGroup(face_cyl_edges,SMESH.EDGE,"edges from face_cyl_edges")
116 MG_Tetra_Parameters_face.SetEnforcedMeshWithGroup(face_cyl_faces,SMESH.FACE,"faces from face_cyl_faces")
117
118 #Compute the meshes
119 mesh_node.Compute()
120 mesh_edge.Compute()
121 mesh_face.Compute()
122 mesh_mesh.Compute()
123
124 # End of script