Version: 8.3.0
 All Classes Namespaces Files Functions Variables Groups Pages
Modifying Meshes


Adding Nodes and Elements


Add Node

1 # Add Node
2 
3 import salome
4 salome.salome_init()
5 
6 from salome.smesh import smeshBuilder
7 smesh = smeshBuilder.New(salome.myStudy)
8 
9 
10 mesh = smesh.Mesh()
11 
12 # add node
13 new_id = mesh.AddNode(50, 10, 0)
14 print ""
15 if new_id == 0: print "KO node addition."
16 else: print "New Node has been added with ID ", new_id

Download this script


Add 0D Element

1 # Add 0D Element
2 
3 import salome
4 salome.salome_init()
5 
6 from salome.smesh import smeshBuilder
7 smesh = smeshBuilder.New(salome.myStudy)
8 
9 
10 mesh = smesh.Mesh()
11 
12 # add node
13 node_id = mesh.AddNode(50, 10, 0)
14 
15 # add 0D Element
16 new_id = mesh.Add0DElement(node_id)
17 
18 print ""
19 if new_id == 0: print "KO node addition."
20 else: print "New 0D Element has been added with ID ", new_id

Download this script


Add 0D Element on Element Nodes

1 # Add 0D Element on Element Nodes
2 
3 
4 import salome
5 salome.salome_init()
6 
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New(salome.myStudy)
9 
10 import SMESH, SALOMEDS
11 from salome.smesh import smeshBuilder
12 smesh = smeshBuilder.New(salome.myStudy)
13 
14 
15 # create a geometry
16 box = geompy.MakeBoxDXDYDZ( 10, 10, 10 )
17 face = geompy.SubShapeAll( box, geompy.ShapeType["FACE"])[0]
18 
19 # make 3D mesh
20 mesh = smesh.Mesh( box )
21 mesh.AutomaticHexahedralization(0)
22 
23 # create 0D elements on all nodes of the mesh
24 res = mesh.Add0DElementsToAllNodes( mesh )
25 
26 # find 0D elements on all nodes of the mesh, all found nodes are added to a new group
27 groupName = "0Dmesh"
28 res = mesh.Add0DElementsToAllNodes( mesh, groupName )
29 mesh.RemoveGroupWithContents( res ) # remove all found 0D elements
30 
31 # create 0D elements on all nodes of a sub-mesh, with group creation
32 groupName = "0Dsubmesh"
33 submesh = mesh.GetSubMesh( face, "faceSM")
34 res = mesh.Add0DElementsToAllNodes( submesh, groupName )
35 
36 # create 0D elements on all nodes of a group
37 group = mesh.Group( face, "faceGroup" )
38 res = mesh.Add0DElementsToAllNodes( group )
39 
40 # remove all 0D elements
41 mesh.RemoveElements( mesh.GetIdsFromFilter( smesh.GetFilter( SMESH.ELEM0D,
42  SMESH.FT_ElemGeomType,
43  "=",SMESH.Geom_POINT )))
44 
45 # create 0D elements on all nodes of some elements
46 res = mesh.Add0DElementsToAllNodes( mesh.GetElementsId() )
47 
48 mesh.RemoveElements( mesh.GetElementsByType( SMESH.ELEM0D ))
49 
50 # create 0D elements on some nodes
51 nodes = range(1,10)
52 res = mesh.Add0DElementsToAllNodes( mesh.GetIDSource( nodes, SMESH.NODE ))

Download this script


Add Edge

1 # Add Edge
2 
3 import SMESH_mechanic
4 
5 mesh = SMESH_mechanic.mesh
6 print ""
7 
8 # add node
9 n1 = mesh.AddNode(50, 10, 0)
10 if n1 == 0: print "KO node addition."
11 
12 # add edge
13 e1 = mesh.AddEdge([n1, 38])
14 if e1 == 0: print "KO edge addition."
15 else: print "New Edge has been added with ID ", e1

Download this script


Add Triangle

1 # Add Triangle
2 
3 import SMESH_mechanic
4 
5 mesh = SMESH_mechanic.mesh
6 print ""
7 
8 # add node
9 n1 = mesh.AddNode(50, 10, 0)
10 if n1 == 0: print "KO node addition."
11 
12 # add triangle
13 t1 = mesh.AddFace([n1, 38, 39])
14 if t1 == 0: print "KO triangle addition."
15 else: print "New Triangle has been added with ID ", t1

Download this script


Add Quadrangle

1 # Add Quadrangle
2 
3 import SMESH_mechanic
4 
5 mesh = SMESH_mechanic.mesh
6 print ""
7 
8 # add node
9 n1 = mesh.AddNode(50, 10, 0)
10 if n1 == 0: print "KO node addition."
11 
12 n2 = mesh.AddNode(40, 20, 0)
13 if n2 == 0: print "KO node addition."
14 
15 # add quadrangle
16 q1 = mesh.AddFace([n2, n1, 38, 39])
17 if q1 == 0: print "KO quadrangle addition."
18 else: print "New Quadrangle has been added with ID ", q1

Download this script


Add Tetrahedron

1 # Add Tetrahedron
2 
3 import SMESH_mechanic
4 
5 mesh = SMESH_mechanic.mesh
6 print ""
7 
8 # add node
9 n1 = mesh.AddNode(50, 10, 0)
10 if n1 == 0: print "KO node addition."
11 
12 # add tetrahedron
13 t1 = mesh.AddVolume([n1, 38, 39, 246])
14 if t1 == 0: print "KO tetrahedron addition."
15 else: print "New Tetrahedron has been added with ID ", t1

Download this script


Add Hexahedron

1 # Add Hexahedron
2 
3 import SMESH_mechanic
4 
5 mesh = SMESH_mechanic.mesh
6 print ""
7 
8 # add nodes
9 nId1 = mesh.AddNode(50, 10, 0)
10 nId2 = mesh.AddNode(47, 12, 0)
11 nId3 = mesh.AddNode(50, 10, 10)
12 nId4 = mesh.AddNode(47, 12, 10)
13 
14 if nId1 == 0 or nId2 == 0 or nId3 == 0 or nId4 == 0: print "KO node addition."
15 
16 # add hexahedron
17 vId = mesh.AddVolume([nId2, nId1, 38, 39, nId4, nId3, 245, 246])
18 if vId == 0: print "KO Hexahedron addition."
19 else: print "New Hexahedron has been added with ID ", vId

Download this script


Add Polygon

1 # Add Polygon
2 
3 import math
4 
5 import salome
6 salome.salome_init()
7 
8 import SMESH, SALOMEDS
9 from salome.smesh import smeshBuilder
10 smesh = smeshBuilder.New(salome.myStudy)
11 
12 
13 # create an empty mesh structure
14 mesh = smesh.Mesh()
15 
16 # a method to build a polygonal mesh element with <nb_vert> angles:
17 def MakePolygon (a_mesh, x0, y0, z0, radius, nb_vert):
18  al = 2.0 * math.pi / nb_vert
19  node_ids = []
20 
21  # Create nodes for a polygon
22  for ii in range(nb_vert):
23  nid = mesh.AddNode(x0 + radius * math.cos(ii*al),
24  y0 + radius * math.sin(ii*al),
25  z0)
26  node_ids.append(nid)
27  pass
28 
29  # Create a polygon
30  return mesh.AddPolygonalFace(node_ids)
31 
32 # Create three polygons
33 f1 = MakePolygon(mesh, 0, 0, 0, 30, 13)
34 f2 = MakePolygon(mesh, 0, 0, 10, 21, 9)
35 f3 = MakePolygon(mesh, 0, 0, 20, 13, 6)
36 
37 salome.sg.updateObjBrowser(True)

Download this script


Add Polyhedron

1 # Add Polyhedron
2 
3 
4 import salome
5 salome.salome_init()
6 
7 from salome.smesh import smeshBuilder
8 smesh = smeshBuilder.New(salome.myStudy)
9 
10 import math
11 
12 # create an empty mesh structure
13 mesh = smesh.Mesh()
14 
15 # Create nodes for 12-hedron with pentagonal faces
16 al = 2 * math.pi / 5.0
17 cosal = math.cos(al)
18 aa = 13
19 rr = aa / (2.0 * math.sin(al/2.0))
20 dr = 2.0 * rr * cosal
21 r1 = rr + dr
22 dh = rr * math.sqrt(2.0 * (1.0 - cosal * (1.0 + 2.0 * cosal)))
23 hh = 2.0 * dh - dr * (rr*(cosal - 1) + (rr + dr)*(math.cos(al/2) - 1)) / dh
24 
25 dd = [] # top
26 cc = [] # below top
27 bb = [] # above bottom
28 aa = [] # bottom
29 
30 for i in range(5):
31  cos_bot = math.cos(i*al)
32  sin_bot = math.sin(i*al)
33 
34  cos_top = math.cos(i*al + al/2.0)
35  sin_top = math.sin(i*al + al/2.0)
36 
37  nd = mesh.AddNode(rr * cos_top, rr * sin_top, hh ) # top
38  nc = mesh.AddNode(r1 * cos_top, r1 * sin_top, hh - dh) # below top
39  nb = mesh.AddNode(r1 * cos_bot, r1 * sin_bot, dh) # above bottom
40  na = mesh.AddNode(rr * cos_bot, rr * sin_bot, 0) # bottom
41  dd.append(nd) # top
42  cc.append(nc) # below top
43  bb.append(nb) # above bottom
44  aa.append(na) # bottom
45  pass
46 
47 # Create a polyhedral volume (12-hedron with pentagonal faces)
48 mesh.AddPolyhedralVolume([dd[0], dd[1], dd[2], dd[3], dd[4], # top
49  dd[0], cc[0], bb[1], cc[1], dd[1], # -
50  dd[1], cc[1], bb[2], cc[2], dd[2], # -
51  dd[2], cc[2], bb[3], cc[3], dd[3], # - below top
52  dd[3], cc[3], bb[4], cc[4], dd[4], # -
53  dd[4], cc[4], bb[0], cc[0], dd[0], # -
54  aa[4], bb[4], cc[4], bb[0], aa[0], # .
55  aa[3], bb[3], cc[3], bb[4], aa[4], # .
56  aa[2], bb[2], cc[2], bb[3], aa[3], # . above bottom
57  aa[1], bb[1], cc[1], bb[2], aa[2], # .
58  aa[0], bb[0], cc[0], bb[1], aa[1], # .
59  aa[0], aa[1], aa[2], aa[3], aa[4]], # bottom
60  [5,5,5,5,5,5,5,5,5,5,5,5])
61 
62 if salome.sg.hasDesktop():
63  salome.sg.updateObjBrowser(True)

Download this script


Removing Nodes and Elements


Removing Nodes

1 # Removing Nodes
2 
3 import SMESH_mechanic
4 
5 mesh = SMESH_mechanic.mesh
6 
7 # remove nodes #246 and #255
8 res = mesh.RemoveNodes([246, 255])
9 if res == 1: print "Nodes removing is OK!"
10 else: print "KO nodes removing."

Download this script


Removing Elements

1 # Removing Elements
2 
3 import SMESH_mechanic
4 
5 mesh = SMESH_mechanic.mesh
6 
7 # remove three elements: #850, #859 and #814
8 res = mesh.RemoveElements([850, 859, 814])
9 if res == 1: print "Elements removing is OK!"
10 else: print "KO Elements removing."

Download this script


Removing Orphan Nodes

1 # Removing Orphan Nodes
2 
3 import SMESH_mechanic
4 
5 mesh = SMESH_mechanic.mesh
6 
7 # add orphan nodes
8 mesh.AddNode(0,0,0)
9 mesh.AddNode(1,1,1)
10 # remove just created orphan nodes
11 res = mesh.RemoveOrphanNodes()
12 if res == 1: print "Removed %d nodes!" % res
13 else: print "KO nodes removing."

Download this script


Moving Nodes

1 # Moving Nodes
2 
3 
4 import salome
5 salome.salome_init()
6 
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New(salome.myStudy)
9 
10 import SMESH, SALOMEDS
11 from salome.smesh import smeshBuilder
12 smesh = smeshBuilder.New(salome.myStudy)
13 
14 
15 box = geompy.MakeBoxDXDYDZ(200, 200, 200)
16 
17 mesh = smesh.Mesh( box )
18 mesh.Segment().AutomaticLength(0.1)
19 mesh.Quadrangle()
20 mesh.Compute()
21 
22 # find node at (0,0,0) which is located on a geom vertex
23 node000 = None
24 for vId in geompy.SubShapeAllIDs( box, geompy.ShapeType["VERTEX"]):
25  if node000: break
26  nodeIds = mesh.GetSubMeshNodesId( vId, True )
27  for node in nodeIds:
28  xyz = mesh.GetNodeXYZ( node )
29  if xyz[0] == 0 and xyz[1] == 0 and xyz[2] == 0 :
30  node000 = node
31  pass
32  pass
33  pass
34 
35 if not node000:
36  raise "node000 not found"
37 
38 # find node000 using a dedicated function
39 n = mesh.FindNodeClosestTo( -1,-1,-1 )
40 if not n == node000:
41  raise "FindNodeClosestTo() returns " + str( n ) + " != " + str( node000 )
42 
43 # move node000 to a new location
44 x,y,z = -10, -10, -10
45 n = mesh.MoveNode( n,x,y,z )
46 if not n:
47  raise "MoveNode() returns " + n
48 
49 # check the coordinates of the node000
50 xyz = mesh.GetNodeXYZ( node000 )
51 if not ( xyz[0] == x and xyz[1] == y and xyz[2] == z) :
52  raise "Wrong coordinates: " + str( xyz ) + " != " + str( [x,y,z] )

Download this script


Diagonal Inversion

1 # Diagonal Inversion
2 
3 
4 import salome
5 salome.salome_init()
6 import GEOM
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New(salome.myStudy)
9 
10 import SMESH, SALOMEDS
11 from salome.smesh import smeshBuilder
12 smesh = smeshBuilder.New(salome.myStudy)
13 import salome_notebook
14 
15 
16 # create an empty mesh structure
17 mesh = smesh.Mesh()
18 
19 # create the following mesh:
20 # .----.----.----.
21 # | /| /| /|
22 # | / | / | / |
23 # | / | / | / |
24 # |/ |/ |/ |
25 # .----.----.----.
26 
27 bb = [0, 0, 0, 0]
28 tt = [0, 0, 0, 0]
29 ff = [0, 0, 0, 0, 0, 0]
30 
31 bb[0] = mesh.AddNode( 0., 0., 0.)
32 bb[1] = mesh.AddNode(10., 0., 0.)
33 bb[2] = mesh.AddNode(20., 0., 0.)
34 bb[3] = mesh.AddNode(30., 0., 0.)
35 
36 tt[0] = mesh.AddNode( 0., 15., 0.)
37 tt[1] = mesh.AddNode(10., 15., 0.)
38 tt[2] = mesh.AddNode(20., 15., 0.)
39 tt[3] = mesh.AddNode(30., 15., 0.)
40 
41 ff[0] = mesh.AddFace([bb[0], bb[1], tt[1]])
42 ff[1] = mesh.AddFace([bb[0], tt[1], tt[0]])
43 ff[2] = mesh.AddFace([bb[1], bb[2], tt[2]])
44 ff[3] = mesh.AddFace([bb[1], tt[2], tt[1]])
45 ff[4] = mesh.AddFace([bb[2], bb[3], tt[3]])
46 ff[5] = mesh.AddFace([bb[2], tt[3], tt[2]])
47 
48 # inverse the diagonal bb[1] - tt[2]
49 print "\nDiagonal inversion ... ",
50 res = mesh.InverseDiag(bb[1], tt[2])
51 if not res: print "failed!"
52 else: print "done."
53 
54 salome.sg.updateObjBrowser(True)

Download this script


Uniting two Triangles

1 # Uniting two Triangles
2 
3 
4 import salome
5 salome.salome_init()
6 import GEOM
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New(salome.myStudy)
9 
10 import SMESH, SALOMEDS
11 from salome.smesh import smeshBuilder
12 smesh = smeshBuilder.New(salome.myStudy)
13 import salome_notebook
14 
15 
16 # create an empty mesh structure
17 mesh = smesh.Mesh()
18 
19 # create the following mesh:
20 # .----.----.----.
21 # | /| /| /|
22 # | / | / | / |
23 # | / | / | / |
24 # |/ |/ |/ |
25 # .----.----.----.
26 
27 bb = [0, 0, 0, 0]
28 tt = [0, 0, 0, 0]
29 ff = [0, 0, 0, 0, 0, 0]
30 
31 bb[0] = mesh.AddNode( 0., 0., 0.)
32 bb[1] = mesh.AddNode(10., 0., 0.)
33 bb[2] = mesh.AddNode(20., 0., 0.)
34 bb[3] = mesh.AddNode(30., 0., 0.)
35 
36 tt[0] = mesh.AddNode( 0., 15., 0.)
37 tt[1] = mesh.AddNode(10., 15., 0.)
38 tt[2] = mesh.AddNode(20., 15., 0.)
39 tt[3] = mesh.AddNode(30., 15., 0.)
40 
41 ff[0] = mesh.AddFace([bb[0], bb[1], tt[1]])
42 ff[1] = mesh.AddFace([bb[0], tt[1], tt[0]])
43 ff[2] = mesh.AddFace([bb[1], bb[2], tt[2]])
44 ff[3] = mesh.AddFace([bb[1], tt[2], tt[1]])
45 ff[4] = mesh.AddFace([bb[2], bb[3], tt[3]])
46 ff[5] = mesh.AddFace([bb[2], tt[3], tt[2]])
47 
48 # delete the diagonal bb[1] - tt[2]
49 print "\nUnite two triangles ... ",
50 res = mesh.DeleteDiag(bb[1], tt[2])
51 if not res: print "failed!"
52 else: print "done."
53 
54 salome.sg.updateObjBrowser(True)

Download this script


Uniting a Set of Triangles

1 # Uniting a Set of Triangles
2 
3 
4 import salome
5 salome.salome_init()
6 import GEOM
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New(salome.myStudy)
9 
10 import SMESH, SALOMEDS
11 from salome.smesh import smeshBuilder
12 smesh = smeshBuilder.New(salome.myStudy)
13 import salome_notebook
14 
15 
16 # create an empty mesh structure
17 mesh = smesh.Mesh()
18 
19 # create the following mesh:
20 # .----.----.----.
21 # | /| /| /|
22 # | / | / | / |
23 # | / | / | / |
24 # |/ |/ |/ |
25 # .----.----.----.
26 
27 bb = [0, 0, 0, 0]
28 tt = [0, 0, 0, 0]
29 ff = [0, 0, 0, 0, 0, 0]
30 
31 bb[0] = mesh.AddNode( 0., 0., 0.)
32 bb[1] = mesh.AddNode(10., 0., 0.)
33 bb[2] = mesh.AddNode(20., 0., 0.)
34 bb[3] = mesh.AddNode(30., 0., 0.)
35 
36 tt[0] = mesh.AddNode( 0., 15., 0.)
37 tt[1] = mesh.AddNode(10., 15., 0.)
38 tt[2] = mesh.AddNode(20., 15., 0.)
39 tt[3] = mesh.AddNode(30., 15., 0.)
40 
41 ff[0] = mesh.AddFace([bb[0], bb[1], tt[1]])
42 ff[1] = mesh.AddFace([bb[0], tt[1], tt[0]])
43 ff[2] = mesh.AddFace([bb[1], bb[2], tt[2]])
44 ff[3] = mesh.AddFace([bb[1], tt[2], tt[1]])
45 ff[4] = mesh.AddFace([bb[2], bb[3], tt[3]])
46 ff[5] = mesh.AddFace([bb[2], tt[3], tt[2]])
47 
48 # unite a set of triangles
49 print "\nUnite a set of triangles ... ",
50 res = mesh.TriToQuad([ff[2], ff[3], ff[4], ff[5]], SMESH.FT_MinimumAngle, 60.)
51 if not res: print "failed!"
52 else: print "done."
53 
54 salome.sg.updateObjBrowser(True)

Download this script


Orientation

1 # Orientation
2 
3 
4 import salome
5 salome.salome_init()
6 import GEOM
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New(salome.myStudy)
9 
10 import SMESH, SALOMEDS
11 from salome.smesh import smeshBuilder
12 smesh = smeshBuilder.New(salome.myStudy)
13 import salome_notebook
14 
15 
16 # create an empty mesh structure
17 mesh = smesh.Mesh()
18 
19 # build five quadrangles:
20 dx = 10
21 dy = 20
22 
23 n1 = mesh.AddNode(0.0 * dx, 0, 0)
24 n2 = mesh.AddNode(1.0 * dx, 0, 0)
25 n3 = mesh.AddNode(2.0 * dx, 0, 0)
26 n4 = mesh.AddNode(3.0 * dx, 0, 0)
27 n5 = mesh.AddNode(4.0 * dx, 0, 0)
28 n6 = mesh.AddNode(5.0 * dx, 0, 0)
29 n7 = mesh.AddNode(0.0 * dx, dy, 0)
30 n8 = mesh.AddNode(1.0 * dx, dy, 0)
31 n9 = mesh.AddNode(2.0 * dx, dy, 0)
32 n10 = mesh.AddNode(3.0 * dx, dy, 0)
33 n11 = mesh.AddNode(4.0 * dx, dy, 0)
34 n12 = mesh.AddNode(5.0 * dx, dy, 0)
35 
36 f1 = mesh.AddFace([n1, n2, n8 , n7 ])
37 f2 = mesh.AddFace([n2, n3, n9 , n8 ])
38 f3 = mesh.AddFace([n3, n4, n10, n9 ])
39 f4 = mesh.AddFace([n4, n5, n11, n10])
40 f5 = mesh.AddFace([n5, n6, n12, n11])
41 
42 # Change the orientation of the second and the fourth faces.
43 mesh.Reorient([2, 4])
44 
45 salome.sg.updateObjBrowser(True)

Download this script


Cutting Quadrangles

1 # Cutting Quadrangles
2 
3 import SMESH_mechanic
4 import SMESH
5 
6 smesh = SMESH_mechanic.smesh
7 mesh = SMESH_mechanic.mesh
8 
9 # cut two quadrangles: 405 and 406
10 mesh.QuadToTri([405, 406], SMESH.FT_MinimumAngle)

Download this script


Smoothing

1 # Smoothing
2 
3 
4 import salome
5 salome.salome_init()
6 import GEOM
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New(salome.myStudy)
9 
10 import SMESH, SALOMEDS
11 from salome.smesh import smeshBuilder
12 smesh = smeshBuilder.New(salome.myStudy)
13 
14 import SMESH_mechanic
15 
16 #smesh = SMESH_mechanic.smesh
17 mesh = SMESH_mechanic.mesh
18 
19 # select the top face
20 faces = geompy.SubShapeAllSorted(SMESH_mechanic.shape_mesh, geompy.ShapeType["FACE"])
21 face = faces[3]
22 geompy.addToStudyInFather(SMESH_mechanic.shape_mesh, face, "face planar with hole")
23 
24 # create a group of faces to be smoothed
25 GroupSmooth = mesh.GroupOnGeom(face, "Group of faces (smooth)", SMESH.FACE)
26 
27 # perform smoothing
28 
29 # boolean SmoothObject(Object, IDsOfFixedNodes, MaxNbOfIterations, MaxAspectRatio, Method)
30 res = mesh.SmoothObject(GroupSmooth, [], 20, 2., smesh.CENTROIDAL_SMOOTH)
31 print "\nSmoothing ... ",
32 if not res: print "failed!"
33 else: print "done."
34 
35 salome.sg.updateObjBrowser(True)

Download this script


Extrusion

1 # Extrusion
2 
3 
4 import salome
5 salome.salome_init()
6 import GEOM
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New(salome.myStudy)
9 
10 import SMESH, SALOMEDS
11 from salome.smesh import smeshBuilder
12 smesh = smeshBuilder.New(salome.myStudy)
13 
14 import SMESH_mechanic
15 
16 #smesh = SMESH_mechanic.smesh
17 mesh = SMESH_mechanic.mesh
18 
19 # select the top face
20 faces = geompy.SubShapeAllSorted(SMESH_mechanic.shape_mesh, geompy.ShapeType["FACE"])
21 face = faces[7]
22 geompy.addToStudyInFather(SMESH_mechanic.shape_mesh, face, "face circular top")
23 
24 # create a vector for extrusion
25 point = SMESH.PointStruct(0., 0., 5.)
26 vector = SMESH.DirStruct(point)
27 
28 # create a group to be extruded
29 GroupTri = mesh.GroupOnGeom(face, "Group of faces (extrusion)", SMESH.FACE)
30 
31 # perform extrusion of the group
32 mesh.ExtrusionSweepObject(GroupTri, vector, 5)
33 
34 salome.sg.updateObjBrowser(True)

Download this script


Extrusion along a Path

1 # Extrusion along a Path
2 
3 import math
4 
5 import salome
6 salome.salome_init()
7 import GEOM
8 from salome.geom import geomBuilder
9 geompy = geomBuilder.New(salome.myStudy)
10 
11 import SMESH, SALOMEDS
12 from salome.smesh import smeshBuilder
13 smesh = smeshBuilder.New(salome.myStudy)
14 
15 # 1. Create points
16 points = [[0, 0], [50, 30], [50, 110], [0, 150], [-80, 150], [-130, 70], [-130, -20]]
17 
18 iv = 1
19 vertices = []
20 for point in points:
21  vert = geompy.MakeVertex(point[0], point[1], 0)
22  geompy.addToStudy(vert, "Vertex_" + `iv`)
23  vertices.append(vert)
24  iv += 1
25  pass
26 
27 # 2. Create edges and wires
28 Edge_straight = geompy.MakeEdge(vertices[0], vertices[4])
29 Edge_bezierrr = geompy.MakeBezier(vertices)
30 Wire_polyline = geompy.MakePolyline(vertices)
31 Edge_Circle = geompy.MakeCircleThreePnt(vertices[0], vertices[1], vertices[2])
32 
33 geompy.addToStudy(Edge_straight, "Edge_straight")
34 geompy.addToStudy(Edge_bezierrr, "Edge_bezierrr")
35 geompy.addToStudy(Wire_polyline, "Wire_polyline")
36 geompy.addToStudy(Edge_Circle , "Edge_Circle")
37 
38 # 3. Explode wire on edges, as they will be used for mesh extrusion
39 Wire_polyline_edges = geompy.SubShapeAll(Wire_polyline, geompy.ShapeType["EDGE"])
40 for ii in range(len(Wire_polyline_edges)):
41  geompy.addToStudyInFather(Wire_polyline, Wire_polyline_edges[ii], "Edge_" + `ii + 1`)
42  pass
43 
44 # Mesh
45 
46 # Mesh the given shape with the given 1d hypothesis
47 def Mesh1D(shape1d, nbSeg, name):
48  mesh1d_tool = smesh.Mesh(shape1d, name)
49  algo = mesh1d_tool.Segment()
50  hyp = algo.NumberOfSegments(nbSeg)
51  isDone = mesh1d_tool.Compute()
52  if not isDone: print 'Mesh ', name, ': computation failed'
53  return mesh1d_tool
54 
55 # Create a mesh with six nodes, seven edges and two quadrangle faces
56 def MakeQuadMesh2(mesh_name):
57  quad_1 = smesh.Mesh(name = mesh_name)
58 
59  # six nodes
60  n1 = quad_1.AddNode(0, 20, 10)
61  n2 = quad_1.AddNode(0, 40, 10)
62  n3 = quad_1.AddNode(0, 40, 30)
63  n4 = quad_1.AddNode(0, 20, 30)
64  n5 = quad_1.AddNode(0, 0, 30)
65  n6 = quad_1.AddNode(0, 0, 10)
66 
67  # seven edges
68  quad_1.AddEdge([n1, n2]) # 1
69  quad_1.AddEdge([n2, n3]) # 2
70  quad_1.AddEdge([n3, n4]) # 3
71  quad_1.AddEdge([n4, n1]) # 4
72  quad_1.AddEdge([n4, n5]) # 5
73  quad_1.AddEdge([n5, n6]) # 6
74  quad_1.AddEdge([n6, n1]) # 7
75 
76  # two quadrangle faces
77  quad_1.AddFace([n1, n2, n3, n4]) # 8
78  quad_1.AddFace([n1, n4, n5, n6]) # 9
79  return [quad_1, [1,2,3,4,5,6,7], [8,9]]
80 
81 # Path meshes
82 Edge_straight_mesh = Mesh1D(Edge_straight, 7, "Edge_straight")
83 Edge_bezierrr_mesh = Mesh1D(Edge_bezierrr, 7, "Edge_bezierrr")
84 Wire_polyline_mesh = Mesh1D(Wire_polyline, 3, "Wire_polyline")
85 Edge_Circle_mesh = Mesh1D(Edge_Circle , 8, "Edge_Circle")
86 
87 # Initial meshes (to be extruded)
88 [quad_1, ee_1, ff_1] = MakeQuadMesh2("quad_1")
89 [quad_2, ee_2, ff_2] = MakeQuadMesh2("quad_2")
90 [quad_3, ee_3, ff_3] = MakeQuadMesh2("quad_3")
91 [quad_4, ee_4, ff_4] = MakeQuadMesh2("quad_4")
92 [quad_5, ee_5, ff_5] = MakeQuadMesh2("quad_5")
93 [quad_6, ee_6, ff_6] = MakeQuadMesh2("quad_6")
94 [quad_7, ee_7, ff_7] = MakeQuadMesh2("quad_7")
95 
96 # ExtrusionAlongPath
97 # IDsOfElements, PathMesh, PathShape, NodeStart,
98 # HasAngles, Angles, HasRefPoint, RefPoint
99 refPoint = SMESH.PointStruct(0, 0, 0)
100 a10 = 10.0*math.pi/180.0
101 a45 = 45.0*math.pi/180.0
102 
103 # 1. Extrusion of two mesh edges along a straight path
104 error = quad_1.ExtrusionAlongPath([1,2], Edge_straight_mesh, Edge_straight, 1,
105  0, [], 0, refPoint)
106 
107 # 2. Extrusion of one mesh edge along a curved path
108 error = quad_2.ExtrusionAlongPath([2], Edge_bezierrr_mesh, Edge_bezierrr, 1,
109  0, [], 0, refPoint)
110 
111 # 3. Extrusion of one mesh edge along a curved path with usage of angles
112 error = quad_3.ExtrusionAlongPath([2], Edge_bezierrr_mesh, Edge_bezierrr, 1,
113  1, [a45, a45, a45, 0, -a45, -a45, -a45], 0, refPoint)
114 
115 # 4. Extrusion of one mesh edge along the path, which is a part of a meshed wire
116 error = quad_4.ExtrusionAlongPath([4], Wire_polyline_mesh, Wire_polyline_edges[0], 1,
117  1, [a10, a10, a10], 0, refPoint)
118 
119 # 5. Extrusion of two mesh faces along the path, which is a part of a meshed wire
120 error = quad_5.ExtrusionAlongPath(ff_5 , Wire_polyline_mesh, Wire_polyline_edges[2], 4,
121  0, [], 0, refPoint)
122 
123 # 6. Extrusion of two mesh faces along a closed path
124 error = quad_6.ExtrusionAlongPath(ff_6 , Edge_Circle_mesh, Edge_Circle, 1,
125  0, [], 0, refPoint)
126 
127 # 7. Extrusion of two mesh faces along a closed path with usage of angles
128 error = quad_7.ExtrusionAlongPath(ff_7, Edge_Circle_mesh, Edge_Circle, 1,
129  1, [a45, -a45, a45, -a45, a45, -a45, a45, -a45], 0, refPoint)
130 
131 salome.sg.updateObjBrowser(True)

Download this script


Revolution

1 # Revolution
2 
3 import math
4 import SMESH
5 
6 import SMESH_mechanic
7 
8 mesh = SMESH_mechanic.mesh
9 smesh = SMESH_mechanic.smesh
10 
11 # create a group of faces to be revolved
12 FacesRotate = [492, 493, 502, 503]
13 GroupRotate = mesh.CreateEmptyGroup(SMESH.FACE,"Group of faces (rotate)")
14 GroupRotate.Add(FacesRotate)
15 
16 # define revolution angle and axis
17 angle45 = 45 * math.pi / 180
18 axisXYZ = SMESH.AxisStruct(-38.3128, -73.3658, -23.321, -13.3402, -13.3265, 6.66632)
19 
20 # perform revolution of an object
21 mesh.RotationSweepObject(GroupRotate, axisXYZ, angle45, 4, 1e-5)

Download this script


Pattern Mapping

1 # Pattern Mapping
2 
3 
4 import salome
5 salome.salome_init()
6 import GEOM
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New(salome.myStudy)
9 
10 import SMESH, SALOMEDS
11 from salome.smesh import smeshBuilder
12 smesh = smeshBuilder.New(salome.myStudy)
13 
14 # define the geometry
15 Box_1 = geompy.MakeBoxDXDYDZ(200., 200., 200.)
16 geompy.addToStudy(Box_1, "Box_1")
17 
18 faces = geompy.SubShapeAll(Box_1, geompy.ShapeType["FACE"])
19 Face_1 = faces[0]
20 Face_2 = faces[1]
21 
22 geompy.addToStudyInFather(Box_1, Face_1, "Face_1")
23 geompy.addToStudyInFather(Box_1, Face_2, "Face_2")
24 
25 # build a quadrangle mesh 3x3 on Face_1
26 Mesh_1 = smesh.Mesh(Face_1)
27 algo1D = Mesh_1.Segment()
28 algo1D.NumberOfSegments(3)
29 Mesh_1.Quadrangle()
30 
31 isDone = Mesh_1.Compute()
32 if not isDone: print 'Mesh Mesh_1 : computation failed'
33 
34 # build a triangle mesh on Face_2
35 Mesh_2 = smesh.Mesh(Face_2)
36 
37 algo1D = Mesh_2.Segment()
38 algo1D.NumberOfSegments(1)
39 algo2D = Mesh_2.Triangle()
40 algo2D.MaxElementArea(240)
41 
42 isDone = Mesh_2.Compute()
43 if not isDone: print 'Mesh Mesh_2 : computation failed'
44 
45 # create a 2d pattern
46 pattern = smesh.GetPattern()
47 
48 isDone = pattern.LoadFromFace(Mesh_2.GetMesh(), Face_2, 0)
49 if (isDone != 1): print 'LoadFromFace :', pattern.GetErrorCode()
50 
51 # apply the pattern to a face of the first mesh
52 facesToSplit = Mesh_1.GetElementsByType(SMESH.FACE)
53 print "Splitting %d rectangular face(s) to %d triangles..."%(len(facesToSplit), 2*len(facesToSplit))
54 pattern.ApplyToMeshFaces(Mesh_1.GetMesh(), facesToSplit, 0, 0)
55 isDone = pattern.MakeMesh(Mesh_1.GetMesh(), 0, 0)
56 if (isDone != 1): print 'MakeMesh :', pattern.GetErrorCode()
57 
58 # create quadrangle mesh
59 Mesh_3 = smesh.Mesh(Box_1)
60 Mesh_3.Segment().NumberOfSegments(1)
61 Mesh_3.Quadrangle()
62 Mesh_3.Hexahedron()
63 isDone = Mesh_3.Compute()
64 if not isDone: print 'Mesh Mesh_3 : computation failed'
65 
66 # create a 3d pattern (hexahedrons)
67 pattern_hexa = smesh.GetPattern()
68 
69 smp_hexa = """!!! Nb of points:
70 15
71  0 0 0 !- 0
72  1 0 0 !- 1
73  0 1 0 !- 2
74  1 1 0 !- 3
75  0 0 1 !- 4
76  1 0 1 !- 5
77  0 1 1 !- 6
78  1 1 1 !- 7
79  0.5 0 0.5 !- 8
80  0.5 0 1 !- 9
81  0.5 0.5 0.5 !- 10
82  0.5 0.5 1 !- 11
83  1 0 0.5 !- 12
84  1 0.5 0.5 !- 13
85  1 0.5 1 !- 14
86  !!! Indices of points of 4 elements:
87  8 12 5 9 10 13 14 11
88  0 8 9 4 2 10 11 6
89  2 10 11 6 3 13 14 7
90  0 1 12 8 2 3 13 10"""
91 
92 pattern_hexa.LoadFromFile(smp_hexa)
93 
94 # apply the pattern to a mesh
95 volsToSplit = Mesh_3.GetElementsByType(SMESH.VOLUME)
96 print "Splitting %d hexa volume(s) to %d hexas..."%(len(volsToSplit), 4*len(volsToSplit))
97 pattern_hexa.ApplyToHexahedrons(Mesh_3.GetMesh(), volsToSplit,0,3)
98 isDone = pattern_hexa.MakeMesh(Mesh_3.GetMesh(), True, True)
99 if (isDone != 1): print 'MakeMesh :', pattern_hexa.GetErrorCode()
100 
101 # create one more quadrangle mesh
102 Mesh_4 = smesh.Mesh(Box_1)
103 Mesh_4.Segment().NumberOfSegments(1)
104 Mesh_4.Quadrangle()
105 Mesh_4.Hexahedron()
106 isDone = Mesh_4.Compute()
107 if not isDone: print 'Mesh Mesh_4 : computation failed'
108 
109 # create another 3d pattern (pyramids)
110 pattern_pyra = smesh.GetPattern()
111 
112 smp_pyra = """!!! Nb of points:
113 9
114  0 0 0 !- 0
115  1 0 0 !- 1
116  0 1 0 !- 2
117  1 1 0 !- 3
118  0 0 1 !- 4
119  1 0 1 !- 5
120  0 1 1 !- 6
121  1 1 1 !- 7
122  0.5 0.5 0.5 !- 8
123  !!! Indices of points of 6 elements:
124  0 1 5 4 8
125  7 5 1 3 8
126  3 2 6 7 8
127  2 0 4 6 8
128  0 2 3 1 8
129  4 5 7 6 8"""
130 
131 pattern_pyra.LoadFromFile(smp_pyra)
132 
133 # apply the pattern to a face mesh
134 volsToSplit = Mesh_4.GetElementsByType(SMESH.VOLUME)
135 print "Splitting %d hexa volume(s) to %d hexas..."%(len(volsToSplit), 6*len(volsToSplit))
136 pattern_pyra.ApplyToHexahedrons(Mesh_4.GetMesh(), volsToSplit,1,0)
137 isDone = pattern_pyra.MakeMesh(Mesh_4.GetMesh(), True, True)
138 if (isDone != 1): print 'MakeMesh :', pattern_pyra.GetErrorCode()

Download this script


Convert mesh to/from quadratic

1 # Convert mesh to/from quadratic
2 
3 
4 import salome
5 salome.salome_init()
6 import GEOM
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New(salome.myStudy)
9 
10 import SMESH, SALOMEDS
11 from salome.smesh import smeshBuilder
12 smesh = smeshBuilder.New(salome.myStudy)
13 
14 # create sphere of radius 100
15 
16 Sphere = geompy.MakeSphereR( 100 )
17 geompy.addToStudy( Sphere, "Sphere" )
18 
19 # create simple trihedral mesh
20 
21 Mesh = smesh.Mesh(Sphere)
22 Regular_1D = Mesh.Segment()
23 Nb_Segments = Regular_1D.NumberOfSegments(5)
24 MEFISTO_2D = Mesh.Triangle()
25 Tetrahedron = Mesh.Tetrahedron()
26 
27 # compute mesh
28 
29 isDone = Mesh.Compute()
30 
31 # convert to quadratic
32 # theForce3d = 1; this results in the medium node lying at the
33 # middle of the line segments connecting start and end node of a mesh
34 # element
35 
36 Mesh.ConvertToQuadratic( theForce3d=1 )
37 
38 # revert back to the non-quadratic mesh
39 
40 Mesh.ConvertFromQuadratic()
41 
42 # convert to quadratic
43 # theForce3d = 0; this results in the medium node lying at the
44 # geometrical edge from which the mesh element is built
45 
46 Mesh.ConvertToQuadratic( theForce3d=0 )
47 
48 # to convert not the whole mesh but a sub-mesh, provide it as
49 # an additional argument to the functions:
50 # Mesh.ConvertToQuadratic( 0, subMesh )
51 # Mesh.ConvertFromQuadratic( subMesh )
52 #
53 # Note that the mesh becomes non-conformal at conversion of sub-mesh.

Download this script


Split bi-quadratic into linear

1 # Split bi-quadratic to linear
2 
3 import salome
4 salome.salome_init()
5 
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 from salome.smesh import smeshBuilder
10 smesh = smeshBuilder.New(salome.myStudy)
11 
12 # make a shape consisting of two quadranges
13 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
14 OY1 = geompy.MakeTranslation( OY, 1, 0, 0 )
15 OY2 = geompy.MakeTranslation( OY, 2, 0, 0 )
16 q1 = geompy.MakeQuad2Edges( OY, OY1 )
17 q2 = geompy.MakeQuad2Edges( OY1, OY2 )
18 
19 shape = geompy.Partition( [q1,q2], theName='shape' )
20 ff = geompy.SubShapeAll( shape, geompy.ShapeType["FACE"], theName="quad" )
21 
22 # mesh one quadrange with quadrangless and the other with triangles
23 mesh = smesh.Mesh( shape )
24 mesh.Segment().NumberOfSegments(1)
25 mesh.Quadrangle()
26 mesh.Triangle( ff[1] )
27 mesh.Compute()
28 
29 # make group of quadrangles and extrude them into a hexahedron
30 quadGroup = mesh.Group( ff[0], "quads")
31 mesh.ExtrusionSweepObject2D( quadGroup, [0,0,1], 1 )
32 
33 # make the mesh bi-quadratic
34 mesh.ConvertToQuadratic( theToBiQuad=True )
35 
36 # split all elements into linear ones
37 mesh.SplitBiQuadraticIntoLinear()

Download this script