Salome HOME
e725ef99cf237c4d8d012ac6cd3f0752efb768f4
[modules/smesh.git] / doc / salome / gui / SMESH / input / smeshpy_interface.doc
1 /*!
2
3 \page smeshpy_interface_page Python interface
4
5 Python package smesh defines several classes, destined for easy and
6 clear mesh creation and edition.
7
8 Documentation for smesh package is available in two forms:
9
10 The <a href="smeshpy_doc/modules.html"> structured
11 documentation for smesh package</a>, where all methods and
12 classes are grouped by their functionality, like it is done in the GUI documentation
13 and the \ref smeshDC "linear documentation for smesh package"
14 grouped only by classes, declared in the smesh.py file.
15
16 The main page of the \ref smeshDC "linear documentation for smesh package"
17 contains a list of data structures and a list of
18 functions, provided by the package smesh.py. The first item in
19 the list of data structures (\ref smeshDC::smeshDC "class smesh")
20 also represents documentation for the methods of the package smesh.py itself.
21
22 The package smesh.py provides an interface to create and handle
23 meshes. Use it to create an empty mesh or to import it from the data file.
24
25 Once a mesh has been created, it is possible to  manage it via its own
26 methods, described at \ref smeshDC::Mesh "class Mesh" documentation
27 (it is also accessible by the second item "class Mesh" in the list of data structures).
28
29 Class \b Mesh allows assigning algorithms to a mesh.
30 Please note, that some algorithms, included in the standard SALOME
31 distribution are always available:
32 - REGULAR (1D)
33 - COMPOSITE (1D)
34 - MEFISTO (2D)
35 - Quadrangle (2D)
36 - Hexa(3D)
37 - etc...
38
39 To add hypotheses, use the interfaces, provided by the assigned
40 algorithms.
41
42 Below you can see an example of usage of the package smesh for 3d mesh generation. 
43
44 \anchor example_3d_mesh
45 <h2>Example of 3d mesh generation:</h2>
46
47 \code
48 from geompy import * 
49 import smesh 
50
51 ###
52 # Geometry: an assembly of a box, a cylinder and a truncated cone
53 # meshed with tetrahedral 
54 ###
55
56 # Define values
57 name = "ex21_lamp" 
58 cote = 60 
59 section = 20 
60 size = 200 
61 radius_1 = 80 
62 radius_2 = 40 
63 height = 100 
64
65 # Build a box
66 box = MakeBox(-cote, -cote, -cote, +cote, +cote, +cote) 
67
68 # Build a cylinder
69 pt1 = MakeVertex(0, 0, cote/3) 
70 di1 = MakeVectorDXDYDZ(0, 0, 1) 
71 cyl = MakeCylinder(pt1, di1, section, size) 
72
73 # Build a truncated cone
74 pt2 = MakeVertex(0, 0, size) 
75 cone = MakeCone(pt2, di1, radius_1, radius_2, height) 
76
77 # Fuse
78 box_cyl = MakeFuse(box, cyl) 
79 piece = MakeFuse(box_cyl, cone) 
80
81 # Add to the study
82 addToStudy(piece, name) 
83
84 # Create a group of faces
85 group = CreateGroup(piece, ShapeType["FACE"]) 
86 group_name = name + "_grp" 
87 addToStudy(group, group_name) 
88 group.SetName(group_name) 
89
90 # Add faces to the group
91 faces = SubShapeAllIDs(piece, ShapeType["FACE"]) 
92 UnionIDs(group, faces) 
93
94 ###
95 # Create a mesh
96 ###
97
98 # Define a mesh on a geometry
99 tetra = smesh.Mesh(piece, name) 
100
101 # Define 1D hypothesis
102 algo1d = tetra.Segment() 
103 algo1d.LocalLength(10) 
104
105 # Define 2D hypothesis
106 algo2d = tetra.Triangle() 
107 algo2d.LengthFromEdges() 
108
109 # Define 3D hypothesis
110 algo3d = tetra.Tetrahedron()
111 algo3d.MaxElementVolume(100) 
112
113 # Compute the mesh
114 tetra.Compute() 
115
116 # Create a groupe of faces
117 tetra.Group(group)
118
119 \endcode
120
121 Examples of Python scripts for all Mesh operations are available by
122 the following links:
123
124 - \subpage tui_creating_meshes_page
125 - \subpage tui_cartesian_algo
126 - \subpage tui_viewing_meshes_page
127 - \subpage tui_defining_hypotheses_page
128 - \subpage tui_quality_controls_page
129 - \subpage tui_filters_page
130 - \subpage tui_grouping_elements_page
131 - \subpage tui_modifying_meshes_page
132 - \subpage tui_transforming_meshes_page
133 - \subpage tui_notebook_smesh_page
134 - \subpage tui_measurements_page
135 - \subpage tui_generate_flat_elements_page
136 - \subpage tui_work_on_objects_from_gui
137
138 */