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


Translation

1 # Translation
2 
3 import SMESH_mechanic
4 
5 mesh = SMESH_mechanic.mesh
6 
7 # define translation vector
8 vector = [-150., -150., 0.]
9 
10 # make a translated copy of all elements of the mesh
11 mesh.TranslateObject(mesh, vector, Copy=True)

Download this script


Rotation

1 # Rotation
2 
3 import math
4 
5 import SMESH_mechanic
6 import SMESH
7 
8 smesh = SMESH_mechanic.smesh
9 mesh = SMESH_mechanic.mesh
10 
11 # define rotation axis and angle
12 axisXYZ = SMESH.AxisStruct(0., 0., 0., 5., 5., 20.)
13 angle270 = 1.5 * math.pi
14 
15 # rotate a mesh
16 mesh.Rotate([], axisXYZ, angle270, 1)

Download this script


Scale

1 # Scale
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 import SMESH, SALOMEDS
10 from salome.smesh import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
12 
13 Box = geompy.MakeBoxDXDYDZ(200, 200, 200)
14 f = geompy.SubShapeAllSorted(Box, geompy.ShapeType["FACE"])
15 
16 Mesh1 = smesh.Mesh(f[0])
17 Regular_1D = Mesh1.Segment()
18 Nb_Segments_1 = Regular_1D.NumberOfSegments(3)
19 Nb_Segments_1.SetDistrType( 0 )
20 Quadrangle_2D = Mesh1.Quadrangle()
21 isDone = Mesh1.Compute()
22 
23 #Perform scale opration for the whole mesh and creation of a new mesh
24 newMesh = Mesh1.ScaleMakeMesh(Mesh1,SMESH.PointStruct(100,100,200),[0.5,0.3,0.7],True,"ScaledMesh")
25 
26 #Perform scale operation for the whole mesh and copy elements
27 Mesh1.Scale(Mesh1,SMESH.PointStruct(200,100,100),[0.5,0.5,0.5],True,True)
28 
29 #Perform scale opration for two edges and move elements
30 Mesh1.Scale([1,2],SMESH.PointStruct(-100,100,100),[0.8,1.0,0.7],False)
31 
32 #Perform scale opration for one face and move elements
33 Mesh1.Scale([21],SMESH.PointStruct(0,200,200),[0.7,0.7,0.7],False)

Download this script


Symmetry

1 # Symmetry
2 
3 import math
4 
5 import SMESH_mechanic
6 import SMESH
7 
8 smesh = SMESH_mechanic.smesh
9 mesh = SMESH_mechanic.mesh
10 
11 # create a symmetrical copy of the mesh mirrored through a point
12 axis = SMESH.AxisStruct(0, 0, 0, 0, 0, 0)
13 
14 mesh.Mirror([], axis, smesh.POINT, 1)

Download this script


Merging Nodes

1 # Merging Nodes
2 
3 import SMESH_mechanic, SMESH
4 mesh = SMESH_mechanic.mesh
5 
6 # merge nodes
7 Tolerance = 4.0
8 
9 # prevent nodes located on geom edges from removal during merge:
10 # create a group including all nodes on edges
11 allSegs = mesh.MakeGroup( "all segments", SMESH.EDGE, SMESH.FT_ElemGeomType,'=', SMESH.Geom_EDGE )
12 
13 GroupsOfNodes = mesh.FindCoincidentNodes(Tolerance)
14 mesh.MergeNodes(GroupsOfNodes, NodesToKeep=allSegs)

Download this script


Merging Elements

1 # Merging Elements
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 a face to be meshed
15 px = geompy.MakeVertex(100., 0. , 0. )
16 py = geompy.MakeVertex(0. , 100., 0. )
17 pz = geompy.MakeVertex(0. , 0. , 100.)
18 
19 vxy = geompy.MakeVector(px, py)
20 arc = geompy.MakeArc(py, pz, px)
21 
22 wire = geompy.MakeWire([vxy, arc])
23 isPlanarFace = 1
24 
25 face1 = geompy.MakeFace(wire, isPlanarFace)
26 id_face1 = geompy.addToStudy(face1, "Face1")
27 
28 # create a circle to be an extrusion path
29 px1 = geompy.MakeVertex( 100., 100., 0.)
30 py1 = geompy.MakeVertex(-100., -100., 0.)
31 pz1 = geompy.MakeVertex( 0., 0., 50.)
32 
33 circle = geompy.MakeCircleThreePnt(py1, pz1, px1)
34 id_circle = geompy.addToStudy(circle, "Path")
35 
36 # create a 2D mesh on the face
37 trias = smesh.Mesh(face1, "Face : 2D mesh")
38 
39 algo1D = trias.Segment()
40 algo1D.NumberOfSegments(6)
41 algo2D = trias.Triangle()
42 algo2D.LengthFromEdges()
43 
44 trias.Compute()
45 
46 # create a path mesh
47 circlemesh = smesh.Mesh(circle, "Path mesh")
48 algo = circlemesh.Segment()
49 algo.NumberOfSegments(10)
50 circlemesh.Compute()
51 
52 # extrusion of the mesh
53 trias.ExtrusionAlongPath([], circlemesh, circle,
54  1, 0, [], 0, SMESH.PointStruct(0, 0, 0))
55 
56 # merge nodes
57 print "Number of nodes before MergeNodes:",
58 trias.NbNodes()
59 tolerance = 0.001
60 array_of_nodes_groups = trias.FindCoincidentNodes(tolerance)
61 
62 trias.MergeNodes(array_of_nodes_groups)
63 
64 print "Number of nodes after MergeNodes:", trias.NbNodes()
65 print ""
66 print "Number of elements before MergeEqualElements:"
67 print "Edges : ", trias.NbEdges()
68 print "Triangles : ", trias.NbTriangles()
69 print "Quadrangles: ", trias.NbQuadrangles()
70 print "Volumes : ", trias.NbVolumes()
71 
72 # merge elements
73 trias.MergeEqualElements()
74 print "Number of elements after MergeEqualElements:"
75 print "Edges : ", trias.NbEdges()
76 print "Triangles : ", trias.NbTriangles()
77 print "Quadrangles: ", trias.NbQuadrangles()
78 print "Volumes : ", trias.NbVolumes()
79 
80 salome.sg.updateObjBrowser(True)

Download this script


Sew Meshes Border to Side

1 # Sew Meshes Border to Side
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 two faces of a box
15 box1 = geompy.MakeBox(0., 0., -10., 30., 20., 25.)
16 facesList1 = geompy.SubShapeAll(box1, geompy.ShapeType["FACE"])
17 face1 = facesList1[2]
18 
19 box2 = geompy.MakeBox(0., 5., 0., 20., 20., 15.)
20 facesList2 = geompy.SubShapeAll(box2, geompy.ShapeType["FACE"])
21 face2 = facesList2[1]
22 
23 edgesList = geompy.SubShapeAll(face2, geompy.ShapeType["EDGE"])
24 edge1 = edgesList[2]
25 
26 aComp = geompy.MakeCompound([face1, face2])
27 geompy.addToStudy(aComp, "Two faces")
28 
29 # create a mesh on two faces
30 mesh = smesh.Mesh(aComp, "Two faces : quadrangle mesh")
31 
32 algo1D = mesh.Segment()
33 algo1D.NumberOfSegments(9)
34 algo2D = mesh.Quadrangle()
35 
36 algo_local = mesh.Segment(edge1)
37 algo_local.Arithmetic1D(1, 4)
38 algo_local.Propagation()
39 
40 mesh.Compute()
41 
42 # sew border to side
43 # FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
44 # FirstNodeIDOnSide, LastNodeIDOnSide,
45 # CreatePolygons, CreatePolyedrs
46 mesh.SewBorderToSide(5, 45, 6, 113, 109, 0, 0)

Download this script


Sew Conform Free Borders

1 # Sew Conform Free Borders
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 two faces of the box
17 box1 = geompy.MakeBox(0., 0., -10., 20., 20., 15.)
18 facesList1 = geompy.SubShapeAll(box1, geompy.ShapeType["FACE"])
19 face1 = facesList1[2]
20 
21 box2 = geompy.MakeBox(0., 5., 0., 20., 20., 15.)
22 facesList2 = geompy.SubShapeAll(box2, geompy.ShapeType["FACE"])
23 face2 = facesList2[1]
24 
25 edgesList = geompy.SubShapeAll(face2, geompy.ShapeType["EDGE"])
26 edge1 = edgesList[2]
27 
28 aComp = geompy.MakeCompound([face1, face2])
29 geompy.addToStudy(aComp, "Two faces")
30 
31 # create a mesh on two faces
32 mesh = smesh.Mesh(aComp, "Two faces : quadrangle mesh")
33 
34 algo1D = mesh.Segment()
35 algo1D.NumberOfSegments(9)
36 algo2D = mesh.Quadrangle()
37 
38 algo_local = mesh.Segment(edge1)
39 algo_local.Arithmetic1D(1, 4)
40 algo_local.Propagation()
41 
42 mesh.Compute()
43 
44 # sew conform free borders
45 # FirstNodeID1, SecondNodeID1, LastNodeID1, FirstNodeID2, SecondNodeID2
46 mesh.SewConformFreeBorders(5, 45, 6, 3, 24)

Download this script


Sew Free Borders

1 # Sew Free Borders
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 # make two not sewed quadranges
15 OY0 = geompy.MakeVectorDXDYDZ(0, 1, 0)
16 OY1 = geompy.MakeTranslation( OY0, 1, 0, 0, theName="OY1" )
17 OY2 = geompy.MakeTranslation( OY0, 1.01, 0, 0, theName="OY2" )
18 OY3 = geompy.MakeTranslation( OY0, 2, 0, 0 )
19 q1 = geompy.MakeQuad2Edges( OY0, OY1 )
20 q2 = geompy.MakeQuad2Edges( OY2, OY3 )
21 
22 shape = geompy.MakeCompound( [q1,q2], theName='shape' )
23 
24 # make a non-uniform quadrangle mesh on two faces
25 mesh = smesh.Mesh(shape, "Two faces : quadrangle mesh")
26 mesh.Segment().Arithmetic1D( 0.1, 0.4 )
27 mesh.Segment(q1).NumberOfSegments( 5 )
28 mesh.Quadrangle()
29 mesh.Compute()
30 
31 # sew free borders
32 
33 segs1 = mesh.GetSubMeshElementsId( OY1 ) # mesh segments generated on borders
34 segs2 = mesh.GetSubMeshElementsId( OY2 )
35 
36 FirstNodeID1 = mesh.GetElemNode( segs1[0], 0 )
37 SecondNodeID1 = mesh.GetElemNode( segs1[0], 1 )
38 LastNodeID1 = mesh.GetElemNode( segs1[-1], 1 )
39 FirstNodeID2 = mesh.GetElemNode( segs2[0], 0 )
40 SecondNodeID2 = mesh.GetElemNode( segs2[0], 1 )
41 LastNodeID2 = mesh.GetElemNode( segs2[-1], 1 )
42 CreatePolygons = True
43 CreatePolyedrs = False
44 
45 res = mesh.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
46  FirstNodeID2, SecondNodeID2, LastNodeID2,
47  CreatePolygons, CreatePolyedrs )
48 print res
49 print "nb polygons:", mesh.NbPolygons()
50 

Download this script


Sew Side Elements

1 # Sew Side Elements
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 import SMESH, SALOMEDS
10 from salome.smesh import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
12 
13 # create two boxes
14 box1 = geompy.MakeBox(0., 0., 0., 10., 10., 10.)
15 box2 = geompy.MakeBox(0., 15., 0., 20., 25., 10.)
16 
17 EdgesList = geompy.SubShapeAll(box2, geompy.ShapeType["EDGE"])
18 
19 aComp = geompy.MakeCompound([box1, box2])
20 geompy.addToStudy(aComp, "Two boxes")
21 
22 # create a mesh on two boxes
23 mesh = smesh.Mesh(aComp, "Sew Side Elements")
24 
25 algo1D = mesh.Segment()
26 algo1D.NumberOfSegments(2)
27 algo2D = mesh.Quadrangle()
28 
29 algo_local = mesh.Segment(EdgesList[8])
30 algo_local.NumberOfSegments(4)
31 algo_local.Propagation()
32 
33 mesh.Compute()
34 
35 # sew side elements
36 
37 # find elements to sew
38 face1 = geompy.GetFaceNearPoint( aComp, geompy.MakeVertex( 5, 10, 5 ))
39 IDsOfSide1Elements = mesh.GetSubMeshElementsId( face1 )
40 print "side faces 1:",IDsOfSide1Elements
41 
42 face1Translated = geompy.MakeTranslation( face1, 0,5,0 )
43 faceFilter = smesh.GetFilter( SMESH.FACE, SMESH.FT_BelongToGeom,'=', face1Translated )
44 IDsOfSide2Elements = mesh.GetIdsFromFilter( faceFilter )
45 print "side faces 2:",IDsOfSide2Elements
46 
47 # find corresponding nodes on sides
48 edge1 = geompy.GetEdgeNearPoint( aComp, geompy.MakeVertex( 0, 10, 5 ))
49 segs1 = mesh.GetSubMeshElementsId( edge1 ) # mesh segments generated on edge1
50 NodeID1OfSide1ToMerge = mesh.GetElemNode( segs1[0], 0 )
51 NodeID2OfSide1ToMerge = mesh.GetElemNode( segs1[0], 1 )
52 print "nodes of side1:", [NodeID1OfSide1ToMerge,NodeID2OfSide1ToMerge]
53 
54 edge2 = geompy.GetEdgeNearPoint( aComp, geompy.MakeVertex( 0, 15, 5 ))
55 segs2 = mesh.GetSubMeshElementsId( edge2 ) # mesh segments generated on edge2
56 NodeID1OfSide2ToMerge = mesh.GetElemNode( segs2[0], 0 )
57 NodeID2OfSide2ToMerge = mesh.GetElemNode( segs2[0], 1 )
58 print "nodes of side2:", [NodeID1OfSide2ToMerge,NodeID2OfSide2ToMerge]
59 
60 res = mesh.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
61  NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
62  NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
63 print res

Download this script


Duplicate nodes or/and elements

1 # Duplicate nodes or/and elements
2 
3 
4 import salome
5 salome.salome_init()
6 
7 import GEOM
8 from salome.geom import geomBuilder
9 geompy = geomBuilder.New(salome.myStudy)
10 
11 import SMESH
12 from salome.smesh import smeshBuilder
13 smesh = smeshBuilder.New(salome.myStudy)
14 
15 # Create a box
16 
17 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
18 
19 # Define hexa mesh on a box
20 mesh = smesh.Mesh(box, "Mesh")
21 mesh.Segment().NumberOfSegments(7)
22 mesh.Quadrangle()
23 mesh.Hexahedron()
24 
25 # Compute mesh
26 mesh.Compute()
27 
28 # Duplicate nodes only
29 
30 # Nodes to duplicate
31 nodes1 = mesh.CreateEmptyGroup( SMESH.NODE, 'nodes1' )
32 nodes1.Add( [ 119, 125, 131, 137 ] )
33 
34 # Group of faces to replace nodes with new ones
35 faces1 = mesh.CreateEmptyGroup( SMESH.FACE, 'faces1' )
36 faces1.Add( [ 144, 151, 158 ] )
37 
38 # Duplicate nodes
39 print "\nMesh before the first nodes duplication:"
40 print "Nodes : ", mesh.NbNodes()
41 print "Edges : ", mesh.NbEdges()
42 print "Quadrangles : ", mesh.NbQuadrangles()
43 
44 groupOfCreatedNodes = mesh.DoubleNodeGroup(nodes1, faces1, theMakeGroup=True)
45 print "New nodes:", groupOfCreatedNodes.GetIDs()
46 
47 print "\nMesh after the first nodes duplication:"
48 print "Nodes : ", mesh.NbNodes()
49 print "Edges : ", mesh.NbEdges()
50 print "Quadrangles : ", mesh.NbQuadrangles()
51 
52 # Duplicate nodes and border elements
53 
54 # Edges to duplicate
55 edges = mesh.CreateEmptyGroup( SMESH.EDGE, 'edges' )
56 edges.Add( [ 32, 33, 34 ] )
57 
58 # Nodes not to duplicate
59 nodes2 = mesh.CreateEmptyGroup( SMESH.NODE, 'nodes2' )
60 nodes2.Add( [ 35, 38 ] )
61 
62 # Group of faces to replace nodes with new ones
63 faces2 = mesh.CreateEmptyGroup( SMESH.FACE, 'faces2' )
64 faces2.Add( [ 141, 148, 155 ] )
65 
66 # Duplicate nodes
67 print "\nMesh before the second nodes duplication:"
68 print "Nodes : ", mesh.NbNodes()
69 print "Edges : ", mesh.NbEdges()
70 print "Quadrangles : ", mesh.NbQuadrangles()
71 
72 groupOfNewEdges = mesh.DoubleNodeElemGroup( edges, nodes2, faces2, theMakeGroup=True )
73 print "New edges:", groupOfNewEdges.GetIDs()
74 
75 print "\nMesh after the second nodes duplication:"
76 print "Nodes : ", mesh.NbNodes()
77 print "Edges : ", mesh.NbEdges()
78 print "Quadrangles : ", mesh.NbQuadrangles()
79 
80 
81 # Duplicate elements only
82 
83 # Duplicate all faces and make a group of new faces.
84 # If a mesh is given to DoubleElements(), all elements of the greatest dimension are duplicated
85 newFacesGroup = mesh.DoubleElements( mesh, "newFacesGroup" )
86 
87 # Duplicate edges contained in the group "edges" and add new edges to this group
88 mesh.DoubleElements( edges, edges.GetName() )
89 
90 # Duplicate two first edges of the mesh
91 mesh.DoubleElements([ 1, 2 ])
92 
93 # Update object browser
94 if salome.sg.hasDesktop():
95  salome.sg.updateObjBrowser(False)

Download this script


Create boundary elements

1 # Create boundary elements
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 box = geompy.MakeBoxDXDYDZ(100, 100, 100)
17 gFaces = geompy.SubShapeAllSorted(box, geompy.ShapeType["FACE"])
18 f1,f2 = gFaces[0],gFaces[1]
19 geompy.addToStudy(box,"box")
20 geompy.addToStudyInFather(box,f1,"face1")
21 geompy.addToStudyInFather(box,f2,"face2")
22 
23 twoFaces = geompy.MakeCompound([f1,f2])
24 
25 ## -----------
26 ##
27 ## 2D from 3D
28 ##
29 ## -----------
30 dim = SMESH.BND_2DFROM3D
31 
32 init_mesh = smesh.Mesh(box, "box")
33 init_mesh.AutomaticHexahedralization() # it makes 3 x 3 x 3 hexahedrons
34 
35 # remove some faces
36 faces = init_mesh.GetElementsByType( SMESH.FACE )
37 nb_faces = len( faces )
38 rm_face = faces[ : nb_faces/2]
39 init_mesh.RemoveElements( rm_face )
40 
41 # restore boundary in this mesh
42 mesh = smesh.CopyMesh( init_mesh, "2D from 3D")
43 groupName = "bnd 2D"
44 nb, new_mesh, new_group = mesh.MakeBoundaryElements(dim, groupName)
45 
46 # restore boundary (only) in other mesh
47 meshName = "2D boundary of " + init_mesh.GetName()
48 nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName)
49 
50 # restore boundary in mesh copy
51 meshName = init_mesh.GetName() + " + boundary"
52 nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName, toCopyAll=True)
53 
54 
55 ## -----------
56 ##
57 ## 1D from 2D
58 ##
59 ## -----------
60 dim = SMESH.BND_1DFROM2D
61 
62 init_mesh = smesh.Mesh(f1, "2D mesh")
63 init_mesh.AutomaticHexahedralization()
64 
65 # remove some edges
66 edges = init_mesh.GetElementsByType( SMESH.EDGE )
67 nb_edges = len( edges )
68 rm_edge = edges[ : nb_edges/2]
69 init_mesh.RemoveElements( rm_edge )
70 
71 
72 # restore boundary edges in this mesh
73 mesh = smesh.CopyMesh( init_mesh, "1D from 2D")
74 groupName = "bnd 1D"
75 nb, new_mesh, new_group = mesh.MakeBoundaryElements(dim, groupName)
76 
77 # restore boundary edges (only) in other mesh
78 meshName = "1D boundary of " + init_mesh.GetName()
79 nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName)
80 
81 # restore boundary edges in mesh copy
82 meshName = init_mesh.GetName() + " + boundary"
83 nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName, toCopyAll=True)
84 
85 
86 
87 ## ------------------
88 ##
89 ## 1D from 2D GROUPS
90 ##
91 ## ------------------
92 dim = SMESH.BND_1DFROM3D
93 
94 init_mesh = smesh.Mesh(box, "box")
95 init_mesh.AutomaticHexahedralization() # it makes 3 x 3 x 3 hexahedrons
96 # remove all edges
97 rm_edges = init_mesh.GetElementsByType( SMESH.EDGE )
98 init_mesh.RemoveElements( rm_edges )
99 
100 # make groups of faces
101 fGroup1 = init_mesh.Group( f1, "f1" )
102 fGroup2 = init_mesh.Group( f2, "f2" )
103 
104 # make 1D boundary around groups in this mesh
105 mesh = smesh.CopyMesh( init_mesh, "1D from 2D groups", toCopyGroups=True)
106 groups = mesh.GetGroups()
107 nb, new_mesh, new_group = mesh.MakeBoundaryElements(dim, groupName,groups=groups)
108 
109 # make 1D boundary (only) in other mesh
110 meshName = "boundary from groups of " + init_mesh.GetName()
111 groups = init_mesh.GetGroups()
112 nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName,groups=groups)
113 
114 # make 1D boundary in mesh copy
115 meshName = init_mesh.GetName() + " + boundary from groups"
116 nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName,
117  groups=groups, toCopyAll=True)
118 

Download this script


Reorient faces

1 # Reorient faces
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 a geometry consisting of two faces
17 box = geompy.MakeBoxDXDYDZ( 10, 10, 10 )
18 faces = geompy.SubShapeAllSorted( box, geompy.ShapeType["FACE"])
19 
20 shape = geompy.MakeCompound( faces[:2] )
21 faces = geompy.SubShapeAll( shape, geompy.ShapeType["FACE"] )
22 geompy.addToStudy( shape, "shape")
23 geompy.addToStudyInFather( shape, faces[0], "faces[0]")
24 geompy.addToStudyInFather( shape, faces[1], "faces[1]")
25 
26 # create a 2D mesh
27 mesh = smesh.Mesh( shape, "test_Reorient2D")
28 mesh.AutomaticHexahedralization(0.5)
29 localAlgo = mesh.Segment(faces[0])
30 localAlgo.NumberOfSegments( 11 )
31 mesh.Compute()
32 group = mesh.Group( faces[1] )
33 
34 vec = geompy.MakeVectorDXDYDZ( 1, 1, 1 )
35 
36 # Each of arguments of Reorient2D() function can be of different types:
37 #
38 # 2DObject - the whole mesh
39 # Direction - a GEOM object (vector)
40 # FaceOrPoint - an ID of face
41 mesh.Reorient2D( mesh, vec, mesh.NbElements() )
42 #
43 # 2DObject - a sub-mesh
44 # Direction - components of a vector
45 # FaceOrPoint - a GEOM object (vertex)
46 mesh.Reorient2D( localAlgo.GetSubMesh(), [ 1, -1, 1 ], geompy.GetFirstVertex( vec ))
47 #
48 # 2DObject - a group of faces
49 # Direction - a SMESH.DirStruct structure
50 # FaceOrPoint - coordinates of a point
51 mesh.Reorient2D( group, smesh.MakeDirStruct( -10, 1, 10 ), [0,0,0])
52 #
53 # FaceOrPoint - a SMESH.PointStruct structure
54 mesh.Reorient2D( localAlgo.GetSubMesh().GetIDs(), [10,1,0], SMESH.PointStruct(0,0,0))
55 
56 
57 # Use Reorient2DBy3D() to orient faces of 2 geom faces to have their normal pointing inside volumes
58 
59 mesh3D = smesh.Mesh( box, '3D mesh')
60 mesh3D.AutomaticHexahedralization(0.5)
61 group0 = mesh3D.Group( faces[0] )
62 group1 = mesh3D.Group( faces[1] )
63 
64 # pass group0 and ids of faces of group1 to inverse
65 nbRev = mesh3D.Reorient2DBy3D([ group0, group1.GetIDs() ], mesh3D, theOutsideNormal=False)
66 print "Nb reoriented faces:", nbRev
67 
68 # orient the reversed faces back
69 nbRev = mesh3D.Reorient2DBy3D( mesh3D, mesh3D, theOutsideNormal=True)
70 print "Nb re-reoriented faces:", nbRev
71 

Download this script