Salome HOME
Typo-fix by Kunda + fix user doc generation
[modules/smesh.git] / doc / salome / gui / SMESH / input / smeshpy_interface.rst
1 .. _smeshpy_interface_page:
2
3 ****************
4 Python interface
5 ****************
6
7 Python API of SALOME Mesh module defines several classes that can
8 be used for easy mesh creation and edition.
9
10 Documentation of SALOME Mesh module Python API is available in two forms:
11
12 - :doc:`Structured documentation <modules>`, where all methods and classes are grouped by their functionality.
13
14 - :ref:`Linear documentation <modindex>` grouped only by classes, declared in the :mod:`smeshBuilder` and :mod:`StdMeshersBuilder` Python packages.
15
16 With SALOME 7.2, the Python interface for Mesh has been slightly modified to offer new functionality.
17 You may have to modify your scripts generated with SALOME 6 or older versions.
18 Please see :ref:`smesh_migration_page`.
19
20 Class :class:`smeshBuilder.smeshBuilder` provides an interface to create and handle
21 meshes. It can be used to create an empty mesh or to import mesh from the data file.
22
23 As soon as a mesh is created, it is possible to manage it via its own
24 methods, described in class :class:`smeshBuilder.Mesh` documentation.
25
26 Class :class:`smeshstudytools.SMeshStudyTools` provides several methods to manipulate mesh objects in Salome study. 
27
28 A usual workflow to generate a mesh on geometry is following:
29
30 #. Create an instance of :class:`smeshBuilder.smeshBuilder`:
31         .. code-block:: python
32                 :linenos:
33
34                 from salome.smesh import smeshBuilder
35                 smesh = smeshBuilder.New()
36
37 #. Create a :class:`smeshBuilder.Mesh` object:
38
39         .. code-block:: python
40                 :linenos:
41
42                 mesh = smesh.Mesh( geometry )
43
44 #. Create and assign :ref:`algorithms <basic_meshing_algos_page>` by calling corresponding methods of the mesh. If a sub-shape is provided as an argument, a :ref:`sub-mesh <constructing_submeshes_page>` is implicitly created on this sub-shape:
45         .. code-block:: python
46                 :linenos:
47
48                 regular1D = mesh.Segment()
49                 mefisto   = mesh.Triangle( smeshBuilder.MEFISTO )
50                 # use other triangle algorithm on a face -- a sub-mesh appears in the mesh
51                 netgen    = mesh.Triangle( smeshBuilder.NETGEN_1D2D, face )
52
53 #. Create and assign :ref:`hypotheses <about_hypo_page>` by calling corresponding methods of algorithms:
54         .. code-block:: python
55                 :linenos:
56
57                 segLen10 = regular1D.LocalLength( 10. )
58                 maxArea  = mefisto.LocalLength( 100. )
59                 netgen.SetMaxSize( 20. )
60                 netgen.SetFineness( smeshBuilder.VeryCoarse )
61   
62 #. :ref:`compute_anchor` the mesh (generate mesh nodes and elements):
63         .. code-block:: python
64                 :linenos:
65
66                 mesh.Compute()
67
68 An easiest way to start with Python scripting is to do something in
69 GUI and then to get a corresponding Python script via 
70 **File > Dump Study** menu item. Don't forget that you can get
71 all methods of any object in hand (e.g. a mesh group or a hypothesis)
72 by calling *dir()* Python built-in function.
73
74 All methods of the Mesh Group can be found in :ref:`tui_create_standalone_group` sample script.
75
76 An example below demonstrates usage of the Python API for 3d mesh
77 generation and for retrieving information on mesh nodes and elements.
78
79 .. _example_3d_mesh:
80
81 Example of 3d mesh generation:
82 ##############################
83
84 .. literalinclude:: ../../../examples/3dmesh.py
85     :linenos:
86     :language: python
87
88 :download:`Download this script <../../../examples/3dmesh.py>`
89
90 Examples of Python scripts for Mesh operations are available by
91 the following links:
92
93 .. toctree::
94    :titlesonly:
95
96    tui_creating_meshes
97    tui_defining_hypotheses
98    tui_grouping_elements
99    tui_filters
100    tui_modifying_meshes
101    tui_transforming_meshes
102    tui_viewing_meshes
103    tui_quality_controls
104    tui_measurements
105    tui_work_on_objects_from_gui
106    tui_notebook_smesh
107    tui_cartesian_algo
108    tui_use_existing_faces
109    tui_prism_3d_algo
110    tui_generate_flat_elements
111
112 .. toctree::
113    :hidden:
114
115    smesh_migration.rst
116    smeshBuilder.rst
117    StdMeshersBuilder.rst
118    smeshstudytools.rst
119    modules.rst
120    smesh_module.rst