1 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 def GetNewNodes(mesh,Elems,OldNodes):
27 Auxilary function, which return list of nodes from
28 given Elems avoided nodes from OldNodes
32 nbn = mesh.GetElemNbNodes(i)
33 for j in range(0,nbn):
34 nn = mesh.GetElemNode(i,j)
36 for k in range(0,len(newnodes)):
42 for k in range(0,len(OldNodes)):
59 # create a cross from quadrangle faces
60 # 1. create first edge and make extrusion along 0x
61 n1 = mesh.AddNode(55,-5,0)
62 n2 = mesh.AddNode(55,5,0)
63 e1 = mesh.AddEdge([n1,n2])
64 dir1 = smesh.DirStruct(smesh.PointStruct(-10,0,0))
65 mesh.ExtrusionSweep([e1],dir1,11)
66 # 2. create second edge and make extrusion along 0y
67 n3 = mesh.AddNode(-5,-55,0)
68 n4 = mesh.AddNode(5,-55,0)
69 e2 = mesh.AddEdge([n3,n4])
70 dir2 = smesh.DirStruct(smesh.PointStruct(0,10,0))
71 mesh.ExtrusionSweep([e2],dir2,11)
73 # since result has coincident nodes and faces
74 # we have to make merge
75 nodes = mesh.FindCoincidentNodes(0.001)
76 mesh.MergeNodes(nodes)
77 mesh.MergeEqualElements()
79 # make extrusion faces along 0z
80 faces = mesh.GetElementsByType(smesh.FACE)
85 dir3 = smesh.DirStruct(smesh.PointStruct(0,0,zstep))
86 newfaces = [] # list for keeping created top faces
89 for i in range(0,nbzsteps):
90 mesh.ExtrusionSweep(faces,dir3,1)
91 # find top faces after each extrusion and keep them
92 res = mesh.GetLastCreatedElems()
96 nbn = mesh.GetElemNbNodes(j)
98 nn1 = mesh.GetElemNode(j,0)
99 xyz1 = mesh.GetNodeXYZ(nn1)
100 nn2 = mesh.GetElemNode(j,1)
101 xyz2 = mesh.GetNodeXYZ(nn2)
102 nn3 = mesh.GetElemNode(j,2)
103 xyz3 = mesh.GetNodeXYZ(nn3)
104 if abs(xyz1[2]-xyz2[2])<tol and abs(xyz1[2]-xyz3[2])<tol :
105 # this face is a top face
110 print "len(nfaces)!=nbf"
112 newfaces.append(nfaces)
113 # update faces for before next step of extrusion
117 # rotate faces from newfaces
118 axisr1 = smesh.AxisStruct(0,0,0,0,0,1)
119 for i in range(0,nbzsteps):
120 ang = maxang*(1-math.cos((i+1)*math.pi/nbzsteps))
121 mesh.Rotate(newfaces[i],axisr1,ang,0)
125 # create two edges and rotate them for creation
127 n5 = mesh.AddNode(65,0,0)
128 n6 = mesh.AddNode(67.5,0,0)
129 n7 = mesh.AddNode(70,0,0)
130 e56 = mesh.AddEdge([n5,n6])
131 e67 = mesh.AddEdge([n6,n7])
132 axisr2 = smesh.AxisStruct(65,0,0,0,1,0)
133 mesh.RotationSweep([e56,e67],axisr2, math.pi/6, 12, tol)
134 res = mesh.GetLastCreatedElems()
137 nbn = mesh.GetElemNbNodes(i)
138 if nbn>2: faces1.append(i)
142 # create other two edges and rotate them for creation
144 n8 = mesh.AddNode(-65,0,0)
145 n9 = mesh.AddNode(-67.5,0,0)
146 n10 = mesh.AddNode(-70,0,0)
147 e8 = mesh.AddEdge([n8,n9])
148 e9 = mesh.AddEdge([n9,n10])
149 axisr3 = smesh.AxisStruct(-65,0,0,0,-1,0)
150 mesh.RotationSweep([e8,e9],axisr3, math.pi/6, 12, tol)
151 res = mesh.GetLastCreatedElems()
154 nbn = mesh.GetElemNbNodes(i)
155 if nbn>2: faces2.append(i)
159 # there are coincident nodes after rotation
160 # therefore we have to merge nodes
161 nodes = mesh.FindCoincidentNodes(0.001)
162 mesh.MergeNodes(nodes)
166 nbrs = nbcircs*nbrsteps
167 dz = nbzsteps*zstep/nbrs
169 # create first spiral
171 newnodes = GetNewNodes(mesh,faces1,oldnodes)
175 mesh.RotationSweep(faces1,axisr1, math.pi*2/nbrsteps, nbrs, tol)
176 res = mesh.GetLastCreatedElems()
178 for i in range(0,nbrs):
180 for j in range(0,nbf1): volumes.append(res[i+j*nbrs])
181 newnodes = GetNewNodes(mesh,volumes,oldnodes)
183 xyz = mesh.GetNodeXYZ(j)
184 mesh.MoveNode(j,xyz[0],xyz[1],xyz[2]+dz*(i+1))
189 # create second spiral
191 newnodes = GetNewNodes(mesh,faces2,oldnodes)
195 mesh.RotationSweep(faces2,axisr1, math.pi*2/nbrsteps, nbrs, tol)
196 res = mesh.GetLastCreatedElems()
198 for i in range(0,nbrs):
200 for j in range(0,nbf2): volumes.append(res[i+j*nbrs])
201 newnodes = GetNewNodes(mesh,volumes,oldnodes)
203 xyz = mesh.GetNodeXYZ(j)
204 mesh.MoveNode(j,xyz[0],xyz[1],xyz[2]+dz*(i+1))
209 smesh.salome.sg.updateObjBrowser(1)