1 # -------------------------------------------------
2 # blsurf_construct_mesh_basic_hypo Basic hypothesis
3 # -------------------------------------------------
8 from salome.geom import geomBuilder
9 geompy = geomBuilder.New()
11 import SMESH, SALOMEDS
12 from salome.smesh import smeshBuilder
13 smesh = smeshBuilder.New()
16 box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
17 geompy.addToStudy(box, "box")
20 Face_1 = geompy.SubShapeAllSorted(box, geompy.ShapeType["FACE"])[0]
21 Edge_1 = geompy.SubShapeAllSorted(box, geompy.ShapeType["EDGE"])[0]
22 Vertex_1 = geompy.SubShapeAllSorted(box, geompy.ShapeType["VERTEX"])[0]
24 Face_2 = geompy.SubShapeAllSorted(box, geompy.ShapeType["FACE"])[5]
25 Wire_1 = geompy.SubShapeAllSorted(Face_2, geompy.ShapeType["WIRE"])[0]
27 # Geom object with sizemaps can be unpublished in study.
28 # They will then be automatically published.
29 geompy.addToStudyInFather(box,Face_1, "Face_1")
30 geompy.addToStudyInFather(box,Edge_1, "Edge_1")
31 geompy.addToStudyInFather(box,Vertex_1, "Vertex_1")
33 geompy.addToStudyInFather(box ,Face_2, "Face_2")
34 geompy.addToStudyInFather(Face_2,Wire_1, "Wire_1")
36 # create a mesh on the box
37 cadsurfMesh = smesh.Mesh(box,"box: MG-CADSurf mesh")
39 # create a BLSurf algorithm for faces
40 algo2d = cadsurfMesh.Triangle(algo=smeshBuilder.MG_CADSurf)
42 # ----------------------------------------------
43 # blsurf_construct_mesh_sizemaps Adding sizemaps
44 # ----------------------------------------------
46 # optional - set physical mesh to 2 = Size Map
47 algo2d.SetPhysicalMesh( 2 )
49 # optional - set global mesh size
50 algo2d.SetPhySize( 34.641 )
53 algo2d.SetSizeMap(Face_1, 'def f(u,v): return 10' )
55 algo2d.SetSizeMap(Edge_1, 'def f(t): return 5' )
56 # set size on Vertex_1
57 algo2d.SetSizeMap(Vertex_1, 'def f(): return 2' )
62 # ----------------------------------------------------------------
63 # blsurf_construct_mesh_enforced_vertices Adding enforced vertices
64 # ----------------------------------------------------------------
66 # Add enforced vertex for Face_1 on (50, 50, 50)
67 # The projection coordinates will be (50, 50, 0)
68 algo2d.SetEnforcedVertex(Face_1, 50, 50, 50)
70 # Add another enforced vertex on (150, 150, 150)
71 algo2d.SetEnforcedVertex(Face_1, 150, 150, 150)
73 # Retrieve and print the list of enforced vertices defines on Face_1
74 enfList = algo2d.GetEnforcedVertices(Face_1)
75 print("List of enforced vertices for Face_1: ")
81 # Remove an enforced vertex and print the list
82 algo2d.UnsetEnforcedVertex(Face_1, 50, 50, 50)
83 enfList = algo2d.GetEnforcedVertices(Face_1)
84 print("List of enforced vertices for Face_1: ")
90 # Remove all enforced vertices defined on Face_1
91 algo2d.UnsetEnforcedVertices(Face_1)
96 # ---------------------------------------------------
97 # blsurf_construct_mesh_attractor Adding an attractor
98 # ---------------------------------------------------
100 # Add an attractor on Face_2, which shape is Wire_1
102 # The size on Wire_1 is 1 and will grow until a maximum of 36.641 (physical size set above)
103 # The influence distance of the attractor is 20
104 # The size is kept constant until a distance of 10
105 algo2d.SetAttractorGeom(Face_2, Wire_1, 1, 36.641, 20, 10)
107 # In order to let the attractor control the growing of the mesh let set
108 # the gradation to its maximum
109 algo2d.SetGradation( 2.5 )
112 cadsurfMesh.Compute()
114 # ---------------------------------------------------------------
115 # blsurf_construct_mesh_internal_vertices Using internal vertices
116 # ---------------------------------------------------------------
118 # Creating a geometry containing internal vertices
119 Face_3 = geompy.MakeFaceHW(1, 1, 1)
120 Vertex_2 = geompy.MakeVertex(0.2, 0.2, 0)
121 Partition_1 = geompy.MakePartition([Face_3, Vertex_2], [], [], [], geompy.ShapeType["FACE"], 0, [], 0)
122 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
123 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
124 Multi_Translation_1 = geompy.MakeMultiTranslation2D(Partition_1, OX, 1, 10, OY, 1, 10)
125 Multi_Translation_glued = geompy.MakeGlueEdges(Multi_Translation_1, 1e-7)
126 geompy.addToStudy( Face_3, 'Face_3' )
127 geompy.addToStudy( Vertex_2, 'Vertex_2' )
128 geompy.addToStudy( Partition_1, 'Partition_1' )
129 geompy.addToStudy( OX, 'OX' )
130 geompy.addToStudy( OY, 'OY' )
131 geompy.addToStudy( Multi_Translation_1, 'Multi_Translation_1' )
132 geompy.addToStudy( Multi_Translation_glued, 'Multi_Translation_glued' )
134 # The mesh on the geometry with internal vertices
135 cadsurfMesh_internal = smesh.Mesh(Multi_Translation_glued, "cadsurfMesh_internal")
136 algo2d = cadsurfMesh_internal.Triangle(algo=smeshBuilder.MG_CADSurf)
137 algo2d.SetPhySize( 0.1 )
139 # Allow MG-CADSURF to take into account internal vertices
140 algo2d.SetInternalEnforcedVertexAllFaces( True )
142 # Add the created nodes into a group
143 algo2d.SetInternalEnforcedVertexAllFacesGroup( "my group" )
146 cadsurfMesh_internal.Compute()