From CAELinuxWiki
Jump to: navigation, search

Topic under construction

Creating Mesh Groups Using a TUI

Why use a TUI?

Salome node and element grouping methods using the GUI (Graphical User Interface) are good but inadequate for many situations. Here we will show some rapid ways to group nodes or elements using Python scripts (TUI - Text User Interface) that are much faster (10 times or more) and more flexible compared to using the GUI methods. In fact there are situations where a GUI method has failed for medium to large sized meshes because Salome goes into a severe disk thrashing mode resulting in a locked up PC, to be relieved only by a reboot! In such cases learning to use the TUI method can be the difference between going to bed and hoping the grouping will be done along with the sun rising, or waiting for a few minutes for the TUI script to do its work. The difference is that significant, as experienced by the author.

Grouping nodes on a planar face:

In a part it is easier to define mesh groups by planes than by faces (imported from geompy) if the nodes (or elements) you want to group lie on defined planes. For this one can use the SMESH.Filter.Criterion function. In order to understand how this function works we need to know its parameters which are listed later in this tutorial.

To demonstrate creating groups using a TUI in action, let us import a simple quadrangle meshed cube (100 mm3) and select all the elements belonging to the XY plane that are at z=100 mm using the following Python script. The process of creating this meshed cube is left to the reader.

import salome,geompy,smesh, SMESH
([Box], status) = smesh.CreateMeshesFromMED('/home/.../')
PT = geompy.MakeVertex(0, 0, 100)
Z_Axis = geompy.MakeVectorDXDYDZ(0, 0, 1)
SelectionPlane = geompy.MakePlane(PT, Z_Axis, 2000)
# Get all Elements touching the plane at Z= 100
aCriterion = SMESH.Filter.Criterion(20,32,0,'SelectionPlane',,32,32,1e-06,SMESH.VOLUME,-1)
If you want to select all the elements belonging to a sphere of radius 40 mm the additional lines below should do it:
Ball = geompy.MakeSphereR(40)
aCriterion = SMESH.Filter.Criterion(20,32,0,'Ball',,32,32,1e-06,SMESH.VOLUME,-1)

You can download the mesh here:

Logical filter 'AND'

Next we have the relevant portion of a python script that uses the logical 'AND' operation in the filter, using both the plane and sphere selection criteria:

aFilterManager = smesh.CreateFilterManager()
Filter = aFilterManager.CreateFilter()
aCriteria = []
aCriterion = SMESH.Filter.Criterion(20,32,0,'SelectionPlane','SelectionPlane',32,30,1e-07,SMESH.VOLUME,-1)
LyingOnSelectionPlane = aFilterManager.CreateLyingOnGeom()
aCriterion = SMESH.Filter.Criterion(20,32,0,'Ball','Ball',32,32,1e-07,SMESH.VOLUME,-1)
LyingOnBall = aFilterManager.CreateLyingOnGeom()
LogicalAND = aFilterManager.CreateLogicalAND()

The Group

A display of the resulting group 'andGRP' is shown here LogicalAND.png

Note: Screenshot shows the result of a TUI based group creation using a filter with a logical 'AND selection criteria over which are superimposed the two windows showing how one would have normally done it with a GUI.

Some background information

The SMESH.Filter.Criterion function. In order to understand how this function works we need to know its parameters which are listed below:

Criterion:             17      - BelongToPlane
Compare:               32      - EqualTo (or MoreThan, or LessThan)
Unknown:               0       - Unknown
ThresholdValue:                - The name of the geometric entity or criterion ('TopPl')
Name of Geom:                  - The name of the geometric entity (again?)
Unary:                 32      - Blank; 29 - Not
Binary:                32      - Blank; 30 - And; 31 - Or
Tolerance:             1e-07   - Geometrical tolerance zone for selecting entities
MeshEntity:            SMESH.[NODE/EDGE/FACE/VOLUME]

The above represents for example a command that could be used for selecting (SMESH.FACE) face elements that '17=BelongToPlane' that lie within a selection tolerance zone of 1e-07 units as coded for Salome in Python as:

aCriterion = SMESH.Filter.Criterion(17,32,0,'TopPl',,32,32,1e-07,SMESH.FACE,-1)

Note 1) After 'TopPl' there are two single quotes (') with no space between them NOT a single double quote(“)! 2) The list for criterion from the source code SMESH_Filter.idl (complete list at: /opt/salome_5.1.4/SMESH_5.1.4/idl/salome/SMESH_Filter.idl or is shown below with numbers corresponding to the criterion so you can substitute the appropriate number for the filter you want to create:

enum FunctorType	
0	     FT_AspectRatio,	
1	     FT_AspectRatio3D,	
2	     FT_Warping,	
3	     FT_MinimumAngle,	
4	     FT_Taper,	
5	     FT_Skew,	
6	     FT_Area,	
7	     FT_Volume3D,	
8	     FT_FreeBorders,	
9	     FT_FreeEdges,	
10	     FT_FreeNodes,	
11	     FT_FreeFaces,	
12	     FT_MultiConnection,	
13	     FT_MultiConnection2D,	
14	     FT_Length,	
15	     FT_Length2D,	
16	     FT_BelongToGeom,	
17	     FT_BelongToPlane,	
18	     FT_BelongToCylinder,	
19	     FT_BelongToGenSurface,	
20	     FT_LyingOnGeom,	
21	     FT_RangeOfIds,	
22	     FT_BadOrientedVolume,	
23	     FT_LinearOrQuadratic,	
24	     FT_GroupColor,	
25	     FT_ElemGeomType,	
26	     FT_LessThan,	
27	     FT_MoreThan,	
28	     FT_EqualTo,	
29	     FT_LogicalNOT,	
30	     FT_LogicalAND,	
31	     FT_LogicalOR,	
32	     FT_Undefined	

General note: Here is how to get more information about something in Salome: Suppose you want information about the meaning and other options for the inputs (e.g. 16=SMESH.FT_BelongToGeom) In the Salome Python Console type:


(It will list all the classes & functions available in SMESH). Then type:


and you will get 'SMESH_Filter.idl' as seen from the output:


(Not in a pretty format as shown above but the lines are demarcated by '\n' which can be removed by pasting the output into gedit and using 'Find and Replace' to put actual 'LineFeed' characters to get the neat display above.) From this you can learn that one should perhaps look in the 'SMESH_Filter.idl' file. This can be found on your linux system by typing:

locate SMESH_Filter.idl

Then after you have found it (on the author's PC it is at /opt/salome_5.1.4/SMESH_5.1.4/idl/salome/SMESH_Filter.idl) use less to display it:

less /opt/salome_5.1.4/SMESH_5.1.4/idl/salome/SMESH_Filter.idl

Scroll down this 'C' source code you will find the definitions of the various parameters of SMESH_Filter and FT_BelongToGeom is the 17th enumerator listed there. The other variables of SMESH_Filter are listed further down.


This page was made possible by the help and advice of several individuals on the Salome Forum in particular: Christophe BOURCIER, Pete HALVERSON and Kees WOUTERS. If I have missed mentioning somebody whose name should be added, please let me know or edit this section since it is a Wiki that anybody can add to, or correct.

Disclaimer: This page is still evolving and omissions or errors are a regrettable part of such a process. So user beware! -JMB

A new page