- Timestamp:
- Sep 4, 2009, 6:22:15 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/general_mesh.py
r7317 r7484 144 144 self.edgelengths = num.zeros((N, 3), num.float) 145 145 146 # Get x,y coordinates for all triangle s and store146 # Get x,y coordinates for all triangle vertices and store 147 147 self.vertex_coordinates = V = self.compute_vertex_coordinates() 148 149 # Get x,y coordinates for all triangle edge midpoints and store 150 self.edge_midpoint_coordinates = self.compute_edge_midpoint_coordinates() 148 151 149 152 # Initialise each triangle … … 327 330 return V[j,:] 328 331 332 333 329 334 def compute_vertex_coordinates(self): 330 335 """Return all vertex coordinates for all triangles as a 3*M x 2 array … … 344 349 345 350 return vertex_coordinates 351 352 353 def get_edge_midpoint_coordinates(self, triangle_id=None, absolute=False): 354 """Return edge midpoint coordinates for all triangles or from particular triangle. 355 356 Return all edge midpoint coordinates for all triangles as a 3*M x 2 array 357 where the jth midpoint of the ith triangle is located in row 3*i+j and 358 M the number of triangles in the mesh. 359 360 if triangle_id is specified (an integer) the 3 midpoint coordinates 361 for triangle_id are returned. 362 363 Boolean keyword argument absolute determines whether coordinates 364 are to be made absolute by taking georeference into account 365 Default is False as many parts of ANUGA expects relative coordinates. 366 """ 367 368 E = self.edge_midpoint_coordinates 369 370 if triangle_id is None: 371 if absolute is True: 372 if not self.geo_reference.is_absolute(): 373 E = self.geo_reference.get_absolute(E) 374 return E 375 else: 376 i = triangle_id 377 msg = 'triangle_id must be an integer' 378 assert int(i) == i, msg 379 assert 0 <= i < self.number_of_triangles 380 381 i3 = 3*i 382 if absolute is True and not self.geo_reference.is_absolute(): 383 offset=num.array([self.geo_reference.get_xllcorner(), 384 self.geo_reference.get_yllcorner()], num.float) 385 return num.array([E[i3,:]+offset, 386 E[i3+1,:]+offset, 387 E[i3+2,:]+offset], num.float) 388 else: 389 return num.array([E[i3,:], E[i3+1,:], E[i3+2,:]], num.float) 390 391 392 def get_edge_midpoint_coordinate(self, i, j, absolute=False): 393 """Return coordinates for edge midpoint j of the i'th triangle. 394 Return value is the numeric array slice [x, y] 395 """ 396 397 msg = 'edge midpoint id j must be an integer in [0,1,2]' 398 assert j in [0,1,2], msg 399 400 E = self.get_edge_midpoint_coordinates(triangle_id=i, absolute=absolute) 401 return E[j,:] 402 403 404 def compute_edge_midpoint_coordinates(self): 405 """Return all edge midpoint coordinates for all triangles as a 3*M x 2 array 406 where the jth edge midpoint of the ith triangle is located in row 3*i+j. 407 408 This function is used to precompute this important structure. Use 409 get_edge_midpoint_coordinates to retrieve the points. 410 411 Assumes that vertex_coordinates have been computed 412 """ 413 414 M = self.number_of_triangles 415 E = num.zeros((3*M, 2), num.float) 416 417 V = self.vertex_coordinates 418 419 V0 = V[0:3*M:3, :] 420 V1 = V[1:3*M:3, :] 421 V2 = V[2:3*M:3, :] 422 423 424 #print V.shape, V0.shape, V1.shape, V2.shape 425 426 #print E.shape, E[0:3*M:3, :].shape, E[1:3*M:3, :].shape, E[2:3*M:3, :].shape 427 E[0:3*M:3, :] = 0.5*(V1+V2) 428 E[1:3*M:3, :] = 0.5*(V2+V0) 429 E[2:3*M:3, :] = 0.5*(V0+V1) 430 431 return E 432 433 346 434 347 435 def get_triangles(self, indices=None):
Note: See TracChangeset
for help on using the changeset viewer.