Changeset 305
- Timestamp:
- Sep 15, 2004, 6:00:32 PM (21 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/least_squares.py
r304 r305 79 79 80 80 #Assign values to matrix 81 j = self. vertices[k,0] #Global vertex id81 j = self.triangles[k,0] #Global vertex id 82 82 self.matrix[i, j] = sigma0 83 83 84 j = self. vertices[k,1] #Global vertex id84 j = self.triangles[k,1] #Global vertex id 85 85 self.matrix[i, j] = sigma1 86 86 87 j = self. vertices[k,2] #Global vertex id87 j = self.triangles[k,2] #Global vertex id 88 88 self.matrix[i, j] = sigma2 89 89 -
inundation/ga/storm_surge/pyvolution/mesh.py
r303 r305 20 20 21 21 To instantiate: 22 Mesh(coordinates, vertices)22 Mesh(coordinates, triangles) 23 23 24 24 where … … 27 27 floats representing all x, y coordinates in the mesh. 28 28 29 vertices is either a list of 3-tuples or an Nx3 Numeric array of29 triangles is either a list of 3-tuples or an Nx3 Numeric array of 30 30 integers representing indices of all vertices in the mesh. 31 31 Each vertex is identified by its index i in [0, M-1]. … … 39 39 40 40 points = [a, b, c, e] 41 vertices = [ [1,0,2], [1,2,3] ] #bac, bce42 mesh = Mesh(points, vertices)41 triangles = [ [1,0,2], [1,2,3] ] #bac, bce 42 mesh = Mesh(points, triangles) 43 43 44 44 #creates two triangles: bac and bce … … 51 51 """ 52 52 53 def __init__(self, coordinates, vertices, boundary = None):53 def __init__(self, coordinates, triangles, boundary = None): 54 54 """ 55 55 Build triangles from x,y coordinates (sequence of 2-tuples or 56 Mx2 Numeric array of floats) and vertices (sequence of 3-tuples56 Mx2 Numeric array of floats) and triangles (sequence of 3-tuples 57 57 or Nx3 Numeric array of non-negative integers). 58 58 """ … … 60 60 from Numeric import array, zeros, Int, Float, maximum, sqrt, sum 61 61 62 self. vertices = array(vertices).astype(Int)62 self.triangles = array(triangles).astype(Int) 63 63 self.coordinates = array(coordinates) 64 64 65 65 #Input checks 66 msg = ' Vertices must an Nx2 Numeric array or a sequence of 2-tuples'67 assert len(self. vertices.shape) == 2, msg66 msg = 'Triangles must an Nx2 Numeric array or a sequence of 2-tuples' 67 assert len(self.triangles.shape) == 2, msg 68 68 69 69 msg = 'Coordinates must an Mx2 Numeric array or a sequence of 2-tuples' … … 71 71 72 72 msg = 'Vertex indices reference non-existing coordinate sets' 73 assert max(max(self. vertices)) <= self.coordinates.shape[0], msg73 assert max(max(self.triangles)) <= self.coordinates.shape[0], msg 74 74 75 75 76 76 #Register number of elements (N) 77 self.number_of_elements = N = self. vertices.shape[0]77 self.number_of_elements = N = self.triangles.shape[0] 78 78 79 79 #Allocate space for geometric quantities 80 self.centroid s = zeros((N, 2), Float)81 #FIXME: Should be renamed to centroid_coordinates 80 self.centroid_coordinates = zeros((N, 2), Float) 81 82 82 83 83 self.areas = zeros(N, Float) … … 92 92 self.normals = zeros((N, 6), Float) 93 93 94 #Get x,y coordinates for all vertices for all triangles 95 #and store 94 #Get x,y coordinates for all triangles and store 96 95 self.vertex_coordinates = V = self.compute_vertex_coordinates() 97 96 98 99 ##print 'Initialise mesh'100 97 #Initialise each triangle 101 98 for i in range(N): … … 108 105 #Compute centroid 109 106 centroid = array([(x0 + x1 + x2)/3, (y0 + y1 + y2)/3]) 110 self.centroid s[i] = centroid107 self.centroid_coordinates[i] = centroid 111 108 112 109 #Area … … 191 188 192 189 def __repr__(self): 193 return 'Mesh: %d vertices, %d elements, %d boundary segments'\190 return 'Mesh: %d triangles, %d elements, %d boundary segments'\ 194 191 %(self.coordinates.shape[0], len(self), len(self.boundary)) 195 192 … … 215 212 #Register all segments as keys mapping to current triangle 216 213 #and segment id 217 a = self. vertices[i, 0]218 b = self. vertices[i, 1]219 c = self. vertices[i, 2]214 a = self.triangles[i, 0] 215 b = self.triangles[i, 1] 216 c = self.triangles[i, 2] 220 217 neighbourdict[a,b] = (i, 2) #(id, edge) 221 218 neighbourdict[b,c] = (i, 0) #(id, edge) … … 227 224 #reverse direction of segments and lookup neighbours. 228 225 for i in range(N): 229 a = self. vertices[i, 0]230 b = self. vertices[i, 1]231 c = self. vertices[i, 2]226 a = self.triangles[i, 0] 227 b = self.triangles[i, 1] 228 c = self.triangles[i, 2] 232 229 233 230 self.number_of_boundaries[i] = 3 … … 255 252 256 253 Preconditions: 257 self.coordinates and self. vertices are defined254 self.coordinates and self.triangles are defined 258 255 259 256 Postcondition: … … 264 261 for i in range(self.number_of_elements): 265 262 266 a = self. vertices[i, 0]267 b = self. vertices[i, 1]268 c = self. vertices[i, 2]263 a = self.triangles[i, 0] 264 b = self.triangles[i, 1] 265 c = self.triangles[i, 2] 269 266 270 267 #Register the vertices v as lists of … … 462 459 #Check integrity of neighbour structure 463 460 for i in range(N): 464 for v in self. vertices[i, :]:461 for v in self.triangles[i, :]: 465 462 #Check that all vertices have been registered 466 463 assert self.vertexlist[v] is not None … … 546 543 for i in range(N): 547 544 for j in range(3): 548 k = self. vertices[i,j] #Index of vertex 0545 k = self.triangles[i,j] #Index of vertex 0 549 546 v_k = self.coordinates[k] 550 547 vertex_coordinates[i, 2*j+0] = v_k[0] … … 553 550 return vertex_coordinates 554 551 555 def get_ vertices(self, unique=False):552 def get_triangles(self, unique=False): 556 553 """Get connectivity 557 554 If unique is True give them only once as stored internally. … … 560 557 561 558 if unique is True: 562 return self. vertices559 return self.triangles 563 560 else: 564 561 from Numeric import reshape, array, Int … … 568 565 return reshape(array(range(M)).astype(Int), (m,3)) 569 566 567 568 570 569 #FIXME: May get rid of 571 570 def rectangular_mesh(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)): 572 571 from mesh_factory import rectangular 573 points, vertices, boundary = rectangular(m, n, len1, len2, origin)574 575 return Mesh(points, vertices, boundary)572 points, triangles, boundary = rectangular(m, n, len1, len2, origin) 573 574 return Mesh(points, triangles, boundary) 576 575 577 576 -
inundation/ga/storm_surge/pyvolution/quantity.py
r297 r305 143 143 144 144 if location == 'centroids': 145 P = self.domain.centroid s145 P = self.domain.centroid_coordinates 146 146 self.set_values(f(P[:,0], P[:,1]), location) 147 147 elif location == 'edges': … … 282 282 283 283 #Create connectivity 284 V = self.domain.get_ vertices(unique=smooth)284 V = self.domain.get_triangles(unique=smooth) 285 285 286 286 if smooth == True: … … 448 448 for k in range(quantity.domain.number_of_elements): 449 449 #Centroid coordinates 450 x, y = quantity.domain.centroid s[k]450 x, y = quantity.domain.centroid_coordinates[k] 451 451 452 452 #vertex coordinates … … 469 469 from util import gradient 470 470 471 centroid s = quantity.domain.centroids471 centroid_coordinates = quantity.domain.centroid_coordinates 472 472 surrogate_neighbours = quantity.domain.surrogate_neighbours 473 473 centroid_values = quantity.centroid_values … … 491 491 q2 = centroid_values[k2] 492 492 493 x0, y0 = centroid s[k0] #V0 centroid494 x1, y1 = centroid s[k1] #V1 centroid495 x2, y2 = centroid s[k2] #V2 centroid493 x0, y0 = centroid_coordinates[k0] #V0 centroid 494 x1, y1 = centroid_coordinates[k1] #V1 centroid 495 x2, y2 = centroid_coordinates[k2] #V2 centroid 496 496 497 497 #Gradient … … 512 512 q1 = centroid_values[k1] 513 513 514 x0, y0 = centroid s[k0] #V0 centroid515 x1, y1 = centroid s[k1] #V1 centroid514 x0, y0 = centroid_coordinates[k0] #V0 centroid 515 x1, y1 = centroid_coordinates[k1] #V1 centroid 516 516 517 517 #Gradient -
inundation/ga/storm_surge/pyvolution/quantity_ext.c
r272 r305 298 298 299 299 //Get pertinent variables 300 centroids = (PyArrayObject*) PyObject_GetAttrString(domain, "centroids"); 300 centroids = (PyArrayObject*) 301 PyObject_GetAttrString(domain, "centroid_coordinates"); 301 302 if (!centroids) return NULL; 302 303 … … 378 379 379 380 //Get pertinent variables 380 centroids = (PyArrayObject*) PyObject_GetAttrString(domain, "centroids"); 381 centroids = (PyArrayObject*) 382 PyObject_GetAttrString(domain, "centroid_coordinates"); 381 383 if (!centroids) return NULL; 382 384 -
inundation/ga/storm_surge/pyvolution/show_balanced_limiters.py
r287 r305 38 38 domain.visualise = True 39 39 domain.default_order = 2 40 41 #domain.store = True 40 domain.filename = 'test_of_pyvolution' 41 domain.store = True 42 domain.format = 'sww' #Native netcdf visualisation format 42 43 43 44 #Set bed-slope and friction -
inundation/ga/storm_surge/pyvolution/test_least_squares.py
r301 r305 24 24 c = [2.0,0.0] 25 25 points = [a, b, c] 26 vertices = [ [1,0,2] ] #bac26 triangles = [ [1,0,2] ] #bac 27 27 28 28 data = [ [2.0/3, 2.0/3] ] #Use centroid as one data point 29 29 30 mesh = Interpolation(points, vertices, data)30 mesh = Interpolation(points, triangles, data) 31 31 assert allclose(mesh.matrix, [[1./3, 1./3, 1./3]]) 32 32 … … 41 41 c = [2.0,0.0] 42 42 points = [a, b, c] 43 vertices = [ [1,0,2] ] #bac43 triangles = [ [1,0,2] ] #bac 44 44 45 45 data = points #Use data at vertices 46 46 47 mesh = Interpolation(points, vertices, data)47 mesh = Interpolation(points, triangles, data) 48 48 assert allclose(mesh.matrix, [[1., 0., 0.], 49 49 [0., 1., 0.], … … 61 61 c = [2.0,0.0] 62 62 points = [a, b, c] 63 vertices = [ [1,0,2] ] #bac63 triangles = [ [1,0,2] ] #bac 64 64 65 65 data = [ [0., 1.], [1., 0.], [1., 1.] ] 66 66 67 mesh = Interpolation(points, vertices, data)67 mesh = Interpolation(points, triangles, data) 68 68 69 69 assert allclose(mesh.matrix, [[0.5, 0.5, 0.0], #Affects vertex 1 and 0 … … 81 81 c = [2.0,0.0] 82 82 points = [a, b, c] 83 vertices = [ [1,0,2] ] #bac83 triangles = [ [1,0,2] ] #bac 84 84 85 85 data = [ [0., 1.5], [1.5, 0.], [1.5, 0.5] ] 86 86 87 mesh = Interpolation(points, vertices, data)87 mesh = Interpolation(points, triangles, data) 88 88 89 89 assert allclose(mesh.matrix, [[0.25, 0.75, 0.0], #Affects vertex 1 and 0 … … 101 101 c = [2.0,0.0] 102 102 points = [a, b, c] 103 vertices = [ [1,0,2] ] #bac103 triangles = [ [1,0,2] ] #bac 104 104 105 105 data = [ [0.2, 1.5], [0.123, 1.768], [1.43, 0.44] ] 106 106 107 mesh = Interpolation(points, vertices, data)107 mesh = Interpolation(points, triangles, data) 108 108 109 109 assert allclose(sum(mesh.matrix, axis=1), 1.0) … … 124 124 points = [a, b, c, d, e, f] 125 125 #bac, bce, ecf, dbe, daf, dae 126 vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4], [3,0,5], [3,0,4]]126 triangles = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4], [3,0,5], [3,0,4]] 127 127 128 128 … … 130 130 data = [ [0., 2.0], [1.15, 0.75], [0.8888, 0.21], [1.000001, 0.00001] ] 131 131 132 mesh = Interpolation(points, vertices, data)132 mesh = Interpolation(points, triangles, data) 133 133 134 134 #print mesh.matrix -
inundation/ga/storm_surge/pyvolution/test_mesh.py
r297 r305 42 42 43 43 #Centroid 44 centroid = mesh.centroid s[0]44 centroid = mesh.centroid_coordinates[0] 45 45 assert centroid[0] == 4.0/3 46 46 assert centroid[1] == 1.0 … … 151 151 152 152 mesh = Mesh(points, vertices) 153 centroid = mesh.centroid s[0]153 centroid = mesh.centroid_coordinates[0] 154 154 155 155 … … 233 233 assert mesh.areas[0] == 2.0 234 234 235 assert allclose(mesh.centroid s[0], [2.0/3, 2.0/3])235 assert allclose(mesh.centroid_coordinates[0], [2.0/3, 2.0/3]) 236 236 237 237 … … 269 269 assert mesh.edgelengths[1,2] == sqrt(8.0) 270 270 271 assert allclose(mesh.centroid s[0], [2.0/3, 2.0/3])272 assert allclose(mesh.centroid s[1], [4.0/3, 4.0/3])273 assert allclose(mesh.centroid s[2], [8.0/3, 2.0/3])274 assert allclose(mesh.centroid s[3], [2.0/3, 8.0/3])271 assert allclose(mesh.centroid_coordinates[0], [2.0/3, 2.0/3]) 272 assert allclose(mesh.centroid_coordinates[1], [4.0/3, 4.0/3]) 273 assert allclose(mesh.centroid_coordinates[2], [8.0/3, 2.0/3]) 274 assert allclose(mesh.centroid_coordinates[3], [2.0/3, 8.0/3]) 275 275 276 276
Note: See TracChangeset
for help on using the changeset viewer.