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