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