2017-12-08 19:09:48 +05:00
.. _smeshpy_interface_page:
***** ***** ***** *
Python interface
***** ***** ***** *
Python API of SALOME Mesh module defines several classes that can
be used for easy mesh creation and edition.
2018-05-25 22:04:48 +05:00
Documentation of SALOME Mesh module Python API is available in two forms:
2017-12-08 19:09:48 +05:00
2018-05-25 22:04:48 +05:00
- :doc: `Structured documentation <modules>` , where all methods and classes are grouped by their functionality.
2017-12-08 19:09:48 +05:00
2018-06-29 18:38:39 +05:00
- :ref: `Linear documentation <modindex>` grouped only by classes, declared in the :mod: `smeshBuilder` Python module.
2017-12-08 19:09:48 +05:00
With SALOME 7.2, the Python interface for Mesh has been slightly modified to offer new functionality.
You may have to modify your scripts generated with SALOME 6 or older versions.
Please see :ref: `smesh_migration_page` .
Class :class: `smeshBuilder.smeshBuilder` provides an interface to create and handle
meshes. It can be used to create an empty mesh or to import mesh from the data file.
As soon as a mesh is created, it is possible to manage it via its own
methods, described in class :class: `smeshBuilder.Mesh` documentation.
2021-03-22 17:02:50 +05:00
Class :class: `smeshstudytools.SMeshStudyTools` provides several methods to manipulate mesh objects in Salome study.
2017-12-08 19:09:48 +05:00
A usual workflow to generate a mesh on geometry is following:
#. Create an instance of :class: `smeshBuilder.smeshBuilder` :
.. code-block:: python
from salome.smesh import smeshBuilder
2018-06-19 21:58:29 +05:00
smesh = smeshBuilder.New()
2017-12-08 19:09:48 +05:00
#. Create a :class: `smeshBuilder.Mesh` object:
.. code-block:: python
mesh = smesh.Mesh( geometry )
2018-05-25 22:04:48 +05:00
#. 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:
2017-12-08 19:09:48 +05:00
.. code-block:: python
2022-04-15 20:49:22 +05:00
regular1D = mesh.Segment()
quadrangle = mesh.Quadrangle()
# use other 2D algorithm on a face -- a sub-mesh appears in the mesh
triangle = mesh.Triangle( face )
2017-12-08 19:09:48 +05:00
2018-05-25 22:04:48 +05:00
#. Create and assign :ref: `hypotheses <about_hypo_page>` by calling corresponding methods of algorithms:
2017-12-08 19:09:48 +05:00
.. code-block:: python
2022-04-15 20:49:22 +05:00
regular1D.LocalLength( 10. )
quadrangle.Reduced()
triangle.SetMaxSize( 20. )
triangle.SetFineness( smeshBuilder.VeryCoarse )
2021-03-22 17:02:50 +05:00
2019-03-06 18:59:54 +05:00
#. :ref: `Compute the mesh <compute_anchor>` (generate mesh nodes and elements):
2017-12-08 19:09:48 +05:00
.. code-block:: python
2018-05-25 22:04:48 +05:00
mesh.Compute()
2017-12-08 19:09:48 +05:00
An easiest way to start with Python scripting is to do something in
2021-03-22 17:02:50 +05:00
GUI and then to get a corresponding Python script via
2017-12-08 19:09:48 +05:00
**File > Dump Study** menu item. Don't forget that you can get
all methods of any object in hand (e.g. a mesh group or a hypothesis)
by calling *dir()* Python built-in function.
2019-03-06 18:59:54 +05:00
All methods of the :class: `Mesh Group <SMESH.SMESH_GroupBase>` can be found in :ref: `tui_create_standalone_group` sample script.
2017-12-08 19:09:48 +05:00
2018-06-29 18:38:39 +05:00
An example below demonstrates usage of the Python API for 3D mesh
2019-03-06 18:59:54 +05:00
generation and for retrieving basic information on mesh nodes, elements and groups.
2017-12-08 19:09:48 +05:00
.. _example_3d_mesh:
Example of 3d mesh generation:
##############################
2022-04-11 18:28:01 +05:00
.. literalinclude :: ../../examples/mesh_3d.py
2017-12-08 19:09:48 +05:00
:language: python
2022-04-11 18:28:01 +05:00
:download: `Download this script <../../examples/mesh_3d.py>`
2017-12-08 19:09:48 +05:00
Examples of Python scripts for Mesh operations are available by
the following links:
.. toctree ::
2018-05-25 22:04:48 +05:00
:titlesonly:
tui_creating_meshes
tui_defining_hypotheses
tui_grouping_elements
tui_filters
tui_modifying_meshes
tui_transforming_meshes
tui_viewing_meshes
tui_quality_controls
2021-03-22 17:02:50 +05:00
tui_adaptation
2018-05-25 22:04:48 +05:00
tui_measurements
tui_work_on_objects_from_gui
tui_notebook_smesh
2017-12-08 19:09:48 +05:00
2018-05-25 22:04:48 +05:00
.. toctree ::
:hidden:
smesh_migration.rst
smeshBuilder.rst
StdMeshersBuilder.rst
smeshstudytools.rst
modules.rst
smesh_module.rst