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