Salome HOME
Merge from V6_main (04/10/2012)
[plugins/blsurfplugin.git] / doc / salome / gui / BLSURFPLUGIN / input / blsurfplugin_python_interface.doc
1 /*!
2
3 \page blsurfplugin_python_interface_page Python Interface
4
5 Python package BLSURFPluginDC defines several classes, destined for creation of the 2D meshes.
6
7 BLSURF meshing plugin dynamically adds several methods to the smesh.Mesh class to create meshing algorithms.
8
9 Below you can see an example of usage of the BLSURFPlugin Python API for mesh generation:
10
11 \anchor tui_blsurf
12
13 \section blsurf_construct_mesh Construction of Mesh using BLSurf algorithm
14
15 \subsection blsurf_construct_mesh_basic_hypo Basic hypothesis
16 \code
17 import geompy
18 import smesh
19 import BLSURFPlugin
20
21 # create a box
22 box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
23 geompy.addToStudy(box, "box")
24
25 # get sub-shapes
26 Face_1   = geompy.SubShapeAllSorted(box, geompy.ShapeType["FACE"])[0]
27 Edge_1   = geompy.SubShapeAllSorted(box, geompy.ShapeType["EDGE"])[0]
28 Vertex_1 = geompy.SubShapeAllSorted(box, geompy.ShapeType["VERTEX"])[0]
29
30 Face_2   = geompy.SubShapeAllSorted(box,    geompy.ShapeType["FACE"])[5]
31 Wire_1   = geompy.SubShapeAllSorted(Face_2, geompy.ShapeType["WIRE"])[0]
32
33 # Geom object with sizemaps can be unpublished in study.
34 # They will then be automatically published.
35 geompy.addToStudyInFather(box,Face_1, "Face_1")
36 geompy.addToStudyInFather(box,Edge_1, "Edge_1")
37 geompy.addToStudyInFather(box,Vertex_1, "Vertex_1")
38
39 geompy.addToStudyInFather(box   ,Face_2, "Face_2")
40 geompy.addToStudyInFather(Face_2,Wire_1, "Wire_1")
41
42 # create a mesh on the box
43 blsurfMesh = smesh.Mesh(box,"box: BLSurf mesh")
44
45 # create a BLSurf algorithm for faces
46 algo2d = blsurfMesh.Triangle(algo=smesh.BLSURF)
47
48 # End of script
49 \endcode
50
51 \subsection blsurf_construct_mesh_sizemaps Adding sizemaps
52 \code
53 # optional - set physical mesh to 2 = Size Map
54 algo2d.SetPhysicalMesh( 2 )
55
56 # optional - set global mesh size
57 algo2d.SetPhySize( 34.641 )
58
59 # set size on Face_1
60 algo2d.SetSizeMap(Face_1, 'def f(u,v): return 10' )
61 # set size on Edge_1
62 algo2d.SetSizeMap(Edge_1, 'def f(t): return 5' )
63 # set size on Vertex_1
64 algo2d.SetSizeMap(Vertex_1, 'def f(): return 2' )
65
66 # compute the mesh
67 blsurfMesh.Compute()
68
69 # End of script
70 \endcode
71
72 \subsection blsurf_construct_mesh_enforced_vertices Adding enforced vertices
73 \code
74 # Add enforced vertex for Face_1 on (50, 50, 50)
75 # The projection coordinates will be (50, 50, 0)
76 algo2d.SetEnforcedVertex(Face_1, 50, 50, 50)
77
78 # Add another enforced vertex on (150, 150, 150)
79 algo2d.SetEnforcedVertex(Face_1, 150, 150, 150)
80
81 # Retrieve and print the list of enforced vertices defines on Face_1
82 enfList = algo2d.GetEnforcedVertices(Face_1)
83 print "List of enforced vertices for Face_1: "
84 print enfList
85
86 # compute the mesh
87 blsurfMesh.Compute()
88
89 # Remove an enforced vertex and print the list
90 algo2d.UnsetEnforcedVertex(Face_1, 50, 50, 50)
91 enfList = algo2d.GetEnforcedVertices(Face_1)
92 print "List of enforced vertices for Face_1: "
93 print enfList
94
95 # compute the mesh
96 blsurfMesh.Compute()
97
98 # Remove all enforced vertices defined on Face_1
99 algo2d.UnsetEnforcedVertices(Face_1)
100
101 # compute the mesh
102 blsurfMesh.Compute()
103
104 # End of script
105 \endcode
106
107 \subsection blsurf_construct_mesh_attractor Adding an attractor
108 \code
109 # Add an attractor on Face_2, which shape is Wire_1
110
111 # The size on Wire_1 is 1 and will grow until a maximum of 36.641 (physical size set above) 
112 # The influence distance of the attractor is 20
113 # The size is kept constant until a distance of 10
114 algo2d.SetAttractorGeom(Face_2, Wire_1, 1, 36.641, 20, 10)
115
116 # In order to let the attractor control the growing of the mesh let set
117 # the gradation to its maximum
118 algo2d.SetGradation( 2.5 )
119
120 # compute the mesh
121 blsurfMesh.Compute()
122
123 # End of script
124 \endcode
125
126 \subsection blsurf_construct_mesh_internal_vertices Using internal vertices
127 \code
128 # Creating a geometry containing internal vertices
129 Face_3 = geompy.MakeFaceHW(1, 1, 1)
130 Vertex_2 = geompy.MakeVertex(0.2, 0.2, 0)
131 Partition_1 = geompy.MakePartition([Face_3, Vertex_2], [], [], [], geompy.ShapeType["FACE"], 0, [], 0)
132 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
133 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
134 Multi_Translation_1 = geompy.MakeMultiTranslation2D(Partition_1, OX, 1, 10, OY, 1, 10)
135 geompy.addToStudy( Face_3, 'Face_3' )
136 geompy.addToStudy( Vertex_2, 'Vertex_2' )
137 geompy.addToStudy( Partition_1, 'Partition_1' )
138 geompy.addToStudy( OX, 'OX' )
139 geompy.addToStudy( OY, 'OY' )
140 geompy.addToStudy( Multi_Translation_1, 'Multi-Translation_1' )
141
142 # The mesh on the geometry with internal vertices
143 blsurfMesh_internal = smesh.Mesh(Multi_Translation_1, "blsurfMesh_internal")
144 algo2d = blsurfMesh_internal.Triangle(algo=smesh.BLSURF)
145 algo2d.SetPhySize( 0.1 )
146
147 # Allows BLSURF to take into account internal vertices
148 algo2d.SetInternalEnforcedVertexAllFaces( True )
149
150 # Add the created nodes into a group
151 algo2d.SetInternalEnforcedVertexAllFacesGroup( "my group" )
152
153 # compute the mesh
154 blsurfMesh_internal.Compute()
155
156 # End of script
157 \endcode
158
159 */