3 \page blsurfplugin_python_interface_page Python Interface
5 Python package \ref BLSURFPluginDC "BLSURFPlugin" defines several classes, destined for creation of the 2D meshes.
7 Documentation for BLSURFPlugin package is available in linear form grouped by classes, declared in the BLSURFPluginDC.py file.
9 Below you can see an example of usage of the BLSURFPlugin package for mesh generation:
12 <h2>Construction of Mesh using BLSurf algorithm</h2>
13 <h3>Basic hypothesis</h3>
20 box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
21 geompy.addToStudy(box, "box")
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]
28 Face_2 = geompy.SubShapeAllSorted(box, geompy.ShapeType["FACE"])[5]
29 Wire_1 = geompy.SubShapeAllSorted(Face_2, geompy.ShapeType["WIRE"])[0]
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")
37 geompy.addToStudyInFather(box ,Face_2, "Face_2")
38 geompy.addToStudyInFather(Face_2,Wire_1, "Wire_1")
40 # create a mesh on the box
41 blsurfMesh = smesh.Mesh(box,"box: BLSurf mesh")
43 # create a BLSurf algorithm for faces
44 algo2d = blsurfMesh.Triangle(algo=smesh.BLSURF)
49 <h3>Adding sizemaps</h3>
51 # optional - set physical mesh to 2 = Size Map
52 algo2d.SetPhysicalMesh( 2 )
54 # optional - set global mesh size
55 algo2d.SetPhySize( 34.641 )
58 algo2d.SetSizeMap(Face_1, 'def f(u,v): return 10' )
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' )
70 <h3>Adding enforced vertices</h3>
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)
77 # Add another enforced vertex on (150, 150, 150)
78 algo2d.SetEnforcedVertex(Face_1, 150, 150, 150)
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: "
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: "
97 # Remove all enforced vertices defined on Face_1
98 algo2d.UnsetEnforcedVertices(Face_1)
107 <h3>Adding an attractor</h3>
110 # Add an attractor on Face_2, which shape is Wire_1
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)
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 )
128 <h3>Using internal vertices</h3>
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' )
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 )
150 # Allows BLSURF to take into account internal vertices
151 algo2d.SetInternalEnforcedVertexAllFaces( True )
153 # Add the created nodes into a group
154 algo2d.SetInternalEnforcedVertexAllFacesGroup( "my group" )
157 blsurfMesh_internal.Compute()