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