3 \page blsurfplugin_python_interface_page Python Interface
5 Python package BLSURFPluginDC defines several classes, destined for creation of the 2D meshes.
7 BLSURF meshing plugin dynamically adds several methods to the smesh.Mesh class to create meshing algorithms.
9 Below you can see an example of usage of the BLSURFPlugin Python API for mesh generation:
13 \section blsurf_construct_mesh Construction of Mesh using BLSurf algorithm
15 \subsection blsurf_construct_mesh_basic_hypo Basic hypothesis
22 box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
23 geompy.addToStudy(box, "box")
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]
30 Face_2 = geompy.SubShapeAllSorted(box, geompy.ShapeType["FACE"])[5]
31 Wire_1 = geompy.SubShapeAllSorted(Face_2, geompy.ShapeType["WIRE"])[0]
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")
39 geompy.addToStudyInFather(box ,Face_2, "Face_2")
40 geompy.addToStudyInFather(Face_2,Wire_1, "Wire_1")
42 # create a mesh on the box
43 blsurfMesh = smesh.Mesh(box,"box: BLSurf mesh")
45 # create a BLSurf algorithm for faces
46 algo2d = blsurfMesh.Triangle(algo=smesh.BLSURF)
51 \subsection blsurf_construct_mesh_sizemaps Adding sizemaps
53 # optional - set physical mesh to 2 = Size Map
54 algo2d.SetPhysicalMesh( 2 )
56 # optional - set global mesh size
57 algo2d.SetPhySize( 34.641 )
60 algo2d.SetSizeMap(Face_1, 'def f(u,v): return 10' )
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' )
72 \subsection blsurf_construct_mesh_enforced_vertices Adding enforced vertices
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)
78 # Add another enforced vertex on (150, 150, 150)
79 algo2d.SetEnforcedVertex(Face_1, 150, 150, 150)
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: "
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: "
98 # Remove all enforced vertices defined on Face_1
99 algo2d.UnsetEnforcedVertices(Face_1)
107 \subsection blsurf_construct_mesh_attractor Adding an attractor
109 # Add an attractor on Face_2, which shape is Wire_1
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)
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 )
126 \subsection blsurf_construct_mesh_internal_vertices Using internal vertices
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' )
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 )
147 # Allows BLSURF to take into account internal vertices
148 algo2d.SetInternalEnforcedVertexAllFaces( True )
150 # Add the created nodes into a group
151 algo2d.SetInternalEnforcedVertexAllFacesGroup( "my group" )
154 blsurfMesh_internal.Compute()