Changeset 5897
- Timestamp:
- Nov 6, 2008, 12:17:15 PM (15 years ago)
- Location:
- anuga_core
- Files:
-
- 44 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/compile_all.py
r4978 r5897 3 3 buildroot = os.getcwd() 4 4 5 os.chdir('source ')5 os.chdir('source_numpy_conversion') 6 6 7 7 os.chdir('anuga') -
anuga_core/source/anuga/abstract_2d_finite_volumes/domain.py
r5892 r5897 8 8 """ 9 9 10 ##from numpy.oldnumeric import allclose, argmax, zeros, Float 11 import numpy 12 10 from Numeric import allclose, argmax, zeros, Float 13 11 from anuga.config import epsilon 14 12 from anuga.config import beta_euler, beta_rk2 … … 107 105 108 106 if verbose: print 'Initialising Domain' 107 from Numeric import zeros, Float, Int, ones 109 108 from quantity import Quantity 110 109 … … 156 155 for key in self.full_send_dict: 157 156 buffer_shape = self.full_send_dict[key][0].shape[0] 158 self.full_send_dict[key].append( numpy.zeros( (buffer_shape,self.nsys), numpy.float))157 self.full_send_dict[key].append(zeros( (buffer_shape,self.nsys) ,Float)) 159 158 160 159 161 160 for key in self.ghost_recv_dict: 162 161 buffer_shape = self.ghost_recv_dict[key][0].shape[0] 163 self.ghost_recv_dict[key].append( numpy.zeros( (buffer_shape,self.nsys), numpy.float))162 self.ghost_recv_dict[key].append(zeros( (buffer_shape,self.nsys) ,Float)) 164 163 165 164 … … 169 168 N = len(self) #number_of_elements 170 169 self.number_of_elements = N 171 self.tri_full_flag = numpy.ones(N, numpy.int)170 self.tri_full_flag = ones(N, Int) 172 171 for i in self.ghost_recv_dict.keys(): 173 172 for id in self.ghost_recv_dict[i][0]: … … 176 175 # Test the assumption that all full triangles are store before 177 176 # the ghost triangles. 178 if not numpy.allclose(self.tri_full_flag[:self.number_of_full_nodes],1):177 if not allclose(self.tri_full_flag[:self.number_of_full_nodes],1): 179 178 print 'WARNING: Not all full triangles are store before ghost triangles' 180 179 … … 231 230 # calculation 232 231 N = len(self) # Number_of_triangles 233 self.already_computed_flux = numpy.zeros((N, 3), numpy.int)232 self.already_computed_flux = zeros((N, 3), Int) 234 233 235 234 # Storage for maximal speeds computed for each triangle by 236 235 # compute_fluxes 237 236 # This is used for diagnostics only (reset at every yieldstep) 238 self.max_speed = numpy.zeros(N, numpy.float)237 self.max_speed = zeros(N, Float) 239 238 240 239 if mesh_filename is not None: … … 267 266 """ 268 267 268 from Numeric import zeros, Float 269 269 270 if not (vertex is None or edge is None): 270 271 msg = 'Values for both vertex and edge was specified.' … … 272 273 raise msg 273 274 274 q = numpy.zeros( len(self.conserved_quantities), numpy.float)275 q = zeros( len(self.conserved_quantities), Float) 275 276 276 277 for i, name in enumerate(self.conserved_quantities): … … 768 769 # Find index of largest computed flux speed 769 770 if triangle_id is None: 770 k = self.k = numpy.argmax(self.max_speed)771 k = self.k = argmax(self.max_speed) 771 772 else: 772 773 errmsg = 'Triangle_id %d does not exist in mesh: %s' %(triangle_id, … … 1085 1086 1086 1087 """ 1087 print '.evolve: 0'1088 1088 1089 1089 from anuga.config import min_timestep, max_timestep, epsilon … … 1096 1096 %self.get_boundary_tags() 1097 1097 assert hasattr(self, 'boundary_objects'), msg 1098 print '.evolve: 1'1099 1098 1100 1099 … … 1105 1104 1106 1105 self._order_ = self.default_order 1107 print '.evolve: 2'1108 1106 1109 1107 … … 1129 1127 self.number_of_first_order_steps = 0 1130 1128 1131 print '.evolve: 3' 1129 1132 1130 # Update ghosts 1133 1131 self.update_ghosts() 1134 1132 1135 print '.evolve: 4'1136 1133 # Initial update of vertex and edge values 1137 1134 self.distribute_to_vertices_and_edges() 1138 1135 1139 print '.evolve: 5'1140 1136 # Update extrema if necessary (for reporting) 1141 1137 self.update_extrema() 1142 1138 1143 print '.evolve: 6'1144 1139 # Initial update boundary values 1145 1140 self.update_boundary() 1146 1141 1147 print '.evolve: 7'1148 1142 # Or maybe restore from latest checkpoint 1149 1143 if self.checkpoint is True: 1150 1144 self.goto_latest_checkpoint() 1151 print '.evolve: 8'1152 1145 1153 1146 if skip_initial_step is False: … … 1209 1202 self.number_of_steps = 0 1210 1203 self.number_of_first_order_steps = 0 1211 self.max_speed = numpy.zeros(N, numpy.float)1204 self.max_speed = zeros(N, Float) 1212 1205 1213 1206 def evolve_one_euler_step(self, yieldstep, finaltime): … … 1575 1568 """ 1576 1569 1570 from Numeric import ones, sum, equal, Float 1571 1577 1572 N = len(self) # Number_of_triangles 1578 1573 d = len(self.conserved_quantities) -
anuga_core/source/anuga/abstract_2d_finite_volumes/ermapper_grids.py
r5892 r5897 2 2 3 3 # from os import open, write, read 4 ##import numpy.oldnumeric as Numeric 5 import numpy 6 7 celltype_map = {'IEEE4ByteReal': numpy.float32, 'IEEE8ByteReal': numpy.float64} 4 import Numeric 5 6 celltype_map = {'IEEE4ByteReal': Numeric.Float32, 'IEEE8ByteReal': Numeric.Float64} 8 7 9 8 … … 12 11 write_ermapper_grid(ofile, data, header = {}): 13 12 14 Function to write a 2D Num Pyarray to an ERMapper grid. There are a series of conventions adopted within13 Function to write a 2D Numeric array to an ERMapper grid. There are a series of conventions adopted within 15 14 this code, specifically: 16 15 1) The registration coordinate for the data is the SW (or lower-left) corner of the data 17 16 2) The registration coordinates refer to cell centres 18 3) The data is a 2D Num Pyarray with the NW-most data in element (0,0) and the SE-most data in element (N,M)17 3) The data is a 2D Numeric array with the NW-most data in element (0,0) and the SE-most data in element (N,M) 19 18 where N is the last line and M is the last column 20 19 4) There has been no testng of the use of a rotated grid. Best to keep data in an NS orientation … … 23 22 ofile: string - filename for output (note the output will consist of two files 24 23 ofile and ofile.ers. Either of these can be entered into this function 25 data: Num Py.array - 2D array containing the data to be output to the grid24 data: Numeric.array - 2D array containing the data to be output to the grid 26 25 header: dictionary - contains spatial information about the grid, in particular: 27 26 header['datum'] datum for the data ('"GDA94"') … … 58 57 59 58 # Check that the data is a 2 dimensional array 60 data_size = numpy.shape(data)59 data_size = Numeric.shape(data) 61 60 assert len(data_size) == 2 62 61 … … 84 83 nrofcellsperlines = int(header['nrofcellsperline']) 85 84 data = read_ermapper_data(data_file) 86 data = numpy.reshape(data,(nroflines,nrofcellsperlines))85 data = Numeric.reshape(data,(nroflines,nrofcellsperlines)) 87 86 return data 88 87 … … 164 163 return header 165 164 166 def write_ermapper_data(grid, ofile, data_format = numpy.float32):165 def write_ermapper_data(grid, ofile, data_format = Numeric.Float32): 167 166 168 167 … … 182 181 183 182 184 # Convert the array to data_format (default format is float32)183 # Convert the array to data_format (default format is Float32) 185 184 grid_as_float = grid.astype(data_format) 186 185 … … 194 193 195 194 196 def read_ermapper_data(ifile, data_format = numpy.float32):195 def read_ermapper_data(ifile, data_format = Numeric.Float32): 197 196 # open input file in a binary format and read the input string 198 197 fid = open(ifile,'rb') … … 200 199 fid.close() 201 200 202 # convert input string to required format (Note default format is numpy.float32)203 grid_as_float = numpy.fromstring(input_string,data_format)201 # convert input string to required format (Note default format is Numeric.Float32) 202 grid_as_float = Numeric.fromstring(input_string,data_format) 204 203 return grid_as_float 205 204 -
anuga_core/source/anuga/abstract_2d_finite_volumes/general_mesh.py
r5894 r5897 1 import numpy 1 2 from Numeric import concatenate, reshape, take, allclose 3 from Numeric import array, zeros, Int, Float, sqrt, sum, arange 2 4 3 5 from anuga.coordinate_transforms.geo_reference import Geo_reference … … 88 90 if verbose: print 'General_mesh: Building basic mesh structure in ANUGA domain' 89 91 90 ## self.triangles = array(triangles, Int) 91 ## self.nodes = array(nodes, Float) 92 self.triangles = numpy.array(triangles, numpy.int) 93 self.nodes = numpy.array(nodes, numpy.float) 92 self.triangles = array(triangles, Int) 93 self.nodes = array(nodes, Float) 94 94 95 95 … … 138 138 139 139 msg = 'Vertex indices reference non-existing coordinate sets' 140 assert max(self.triangles. ravel()) < self.nodes.shape[0], msg140 assert max(self.triangles.flat) < self.nodes.shape[0], msg 141 141 142 142 … … 146 146 max(self.nodes[:,0]), max(self.nodes[:,1]) ] 147 147 148 ## self.xy_extent = array(xy_extent, Float) 149 self.xy_extent = numpy.array(xy_extent, numpy.float) 148 self.xy_extent = array(xy_extent, Float) 150 149 151 150 152 151 # Allocate space for geometric quantities 153 ## self.normals = zeros((N, 6), Float) 154 ## self.areas = zeros(N, Float) 155 ## self.edgelengths = zeros((N, 3), Float) 156 self.normals = numpy.zeros((N, 6), numpy.float) 157 self.areas = numpy.zeros(N, numpy.float) 158 self.edgelengths = numpy.zeros((N, 3), numpy.float) 152 self.normals = zeros((N, 6), Float) 153 self.areas = zeros(N, Float) 154 self.edgelengths = zeros((N, 3), Float) 159 155 160 156 # Get x,y coordinates for all triangles and store … … 191 187 # - Stored as six floats n0x,n0y,n1x,n1y,n2x,n2y per triangle 192 188 193 n0 = numpy.array([x2 - x1, y2 - y1])194 l0 = numpy.sqrt(numpy.sum(n0**2))195 196 n1 = numpy.array([x0 - x2, y0 - y2])197 l1 = numpy.sqrt(numpy.sum(n1**2))198 199 n2 = numpy.array([x1 - x0, y1 - y0])200 l2 = numpy.sqrt(numpy.sum(n2**2))189 n0 = array([x2 - x1, y2 - y1]) 190 l0 = sqrt(sum(n0**2)) 191 192 n1 = array([x0 - x2, y0 - y2]) 193 l1 = sqrt(sum(n1**2)) 194 195 n2 = array([x1 - x0, y1 - y0]) 196 l2 = sqrt(sum(n2**2)) 201 197 202 198 # Normalise … … 278 274 if absolute is True: 279 275 if not self.geo_reference.is_absolute(): 280 return V + numpy.array([self.geo_reference.get_xllcorner(),281 276 return V + array([self.geo_reference.get_xllcorner(), 277 self.geo_reference.get_yllcorner()]) 282 278 else: 283 279 return V … … 320 316 i3 = 3*i 321 317 if absolute is True and not self.geo_reference.is_absolute(): 322 offset = numpy.array([self.geo_reference.get_xllcorner(),323 324 return numpy.array([V[i3,:]+offset,325 326 318 offset=array([self.geo_reference.get_xllcorner(), 319 self.geo_reference.get_yllcorner()]) 320 return array([V[i3,:]+offset, 321 V[i3+1,:]+offset, 322 V[i3+2,:]+offset]) 327 323 else: 328 return numpy.array([V[i3,:], V[i3+1,:], V[i3+2,:]])324 return array([V[i3,:], V[i3+1,:], V[i3+2,:]]) 329 325 330 326 … … 353 349 354 350 M = self.number_of_triangles 355 ## vertex_coordinates = zeros((3*M, 2), Float) 356 vertex_coordinates = numpy.zeros((3*M, 2), numpy.float) 351 vertex_coordinates = zeros((3*M, 2), Float) 357 352 358 353 for i in range(M): … … 381 376 indices = range(M) 382 377 383 return numpy.take(self.triangles, indices, axis=0)378 return take(self.triangles, indices) 384 379 385 380 … … 414 409 415 410 #T = reshape(array(range(K)).astype(Int), (M,3)) 416 ## T = reshape(arange(K).astype(Int), (M,3)) # Faster 417 T = numpy.reshape(numpy.arange(K).astype(numpy.int), (M,3)) # Faster 411 T = reshape(arange(K).astype(Int), (M,3)) # Faster 418 412 419 413 return T … … 445 439 if node is not None: 446 440 # Get index for this node 447 first = numpy.sum(self.number_of_triangles_per_node[:node])441 first = sum(self.number_of_triangles_per_node[:node]) 448 442 449 443 # Get number of triangles for this node 450 count = int(self.number_of_triangles_per_node[node])444 count = self.number_of_triangles_per_node[node] 451 445 452 446 for i in range(count): … … 458 452 triangle_list.append( (volume_id, vertex_id) ) 459 453 460 triangle_list = numpy.array(triangle_list)454 triangle_list = array(triangle_list) 461 455 else: 462 456 # Get info for all nodes recursively. … … 535 529 536 530 # Count number of triangles per node 537 number_of_triangles_per_node = numpy.zeros(self.number_of_full_nodes)531 number_of_triangles_per_node = zeros(self.number_of_full_nodes) 538 532 for volume_id, triangle in enumerate(self.get_triangles()): 539 533 for vertex_id in triangle: … … 541 535 542 536 # Allocate space for inverted structure 543 number_of_entries = numpy.sum(number_of_triangles_per_node)544 vertex_value_indices = numpy.zeros(number_of_entries, numpy.int)537 number_of_entries = sum(number_of_triangles_per_node) 538 vertex_value_indices = zeros(number_of_entries) 545 539 546 540 # Register (triangle, vertex) indices for each node … … 588 582 Y = C[:,1:6:2].copy() 589 583 590 xmin = min(X. ravel())591 xmax = max(X. ravel())592 ymin = min(Y. ravel())593 ymax = max(Y. ravel())584 xmin = min(X.flat) 585 xmax = max(X.flat) 586 ymin = min(Y.flat) 587 ymax = max(Y.flat) 594 588 #print "C",C 595 589 return xmin, xmax, ymin, ymax … … 604 598 """ 605 599 606 return numpy.sum(self.areas) 600 return sum(self.areas) 601 602 603 -
anuga_core/source/anuga/abstract_2d_finite_volumes/generic_boundary_conditions.py
r5892 r5897 7 7 from anuga.fit_interpolate.interpolate import Modeltime_too_late 8 8 from anuga.fit_interpolate.interpolate import Modeltime_too_early 9 10 import numpy11 9 12 10 … … 69 67 raise Exception, msg 70 68 71 self.conserved_quantities=numpy.array(conserved_quantities).astype(numpy.float) 69 from Numeric import array, Float 70 self.conserved_quantities=array(conserved_quantities).astype(Float) 72 71 73 72 def __repr__(self): … … 97 96 raise msg 98 97 98 99 from Numeric import array, Float 99 100 try: 100 q = numpy.array(q).astype(numpy.float)101 q = array(q).astype(Float) 101 102 except: 102 103 msg = 'Return value from time boundary function could ' … … 135 136 def __init__(self, filename, domain): 136 137 import time 138 from Numeric import array 137 139 from anuga.config import time_format 138 140 from anuga.abstract_2d_finite_volumes.util import File_function … … 204 206 205 207 import time 208 from Numeric import array, zeros, Float 206 209 from anuga.config import time_format 207 210 from anuga.abstract_2d_finite_volumes.util import file_function … … 219 222 220 223 if verbose: print 'Find midpoint coordinates of entire boundary' 221 self.midpoint_coordinates = numpy.zeros( (len(domain.boundary), 2), numpy.float)224 self.midpoint_coordinates = zeros( (len(domain.boundary), 2), Float) 222 225 boundary_keys = domain.boundary.keys() 223 226 … … 239 242 240 243 # Compute midpoints 241 if edge_id == 0: m = numpy.array([(x1 + x2)/2, (y1 + y2)/2])242 if edge_id == 1: m = numpy.array([(x0 + x2)/2, (y0 + y2)/2])243 if edge_id == 2: m = numpy.array([(x1 + x0)/2, (y1 + y0)/2])244 if edge_id == 0: m = array([(x1 + x2)/2, (y1 + y2)/2]) 245 if edge_id == 1: m = array([(x0 + x2)/2, (y0 + y2)/2]) 246 if edge_id == 2: m = array([(x1 + x0)/2, (y1 + y0)/2]) 244 247 245 248 # Convert to absolute UTM coordinates -
anuga_core/source/anuga/abstract_2d_finite_volumes/mesh_factory.py
r5892 r5897 2 2 mesh file formats 3 3 """ 4 5 import numpy6 4 7 5 … … 75 73 76 74 from anuga.config import epsilon 75 from Numeric import zeros, Float, Int 77 76 78 77 delta1 = float(len1)/m … … 94 93 index = Index(n,m) 95 94 96 points = numpy.zeros( (Np,2), numpy.float)95 points = zeros( (Np,2), Float) 97 96 98 97 for i in range(m+1): … … 106 105 107 106 108 elements = numpy.zeros( (Nt,3), numpy.int)107 elements = zeros( (Nt,3), Int) 109 108 boundary = {} 110 109 nt = -1 … … 150 149 151 150 from anuga.config import epsilon 151 from Numeric import zeros, Float, Int 152 152 153 153 delta1 = float(len1)/m … … 208 208 """ 209 209 210 from Numeric import array 210 211 import math 211 212 … … 509 510 """ 510 511 511 # from numpy.oldnumeric import array512 from Numeric import array 512 513 import math 513 514 … … 591 592 """ 592 593 594 from Numeric import array 593 595 import math 594 596 … … 684 686 """ 685 687 688 from Numeric import array 686 689 import math 690 687 691 from anuga.config import epsilon 692 688 693 689 694 deltax = lenx/float(m) -
anuga_core/source/anuga/abstract_2d_finite_volumes/neighbour_mesh.py
r5892 r5897 11 11 from anuga.caching import cache 12 12 from math import pi, sqrt 13 import numpy 13 from Numeric import array, allclose 14 14 15 15 16 class Mesh(General_mesh): … … 78 79 """ 79 80 81 82 83 from Numeric import array, zeros, Int, Float, maximum, sqrt, sum 84 80 85 General_mesh.__init__(self, coordinates, triangles, 81 86 number_of_full_nodes=\ … … 93 98 94 99 #Allocate space for geometric quantities 95 self.centroid_coordinates = numpy.zeros((N, 2), numpy.float)96 97 self.radii = numpy.zeros(N, numpy.float)98 99 self.neighbours = numpy.zeros((N, 3), numpy.int)100 self.neighbour_edges = numpy.zeros((N, 3), numpy.int)101 self.number_of_boundaries = numpy.zeros(N, numpy.int)102 self.surrogate_neighbours = numpy.zeros((N, 3), numpy.int)100 self.centroid_coordinates = zeros((N, 2), Float) 101 102 self.radii = zeros(N, Float) 103 104 self.neighbours = zeros((N, 3), Int) 105 self.neighbour_edges = zeros((N, 3), Int) 106 self.number_of_boundaries = zeros(N, Int) 107 self.surrogate_neighbours = zeros((N, 3), Int) 103 108 104 109 #Get x,y coordinates for all triangles and store … … 119 124 120 125 #Compute centroid 121 centroid = numpy.array([(x0 + x1 + x2)/3, (y0 + y1 + y2)/3])126 centroid = array([(x0 + x1 + x2)/3, (y0 + y1 + y2)/3]) 122 127 self.centroid_coordinates[i] = centroid 123 128 … … 128 133 129 134 #Midpoints 130 m0 = numpy.array([(x1 + x2)/2, (y1 + y2)/2])131 m1 = numpy.array([(x0 + x2)/2, (y0 + y2)/2])132 m2 = numpy.array([(x1 + x0)/2, (y1 + y0)/2])135 m0 = array([(x1 + x2)/2, (y1 + y2)/2]) 136 m1 = array([(x0 + x2)/2, (y0 + y2)/2]) 137 m2 = array([(x1 + x0)/2, (y1 + y0)/2]) 133 138 134 139 #The radius is the distance from the centroid of 135 140 #a triangle to the midpoint of the side of the triangle 136 141 #closest to the centroid 137 d0 = numpy.sqrt(numpy.sum( (centroid-m0)**2 ))138 d1 = numpy.sqrt(numpy.sum( (centroid-m1)**2 ))139 d2 = numpy.sqrt(numpy.sum( (centroid-m2)**2 ))142 d0 = sqrt(sum( (centroid-m0)**2 )) 143 d1 = sqrt(sum( (centroid-m1)**2 )) 144 d2 = sqrt(sum( (centroid-m2)**2 )) 140 145 141 146 self.radii[i] = min(d0, d1, d2) … … 145 150 #of inscribed circle is computed 146 151 147 a = numpy.sqrt((x0-x1)**2+(y0-y1)**2)148 b = numpy.sqrt((x1-x2)**2+(y1-y2)**2)149 c = numpy.sqrt((x2-x0)**2+(y2-y0)**2)152 a = sqrt((x0-x1)**2+(y0-y1)**2) 153 b = sqrt((x1-x2)**2+(y1-y2)**2) 154 c = sqrt((x2-x0)**2+(y2-y0)**2) 150 155 151 156 self.radii[i]=2.0*self.areas[i]/(a+b+c) … … 383 388 self.element_tag is defined 384 389 """ 390 from Numeric import array, Int 385 391 386 392 if tagged_elements is None: … … 389 395 #Check that all keys in given boundary exist 390 396 for tag in tagged_elements.keys(): 391 tagged_elements[tag] = numpy.array(tagged_elements[tag]).astype(numpy.int)397 tagged_elements[tag] = array(tagged_elements[tag]).astype(Int) 392 398 393 399 msg = 'Not all elements exist. ' … … 457 463 """ 458 464 465 from Numeric import allclose, sqrt, array, minimum, maximum 459 466 from anuga.utilities.numerical_tools import angle, ensure_numeric 460 467 … … 470 477 inverse_segments = {} 471 478 p0 = None 472 mindist = numpy.sqrt(numpy.sum((pmax-pmin)**2)) # Start value across entire mesh479 mindist = sqrt(sum((pmax-pmin)**2)) # Start value across entire mesh 473 480 for i, edge_id in self.boundary.keys(): 474 481 # Find vertex ids for boundary segment … … 480 487 B = self.get_vertex_coordinate(i, b, absolute=True) # End 481 488 489 482 490 # Take the point closest to pmin as starting point 483 491 # Note: Could be arbitrary, but nice to have 484 492 # a unique way of selecting 485 dist_A = numpy.sqrt(numpy.sum((A-pmin)**2))486 dist_B = numpy.sqrt(numpy.sum((B-pmin)**2))493 dist_A = sqrt(sum((A-pmin)**2)) 494 dist_B = sqrt(sum((B-pmin)**2)) 487 495 488 496 # Find lower leftmost point … … 585 593 # We have reached a point already visited. 586 594 587 if numpy.allclose(p1, polygon[0]):595 if allclose(p1, polygon[0]): 588 596 # If it is the initial point, the polygon is complete. 589 597 … … 621 629 from anuga.utilities.numerical_tools import anglediff 622 630 631 from Numeric import sort, allclose 632 623 633 N = len(self) 624 634 … … 662 672 663 673 # Normalise 664 l_u = numpy.sqrt(u[0]*u[0] + u[1]*u[1])665 l_v = numpy.sqrt(v[0]*v[0] + v[1]*v[1])674 l_u = sqrt(u[0]*u[0] + u[1]*u[1]) 675 l_v = sqrt(v[0]*v[0] + v[1]*v[1]) 666 676 667 677 msg = 'Normal vector in triangle %d does not have unit length' %i 668 assert numpy.allclose(l_v, 1), msg678 assert allclose(l_v, 1), msg 669 679 670 680 x = (u[0]*v[0] + u[1]*v[1])/l_u # Inner product … … 720 730 721 731 V = self.vertex_value_indices[:] #Take a copy 722 V = numpy.sort(V)723 assert numpy.allclose(V, range(3*N))732 V = sort(V) 733 assert allclose(V, range(3*N)) 724 734 725 735 assert sum(self.number_of_triangles_per_node) ==\ … … 732 742 count[i] += 1 733 743 734 assert numpy.allclose(count, self.number_of_triangles_per_node)744 assert allclose(count, self.number_of_triangles_per_node) 735 745 736 746 … … 795 805 """ 796 806 807 from Numeric import arange 797 808 from anuga.utilities.numerical_tools import histogram, create_bins 798 809 … … 1130 1141 1131 1142 # Distances from line origin to the two intersections 1132 z0 = numpy.array([x0 - xi0, y0 - eta0])1133 z1 = numpy.array([x1 - xi0, y1 - eta0])1134 d0 = numpy.sqrt(numpy.sum(z0**2))1135 d1 = numpy.sqrt(numpy.sum(z1**2))1143 z0 = array([x0 - xi0, y0 - eta0]) 1144 z1 = array([x1 - xi0, y1 - eta0]) 1145 d0 = sqrt(sum(z0**2)) 1146 d1 = sqrt(sum(z1**2)) 1136 1147 1137 1148 if d1 < d0: … … 1146 1157 # Normal direction: 1147 1158 # Right hand side relative to line direction 1148 vector = numpy.array([x1 - x0, y1 - y0]) # Segment vector1149 length = numpy.sqrt(numpy.sum(vector**2)) # Segment length1150 normal = numpy.array([vector[1], -vector[0]])/length1159 vector = array([x1 - x0, y1 - y0]) # Segment vector 1160 length = sqrt(sum(vector**2)) # Segment length 1161 normal = array([vector[1], -vector[0]])/length 1151 1162 1152 1163 … … 1228 1239 assert isinstance(segment, Triangle_intersection), msg 1229 1240 1230 midpoint = numpy.sum(numpy.array(segment.segment))/21241 midpoint = sum(array(segment.segment))/2 1231 1242 midpoints.append(midpoint) 1232 1243 -
anuga_core/source/anuga/abstract_2d_finite_volumes/pmesh2domain.py
r5892 r5897 9 9 import sys 10 10 11 import numpy12 11 13 12 … … 162 161 """ 163 162 163 from Numeric import transpose 164 164 from load_mesh.loadASCII import import_mesh_file 165 165 … … 172 172 volumes = mesh_dict['triangles'] 173 173 vertex_quantity_dict = {} 174 point_atts = numpy.transpose(mesh_dict['vertex_attributes'])174 point_atts = transpose(mesh_dict['vertex_attributes']) 175 175 point_titles = mesh_dict['vertex_attribute_titles'] 176 176 geo_reference = mesh_dict['geo_reference'] 177 177 if point_atts != None: 178 print 'type(point_atts)=%s' % type(point_atts) 179 for quantity, value_vector in map(None, point_titles, point_atts): 178 for quantity, value_vector in map (None, point_titles, point_atts): 180 179 vertex_quantity_dict[quantity] = value_vector 181 180 tag_dict = pmesh_dict_to_tag_dict(mesh_dict) -
anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py
r5892 r5897 15 15 """ 16 16 17 import numpy 17 from Numeric import array, zeros, Float, less, concatenate, NewAxis,\ 18 argmax, argmin, allclose, take, reshape, alltrue 18 19 19 20 from anuga.utilities.numerical_tools import ensure_numeric, is_scalar … … 37 38 if vertex_values is None: 38 39 N = len(domain) # number_of_elements 39 self.vertex_values = numpy.zeros((N, 3), numpy.float)40 self.vertex_values = zeros((N, 3), Float) 40 41 else: 41 self.vertex_values = numpy.array(vertex_values).astype(numpy.float)42 self.vertex_values = array(vertex_values).astype(Float) 42 43 43 44 N, V = self.vertex_values.shape … … 56 57 57 58 # Allocate space for other quantities 58 self.centroid_values = numpy.zeros(N, numpy.float)59 self.edge_values = numpy.zeros((N, 3), numpy.float)59 self.centroid_values = zeros(N, Float) 60 self.edge_values = zeros((N, 3), Float) 60 61 61 62 # Allocate space for Gradient 62 self.x_gradient = numpy.zeros(N, numpy.float)63 self.y_gradient = numpy.zeros(N, numpy.float)63 self.x_gradient = zeros(N, Float) 64 self.y_gradient = zeros(N, Float) 64 65 65 66 # Allocate space for Limiter Phi 66 self.phi = numpy.zeros(N, numpy.float)67 self.phi = zeros(N, Float) 67 68 68 69 # Intialise centroid and edge_values … … 71 72 # Allocate space for boundary values 72 73 L = len(domain.boundary) 73 self.boundary_values = numpy.zeros(L, numpy.float)74 self.boundary_values = zeros(L, Float) 74 75 75 76 # Allocate space for updates of conserved quantities by … … 77 78 78 79 # Allocate space for update fields 79 self.explicit_update = numpy.zeros(N, numpy.float )80 self.semi_implicit_update = numpy.zeros(N, numpy.float )81 self.centroid_backup_values = numpy.zeros(N, numpy.float)80 self.explicit_update = zeros(N, Float ) 81 self.semi_implicit_update = zeros(N, Float ) 82 self.centroid_backup_values = zeros(N, Float) 82 83 83 84 self.set_beta(1.0) … … 381 382 from anuga.geospatial_data.geospatial_data import Geospatial_data 382 383 from types import FloatType, IntType, LongType, ListType, NoneType 384 from Numeric import ArrayType 383 385 384 386 # Treat special case: Polygon situation … … 446 448 447 449 msg = 'Indices must be a list or None' 448 assert type(indices) in [ListType, NoneType, numpy.ndarray], msg450 assert type(indices) in [ListType, NoneType, ArrayType], msg 449 451 450 452 … … 456 458 self.set_values_from_constant(numeric, 457 459 location, indices, verbose) 458 elif type(numeric) in [ numpy.ndarray, ListType]:460 elif type(numeric) in [ArrayType, ListType]: 459 461 self.set_values_from_array(numeric, 460 462 location, indices, verbose) … … 472 474 use_cache=use_cache) 473 475 else: 474 msg = 'Illegal type for argument numeric: %s' % 475 raise TypeError,msg476 msg = 'Illegal type for argument numeric: %s' %str(numeric) 477 raise msg 476 478 477 479 elif quantity is not None: … … 608 610 """ 609 611 610 values = numpy.array(values).astype(numpy.float) 612 from Numeric import array, Float, Int, allclose 613 614 values = array(values).astype(Float) 611 615 612 616 if indices is not None: 613 indices = numpy.array(indices).astype(numpy.int)617 indices = array(indices).astype(Int) 614 618 msg = 'Number of values must match number of indices:' 615 619 msg += ' You specified %d values and %d indices'\ … … 636 640 637 641 elif location == 'unique vertices': 638 assert len(values.shape) == 1 or numpy.allclose(values.shape[1:], 1),\642 assert len(values.shape) == 1 or allclose(values.shape[1:], 1),\ 639 643 'Values array must be 1d' 640 644 641 self.set_vertex_values(values. ravel(), indices=indices)645 self.set_vertex_values(values.flat, indices=indices) 642 646 643 647 else: … … 672 676 A = q.vertex_values 673 677 678 from Numeric import allclose 674 679 msg = 'Quantities are defined on different meshes. '+\ 675 680 'This might be a case for implementing interpolation '+\ 676 681 'between different meshes.' 677 assert numpy.allclose(A.shape, self.vertex_values.shape), msg682 assert allclose(A.shape, self.vertex_values.shape), msg 678 683 679 684 self.set_values(A, location='vertices', … … 711 716 indices = range(len(self)) 712 717 713 V = numpy.take(self.domain.get_centroid_coordinates(), indices, axis=0) 714 print 'V=%s' % str(V) 718 V = take(self.domain.get_centroid_coordinates(), indices) 715 719 self.set_values(f(V[:,0], V[:,1]), 716 720 location=location, … … 776 780 777 781 778 points = ensure_numeric(points, numpy.float)779 values = ensure_numeric(values, numpy.float)782 points = ensure_numeric(points, Float) 783 values = ensure_numeric(values, Float) 780 784 781 785 if location != 'vertices': … … 909 913 # Always return absolute indices 910 914 if mode is None or mode == 'max': 911 i = numpy.argmax(V)915 i = argmax(V) 912 916 elif mode == 'min': 913 i = numpy.argmin(V)917 i = argmin(V) 914 918 915 919 … … 1114 1118 """ 1115 1119 1120 from Numeric import take 1121 1116 1122 # FIXME (Ole): I reckon we should have the option of passing a 1117 1123 # polygon into get_values. The question becomes how … … 1137 1143 raise msg 1138 1144 1139 import types 1140 1141 assert type(indices) in [types.ListType, types.NoneType, numpy.ndarray],\1145 import types, Numeric 1146 assert type(indices) in [types.ListType, types.NoneType, 1147 Numeric.ArrayType],\ 1142 1148 'Indices must be a list or None' 1143 1149 … … 1145 1151 if (indices == None): 1146 1152 indices = range(len(self)) 1147 return numpy.take(self.centroid_values, indices, axis=0)1153 return take(self.centroid_values,indices) 1148 1154 elif location == 'edges': 1149 1155 if (indices == None): 1150 1156 indices = range(len(self)) 1151 return numpy.take(self.edge_values, indices, axis=0)1157 return take(self.edge_values,indices) 1152 1158 elif location == 'unique vertices': 1153 1159 if (indices == None): … … 1172 1178 sum += self.vertex_values[triangle_id, vertex_id] 1173 1179 vert_values.append(sum/len(triangles)) 1174 return numpy.array(vert_values)1180 return Numeric.array(vert_values) 1175 1181 else: 1176 1182 if (indices is None): 1177 1183 indices = range(len(self)) 1178 return numpy.take(self.vertex_values, indices, axis=0)1184 return take(self.vertex_values, indices) 1179 1185 1180 1186 … … 1190 1196 """ 1191 1197 1198 from Numeric import array, Float 1199 1192 1200 # Assert that A can be converted to a Numeric array of appropriate dim 1193 A = ensure_numeric(A, numpy.float)1201 A = ensure_numeric(A, Float) 1194 1202 1195 1203 # print 'SHAPE A', A.shape … … 1265 1273 """ 1266 1274 1275 from Numeric import concatenate, zeros, Float, Int, array, reshape 1276 1277 1267 1278 if smooth is None: 1268 1279 # Take default from domain … … 1273 1284 1274 1285 if precision is None: 1275 precision = numpy.float1286 precision = Float 1276 1287 1277 1288 … … 1282 1293 V = self.domain.get_triangles() 1283 1294 N = self.domain.number_of_full_nodes # Ignore ghost nodes if any 1284 A = numpy.zeros(N, numpy.float)1295 A = zeros(N, Float) 1285 1296 points = self.domain.get_nodes() 1286 1297 … … 1332 1343 V = self.domain.get_disconnected_triangles() 1333 1344 points = self.domain.get_vertex_coordinates() 1334 A = self.vertex_values. ravel().astype(precision)1345 A = self.vertex_values.flat.astype(precision) 1335 1346 1336 1347 -
anuga_core/source/anuga/abstract_2d_finite_volumes/quantity_ext.c
r5892 r5897 11 11 12 12 #include "Python.h" 13 #include " numpy/arrayobject.h"13 #include "Numeric/arrayobject.h" 14 14 #include "math.h" 15 15 -
anuga_core/source/anuga/abstract_2d_finite_volumes/region.py
r5892 r5897 8 8 # FIXME (DSG-DSG) add better comments 9 9 10 import numpy 11 12 10 from Numeric import average 13 11 class Region: 14 12 """Base class for modifying quantities based on a region. … … 103 101 values = Q.get_values(indices=self.build_indices(elements, domain), 104 102 location=self.location) 105 av = numpy.average(values)103 av = average(values) 106 104 if self.location == "vertices": 107 av = numpy.average(av)105 av = average(av) 108 106 new_values = av + self.X 109 107 else: -
anuga_core/source/anuga/abstract_2d_finite_volumes/show_balanced_limiters.py
r5892 r5897 18 18 19 19 from mesh_factory import rectangular 20 20 from Numeric import array 21 21 22 22 23 ###################### … … 77 78 domain.set_quantity('stage', Z) 78 79 80 from Numeric import allclose 81 79 82 #Evolve 80 83 for t in domain.evolve(yieldstep = 0.1, finaltime = 30): -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_domain.py
r5892 r5897 6 6 from domain import * 7 7 from anuga.config import epsilon 8 import numpy 8 from Numeric import allclose, array, ones, Float 9 9 10 10 … … 64 64 65 65 66 assert numpy.alltrue(domain.get_conserved_quantities(0, edge=1) == 0.)66 assert domain.get_conserved_quantities(0, edge=1) == 0. 67 67 68 68 … … 95 95 #Centroids 96 96 q = domain.get_conserved_quantities(0) 97 assert numpy.allclose(q, [2., 2., 0.])97 assert allclose(q, [2., 2., 0.]) 98 98 99 99 q = domain.get_conserved_quantities(1) 100 assert numpy.allclose(q, [5., 5., 0.])100 assert allclose(q, [5., 5., 0.]) 101 101 102 102 q = domain.get_conserved_quantities(2) 103 assert numpy.allclose(q, [3., 3., 0.])103 assert allclose(q, [3., 3., 0.]) 104 104 105 105 q = domain.get_conserved_quantities(3) 106 assert numpy.allclose(q, [0., 0., 0.])106 assert allclose(q, [0., 0., 0.]) 107 107 108 108 109 109 #Edges 110 110 q = domain.get_conserved_quantities(0, edge=0) 111 assert numpy.allclose(q, [2.5, 2.5, 0.])111 assert allclose(q, [2.5, 2.5, 0.]) 112 112 q = domain.get_conserved_quantities(0, edge=1) 113 assert numpy.allclose(q, [2., 2., 0.])113 assert allclose(q, [2., 2., 0.]) 114 114 q = domain.get_conserved_quantities(0, edge=2) 115 assert numpy.allclose(q, [1.5, 1.5, 0.])115 assert allclose(q, [1.5, 1.5, 0.]) 116 116 117 117 for i in range(3): 118 118 q = domain.get_conserved_quantities(1, edge=i) 119 assert numpy.allclose(q, [5, 5, 0.])119 assert allclose(q, [5, 5, 0.]) 120 120 121 121 122 122 q = domain.get_conserved_quantities(2, edge=0) 123 assert numpy.allclose(q, [4.5, 4.5, 0.])123 assert allclose(q, [4.5, 4.5, 0.]) 124 124 q = domain.get_conserved_quantities(2, edge=1) 125 assert numpy.allclose(q, [4.5, 4.5, 0.])125 assert allclose(q, [4.5, 4.5, 0.]) 126 126 q = domain.get_conserved_quantities(2, edge=2) 127 assert numpy.allclose(q, [0., 0., 0.])127 assert allclose(q, [0., 0., 0.]) 128 128 129 129 130 130 q = domain.get_conserved_quantities(3, edge=0) 131 assert numpy.allclose(q, [3., 3., 0.])131 assert allclose(q, [3., 3., 0.]) 132 132 q = domain.get_conserved_quantities(3, edge=1) 133 assert numpy.allclose(q, [-1.5, -1.5, 0.])133 assert allclose(q, [-1.5, -1.5, 0.]) 134 134 q = domain.get_conserved_quantities(3, edge=2) 135 assert numpy.allclose(q, [-1.5, -1.5, 0.])135 assert allclose(q, [-1.5, -1.5, 0.]) 136 136 137 137 … … 179 179 Q = domain.create_quantity_from_expression(expression) 180 180 181 assert numpy.allclose(Q.vertex_values, [[2,3,4], [6,6,6],182 181 assert allclose(Q.vertex_values, [[2,3,4], [6,6,6], 182 [1,1,10], [-5, 4, 4]]) 183 183 184 184 expression = '(xmomentum*xmomentum + ymomentum*ymomentum)**0.5' … … 188 188 Y = domain.quantities['ymomentum'].vertex_values 189 189 190 assert numpy.allclose(Q.vertex_values, (X**2 + Y**2)**0.5)190 assert allclose(Q.vertex_values, (X**2 + Y**2)**0.5) 191 191 192 192 … … 314 314 Q = domain.quantities['depth'] 315 315 316 assert numpy.allclose(Q.vertex_values, [[2,3,4], [6,6,6],317 316 assert allclose(Q.vertex_values, [[2,3,4], [6,6,6], 317 [1,1,10], [-5, 4, 4]]) 318 318 319 319 … … 382 382 domain.check_integrity() 383 383 384 assert numpy.allclose(domain.neighbours, [[-1,-2,-3]])384 assert allclose(domain.neighbours, [[-1,-2,-3]]) 385 385 386 386 … … 471 471 [0,0,9], [-6, 3, 3]]) 472 472 473 assert numpy.allclose( domain.quantities['stage'].centroid_values,474 473 assert allclose( domain.quantities['stage'].centroid_values, 474 [2,5,3,0] ) 475 475 476 476 domain.set_quantity('xmomentum', [[1,1,1], [2,2,2], … … 484 484 485 485 #First order extrapolation 486 assert numpy.allclose( domain.quantities['stage'].vertex_values,487 488 489 490 486 assert allclose( domain.quantities['stage'].vertex_values, 487 [[ 2., 2., 2.], 488 [ 5., 5., 5.], 489 [ 3., 3., 3.], 490 [ 0., 0., 0.]]) 491 491 492 492 … … 527 527 528 528 for name in domain.conserved_quantities: 529 domain.quantities[name].explicit_update = numpy.array([4.,3.,2.,1.])530 domain.quantities[name].semi_implicit_update = numpy.array([1.,1.,1.,1.])529 domain.quantities[name].explicit_update = array([4.,3.,2.,1.]) 530 domain.quantities[name].semi_implicit_update = array([1.,1.,1.,1.]) 531 531 532 532 … … 535 535 domain.update_conserved_quantities() 536 536 537 sem = numpy.array([1.,1.,1.,1.])/numpy.array([1, 2, 3, 4])538 denom = numpy.ones(4, numpy.float)-domain.timestep*sem537 sem = array([1.,1.,1.,1.])/array([1, 2, 3, 4]) 538 denom = ones(4, Float)-domain.timestep*sem 539 539 540 540 # x = array([1, 2, 3, 4]) + array( [.4,.3,.2,.1] ) 541 541 # x /= denom 542 542 543 x = numpy.array([1., 2., 3., 4.])543 x = array([1., 2., 3., 4.]) 544 544 x /= denom 545 x += domain.timestep* numpy.array( [4,3,2,1] )545 x += domain.timestep*array( [4,3,2,1] ) 546 546 547 547 for name in domain.conserved_quantities: 548 assert numpy.allclose(domain.quantities[name].centroid_values, x)548 assert allclose(domain.quantities[name].centroid_values, x) 549 549 550 550 … … 578 578 [0,0,9], [-6, 3, 3]]) 579 579 580 assert numpy.allclose( domain.quantities['stage'].centroid_values,581 580 assert allclose( domain.quantities['stage'].centroid_values, 581 [2,5,3,0] ) 582 582 583 583 domain.set_quantity('xmomentum', [[1,1,1], [2,2,2], … … 591 591 592 592 #First order extrapolation 593 assert numpy.allclose( domain.quantities['stage'].vertex_values,594 595 596 597 593 assert allclose( domain.quantities['stage'].vertex_values, 594 [[ 2., 2., 2.], 595 [ 5., 5., 5.], 596 [ 3., 3., 3.], 597 [ 0., 0., 0.]]) 598 598 599 599 domain.build_tagged_elements_dictionary({'mound':[0,1]}) … … 610 610 from mesh_factory import rectangular 611 611 from shallow_water import Domain 612 from Numeric import zeros, Float 612 613 613 614 #Create basic mesh … … 626 627 from mesh_factory import rectangular 627 628 from shallow_water import Domain 629 from Numeric import zeros, Float 628 630 629 631 #Create basic mesh … … 643 645 domain.set_region([set_bottom_friction, set_top_friction]) 644 646 #print domain.quantities['friction'].get_values() 645 assert numpy.allclose(domain.quantities['friction'].get_values(),\646 647 648 649 650 651 647 assert allclose(domain.quantities['friction'].get_values(),\ 648 [[ 0.09, 0.09, 0.09], 649 [ 0.09, 0.09, 0.09], 650 [ 0.07, 0.07, 0.07], 651 [ 0.07, 0.07, 0.07], 652 [ 1.0, 1.0, 1.0], 653 [ 1.0, 1.0, 1.0]]) 652 654 653 655 domain.set_region([set_all_friction]) 654 656 #print domain.quantities['friction'].get_values() 655 assert numpy.allclose(domain.quantities['friction'].get_values(),656 657 658 659 660 661 657 assert allclose(domain.quantities['friction'].get_values(), 658 [[ 10.09, 10.09, 10.09], 659 [ 10.09, 10.09, 10.09], 660 [ 10.07, 10.07, 10.07], 661 [ 10.07, 10.07, 10.07], 662 [ 11.0, 11.0, 11.0], 663 [ 11.0, 11.0, 11.0]]) 662 664 663 665 … … 668 670 from mesh_factory import rectangular 669 671 from shallow_water import Domain 672 from Numeric import zeros, Float 670 673 671 674 #Create basic mesh … … 687 690 688 691 #print domain.quantities['friction'].get_values() 689 assert numpy.allclose(domain.quantities['friction'].get_values(),690 691 692 693 694 695 692 assert allclose(domain.quantities['friction'].get_values(),\ 693 [[ 0.09, 0.09, 0.09], 694 [ 0.09, 0.09, 0.09], 695 [ 0.07, 0.07, 0.07], 696 [ 0.07, 0.07, 0.07], 697 [ 1.0, 1.0, 1.0], 698 [ 1.0, 1.0, 1.0]]) 696 699 697 700 domain.set_region([set_bottom_friction, set_top_friction]) 698 701 #print domain.quantities['friction'].get_values() 699 assert numpy.allclose(domain.quantities['friction'].get_values(),700 701 702 703 704 705 702 assert allclose(domain.quantities['friction'].get_values(),\ 703 [[ 0.09, 0.09, 0.09], 704 [ 0.09, 0.09, 0.09], 705 [ 0.07, 0.07, 0.07], 706 [ 0.07, 0.07, 0.07], 707 [ 1.0, 1.0, 1.0], 708 [ 1.0, 1.0, 1.0]]) 706 709 707 710 domain.set_region([set_all_friction]) 708 711 #print domain.quantities['friction'].get_values() 709 assert numpy.allclose(domain.quantities['friction'].get_values(),710 711 712 713 714 715 712 assert allclose(domain.quantities['friction'].get_values(), 713 [[ 10.09, 10.09, 10.09], 714 [ 10.09, 10.09, 10.09], 715 [ 10.07, 10.07, 10.07], 716 [ 10.07, 10.07, 10.07], 717 [ 11.0, 11.0, 11.0], 718 [ 11.0, 11.0, 11.0]]) 716 719 717 720 #------------------------------------------------------------- -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_ermapper.py
r5892 r5897 5 5 6 6 import ermapper_grids 7 import numpy7 import Numeric 8 8 from os import remove 9 9 … … 19 19 data_filename = 'test_write_ermapper_grid' 20 20 21 original_grid = numpy.array([[0.0, 0.1, 1.0], [2.0, 3.0, 4.0]])21 original_grid = Numeric.array([[0.0, 0.1, 1.0], [2.0, 3.0, 4.0]]) 22 22 23 23 # Check that the function works when passing the filename without … … 25 25 ermapper_grids.write_ermapper_grid(data_filename, original_grid) 26 26 new_grid = ermapper_grids.read_ermapper_grid(data_filename) 27 assert numpy.allclose(original_grid, new_grid)27 assert Numeric.allclose(original_grid, new_grid) 28 28 29 29 # Check that the function works when passing the filename with … … 31 31 ermapper_grids.write_ermapper_grid(header_filename, original_grid) 32 32 new_grid = ermapper_grids.read_ermapper_grid(header_filename) 33 assert numpy.allclose(original_grid, new_grid)33 assert Numeric.allclose(original_grid, new_grid) 34 34 35 35 # Clean up created files … … 40 40 # Setup test data 41 41 filename = 'test_write_ermapper_grid' 42 original_grid = numpy.array([0.0, 0.1, 1.0, 2.0, 3.0, 4.0])42 original_grid = Numeric.array([0.0, 0.1, 1.0, 2.0, 3.0, 4.0]) 43 43 44 44 # Write test data 45 ermapper_grids.write_ermapper_data(original_grid, filename, numpy.float64)45 ermapper_grids.write_ermapper_data(original_grid, filename, Numeric.Float64) 46 46 47 47 # Read in the test data 48 new_grid = ermapper_grids.read_ermapper_data(filename, numpy.float64)48 new_grid = ermapper_grids.read_ermapper_data(filename, Numeric.Float64) 49 49 50 50 # Check that the test data that has been read in matches the original data 51 assert numpy.allclose(original_grid, new_grid)51 assert Numeric.allclose(original_grid, new_grid) 52 52 53 53 # Clean up created files … … 57 57 # Setup test data 58 58 filename = 'test_write_ermapper_grid' 59 original_grid = numpy.array([0.0, 0.1, 1.0, 2.0, 3.0, 4.0])59 original_grid = Numeric.array([0.0, 0.1, 1.0, 2.0, 3.0, 4.0]) 60 60 61 61 # Write test data … … 66 66 67 67 # Check that the test data that has been read in matches the original data 68 assert numpy.allclose(original_grid, new_grid)68 assert Numeric.allclose(original_grid, new_grid) 69 69 70 70 # Clean up created files … … 75 75 76 76 # setup test data 77 original_grid = numpy.array([[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]])77 original_grid = Numeric.array([[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]]) 78 78 # Write test data 79 79 ermapper_grids.write_ermapper_data(original_grid, data_filename) -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_general_mesh.py
r5892 r5897 7 7 8 8 from anuga.config import epsilon 9 import numpy 9 from Numeric import allclose, array, ones, Float 10 10 from general_mesh import General_mesh 11 11 from anuga.coordinate_transforms.geo_reference import Geo_reference … … 23 23 def test_get_vertex_coordinates(self): 24 24 from mesh_factory import rectangular 25 from Numeric import zeros, Float 25 26 26 27 #Create basic mesh … … 29 30 30 31 31 assert numpy.allclose(domain.get_nodes(), nodes)32 assert allclose(domain.get_nodes(), nodes) 32 33 33 34 … … 40 41 for j in range(3): 41 42 k = triangles[i,j] #Index of vertex j in triangle i 42 assert numpy.allclose(V[3*i+j,:], nodes[k])43 assert allclose(V[3*i+j,:], nodes[k]) 43 44 44 45 def test_get_vertex_coordinates_with_geo_ref(self): … … 54 55 f = [4.0, 0.0] 55 56 56 nodes = numpy.array([a, b, c, d, e, f])57 nodes = array([a, b, c, d, e, f]) 57 58 58 59 nodes_absolute = geo.get_absolute(nodes) 59 60 60 61 #bac, bce, ecf, dbe, daf, dae 61 triangles = numpy.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]])62 triangles = array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 62 63 63 64 domain = General_mesh(nodes, triangles, 64 65 geo_reference = geo) 65 66 verts = domain.get_vertex_coordinates(triangle_id=0) 66 self.assert_( numpy.allclose(numpy.array([b,a,c]), verts))67 self.assert_(allclose(array([b,a,c]), verts)) 67 68 verts = domain.get_vertex_coordinates(triangle_id=0) 68 self.assert_( numpy.allclose(numpy.array([b,a,c]), verts))69 self.assert_(allclose(array([b,a,c]), verts)) 69 70 verts = domain.get_vertex_coordinates(triangle_id=0, 70 71 absolute=True) 71 self.assert_( numpy.allclose(numpy.array([nodes_absolute[1],72 73 72 self.assert_(allclose(array([nodes_absolute[1], 73 nodes_absolute[0], 74 nodes_absolute[2]]), verts)) 74 75 verts = domain.get_vertex_coordinates(triangle_id=0, 75 76 absolute=True) 76 self.assert_( numpy.allclose(numpy.array([nodes_absolute[1],77 78 77 self.assert_(allclose(array([nodes_absolute[1], 78 nodes_absolute[0], 79 nodes_absolute[2]]), verts)) 79 80 80 81 … … 85 86 """ 86 87 from mesh_factory import rectangular 88 from Numeric import zeros, Float 87 89 88 90 #Create basic mesh … … 91 93 92 94 93 assert numpy.allclose(domain.get_nodes(), nodes)95 assert allclose(domain.get_nodes(), nodes) 94 96 95 97 … … 102 104 for j in range(3): 103 105 k = triangles[i,j] #Index of vertex j in triangle i 104 assert numpy.allclose(V[j,:], nodes[k])106 assert allclose(V[j,:], nodes[k]) 105 107 106 108 … … 112 114 """ 113 115 from mesh_factory import rectangular 116 from Numeric import zeros, Float 114 117 115 118 #Create basic mesh … … 118 121 119 122 value = [7] 120 assert numpy.allclose(domain.get_triangles(), triangles)121 assert numpy.allclose(domain.get_triangles([0,4]),122 123 assert allclose(domain.get_triangles(), triangles) 124 assert allclose(domain.get_triangles([0,4]), 125 [triangles[0], triangles[4]]) 123 126 124 127 … … 127 130 """ 128 131 from mesh_factory import rectangular 129 130 a = [0.0, 0.0] 131 b = [0.0, 2.0] 132 c = [2.0, 0.0] 133 d = [0.0, 4.0] 134 e = [2.0, 2.0] 135 f = [4.0, 0.0] 136 137 nodes = numpy.array([a, b, c, d, e, f]) 132 from Numeric import zeros, Float, array 133 134 a = [0.0, 0.0] 135 b = [0.0, 2.0] 136 c = [2.0, 0.0] 137 d = [0.0, 4.0] 138 e = [2.0, 2.0] 139 f = [4.0, 0.0] 140 141 nodes = array([a, b, c, d, e, f]) 138 142 #bac, bce, ecf, dbe, daf, dae 139 triangles = numpy.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]])143 triangles = array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 140 144 141 145 domain1 = General_mesh(nodes, triangles) … … 158 162 #print count 159 163 # 160 assert numpy.allclose(count, domain.number_of_triangles_per_node)164 assert allclose(count, domain.number_of_triangles_per_node) 161 165 162 166 # Check indices … … 192 196 f = [4.0, 0.0] 193 197 194 nodes = numpy.array([a, b, c, d, e, f])198 nodes = array([a, b, c, d, e, f]) 195 199 #bac, bce, ecf, dbe, daf, dae 196 triangles = numpy.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]])200 triangles = array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 197 201 198 202 domain = General_mesh(nodes, triangles) … … 200 204 # One node 201 205 L = domain.get_triangles_and_vertices_per_node(node=2) 202 print 'L=%s' % str(L) 203 assert numpy.allclose(L[0], [0, 2]) 204 assert numpy.allclose(L[1], [1, 1]) 205 assert numpy.allclose(L[2], [2, 1]) 206 assert allclose(L[0], [0, 2]) 207 assert allclose(L[1], [1, 1]) 208 assert allclose(L[2], [2, 1]) 206 209 207 210 # All nodes … … 210 213 for i, Lref in enumerate(ALL): 211 214 L = domain.get_triangles_and_vertices_per_node(node=i) 212 assert numpy.allclose(L, Lref)215 assert allclose(L, Lref) 213 216 214 217 … … 221 224 from mesh_factory import rectangular 222 225 from shallow_water import Domain 226 from Numeric import zeros, Float 223 227 224 228 #Create basic mesh … … 235 239 from mesh_factory import rectangular 236 240 from shallow_water import Domain 241 from Numeric import zeros, Float 237 242 238 243 #Create basic mesh … … 268 273 f = [4.0, 0.0] 269 274 270 nodes = numpy.array([a, b, c, d, e, f])275 nodes = array([a, b, c, d, e, f]) 271 276 272 277 nodes_absolute = geo.get_absolute(nodes) 273 278 274 279 #bac, bce, ecf, dbe, daf, dae 275 triangles = numpy.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]])280 triangles = array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 276 281 277 282 domain = General_mesh(nodes, triangles, 278 283 geo_reference = geo) 279 284 node = domain.get_node(2) 280 self.assert True(numpy.alltrue(c == node))285 self.assertEqual(c, node) 281 286 282 287 node = domain.get_node(2, absolute=True) 283 self.assert True(numpy.alltrue(nodes_absolute[2] == node))288 self.assertEqual(nodes_absolute[2], node) 284 289 285 290 node = domain.get_node(2, absolute=True) 286 self.assert True(numpy.alltrue(nodes_absolute[2] == node))291 self.assertEqual(nodes_absolute[2], node) 287 292 288 293 … … 305 310 f = [4.0, 0.0] 306 311 307 nodes = numpy.array([a, b, c, d, e, f])312 nodes = array([a, b, c, d, e, f]) 308 313 309 314 nodes_absolute = geo.get_absolute(nodes) 310 315 311 316 # max index is 5, use 5, expect success 312 triangles = numpy.array([[1,5,2], [1,2,4], [4,2,5], [3,1,4]])317 triangles = array([[1,5,2], [1,2,4], [4,2,5], [3,1,4]]) 313 318 General_mesh(nodes, triangles, geo_reference=geo) 314 319 315 320 # max index is 5, use 6, expect assert failure 316 triangles = numpy.array([[1,6,2], [1,2,4], [4,2,5], [3,1,4]])321 triangles = array([[1,6,2], [1,2,4], [4,2,5], [3,1,4]]) 317 322 self.failUnlessRaises(AssertionError, General_mesh, 318 323 nodes, triangles, geo_reference=geo) 319 324 320 325 # max index is 5, use 10, expect assert failure 321 triangles = numpy.array([[1,10,2], [1,2,4], [4,2,5], [3,1,4]])326 triangles = array([[1,10,2], [1,2,4], [4,2,5], [3,1,4]]) 322 327 self.failUnlessRaises(AssertionError, General_mesh, 323 328 nodes, triangles, geo_reference=geo) … … 328 333 if __name__ == "__main__": 329 334 suite = unittest.makeSuite(Test_General_Mesh,'test') 335 #suite = unittest.makeSuite(Test_General_Mesh,'test_get_node') 330 336 runner = unittest.TextTestRunner() 331 337 runner.run(suite) -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_generic_boundary_conditions.py
r5892 r5897 6 6 from generic_boundary_conditions import * 7 7 from anuga.config import epsilon 8 import numpy8 from Numeric import allclose, array 9 9 10 10 … … 44 44 45 45 q = Bd.evaluate() 46 assert numpy.allclose(q, x)46 assert allclose(q, x) 47 47 48 48 … … 98 98 q = T.evaluate(0, 2) #Vol=0, edge=2 99 99 100 assert numpy.allclose(q, [1.5, 2.5])100 assert allclose(q, [1.5, 2.5]) 101 101 102 102 … … 175 175 176 176 #Check that midpoint coordinates at boundary are correctly computed 177 assert numpy.allclose( F.midpoint_coordinates,178 179 180 181 #assert numpy.allclose(F.midpoint_coordinates[(3,2)], [0.0, 3.0])182 #assert numpy.allclose(F.midpoint_coordinates[(3,1)], [1.0, 3.0])183 #assert numpy.allclose(F.midpoint_coordinates[(0,2)], [0.0, 1.0])184 #assert numpy.allclose(F.midpoint_coordinates[(0,0)], [1.0, 0.0])185 #assert numpy.allclose(F.midpoint_coordinates[(2,0)], [3.0, 0.0])186 #assert numpy.allclose(F.midpoint_coordinates[(2,1)], [3.0, 1.0])177 assert allclose( F.midpoint_coordinates, 178 [[1.0, 0.0], [0.0, 1.0], [3.0, 0.0], 179 [3.0, 1.0], [1.0, 3.0], [0.0, 3.0]]) 180 181 #assert allclose(F.midpoint_coordinates[(3,2)], [0.0, 3.0]) 182 #assert allclose(F.midpoint_coordinates[(3,1)], [1.0, 3.0]) 183 #assert allclose(F.midpoint_coordinates[(0,2)], [0.0, 1.0]) 184 #assert allclose(F.midpoint_coordinates[(0,0)], [1.0, 0.0]) 185 #assert allclose(F.midpoint_coordinates[(2,0)], [3.0, 0.0]) 186 #assert allclose(F.midpoint_coordinates[(2,1)], [3.0, 1.0]) 187 187 188 188 … … 193 193 domain.time = 5*30/2 #A quarter way through first step 194 194 q = F.evaluate() 195 assert numpy.allclose(q, [1.0/4, sin(2*pi/10)/4])195 assert allclose(q, [1.0/4, sin(2*pi/10)/4]) 196 196 197 197 198 198 domain.time = 2.5*5*60 #Half way between steps 2 and 3 199 199 q = F.evaluate() 200 assert numpy.allclose(q, [2.5, (sin(2*2*pi/10) + sin(3*2*pi/10))/2])200 assert allclose(q, [2.5, (sin(2*2*pi/10) + sin(3*2*pi/10))/2]) 201 201 202 202 -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_ghost.py
r5892 r5897 6 6 from domain import * 7 7 from anuga.config import epsilon 8 import numpy 8 from Numeric import allclose, array, ones, Float 9 10 9 11 10 12 … … 41 43 42 44 43 assert numpy.alltrue(domain.get_conserved_quantities(0, edge=1) == 0.)45 assert domain.get_conserved_quantities(0, edge=1) == 0. 44 46 45 47 -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_neighbour_mesh.py
r5892 r5897 1 1 #!/usr/bin/env python 2 3 2 4 3 5 #FIXME: Seperate the tests for mesh and general_mesh … … 11 13 from mesh_factory import rectangular 12 14 from anuga.config import epsilon 13 import numpy 15 from Numeric import allclose, array, Int 14 16 15 17 from anuga.coordinate_transforms.geo_reference import Geo_reference … … 18 20 19 21 def distance(x, y): 20 return sqrt( sum( ( numpy.array(x)-numpy.array(y))**2 ))22 return sqrt( sum( (array(x)-array(y))**2 )) 21 23 22 24 class Test_Mesh(unittest.TestCase): … … 61 63 #Normals 62 64 normals = mesh.get_normals() 63 assert numpy.allclose(normals[0, 0:2], [3.0/5, 4.0/5])64 assert numpy.allclose(normals[0, 2:4], [-1.0, 0.0])65 assert numpy.allclose(normals[0, 4:6], [0.0, -1.0])66 67 assert numpy.allclose(mesh.get_normal(0,0), [3.0/5, 4.0/5])68 assert numpy.allclose(mesh.get_normal(0,1), [-1.0, 0.0])69 assert numpy.allclose(mesh.get_normal(0,2), [0.0, -1.0])65 assert allclose(normals[0, 0:2], [3.0/5, 4.0/5]) 66 assert allclose(normals[0, 2:4], [-1.0, 0.0]) 67 assert allclose(normals[0, 4:6], [0.0, -1.0]) 68 69 assert allclose(mesh.get_normal(0,0), [3.0/5, 4.0/5]) 70 assert allclose(mesh.get_normal(0,1), [-1.0, 0.0]) 71 assert allclose(mesh.get_normal(0,2), [0.0, -1.0]) 70 72 71 73 #Edge lengths 72 assert numpy.allclose(mesh.edgelengths[0], [5.0, 3.0, 4.0])74 assert allclose(mesh.edgelengths[0], [5.0, 3.0, 4.0]) 73 75 74 76 … … 79 81 80 82 V = mesh.get_vertex_coordinates() 81 assert numpy.allclose(V, [ [0.0, 0.0],82 83 83 assert allclose(V, [ [0.0, 0.0], 84 [4.0, 0.0], 85 [0.0, 3.0] ]) 84 86 85 87 V0 = mesh.get_vertex_coordinate(0, 0) 86 assert numpy.allclose(V0, [0.0, 0.0])88 assert allclose(V0, [0.0, 0.0]) 87 89 88 90 V1 = mesh.get_vertex_coordinate(0, 1) 89 assert numpy.allclose(V1, [4.0, 0.0])91 assert allclose(V1, [4.0, 0.0]) 90 92 91 93 V2 = mesh.get_vertex_coordinate(0, 2) 92 assert numpy.allclose(V2, [0.0, 3.0])94 assert allclose(V2, [0.0, 3.0]) 93 95 94 96 … … 235 237 236 238 mesh = Mesh(points, vertices,use_inscribed_circle=False) 237 assert numpy.allclose(mesh.radii[0],sqrt(3.0)/3),'Steve''s doesn''t work'239 assert allclose(mesh.radii[0],sqrt(3.0)/3),'Steve''s doesn''t work' 238 240 239 241 mesh = Mesh(points, vertices,use_inscribed_circle=True) 240 assert numpy.allclose(mesh.radii[0],sqrt(3.0)/3),'inscribed circle doesn''t work'242 assert allclose(mesh.radii[0],sqrt(3.0)/3),'inscribed circle doesn''t work' 241 243 242 244 def test_inscribed_circle_rightangle_triangle(self): … … 250 252 251 253 mesh = Mesh(points, vertices,use_inscribed_circle=False) 252 assert numpy.allclose(mesh.radii[0],5.0/6),'Steve''s doesn''t work'254 assert allclose(mesh.radii[0],5.0/6),'Steve''s doesn''t work' 253 255 254 256 mesh = Mesh(points, vertices,use_inscribed_circle=True) 255 assert numpy.allclose(mesh.radii[0],1.0),'inscribed circle doesn''t work'257 assert allclose(mesh.radii[0],1.0),'inscribed circle doesn''t work' 256 258 257 259 … … 267 269 assert mesh.areas[0] == 2.0 268 270 269 assert numpy.allclose(mesh.centroid_coordinates[0], [2.0/3, 2.0/3])271 assert allclose(mesh.centroid_coordinates[0], [2.0/3, 2.0/3]) 270 272 271 273 … … 301 303 assert mesh.edgelengths[1,2] == sqrt(8.0) 302 304 303 assert numpy.allclose(mesh.centroid_coordinates[0], [2.0/3, 2.0/3])304 assert numpy.allclose(mesh.centroid_coordinates[1], [4.0/3, 4.0/3])305 assert numpy.allclose(mesh.centroid_coordinates[2], [8.0/3, 2.0/3])306 assert numpy.allclose(mesh.centroid_coordinates[3], [2.0/3, 8.0/3])305 assert allclose(mesh.centroid_coordinates[0], [2.0/3, 2.0/3]) 306 assert allclose(mesh.centroid_coordinates[1], [4.0/3, 4.0/3]) 307 assert allclose(mesh.centroid_coordinates[2], [8.0/3, 2.0/3]) 308 assert allclose(mesh.centroid_coordinates[3], [2.0/3, 8.0/3]) 307 309 308 310 def test_mesh_and_neighbours(self): … … 695 697 get values based on triangle lists. 696 698 """ 697 698 699 from mesh_factory import rectangular 700 from Numeric import zeros, Float 699 701 700 702 #Create basic mesh … … 714 716 def test_boundary_polygon(self): 715 717 from mesh_factory import rectangular 718 #from mesh import Mesh 719 from Numeric import zeros, Float 716 720 717 721 #Create basic mesh … … 723 727 724 728 assert len(P) == 8 725 assert numpy.allclose(P, [[0.0, 0.0], [0.5, 0.0], [1.0, 0.0],726 727 729 assert allclose(P, [[0.0, 0.0], [0.5, 0.0], [1.0, 0.0], 730 [1.0, 0.5], [1.0, 1.0], [0.5, 1.0], 731 [0.0, 1.0], [0.0, 0.5]]) 728 732 for p in points: 729 733 #print p, P … … 732 736 733 737 def test_boundary_polygon_II(self): 738 from Numeric import zeros, Float 739 740 734 741 #Points 735 742 a = [0.0, 0.0] #0 … … 757 764 758 765 assert len(P) == 8 759 assert numpy.allclose(P, [a, d, f, i, h, e, c, b])766 assert allclose(P, [a, d, f, i, h, e, c, b]) 760 767 761 768 for p in points: … … 767 774 """Same as II but vertices ordered differently 768 775 """ 776 777 from Numeric import zeros, Float 778 769 779 770 780 #Points … … 794 804 795 805 assert len(P) == 8 796 assert numpy.allclose(P, [a, d, f, i, h, e, c, b])806 assert allclose(P, [a, d, f, i, h, e, c, b]) 797 807 798 808 for p in points: … … 805 815 is partitioned using pymetis. 806 816 """ 817 818 from Numeric import zeros, Float 819 807 820 808 821 #Points … … 834 847 835 848 # Note that point e appears twice! 836 assert numpy.allclose(P, [a, d, f, e, g, h, e, c, b])849 assert allclose(P, [a, d, f, e, g, h, e, c, b]) 837 850 838 851 for p in points: … … 851 864 """ 852 865 866 from Numeric import zeros, Float 853 867 from mesh_factory import rectangular 854 868 … … 893 907 894 908 """ 909 from Numeric import zeros, Float 910 895 911 896 912 #Points … … 939 955 940 956 assert len(P) == 8 941 assert numpy.allclose(P, [a, d, f, i, h, e, c, b])942 assert numpy.allclose(P, [(0.0, 0.0), (0.5, 0.0), (1.0, 0.0), (1.5, 0.5), (1.0, 1.0), (0.5, 0.5), (0.0, 1.0), (0.0, 0.5)])957 assert allclose(P, [a, d, f, i, h, e, c, b]) 958 assert allclose(P, [(0.0, 0.0), (0.5, 0.0), (1.0, 0.0), (1.5, 0.5), (1.0, 1.0), (0.5, 0.5), (0.0, 1.0), (0.0, 0.5)]) 943 959 944 960 … … 982 998 [ 52341.70703125, 38563.39453125]] 983 999 984 ##points = ensure_numeric(points, int)/1000 # Simplify for ease of interpretation1000 ##points = ensure_numeric(points, Int)/1000 # Simplify for ease of interpretation 985 1001 986 1002 triangles = [[19, 0,15], … … 1085 1101 [ 35406.3359375 , 79332.9140625 ]] 1086 1102 1087 scaled_points = ensure_numeric(points, int)/1000 # Simplify for ease of interpretation1103 scaled_points = ensure_numeric(points, Int)/1000 # Simplify for ease of interpretation 1088 1104 1089 1105 triangles = [[ 0, 1, 2], … … 1126 1142 assert is_inside_polygon(p, P) 1127 1143 1128 assert numpy.allclose(P, Pref)1144 assert allclose(P, Pref) 1129 1145 1130 1146 def test_lone_vertices(self): … … 1178 1194 boundary_polygon = mesh.get_boundary_polygon() 1179 1195 1180 assert numpy.allclose(absolute_points, boundary_polygon)1196 assert allclose(absolute_points, boundary_polygon) 1181 1197 1182 1198 def test_get_triangle_containing_point(self): … … 1225 1241 1226 1242 neighbours = mesh.get_triangle_neighbours(0) 1227 assert numpy.allclose(neighbours, [-1,1,-1])1243 assert allclose(neighbours, [-1,1,-1]) 1228 1244 neighbours = mesh.get_triangle_neighbours(-10) 1229 1245 assert neighbours == [] … … 1274 1290 for x in L: 1275 1291 if x.triangle_id % 2 == 0: 1276 assert numpy.allclose(x.length, ceiling-y_line)1292 assert allclose(x.length, ceiling-y_line) 1277 1293 else: 1278 assert numpy.allclose(x.length, y_line-floor)1294 assert allclose(x.length, y_line-floor) 1279 1295 1280 1296 1281 assert numpy.allclose(x.normal, [0,-1])1282 1283 assert numpy.allclose(x.segment[1][0], x.segment[0][0] + x.length)1284 assert numpy.allclose(x.segment[0][1], y_line)1285 assert numpy.allclose(x.segment[1][1], y_line)1297 assert allclose(x.normal, [0,-1]) 1298 1299 assert allclose(x.segment[1][0], x.segment[0][0] + x.length) 1300 assert allclose(x.segment[0][1], y_line) 1301 assert allclose(x.segment[1][1], y_line) 1286 1302 1287 1303 assert x.triangle_id in intersected_triangles … … 1290 1306 1291 1307 msg = 'Segments do not add up' 1292 assert numpy.allclose(total_length, 2), msg1308 assert allclose(total_length, 2), msg 1293 1309 1294 1310 … … 1325 1341 total_length = 0 1326 1342 for x in L: 1327 assert numpy.allclose(x.length, 1.0)1328 assert numpy.allclose(x.normal, [0,-1])1329 1330 assert numpy.allclose(x.segment[1][0], x.segment[0][0] + x.length)1331 assert numpy.allclose(x.segment[0][1], y_line)1332 assert numpy.allclose(x.segment[1][1], y_line)1343 assert allclose(x.length, 1.0) 1344 assert allclose(x.normal, [0,-1]) 1345 1346 assert allclose(x.segment[1][0], x.segment[0][0] + x.length) 1347 assert allclose(x.segment[0][1], y_line) 1348 assert allclose(x.segment[1][1], y_line) 1333 1349 1334 1350 … … 1339 1355 1340 1356 msg = 'Segments do not add up' 1341 assert numpy.allclose(total_length, 2), msg1357 assert allclose(total_length, 2), msg 1342 1358 1343 1359 … … 1379 1395 for x in L: 1380 1396 if x.triangle_id == 1: 1381 assert numpy.allclose(x.length, 1)1382 assert numpy.allclose(x.normal, [0, -1])1397 assert allclose(x.length, 1) 1398 assert allclose(x.normal, [0, -1]) 1383 1399 1384 1400 if x.triangle_id == 5: 1385 assert numpy.allclose(x.length, 0.5)1386 assert numpy.allclose(x.normal, [0, -1])1401 assert allclose(x.length, 0.5) 1402 assert allclose(x.normal, [0, -1]) 1387 1403 1388 1404 … … 1392 1408 1393 1409 msg = 'Segments do not add up' 1394 assert numpy.allclose(total_length, 1.5), msg1410 assert allclose(total_length, 1.5), msg 1395 1411 1396 1412 … … 1426 1442 total_length = 0 1427 1443 for i, x in enumerate(L): 1428 assert numpy.allclose(x.length, s2)1429 assert numpy.allclose(x.normal, [-s2, -s2])1430 assert numpy.allclose(sum(x.normal**2), 1)1444 assert allclose(x.length, s2) 1445 assert allclose(x.normal, [-s2, -s2]) 1446 assert allclose(sum(x.normal**2), 1) 1431 1447 1432 1448 assert x.triangle_id in intersected_triangles … … 1435 1451 1436 1452 msg = 'Segments do not add up' 1437 assert numpy.allclose(total_length, 4*s2), msg1453 assert allclose(total_length, 4*s2), msg 1438 1454 1439 1455 … … 1450 1466 total_length = 0 1451 1467 for i, x in enumerate(L): 1452 assert numpy.allclose(x.length, s2)1453 assert numpy.allclose(x.normal, [s2, s2])1454 assert numpy.allclose(sum(x.normal**2), 1)1468 assert allclose(x.length, s2) 1469 assert allclose(x.normal, [s2, s2]) 1470 assert allclose(sum(x.normal**2), 1) 1455 1471 1456 1472 assert x.triangle_id in intersected_triangles … … 1459 1475 1460 1476 msg = 'Segments do not add up' 1461 assert numpy.allclose(total_length, 4*s2), msg1477 assert allclose(total_length, 4*s2), msg 1462 1478 1463 1479 … … 1475 1491 total_length = 0 1476 1492 for i, x in enumerate(L): 1477 assert numpy.allclose(x.length, 2*s2)1478 assert numpy.allclose(x.normal, [-s2, s2])1479 assert numpy.allclose(sum(x.normal**2), 1)1493 assert allclose(x.length, 2*s2) 1494 assert allclose(x.normal, [-s2, s2]) 1495 assert allclose(sum(x.normal**2), 1) 1480 1496 1481 1497 assert x.triangle_id in intersected_triangles … … 1484 1500 1485 1501 msg = 'Segments do not add up' 1486 assert numpy.allclose(total_length, 4*s2), msg1502 assert allclose(total_length, 4*s2), msg 1487 1503 1488 1504 … … 1499 1515 total_length = 0 1500 1516 for i, x in enumerate(L): 1501 assert numpy.allclose(x.length, 2*s2)1502 assert numpy.allclose(x.normal, [s2, -s2])1503 assert numpy.allclose(sum(x.normal**2), 1)1517 assert allclose(x.length, 2*s2) 1518 assert allclose(x.normal, [s2, -s2]) 1519 assert allclose(sum(x.normal**2), 1) 1504 1520 1505 1521 assert x.triangle_id in intersected_triangles … … 1508 1524 1509 1525 msg = 'Segments do not add up' 1510 assert numpy.allclose(total_length, 4*s2), msg1526 assert allclose(total_length, 4*s2), msg 1511 1527 1512 1528 … … 1524 1540 total_length = 0 1525 1541 for i, x in enumerate(L): 1526 assert numpy.allclose(x.length, s2)1527 assert numpy.allclose(x.normal, [-s2, -s2])1528 assert numpy.allclose(sum(x.normal**2), 1)1542 assert allclose(x.length, s2) 1543 assert allclose(x.normal, [-s2, -s2]) 1544 assert allclose(sum(x.normal**2), 1) 1529 1545 1530 1546 assert x.triangle_id in intersected_triangles … … 1533 1549 1534 1550 msg = 'Segments do not add up' 1535 assert numpy.allclose(total_length, 2*s2), msg1551 assert allclose(total_length, 2*s2), msg 1536 1552 1537 1553 … … 1546 1562 total_length = 0 1547 1563 for i, x in enumerate(L): 1548 assert numpy.allclose(x.normal, [-s2, -s2])1549 assert numpy.allclose(sum(x.normal**2), 1)1564 assert allclose(x.normal, [-s2, -s2]) 1565 assert allclose(sum(x.normal**2), 1) 1550 1566 1551 1567 msg = 'Triangle %d' %x.triangle_id + ' is not in %s' %(intersected_triangles) … … 1582 1598 assert len(L) == 1 1583 1599 assert L[0].triangle_id == 3 1584 assert numpy.allclose(L[0].length, 0.5)1585 assert numpy.allclose(L[0].normal, [-1,0])1600 assert allclose(L[0].length, 0.5) 1601 assert allclose(L[0].normal, [-1,0]) 1586 1602 1587 1603 … … 1594 1610 assert len(L) == 1 1595 1611 assert L[0].triangle_id == 3 1596 assert numpy.allclose(L[0].length, 0.4)1597 assert numpy.allclose(L[0].normal, [-1,0])1612 assert allclose(L[0].length, 0.4) 1613 assert allclose(L[0].normal, [-1,0]) 1598 1614 1599 1615 intersected_triangles = [3] … … 1607 1623 assert len(L) == 1 1608 1624 assert L[0].triangle_id == 3 1609 assert numpy.allclose(L[0].length, 0.4)1610 assert numpy.allclose(L[0].normal, [1,0])1625 assert allclose(L[0].length, 0.4) 1626 assert allclose(L[0].normal, [1,0]) 1611 1627 1612 1628 … … 1642 1658 for x in L: 1643 1659 if x.triangle_id == 3: 1644 assert numpy.allclose(x.length, 0.5)1645 assert numpy.allclose(x.normal, [-1,0])1660 assert allclose(x.length, 0.5) 1661 assert allclose(x.normal, [-1,0]) 1646 1662 1647 1663 if x.triangle_id == 2: 1648 assert numpy.allclose(x.length, s2)1649 assert numpy.allclose(x.normal, [-s2,-s2])1664 assert allclose(x.length, s2) 1665 assert allclose(x.normal, [-s2,-s2]) 1650 1666 1651 1667 … … 1680 1696 for x in L: 1681 1697 if x.triangle_id == 3: 1682 assert numpy.allclose(x.length, 0.5)1683 assert numpy.allclose(x.normal, [-1,0])1698 assert allclose(x.length, 0.5) 1699 assert allclose(x.normal, [-1,0]) 1684 1700 1685 1701 if x.triangle_id == 2: 1686 1702 msg = str(x.length) 1687 assert numpy.allclose(x.length, s2), msg1688 assert numpy.allclose(x.normal, [-s2,-s2])1703 assert allclose(x.length, s2), msg 1704 assert allclose(x.normal, [-s2,-s2]) 1689 1705 1690 1706 if x.triangle_id == 5: 1691 segvec = numpy.array([line[2][0]-1,1692 1707 segvec = array([line[2][0]-1, 1708 line[2][1]-1]) 1693 1709 msg = str(x.length) 1694 assert numpy.allclose(x.length, sqrt(sum(segvec**2))), msg1695 assert numpy.allclose(x.normal, [-s2,-s2])1710 assert allclose(x.length, sqrt(sum(segvec**2))), msg 1711 assert allclose(x.normal, [-s2,-s2]) 1696 1712 1697 1713 … … 1731 1747 for x in L: 1732 1748 if x.triangle_id == 3: 1733 assert numpy.allclose(x.length, 0.5)1734 assert numpy.allclose(x.normal, [-1,0])1749 assert allclose(x.length, 0.5) 1750 assert allclose(x.normal, [-1,0]) 1735 1751 1736 1752 if x.triangle_id == 2: 1737 1753 msg = str(x.length) 1738 assert numpy.allclose(x.length, s2), msg1739 assert numpy.allclose(x.normal, [-s2,-s2])1754 assert allclose(x.length, s2), msg 1755 assert allclose(x.normal, [-s2,-s2]) 1740 1756 1741 1757 if x.triangle_id == 5: 1742 1758 if x.segment == ((1.0, 1.0), (1.25, 0.75)): 1743 segvec = numpy.array([line[2][0]-1,1744 1759 segvec = array([line[2][0]-1, 1760 line[2][1]-1]) 1745 1761 msg = str(x.length) 1746 assert numpy.allclose(x.length, sqrt(sum(segvec**2))), msg1747 assert numpy.allclose(x.normal, [-s2,-s2])1762 assert allclose(x.length, sqrt(sum(segvec**2))), msg 1763 assert allclose(x.normal, [-s2,-s2]) 1748 1764 elif x.segment == ((1.25, 0.75), (1.5, 1.0)): 1749 segvec = numpy.array([1.5-line[2][0],1750 1765 segvec = array([1.5-line[2][0], 1766 1.0-line[2][1]]) 1751 1767 1752 assert numpy.allclose(x.length, sqrt(sum(segvec**2))), msg1753 assert numpy.allclose(x.normal, [s2,-s2])1768 assert allclose(x.length, sqrt(sum(segvec**2))), msg 1769 assert allclose(x.normal, [s2,-s2]) 1754 1770 else: 1755 1771 msg = 'Unknow segment: %s' %x.segment … … 1759 1775 1760 1776 if x.triangle_id == 6: 1761 assert numpy.allclose(x.normal, [s2,-s2])1762 assert numpy.allclose(x.segment, ((1.5, 1.0), (2, 1.5)))1777 assert allclose(x.normal, [s2,-s2]) 1778 assert allclose(x.segment, ((1.5, 1.0), (2, 1.5))) 1763 1779 1764 1780 … … 1826 1842 ref_length = line[1][1] - line[0][1] 1827 1843 #print ref_length, total_length 1828 assert numpy.allclose(total_length, ref_length)1844 assert allclose(total_length, ref_length) 1829 1845 1830 1846 -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_pmesh2domain.py
r5892 r5897 3 3 4 4 import unittest 5 import numpy 5 6 from Numeric import allclose, array 7 6 8 7 9 #from anuga.pyvolution.pmesh2domain import * … … 64 66 65 67 tags = {} 66 b1 = Dirichlet_boundary(conserved_quantities = numpy.array([0.0]))67 b2 = Dirichlet_boundary(conserved_quantities = numpy.array([1.0]))68 b3 = Dirichlet_boundary(conserved_quantities = numpy.array([2.0]))68 b1 = Dirichlet_boundary(conserved_quantities = array([0.0])) 69 b2 = Dirichlet_boundary(conserved_quantities = array([1.0])) 70 b3 = Dirichlet_boundary(conserved_quantities = array([2.0])) 69 71 tags["1"] = b1 70 72 tags["2"] = b2 … … 78 80 answer = [[0., 8., 0.], 79 81 [0., 10., 8.]] 80 assert numpy.allclose(domain.quantities['elevation'].vertex_values,81 82 assert allclose(domain.quantities['elevation'].vertex_values, 83 answer) 82 84 83 85 #print domain.quantities['stage'].vertex_values 84 86 answer = [[0., 12., 10.], 85 87 [0., 10., 12.]] 86 assert numpy.allclose(domain.quantities['stage'].vertex_values,87 88 assert allclose(domain.quantities['stage'].vertex_values, 89 answer) 88 90 89 91 #print domain.quantities['friction'].vertex_values 90 92 answer = [[0.01, 0.04, 0.03], 91 93 [0.01, 0.02, 0.04]] 92 assert numpy.allclose(domain.quantities['friction'].vertex_values,93 94 95 #print domain.quantities['friction'].vertex_values 96 assert numpy.allclose(domain.tagged_elements['dsg'][0],0)97 assert numpy.allclose(domain.tagged_elements['ole nielsen'][0],1)94 assert allclose(domain.quantities['friction'].vertex_values, 95 answer) 96 97 #print domain.quantities['friction'].vertex_values 98 assert allclose(domain.tagged_elements['dsg'][0],0) 99 assert allclose(domain.tagged_elements['ole nielsen'][0],1) 98 100 99 101 self.failUnless( domain.boundary[(1, 0)] == '1', … … 157 159 158 160 tags = {} 159 b1 = Dirichlet_boundary(conserved_quantities = numpy.array([0.0]))160 b2 = Dirichlet_boundary(conserved_quantities = numpy.array([1.0]))161 b3 = Dirichlet_boundary(conserved_quantities = numpy.array([2.0]))161 b1 = Dirichlet_boundary(conserved_quantities = array([0.0])) 162 b2 = Dirichlet_boundary(conserved_quantities = array([1.0])) 163 b3 = Dirichlet_boundary(conserved_quantities = array([2.0])) 162 164 tags["1"] = b1 163 165 tags["2"] = b2 … … 172 174 answer = [[0., 8., 0.], 173 175 [0., 10., 8.]] 174 assert numpy.allclose(domain.quantities['elevation'].vertex_values,175 176 assert allclose(domain.quantities['elevation'].vertex_values, 177 answer) 176 178 177 179 #print domain.quantities['stage'].vertex_values 178 180 answer = [[0., 12., 10.], 179 181 [0., 10., 12.]] 180 assert numpy.allclose(domain.quantities['stage'].vertex_values,181 182 assert allclose(domain.quantities['stage'].vertex_values, 183 answer) 182 184 183 185 #print domain.quantities['friction'].vertex_values 184 186 answer = [[0.01, 0.04, 0.03], 185 187 [0.01, 0.02, 0.04]] 186 assert numpy.allclose(domain.quantities['friction'].vertex_values,187 188 189 #print domain.quantities['friction'].vertex_values 190 assert numpy.allclose(domain.tagged_elements['dsg'][0],0)191 assert numpy.allclose(domain.tagged_elements['ole nielsen'][0],1)188 assert allclose(domain.quantities['friction'].vertex_values, 189 answer) 190 191 #print domain.quantities['friction'].vertex_values 192 assert allclose(domain.tagged_elements['dsg'][0],0) 193 assert allclose(domain.tagged_elements['ole nielsen'][0],1) 192 194 193 195 self.failUnless( domain.boundary[(1, 0)] == '1', … … 226 228 #domain.set_tag_dict(tag_dict) 227 229 #Boundary tests 228 b1 = Dirichlet_boundary(conserved_quantities = numpy.array([0.0]))229 b2 = Dirichlet_boundary(conserved_quantities = numpy.array([1.0]))230 b3 = Dirichlet_boundary(conserved_quantities = numpy.array([1.0]))230 b1 = Dirichlet_boundary(conserved_quantities = array([0.0])) 231 b2 = Dirichlet_boundary(conserved_quantities = array([1.0])) 232 b3 = Dirichlet_boundary(conserved_quantities = array([1.0])) 231 233 #test adding a boundary 232 234 tags = {} -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py
r5894 r5897 7 7 from quantity import * 8 8 from anuga.config import epsilon 9 import numpy 9 from Numeric import allclose, array, ones, Float 10 10 11 11 from anuga.fit_interpolate.fit import fit_to_mesh … … 18 18 #Aux for fit_interpolate.fit example 19 19 def linear_function(point): 20 point = numpy.array(point)20 point = array(point) 21 21 return point[:,0]+point[:,1] 22 22 … … 63 63 64 64 quantity = Quantity(self.mesh1, [[1,2,3]]) 65 assert numpy.allclose(quantity.vertex_values, [[1.,2.,3.]])65 assert allclose(quantity.vertex_values, [[1.,2.,3.]]) 66 66 67 67 try: … … 84 84 85 85 quantity = Quantity(self.mesh1) 86 assert numpy.allclose(quantity.vertex_values, [[0.,0.,0.]])87 88 89 quantity = Quantity(self.mesh4) 90 assert numpy.allclose(quantity.vertex_values, [[0.,0.,0.], [0.,0.,0.],86 assert allclose(quantity.vertex_values, [[0.,0.,0.]]) 87 88 89 quantity = Quantity(self.mesh4) 90 assert allclose(quantity.vertex_values, [[0.,0.,0.], [0.,0.,0.], 91 91 [0.,0.,0.], [0.,0.,0.]]) 92 92 … … 94 94 def test_interpolation(self): 95 95 quantity = Quantity(self.mesh1, [[1,2,3]]) 96 assert numpy.allclose(quantity.centroid_values, [2.0]) #Centroid97 98 assert numpy.allclose(quantity.edge_values, [[2.5, 2.0, 1.5]])96 assert allclose(quantity.centroid_values, [2.0]) #Centroid 97 98 assert allclose(quantity.edge_values, [[2.5, 2.0, 1.5]]) 99 99 100 100 … … 102 102 quantity = Quantity(self.mesh4, 103 103 [[1,2,3], [5,5,5], [0,0,9], [-6, 3, 3]]) 104 assert numpy.allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroid104 assert allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroid 105 105 106 106 … … 108 108 109 109 #print quantity.vertex_values 110 assert numpy.allclose(quantity.vertex_values, [[3.5, -1.0, 3.5],111 112 113 110 assert allclose(quantity.vertex_values, [[3.5, -1.0, 3.5], 111 [3.+2./3, 6.+2./3, 4.+2./3], 112 [4.6, 3.4, 1.], 113 [-5.0, 1.0, 4.0]]) 114 114 115 115 #print quantity.edge_values 116 assert numpy.allclose(quantity.edge_values, [[1.25, 3.5, 1.25],117 118 119 120 121 122 #assert numpy.allclose(quantity.edge_values, [[2.5, 2.0, 1.5],123 # 124 # 125 # 116 assert allclose(quantity.edge_values, [[1.25, 3.5, 1.25], 117 [5. + 2/3.0, 4.0 + 1.0/6, 5.0 + 1.0/6], 118 [2.2, 2.8, 4.0], 119 [2.5, -0.5, -2.0]]) 120 121 122 #assert allclose(quantity.edge_values, [[2.5, 2.0, 1.5], 123 # [5., 5., 5.], 124 # [4.5, 4.5, 0.], 125 # [3.0, -1.5, -1.5]]) 126 126 127 127 def test_get_extrema_1(self): 128 128 quantity = Quantity(self.mesh4, 129 129 [[1,2,3], [5,5,5], [0,0,9], [-6, 3, 3]]) 130 assert numpy.allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroids130 assert allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroids 131 131 132 132 v = quantity.get_maximum_value() … … 148 148 149 149 v = quantity.get_values(interpolation_points = [[x,y]]) 150 assert numpy.allclose(v, 5)150 assert allclose(v, 5) 151 151 152 152 153 153 x,y = quantity.get_minimum_location() 154 154 v = quantity.get_values(interpolation_points = [[x,y]]) 155 assert numpy.allclose(v, 0)155 assert allclose(v, 0) 156 156 157 157 … … 192 192 193 193 v = quantity.get_values(interpolation_points = [[x,y]]) 194 assert numpy.allclose(v, 6)194 assert allclose(v, 6) 195 195 196 196 x,y = quantity.get_minimum_location() 197 197 v = quantity.get_values(interpolation_points = [[x,y]]) 198 assert numpy.allclose(v, 2)198 assert allclose(v, 2) 199 199 200 200 #Multiple locations for maximum - 201 201 #Test that the algorithm picks the first occurrence 202 202 v = quantity.get_maximum_value(indices=[0,1,2]) 203 assert numpy.allclose(v, 4)203 assert allclose(v, 4) 204 204 205 205 i = quantity.get_maximum_index(indices=[0,1,2]) … … 212 212 213 213 v = quantity.get_values(interpolation_points = [[x,y]]) 214 assert numpy.allclose(v, 4)214 assert allclose(v, 4) 215 215 216 216 # More test of indices...... 217 217 v = quantity.get_maximum_value(indices=[2,3]) 218 assert numpy.allclose(v, 6)218 assert allclose(v, 6) 219 219 220 220 i = quantity.get_maximum_index(indices=[2,3]) … … 227 227 228 228 v = quantity.get_values(interpolation_points = [[x,y]]) 229 assert numpy.allclose(v, 6)229 assert allclose(v, 6) 230 230 231 231 … … 244 244 quantity.set_values([[1,2,3], [5,5,5], [0,0,9], [-6, 3, 3]], 245 245 location = 'vertices') 246 assert numpy.allclose(quantity.vertex_values,247 248 assert numpy.allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroid249 assert numpy.allclose(quantity.edge_values, [[2.5, 2.0, 1.5],250 251 252 246 assert allclose(quantity.vertex_values, 247 [[1,2,3], [5,5,5], [0,0,9], [-6, 3, 3]]) 248 assert allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroid 249 assert allclose(quantity.edge_values, [[2.5, 2.0, 1.5], 250 [5., 5., 5.], 251 [4.5, 4.5, 0.], 252 [3.0, -1.5, -1.5]]) 253 253 254 254 255 255 # Test default 256 256 quantity.set_values([[1,2,3], [5,5,5], [0,0,9], [-6, 3, 3]]) 257 assert numpy.allclose(quantity.vertex_values,258 259 assert numpy.allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroid260 assert numpy.allclose(quantity.edge_values, [[2.5, 2.0, 1.5],261 262 263 257 assert allclose(quantity.vertex_values, 258 [[1,2,3], [5,5,5], [0,0,9], [-6, 3, 3]]) 259 assert allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroid 260 assert allclose(quantity.edge_values, [[2.5, 2.0, 1.5], 261 [5., 5., 5.], 262 [4.5, 4.5, 0.], 263 [3.0, -1.5, -1.5]]) 264 264 265 265 # Test centroids 266 266 quantity.set_values([1,2,3,4], location = 'centroids') 267 assert numpy.allclose(quantity.centroid_values, [1., 2., 3., 4.]) #Centroid267 assert allclose(quantity.centroid_values, [1., 2., 3., 4.]) #Centroid 268 268 269 269 # Test exceptions … … 288 288 289 289 quantity.set_values(1.0, location = 'vertices') 290 assert numpy.allclose(quantity.vertex_values,291 292 293 assert numpy.allclose(quantity.centroid_values, [1, 1, 1, 1]) #Centroid294 assert numpy.allclose(quantity.edge_values, [[1, 1, 1],295 296 297 290 assert allclose(quantity.vertex_values, 291 [[1,1,1], [1,1,1], [1,1,1], [1, 1, 1]]) 292 293 assert allclose(quantity.centroid_values, [1, 1, 1, 1]) #Centroid 294 assert allclose(quantity.edge_values, [[1, 1, 1], 295 [1, 1, 1], 296 [1, 1, 1], 297 [1, 1, 1]]) 298 298 299 299 300 300 quantity.set_values(2.0, location = 'centroids') 301 assert numpy.allclose(quantity.centroid_values, [2, 2, 2, 2])301 assert allclose(quantity.centroid_values, [2, 2, 2, 2]) 302 302 303 303 … … 310 310 quantity.set_values(f, location = 'vertices') 311 311 #print "quantity.vertex_values",quantity.vertex_values 312 assert numpy.allclose(quantity.vertex_values,313 314 assert numpy.allclose(quantity.centroid_values,315 316 assert numpy.allclose(quantity.edge_values,317 312 assert allclose(quantity.vertex_values, 313 [[2,0,2], [2,2,4], [4,2,4], [4,2,4]]) 314 assert allclose(quantity.centroid_values, 315 [4.0/3, 8.0/3, 10.0/3, 10.0/3]) 316 assert allclose(quantity.edge_values, 317 [[1,2,1], [3,3,2], [3,4,3], [3,4,3]]) 318 318 319 319 320 320 quantity.set_values(f, location = 'centroids') 321 assert numpy.allclose(quantity.centroid_values,322 321 assert allclose(quantity.centroid_values, 322 [4.0/3, 8.0/3, 10.0/3, 10.0/3]) 323 323 324 324 … … 331 331 #print 'Q', quantity.get_integral() 332 332 333 assert numpy.allclose(quantity.get_integral(), self.mesh4.get_area() * const)333 assert allclose(quantity.get_integral(), self.mesh4.get_area() * const) 334 334 335 335 #Try with a linear function … … 342 342 ref_integral = (4.0/3 + 8.0/3 + 10.0/3 + 10.0/3) * 2 343 343 344 assert numpy.allclose (quantity.get_integral(), ref_integral)344 assert allclose (quantity.get_integral(), ref_integral) 345 345 346 346 … … 350 350 quantity.set_vertex_values([0,1,2,3,4,5]) 351 351 352 assert numpy.allclose(quantity.vertex_values,353 354 assert numpy.allclose(quantity.centroid_values,355 356 assert numpy.allclose(quantity.edge_values, [[1., 1.5, 0.5],357 358 359 352 assert allclose(quantity.vertex_values, 353 [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 354 assert allclose(quantity.centroid_values, 355 [1., 7./3, 11./3, 8./3]) #Centroid 356 assert allclose(quantity.edge_values, [[1., 1.5, 0.5], 357 [3., 2.5, 1.5], 358 [3.5, 4.5, 3.], 359 [2.5, 3.5, 2]]) 360 360 361 361 … … 365 365 quantity.set_vertex_values([0,20,30,50], indices = [0,2,3,5]) 366 366 367 assert numpy.allclose(quantity.vertex_values,368 367 assert allclose(quantity.vertex_values, 368 [[1,0,20], [1,20,4], [4,20,50], [30,1,4]]) 369 369 370 370 … … 376 376 377 377 378 assert numpy.allclose(quantity.vertex_values,379 378 assert allclose(quantity.vertex_values, 379 [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 380 380 381 381 #Centroid 382 assert numpy.allclose(quantity.centroid_values, [1., 7./3, 11./3, 8./3])383 384 assert numpy.allclose(quantity.edge_values, [[1., 1.5, 0.5],385 386 387 382 assert allclose(quantity.centroid_values, [1., 7./3, 11./3, 8./3]) 383 384 assert allclose(quantity.edge_values, [[1., 1.5, 0.5], 385 [3., 2.5, 1.5], 386 [3.5, 4.5, 3.], 387 [2.5, 3.5, 2]]) 388 388 389 389 … … 399 399 400 400 quantity.set_values([0,2,3,5], indices=[0,2,3,5]) 401 assert numpy.allclose(quantity.vertex_values,402 401 assert allclose(quantity.vertex_values, 402 [[0,0,2], [0,2,0], [0,2,5], [3,0,0]]) 403 403 404 404 … … 408 408 409 409 # Indices refer to triangle numbers 410 assert numpy.allclose(quantity.vertex_values,411 412 410 assert allclose(quantity.vertex_values, 411 [[3.14,3.14,3.14], [0,0,0], 412 [3.14,3.14,3.14], [0,0,0]]) 413 413 414 414 … … 419 419 quantity.set_values(3.14, polygon=polygon) 420 420 421 assert numpy.allclose(quantity.vertex_values,422 423 421 assert allclose(quantity.vertex_values, 422 [[0,0,0], [0,0,0], [0,0,0], 423 [3.14,3.14,3.14]]) 424 424 425 425 … … 429 429 quantity.set_values(0.0) 430 430 quantity.set_values(3.14, location='centroids', polygon=polygon) 431 assert numpy.allclose(quantity.vertex_values,432 433 434 435 431 assert allclose(quantity.vertex_values, 432 [[0,0,0], 433 [3.14,3.14,3.14], 434 [3.14,3.14,3.14], 435 [0,0,0]]) 436 436 437 437 … … 441 441 #print 'Here 2' 442 442 quantity.set_values(3.14, polygon=polygon) 443 assert numpy.allclose(quantity.vertex_values,444 445 446 447 443 assert allclose(quantity.vertex_values, 444 [[0,0,0], 445 [3.14,3.14,3.14], 446 [3.14,3.14,3.14], 447 [0,0,0]]) 448 448 449 449 … … 478 478 479 479 # Indices refer to triangle numbers here - not vertices (why?) 480 assert numpy.allclose(quantity.vertex_values,481 482 480 assert allclose(quantity.vertex_values, 481 [[3.14,3.14,3.14], [0,0,0], 482 [3.14,3.14,3.14], [0,0,0]]) 483 483 484 484 485 485 486 486 # Now try with polygon (pick points where y>2) 487 polygon = numpy.array([[0,2.1], [4,2.1], [4,7], [0,7]])487 polygon = array([[0,2.1], [4,2.1], [4,7], [0,7]]) 488 488 polygon += [G.xllcorner, G.yllcorner] 489 489 … … 491 491 quantity.set_values(3.14, polygon=polygon, location='centroids') 492 492 493 assert numpy.allclose(quantity.vertex_values,494 495 493 assert allclose(quantity.vertex_values, 494 [[0,0,0], [0,0,0], [0,0,0], 495 [3.14,3.14,3.14]]) 496 496 497 497 498 498 # Another polygon (pick triangle 1 and 2 (rightmost triangles) 499 polygon = numpy.array([[2.1, 0.0], [3.5,0.1], [2,2.2], [0.2,2]])499 polygon = array([[2.1, 0.0], [3.5,0.1], [2,2.2], [0.2,2]]) 500 500 polygon += [G.xllcorner, G.yllcorner] 501 501 … … 503 503 quantity.set_values(3.14, polygon=polygon) 504 504 505 assert numpy.allclose(quantity.vertex_values,506 507 508 509 505 assert allclose(quantity.vertex_values, 506 [[0,0,0], 507 [3.14,3.14,3.14], 508 [3.14,3.14,3.14], 509 [0,0,0]]) 510 510 511 511 … … 540 540 answer = linear_function(quantity.domain.get_vertex_coordinates()) 541 541 #print quantity.vertex_values, answer 542 assert numpy.allclose(quantity.vertex_values.ravel(), answer)542 assert allclose(quantity.vertex_values.flat, answer) 543 543 544 544 … … 553 553 #print vertex_attributes 554 554 quantity.set_values(vertex_attributes) 555 assert numpy.allclose(quantity.vertex_values.ravel(), answer)555 assert allclose(quantity.vertex_values.flat, answer) 556 556 557 557 … … 593 593 alpha = 0) 594 594 595 assert numpy.allclose( ref, [0,5,5] )595 assert allclose( ref, [0,5,5] ) 596 596 597 597 … … 610 610 # data_georef = data_georef, 611 611 # alpha = 0) 612 assert numpy.allclose(quantity.vertex_values.ravel(), ref)612 assert allclose(quantity.vertex_values.flat, ref) 613 613 614 614 … … 621 621 622 622 quantity.set_values(geospatial_data = geo, alpha = 0) 623 assert numpy.allclose(quantity.vertex_values.ravel(), ref)623 assert allclose(quantity.vertex_values.flat, ref) 624 624 625 625 … … 666 666 answer = linear_function(quantity.domain.get_vertex_coordinates()) 667 667 668 #print quantity.vertex_values. ravel()668 #print quantity.vertex_values.flat 669 669 #print answer 670 670 671 671 672 assert numpy.allclose(quantity.vertex_values.ravel(), answer)672 assert allclose(quantity.vertex_values.flat, answer) 673 673 674 674 675 675 #Check that values can be set from file using default attribute 676 676 quantity.set_values(filename = ptsfile, alpha = 0) 677 assert numpy.allclose(quantity.vertex_values.ravel(), answer)677 assert allclose(quantity.vertex_values.flat, answer) 678 678 679 679 #Cleanup … … 730 730 #print self.mesh4.nodes 731 731 #print inside_polygon(self.mesh4.nodes, polygon) 732 assert numpy.allclose(inside_polygon(self.mesh4.nodes, polygon), 4)732 assert allclose(inside_polygon(self.mesh4.nodes, polygon), 4) 733 733 734 734 #print quantity.domain.get_vertex_coordinates() … … 748 748 answer = linear_function(points) 749 749 750 #print quantity.vertex_values. ravel()750 #print quantity.vertex_values.flat 751 751 #print answer 752 752 753 753 # Check vertices in polygon have been set 754 assert numpy.allclose(take(quantity.vertex_values.ravel(), indices),755 754 assert allclose(take(quantity.vertex_values.flat, indices), 755 answer) 756 756 757 757 # Check vertices outside polygon are zero 758 758 indices = outside_polygon(quantity.domain.get_vertex_coordinates(), 759 759 polygon) 760 assert numpy.allclose(take(quantity.vertex_values.ravel(), indices),761 760 assert allclose(take(quantity.vertex_values.flat, indices), 761 0.0) 762 762 763 763 #Cleanup … … 815 815 verbose=False) 816 816 answer = linear_function(quantity.domain.get_vertex_coordinates()) 817 assert numpy.allclose(quantity.vertex_values.ravel(), answer)817 assert allclose(quantity.vertex_values.flat, answer) 818 818 819 819 … … 821 821 quantity.set_values(filename=ptsfile, 822 822 alpha=0) 823 assert numpy.allclose(quantity.vertex_values.ravel(), answer)823 assert allclose(quantity.vertex_values.flat, answer) 824 824 825 825 # Check cache … … 866 866 answer = linear_function(quantity.domain.get_vertex_coordinates()) 867 867 868 #print "quantity.vertex_values. ravel()", quantity.vertex_values.ravel()868 #print "quantity.vertex_values.flat", quantity.vertex_values.flat 869 869 #print "answer",answer 870 870 871 assert numpy.allclose(quantity.vertex_values.ravel(), answer)871 assert allclose(quantity.vertex_values.flat, answer) 872 872 873 873 874 874 #Check that values can be set from file using default attribute 875 875 quantity.set_values(filename=txt_file, alpha=0) 876 assert numpy.allclose(quantity.vertex_values.ravel(), answer)876 assert allclose(quantity.vertex_values.flat, answer) 877 877 878 878 #Cleanup … … 910 910 answer = linear_function(quantity.domain.get_vertex_coordinates()) 911 911 912 #print "quantity.vertex_values. ravel()", quantity.vertex_values.ravel()912 #print "quantity.vertex_values.flat", quantity.vertex_values.flat 913 913 #print "answer",answer 914 914 915 assert numpy.allclose(quantity.vertex_values.ravel(), answer)915 assert allclose(quantity.vertex_values.flat, answer) 916 916 917 917 918 918 #Check that values can be set from file using default attribute 919 919 quantity.set_values(filename=txt_file, alpha=0) 920 assert numpy.allclose(quantity.vertex_values.ravel(), answer)920 assert allclose(quantity.vertex_values.flat, answer) 921 921 922 922 #Cleanup … … 957 957 'vertices', None) 958 958 answer = linear_function(quantity.domain.get_vertex_coordinates()) 959 #print "quantity.vertex_values. ravel()", quantity.vertex_values.ravel()959 #print "quantity.vertex_values.flat", quantity.vertex_values.flat 960 960 #print "answer",answer 961 assert numpy.allclose(quantity.vertex_values.ravel(), answer)961 assert allclose(quantity.vertex_values.flat, answer) 962 962 963 963 #Check that values can be set from file … … 965 965 attribute_name=att, alpha=0) 966 966 answer = linear_function(quantity.domain.get_vertex_coordinates()) 967 #print "quantity.vertex_values. ravel()", quantity.vertex_values.ravel()967 #print "quantity.vertex_values.flat", quantity.vertex_values.flat 968 968 #print "answer",answer 969 assert numpy.allclose(quantity.vertex_values.ravel(), answer)969 assert allclose(quantity.vertex_values.flat, answer) 970 970 971 971 972 972 #Check that values can be set from file using default attribute 973 973 quantity.set_values(filename=txt_file, alpha=0) 974 assert numpy.allclose(quantity.vertex_values.ravel(), answer)974 assert allclose(quantity.vertex_values.flat, answer) 975 975 976 976 #Cleanup … … 1039 1039 max_read_lines=2) 1040 1040 answer = linear_function(quantity.domain.get_vertex_coordinates()) 1041 #print "quantity.vertex_values. ravel()", quantity.vertex_values.ravel()1041 #print "quantity.vertex_values.flat", quantity.vertex_values.flat 1042 1042 #print "answer",answer 1043 assert numpy.allclose(quantity.vertex_values.ravel(), answer)1043 assert allclose(quantity.vertex_values.flat, answer) 1044 1044 1045 1045 #Check that values can be set from file … … 1047 1047 attribute_name=att, alpha=0) 1048 1048 answer = linear_function(quantity.domain.get_vertex_coordinates()) 1049 #print "quantity.vertex_values. ravel()", quantity.vertex_values.ravel()1049 #print "quantity.vertex_values.flat", quantity.vertex_values.flat 1050 1050 #print "answer",answer 1051 assert numpy.allclose(quantity.vertex_values.ravel(), answer)1051 assert allclose(quantity.vertex_values.flat, answer) 1052 1052 1053 1053 1054 1054 #Check that values can be set from file using default attribute 1055 1055 quantity.set_values(filename=txt_file, alpha=0) 1056 assert numpy.allclose(quantity.vertex_values.ravel(), answer)1056 assert allclose(quantity.vertex_values.flat, answer) 1057 1057 1058 1058 #Cleanup … … 1128 1128 answer = linear_function(quantity.domain.get_vertex_coordinates()) 1129 1129 1130 assert numpy.allclose(quantity.vertex_values.ravel(), answer)1130 assert allclose(quantity.vertex_values.flat, answer) 1131 1131 1132 1132 1133 1133 #Check that values can be set from file using default attribute 1134 1134 quantity.set_values(filename=ptsfile, alpha=0) 1135 assert numpy.allclose(quantity.vertex_values.ravel(), answer)1135 assert allclose(quantity.vertex_values.flat, answer) 1136 1136 1137 1137 #Cleanup … … 1207 1207 1208 1208 1209 assert numpy.allclose(quantity.vertex_values.ravel(), answer)1209 assert allclose(quantity.vertex_values.flat, answer) 1210 1210 1211 1211 1212 1212 #Check that values can be set from file using default attribute 1213 1213 quantity.set_values(filename=ptsfile, alpha=0) 1214 assert numpy.allclose(quantity.vertex_values.ravel(), answer)1214 assert allclose(quantity.vertex_values.flat, answer) 1215 1215 1216 1216 #Cleanup … … 1226 1226 quantity1.set_vertex_values([0,1,2,3,4,5]) 1227 1227 1228 assert numpy.allclose(quantity1.vertex_values,1229 1228 assert allclose(quantity1.vertex_values, 1229 [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 1230 1230 1231 1231 1232 1232 quantity2 = Quantity(self.mesh4) 1233 1233 quantity2.set_values(quantity=quantity1) 1234 assert numpy.allclose(quantity2.vertex_values,1235 1234 assert allclose(quantity2.vertex_values, 1235 [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 1236 1236 1237 1237 quantity2.set_values(quantity = 2*quantity1) 1238 assert numpy.allclose(quantity2.vertex_values,1239 1238 assert allclose(quantity2.vertex_values, 1239 [[2,0,4], [2,4,8], [8,4,10], [6,2,8]]) 1240 1240 1241 1241 quantity2.set_values(quantity = 2*quantity1 + 3) 1242 assert numpy.allclose(quantity2.vertex_values,1243 1242 assert allclose(quantity2.vertex_values, 1243 [[5,3,7], [5,7,11], [11,7,13], [9,5,11]]) 1244 1244 1245 1245 1246 1246 #Check detection of quantity as first orgument 1247 1247 quantity2.set_values(2*quantity1 + 3) 1248 assert numpy.allclose(quantity2.vertex_values,1249 1248 assert allclose(quantity2.vertex_values, 1249 [[5,3,7], [5,7,11], [11,7,13], [9,5,11]]) 1250 1250 1251 1251 … … 1262 1262 polygon = [[1.0, 1.0], [4.0, 1.0], 1263 1263 [4.0, 4.0], [1.0, 4.0]] 1264 assert numpy.allclose(inside_polygon(self.mesh4.nodes, polygon), 4)1264 assert allclose(inside_polygon(self.mesh4.nodes, polygon), 4) 1265 1265 1266 1266 quantity1 = Quantity(self.mesh4) 1267 1267 quantity1.set_vertex_values([0,1,2,3,4,5]) 1268 1268 1269 assert numpy.allclose(quantity1.vertex_values,1270 1269 assert allclose(quantity1.vertex_values, 1270 [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 1271 1271 1272 1272 … … 1276 1276 1277 1277 msg = 'Only node #4(e) at (2,2) should have values applied ' 1278 assert numpy.allclose(quantity2.vertex_values,1279 1280 1278 assert allclose(quantity2.vertex_values, 1279 [[0,0,0], [0,0,4], [4,0,0], [0,0,4]]), msg 1280 #bac, bce, ecf, dbe 1281 1281 1282 1282 … … 1287 1287 quantity1.set_vertex_values([0,1,2,3,4,5]) 1288 1288 1289 assert numpy.allclose(quantity1.vertex_values,1290 1289 assert allclose(quantity1.vertex_values, 1290 [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 1291 1291 1292 1292 … … 1304 1304 # Negation 1305 1305 Q = -quantity1 1306 assert numpy.allclose(Q.vertex_values, -quantity1.vertex_values)1307 assert numpy.allclose(Q.centroid_values, -quantity1.centroid_values)1308 assert numpy.allclose(Q.edge_values, -quantity1.edge_values)1306 assert allclose(Q.vertex_values, -quantity1.vertex_values) 1307 assert allclose(Q.centroid_values, -quantity1.centroid_values) 1308 assert allclose(Q.edge_values, -quantity1.edge_values) 1309 1309 1310 1310 # Addition 1311 1311 Q = quantity1 + 7 1312 assert numpy.allclose(Q.vertex_values, quantity1.vertex_values + 7)1313 assert numpy.allclose(Q.centroid_values, quantity1.centroid_values + 7)1314 assert numpy.allclose(Q.edge_values, quantity1.edge_values + 7)1312 assert allclose(Q.vertex_values, quantity1.vertex_values + 7) 1313 assert allclose(Q.centroid_values, quantity1.centroid_values + 7) 1314 assert allclose(Q.edge_values, quantity1.edge_values + 7) 1315 1315 1316 1316 Q = 7 + quantity1 1317 assert numpy.allclose(Q.vertex_values, quantity1.vertex_values + 7)1318 assert numpy.allclose(Q.centroid_values, quantity1.centroid_values + 7)1319 assert numpy.allclose(Q.edge_values, quantity1.edge_values + 7)1317 assert allclose(Q.vertex_values, quantity1.vertex_values + 7) 1318 assert allclose(Q.centroid_values, quantity1.centroid_values + 7) 1319 assert allclose(Q.edge_values, quantity1.edge_values + 7) 1320 1320 1321 1321 Q = quantity1 + quantity2 1322 assert numpy.allclose(Q.vertex_values,1323 1324 assert numpy.allclose(Q.centroid_values,1325 1326 assert numpy.allclose(Q.edge_values,1327 1322 assert allclose(Q.vertex_values, 1323 quantity1.vertex_values + quantity2.vertex_values) 1324 assert allclose(Q.centroid_values, 1325 quantity1.centroid_values + quantity2.centroid_values) 1326 assert allclose(Q.edge_values, 1327 quantity1.edge_values + quantity2.edge_values) 1328 1328 1329 1329 1330 1330 Q = quantity1 + quantity2 - 3 1331 assert numpy.allclose(Q.vertex_values,1332 1331 assert allclose(Q.vertex_values, 1332 quantity1.vertex_values + quantity2.vertex_values - 3) 1333 1333 1334 1334 Q = quantity1 - quantity2 1335 assert numpy.allclose(Q.vertex_values,1336 1335 assert allclose(Q.vertex_values, 1336 quantity1.vertex_values - quantity2.vertex_values) 1337 1337 1338 1338 #Scaling 1339 1339 Q = quantity1*3 1340 assert numpy.allclose(Q.vertex_values, quantity1.vertex_values*3)1341 assert numpy.allclose(Q.centroid_values, quantity1.centroid_values*3)1342 assert numpy.allclose(Q.edge_values, quantity1.edge_values*3)1340 assert allclose(Q.vertex_values, quantity1.vertex_values*3) 1341 assert allclose(Q.centroid_values, quantity1.centroid_values*3) 1342 assert allclose(Q.edge_values, quantity1.edge_values*3) 1343 1343 Q = 3*quantity1 1344 assert numpy.allclose(Q.vertex_values, quantity1.vertex_values*3)1344 assert allclose(Q.vertex_values, quantity1.vertex_values*3) 1345 1345 1346 1346 #Multiplication … … 1351 1351 #print quantity2.centroid_values 1352 1352 1353 assert numpy.allclose(Q.vertex_values,1354 1353 assert allclose(Q.vertex_values, 1354 quantity1.vertex_values * quantity2.vertex_values) 1355 1355 1356 1356 #Linear combinations 1357 1357 Q = 4*quantity1 + 2 1358 assert numpy.allclose(Q.vertex_values,1359 1358 assert allclose(Q.vertex_values, 1359 4*quantity1.vertex_values + 2) 1360 1360 1361 1361 Q = quantity1*quantity2 + 2 1362 assert numpy.allclose(Q.vertex_values,1363 1362 assert allclose(Q.vertex_values, 1363 quantity1.vertex_values * quantity2.vertex_values + 2) 1364 1364 1365 1365 Q = quantity1*quantity2 + quantity3 1366 assert numpy.allclose(Q.vertex_values,1367 1368 1366 assert allclose(Q.vertex_values, 1367 quantity1.vertex_values * quantity2.vertex_values + 1368 quantity3.vertex_values) 1369 1369 Q = quantity1*quantity2 + 3*quantity3 1370 assert numpy.allclose(Q.vertex_values,1371 1372 1370 assert allclose(Q.vertex_values, 1371 quantity1.vertex_values * quantity2.vertex_values + 1372 3*quantity3.vertex_values) 1373 1373 Q = quantity1*quantity2 + 3*quantity3 + 5.0 1374 assert numpy.allclose(Q.vertex_values,1375 1376 1374 assert allclose(Q.vertex_values, 1375 quantity1.vertex_values * quantity2.vertex_values + 1376 3*quantity3.vertex_values + 5) 1377 1377 1378 1378 Q = quantity1*quantity2 - quantity3 1379 assert numpy.allclose(Q.vertex_values,1380 1381 1379 assert allclose(Q.vertex_values, 1380 quantity1.vertex_values * quantity2.vertex_values - 1381 quantity3.vertex_values) 1382 1382 Q = 1.5*quantity1*quantity2 - 3*quantity3 + 5.0 1383 assert numpy.allclose(Q.vertex_values,1384 1385 1383 assert allclose(Q.vertex_values, 1384 1.5*quantity1.vertex_values * quantity2.vertex_values - 1385 3*quantity3.vertex_values + 5) 1386 1386 1387 1387 #Try combining quantities and arrays and scalars 1388 Q = 1.5*quantity1*quantity2.vertex_values - 1388 Q = 1.5*quantity1*quantity2.vertex_values -\ 1389 1389 3*quantity3.vertex_values + 5.0 1390 assert numpy.allclose(Q.vertex_values,1391 1392 1390 assert allclose(Q.vertex_values, 1391 1.5*quantity1.vertex_values * quantity2.vertex_values - 1392 3*quantity3.vertex_values + 5) 1393 1393 1394 1394 1395 1395 #Powers 1396 1396 Q = quantity1**2 1397 assert numpy.allclose(Q.vertex_values, quantity1.vertex_values**2)1397 assert allclose(Q.vertex_values, quantity1.vertex_values**2) 1398 1398 1399 1399 Q = quantity1**2 +quantity2**2 1400 assert numpy.allclose(Q.vertex_values,1401 quantity1.vertex_values**2 +1402 1400 assert allclose(Q.vertex_values, 1401 quantity1.vertex_values**2 + \ 1402 quantity2.vertex_values**2) 1403 1403 1404 1404 Q = (quantity1**2 +quantity2**2)**0.5 1405 assert numpy.allclose(Q.vertex_values,1406 (quantity1.vertex_values**2 +1407 1405 assert allclose(Q.vertex_values, 1406 (quantity1.vertex_values**2 + \ 1407 quantity2.vertex_values**2)**0.5) 1408 1408 1409 1409 … … 1431 1431 #The central triangle (1) 1432 1432 #(using standard gradient based on neigbours controid values) 1433 assert numpy.allclose(a[1], 2.0)1434 assert numpy.allclose(b[1], 0.0)1433 assert allclose(a[1], 2.0) 1434 assert allclose(b[1], 0.0) 1435 1435 1436 1436 … … 1438 1438 #q0 = q1 + a*(x0-x1) + b*(y0-y1) <=> 1439 1439 #2 = 4 + a*(-2/3) + b*(-2/3) 1440 assert numpy.allclose(a[0] + b[0], 3)1440 assert allclose(a[0] + b[0], 3) 1441 1441 #From orthogonality (a*(y0-y1) + b*(x0-x1) == 0) 1442 assert numpy.allclose(a[0] - b[0], 0)1442 assert allclose(a[0] - b[0], 0) 1443 1443 1444 1444 … … 1446 1446 #q2 = q1 + a*(x2-x1) + b*(y2-y1) <=> 1447 1447 #6 = 4 + a*(4/3) + b*(-2/3) 1448 assert numpy.allclose(2*a[2] - b[2], 3)1448 assert allclose(2*a[2] - b[2], 3) 1449 1449 #From orthogonality (a*(y1-y2) + b*(x2-x1) == 0) 1450 assert numpy.allclose(a[2] + 2*b[2], 0)1450 assert allclose(a[2] + 2*b[2], 0) 1451 1451 1452 1452 … … 1454 1454 #q3 = q1 + a*(x3-x1) + b*(y3-y1) <=> 1455 1455 #2 = 4 + a*(-2/3) + b*(4/3) 1456 assert numpy.allclose(a[3] - 2*b[3], 3)1456 assert allclose(a[3] - 2*b[3], 3) 1457 1457 #From orthogonality (a*(y1-y3) + b*(x3-x1) == 0) 1458 assert numpy.allclose(2*a[3] + b[3], 0)1458 assert allclose(2*a[3] + b[3], 0) 1459 1459 1460 1460 … … 1464 1464 1465 1465 #Apply q(x,y) = qc + a*(x-xc) + b*(y-yc) 1466 assert numpy.allclose(quantity.vertex_values[0,:], [3., 0., 3.])1467 assert numpy.allclose(quantity.vertex_values[1,:], [4./3, 16./3, 16./3])1466 assert allclose(quantity.vertex_values[0,:], [3., 0., 3.]) 1467 assert allclose(quantity.vertex_values[1,:], [4./3, 16./3, 16./3]) 1468 1468 1469 1469 1470 1470 #a = 1.2, b=-0.6 1471 1471 #q(4,0) = 6 + a*(4 - 8/3) + b*(-2/3) 1472 assert numpy.allclose(quantity.vertex_values[2,2], 8)1472 assert allclose(quantity.vertex_values[2,2], 8) 1473 1473 1474 1474 def test_get_gradients(self): … … 1489 1489 #The central triangle (1) 1490 1490 #(using standard gradient based on neigbours controid values) 1491 assert numpy.allclose(a[1], 2.0)1492 assert numpy.allclose(b[1], 0.0)1491 assert allclose(a[1], 2.0) 1492 assert allclose(b[1], 0.0) 1493 1493 1494 1494 … … 1496 1496 #q0 = q1 + a*(x0-x1) + b*(y0-y1) <=> 1497 1497 #2 = 4 + a*(-2/3) + b*(-2/3) 1498 assert numpy.allclose(a[0] + b[0], 3)1498 assert allclose(a[0] + b[0], 3) 1499 1499 #From orthogonality (a*(y0-y1) + b*(x0-x1) == 0) 1500 assert numpy.allclose(a[0] - b[0], 0)1500 assert allclose(a[0] - b[0], 0) 1501 1501 1502 1502 … … 1504 1504 #q2 = q1 + a*(x2-x1) + b*(y2-y1) <=> 1505 1505 #6 = 4 + a*(4/3) + b*(-2/3) 1506 assert numpy.allclose(2*a[2] - b[2], 3)1506 assert allclose(2*a[2] - b[2], 3) 1507 1507 #From orthogonality (a*(y1-y2) + b*(x2-x1) == 0) 1508 assert numpy.allclose(a[2] + 2*b[2], 0)1508 assert allclose(a[2] + 2*b[2], 0) 1509 1509 1510 1510 … … 1512 1512 #q3 = q1 + a*(x3-x1) + b*(y3-y1) <=> 1513 1513 #2 = 4 + a*(-2/3) + b*(4/3) 1514 assert numpy.allclose(a[3] - 2*b[3], 3)1514 assert allclose(a[3] - 2*b[3], 3) 1515 1515 #From orthogonality (a*(y1-y3) + b*(x3-x1) == 0) 1516 assert numpy.allclose(2*a[3] + b[3], 0)1516 assert allclose(2*a[3] + b[3], 0) 1517 1517 1518 1518 … … 1532 1532 #print a, b 1533 1533 1534 assert numpy.allclose(a[1], 3.0)1535 assert numpy.allclose(b[1], 1.0)1534 assert allclose(a[1], 3.0) 1535 assert allclose(b[1], 1.0) 1536 1536 1537 1537 #Work out the others … … 1540 1540 1541 1541 #print quantity.vertex_values 1542 assert numpy.allclose(quantity.vertex_values[1,0], 2.0)1543 assert numpy.allclose(quantity.vertex_values[1,1], 6.0)1544 assert numpy.allclose(quantity.vertex_values[1,2], 8.0)1542 assert allclose(quantity.vertex_values[1,0], 2.0) 1543 assert allclose(quantity.vertex_values[1,1], 6.0) 1544 assert allclose(quantity.vertex_values[1,2], 8.0) 1545 1545 1546 1546 … … 1550 1550 1551 1551 #Set up for a gradient of (3,1), f(x) = 3x+y 1552 c_values = numpy.array([2.0+2.0/3, 4.0+4.0/3, 8.0+2.0/3, 2.0+8.0/3])1553 d_values = numpy.array([1.0, 2.0, 3.0, 4.0])1552 c_values = array([2.0+2.0/3, 4.0+4.0/3, 8.0+2.0/3, 2.0+8.0/3]) 1553 d_values = array([1.0, 2.0, 3.0, 4.0]) 1554 1554 quantity.set_values(c_values, location = 'centroids') 1555 1555 … … 1558 1558 1559 1559 #print quantity.vertex_values 1560 assert numpy.allclose(quantity.centroid_values, quantity.centroid_backup_values)1560 assert allclose(quantity.centroid_values, quantity.centroid_backup_values) 1561 1561 1562 1562 … … 1574 1574 #Test centroids 1575 1575 quantity.set_values([1.,2.,3.,4.], location = 'centroids') 1576 assert numpy.allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid1576 assert allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid 1577 1577 1578 1578 #Extrapolate … … 1581 1581 #Check that gradient is zero 1582 1582 a,b = quantity.get_gradients() 1583 assert numpy.allclose(a, [0,0,0,0])1584 assert numpy.allclose(b, [0,0,0,0])1583 assert allclose(a, [0,0,0,0]) 1584 assert allclose(b, [0,0,0,0]) 1585 1585 1586 1586 #Check vertices but not edge values 1587 assert numpy.allclose(quantity.vertex_values,1588 1587 assert allclose(quantity.vertex_values, 1588 [[1,1,1], [2,2,2], [3,3,3], [4, 4, 4]]) 1589 1589 1590 1590 … … 1614 1614 1615 1615 #Assert that quantities are conserved 1616 from Numeric import sum 1616 1617 for k in range(quantity.centroid_values.shape[0]): 1617 assert numpy.allclose (quantity.centroid_values[k],1618 numpy.sum(quantity.vertex_values[k,:])/3)1618 assert allclose (quantity.centroid_values[k], 1619 sum(quantity.vertex_values[k,:])/3) 1619 1620 1620 1621 … … 1645 1646 1646 1647 #Assert that quantities are conserved 1648 from Numeric import sum 1647 1649 for k in range(quantity.centroid_values.shape[0]): 1648 assert numpy.allclose (quantity.centroid_values[k],1649 numpy.sum(quantity.vertex_values[k,:])/3)1650 assert allclose (quantity.centroid_values[k], 1651 sum(quantity.vertex_values[k,:])/3) 1650 1652 1651 1653 … … 1674 1676 1675 1677 #Assert that quantities are conserved 1678 from Numeric import sum 1676 1679 for k in range(quantity.centroid_values.shape[0]): 1677 assert numpy.allclose (quantity.centroid_values[k],1678 numpy.sum(quantity.vertex_values[k,:])/3)1680 assert allclose (quantity.centroid_values[k], 1681 sum(quantity.vertex_values[k,:])/3) 1679 1682 1680 1683 … … 1702 1705 1703 1706 #Assert that quantities are conserved 1707 from Numeric import sum 1704 1708 for k in range(quantity.centroid_values.shape[0]): 1705 assert numpy.allclose (quantity.centroid_values[k],1706 numpy.sum(quantity.vertex_values[k,:])/3)1709 assert allclose (quantity.centroid_values[k], 1710 sum(quantity.vertex_values[k,:])/3) 1707 1711 1708 1712 def test_limiter2(self): … … 1714 1718 #Test centroids 1715 1719 quantity.set_values([2.,4.,8.,2.], location = 'centroids') 1716 assert numpy.allclose(quantity.centroid_values, [2, 4, 8, 2]) #Centroid1720 assert allclose(quantity.centroid_values, [2, 4, 8, 2]) #Centroid 1717 1721 1718 1722 … … 1720 1724 quantity.extrapolate_second_order() 1721 1725 1722 assert numpy.allclose(quantity.vertex_values[1,:], [0.0, 6, 6])1726 assert allclose(quantity.vertex_values[1,:], [0.0, 6, 6]) 1723 1727 1724 1728 #Limit … … 1727 1731 # limited value for beta_w = 0.9 1728 1732 1729 assert numpy.allclose(quantity.vertex_values[1,:], [2.2, 4.9, 4.9])1733 assert allclose(quantity.vertex_values[1,:], [2.2, 4.9, 4.9]) 1730 1734 # limited values for beta_w = 0.5 1731 #assert numpy.allclose(quantity.vertex_values[1,:], [3.0, 4.5, 4.5])1735 #assert allclose(quantity.vertex_values[1,:], [3.0, 4.5, 4.5]) 1732 1736 1733 1737 1734 1738 #Assert that quantities are conserved 1739 from Numeric import sum 1735 1740 for k in range(quantity.centroid_values.shape[0]): 1736 assert numpy.allclose (quantity.centroid_values[k],1737 numpy.sum(quantity.vertex_values[k,:])/3)1741 assert allclose (quantity.centroid_values[k], 1742 sum(quantity.vertex_values[k,:])/3) 1738 1743 1739 1744 … … 1746 1751 #Test centroids 1747 1752 quantity.set_values([1.,2.,3.,4.], location = 'centroids') 1748 assert numpy.allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid1753 assert allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid 1749 1754 1750 1755 … … 1755 1760 #quantity.interpolate_from_vertices_to_edges() 1756 1761 1757 assert numpy.allclose(quantity.vertex_values,1758 1759 assert numpy.allclose(quantity.edge_values, [[1,1,1], [2,2,2],1760 1762 assert allclose(quantity.vertex_values, 1763 [[1,1,1], [2,2,2], [3,3,3], [4, 4, 4]]) 1764 assert allclose(quantity.edge_values, [[1,1,1], [2,2,2], 1765 [3,3,3], [4, 4, 4]]) 1761 1766 1762 1767 … … 1764 1769 quantity = Quantity(self.mesh4) 1765 1770 1766 quantity.vertex_values = numpy.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]], numpy.float)1771 quantity.vertex_values = array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]],Float) 1767 1772 1768 1773 quantity.interpolate_from_vertices_to_edges() 1769 1774 1770 assert numpy.allclose(quantity.edge_values, [[1., 1.5, 0.5],1771 1772 1773 1775 assert allclose(quantity.edge_values, [[1., 1.5, 0.5], 1776 [3., 2.5, 1.5], 1777 [3.5, 4.5, 3.], 1778 [2.5, 3.5, 2]]) 1774 1779 1775 1780 … … 1777 1782 quantity = Quantity(self.mesh4) 1778 1783 1779 quantity.edge_values = numpy.array([[1., 1.5, 0.5],1780 1781 1782 [2.5, 3.5, 2]], numpy.float)1784 quantity.edge_values = array([[1., 1.5, 0.5], 1785 [3., 2.5, 1.5], 1786 [3.5, 4.5, 3.], 1787 [2.5, 3.5, 2]],Float) 1783 1788 1784 1789 quantity.interpolate_from_edges_to_vertices() 1785 1790 1786 assert numpy.allclose(quantity.vertex_values,1787 1791 assert allclose(quantity.vertex_values, 1792 [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 1788 1793 1789 1794 … … 1794 1799 #Test centroids 1795 1800 quantity.set_values([2.,4.,8.,2.], location = 'centroids') 1796 assert numpy.allclose(quantity.centroid_values, [2, 4, 8, 2]) #Centroid1801 assert allclose(quantity.centroid_values, [2, 4, 8, 2]) #Centroid 1797 1802 1798 1803 … … 1800 1805 quantity.extrapolate_second_order() 1801 1806 1802 assert numpy.allclose(quantity.vertex_values[1,:], [0.0, 6, 6])1807 assert allclose(quantity.vertex_values[1,:], [0.0, 6, 6]) 1803 1808 1804 1809 … … 1808 1813 #Test centroids 1809 1814 quantity.set_values([1.,2.,3.,4.], location = 'centroids') 1810 assert numpy.allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid1815 assert allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid 1811 1816 1812 1817 #Set explicit_update 1813 quantity.explicit_update = numpy.array( [1.,1.,1.,1.] )1818 quantity.explicit_update = array( [1.,1.,1.,1.] ) 1814 1819 1815 1820 #Update with given timestep 1816 1821 quantity.update(0.1) 1817 1822 1818 x = numpy.array([1, 2, 3, 4]) + numpy.array( [.1,.1,.1,.1] )1819 assert numpy.allclose( quantity.centroid_values, x)1823 x = array([1, 2, 3, 4]) + array( [.1,.1,.1,.1] ) 1824 assert allclose( quantity.centroid_values, x) 1820 1825 1821 1826 def test_update_semi_implicit(self): … … 1824 1829 #Test centroids 1825 1830 quantity.set_values([1.,2.,3.,4.], location = 'centroids') 1826 assert numpy.allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid1831 assert allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid 1827 1832 1828 1833 #Set semi implicit update 1829 quantity.semi_implicit_update = numpy.array([1.,1.,1.,1.])1834 quantity.semi_implicit_update = array([1.,1.,1.,1.]) 1830 1835 1831 1836 #Update with given timestep … … 1833 1838 quantity.update(timestep) 1834 1839 1835 sem = numpy.array([1.,1.,1.,1.])/numpy.array([1, 2, 3, 4])1836 denom = numpy.ones(4, numpy.float)-timestep*sem1837 1838 x = numpy.array([1, 2, 3, 4])/denom1839 assert numpy.allclose( quantity.centroid_values, x)1840 sem = array([1.,1.,1.,1.])/array([1, 2, 3, 4]) 1841 denom = ones(4, Float)-timestep*sem 1842 1843 x = array([1, 2, 3, 4])/denom 1844 assert allclose( quantity.centroid_values, x) 1840 1845 1841 1846 … … 1845 1850 #Test centroids 1846 1851 quantity.set_values([1.,2.,3.,4.], location = 'centroids') 1847 assert numpy.allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid1852 assert allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid 1848 1853 1849 1854 #Set explicit_update 1850 quantity.explicit_update = numpy.array( [4.,3.,2.,1.] )1855 quantity.explicit_update = array( [4.,3.,2.,1.] ) 1851 1856 1852 1857 #Set semi implicit update 1853 quantity.semi_implicit_update = numpy.array( [1.,1.,1.,1.] )1858 quantity.semi_implicit_update = array( [1.,1.,1.,1.] ) 1854 1859 1855 1860 #Update with given timestep … … 1857 1862 quantity.update(0.1) 1858 1863 1859 sem = numpy.array([1.,1.,1.,1.])/numpy.array([1, 2, 3, 4])1860 denom = numpy.ones(4, numpy.float)-timestep*sem1861 1862 x = numpy.array([1., 2., 3., 4.])1864 sem = array([1.,1.,1.,1.])/array([1, 2, 3, 4]) 1865 denom = ones(4, Float)-timestep*sem 1866 1867 x = array([1., 2., 3., 4.]) 1863 1868 x /= denom 1864 x += timestep* numpy.array( [4.0, 3.0, 2.0, 1.0] )1865 1866 assert numpy.allclose( quantity.centroid_values, x)1869 x += timestep*array( [4.0, 3.0, 2.0, 1.0] ) 1870 1871 assert allclose( quantity.centroid_values, x) 1867 1872 1868 1873 … … 1874 1879 from mesh_factory import rectangular 1875 1880 from shallow_water import Domain, Transmissive_boundary 1881 from Numeric import zeros, Float 1876 1882 from anuga.utilities.numerical_tools import mean 1877 1883 … … 1900 1906 1901 1907 bed = domain.quantities['elevation'].vertex_values 1902 stage = numpy.zeros(bed.shape, numpy.float)1908 stage = zeros(bed.shape, Float) 1903 1909 1904 1910 h = 0.03 … … 1923 1929 1924 1930 #First four points 1925 assert numpy.allclose(A[0], (Q[0,2] + Q[1,1])/2)1926 assert numpy.allclose(A[1], (Q[1,0] + Q[3,1] + Q[2,2])/3)1927 assert numpy.allclose(A[2], Q[3,0])1928 assert numpy.allclose(A[3], (Q[0,0] + Q[5,1] + Q[4,2])/3)1931 assert allclose(A[0], (Q[0,2] + Q[1,1])/2) 1932 assert allclose(A[1], (Q[1,0] + Q[3,1] + Q[2,2])/3) 1933 assert allclose(A[2], Q[3,0]) 1934 assert allclose(A[3], (Q[0,0] + Q[5,1] + Q[4,2])/3) 1929 1935 1930 1936 #Center point 1931 assert numpy.allclose(A[4], (Q[0,1] + Q[1,2] + Q[2,0] +\1932 1937 assert allclose(A[4], (Q[0,1] + Q[1,2] + Q[2,0] +\ 1938 Q[5,0] + Q[6,2] + Q[7,1])/6) 1933 1939 1934 1940 1935 1941 #Check V 1936 assert numpy.allclose(V[0,:], [3,4,0])1937 assert numpy.allclose(V[1,:], [1,0,4])1938 assert numpy.allclose(V[2,:], [4,5,1])1939 assert numpy.allclose(V[3,:], [2,1,5])1940 assert numpy.allclose(V[4,:], [6,7,3])1941 assert numpy.allclose(V[5,:], [4,3,7])1942 assert numpy.allclose(V[6,:], [7,8,4])1943 assert numpy.allclose(V[7,:], [5,4,8])1942 assert allclose(V[0,:], [3,4,0]) 1943 assert allclose(V[1,:], [1,0,4]) 1944 assert allclose(V[2,:], [4,5,1]) 1945 assert allclose(V[3,:], [2,1,5]) 1946 assert allclose(V[4,:], [6,7,3]) 1947 assert allclose(V[5,:], [4,3,7]) 1948 assert allclose(V[6,:], [7,8,4]) 1949 assert allclose(V[7,:], [5,4,8]) 1944 1950 1945 1951 #Get smoothed stage with XY 1946 1952 X, Y, A1, V1 = stage.get_vertex_values(xy=True, smooth=True) 1947 1953 1948 assert numpy.allclose(A, A1)1949 assert numpy.allclose(V, V1)1954 assert allclose(A, A1) 1955 assert allclose(V, V1) 1950 1956 1951 1957 #Check XY 1952 assert numpy.allclose(X[4], 0.5)1953 assert numpy.allclose(Y[4], 0.5)1954 1955 assert numpy.allclose(X[7], 1.0)1956 assert numpy.allclose(Y[7], 0.5)1958 assert allclose(X[4], 0.5) 1959 assert allclose(Y[4], 0.5) 1960 1961 assert allclose(X[7], 1.0) 1962 assert allclose(Y[7], 0.5) 1957 1963 1958 1964 … … 1963 1969 from mesh_factory import rectangular 1964 1970 from shallow_water import Domain, Transmissive_boundary 1971 from Numeric import zeros, Float 1965 1972 from anuga.utilities.numerical_tools import mean 1966 1973 … … 1984 1991 1985 1992 bed = domain.quantities['elevation'].vertex_values 1986 stage = numpy.zeros(bed.shape, numpy.float)1993 stage = zeros(bed.shape, Float) 1987 1994 1988 1995 h = 0.03 … … 1998 2005 stage = domain.quantities['stage'] 1999 2006 A, V = stage.get_vertex_values(xy=False, smooth=False) 2000 Q = stage.vertex_values. ravel()2007 Q = stage.vertex_values.flat 2001 2008 2002 2009 for k in range(8): 2003 assert numpy.allclose(A[k], Q[k])2010 assert allclose(A[k], Q[k]) 2004 2011 2005 2012 … … 2014 2021 2015 2022 2016 assert numpy.allclose(A, A1)2017 assert numpy.allclose(V, V1)2023 assert allclose(A, A1) 2024 assert allclose(V, V1) 2018 2025 2019 2026 #Check XY 2020 assert numpy.allclose(X[1], 0.5)2021 assert numpy.allclose(Y[1], 0.5)2022 assert numpy.allclose(X[4], 0.0)2023 assert numpy.allclose(Y[4], 0.0)2024 assert numpy.allclose(X[12], 1.0)2025 assert numpy.allclose(Y[12], 0.0)2027 assert allclose(X[1], 0.5) 2028 assert allclose(Y[1], 0.5) 2029 assert allclose(X[4], 0.0) 2030 assert allclose(Y[4], 0.0) 2031 assert allclose(X[12], 1.0) 2032 assert allclose(Y[12], 0.0) 2026 2033 2027 2034 … … 2031 2038 from mesh_factory import rectangular 2032 2039 from shallow_water import Domain 2040 from Numeric import zeros, Float 2033 2041 2034 2042 #Create basic mesh … … 2046 2054 #print "quantity.centroid_values",quantity.centroid_values 2047 2055 2048 assert numpy.allclose(quantity.centroid_values, [1,7])2056 assert allclose(quantity.centroid_values, [1,7]) 2049 2057 2050 2058 quantity.set_array_values([15,20,25], indices = indices) 2051 assert numpy.allclose(quantity.centroid_values, [1,20])2059 assert allclose(quantity.centroid_values, [1,20]) 2052 2060 2053 2061 quantity.set_array_values([15,20,25], indices = indices) 2054 assert numpy.allclose(quantity.centroid_values, [1,20])2062 assert allclose(quantity.centroid_values, [1,20]) 2055 2063 2056 2064 def test_setting_some_vertex_values(self): … … 2060 2068 from mesh_factory import rectangular 2061 2069 from shallow_water import Domain 2070 from Numeric import zeros, Float 2062 2071 2063 2072 #Create basic mesh … … 2078 2087 indices = indices) 2079 2088 #print "quantity.centroid_values",quantity.centroid_values 2080 assert numpy.allclose(quantity.centroid_values, [1,7,3,4,5,6])2089 assert allclose(quantity.centroid_values, [1,7,3,4,5,6]) 2081 2090 2082 2091 value = [7] … … 2086 2095 indices = indices) 2087 2096 #print "quantity.centroid_values",quantity.centroid_values 2088 assert numpy.allclose(quantity.centroid_values, [1,7,3,4,5,6])2097 assert allclose(quantity.centroid_values, [1,7,3,4,5,6]) 2089 2098 2090 2099 value = [[15,20,25]] 2091 2100 quantity.set_values(value, indices = indices) 2092 2101 #print "1 quantity.vertex_values",quantity.vertex_values 2093 assert numpy.allclose(quantity.vertex_values[1], value[0])2102 assert allclose(quantity.vertex_values[1], value[0]) 2094 2103 2095 2104 … … 2098 2107 quantity.set_values(values, indices = [0,1,5], location = 'centroids') 2099 2108 #print "2 quantity.vertex_values",quantity.vertex_values 2100 assert numpy.allclose(quantity.vertex_values[0], [10,10,10])2101 assert numpy.allclose(quantity.vertex_values[5], [50,50,50])2109 assert allclose(quantity.vertex_values[0], [10,10,10]) 2110 assert allclose(quantity.vertex_values[5], [50,50,50]) 2102 2111 #quantity.interpolate() 2103 2112 #print "quantity.centroid_values",quantity.centroid_values 2104 assert numpy.allclose(quantity.centroid_values, [10,100,3,4,5,50])2113 assert allclose(quantity.centroid_values, [10,100,3,4,5,50]) 2105 2114 2106 2115 … … 2112 2121 quantity.set_values(values, indices = [0,1,5]) 2113 2122 #print "quantity.vertex_values",quantity.vertex_values 2114 assert numpy.allclose(quantity.vertex_values[0], [1,50,10])2115 assert numpy.allclose(quantity.vertex_values[5], [6,6,6])2116 assert numpy.allclose(quantity.vertex_values[1], [100,10,50])2123 assert allclose(quantity.vertex_values[0], [1,50,10]) 2124 assert allclose(quantity.vertex_values[5], [6,6,6]) 2125 assert allclose(quantity.vertex_values[1], [100,10,50]) 2117 2126 2118 2127 quantity = Quantity(domain,[[1,1,1],[2,2,2],[3,3,3], … … 2121 2130 quantity.set_values(values, indices = [3,3,5]) 2122 2131 quantity.interpolate() 2123 assert numpy.allclose(quantity.centroid_values, [1,2,3,400,5,999])2132 assert allclose(quantity.centroid_values, [1,2,3,400,5,999]) 2124 2133 2125 2134 values = [[1,1,1],[2,2,2],[3,3,3], … … 2133 2142 quantity.set_values(values) 2134 2143 #print "1 quantity.vertex_values",quantity.vertex_values 2135 assert numpy.allclose(quantity.vertex_values,[[ 4., 5., 0.],2136 2137 2138 2139 2140 2144 assert allclose(quantity.vertex_values,[[ 4., 5., 0.], 2145 [ 1., 0., 5.], 2146 [ 5., 6., 1.], 2147 [ 2., 1., 6.], 2148 [ 6., 7., 2.], 2149 [ 3., 2., 7.]]) 2141 2150 2142 2151 def test_setting_unique_vertex_values(self): … … 2146 2155 from mesh_factory import rectangular 2147 2156 from shallow_water import Domain 2157 from Numeric import zeros, Float 2148 2158 2149 2159 #Create basic mesh … … 2161 2171 indices = indices) 2162 2172 #print "quantity.centroid_values",quantity.centroid_values 2163 assert numpy.allclose(quantity.vertex_values[0], [0,7,0])2164 assert numpy.allclose(quantity.vertex_values[1], [7,1,7])2165 assert numpy.allclose(quantity.vertex_values[2], [7,2,7])2173 assert allclose(quantity.vertex_values[0], [0,7,0]) 2174 assert allclose(quantity.vertex_values[1], [7,1,7]) 2175 assert allclose(quantity.vertex_values[2], [7,2,7]) 2166 2176 2167 2177 … … 2172 2182 from mesh_factory import rectangular 2173 2183 from shallow_water import Domain 2184 from Numeric import zeros, Float 2174 2185 2175 2186 #Create basic mesh … … 2194 2205 2195 2206 answer = [0.5,2,4,5,0,1,3,4.5] 2196 assert numpy.allclose(answer,2197 2207 assert allclose(answer, 2208 quantity.get_values(location = 'unique vertices')) 2198 2209 2199 2210 indices = [0,5,3] 2200 2211 answer = [0.5,1,5] 2201 assert numpy.allclose(answer,2202 quantity.get_values(indices=indices,2203 2212 assert allclose(answer, 2213 quantity.get_values(indices=indices, \ 2214 location = 'unique vertices')) 2204 2215 #print "quantity.centroid_values",quantity.centroid_values 2205 2216 #print "quantity.get_values(location = 'centroids') ",\ … … 2230 2241 quantity.set_values(lambda x, y: x+2*y) #2 4 4 6 2231 2242 2232 assert numpy.allclose(quantity.get_values(location='centroids'), [2,4,4,6])2233 assert numpy.allclose(quantity.get_values(location='centroids', indices=[1,3]), [4,6])2234 2235 2236 assert numpy.allclose(quantity.get_values(location='vertices'), [[4,0,2],2237 2238 2239 2240 2241 assert numpy.allclose(quantity.get_values(location='vertices', indices=[1,3]), [[4,2,6],2242 2243 2244 2245 assert numpy.allclose(quantity.get_values(location='edges'), [[1,3,2],2246 2247 2248 2249 assert numpy.allclose(quantity.get_values(location='edges', indices=[1,3]),2250 2251 2243 assert allclose(quantity.get_values(location='centroids'), [2,4,4,6]) 2244 assert allclose(quantity.get_values(location='centroids', indices=[1,3]), [4,6]) 2245 2246 2247 assert allclose(quantity.get_values(location='vertices'), [[4,0,2], 2248 [4,2,6], 2249 [6,2,4], 2250 [8,4,6]]) 2251 2252 assert allclose(quantity.get_values(location='vertices', indices=[1,3]), [[4,2,6], 2253 [8,4,6]]) 2254 2255 2256 assert allclose(quantity.get_values(location='edges'), [[1,3,2], 2257 [4,5,3], 2258 [3,5,4], 2259 [5,7,6]]) 2260 assert allclose(quantity.get_values(location='edges', indices=[1,3]), 2261 [[4,5,3], 2262 [5,7,6]]) 2252 2263 2253 2264 # Check averaging over vertices … … 2269 2280 from mesh_factory import rectangular 2270 2281 from shallow_water import Domain 2282 from Numeric import zeros, Float 2271 2283 2272 2284 #Create basic mesh … … 2286 2298 2287 2299 #print quantity.get_values(points=interpolation_points) 2288 assert numpy.allclose(answer, quantity.get_values(interpolation_points=interpolation_points))2300 assert allclose(answer, quantity.get_values(interpolation_points=interpolation_points)) 2289 2301 2290 2302 … … 2299 2311 #print answer 2300 2312 #print quantity.get_values(interpolation_points=interpolation_points) 2301 assert numpy.allclose(answer, quantity.get_values(interpolation_points=interpolation_points,2302 2313 assert allclose(answer, quantity.get_values(interpolation_points=interpolation_points, 2314 verbose=False)) 2303 2315 2304 2316 … … 2306 2318 #indices = [0,5,3] 2307 2319 #answer = [0.5,1,5] 2308 #assert numpy.allclose(answer,2309 # quantity.get_values(indices=indices,2310 # 2320 #assert allclose(answer, 2321 # quantity.get_values(indices=indices, \ 2322 # location = 'unique vertices')) 2311 2323 2312 2324 … … 2333 2345 x, y = 2.0/3, 8.0/3 2334 2346 v = quantity.get_values(interpolation_points = [[x,y]]) 2335 assert numpy.allclose(v, 6)2347 assert allclose(v, 6) 2336 2348 2337 2349 # Then another to test that algorithm won't blindly … … 2339 2351 x, y = 4.0/3, 4.0/3 2340 2352 v = quantity.get_values(interpolation_points = [[x,y]]) 2341 assert numpy.allclose(v, 4)2353 assert allclose(v, 4) 2342 2354 2343 2355 … … 2368 2380 x, y = 2.0/3, 8.0/3 2369 2381 v = quantity.get_values(interpolation_points = [[x+xllcorner,y+yllcorner]]) 2370 assert numpy.allclose(v, 6)2382 assert allclose(v, 6) 2371 2383 2372 2384 … … 2375 2387 x, y = 4.0/3, 4.0/3 2376 2388 v = quantity.get_values(interpolation_points = [[x+xllcorner,y+yllcorner]]) 2377 assert numpy.allclose(v, 4)2389 assert allclose(v, 4) 2378 2390 2379 2391 # Try two points … … 2381 2393 [4.0/3 + xllcorner, 4.0/3 + yllcorner]] 2382 2394 v = quantity.get_values(interpolation_points=pts) 2383 assert numpy.allclose(v, [6, 4])2395 assert allclose(v, [6, 4]) 2384 2396 2385 2397 # Test it using the geospatial data format with absolute input points and default georef 2386 2398 pts = Geospatial_data(data_points=pts) 2387 2399 v = quantity.get_values(interpolation_points=pts) 2388 assert numpy.allclose(v, [6, 4])2400 assert allclose(v, [6, 4]) 2389 2401 2390 2402 … … 2393 2405 geo_reference=Geo_reference(zone,xllcorner,yllcorner)) 2394 2406 v = quantity.get_values(interpolation_points=pts) 2395 assert numpy.allclose(v, [6, 4])2407 assert allclose(v, [6, 4]) 2396 2408 2397 2409 … … 2404 2416 from mesh_factory import rectangular 2405 2417 from shallow_water import Domain 2418 from Numeric import zeros, Float 2406 2419 2407 2420 #Create basic mesh … … 2425 2438 #print "quantity.get_values(location = 'centroids') ",\ 2426 2439 # quantity.get_values(location = 'centroids') 2427 assert numpy.allclose(quantity.centroid_values,2428 2440 assert allclose(quantity.centroid_values, 2441 quantity.get_values(location = 'centroids')) 2429 2442 2430 2443 … … 2432 2445 quantity.set_values(value, indices = indices) 2433 2446 #print "1 quantity.vertex_values",quantity.vertex_values 2434 assert numpy.allclose(quantity.vertex_values, quantity.get_values())2435 2436 assert numpy.allclose(quantity.edge_values,2437 2447 assert allclose(quantity.vertex_values, quantity.get_values()) 2448 2449 assert allclose(quantity.edge_values, 2450 quantity.get_values(location = 'edges')) 2438 2451 2439 2452 # get a subset of elements 2440 2453 subset = quantity.get_values(location='centroids', indices=[0,5]) 2441 2454 answer = [quantity.centroid_values[0],quantity.centroid_values[5]] 2442 assert numpy.allclose(subset, answer)2455 assert allclose(subset, answer) 2443 2456 2444 2457 … … 2447 2460 #print "subset",subset 2448 2461 #print "answer",answer 2449 assert numpy.allclose(subset, answer)2462 assert allclose(subset, answer) 2450 2463 2451 2464 subset = quantity.get_values( indices=[1,5]) … … 2453 2466 #print "subset",subset 2454 2467 #print "answer",answer 2455 assert numpy.allclose(subset, answer)2468 assert allclose(subset, answer) 2456 2469 2457 2470 def test_smooth_vertex_values(self): … … 2461 2474 from mesh_factory import rectangular 2462 2475 from shallow_water import Domain 2476 from Numeric import zeros, Float 2463 2477 2464 2478 #Create basic mesh … … 2487 2501 2488 2502 #answer = [0.5, 2, 3, 3, 3.5, 4, 4, 5, 6.5] 2489 #assert numpy.allclose(answer,2490 # 2503 #assert allclose(answer, 2504 # quantity.get_values(location = 'unique vertices')) 2491 2505 2492 2506 quantity.smooth_vertex_values() … … 2498 2512 [4,5,3],[3.5,3,5],[5,6.5,3.5],[4,3.5,6.5]] 2499 2513 2500 assert numpy.allclose(answer_vertex_values,2501 2514 assert allclose(answer_vertex_values, 2515 quantity.vertex_values) 2502 2516 #print "quantity.centroid_values",quantity.centroid_values 2503 2517 #print "quantity.get_values(location = 'centroids') ",\ … … 2509 2523 if __name__ == "__main__": 2510 2524 suite = unittest.makeSuite(Test_Quantity, 'test') 2511 # suite = unittest.makeSuite(Test_Quantity, 'test_get_extrema_1') 2525 #suite = unittest.makeSuite(Test_Quantity, 'test_set_values_from_file_using_polygon') 2526 2527 #suite = unittest.makeSuite(Test_Quantity, 'test_set_vertex_values_using_general_interface_with_subset') 2528 #print "restricted test" 2529 #suite = unittest.makeSuite(Test_Quantity,'verbose_test_set_values_from_UTM_pts') 2512 2530 runner = unittest.TextTestRunner() 2513 2531 runner.run(suite) -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_region.py
r5892 r5897 6 6 from domain import * 7 7 from region import * 8 import numpy 9 8 #from anuga.config import epsilon 9 from Numeric import allclose, average #, array, ones, Float 10 10 """ 11 11 This is what the mesh in these tests look like; … … 44 44 from mesh_factory import rectangular 45 45 from shallow_water import Domain 46 from Numeric import zeros, Float 46 47 47 48 #Create basic mesh … … 63 64 domain.set_region([a, b]) 64 65 #print domain.quantities['friction'].get_values() 65 assert numpy.allclose(domain.quantities['friction'].get_values(),66 67 68 69 70 71 66 assert allclose(domain.quantities['friction'].get_values(),\ 67 [[ 0.09, 0.09, 0.09], 68 [ 0.09, 0.09, 0.09], 69 [ 0.07, 0.07, 0.07], 70 [ 0.07, 0.07, 0.07], 71 [ 1.0, 1.0, 1.0], 72 [ 1.0, 1.0, 1.0]]) 72 73 73 74 #c = Add_Value_To_region('all', 'friction', 10.0) 74 75 domain.set_region(Add_value_to_region('all', 'friction', 10.0)) 75 76 #print domain.quantities['friction'].get_values() 76 assert numpy.allclose(domain.quantities['friction'].get_values(),77 78 79 80 81 82 77 assert allclose(domain.quantities['friction'].get_values(), 78 [[ 10.09, 10.09, 10.09], 79 [ 10.09, 10.09, 10.09], 80 [ 10.07, 10.07, 10.07], 81 [ 10.07, 10.07, 10.07], 82 [ 11.0, 11.0, 11.0], 83 [ 11.0, 11.0, 11.0]]) 83 84 84 85 # trying a function 85 86 domain.set_region(Set_region('top', 'friction', add_x_y)) 86 87 #print domain.quantities['friction'].get_values() 87 assert numpy.allclose(domain.quantities['friction'].get_values(),88 89 90 91 92 93 88 assert allclose(domain.quantities['friction'].get_values(), 89 [[ 10.09, 10.09, 10.09], 90 [ 10.09, 10.09, 10.09], 91 [ 10.07, 10.07, 10.07], 92 [ 10.07, 10.07, 10.07], 93 [ 5./3, 2.0, 2./3], 94 [ 1.0, 2./3, 2.0]]) 94 95 95 96 domain.set_quantity('elevation', 10.0) … … 97 98 domain.set_region(Add_value_to_region('top', 'stage', 1.0,initial_quantity='elevation')) 98 99 #print domain.quantities['stage'].get_values() 99 assert numpy.allclose(domain.quantities['stage'].get_values(),100 101 102 103 104 105 100 assert allclose(domain.quantities['stage'].get_values(), 101 [[ 10., 10., 10.], 102 [ 10., 10., 10.], 103 [ 10., 10., 10.], 104 [ 10., 10., 10.], 105 [ 11.0, 11.0, 11.0], 106 [ 11.0, 11.0, 11.0]]) 106 107 107 108 … … 114 115 domain.set_region(Add_quantities('top', 'elevation','stage')) 115 116 #print domain.quantities['stage'].get_values() 116 assert numpy.allclose(domain.quantities['elevation'].get_values(),117 118 119 120 121 122 117 assert allclose(domain.quantities['elevation'].get_values(), 118 [[ 10., 10., 10.], 119 [ 10., 10., 10.], 120 [ 10., 10., 10.], 121 [ 10., 10., 10.], 122 [ 33., 33.0, 33.], 123 [ 33.0, 33., 33.]]) 123 124 124 125 def test_unique_vertices(self): … … 128 129 from mesh_factory import rectangular 129 130 from shallow_water import Domain 131 from Numeric import zeros, Float 130 132 131 133 #Create basic mesh … … 145 147 domain.set_region(a) 146 148 #print domain.quantities['friction'].get_values() 147 assert numpy.allclose(domain.quantities['friction'].get_values(),\148 149 150 151 152 153 149 assert allclose(domain.quantities['friction'].get_values(),\ 150 [[ 0.09, 0.09, 0.09], 151 [ 0.09, 0.09, 0.09], 152 [ 0.09, 0.07, 0.09], 153 [ 0.07, 0.09, 0.07], 154 [ 0.07, 0.07, 0.07], 155 [ 0.07, 0.07, 0.07]]) 154 156 155 157 … … 160 162 from mesh_factory import rectangular 161 163 from shallow_water import Domain 164 from Numeric import zeros, Float 162 165 163 166 #Create basic mesh … … 177 180 178 181 #print domain.quantities['friction'].get_values() 179 assert numpy.allclose(domain.quantities['friction'].get_values(),\180 181 182 183 184 185 182 assert allclose(domain.quantities['friction'].get_values(),\ 183 [[ 1.07, 1.07, 1.07], 184 [ 1.07, 1.07, 1.07], 185 [ 1.07, 0.07, 1.07], 186 [ 0.07, 1.07, 0.07], 187 [ 0.07, 0.07, 0.07], 188 [ 0.07, 0.07, 0.07]]) 186 189 187 190 def test_unique_vertices_average_loc_vert(self): … … 191 194 from mesh_factory import rectangular 192 195 from shallow_water import Domain 196 from Numeric import zeros, Float 193 197 194 198 #Create basic mesh … … 214 218 #print domain.quantities['friction'].get_values() 215 219 frict_points = domain.quantities['friction'].get_values() 216 assert numpy.allclose(frict_points[0],217 218 assert numpy.allclose(frict_points[1],219 220 assert allclose(frict_points[0],\ 221 [ calc_frict, calc_frict, calc_frict]) 222 assert allclose(frict_points[1],\ 223 [ calc_frict, calc_frict, calc_frict]) 220 224 221 225 def test_unique_vertices_average_loc_unique_vert(self): … … 225 229 from mesh_factory import rectangular 226 230 from shallow_water import Domain 231 from Numeric import zeros, Float 227 232 228 233 #Create basic mesh … … 247 252 #print domain.quantities['friction'].get_values() 248 253 frict_points = domain.quantities['friction'].get_values() 249 assert numpy.allclose(frict_points[0],250 251 assert numpy.allclose(frict_points[1],252 253 assert numpy.allclose(frict_points[2],254 255 assert numpy.allclose(frict_points[3],256 254 assert allclose(frict_points[0],\ 255 [ calc_frict, calc_frict, calc_frict]) 256 assert allclose(frict_points[1],\ 257 [ calc_frict, calc_frict, calc_frict]) 258 assert allclose(frict_points[2],\ 259 [ calc_frict, 1.0 + 2.0/3.0, calc_frict]) 260 assert allclose(frict_points[3],\ 261 [ 2.0/3.0,calc_frict, 1.0 + 2.0/3.0]) 257 262 258 263 … … 260 265 if __name__ == "__main__": 261 266 suite = unittest.makeSuite(Test_Region,'test') 262 ## suite = unittest.makeSuite(Test_Region,'test_unique_vertices_average_loc_unique_vert')263 267 runner = unittest.TextTestRunner() 264 268 runner.run(suite) -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_util.py
r5892 r5897 1 1 #!/usr/bin/env python 2 2 3 3 4 import unittest 4 import numpy 5 5 from Numeric import zeros, array, allclose, Float 6 6 from math import sqrt, pi 7 7 import tempfile, os … … 91 91 92 92 #Exact linear intpolation 93 assert numpy.allclose(q[0], 2*t)93 assert allclose(q[0], 2*t) 94 94 if i%6 == 0: 95 assert numpy.allclose(q[1], t**2)96 assert numpy.allclose(q[2], sin(t*pi/600))95 assert allclose(q[1], t**2) 96 assert allclose(q[2], sin(t*pi/600)) 97 97 98 98 #Check non-exact … … 100 100 t = 90 #Halfway between 60 and 120 101 101 q = F(t) 102 assert numpy.allclose( (120**2 + 60**2)/2, q[1] )103 assert numpy.allclose( (sin(120*pi/600) + sin(60*pi/600))/2, q[2] )102 assert allclose( (120**2 + 60**2)/2, q[1] ) 103 assert allclose( (sin(120*pi/600) + sin(60*pi/600))/2, q[2] ) 104 104 105 105 106 106 t = 100 #Two thirds of the way between between 60 and 120 107 107 q = F(t) 108 assert numpy.allclose( 2*120**2/3 + 60**2/3, q[1] )109 assert numpy.allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] )108 assert allclose( 2*120**2/3 + 60**2/3, q[1] ) 109 assert allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] ) 110 110 111 111 os.remove(filename + '.txt') … … 125 125 from shallow_water import Domain, Dirichlet_boundary 126 126 from mesh_factory import rectangular 127 from Numeric import take, concatenate, reshape 127 128 128 129 #Create basic mesh and shallow water domain … … 147 148 148 149 # Boundary conditions 149 print 'test_util: 0'150 150 B0 = Dirichlet_boundary([0,0,0]) 151 151 B6 = Dirichlet_boundary([0.6,0,0]) 152 print 'test_util: 1'153 152 domain1.set_boundary({'left': B6, 'top': B6, 'right': B0, 'bottom': B0}) 154 153 domain1.check_integrity() 155 print 'test_util: 2'156 154 157 155 finaltime = 8 158 156 #Evolution 159 157 t0 = -1 160 print 'test_util: 3'161 # crash at following line162 158 for t in domain1.evolve(yieldstep = 0.1, finaltime = finaltime): 163 print 'test_util: 4'164 159 #print 'Timesteps: %.16f, %.16f' %(t0, t) 165 160 #if t == t0: … … 169 164 170 165 #domain1.write_time() 171 print 'test_util: 5'172 166 173 167 … … 188 182 189 183 last_time_index = len(time)-1 #Last last_time_index 190 d_stage = numpy.reshape(numpy.take(stage[last_time_index, :], [0,5,10,15], axis=0), (4,1))191 d_uh = numpy.reshape(numpy.take(xmomentum[last_time_index, :], [0,5,10,15], axis=0), (4,1))192 d_vh = numpy.reshape(numpy.take(ymomentum[last_time_index, :], [0,5,10,15], axis=0), (4,1))193 D = numpy.concatenate( (d_stage, d_uh, d_vh), axis=1)184 d_stage = reshape(take(stage[last_time_index, :], [0,5,10,15]), (4,1)) 185 d_uh = reshape(take(xmomentum[last_time_index, :], [0,5,10,15]), (4,1)) 186 d_vh = reshape(take(ymomentum[last_time_index, :], [0,5,10,15]), (4,1)) 187 D = concatenate( (d_stage, d_uh, d_vh), axis=1) 194 188 195 189 #Reference interpolated values at midpoints on diagonal at … … 200 194 201 195 #And the midpoints are found now 202 Dx = numpy.take(numpy.reshape(x, (16,1)), [0,5,10,15], axis=0)203 Dy = numpy.take(numpy.reshape(y, (16,1)), [0,5,10,15], axis=0)204 205 diag = numpy.concatenate( (Dx, Dy), axis=1)196 Dx = take(reshape(x, (16,1)), [0,5,10,15]) 197 Dy = take(reshape(y, (16,1)), [0,5,10,15]) 198 199 diag = concatenate( (Dx, Dy), axis=1) 206 200 d_midpoints = (diag[1:] + diag[:-1])/2 207 201 … … 215 209 assert not T[-1] == T[-2], msg 216 210 t = time[last_time_index] 217 q = f(t, point_id=0); assert numpy.allclose(r0, q)218 q = f(t, point_id=1); assert numpy.allclose(r1, q)219 q = f(t, point_id=2); assert numpy.allclose(r2, q)211 q = f(t, point_id=0); assert allclose(r0, q) 212 q = f(t, point_id=1); assert allclose(r1, q) 213 q = f(t, point_id=2); assert allclose(r2, q) 220 214 221 215 … … 224 218 225 219 timestep = 0 #First timestep 226 d_stage = numpy.reshape(numpy.take(stage[timestep, :], [0,5,10,15], axis=0), (4,1))227 d_uh = numpy.reshape(numpy.take(xmomentum[timestep, :], [0,5,10,15], axis=0), (4,1))228 d_vh = numpy.reshape(numpy.take(ymomentum[timestep, :], [0,5,10,15], axis=0), (4,1))229 D = numpy.concatenate( (d_stage, d_uh, d_vh), axis=1)220 d_stage = reshape(take(stage[timestep, :], [0,5,10,15]), (4,1)) 221 d_uh = reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1)) 222 d_vh = reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1)) 223 D = concatenate( (d_stage, d_uh, d_vh), axis=1) 230 224 231 225 #Reference interpolated values at midpoints on diagonal at … … 237 231 #Let us see if the file function can find the correct 238 232 #values 239 q = f(0, point_id=0); assert numpy.allclose(r0, q)240 q = f(0, point_id=1); assert numpy.allclose(r1, q)241 q = f(0, point_id=2); assert numpy.allclose(r2, q)233 q = f(0, point_id=0); assert allclose(r0, q) 234 q = f(0, point_id=1); assert allclose(r1, q) 235 q = f(0, point_id=2); assert allclose(r2, q) 242 236 243 237 … … 246 240 247 241 timestep = 33 248 d_stage = numpy.reshape(numpy.take(stage[timestep, :], [0,5,10,15], axis=0), (4,1))249 d_uh = numpy.reshape(numpy.take(xmomentum[timestep, :], [0,5,10,15], axis=0), (4,1))250 d_vh = numpy.reshape(numpy.take(ymomentum[timestep, :], [0,5,10,15], axis=0), (4,1))251 D = numpy.concatenate( (d_stage, d_uh, d_vh), axis=1)242 d_stage = reshape(take(stage[timestep, :], [0,5,10,15]), (4,1)) 243 d_uh = reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1)) 244 d_vh = reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1)) 245 D = concatenate( (d_stage, d_uh, d_vh), axis=1) 252 246 253 247 #Reference interpolated values at midpoints on diagonal at … … 257 251 r2 = (D[2] + D[3])/2 258 252 259 q = f(timestep/10., point_id=0); assert numpy.allclose(r0, q)260 q = f(timestep/10., point_id=1); assert numpy.allclose(r1, q)261 q = f(timestep/10., point_id=2); assert numpy.allclose(r2, q)253 q = f(timestep/10., point_id=0); assert allclose(r0, q) 254 q = f(timestep/10., point_id=1); assert allclose(r1, q) 255 q = f(timestep/10., point_id=2); assert allclose(r2, q) 262 256 263 257 … … 267 261 268 262 timestep = 15 269 d_stage = numpy.reshape(numpy.take(stage[timestep, :], [0,5,10,15], axis=0), (4,1))270 d_uh = numpy.reshape(numpy.take(xmomentum[timestep, :], [0,5,10,15], axis=0), (4,1))271 d_vh = numpy.reshape(numpy.take(ymomentum[timestep, :], [0,5,10,15], axis=0), (4,1))272 D = numpy.concatenate( (d_stage, d_uh, d_vh), axis=1)263 d_stage = reshape(take(stage[timestep, :], [0,5,10,15]), (4,1)) 264 d_uh = reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1)) 265 d_vh = reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1)) 266 D = concatenate( (d_stage, d_uh, d_vh), axis=1) 273 267 274 268 #Reference interpolated values at midpoints on diagonal at … … 280 274 # 281 275 timestep = 16 282 d_stage = numpy.reshape(numpy.take(stage[timestep, :], [0,5,10,15], axis=0), (4,1))283 d_uh = numpy.reshape(numpy.take(xmomentum[timestep, :], [0,5,10,15], axis=0), (4,1))284 d_vh = numpy.reshape(numpy.take(ymomentum[timestep, :], [0,5,10,15], axis=0), (4,1))285 D = numpy.concatenate( (d_stage, d