- Timestamp:
- Nov 9, 2006, 10:41:21 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/general_mesh.py
r3945 r3954 240 240 241 241 def get_nodes(self, absolute=False): 242 """Return all node coordinates ordered in an Nx2 array. 242 """Return all nodes in mesh. 243 244 The nodes are ordered in an Nx2 array where N is the number of nodes. 243 245 This is the same format they were provided in the constructor 244 246 i.e. without any duplication. … … 260 262 261 263 262 def get_vertex_coordinates(self, unique=False, absolute=False): 263 """Return all vertex coordinates. 264 Return all vertex coordinates for all triangles as a 3*N x 2 array 265 where the jth vertex of the ith triangle is located in row 3*i+j. 266 267 Boolean keyword unique will cause the points to be returned as 268 they were provided in the constructor i.e. without any duplication 269 in an N x 2 array. 270 271 """ 272 273 if unique is True: 274 return self.get_nodes(absolute) 275 276 277 V = self.vertex_coordinates 264 def get_vertex_coordinates(self, absolute=False): 265 """Return vertex coordinates for all triangles. 266 267 Return all vertex coordinates for all triangles as a 3*M x 2 array 268 where the jth vertex of the ith triangle is located in row 3*i+j and 269 M the number of triangles in the mesh. 270 271 Boolean keyword argument absolute determines whether coordinates 272 are to be made absolute by taking georeference into account 273 Default is False as many parts of ANUGA expects relative coordinates. 274 """ 275 276 277 278 V = self.vertex_coordinates #[:3*M,:] 278 279 if absolute is True: 279 280 if not self.geo_reference.is_absolute(): … … 294 295 295 296 def compute_vertex_coordinates(self): 296 """Return all vertex coordinates for all triangles as a 3* Nx 2 array297 """Return all vertex coordinates for all triangles as a 3*M x 2 array 297 298 where the jth vertex of the ith triangle is located in row 3*i+j. 298 299 … … 301 302 """ 302 303 303 N= self.number_of_triangles304 vertex_coordinates = zeros((3* N, 2), Float)305 306 for i in range( N):304 M = self.number_of_triangles 305 vertex_coordinates = zeros((3*M, 2), Float) 306 307 for i in range(M): 307 308 for j in range(3): 308 k = self.triangles[i,j] #Index of vertex 0 309 v_k = self.nodes[k] 310 311 vertex_coordinates[3*i+j,:] = v_k 312 309 k = self.triangles[i,j] # Index of vertex j in triangle i 310 vertex_coordinates[3*i+j,:] = self.nodes[k] 313 311 314 312 return vertex_coordinates 315 313 316 314 317 def get_vertices(self, indices=None): 318 """Get connectivity 319 indices is the set of element ids of interest 320 """ 321 322 N = self.number_of_full_triangles 315 316 def get_triangles(self, indices=None): 317 """Get mesh triangles. 318 319 Return Mx3 integer array where M is the number of triangles. 320 Each row corresponds to one triangle and the three entries are 321 indices into the mesh nodes which can be obtained using the method 322 get_nodes() 323 324 Optional argument, indices is the set of triangle ids of interest. 325 """ 326 327 M = self.number_of_full_triangles 323 328 324 329 if indices is None: 325 #indices = range(len(self)) #len(self)=number of elements 326 indices = range(N) 327 328 return take(self.triangles, indices) 330 indices = range(M) 331 332 return take(self.triangles, indices) 329 333 330 334 331 #FIXME - merge these two (get_vertices and get_triangles) 332 def get_triangles(self, obj=False): 333 """Get connetivity 334 Return triangles (triplets of indices into point coordinates) 335 336 If obj is True return structure commensurate with replicated 337 points, allowing for discontinuities 338 (FIXME: Need good name for this concept) 339 """ 340 341 if obj is True: 342 m = len(self) #Number of triangles 343 M = 3*m #Total number of unique vertices 344 T = reshape(array(range(M)).astype(Int), (m,3)) 345 else: 346 T = self.triangles 335 336 def get_disconnected_triangles(self): 337 """Get mesh based on nodes obtained from get_vertex_coordinates. 338 339 Return array Mx3 array of integers where each row corresponds to 340 a triangle. A triangle is a triplet of indices into 341 point coordinates obtained from get_vertex_coordinates and each 342 index appears only once 343 344 This provides a mesh where no triangles share nodes 345 (hence the name disconnected triangles) and different 346 nodes may have the same coordinates. 347 348 This version of the mesh is useful for storing meshes with 349 discontinuities at each node and is e.g. used for storing 350 data in sww files. 351 352 The triangles created will have the format 353 354 [[0,1,2], 355 [3,4,5], 356 [6,7,8], 357 ... 358 [3*M-3 3*M-2 3*M-1]] 359 """ 360 361 M = len(self) # Number of triangles 362 K = 3*M # Total number of unique vertices 363 T = reshape(array(range(K)).astype(Int), (M,3)) 347 364 348 365 return T … … 351 368 352 369 def get_unique_vertices(self, indices=None): 353 triangles = self.get_vertices(indices=indices) 370 """FIXME(Ole): This function needs a docstring 371 """ 372 triangles = self.get_triangles(indices=indices) 354 373 unique_verts = {} 355 374 for triangle in triangles: … … 361 380 362 381 def build_vertexlist(self): 363 """Build vertexlist index by vertex ids and for each entry (point id)382 """Build vertexlist indexed by vertex ids and for each entry (point id) 364 383 build a list of (triangles, vertex_id) pairs that use the point 365 384 as vertex. 366 385 386 The vertex list will have length N, where N is the number of nodes 387 in the mesh. 388 367 389 Preconditions: 368 390 self.nodes and self.triangles are defined … … 372 394 """ 373 395 374 vertexlist = [None]* len(self.nodes)396 vertexlist = [None]*self.number_of_nodes 375 397 for i in range(self.number_of_triangles): 376 398
Note: See TracChangeset
for help on using the changeset viewer.