Salome HOME
IPAL53073: Hexotic Mesh is not compute
[modules/smesh.git] / doc / salome / examples / 3dmesh.py
1 # 3d mesh generation
2
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8
9 import SMESH, SALOMEDS
10 from salome.smesh import smeshBuilder
11 smesh =  smeshBuilder.New(salome.myStudy)
12
13 ###
14 # Geometry: an assembly of a box, a cylinder and a truncated cone
15 # meshed with tetrahedral 
16 ###
17
18 # Define values
19 name = "ex21_lamp" 
20 cote = 60 
21 section = 20 
22 size = 200 
23 radius_1 = 80 
24 radius_2 = 40 
25 height = 100 
26
27 # Build a box
28 box = geompy.MakeBox(-cote, -cote, -cote, +cote, +cote, +cote) 
29
30 # Build a cylinder
31 pt1 = geompy.MakeVertex(0, 0, cote/3) 
32 di1 = geompy.MakeVectorDXDYDZ(0, 0, 1) 
33 cyl = geompy.MakeCylinder(pt1, di1, section, size) 
34
35 # Build a truncated cone
36 pt2 = geompy.MakeVertex(0, 0, size) 
37 cone = geompy.MakeCone(pt2, di1, radius_1, radius_2, height) 
38
39 # Fuse
40 box_cyl = geompy.MakeFuse(box, cyl) 
41 piece = geompy.MakeFuse(box_cyl, cone) 
42
43 # Add to the study
44 geompy.addToStudy(piece, name) 
45
46 # Create a group of faces
47 group = geompy.CreateGroup(piece, geompy.ShapeType["FACE"]) 
48 group_name = name + "_grp" 
49 geompy.addToStudy(group, group_name) 
50 group.SetName(group_name) 
51
52 # Add faces to the group
53 faces = geompy.SubShapeAllIDs(piece, geompy.ShapeType["FACE"]) 
54 geompy.UnionIDs(group, faces) 
55
56 ###
57 # Create a mesh
58 ###
59
60 # Define a mesh on a geometry
61 tetra = smesh.Mesh(piece, name) 
62
63 # Define 1D hypothesis
64 algo1d = tetra.Segment() 
65 algo1d.LocalLength(10) 
66
67 # Define 2D hypothesis
68 algo2d = tetra.Triangle() 
69 algo2d.LengthFromEdges() 
70
71 # Define 3D hypothesis
72 algo3d = tetra.Tetrahedron()
73 algo3d.MaxElementVolume(100) 
74
75 # Compute the mesh
76 tetra.Compute() 
77
78 # Create a groupe of faces
79 tetra.Group(group)