Salome HOME
Merge from V5_1_3_BR branch (07/12/09)
[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 There are also some algorithms, which can be installed optionally,
40 some of them are based on open-source meshers:
41 - NETGEN (1D-2D, 2D, 1D-2D-3D, 3D)
42
43 ... and others are based on commercial meshers:
44 - GHS3D (3D)
45 - BLSURF (2D)
46
47 To add hypotheses, use the interfaces, provided by the assigned
48 algorithms.
49
50 Below you can see an example of usage of the package smesh for 3d mesh generation. 
51
52 \anchor example_3d_mesh
53 <h2>Example of 3d mesh generation with NETGEN:</h2>
54
55 \code
56 from geompy import * 
57 import smesh 
58
59 ###
60 # Geometry: an assembly of a box, a cylinder and a truncated cone
61 # meshed with tetrahedral 
62 ###
63
64 # Define values
65 name = "ex21_lamp" 
66 cote = 60 
67 section = 20 
68 size = 200 
69 radius_1 = 80 
70 radius_2 = 40 
71 height = 100 
72
73 # Build a box
74 box = MakeBox(-cote, -cote, -cote, +cote, +cote, +cote) 
75
76 # Build a cylinder
77 pt1 = MakeVertex(0, 0, cote/3) 
78 di1 = MakeVectorDXDYDZ(0, 0, 1) 
79 cyl = MakeCylinder(pt1, di1, section, size) 
80
81 # Build a truncated cone
82 pt2 = MakeVertex(0, 0, size) 
83 cone = MakeCone(pt2, di1, radius_1, radius_2, height) 
84
85 # Fuse
86 box_cyl = MakeFuse(box, cyl) 
87 piece = MakeFuse(box_cyl, cone) 
88
89 # Add to the study
90 addToStudy(piece, name) 
91
92 # Create a group of faces
93 group = CreateGroup(piece, ShapeType["FACE"]) 
94 group_name = name + "_grp" 
95 addToStudy(group, group_name) 
96 group.SetName(group_name) 
97
98 # Add faces to the group
99 faces = SubShapeAllIDs(piece, ShapeType["FACE"]) 
100 UnionIDs(group, faces) 
101
102 ###
103 # Create a mesh
104 ###
105
106 # Define a mesh on a geometry
107 tetra = smesh.Mesh(piece, name) 
108
109 # Define 1D hypothesis
110 algo1d = tetra.Segment() 
111 algo1d.LocalLength(10) 
112
113 # Define 2D hypothesis
114 algo2d = tetra.Triangle() 
115 algo2d.LengthFromEdges() 
116
117 # Define 3D hypothesis
118 algo3d = tetra.Tetrahedron(smesh.NETGEN) 
119 algo3d.MaxElementVolume(100) 
120
121 # Compute the mesh
122 tetra.Compute() 
123
124 # Create a groupe of faces
125 tetra.Group(group)
126
127 \endcode
128
129 Examples of Python scripts for all Mesh operations are available by
130 the following links:
131
132 - \subpage tui_creating_meshes_page
133 - \subpage tui_viewing_meshes_page
134 - \subpage tui_defining_hypotheses_page
135 - \subpage tui_quality_controls_page
136 - \subpage tui_grouping_elements_page
137 - \subpage tui_modifying_meshes_page
138 - \subpage tui_transforming_meshes_page
139 - \subpage tui_notebook_smesh_page
140
141 */