The class of algorithm has methods to set up meshing parameters.
Below you can see examples of usage of this class for 2D mesh generation.
8 from salome.geom
import geomBuilder
9 geompy = geomBuilder.New(salome.myStudy)
11 import SMESH, SALOMEDS
12 from salome.smesh
import smeshBuilder
13 smesh = smeshBuilder.New(salome.myStudy)
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]
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")
37 cadsurfMesh = smesh.Mesh(box,
"box: MG-CADSurf mesh")
40 algo2d = cadsurfMesh.Triangle(algo=smeshBuilder.MG_CADSurf)
47 algo2d.SetPhysicalMesh( 2 )
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' )
57 algo2d.SetSizeMap(Vertex_1,
'def f(): return 2' )
68 algo2d.SetEnforcedVertex(Face_1, 50, 50, 50)
71 algo2d.SetEnforcedVertex(Face_1, 150, 150, 150)
74 enfList = algo2d.GetEnforcedVertices(Face_1)
75 print "List of enforced vertices for Face_1: "
82 algo2d.UnsetEnforcedVertex(Face_1, 50, 50, 50)
83 enfList = algo2d.GetEnforcedVertices(Face_1)
84 print "List of enforced vertices for Face_1: "
91 algo2d.UnsetEnforcedVertices(Face_1)
105 algo2d.SetAttractorGeom(Face_2, Wire_1, 1, 36.641, 20, 10)
109 algo2d.SetGradation( 2.5 )
112 cadsurfMesh.Compute()
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 geompy.addToStudy( Face_3,
'Face_3' )
126 geompy.addToStudy( Vertex_2,
'Vertex_2' )
127 geompy.addToStudy( Partition_1,
'Partition_1' )
128 geompy.addToStudy( OX,
'OX' )
129 geompy.addToStudy( OY,
'OY' )
130 geompy.addToStudy( Multi_Translation_1,
'Multi-Translation_1' )
133 cadsurfMesh_internal = smesh.Mesh(Multi_Translation_1,
"cadsurfMesh_internal")
134 algo2d = cadsurfMesh_internal.Triangle(algo=smeshBuilder.MG_CADSurf)
135 algo2d.SetPhySize( 0.1 )
138 algo2d.SetInternalEnforcedVertexAllFaces(
True )
141 algo2d.SetInternalEnforcedVertexAllFacesGroup(
"my group" )
144 cadsurfMesh_internal.Compute()
7 from salome.geom
import geomBuilder
8 geompy = geomBuilder.New(salome.myStudy)
15 p1 = geompy.MakeVertex(0., 0., 0.)
16 p2 = geompy.MakeVertex(100., 100., 100.)
17 box = geompy.MakeBoxTwoPnt(p1, p2)
18 geompy.addToStudy(box,
"box")
20 p3 = geompy.MakeVertex(25., 5., 25.)
21 sphere1 = geompy.MakeSpherePntR(p3, 15.)
22 geompy.addToStudy(sphere1,
"sphere1")
24 sphere1_trans = geompy.MakeTranslation(sphere1, 0, 100, 0)
25 geompy.addToStudy(sphere1_trans,
"sphere1_trans")
27 sphere1_trans = geompy.MakeTranslation(sphere1, 0, 100, 0)
28 geompy.addToStudy(sphere1_trans,
"sphere1_trans")
30 p4 = geompy.MakeVertex(5, 50, 90)
31 sphere2 = geompy.MakeSpherePntR(p4, 20.)
33 sphere2_trans = geompy.MakeTranslation(sphere2, 100, 0, 0)
34 geompy.addToStudy(sphere2_trans,
"sphere2_trans")
36 sphere2_trans2 = geompy.MakeTranslation(sphere2, 0, 0, -100)
37 geompy.addToStudy(sphere2_trans2,
"sphere2_trans2")
39 sphere2_trans3 = geompy.MakeTranslation(sphere2, 100, 0, -100)
40 geompy.addToStudy(sphere2_trans3,
"sphere2_trans3")
45 part = geompy.MakePartition([box], [sphere1, sphere1_trans, sphere2, sphere2_trans, sphere2_trans2, sphere2_trans3])
46 geompy.addToStudy(part,
"part")
48 Vx = geompy.MakeVectorDXDYDZ(1, 0, 0)
49 Vy = geompy.MakeVectorDXDYDZ(0, 1, 0)
50 Vz = geompy.MakeVectorDXDYDZ(0, 0, 1)
52 left_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType[
"FACE"], Vy, GEOM.ST_ON)
53 left = geompy.CreateGroup(part, geompy.ShapeType[
"FACE"])
54 geompy.UnionList(left, left_faces)
55 geompy.addToStudyInFather(part, left,
"left")
57 right_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType[
"FACE"], Vy, p2, GEOM.ST_ON)
58 right = geompy.CreateGroup(part, geompy.ShapeType[
"FACE"])
59 geompy.UnionList(right, right_faces)
60 geompy.addToStudyInFather(part, right,
"right")
62 back_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType[
"FACE"], Vx, GEOM.ST_ON)
63 back = geompy.CreateGroup(part, geompy.ShapeType[
"FACE"])
64 geompy.UnionList(back, back_faces)
65 geompy.addToStudyInFather(part, back,
"back")
67 front_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType[
"FACE"], Vx, p2, GEOM.ST_ON)
68 front = geompy.CreateGroup(part, geompy.ShapeType[
"FACE"])
69 geompy.UnionList(front, front_faces)
70 geompy.addToStudyInFather(part, front,
"front")
72 bottom_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType[
"FACE"], Vz, GEOM.ST_ON)
73 bottom = geompy.CreateGroup(part, geompy.ShapeType[
"FACE"])
74 geompy.UnionList(bottom, bottom_faces)
75 geompy.addToStudyInFather(part, bottom,
"bottom")
77 top_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType[
"FACE"], Vz, p2, GEOM.ST_ON)
78 top = geompy.CreateGroup(part, geompy.ShapeType[
"FACE"])
79 geompy.UnionList(top, top_faces)
80 geompy.addToStudyInFather(part, top,
"top")
82 sources = geompy.CreateGroup(part, geompy.ShapeType[
"FACE"])
83 geompy.UnionList(sources, left_faces)
84 geompy.UnionList(sources, back_faces)
85 geompy.UnionList(sources, top_faces)
86 geompy.addToStudyInFather(part, sources,
"sources")
92 from salome.smesh
import smeshBuilder
93 smesh = smeshBuilder.New(salome.myStudy)
95 Mesh = smesh.Mesh(part,
"Mesh")
97 algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf)
98 algo2d.SetGeometricMesh( 1 )
99 algo2d.SetAngleMesh( 4 )
100 algo2d.SetPhySize( 8 )
101 algo2d.SetVerbosity(1)
105 algo2d.AddPreCadFacesPeriodicity(left, right)
106 algo2d.AddPreCadFacesPeriodicity(front, back)
107 algo2d.AddPreCadFacesPeriodicity(bottom, top)
109 gr_left = Mesh.Group(left)
110 gr_right = Mesh.Group(right)
111 gr_front = Mesh.Group(front)
112 gr_back = Mesh.Group(back)
113 gr_bottom = Mesh.Group(bottom)
114 gr_top = Mesh.Group(top)
118 left_translated = Mesh.TranslateObjectMakeMesh( gr_left, SMESH.DirStruct( SMESH.PointStruct ( 0, 100, 0 )), 0,
'left_translated' )
119 front_translated = Mesh.TranslateObjectMakeMesh( gr_front, SMESH.DirStruct( SMESH.PointStruct ( -100, 0, 0 )), 0,
'front_translated' )
120 bottom_translated = Mesh.TranslateObjectMakeMesh( gr_bottom, SMESH.DirStruct( SMESH.PointStruct ( 0, 0, 100 )), 0,
'bottom_translated' )
122 def checkProjection(gr, mesh_translated, tol=1e-7):
123 name = gr.GetName() +
"_" + mesh_translated.GetName().split(
"_")[0]
124 mesh_source = smesh.CopyMesh(gr, gr.GetName())
125 mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name)
126 ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol)
127 coincident_nodes = [item
for sublist
in ll_coincident_nodes
for item
in sublist]
128 mesh_check.MakeGroupByIds(
"coincident_nodes", SMESH.NODE, coincident_nodes)
129 mesh_nodes = mesh_check.GetNodesId()
130 if len(ll_coincident_nodes) != mesh_translated.NbNodes():
131 non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes))
132 mesh_check.MakeGroupByIds(
"non_coincident_nodes", SMESH.NODE, non_coincident_nodes)
133 raise Exception(
"Projection failed for %s"%name)
135 checkProjection(gr_right, left_translated)
136 checkProjection(gr_back, front_translated)
137 checkProjection(gr_top, bottom_translated)
139 salome.sg.updateObjBrowser(
True)