Changeset 543
- Timestamp:
- Nov 15, 2004, 3:56:16 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/mesh_factory.py
r541 r543 164 164 165 165 166 167 def circular(m, n, radius=1.0, center = (0.0, 0.0)): 168 """Setup a circular grid of triangles with m concentric circles and 169 with n radial segments. If radius is are omitted the mesh defaults to 170 the unit circle radius. 171 172 radius: radius of circle 173 174 #FIXME: The triangles become degenerate for large values of m or n. 175 """ 176 177 178 179 from math import pi, cos, sin 180 181 radius = float(radius) #Ensure floating point format 182 183 #Dictionary of vertex objects and list of points 184 vertices = {} 185 points = [[0.0, 0.0]] #Center point 186 vertices[0, 0] = 0 187 188 for i in range(n): 189 theta = 2*i*pi/n 190 x = cos(theta) 191 y = sin(theta) 192 for j in range(1,m+1): 193 delta = j*radius/m 194 vertices[i,j] = len(points) 195 points.append([delta*x, delta*y]) 196 197 #Construct 2 triangles per element 198 elements = [] 199 for i in range(n): 200 for j in range(1,m): 201 202 i1 = (i + 1) % n #Wrap around 203 204 v1 = vertices[i,j+1] 205 v2 = vertices[i,j] 206 v3 = vertices[i1,j+1] 207 v4 = vertices[i1,j] 208 209 elements.append([v4,v2,v3]) #Lower 210 elements.append([v1,v3,v2]) #Upper 211 212 213 #Do the center 214 v1 = vertices[0,0] 215 for i in range(n): 216 i1 = (i + 1) % n #Wrap around 217 v2 = vertices[i,1] 218 v3 = vertices[i1,1] 219 220 elements.append([v1,v2,v3]) #center 221 222 return points, elements 223 224 166 225 def from_polyfile(name): 167 226 """Read mesh from .poly file, an obj like file format … … 335 394 return points, elements 336 395 337 338 339 #FIXME: These haven't been done yet340 # def circular_mesh(m, n, radius=1.0, center = (0.0, 0.0), Triangle=Triangle,341 # Mesh=Mesh, Point=Point):342 # """Setup a circular grid of triangles343 # with m+1 radial segments by n+1 points around the circuference344 # and radius. If radius is are omitted the mesh defaults to the unit circle345 # radius.346 347 # radius: radius of circle348 349 # Triangle refers to the actual class or subclass to be instantiated:350 # e.g. if Volume is a subclass of Triangle,351 # this function can be invoked with the keywords352 # rectangular_mesh(...,Triangle=Volume, Mesh=Domain)"""353 354 355 # from Numeric import array356 # from visual import rate357 # import math358 359 # delta = radius/float(m)360 361 # #Dictionary of vertex objects362 # vertices = {}363 # for i in range(n+1):364 # theta = float(i)*(2*math.pi)/float(n)365 # for j in range(m+1):366 # delta = float(j)*radius/float(m)367 # vertices[i,j] = Point(delta*math.cos(theta),delta*math.sin(theta))368 369 # #Construct 2 triangles per element370 # elements = []371 # for i in range(n):372 # for j in range(1,m):373 # v1 = vertices[i,j+1]374 # v2 = vertices[i,j]375 # v3 = vertices[i+1,j+1]376 # v4 = vertices[i+1,j]377 378 # elements.append(Triangle(v4,v2,v3)) #Lower379 # elements.append(Triangle(v1,v3,v2)) #Upper380 381 # #Do the center382 # v1 = vertices[0,0]383 # for i in range(n):384 # v2 = vertices[i,1]385 # v3 = vertices[i+1,1]386 387 # T = Triangle(v1,v2,v3) #center388 # elements.append(T)389 390 # return Mesh(elements)391 396 392 397
Note: See TracChangeset
for help on using the changeset viewer.