Changeset 5892
- Timestamp:
- Nov 5, 2008, 4:29:38 PM (16 years ago)
- Location:
- anuga_core/source/anuga/abstract_2d_finite_volumes
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/domain.py
r5847 r5892 8 8 """ 9 9 10 from Numeric import allclose, argmax, zeros, Float 10 ##from numpy.oldnumeric import allclose, argmax, zeros, Float 11 import numpy 12 11 13 from anuga.config import epsilon 12 14 from anuga.config import beta_euler, beta_rk2 … … 105 107 106 108 if verbose: print 'Initialising Domain' 107 from Numeric import zeros, Float, Int, ones108 109 from quantity import Quantity 109 110 … … 155 156 for key in self.full_send_dict: 156 157 buffer_shape = self.full_send_dict[key][0].shape[0] 157 self.full_send_dict[key].append( zeros( (buffer_shape,self.nsys) ,Float))158 self.full_send_dict[key].append(numpy.zeros( (buffer_shape,self.nsys), numpy.float)) 158 159 159 160 160 161 for key in self.ghost_recv_dict: 161 162 buffer_shape = self.ghost_recv_dict[key][0].shape[0] 162 self.ghost_recv_dict[key].append( zeros( (buffer_shape,self.nsys) ,Float))163 self.ghost_recv_dict[key].append(numpy.zeros( (buffer_shape,self.nsys), numpy.float)) 163 164 164 165 … … 168 169 N = len(self) #number_of_elements 169 170 self.number_of_elements = N 170 self.tri_full_flag = ones(N, Int)171 self.tri_full_flag = numpy.ones(N, numpy.int) 171 172 for i in self.ghost_recv_dict.keys(): 172 173 for id in self.ghost_recv_dict[i][0]: … … 175 176 # Test the assumption that all full triangles are store before 176 177 # the ghost triangles. 177 if not allclose(self.tri_full_flag[:self.number_of_full_nodes],1):178 if not numpy.allclose(self.tri_full_flag[:self.number_of_full_nodes],1): 178 179 print 'WARNING: Not all full triangles are store before ghost triangles' 179 180 … … 230 231 # calculation 231 232 N = len(self) # Number_of_triangles 232 self.already_computed_flux = zeros((N, 3), Int)233 self.already_computed_flux = numpy.zeros((N, 3), numpy.int) 233 234 234 235 # Storage for maximal speeds computed for each triangle by 235 236 # compute_fluxes 236 237 # This is used for diagnostics only (reset at every yieldstep) 237 self.max_speed = zeros(N, Float)238 self.max_speed = numpy.zeros(N, numpy.float) 238 239 239 240 if mesh_filename is not None: … … 266 267 """ 267 268 268 from Numeric import zeros, Float269 270 269 if not (vertex is None or edge is None): 271 270 msg = 'Values for both vertex and edge was specified.' … … 273 272 raise msg 274 273 275 q = zeros( len(self.conserved_quantities), Float)274 q = numpy.zeros( len(self.conserved_quantities), numpy.float) 276 275 277 276 for i, name in enumerate(self.conserved_quantities): … … 769 768 # Find index of largest computed flux speed 770 769 if triangle_id is None: 771 k = self.k = argmax(self.max_speed)770 k = self.k = numpy.argmax(self.max_speed) 772 771 else: 773 772 errmsg = 'Triangle_id %d does not exist in mesh: %s' %(triangle_id, … … 1086 1085 1087 1086 """ 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' 1098 1099 1099 1100 … … 1104 1105 1105 1106 self._order_ = self.default_order 1107 print '.evolve: 2' 1106 1108 1107 1109 … … 1127 1129 self.number_of_first_order_steps = 0 1128 1130 1129 1131 print '.evolve: 3' 1130 1132 # Update ghosts 1131 1133 self.update_ghosts() 1132 1134 1135 print '.evolve: 4' 1133 1136 # Initial update of vertex and edge values 1134 1137 self.distribute_to_vertices_and_edges() 1135 1138 1139 print '.evolve: 5' 1136 1140 # Update extrema if necessary (for reporting) 1137 1141 self.update_extrema() 1138 1142 1143 print '.evolve: 6' 1139 1144 # Initial update boundary values 1140 1145 self.update_boundary() 1141 1146 1147 print '.evolve: 7' 1142 1148 # Or maybe restore from latest checkpoint 1143 1149 if self.checkpoint is True: 1144 1150 self.goto_latest_checkpoint() 1151 print '.evolve: 8' 1145 1152 1146 1153 if skip_initial_step is False: … … 1202 1209 self.number_of_steps = 0 1203 1210 self.number_of_first_order_steps = 0 1204 self.max_speed = zeros(N, Float)1211 self.max_speed = numpy.zeros(N, numpy.float) 1205 1212 1206 1213 def evolve_one_euler_step(self, yieldstep, finaltime): … … 1568 1575 """ 1569 1576 1570 from Numeric import ones, sum, equal, Float1571 1572 1577 N = len(self) # Number_of_triangles 1573 1578 d = len(self.conserved_quantities) -
anuga_core/source/anuga/abstract_2d_finite_volumes/ermapper_grids.py
r2054 r5892 2 2 3 3 # from os import open, write, read 4 import Numeric 5 6 celltype_map = {'IEEE4ByteReal': Numeric.Float32, 'IEEE8ByteReal': Numeric.Float64} 4 ##import numpy.oldnumeric as Numeric 5 import numpy 6 7 celltype_map = {'IEEE4ByteReal': numpy.float32, 'IEEE8ByteReal': numpy.float64} 7 8 8 9 … … 11 12 write_ermapper_grid(ofile, data, header = {}): 12 13 13 Function to write a 2D Num ericarray to an ERMapper grid. There are a series of conventions adopted within14 Function to write a 2D NumPy array to an ERMapper grid. There are a series of conventions adopted within 14 15 this code, specifically: 15 16 1) The registration coordinate for the data is the SW (or lower-left) corner of the data 16 17 2) The registration coordinates refer to cell centres 17 3) The data is a 2D Num ericarray with the NW-most data in element (0,0) and the SE-most data in element (N,M)18 3) The data is a 2D NumPy array with the NW-most data in element (0,0) and the SE-most data in element (N,M) 18 19 where N is the last line and M is the last column 19 20 4) There has been no testng of the use of a rotated grid. Best to keep data in an NS orientation … … 22 23 ofile: string - filename for output (note the output will consist of two files 23 24 ofile and ofile.ers. Either of these can be entered into this function 24 data: Num eric.array - 2D array containing the data to be output to the grid25 data: NumPy.array - 2D array containing the data to be output to the grid 25 26 header: dictionary - contains spatial information about the grid, in particular: 26 27 header['datum'] datum for the data ('"GDA94"') … … 57 58 58 59 # Check that the data is a 2 dimensional array 59 data_size = Numeric.shape(data)60 data_size = numpy.shape(data) 60 61 assert len(data_size) == 2 61 62 … … 83 84 nrofcellsperlines = int(header['nrofcellsperline']) 84 85 data = read_ermapper_data(data_file) 85 data = Numeric.reshape(data,(nroflines,nrofcellsperlines))86 data = numpy.reshape(data,(nroflines,nrofcellsperlines)) 86 87 return data 87 88 … … 163 164 return header 164 165 165 def write_ermapper_data(grid, ofile, data_format = Numeric.Float32):166 def write_ermapper_data(grid, ofile, data_format = numpy.float32): 166 167 167 168 … … 181 182 182 183 183 # Convert the array to data_format (default format is Float32)184 # Convert the array to data_format (default format is float32) 184 185 grid_as_float = grid.astype(data_format) 185 186 … … 193 194 194 195 195 def read_ermapper_data(ifile, data_format = Numeric.Float32):196 def read_ermapper_data(ifile, data_format = numpy.float32): 196 197 # open input file in a binary format and read the input string 197 198 fid = open(ifile,'rb') … … 199 200 fid.close() 200 201 201 # convert input string to required format (Note default format is Numeric.Float32)202 grid_as_float = Numeric.fromstring(input_string,data_format)202 # convert input string to required format (Note default format is numpy.float32) 203 grid_as_float = numpy.fromstring(input_string,data_format) 203 204 return grid_as_float 204 205 -
anuga_core/source/anuga/abstract_2d_finite_volumes/general_mesh.py
r5842 r5892 1 2 from Numeric import concatenate, reshape, take, allclose 3 from Numeric import array, zeros, Int, Float, sqrt, sum, arange 1 import numpy 4 2 5 3 from anuga.coordinate_transforms.geo_reference import Geo_reference … … 90 88 if verbose: print 'General_mesh: Building basic mesh structure in ANUGA domain' 91 89 92 self.triangles = array(triangles, Int) 93 self.nodes = array(nodes, Float) 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) 94 94 95 95 … … 138 138 139 139 msg = 'Vertex indices reference non-existing coordinate sets' 140 assert max(self.triangles. flat) < self.nodes.shape[0], msg140 assert max(self.triangles.ravel()) < 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) 148 ## self.xy_extent = array(xy_extent, Float) 149 self.xy_extent = numpy.array(xy_extent, numpy.float) 149 150 150 151 151 152 # Allocate space for geometric quantities 152 self.normals = zeros((N, 6), Float) 153 self.areas = zeros(N, Float) 154 self.edgelengths = zeros((N, 3), Float) 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) 155 159 156 160 # Get x,y coordinates for all triangles and store … … 187 191 # - Stored as six floats n0x,n0y,n1x,n1y,n2x,n2y per triangle 188 192 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))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)) 197 201 198 202 # Normalise … … 274 278 if absolute is True: 275 279 if not self.geo_reference.is_absolute(): 276 return V + array([self.geo_reference.get_xllcorner(),277 self.geo_reference.get_yllcorner()])280 return V + numpy.array([self.geo_reference.get_xllcorner(), 281 self.geo_reference.get_yllcorner()]) 278 282 else: 279 283 return V … … 311 315 i = triangle_id 312 316 msg = 'triangle_id must be an integer' 317 print 'type(triangle_id)=%s. triangle_id=%s' % (type(triangle_id), str(triangle_id)) 313 318 assert int(i) == i, msg 314 319 assert 0 <= i < self.number_of_triangles … … 316 321 i3 = 3*i 317 322 if absolute is True and not self.geo_reference.is_absolute(): 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])323 offset = numpy.array([self.geo_reference.get_xllcorner(), 324 self.geo_reference.get_yllcorner()]) 325 return numpy.array([V[i3,:]+offset, 326 V[i3+1,:]+offset, 327 V[i3+2,:]+offset]) 323 328 else: 324 return array([V[i3,:], V[i3+1,:], V[i3+2,:]])329 return numpy.array([V[i3,:], V[i3+1,:], V[i3+2,:]]) 325 330 326 331 … … 349 354 350 355 M = self.number_of_triangles 351 vertex_coordinates = zeros((3*M, 2), Float) 356 ## vertex_coordinates = zeros((3*M, 2), Float) 357 vertex_coordinates = numpy.zeros((3*M, 2), numpy.float) 352 358 353 359 for i in range(M): … … 376 382 indices = range(M) 377 383 378 return take(self.triangles, indices)384 return numpy.take(self.triangles, indices, axis=0) 379 385 380 386 … … 409 415 410 416 #T = reshape(array(range(K)).astype(Int), (M,3)) 411 T = reshape(arange(K).astype(Int), (M,3)) # Faster 417 ## T = reshape(arange(K).astype(Int), (M,3)) # Faster 418 T = numpy.reshape(numpy.arange(K).astype(numpy.int), (M,3)) # Faster 412 419 413 420 return T … … 439 446 if node is not None: 440 447 # Get index for this node 441 first = sum(self.number_of_triangles_per_node[:node])448 first = numpy.sum(self.number_of_triangles_per_node[:node]) 442 449 443 450 # Get number of triangles for this node 444 count = self.number_of_triangles_per_node[node]451 count = int(self.number_of_triangles_per_node[node]) 445 452 446 453 for i in range(count): … … 452 459 triangle_list.append( (volume_id, vertex_id) ) 453 460 454 triangle_list = array(triangle_list)461 triangle_list = numpy.array(triangle_list) 455 462 else: 456 463 # Get info for all nodes recursively. … … 529 536 530 537 # Count number of triangles per node 531 number_of_triangles_per_node = zeros(self.number_of_full_nodes)538 number_of_triangles_per_node = numpy.zeros(self.number_of_full_nodes) 532 539 for volume_id, triangle in enumerate(self.get_triangles()): 533 540 for vertex_id in triangle: … … 535 542 536 543 # Allocate space for inverted structure 537 number_of_entries = sum(number_of_triangles_per_node)538 vertex_value_indices = zeros(number_of_entries)544 number_of_entries = numpy.sum(number_of_triangles_per_node) 545 vertex_value_indices = numpy.zeros(number_of_entries) 539 546 540 547 # Register (triangle, vertex) indices for each node … … 582 589 Y = C[:,1:6:2].copy() 583 590 584 xmin = min(X. flat)585 xmax = max(X. flat)586 ymin = min(Y. flat)587 ymax = max(Y. flat)591 xmin = min(X.ravel()) 592 xmax = max(X.ravel()) 593 ymin = min(Y.ravel()) 594 ymax = max(Y.ravel()) 588 595 #print "C",C 589 596 return xmin, xmax, ymin, ymax … … 598 605 """ 599 606 600 return sum(self.areas) 601 602 603 607 return numpy.sum(self.areas) -
anuga_core/source/anuga/abstract_2d_finite_volumes/generic_boundary_conditions.py
r5672 r5892 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 numpy 9 11 10 12 … … 67 69 raise Exception, msg 68 70 69 from Numeric import array, Float 70 self.conserved_quantities=array(conserved_quantities).astype(Float) 71 self.conserved_quantities=numpy.array(conserved_quantities).astype(numpy.float) 71 72 72 73 def __repr__(self): … … 96 97 raise msg 97 98 98 99 from Numeric import array, Float100 99 try: 101 q = array(q).astype(Float)100 q = numpy.array(q).astype(numpy.float) 102 101 except: 103 102 msg = 'Return value from time boundary function could ' … … 136 135 def __init__(self, filename, domain): 137 136 import time 138 from Numeric import array139 137 from anuga.config import time_format 140 138 from anuga.abstract_2d_finite_volumes.util import File_function … … 206 204 207 205 import time 208 from Numeric import array, zeros, Float209 206 from anuga.config import time_format 210 207 from anuga.abstract_2d_finite_volumes.util import file_function … … 222 219 223 220 if verbose: print 'Find midpoint coordinates of entire boundary' 224 self.midpoint_coordinates = zeros( (len(domain.boundary), 2), Float)221 self.midpoint_coordinates = numpy.zeros( (len(domain.boundary), 2), numpy.float) 225 222 boundary_keys = domain.boundary.keys() 226 223 … … 242 239 243 240 # Compute midpoints 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])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]) 247 244 248 245 # Convert to absolute UTM coordinates -
anuga_core/source/anuga/abstract_2d_finite_volumes/mesh_factory.py
r3678 r5892 2 2 mesh file formats 3 3 """ 4 5 import numpy 4 6 5 7 … … 73 75 74 76 from anuga.config import epsilon 75 from Numeric import zeros, Float, Int76 77 77 78 delta1 = float(len1)/m … … 93 94 index = Index(n,m) 94 95 95 points = zeros( (Np,2), Float)96 points = numpy.zeros( (Np,2), numpy.float) 96 97 97 98 for i in range(m+1): … … 105 106 106 107 107 elements = zeros( (Nt,3), Int)108 elements = numpy.zeros( (Nt,3), numpy.int) 108 109 boundary = {} 109 110 nt = -1 … … 149 150 150 151 from anuga.config import epsilon 151 from Numeric import zeros, Float, Int152 152 153 153 delta1 = float(len1)/m … … 208 208 """ 209 209 210 from Numeric import array211 210 import math 212 211 … … 510 509 """ 511 510 512 from Numeric import array511 # from numpy.oldnumeric import array 513 512 import math 514 513 … … 592 591 """ 593 592 594 from Numeric import array595 593 import math 596 594 … … 686 684 """ 687 685 688 from Numeric import array689 686 import math 690 691 687 from anuga.config import epsilon 692 693 688 694 689 deltax = lenx/float(m) -
anuga_core/source/anuga/abstract_2d_finite_volumes/neighbour_mesh.py
r5866 r5892 11 11 from anuga.caching import cache 12 12 from math import pi, sqrt 13 from Numeric import array, allclose 14 13 import numpy 15 14 16 15 class Mesh(General_mesh): … … 79 78 """ 80 79 81 82 83 from Numeric import array, zeros, Int, Float, maximum, sqrt, sum84 85 80 General_mesh.__init__(self, coordinates, triangles, 86 81 number_of_full_nodes=\ … … 98 93 99 94 #Allocate space for geometric quantities 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)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) 108 103 109 104 #Get x,y coordinates for all triangles and store … … 124 119 125 120 #Compute centroid 126 centroid = array([(x0 + x1 + x2)/3, (y0 + y1 + y2)/3])121 centroid = numpy.array([(x0 + x1 + x2)/3, (y0 + y1 + y2)/3]) 127 122 self.centroid_coordinates[i] = centroid 128 123 … … 133 128 134 129 #Midpoints 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])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]) 138 133 139 134 #The radius is the distance from the centroid of 140 135 #a triangle to the midpoint of the side of the triangle 141 136 #closest to the centroid 142 d0 = sqrt(sum( (centroid-m0)**2 ))143 d1 = sqrt(sum( (centroid-m1)**2 ))144 d2 = sqrt(sum( (centroid-m2)**2 ))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 )) 145 140 146 141 self.radii[i] = min(d0, d1, d2) … … 150 145 #of inscribed circle is computed 151 146 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)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) 155 150 156 151 self.radii[i]=2.0*self.areas[i]/(a+b+c) … … 388 383 self.element_tag is defined 389 384 """ 390 from Numeric import array, Int391 385 392 386 if tagged_elements is None: … … 395 389 #Check that all keys in given boundary exist 396 390 for tag in tagged_elements.keys(): 397 tagged_elements[tag] = array(tagged_elements[tag]).astype(Int)391 tagged_elements[tag] = numpy.array(tagged_elements[tag]).astype(numpy.int) 398 392 399 393 msg = 'Not all elements exist. ' … … 463 457 """ 464 458 465 from Numeric import allclose, sqrt, array, minimum, maximum466 459 from anuga.utilities.numerical_tools import angle, ensure_numeric 467 460 … … 477 470 inverse_segments = {} 478 471 p0 = None 479 mindist = sqrt(sum((pmax-pmin)**2)) # Start value across entire mesh472 mindist = numpy.sqrt(numpy.sum((pmax-pmin)**2)) # Start value across entire mesh 480 473 for i, edge_id in self.boundary.keys(): 481 474 # Find vertex ids for boundary segment … … 487 480 B = self.get_vertex_coordinate(i, b, absolute=True) # End 488 481 489 490 482 # Take the point closest to pmin as starting point 491 483 # Note: Could be arbitrary, but nice to have 492 484 # a unique way of selecting 493 dist_A = sqrt(sum((A-pmin)**2))494 dist_B = sqrt(sum((B-pmin)**2))485 dist_A = numpy.sqrt(numpy.sum((A-pmin)**2)) 486 dist_B = numpy.sqrt(numpy.sum((B-pmin)**2)) 495 487 496 488 # Find lower leftmost point … … 593 585 # We have reached a point already visited. 594 586 595 if allclose(p1, polygon[0]):587 if numpy.allclose(p1, polygon[0]): 596 588 # If it is the initial point, the polygon is complete. 597 589 … … 629 621 from anuga.utilities.numerical_tools import anglediff 630 622 631 from Numeric import sort, allclose632 633 623 N = len(self) 634 624 … … 672 662 673 663 # Normalise 674 l_u = sqrt(u[0]*u[0] + u[1]*u[1])675 l_v = sqrt(v[0]*v[0] + v[1]*v[1])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]) 676 666 677 667 msg = 'Normal vector in triangle %d does not have unit length' %i 678 assert allclose(l_v, 1), msg668 assert numpy.allclose(l_v, 1), msg 679 669 680 670 x = (u[0]*v[0] + u[1]*v[1])/l_u # Inner product … … 730 720 731 721 V = self.vertex_value_indices[:] #Take a copy 732 V = sort(V)733 assert allclose(V, range(3*N))722 V = numpy.sort(V) 723 assert numpy.allclose(V, range(3*N)) 734 724 735 725 assert sum(self.number_of_triangles_per_node) ==\ … … 742 732 count[i] += 1 743 733 744 assert allclose(count, self.number_of_triangles_per_node)734 assert numpy.allclose(count, self.number_of_triangles_per_node) 745 735 746 736 … … 805 795 """ 806 796 807 from Numeric import arange808 797 from anuga.utilities.numerical_tools import histogram, create_bins 809 798 … … 1141 1130 1142 1131 # Distances from line origin to the two intersections 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))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)) 1147 1136 1148 1137 if d1 < d0: … … 1157 1146 # Normal direction: 1158 1147 # Right hand side relative to line direction 1159 vector = array([x1 - x0, y1 - y0]) # Segment vector1160 length = sqrt(sum(vector**2)) # Segment length1161 normal = array([vector[1], -vector[0]])/length1148 vector = numpy.array([x1 - x0, y1 - y0]) # Segment vector 1149 length = numpy.sqrt(numpy.sum(vector**2)) # Segment length 1150 normal = numpy.array([vector[1], -vector[0]])/length 1162 1151 1163 1152 … … 1239 1228 assert isinstance(segment, Triangle_intersection), msg 1240 1229 1241 midpoint = sum(array(segment.segment))/21230 midpoint = numpy.sum(numpy.array(segment.segment))/2 1242 1231 midpoints.append(midpoint) 1243 1232 -
anuga_core/source/anuga/abstract_2d_finite_volumes/pmesh2domain.py
r4902 r5892 9 9 import sys 10 10 11 import numpy 11 12 12 13 … … 161 162 """ 162 163 163 from Numeric import transpose164 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 = transpose(mesh_dict['vertex_attributes'])174 point_atts = numpy.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 for quantity, value_vector in map (None, point_titles, point_atts): 178 print 'type(point_atts)=%s' % type(point_atts) 179 for quantity, value_vector in map(None, point_titles, point_atts): 179 180 vertex_quantity_dict[quantity] = value_vector 180 181 tag_dict = pmesh_dict_to_tag_dict(mesh_dict) -
anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py
r5866 r5892 15 15 """ 16 16 17 from Numeric import array, zeros, Float, less, concatenate, NewAxis,\ 18 argmax, argmin, allclose, take, reshape, alltrue 17 import numpy 19 18 20 19 from anuga.utilities.numerical_tools import ensure_numeric, is_scalar … … 38 37 if vertex_values is None: 39 38 N = len(domain) # number_of_elements 40 self.vertex_values = zeros((N, 3), Float)39 self.vertex_values = numpy.zeros((N, 3), numpy.float) 41 40 else: 42 self.vertex_values = array(vertex_values).astype(Float)41 self.vertex_values = numpy.array(vertex_values).astype(numpy.float) 43 42 44 43 N, V = self.vertex_values.shape … … 57 56 58 57 # Allocate space for other quantities 59 self.centroid_values = zeros(N, Float)60 self.edge_values = zeros((N, 3), Float)58 self.centroid_values = numpy.zeros(N, numpy.float) 59 self.edge_values = numpy.zeros((N, 3), numpy.float) 61 60 62 61 # Allocate space for Gradient 63 self.x_gradient = zeros(N, Float)64 self.y_gradient = zeros(N, Float)62 self.x_gradient = numpy.zeros(N, numpy.float) 63 self.y_gradient = numpy.zeros(N, numpy.float) 65 64 66 65 # Allocate space for Limiter Phi 67 self.phi = zeros(N, Float)66 self.phi = numpy.zeros(N, numpy.float) 68 67 69 68 # Intialise centroid and edge_values … … 72 71 # Allocate space for boundary values 73 72 L = len(domain.boundary) 74 self.boundary_values = zeros(L, Float)73 self.boundary_values = numpy.zeros(L, numpy.float) 75 74 76 75 # Allocate space for updates of conserved quantities by … … 78 77 79 78 # Allocate space for update fields 80 self.explicit_update = zeros(N, Float )81 self.semi_implicit_update = zeros(N, Float )82 self.centroid_backup_values = zeros(N, Float)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) 83 82 84 83 self.set_beta(1.0) … … 382 381 from anuga.geospatial_data.geospatial_data import Geospatial_data 383 382 from types import FloatType, IntType, LongType, ListType, NoneType 384 from Numeric import ArrayType385 383 386 384 # Treat special case: Polygon situation … … 448 446 449 447 msg = 'Indices must be a list or None' 450 assert type(indices) in [ListType, NoneType, ArrayType], msg448 assert type(indices) in [ListType, NoneType, numpy.ndarray], msg 451 449 452 450 … … 458 456 self.set_values_from_constant(numeric, 459 457 location, indices, verbose) 460 elif type(numeric) in [ ArrayType, ListType]:458 elif type(numeric) in [numpy.ndarray, ListType]: 461 459 self.set_values_from_array(numeric, 462 460 location, indices, verbose) … … 474 472 use_cache=use_cache) 475 473 else: 476 msg = 'Illegal type for argument numeric: %s' % str(numeric)477 raise msg474 msg = 'Illegal type for argument numeric: %s' % str(numeric) 475 raise TypeError, msg 478 476 479 477 elif quantity is not None: … … 610 608 """ 611 609 612 from Numeric import array, Float, Int, allclose 613 614 values = array(values).astype(Float) 610 values = numpy.array(values).astype(numpy.float) 615 611 616 612 if indices is not None: 617 indices = array(indices).astype(Int)613 indices = numpy.array(indices).astype(numpy.int) 618 614 msg = 'Number of values must match number of indices:' 619 615 msg += ' You specified %d values and %d indices'\ … … 640 636 641 637 elif location == 'unique vertices': 642 assert len(values.shape) == 1 or allclose(values.shape[1:], 1),\638 assert len(values.shape) == 1 or numpy.allclose(values.shape[1:], 1),\ 643 639 'Values array must be 1d' 644 640 645 self.set_vertex_values(values. flat, indices=indices)641 self.set_vertex_values(values.ravel(), indices=indices) 646 642 647 643 else: … … 676 672 A = q.vertex_values 677 673 678 from Numeric import allclose679 674 msg = 'Quantities are defined on different meshes. '+\ 680 675 'This might be a case for implementing interpolation '+\ 681 676 'between different meshes.' 682 assert allclose(A.shape, self.vertex_values.shape), msg677 assert numpy.allclose(A.shape, self.vertex_values.shape), msg 683 678 684 679 self.set_values(A, location='vertices', … … 716 711 indices = range(len(self)) 717 712 718 V = take(self.domain.get_centroid_coordinates(), indices) 713 V = numpy.take(self.domain.get_centroid_coordinates(), indices, axis=0) 714 print 'V=%s' % str(V) 719 715 self.set_values(f(V[:,0], V[:,1]), 720 716 location=location, … … 780 776 781 777 782 points = ensure_numeric(points, Float)783 values = ensure_numeric(values, Float)778 points = ensure_numeric(points, numpy.float) 779 values = ensure_numeric(values, numpy.float) 784 780 785 781 if location != 'vertices': … … 913 909 # Always return absolute indices 914 910 if mode is None or mode == 'max': 915 i = argmax(V)911 i = numpy.argmax(V) 916 912 elif mode == 'min': 917 i = argmin(V)913 i = numpy.argmin(V) 918 914 919 915 … … 1118 1114 """ 1119 1115 1120 from Numeric import take1121 1122 1116 # FIXME (Ole): I reckon we should have the option of passing a 1123 1117 # polygon into get_values. The question becomes how … … 1143 1137 raise msg 1144 1138 1145 import types , Numeric1146 assert type(indices) in [types.ListType, types.NoneType,1147 Numeric.ArrayType],\1139 import types 1140 1141 assert type(indices) in [types.ListType, types.NoneType, numpy.ndarray], \ 1148 1142 'Indices must be a list or None' 1149 1143 … … 1151 1145 if (indices == None): 1152 1146 indices = range(len(self)) 1153 return take(self.centroid_values,indices)1147 return numpy.take(self.centroid_values, indices, axis=0) 1154 1148 elif location == 'edges': 1155 1149 if (indices == None): 1156 1150 indices = range(len(self)) 1157 return take(self.edge_values,indices)1151 return numpy.take(self.edge_values, indices, axis=0) 1158 1152 elif location == 'unique vertices': 1159 1153 if (indices == None): … … 1178 1172 sum += self.vertex_values[triangle_id, vertex_id] 1179 1173 vert_values.append(sum/len(triangles)) 1180 return Numeric.array(vert_values)1174 return numpy.array(vert_values) 1181 1175 else: 1182 1176 if (indices is None): 1183 1177 indices = range(len(self)) 1184 return take(self.vertex_values, indices)1178 return numpy.take(self.vertex_values, indices, axis=0) 1185 1179 1186 1180 … … 1196 1190 """ 1197 1191 1198 from Numeric import array, Float1199 1200 1192 # Assert that A can be converted to a Numeric array of appropriate dim 1201 A = ensure_numeric(A, Float)1193 A = ensure_numeric(A, numpy.float) 1202 1194 1203 1195 # print 'SHAPE A', A.shape … … 1273 1265 """ 1274 1266 1275 from Numeric import concatenate, zeros, Float, Int, array, reshape1276 1277 1278 1267 if smooth is None: 1279 1268 # Take default from domain … … 1284 1273 1285 1274 if precision is None: 1286 precision = Float1275 precision = numpy.float 1287 1276 1288 1277 … … 1293 1282 V = self.domain.get_triangles() 1294 1283 N = self.domain.number_of_full_nodes # Ignore ghost nodes if any 1295 A = zeros(N, Float)1284 A = numpy.zeros(N, numpy.float) 1296 1285 points = self.domain.get_nodes() 1297 1286 … … 1343 1332 V = self.domain.get_disconnected_triangles() 1344 1333 points = self.domain.get_vertex_coordinates() 1345 A = self.vertex_values. flat.astype(precision)1334 A = self.vertex_values.ravel().astype(precision) 1346 1335 1347 1336 -
anuga_core/source/anuga/abstract_2d_finite_volumes/quantity_ext.c
r5306 r5892 11 11 12 12 #include "Python.h" 13 #include " Numeric/arrayobject.h"13 #include "numpy/arrayobject.h" 14 14 #include "math.h" 15 15 -
anuga_core/source/anuga/abstract_2d_finite_volumes/region.py
r5208 r5892 8 8 # FIXME (DSG-DSG) add better comments 9 9 10 from Numeric import average 10 import numpy 11 12 11 13 class Region: 12 14 """Base class for modifying quantities based on a region. … … 101 103 values = Q.get_values(indices=self.build_indices(elements, domain), 102 104 location=self.location) 103 av = average(values)105 av = numpy.average(values) 104 106 if self.location == "vertices": 105 av = average(av)107 av = numpy.average(av) 106 108 new_values = av + self.X 107 109 else: -
anuga_core/source/anuga/abstract_2d_finite_volumes/show_balanced_limiters.py
r4204 r5892 18 18 19 19 from mesh_factory import rectangular 20 from Numeric import array 21 20 22 21 23 22 ###################### … … 78 77 domain.set_quantity('stage', Z) 79 78 80 from Numeric import allclose81 82 79 #Evolve 83 80 for t in domain.evolve(yieldstep = 0.1, finaltime = 30): -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_domain.py
r4932 r5892 6 6 from domain import * 7 7 from anuga.config import epsilon 8 from Numeric import allclose, array, ones, Float 8 import numpy 9 9 10 10 … … 64 64 65 65 66 assert domain.get_conserved_quantities(0, edge=1) == 0.66 assert numpy.alltrue(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 allclose(q, [2., 2., 0.])97 assert numpy.allclose(q, [2., 2., 0.]) 98 98 99 99 q = domain.get_conserved_quantities(1) 100 assert allclose(q, [5., 5., 0.])100 assert numpy.allclose(q, [5., 5., 0.]) 101 101 102 102 q = domain.get_conserved_quantities(2) 103 assert allclose(q, [3., 3., 0.])103 assert numpy.allclose(q, [3., 3., 0.]) 104 104 105 105 q = domain.get_conserved_quantities(3) 106 assert allclose(q, [0., 0., 0.])106 assert numpy.allclose(q, [0., 0., 0.]) 107 107 108 108 109 109 #Edges 110 110 q = domain.get_conserved_quantities(0, edge=0) 111 assert allclose(q, [2.5, 2.5, 0.])111 assert numpy.allclose(q, [2.5, 2.5, 0.]) 112 112 q = domain.get_conserved_quantities(0, edge=1) 113 assert allclose(q, [2., 2., 0.])113 assert numpy.allclose(q, [2., 2., 0.]) 114 114 q = domain.get_conserved_quantities(0, edge=2) 115 assert allclose(q, [1.5, 1.5, 0.])115 assert numpy.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 allclose(q, [5, 5, 0.])119 assert numpy.allclose(q, [5, 5, 0.]) 120 120 121 121 122 122 q = domain.get_conserved_quantities(2, edge=0) 123 assert allclose(q, [4.5, 4.5, 0.])123 assert numpy.allclose(q, [4.5, 4.5, 0.]) 124 124 q = domain.get_conserved_quantities(2, edge=1) 125 assert allclose(q, [4.5, 4.5, 0.])125 assert numpy.allclose(q, [4.5, 4.5, 0.]) 126 126 q = domain.get_conserved_quantities(2, edge=2) 127 assert allclose(q, [0., 0., 0.])127 assert numpy.allclose(q, [0., 0., 0.]) 128 128 129 129 130 130 q = domain.get_conserved_quantities(3, edge=0) 131 assert allclose(q, [3., 3., 0.])131 assert numpy.allclose(q, [3., 3., 0.]) 132 132 q = domain.get_conserved_quantities(3, edge=1) 133 assert allclose(q, [-1.5, -1.5, 0.])133 assert numpy.allclose(q, [-1.5, -1.5, 0.]) 134 134 q = domain.get_conserved_quantities(3, edge=2) 135 assert allclose(q, [-1.5, -1.5, 0.])135 assert numpy.allclose(q, [-1.5, -1.5, 0.]) 136 136 137 137 … … 179 179 Q = domain.create_quantity_from_expression(expression) 180 180 181 assert allclose(Q.vertex_values, [[2,3,4], [6,6,6],182 [1,1,10], [-5, 4, 4]])181 assert numpy.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 allclose(Q.vertex_values, (X**2 + Y**2)**0.5)190 assert numpy.allclose(Q.vertex_values, (X**2 + Y**2)**0.5) 191 191 192 192 … … 314 314 Q = domain.quantities['depth'] 315 315 316 assert allclose(Q.vertex_values, [[2,3,4], [6,6,6],317 [1,1,10], [-5, 4, 4]])316 assert numpy.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 allclose(domain.neighbours, [[-1,-2,-3]])384 assert numpy.allclose(domain.neighbours, [[-1,-2,-3]]) 385 385 386 386 … … 471 471 [0,0,9], [-6, 3, 3]]) 472 472 473 assert allclose( domain.quantities['stage'].centroid_values,474 [2,5,3,0] )473 assert numpy.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 allclose( domain.quantities['stage'].vertex_values,487 [[ 2., 2., 2.],488 [ 5., 5., 5.],489 [ 3., 3., 3.],490 [ 0., 0., 0.]])486 assert numpy.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 = array([4.,3.,2.,1.])530 domain.quantities[name].semi_implicit_update = array([1.,1.,1.,1.])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.]) 531 531 532 532 … … 535 535 domain.update_conserved_quantities() 536 536 537 sem = array([1.,1.,1.,1.])/array([1, 2, 3, 4])538 denom = ones(4, Float)-domain.timestep*sem537 sem = numpy.array([1.,1.,1.,1.])/numpy.array([1, 2, 3, 4]) 538 denom = numpy.ones(4, numpy.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 = array([1., 2., 3., 4.])543 x = numpy.array([1., 2., 3., 4.]) 544 544 x /= denom 545 x += domain.timestep* array( [4,3,2,1] )545 x += domain.timestep*numpy.array( [4,3,2,1] ) 546 546 547 547 for name in domain.conserved_quantities: 548 assert allclose(domain.quantities[name].centroid_values, x)548 assert numpy.allclose(domain.quantities[name].centroid_values, x) 549 549 550 550 … … 578 578 [0,0,9], [-6, 3, 3]]) 579 579 580 assert allclose( domain.quantities['stage'].centroid_values,581 [2,5,3,0] )580 assert numpy.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 allclose( domain.quantities['stage'].vertex_values,594 [[ 2., 2., 2.],595 [ 5., 5., 5.],596 [ 3., 3., 3.],597 [ 0., 0., 0.]])593 assert numpy.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, Float613 612 614 613 #Create basic mesh … … 627 626 from mesh_factory import rectangular 628 627 from shallow_water import Domain 629 from Numeric import zeros, Float630 628 631 629 #Create basic mesh … … 645 643 domain.set_region([set_bottom_friction, set_top_friction]) 646 644 #print domain.quantities['friction'].get_values() 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]])645 assert numpy.allclose(domain.quantities['friction'].get_values(),\ 646 [[ 0.09, 0.09, 0.09], 647 [ 0.09, 0.09, 0.09], 648 [ 0.07, 0.07, 0.07], 649 [ 0.07, 0.07, 0.07], 650 [ 1.0, 1.0, 1.0], 651 [ 1.0, 1.0, 1.0]]) 654 652 655 653 domain.set_region([set_all_friction]) 656 654 #print domain.quantities['friction'].get_values() 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]])655 assert numpy.allclose(domain.quantities['friction'].get_values(), 656 [[ 10.09, 10.09, 10.09], 657 [ 10.09, 10.09, 10.09], 658 [ 10.07, 10.07, 10.07], 659 [ 10.07, 10.07, 10.07], 660 [ 11.0, 11.0, 11.0], 661 [ 11.0, 11.0, 11.0]]) 664 662 665 663 … … 670 668 from mesh_factory import rectangular 671 669 from shallow_water import Domain 672 from Numeric import zeros, Float673 670 674 671 #Create basic mesh … … 690 687 691 688 #print domain.quantities['friction'].get_values() 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]])689 assert numpy.allclose(domain.quantities['friction'].get_values(), 690 [[ 0.09, 0.09, 0.09], 691 [ 0.09, 0.09, 0.09], 692 [ 0.07, 0.07, 0.07], 693 [ 0.07, 0.07, 0.07], 694 [ 1.0, 1.0, 1.0], 695 [ 1.0, 1.0, 1.0]]) 699 696 700 697 domain.set_region([set_bottom_friction, set_top_friction]) 701 698 #print domain.quantities['friction'].get_values() 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]])699 assert numpy.allclose(domain.quantities['friction'].get_values(), 700 [[ 0.09, 0.09, 0.09], 701 [ 0.09, 0.09, 0.09], 702 [ 0.07, 0.07, 0.07], 703 [ 0.07, 0.07, 0.07], 704 [ 1.0, 1.0, 1.0], 705 [ 1.0, 1.0, 1.0]]) 709 706 710 707 domain.set_region([set_all_friction]) 711 708 #print domain.quantities['friction'].get_values() 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]])709 assert numpy.allclose(domain.quantities['friction'].get_values(), 710 [[ 10.09, 10.09, 10.09], 711 [ 10.09, 10.09, 10.09], 712 [ 10.07, 10.07, 10.07], 713 [ 10.07, 10.07, 10.07], 714 [ 11.0, 11.0, 11.0], 715 [ 11.0, 11.0, 11.0]]) 719 716 720 717 #------------------------------------------------------------- -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_ermapper.py
r1813 r5892 5 5 6 6 import ermapper_grids 7 import Numeric7 import numpy 8 8 from os import remove 9 9 … … 19 19 data_filename = 'test_write_ermapper_grid' 20 20 21 original_grid = Numeric.array([[0.0, 0.1, 1.0], [2.0, 3.0, 4.0]])21 original_grid = numpy.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 Numeric.allclose(original_grid, new_grid)27 assert numpy.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 Numeric.allclose(original_grid, new_grid)33 assert numpy.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 = Numeric.array([0.0, 0.1, 1.0, 2.0, 3.0, 4.0])42 original_grid = numpy.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, Numeric.Float64)45 ermapper_grids.write_ermapper_data(original_grid, filename, numpy.float64) 46 46 47 47 # Read in the test data 48 new_grid = ermapper_grids.read_ermapper_data(filename, Numeric.Float64)48 new_grid = ermapper_grids.read_ermapper_data(filename, numpy.float64) 49 49 50 50 # Check that the test data that has been read in matches the original data 51 assert Numeric.allclose(original_grid, new_grid)51 assert numpy.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 = Numeric.array([0.0, 0.1, 1.0, 2.0, 3.0, 4.0])59 original_grid = numpy.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 Numeric.allclose(original_grid, new_grid)68 assert numpy.allclose(original_grid, new_grid) 69 69 70 70 # Clean up created files … … 75 75 76 76 # setup test data 77 original_grid = Numeric.array([[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]])77 original_grid = numpy.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
r5843 r5892 7 7 8 8 from anuga.config import epsilon 9 from Numeric import allclose, array, ones, Float 9 import numpy 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, Float26 25 27 26 #Create basic mesh … … 30 29 31 30 32 assert allclose(domain.get_nodes(), nodes)31 assert numpy.allclose(domain.get_nodes(), nodes) 33 32 34 33 … … 41 40 for j in range(3): 42 41 k = triangles[i,j] #Index of vertex j in triangle i 43 assert allclose(V[3*i+j,:], nodes[k])42 assert numpy.allclose(V[3*i+j,:], nodes[k]) 44 43 45 44 def test_get_vertex_coordinates_with_geo_ref(self): … … 55 54 f = [4.0, 0.0] 56 55 57 nodes = array([a, b, c, d, e, f])56 nodes = numpy.array([a, b, c, d, e, f]) 58 57 59 58 nodes_absolute = geo.get_absolute(nodes) 60 59 61 60 #bac, bce, ecf, dbe, daf, dae 62 triangles = array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]])61 triangles = numpy.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 63 62 64 63 domain = General_mesh(nodes, triangles, 65 64 geo_reference = geo) 66 65 verts = domain.get_vertex_coordinates(triangle_id=0) 67 self.assert_( allclose(array([b,a,c]), verts))66 self.assert_(numpy.allclose(numpy.array([b,a,c]), verts)) 68 67 verts = domain.get_vertex_coordinates(triangle_id=0) 69 self.assert_( allclose(array([b,a,c]), verts))68 self.assert_(numpy.allclose(numpy.array([b,a,c]), verts)) 70 69 verts = domain.get_vertex_coordinates(triangle_id=0, 71 70 absolute=True) 72 self.assert_( allclose(array([nodes_absolute[1],73 nodes_absolute[0],74 nodes_absolute[2]]), verts))71 self.assert_(numpy.allclose(numpy.array([nodes_absolute[1], 72 nodes_absolute[0], 73 nodes_absolute[2]]), verts)) 75 74 verts = domain.get_vertex_coordinates(triangle_id=0, 76 75 absolute=True) 77 self.assert_( allclose(array([nodes_absolute[1],78 nodes_absolute[0],79 nodes_absolute[2]]), verts))76 self.assert_(numpy.allclose(numpy.array([nodes_absolute[1], 77 nodes_absolute[0], 78 nodes_absolute[2]]), verts)) 80 79 81 80 … … 86 85 """ 87 86 from mesh_factory import rectangular 88 from Numeric import zeros, Float89 87 90 88 #Create basic mesh … … 93 91 94 92 95 assert allclose(domain.get_nodes(), nodes)93 assert numpy.allclose(domain.get_nodes(), nodes) 96 94 97 95 … … 104 102 for j in range(3): 105 103 k = triangles[i,j] #Index of vertex j in triangle i 106 assert allclose(V[j,:], nodes[k])104 assert numpy.allclose(V[j,:], nodes[k]) 107 105 108 106 … … 114 112 """ 115 113 from mesh_factory import rectangular 116 from Numeric import zeros, Float117 114 118 115 #Create basic mesh … … 121 118 122 119 value = [7] 123 assert allclose(domain.get_triangles(), triangles)124 assert allclose(domain.get_triangles([0,4]),125 [triangles[0], triangles[4]])120 assert numpy.allclose(domain.get_triangles(), triangles) 121 assert numpy.allclose(domain.get_triangles([0,4]), 122 [triangles[0], triangles[4]]) 126 123 127 124 … … 130 127 """ 131 128 from mesh_factory import rectangular 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]) 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]) 142 138 #bac, bce, ecf, dbe, daf, dae 143 triangles = array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]])139 triangles = numpy.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 144 140 145 141 domain1 = General_mesh(nodes, triangles) … … 162 158 #print count 163 159 # 164 assert allclose(count, domain.number_of_triangles_per_node)160 assert numpy.allclose(count, domain.number_of_triangles_per_node) 165 161 166 162 # Check indices … … 196 192 f = [4.0, 0.0] 197 193 198 nodes = array([a, b, c, d, e, f])194 nodes = numpy.array([a, b, c, d, e, f]) 199 195 #bac, bce, ecf, dbe, daf, dae 200 triangles = array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]])196 triangles = numpy.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 201 197 202 198 domain = General_mesh(nodes, triangles) … … 204 200 # One node 205 201 L = domain.get_triangles_and_vertices_per_node(node=2) 206 assert allclose(L[0], [0, 2]) 207 assert allclose(L[1], [1, 1]) 208 assert allclose(L[2], [2, 1]) 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]) 209 206 210 207 # All nodes … … 213 210 for i, Lref in enumerate(ALL): 214 211 L = domain.get_triangles_and_vertices_per_node(node=i) 215 assert allclose(L, Lref)212 assert numpy.allclose(L, Lref) 216 213 217 214 … … 224 221 from mesh_factory import rectangular 225 222 from shallow_water import Domain 226 from Numeric import zeros, Float227 223 228 224 #Create basic mesh … … 239 235 from mesh_factory import rectangular 240 236 from shallow_water import Domain 241 from Numeric import zeros, Float242 237 243 238 #Create basic mesh … … 273 268 f = [4.0, 0.0] 274 269 275 nodes = array([a, b, c, d, e, f])270 nodes = numpy.array([a, b, c, d, e, f]) 276 271 277 272 nodes_absolute = geo.get_absolute(nodes) 278 273 279 274 #bac, bce, ecf, dbe, daf, dae 280 triangles = array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]])275 triangles = numpy.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 281 276 282 277 domain = General_mesh(nodes, triangles, 283 278 geo_reference = geo) 284 279 node = domain.get_node(2) 285 self.assert Equal(c, node)280 self.assertTrue(numpy.alltrue(c == node)) 286 281 287 282 node = domain.get_node(2, absolute=True) 288 self.assert Equal(nodes_absolute[2], node)283 self.assertTrue(numpy.alltrue(nodes_absolute[2] == node)) 289 284 290 285 node = domain.get_node(2, absolute=True) 291 self.assert Equal(nodes_absolute[2], node)286 self.assertTrue(numpy.alltrue(nodes_absolute[2] == node)) 292 287 293 288 … … 310 305 f = [4.0, 0.0] 311 306 312 nodes = array([a, b, c, d, e, f])307 nodes = numpy.array([a, b, c, d, e, f]) 313 308 314 309 nodes_absolute = geo.get_absolute(nodes) 315 310 316 311 # max index is 5, use 5, expect success 317 triangles = array([[1,5,2], [1,2,4], [4,2,5], [3,1,4]])312 triangles = numpy.array([[1,5,2], [1,2,4], [4,2,5], [3,1,4]]) 318 313 General_mesh(nodes, triangles, geo_reference=geo) 319 314 320 315 # max index is 5, use 6, expect assert failure 321 triangles = array([[1,6,2], [1,2,4], [4,2,5], [3,1,4]])316 triangles = numpy.array([[1,6,2], [1,2,4], [4,2,5], [3,1,4]]) 322 317 self.failUnlessRaises(AssertionError, General_mesh, 323 318 nodes, triangles, geo_reference=geo) 324 319 325 320 # max index is 5, use 10, expect assert failure 326 triangles = array([[1,10,2], [1,2,4], [4,2,5], [3,1,4]])321 triangles = numpy.array([[1,10,2], [1,2,4], [4,2,5], [3,1,4]]) 327 322 self.failUnlessRaises(AssertionError, General_mesh, 328 323 nodes, triangles, geo_reference=geo) … … 333 328 if __name__ == "__main__": 334 329 suite = unittest.makeSuite(Test_General_Mesh,'test') 335 #suite = unittest.makeSuite(Test_General_Mesh,'test_get_node')336 330 runner = unittest.TextTestRunner() 337 331 runner.run(suite) -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_generic_boundary_conditions.py
r5666 r5892 6 6 from generic_boundary_conditions import * 7 7 from anuga.config import epsilon 8 from Numeric import allclose, array8 import numpy 9 9 10 10 … … 44 44 45 45 q = Bd.evaluate() 46 assert allclose(q, x)46 assert numpy.allclose(q, x) 47 47 48 48 … … 98 98 q = T.evaluate(0, 2) #Vol=0, edge=2 99 99 100 assert allclose(q, [1.5, 2.5])100 assert numpy.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 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])177 assert numpy.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 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]) 187 187 188 188 … … 193 193 domain.time = 5*30/2 #A quarter way through first step 194 194 q = F.evaluate() 195 assert allclose(q, [1.0/4, sin(2*pi/10)/4])195 assert numpy.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 allclose(q, [2.5, (sin(2*2*pi/10) + sin(3*2*pi/10))/2])200 assert numpy.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
r3514 r5892 6 6 from domain import * 7 7 from anuga.config import epsilon 8 from Numeric import allclose, array, ones, Float 9 10 8 import numpy 11 9 12 10 … … 43 41 44 42 45 assert domain.get_conserved_quantities(0, edge=1) == 0.43 assert numpy.alltrue(domain.get_conserved_quantities(0, edge=1) == 0.) 46 44 47 45 -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_neighbour_mesh.py
r5288 r5892 1 1 #!/usr/bin/env python 2 3 4 2 5 3 #FIXME: Seperate the tests for mesh and general_mesh … … 13 11 from mesh_factory import rectangular 14 12 from anuga.config import epsilon 15 from Numeric import allclose, array, Int 13 import numpy 16 14 17 15 from anuga.coordinate_transforms.geo_reference import Geo_reference … … 20 18 21 19 def distance(x, y): 22 return sqrt( sum( ( array(x)-array(y))**2 ))20 return sqrt( sum( (numpy.array(x)-numpy.array(y))**2 )) 23 21 24 22 class Test_Mesh(unittest.TestCase): … … 63 61 #Normals 64 62 normals = mesh.get_normals() 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])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]) 72 70 73 71 #Edge lengths 74 assert allclose(mesh.edgelengths[0], [5.0, 3.0, 4.0])72 assert numpy.allclose(mesh.edgelengths[0], [5.0, 3.0, 4.0]) 75 73 76 74 … … 81 79 82 80 V = mesh.get_vertex_coordinates() 83 assert allclose(V, [ [0.0, 0.0],84 [4.0, 0.0],85 [0.0, 3.0] ])81 assert numpy.allclose(V, [ [0.0, 0.0], 82 [4.0, 0.0], 83 [0.0, 3.0] ]) 86 84 87 85 V0 = mesh.get_vertex_coordinate(0, 0) 88 assert allclose(V0, [0.0, 0.0])86 assert numpy.allclose(V0, [0.0, 0.0]) 89 87 90 88 V1 = mesh.get_vertex_coordinate(0, 1) 91 assert allclose(V1, [4.0, 0.0])89 assert numpy.allclose(V1, [4.0, 0.0]) 92 90 93 91 V2 = mesh.get_vertex_coordinate(0, 2) 94 assert allclose(V2, [0.0, 3.0])92 assert numpy.allclose(V2, [0.0, 3.0]) 95 93 96 94 … … 237 235 238 236 mesh = Mesh(points, vertices,use_inscribed_circle=False) 239 assert allclose(mesh.radii[0],sqrt(3.0)/3),'Steve''s doesn''t work'237 assert numpy.allclose(mesh.radii[0],sqrt(3.0)/3),'Steve''s doesn''t work' 240 238 241 239 mesh = Mesh(points, vertices,use_inscribed_circle=True) 242 assert allclose(mesh.radii[0],sqrt(3.0)/3),'inscribed circle doesn''t work'240 assert numpy.allclose(mesh.radii[0],sqrt(3.0)/3),'inscribed circle doesn''t work' 243 241 244 242 def test_inscribed_circle_rightangle_triangle(self): … … 252 250 253 251 mesh = Mesh(points, vertices,use_inscribed_circle=False) 254 assert allclose(mesh.radii[0],5.0/6),'Steve''s doesn''t work'252 assert numpy.allclose(mesh.radii[0],5.0/6),'Steve''s doesn''t work' 255 253 256 254 mesh = Mesh(points, vertices,use_inscribed_circle=True) 257 assert allclose(mesh.radii[0],1.0),'inscribed circle doesn''t work'255 assert numpy.allclose(mesh.radii[0],1.0),'inscribed circle doesn''t work' 258 256 259 257 … … 269 267 assert mesh.areas[0] == 2.0 270 268 271 assert allclose(mesh.centroid_coordinates[0], [2.0/3, 2.0/3])269 assert numpy.allclose(mesh.centroid_coordinates[0], [2.0/3, 2.0/3]) 272 270 273 271 … … 303 301 assert mesh.edgelengths[1,2] == sqrt(8.0) 304 302 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])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]) 309 307 310 308 def test_mesh_and_neighbours(self): … … 697 695 get values based on triangle lists. 698 696 """ 697 699 698 from mesh_factory import rectangular 700 from Numeric import zeros, Float701 699 702 700 #Create basic mesh … … 716 714 def test_boundary_polygon(self): 717 715 from mesh_factory import rectangular 718 #from mesh import Mesh719 from Numeric import zeros, Float720 716 721 717 #Create basic mesh … … 727 723 728 724 assert len(P) == 8 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]])725 assert numpy.allclose(P, [[0.0, 0.0], [0.5, 0.0], [1.0, 0.0], 726 [1.0, 0.5], [1.0, 1.0], [0.5, 1.0], 727 [0.0, 1.0], [0.0, 0.5]]) 732 728 for p in points: 733 729 #print p, P … … 736 732 737 733 def test_boundary_polygon_II(self): 738 from Numeric import zeros, Float739 740 741 734 #Points 742 735 a = [0.0, 0.0] #0 … … 764 757 765 758 assert len(P) == 8 766 assert allclose(P, [a, d, f, i, h, e, c, b])759 assert numpy.allclose(P, [a, d, f, i, h, e, c, b]) 767 760 768 761 for p in points: … … 774 767 """Same as II but vertices ordered differently 775 768 """ 776 777 from Numeric import zeros, Float778 779 769 780 770 #Points … … 804 794 805 795 assert len(P) == 8 806 assert allclose(P, [a, d, f, i, h, e, c, b])796 assert numpy.allclose(P, [a, d, f, i, h, e, c, b]) 807 797 808 798 for p in points: … … 815 805 is partitioned using pymetis. 816 806 """ 817 818 from Numeric import zeros, Float819 820 807 821 808 #Points … … 847 834 848 835 # Note that point e appears twice! 849 assert allclose(P, [a, d, f, e, g, h, e, c, b])836 assert numpy.allclose(P, [a, d, f, e, g, h, e, c, b]) 850 837 851 838 for p in points: … … 864 851 """ 865 852 866 from Numeric import zeros, Float867 853 from mesh_factory import rectangular 868 854 … … 907 893 908 894 """ 909 from Numeric import zeros, Float910 911 895 912 896 #Points … … 955 939 956 940 assert len(P) == 8 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)])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)]) 959 943 960 944 … … 998 982 [ 52341.70703125, 38563.39453125]] 999 983 1000 ##points = ensure_numeric(points, Int)/1000 # Simplify for ease of interpretation984 ##points = ensure_numeric(points, int)/1000 # Simplify for ease of interpretation 1001 985 1002 986 triangles = [[19, 0,15], … … 1101 1085 [ 35406.3359375 , 79332.9140625 ]] 1102 1086 1103 scaled_points = ensure_numeric(points, Int)/1000 # Simplify for ease of interpretation1087 scaled_points = ensure_numeric(points, int)/1000 # Simplify for ease of interpretation 1104 1088 1105 1089 triangles = [[ 0, 1, 2], … … 1142 1126 assert is_inside_polygon(p, P) 1143 1127 1144 assert allclose(P, Pref)1128 assert numpy.allclose(P, Pref) 1145 1129 1146 1130 def test_lone_vertices(self): … … 1194 1178 boundary_polygon = mesh.get_boundary_polygon() 1195 1179 1196 assert allclose(absolute_points, boundary_polygon)1180 assert numpy.allclose(absolute_points, boundary_polygon) 1197 1181 1198 1182 def test_get_triangle_containing_point(self): … … 1241 1225 1242 1226 neighbours = mesh.get_triangle_neighbours(0) 1243 assert allclose(neighbours, [-1,1,-1])1227 assert numpy.allclose(neighbours, [-1,1,-1]) 1244 1228 neighbours = mesh.get_triangle_neighbours(-10) 1245 1229 assert neighbours == [] … … 1290 1274 for x in L: 1291 1275 if x.triangle_id % 2 == 0: 1292 assert allclose(x.length, ceiling-y_line)1276 assert numpy.allclose(x.length, ceiling-y_line) 1293 1277 else: 1294 assert allclose(x.length, y_line-floor)1278 assert numpy.allclose(x.length, y_line-floor) 1295 1279 1296 1280 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)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) 1302 1286 1303 1287 assert x.triangle_id in intersected_triangles … … 1306 1290 1307 1291 msg = 'Segments do not add up' 1308 assert allclose(total_length, 2), msg1292 assert numpy.allclose(total_length, 2), msg 1309 1293 1310 1294 … … 1341 1325 total_length = 0 1342 1326 for x in L: 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)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) 1349 1333 1350 1334 … … 1355 1339 1356 1340 msg = 'Segments do not add up' 1357 assert allclose(total_length, 2), msg1341 assert numpy.allclose(total_length, 2), msg 1358 1342 1359 1343 … … 1395 1379 for x in L: 1396 1380 if x.triangle_id == 1: 1397 assert allclose(x.length, 1)1398 assert allclose(x.normal, [0, -1])1381 assert numpy.allclose(x.length, 1) 1382 assert numpy.allclose(x.normal, [0, -1]) 1399 1383 1400 1384 if x.triangle_id == 5: 1401 assert allclose(x.length, 0.5)1402 assert allclose(x.normal, [0, -1])1385 assert numpy.allclose(x.length, 0.5) 1386 assert numpy.allclose(x.normal, [0, -1]) 1403 1387 1404 1388 … … 1408 1392 1409 1393 msg = 'Segments do not add up' 1410 assert allclose(total_length, 1.5), msg1394 assert numpy.allclose(total_length, 1.5), msg 1411 1395 1412 1396 … … 1442 1426 total_length = 0 1443 1427 for i, x in enumerate(L): 1444 assert allclose(x.length, s2)1445 assert allclose(x.normal, [-s2, -s2])1446 assert allclose(sum(x.normal**2), 1)1428 assert numpy.allclose(x.length, s2) 1429 assert numpy.allclose(x.normal, [-s2, -s2]) 1430 assert numpy.allclose(sum(x.normal**2), 1) 1447 1431 1448 1432 assert x.triangle_id in intersected_triangles … … 1451 1435 1452 1436 msg = 'Segments do not add up' 1453 assert allclose(total_length, 4*s2), msg1437 assert numpy.allclose(total_length, 4*s2), msg 1454 1438 1455 1439 … … 1466 1450 total_length = 0 1467 1451 for i, x in enumerate(L): 1468 assert allclose(x.length, s2)1469 assert allclose(x.normal, [s2, s2])1470 assert allclose(sum(x.normal**2), 1)1452 assert numpy.allclose(x.length, s2) 1453 assert numpy.allclose(x.normal, [s2, s2]) 1454 assert numpy.allclose(sum(x.normal**2), 1) 1471 1455 1472 1456 assert x.triangle_id in intersected_triangles … … 1475 1459 1476 1460 msg = 'Segments do not add up' 1477 assert allclose(total_length, 4*s2), msg1461 assert numpy.allclose(total_length, 4*s2), msg 1478 1462 1479 1463 … … 1491 1475 total_length = 0 1492 1476 for i, x in enumerate(L): 1493 assert allclose(x.length, 2*s2)1494 assert allclose(x.normal, [-s2, s2])1495 assert allclose(sum(x.normal**2), 1)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) 1496 1480 1497 1481 assert x.triangle_id in intersected_triangles … … 1500 1484 1501 1485 msg = 'Segments do not add up' 1502 assert allclose(total_length, 4*s2), msg1486 assert numpy.allclose(total_length, 4*s2), msg 1503 1487 1504 1488 … … 1515 1499 total_length = 0 1516 1500 for i, x in enumerate(L): 1517 assert allclose(x.length, 2*s2)1518 assert allclose(x.normal, [s2, -s2])1519 assert allclose(sum(x.normal**2), 1)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) 1520 1504 1521 1505 assert x.triangle_id in intersected_triangles … … 1524 1508 1525 1509 msg = 'Segments do not add up' 1526 assert allclose(total_length, 4*s2), msg1510 assert numpy.allclose(total_length, 4*s2), msg 1527 1511 1528 1512 … … 1540 1524 total_length = 0 1541 1525 for i, x in enumerate(L): 1542 assert allclose(x.length, s2)1543 assert allclose(x.normal, [-s2, -s2])1544 assert allclose(sum(x.normal**2), 1)1526 assert numpy.allclose(x.length, s2) 1527 assert numpy.allclose(x.normal, [-s2, -s2]) 1528 assert numpy.allclose(sum(x.normal**2), 1) 1545 1529 1546 1530 assert x.triangle_id in intersected_triangles … … 1549 1533 1550 1534 msg = 'Segments do not add up' 1551 assert allclose(total_length, 2*s2), msg1535 assert numpy.allclose(total_length, 2*s2), msg 1552 1536 1553 1537 … … 1562 1546 total_length = 0 1563 1547 for i, x in enumerate(L): 1564 assert allclose(x.normal, [-s2, -s2])1565 assert allclose(sum(x.normal**2), 1)1548 assert numpy.allclose(x.normal, [-s2, -s2]) 1549 assert numpy.allclose(sum(x.normal**2), 1) 1566 1550 1567 1551 msg = 'Triangle %d' %x.triangle_id + ' is not in %s' %(intersected_triangles) … … 1598 1582 assert len(L) == 1 1599 1583 assert L[0].triangle_id == 3 1600 assert allclose(L[0].length, 0.5)1601 assert allclose(L[0].normal, [-1,0])1584 assert numpy.allclose(L[0].length, 0.5) 1585 assert numpy.allclose(L[0].normal, [-1,0]) 1602 1586 1603 1587 … … 1610 1594 assert len(L) == 1 1611 1595 assert L[0].triangle_id == 3 1612 assert allclose(L[0].length, 0.4)1613 assert allclose(L[0].normal, [-1,0])1596 assert numpy.allclose(L[0].length, 0.4) 1597 assert numpy.allclose(L[0].normal, [-1,0]) 1614 1598 1615 1599 intersected_triangles = [3] … … 1623 1607 assert len(L) == 1 1624 1608 assert L[0].triangle_id == 3 1625 assert allclose(L[0].length, 0.4)1626 assert allclose(L[0].normal, [1,0])1609 assert numpy.allclose(L[0].length, 0.4) 1610 assert numpy.allclose(L[0].normal, [1,0]) 1627 1611 1628 1612 … … 1658 1642 for x in L: 1659 1643 if x.triangle_id == 3: 1660 assert allclose(x.length, 0.5)1661 assert allclose(x.normal, [-1,0])1644 assert numpy.allclose(x.length, 0.5) 1645 assert numpy.allclose(x.normal, [-1,0]) 1662 1646 1663 1647 if x.triangle_id == 2: 1664 assert allclose(x.length, s2)1665 assert allclose(x.normal, [-s2,-s2])1648 assert numpy.allclose(x.length, s2) 1649 assert numpy.allclose(x.normal, [-s2,-s2]) 1666 1650 1667 1651 … … 1696 1680 for x in L: 1697 1681 if x.triangle_id == 3: 1698 assert allclose(x.length, 0.5)1699 assert allclose(x.normal, [-1,0])1682 assert numpy.allclose(x.length, 0.5) 1683 assert numpy.allclose(x.normal, [-1,0]) 1700 1684 1701 1685 if x.triangle_id == 2: 1702 1686 msg = str(x.length) 1703 assert allclose(x.length, s2), msg1704 assert allclose(x.normal, [-s2,-s2])1687 assert numpy.allclose(x.length, s2), msg 1688 assert numpy.allclose(x.normal, [-s2,-s2]) 1705 1689 1706 1690 if x.triangle_id == 5: 1707 segvec = array([line[2][0]-1,1708 line[2][1]-1])1691 segvec = numpy.array([line[2][0]-1, 1692 line[2][1]-1]) 1709 1693 msg = str(x.length) 1710 assert allclose(x.length, sqrt(sum(segvec**2))), msg1711 assert allclose(x.normal, [-s2,-s2])1694 assert numpy.allclose(x.length, sqrt(sum(segvec**2))), msg 1695 assert numpy.allclose(x.normal, [-s2,-s2]) 1712 1696 1713 1697 … … 1747 1731 for x in L: 1748 1732 if x.triangle_id == 3: 1749 assert allclose(x.length, 0.5)1750 assert allclose(x.normal, [-1,0])1733 assert numpy.allclose(x.length, 0.5) 1734 assert numpy.allclose(x.normal, [-1,0]) 1751 1735 1752 1736 if x.triangle_id == 2: 1753 1737 msg = str(x.length) 1754 assert allclose(x.length, s2), msg1755 assert allclose(x.normal, [-s2,-s2])1738 assert numpy.allclose(x.length, s2), msg 1739 assert numpy.allclose(x.normal, [-s2,-s2]) 1756 1740 1757 1741 if x.triangle_id == 5: 1758 1742 if x.segment == ((1.0, 1.0), (1.25, 0.75)): 1759 segvec = array([line[2][0]-1,1760 line[2][1]-1])1743 segvec = numpy.array([line[2][0]-1, 1744 line[2][1]-1]) 1761 1745 msg = str(x.length) 1762 assert allclose(x.length, sqrt(sum(segvec**2))), msg1763 assert allclose(x.normal, [-s2,-s2])1746 assert numpy.allclose(x.length, sqrt(sum(segvec**2))), msg 1747 assert numpy.allclose(x.normal, [-s2,-s2]) 1764 1748 elif x.segment == ((1.25, 0.75), (1.5, 1.0)): 1765 segvec = array([1.5-line[2][0],1766 1.0-line[2][1]])1749 segvec = numpy.array([1.5-line[2][0], 1750 1.0-line[2][1]]) 1767 1751 1768 assert allclose(x.length, sqrt(sum(segvec**2))), msg1769 assert allclose(x.normal, [s2,-s2])1752 assert numpy.allclose(x.length, sqrt(sum(segvec**2))), msg 1753 assert numpy.allclose(x.normal, [s2,-s2]) 1770 1754 else: 1771 1755 msg = 'Unknow segment: %s' %x.segment … … 1775 1759 1776 1760 if x.triangle_id == 6: 1777 assert allclose(x.normal, [s2,-s2])1778 assert allclose(x.segment, ((1.5, 1.0), (2, 1.5)))1761 assert numpy.allclose(x.normal, [s2,-s2]) 1762 assert numpy.allclose(x.segment, ((1.5, 1.0), (2, 1.5))) 1779 1763 1780 1764 … … 1842 1826 ref_length = line[1][1] - line[0][1] 1843 1827 #print ref_length, total_length 1844 assert allclose(total_length, ref_length)1828 assert numpy.allclose(total_length, ref_length) 1845 1829 1846 1830 -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_pmesh2domain.py
r3563 r5892 3 3 4 4 import unittest 5 6 from Numeric import allclose, array 7 5 import numpy 8 6 9 7 #from anuga.pyvolution.pmesh2domain import * … … 66 64 67 65 tags = {} 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]))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])) 71 69 tags["1"] = b1 72 70 tags["2"] = b2 … … 80 78 answer = [[0., 8., 0.], 81 79 [0., 10., 8.]] 82 assert allclose(domain.quantities['elevation'].vertex_values,83 answer)80 assert numpy.allclose(domain.quantities['elevation'].vertex_values, 81 answer) 84 82 85 83 #print domain.quantities['stage'].vertex_values 86 84 answer = [[0., 12., 10.], 87 85 [0., 10., 12.]] 88 assert allclose(domain.quantities['stage'].vertex_values,89 answer)86 assert numpy.allclose(domain.quantities['stage'].vertex_values, 87 answer) 90 88 91 89 #print domain.quantities['friction'].vertex_values 92 90 answer = [[0.01, 0.04, 0.03], 93 91 [0.01, 0.02, 0.04]] 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)92 assert numpy.allclose(domain.quantities['friction'].vertex_values, 93 answer) 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) 100 98 101 99 self.failUnless( domain.boundary[(1, 0)] == '1', … … 159 157 160 158 tags = {} 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]))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])) 164 162 tags["1"] = b1 165 163 tags["2"] = b2 … … 174 172 answer = [[0., 8., 0.], 175 173 [0., 10., 8.]] 176 assert allclose(domain.quantities['elevation'].vertex_values,177 answer)174 assert numpy.allclose(domain.quantities['elevation'].vertex_values, 175 answer) 178 176 179 177 #print domain.quantities['stage'].vertex_values 180 178 answer = [[0., 12., 10.], 181 179 [0., 10., 12.]] 182 assert allclose(domain.quantities['stage'].vertex_values,183 answer)180 assert numpy.allclose(domain.quantities['stage'].vertex_values, 181 answer) 184 182 185 183 #print domain.quantities['friction'].vertex_values 186 184 answer = [[0.01, 0.04, 0.03], 187 185 [0.01, 0.02, 0.04]] 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)186 assert numpy.allclose(domain.quantities['friction'].vertex_values, 187 answer) 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) 194 192 195 193 self.failUnless( domain.boundary[(1, 0)] == '1', … … 228 226 #domain.set_tag_dict(tag_dict) 229 227 #Boundary tests 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]))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])) 233 231 #test adding a boundary 234 232 tags = {} -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py
r5776 r5892 7 7 from quantity import * 8 8 from anuga.config import epsilon 9 from Numeric import allclose, array, ones, Float 9 import numpy 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 = array(point)20 point = numpy.array(point) 21 21 return point[:,0]+point[:,1] 22 22 … … 63 63 64 64 quantity = Quantity(self.mesh1, [[1,2,3]]) 65 assert allclose(quantity.vertex_values, [[1.,2.,3.]])65 assert numpy.allclose(quantity.vertex_values, [[1.,2.,3.]]) 66 66 67 67 try: … … 84 84 85 85 quantity = Quantity(self.mesh1) 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.],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.], 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 allclose(quantity.centroid_values, [2.0]) #Centroid97 98 assert allclose(quantity.edge_values, [[2.5, 2.0, 1.5]])96 assert numpy.allclose(quantity.centroid_values, [2.0]) #Centroid 97 98 assert numpy.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 allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroid104 assert numpy.allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroid 105 105 106 106 … … 108 108 109 109 #print quantity.vertex_values 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]])110 assert numpy.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 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]])116 assert numpy.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 numpy.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 allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroids130 assert numpy.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 allclose(v, 5)150 assert numpy.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 allclose(v, 0)155 assert numpy.allclose(v, 0) 156 156 157 157 … … 192 192 193 193 v = quantity.get_values(interpolation_points = [[x,y]]) 194 assert allclose(v, 6)194 assert numpy.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 allclose(v, 2)198 assert numpy.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 allclose(v, 4)203 assert numpy.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 allclose(v, 4)214 assert numpy.allclose(v, 4) 215 215 216 216 # More test of indices...... 217 217 v = quantity.get_maximum_value(indices=[2,3]) 218 assert allclose(v, 6)218 assert numpy.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 allclose(v, 6)229 assert numpy.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 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.]) #Centroid249 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]])246 assert numpy.allclose(quantity.vertex_values, 247 [[1,2,3], [5,5,5], [0,0,9], [-6, 3, 3]]) 248 assert numpy.allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroid 249 assert numpy.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 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.]) #Centroid260 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]])257 assert numpy.allclose(quantity.vertex_values, 258 [[1,2,3], [5,5,5], [0,0,9], [-6, 3, 3]]) 259 assert numpy.allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroid 260 assert numpy.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 allclose(quantity.centroid_values, [1., 2., 3., 4.]) #Centroid267 assert numpy.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 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]) #Centroid294 assert allclose(quantity.edge_values, [[1, 1, 1],295 [1, 1, 1],296 [1, 1, 1],297 [1, 1, 1]])290 assert numpy.allclose(quantity.vertex_values, 291 [[1,1,1], [1,1,1], [1,1,1], [1, 1, 1]]) 292 293 assert numpy.allclose(quantity.centroid_values, [1, 1, 1, 1]) #Centroid 294 assert numpy.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 allclose(quantity.centroid_values, [2, 2, 2, 2])301 assert numpy.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 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]])312 assert numpy.allclose(quantity.vertex_values, 313 [[2,0,2], [2,2,4], [4,2,4], [4,2,4]]) 314 assert numpy.allclose(quantity.centroid_values, 315 [4.0/3, 8.0/3, 10.0/3, 10.0/3]) 316 assert numpy.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 allclose(quantity.centroid_values,322 [4.0/3, 8.0/3, 10.0/3, 10.0/3])321 assert numpy.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 allclose(quantity.get_integral(), self.mesh4.get_area() * const)333 assert numpy.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 allclose (quantity.get_integral(), ref_integral)344 assert numpy.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 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]) #Centroid356 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]])352 assert numpy.allclose(quantity.vertex_values, 353 [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 354 assert numpy.allclose(quantity.centroid_values, 355 [1., 7./3, 11./3, 8./3]) #Centroid 356 assert numpy.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 allclose(quantity.vertex_values,368 [[1,0,20], [1,20,4], [4,20,50], [30,1,4]])367 assert numpy.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 allclose(quantity.vertex_values,379 [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])378 assert numpy.allclose(quantity.vertex_values, 379 [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 380 380 381 381 #Centroid 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]])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 [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 allclose(quantity.vertex_values,402 [[0,0,2], [0,2,0], [0,2,5], [3,0,0]])401 assert numpy.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 allclose(quantity.vertex_values,411 [[3.14,3.14,3.14], [0,0,0],412 [3.14,3.14,3.14], [0,0,0]])410 assert numpy.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 allclose(quantity.vertex_values,422 [[0,0,0], [0,0,0], [0,0,0],423 [3.14,3.14,3.14]])421 assert numpy.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 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]])431 assert numpy.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 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]])443 assert numpy.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 allclose(quantity.vertex_values,481 [[3.14,3.14,3.14], [0,0,0],482 [3.14,3.14,3.14], [0,0,0]])480 assert numpy.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 = array([[0,2.1], [4,2.1], [4,7], [0,7]])487 polygon = numpy.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 allclose(quantity.vertex_values,494 [[0,0,0], [0,0,0], [0,0,0],495 [3.14,3.14,3.14]])493 assert numpy.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 = array([[2.1, 0.0], [3.5,0.1], [2,2.2], [0.2,2]])499 polygon = numpy.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 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]])505 assert numpy.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 allclose(quantity.vertex_values.flat, answer)542 assert numpy.allclose(quantity.vertex_values.ravel(), answer) 543 543 544 544 … … 553 553 #print vertex_attributes 554 554 quantity.set_values(vertex_attributes) 555 assert allclose(quantity.vertex_values.flat, answer)555 assert numpy.allclose(quantity.vertex_values.ravel(), answer) 556 556 557 557 … … 593 593 alpha = 0) 594 594 595 assert allclose( ref, [0,5,5] )595 assert numpy.allclose( ref, [0,5,5] ) 596 596 597 597 … … 610 610 # data_georef = data_georef, 611 611 # alpha = 0) 612 assert allclose(quantity.vertex_values.flat, ref)612 assert numpy.allclose(quantity.vertex_values.ravel(), ref) 613 613 614 614 … … 621 621 622 622 quantity.set_values(geospatial_data = geo, alpha = 0) 623 assert allclose(quantity.vertex_values.flat, ref)623 assert numpy.allclose(quantity.vertex_values.ravel(), ref) 624 624 625 625 … … 666 666 answer = linear_function(quantity.domain.get_vertex_coordinates()) 667 667 668 #print quantity.vertex_values. flat668 #print quantity.vertex_values.ravel() 669 669 #print answer 670 670 671 671 672 assert allclose(quantity.vertex_values.flat, answer)672 assert numpy.allclose(quantity.vertex_values.ravel(), 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 allclose(quantity.vertex_values.flat, answer)677 assert numpy.allclose(quantity.vertex_values.ravel(), answer) 678 678 679 679 #Cleanup … … 730 730 #print self.mesh4.nodes 731 731 #print inside_polygon(self.mesh4.nodes, polygon) 732 assert allclose(inside_polygon(self.mesh4.nodes, polygon), 4)732 assert numpy.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. flat750 #print quantity.vertex_values.ravel() 751 751 #print answer 752 752 753 753 # Check vertices in polygon have been set 754 assert allclose(take(quantity.vertex_values.flat, indices),755 answer)754 assert numpy.allclose(take(quantity.vertex_values.ravel(), 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 allclose(take(quantity.vertex_values.flat, indices),761 0.0)760 assert numpy.allclose(take(quantity.vertex_values.ravel(), 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 allclose(quantity.vertex_values.flat, answer)817 assert numpy.allclose(quantity.vertex_values.ravel(), answer) 818 818 819 819 … … 821 821 quantity.set_values(filename=ptsfile, 822 822 alpha=0) 823 assert allclose(quantity.vertex_values.flat, answer)823 assert numpy.allclose(quantity.vertex_values.ravel(), answer) 824 824 825 825 # Check cache … … 866 866 answer = linear_function(quantity.domain.get_vertex_coordinates()) 867 867 868 #print "quantity.vertex_values. flat", quantity.vertex_values.flat868 #print "quantity.vertex_values.ravel()", quantity.vertex_values.ravel() 869 869 #print "answer",answer 870 870 871 assert allclose(quantity.vertex_values.flat, answer)871 assert numpy.allclose(quantity.vertex_values.ravel(), 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 allclose(quantity.vertex_values.flat, answer)876 assert numpy.allclose(quantity.vertex_values.ravel(), answer) 877 877 878 878 #Cleanup … … 910 910 answer = linear_function(quantity.domain.get_vertex_coordinates()) 911 911 912 #print "quantity.vertex_values. flat", quantity.vertex_values.flat912 #print "quantity.vertex_values.ravel()", quantity.vertex_values.ravel() 913 913 #print "answer",answer 914 914 915 assert allclose(quantity.vertex_values.flat, answer)915 assert numpy.allclose(quantity.vertex_values.ravel(), 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 allclose(quantity.vertex_values.flat, answer)920 assert numpy.allclose(quantity.vertex_values.ravel(), 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. flat", quantity.vertex_values.flat959 #print "quantity.vertex_values.ravel()", quantity.vertex_values.ravel() 960 960 #print "answer",answer 961 assert allclose(quantity.vertex_values.flat, answer)961 assert numpy.allclose(quantity.vertex_values.ravel(), 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. flat", quantity.vertex_values.flat967 #print "quantity.vertex_values.ravel()", quantity.vertex_values.ravel() 968 968 #print "answer",answer 969 assert allclose(quantity.vertex_values.flat, answer)969 assert numpy.allclose(quantity.vertex_values.ravel(), 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 allclose(quantity.vertex_values.flat, answer)974 assert numpy.allclose(quantity.vertex_values.ravel(), 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. flat", quantity.vertex_values.flat1041 #print "quantity.vertex_values.ravel()", quantity.vertex_values.ravel() 1042 1042 #print "answer",answer 1043 assert allclose(quantity.vertex_values.flat, answer)1043 assert numpy.allclose(quantity.vertex_values.ravel(), 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. flat", quantity.vertex_values.flat1049 #print "quantity.vertex_values.ravel()", quantity.vertex_values.ravel() 1050 1050 #print "answer",answer 1051 assert allclose(quantity.vertex_values.flat, answer)1051 assert numpy.allclose(quantity.vertex_values.ravel(), 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 allclose(quantity.vertex_values.flat, answer)1056 assert numpy.allclose(quantity.vertex_values.ravel(), answer) 1057 1057 1058 1058 #Cleanup … … 1128 1128 answer = linear_function(quantity.domain.get_vertex_coordinates()) 1129 1129 1130 assert allclose(quantity.vertex_values.flat, answer)1130 assert numpy.allclose(quantity.vertex_values.ravel(), 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 allclose(quantity.vertex_values.flat, answer)1135 assert numpy.allclose(quantity.vertex_values.ravel(), answer) 1136 1136 1137 1137 #Cleanup … … 1207 1207 1208 1208 1209 assert allclose(quantity.vertex_values.flat, answer)1209 assert numpy.allclose(quantity.vertex_values.ravel(), 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 allclose(quantity.vertex_values.flat, answer)1214 assert numpy.allclose(quantity.vertex_values.ravel(), answer) 1215 1215 1216 1216 #Cleanup … … 1226 1226 quantity1.set_vertex_values([0,1,2,3,4,5]) 1227 1227 1228 assert allclose(quantity1.vertex_values,1229 [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])1228 assert numpy.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 allclose(quantity2.vertex_values,1235 [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])1234 assert numpy.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 allclose(quantity2.vertex_values,1239 [[2,0,4], [2,4,8], [8,4,10], [6,2,8]])1238 assert numpy.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 allclose(quantity2.vertex_values,1243 [[5,3,7], [5,7,11], [11,7,13], [9,5,11]])1242 assert numpy.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 allclose(quantity2.vertex_values,1249 [[5,3,7], [5,7,11], [11,7,13], [9,5,11]])1248 assert numpy.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 allclose(inside_polygon(self.mesh4.nodes, polygon), 4)1264 assert numpy.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 allclose(quantity1.vertex_values,1270 [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])1269 assert numpy.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 allclose(quantity2.vertex_values,1279 [[0,0,0], [0,0,4], [4,0,0], [0,0,4]]), msg1280 #bac, bce, ecf, dbe1278 assert numpy.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 allclose(quantity1.vertex_values,1290 [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])1289 assert numpy.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 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)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) 1309 1309 1310 1310 # Addition 1311 1311 Q = quantity1 + 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)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) 1315 1315 1316 1316 Q = 7 + quantity1 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)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) 1320 1320 1321 1321 Q = quantity1 + quantity2 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)1322 assert numpy.allclose(Q.vertex_values, 1323 quantity1.vertex_values + quantity2.vertex_values) 1324 assert numpy.allclose(Q.centroid_values, 1325 quantity1.centroid_values + quantity2.centroid_values) 1326 assert numpy.allclose(Q.edge_values, 1327 quantity1.edge_values + quantity2.edge_values) 1328 1328 1329 1329 1330 1330 Q = quantity1 + quantity2 - 3 1331 assert allclose(Q.vertex_values,1332 quantity1.vertex_values + quantity2.vertex_values - 3)1331 assert numpy.allclose(Q.vertex_values, 1332 quantity1.vertex_values + quantity2.vertex_values - 3) 1333 1333 1334 1334 Q = quantity1 - quantity2 1335 assert allclose(Q.vertex_values,1336 quantity1.vertex_values - quantity2.vertex_values)1335 assert numpy.allclose(Q.vertex_values, 1336 quantity1.vertex_values - quantity2.vertex_values) 1337 1337 1338 1338 #Scaling 1339 1339 Q = quantity1*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)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) 1343 1343 Q = 3*quantity1 1344 assert allclose(Q.vertex_values, quantity1.vertex_values*3)1344 assert numpy.allclose(Q.vertex_values, quantity1.vertex_values*3) 1345 1345 1346 1346 #Multiplication … … 1351 1351 #print quantity2.centroid_values 1352 1352 1353 assert allclose(Q.vertex_values,1354 quantity1.vertex_values * quantity2.vertex_values)1353 assert numpy.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 allclose(Q.vertex_values,1359 4*quantity1.vertex_values + 2)1358 assert numpy.allclose(Q.vertex_values, 1359 4*quantity1.vertex_values + 2) 1360 1360 1361 1361 Q = quantity1*quantity2 + 2 1362 assert allclose(Q.vertex_values,1363 quantity1.vertex_values * quantity2.vertex_values + 2)1362 assert numpy.allclose(Q.vertex_values, 1363 quantity1.vertex_values * quantity2.vertex_values + 2) 1364 1364 1365 1365 Q = quantity1*quantity2 + quantity3 1366 assert allclose(Q.vertex_values,1367 quantity1.vertex_values * quantity2.vertex_values +1368 quantity3.vertex_values)1366 assert numpy.allclose(Q.vertex_values, 1367 quantity1.vertex_values * quantity2.vertex_values + 1368 quantity3.vertex_values) 1369 1369 Q = quantity1*quantity2 + 3*quantity3 1370 assert allclose(Q.vertex_values,1371 quantity1.vertex_values * quantity2.vertex_values +1372 3*quantity3.vertex_values)1370 assert numpy.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 allclose(Q.vertex_values,1375 quantity1.vertex_values * quantity2.vertex_values +1376 3*quantity3.vertex_values + 5)1374 assert numpy.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 allclose(Q.vertex_values,1380 quantity1.vertex_values * quantity2.vertex_values -1381 quantity3.vertex_values)1379 assert numpy.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 allclose(Q.vertex_values,1384 1.5*quantity1.vertex_values * quantity2.vertex_values -1385 3*quantity3.vertex_values + 5)1383 assert numpy.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 allclose(Q.vertex_values,1391 1.5*quantity1.vertex_values * quantity2.vertex_values -1392 3*quantity3.vertex_values + 5)1390 assert numpy.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 allclose(Q.vertex_values, quantity1.vertex_values**2)1397 assert numpy.allclose(Q.vertex_values, quantity1.vertex_values**2) 1398 1398 1399 1399 Q = quantity1**2 +quantity2**2 1400 assert allclose(Q.vertex_values,1401 quantity1.vertex_values**2 + \1402 quantity2.vertex_values**2)1400 assert numpy.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 allclose(Q.vertex_values,1406 (quantity1.vertex_values**2 + \1407 quantity2.vertex_values**2)**0.5)1405 assert numpy.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 allclose(a[1], 2.0)1434 assert allclose(b[1], 0.0)1433 assert numpy.allclose(a[1], 2.0) 1434 assert numpy.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 allclose(a[0] + b[0], 3)1440 assert numpy.allclose(a[0] + b[0], 3) 1441 1441 #From orthogonality (a*(y0-y1) + b*(x0-x1) == 0) 1442 assert allclose(a[0] - b[0], 0)1442 assert numpy.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 allclose(2*a[2] - b[2], 3)1448 assert numpy.allclose(2*a[2] - b[2], 3) 1449 1449 #From orthogonality (a*(y1-y2) + b*(x2-x1) == 0) 1450 assert allclose(a[2] + 2*b[2], 0)1450 assert numpy.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 allclose(a[3] - 2*b[3], 3)1456 assert numpy.allclose(a[3] - 2*b[3], 3) 1457 1457 #From orthogonality (a*(y1-y3) + b*(x3-x1) == 0) 1458 assert allclose(2*a[3] + b[3], 0)1458 assert numpy.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 allclose(quantity.vertex_values[0,:], [3., 0., 3.])1467 assert allclose(quantity.vertex_values[1,:], [4./3, 16./3, 16./3])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]) 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 allclose(quantity.vertex_values[2,2], 8)1472 assert numpy.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 allclose(a[1], 2.0)1492 assert allclose(b[1], 0.0)1491 assert numpy.allclose(a[1], 2.0) 1492 assert numpy.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 allclose(a[0] + b[0], 3)1498 assert numpy.allclose(a[0] + b[0], 3) 1499 1499 #From orthogonality (a*(y0-y1) + b*(x0-x1) == 0) 1500 assert allclose(a[0] - b[0], 0)1500 assert numpy.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 allclose(2*a[2] - b[2], 3)1506 assert numpy.allclose(2*a[2] - b[2], 3) 1507 1507 #From orthogonality (a*(y1-y2) + b*(x2-x1) == 0) 1508 assert allclose(a[2] + 2*b[2], 0)1508 assert numpy.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 allclose(a[3] - 2*b[3], 3)1514 assert numpy.allclose(a[3] - 2*b[3], 3) 1515 1515 #From orthogonality (a*(y1-y3) + b*(x3-x1) == 0) 1516 assert allclose(2*a[3] + b[3], 0)1516 assert numpy.allclose(2*a[3] + b[3], 0) 1517 1517 1518 1518 … … 1532 1532 #print a, b 1533 1533 1534 assert allclose(a[1], 3.0)1535 assert allclose(b[1], 1.0)1534 assert numpy.allclose(a[1], 3.0) 1535 assert numpy.allclose(b[1], 1.0) 1536 1536 1537 1537 #Work out the others … … 1540 1540 1541 1541 #print quantity.vertex_values 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)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) 1545 1545 1546 1546 … … 1550 1550 1551 1551 #Set up for a gradient of (3,1), f(x) = 3x+y 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])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]) 1554 1554 quantity.set_values(c_values, location = 'centroids') 1555 1555 … … 1558 1558 1559 1559 #print quantity.vertex_values 1560 assert allclose(quantity.centroid_values, quantity.centroid_backup_values)1560 assert numpy.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 allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid1576 assert numpy.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 allclose(a, [0,0,0,0])1584 assert allclose(b, [0,0,0,0])1583 assert numpy.allclose(a, [0,0,0,0]) 1584 assert numpy.allclose(b, [0,0,0,0]) 1585 1585 1586 1586 #Check vertices but not edge values 1587 assert allclose(quantity.vertex_values,1588 [[1,1,1], [2,2,2], [3,3,3], [4, 4, 4]])1587 assert numpy.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 sum1617 1616 for k in range(quantity.centroid_values.shape[0]): 1618 assert allclose (quantity.centroid_values[k],1619 sum(quantity.vertex_values[k,:])/3)1617 assert numpy.allclose (quantity.centroid_values[k], 1618 numpy.sum(quantity.vertex_values[k,:])/3) 1620 1619 1621 1620 … … 1646 1645 1647 1646 #Assert that quantities are conserved 1648 from Numeric import sum1649 1647 for k in range(quantity.centroid_values.shape[0]): 1650 assert allclose (quantity.centroid_values[k],1651 sum(quantity.vertex_values[k,:])/3)1648 assert numpy.allclose (quantity.centroid_values[k], 1649 numpy.sum(quantity.vertex_values[k,:])/3) 1652 1650 1653 1651 … … 1676 1674 1677 1675 #Assert that quantities are conserved 1678 from Numeric import sum1679 1676 for k in range(quantity.centroid_values.shape[0]): 1680 assert allclose (quantity.centroid_values[k],1681 sum(quantity.vertex_values[k,:])/3)1677 assert numpy.allclose (quantity.centroid_values[k], 1678 numpy.sum(quantity.vertex_values[k,:])/3) 1682 1679 1683 1680 … … 1705 1702 1706 1703 #Assert that quantities are conserved 1707 from Numeric import sum1708 1704 for k in range(quantity.centroid_values.shape[0]): 1709 assert allclose (quantity.centroid_values[k],1710 sum(quantity.vertex_values[k,:])/3)1705 assert numpy.allclose (quantity.centroid_values[k], 1706 numpy.sum(quantity.vertex_values[k,:])/3) 1711 1707 1712 1708 def test_limiter2(self): … … 1718 1714 #Test centroids 1719 1715 quantity.set_values([2.,4.,8.,2.], location = 'centroids') 1720 assert allclose(quantity.centroid_values, [2, 4, 8, 2]) #Centroid1716 assert numpy.allclose(quantity.centroid_values, [2, 4, 8, 2]) #Centroid 1721 1717 1722 1718 … … 1724 1720 quantity.extrapolate_second_order() 1725 1721 1726 assert allclose(quantity.vertex_values[1,:], [0.0, 6, 6])1722 assert numpy.allclose(quantity.vertex_values[1,:], [0.0, 6, 6]) 1727 1723 1728 1724 #Limit … … 1731 1727 # limited value for beta_w = 0.9 1732 1728 1733 assert allclose(quantity.vertex_values[1,:], [2.2, 4.9, 4.9])1729 assert numpy.allclose(quantity.vertex_values[1,:], [2.2, 4.9, 4.9]) 1734 1730 # limited values for beta_w = 0.5 1735 #assert allclose(quantity.vertex_values[1,:], [3.0, 4.5, 4.5])1731 #assert numpy.allclose(quantity.vertex_values[1,:], [3.0, 4.5, 4.5]) 1736 1732 1737 1733 1738 1734 #Assert that quantities are conserved 1739 from Numeric import sum1740 1735 for k in range(quantity.centroid_values.shape[0]): 1741 assert allclose (quantity.centroid_values[k],1742 sum(quantity.vertex_values[k,:])/3)1736 assert numpy.allclose (quantity.centroid_values[k], 1737 numpy.sum(quantity.vertex_values[k,:])/3) 1743 1738 1744 1739 … … 1751 1746 #Test centroids 1752 1747 quantity.set_values([1.,2.,3.,4.], location = 'centroids') 1753 assert allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid1748 assert numpy.allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid 1754 1749 1755 1750 … … 1760 1755 #quantity.interpolate_from_vertices_to_edges() 1761 1756 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]])1757 assert numpy.allclose(quantity.vertex_values, 1758 [[1,1,1], [2,2,2], [3,3,3], [4, 4, 4]]) 1759 assert numpy.allclose(quantity.edge_values, [[1,1,1], [2,2,2], 1760 [3,3,3], [4, 4, 4]]) 1766 1761 1767 1762 … … 1769 1764 quantity = Quantity(self.mesh4) 1770 1765 1771 quantity.vertex_values = array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]],Float)1766 quantity.vertex_values = numpy.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]], numpy.float) 1772 1767 1773 1768 quantity.interpolate_from_vertices_to_edges() 1774 1769 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]])1770 assert numpy.allclose(quantity.edge_values, [[1., 1.5, 0.5], 1771 [3., 2.5, 1.5], 1772 [3.5, 4.5, 3.], 1773 [2.5, 3.5, 2]]) 1779 1774 1780 1775 … … 1782 1777 quantity = Quantity(self.mesh4) 1783 1778 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)1779 quantity.edge_values = numpy.array([[1., 1.5, 0.5], 1780 [3., 2.5, 1.5], 1781 [3.5, 4.5, 3.], 1782 [2.5, 3.5, 2]], numpy.float) 1788 1783 1789 1784 quantity.interpolate_from_edges_to_vertices() 1790 1785 1791 assert allclose(quantity.vertex_values,1792 [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])1786 assert numpy.allclose(quantity.vertex_values, 1787 [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 1793 1788 1794 1789 … … 1799 1794 #Test centroids 1800 1795 quantity.set_values([2.,4.,8.,2.], location = 'centroids') 1801 assert allclose(quantity.centroid_values, [2, 4, 8, 2]) #Centroid1796 assert numpy.allclose(quantity.centroid_values, [2, 4, 8, 2]) #Centroid 1802 1797 1803 1798 … … 1805 1800 quantity.extrapolate_second_order() 1806 1801 1807 assert allclose(quantity.vertex_values[1,:], [0.0, 6, 6])1802 assert numpy.allclose(quantity.vertex_values[1,:], [0.0, 6, 6]) 1808 1803 1809 1804 … … 1813 1808 #Test centroids 1814 1809 quantity.set_values([1.,2.,3.,4.], location = 'centroids') 1815 assert allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid1810 assert numpy.allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid 1816 1811 1817 1812 #Set explicit_update 1818 quantity.explicit_update = array( [1.,1.,1.,1.] )1813 quantity.explicit_update = numpy.array( [1.,1.,1.,1.] ) 1819 1814 1820 1815 #Update with given timestep 1821 1816 quantity.update(0.1) 1822 1817 1823 x = array([1, 2, 3, 4]) +array( [.1,.1,.1,.1] )1824 assert allclose( quantity.centroid_values, x)1818 x = numpy.array([1, 2, 3, 4]) + numpy.array( [.1,.1,.1,.1] ) 1819 assert numpy.allclose( quantity.centroid_values, x) 1825 1820 1826 1821 def test_update_semi_implicit(self): … … 1829 1824 #Test centroids 1830 1825 quantity.set_values([1.,2.,3.,4.], location = 'centroids') 1831 assert allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid1826 assert numpy.allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid 1832 1827 1833 1828 #Set semi implicit update 1834 quantity.semi_implicit_update = array([1.,1.,1.,1.])1829 quantity.semi_implicit_update = numpy.array([1.,1.,1.,1.]) 1835 1830 1836 1831 #Update with given timestep … … 1838 1833 quantity.update(timestep) 1839 1834 1840 sem = array([1.,1.,1.,1.])/array([1, 2, 3, 4])1841 denom = ones(4, Float)-timestep*sem1842 1843 x = array([1, 2, 3, 4])/denom1844 assert allclose( quantity.centroid_values, x)1835 sem = numpy.array([1.,1.,1.,1.])/numpy.array([1, 2, 3, 4]) 1836 denom = numpy.ones(4, numpy.float)-timestep*sem 1837 1838 x = numpy.array([1, 2, 3, 4])/denom 1839 assert numpy.allclose( quantity.centroid_values, x) 1845 1840 1846 1841 … … 1850 1845 #Test centroids 1851 1846 quantity.set_values([1.,2.,3.,4.], location = 'centroids') 1852 assert allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid1847 assert numpy.allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid 1853 1848 1854 1849 #Set explicit_update 1855 quantity.explicit_update = array( [4.,3.,2.,1.] )1850 quantity.explicit_update = numpy.array( [4.,3.,2.,1.] ) 1856 1851 1857 1852 #Set semi implicit update 1858 quantity.semi_implicit_update = array( [1.,1.,1.,1.] )1853 quantity.semi_implicit_update = numpy.array( [1.,1.,1.,1.] ) 1859 1854 1860 1855 #Update with given timestep … … 1862 1857 quantity.update(0.1) 1863 1858 1864 sem = array([1.,1.,1.,1.])/array([1, 2, 3, 4])1865 denom = ones(4, Float)-timestep*sem1866 1867 x = array([1., 2., 3., 4.])1859 sem = numpy.array([1.,1.,1.,1.])/numpy.array([1, 2, 3, 4]) 1860 denom = numpy.ones(4, numpy.float)-timestep*sem 1861 1862 x = numpy.array([1., 2., 3., 4.]) 1868 1863 x /= denom 1869 x += timestep* array( [4.0, 3.0, 2.0, 1.0] )1870 1871 assert allclose( quantity.centroid_values, x)1864 x += timestep*numpy.array( [4.0, 3.0, 2.0, 1.0] ) 1865 1866 assert numpy.allclose( quantity.centroid_values, x) 1872 1867 1873 1868 … … 1879 1874 from mesh_factory import rectangular 1880 1875 from shallow_water import Domain, Transmissive_boundary 1881 from Numeric import zeros, Float1882 1876 from anuga.utilities.numerical_tools import mean 1883 1877 … … 1906 1900 1907 1901 bed = domain.quantities['elevation'].vertex_values 1908 stage = zeros(bed.shape, Float)1902 stage = numpy.zeros(bed.shape, numpy.float) 1909 1903 1910 1904 h = 0.03 … … 1929 1923 1930 1924 #First four points 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)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) 1935 1929 1936 1930 #Center point 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)1931 assert numpy.allclose(A[4], (Q[0,1] + Q[1,2] + Q[2,0] +\ 1932 Q[5,0] + Q[6,2] + Q[7,1])/6) 1939 1933 1940 1934 1941 1935 #Check V 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])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]) 1950 1944 1951 1945 #Get smoothed stage with XY 1952 1946 X, Y, A1, V1 = stage.get_vertex_values(xy=True, smooth=True) 1953 1947 1954 assert allclose(A, A1)1955 assert allclose(V, V1)1948 assert numpy.allclose(A, A1) 1949 assert numpy.allclose(V, V1) 1956 1950 1957 1951 #Check XY 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)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) 1963 1957 1964 1958 … … 1969 1963 from mesh_factory import rectangular 1970 1964 from shallow_water import Domain, Transmissive_boundary 1971 from Numeric import zeros, Float1972 1965 from anuga.utilities.numerical_tools import mean 1973 1966 … … 1991 1984 1992 1985 bed = domain.quantities['elevation'].vertex_values 1993 stage = zeros(bed.shape, Float)1986 stage = numpy.zeros(bed.shape, numpy.float) 1994 1987 1995 1988 h = 0.03 … … 2005 1998 stage = domain.quantities['stage'] 2006 1999 A, V = stage.get_vertex_values(xy=False, smooth=False) 2007 Q = stage.vertex_values. flat2000 Q = stage.vertex_values.ravel() 2008 2001 2009 2002 for k in range(8): 2010 assert allclose(A[k], Q[k])2003 assert numpy.allclose(A[k], Q[k]) 2011 2004 2012 2005 … … 2021 2014 2022 2015 2023 assert allclose(A, A1)2024 assert allclose(V, V1)2016 assert numpy.allclose(A, A1) 2017 assert numpy.allclose(V, V1) 2025 2018 2026 2019 #Check XY 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)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) 2033 2026 2034 2027 … … 2038 2031 from mesh_factory import rectangular 2039 2032 from shallow_water import Domain 2040 from Numeric import zeros, Float2041 2033 2042 2034 #Create basic mesh … … 2054 2046 #print "quantity.centroid_values",quantity.centroid_values 2055 2047 2056 assert allclose(quantity.centroid_values, [1,7])2048 assert numpy.allclose(quantity.centroid_values, [1,7]) 2057 2049 2058 2050 quantity.set_array_values([15,20,25], indices = indices) 2059 assert allclose(quantity.centroid_values, [1,20])2051 assert numpy.allclose(quantity.centroid_values, [1,20]) 2060 2052 2061 2053 quantity.set_array_values([15,20,25], indices = indices) 2062 assert allclose(quantity.centroid_values, [1,20])2054 assert numpy.allclose(quantity.centroid_values, [1,20]) 2063 2055 2064 2056 def test_setting_some_vertex_values(self): … … 2068 2060 from mesh_factory import rectangular 2069 2061 from shallow_water import Domain 2070 from Numeric import zeros, Float2071 2062 2072 2063 #Create basic mesh … … 2087 2078 indices = indices) 2088 2079 #print "quantity.centroid_values",quantity.centroid_values 2089 assert allclose(quantity.centroid_values, [1,7,3,4,5,6])2080 assert numpy.allclose(quantity.centroid_values, [1,7,3,4,5,6]) 2090 2081 2091 2082 value = [7] … … 2095 2086 indices = indices) 2096 2087 #print "quantity.centroid_values",quantity.centroid_values 2097 assert allclose(quantity.centroid_values, [1,7,3,4,5,6])2088 assert numpy.allclose(quantity.centroid_values, [1,7,3,4,5,6]) 2098 2089 2099 2090 value = [[15,20,25]] 2100 2091 quantity.set_values(value, indices = indices) 2101 2092 #print "1 quantity.vertex_values",quantity.vertex_values 2102 assert allclose(quantity.vertex_values[1], value[0])2093 assert numpy.allclose(quantity.vertex_values[1], value[0]) 2103 2094 2104 2095 … … 2107 2098 quantity.set_values(values, indices = [0,1,5], location = 'centroids') 2108 2099 #print "2 quantity.vertex_values",quantity.vertex_values 2109 assert allclose(quantity.vertex_values[0], [10,10,10])2110 assert allclose(quantity.vertex_values[5], [50,50,50])2100 assert numpy.allclose(quantity.vertex_values[0], [10,10,10]) 2101 assert numpy.allclose(quantity.vertex_values[5], [50,50,50]) 2111 2102 #quantity.interpolate() 2112 2103 #print "quantity.centroid_values",quantity.centroid_values 2113 assert allclose(quantity.centroid_values, [10,100,3,4,5,50])2104 assert numpy.allclose(quantity.centroid_values, [10,100,3,4,5,50]) 2114 2105 2115 2106 … … 2121 2112 quantity.set_values(values, indices = [0,1,5]) 2122 2113 #print "quantity.vertex_values",quantity.vertex_values 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])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]) 2126 2117 2127 2118 quantity = Quantity(domain,[[1,1,1],[2,2,2],[3,3,3], … … 2130 2121 quantity.set_values(values, indices = [3,3,5]) 2131 2122 quantity.interpolate() 2132 assert allclose(quantity.centroid_values, [1,2,3,400,5,999])2123 assert numpy.allclose(quantity.centroid_values, [1,2,3,400,5,999]) 2133 2124 2134 2125 values = [[1,1,1],[2,2,2],[3,3,3], … … 2142 2133 quantity.set_values(values) 2143 2134 #print "1 quantity.vertex_values",quantity.vertex_values 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.]])2135 assert numpy.allclose(quantity.vertex_values,[[ 4., 5., 0.], 2136 [ 1., 0., 5.], 2137 [ 5., 6., 1.], 2138 [ 2., 1., 6.], 2139 [ 6., 7., 2.], 2140 [ 3., 2., 7.]]) 2150 2141 2151 2142 def test_setting_unique_vertex_values(self): … … 2155 2146 from mesh_factory import rectangular 2156 2147 from shallow_water import Domain 2157 from Numeric import zeros, Float2158 2148 2159 2149 #Create basic mesh … … 2171 2161 indices = indices) 2172 2162 #print "quantity.centroid_values",quantity.centroid_values 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])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]) 2176 2166 2177 2167 … … 2182 2172 from mesh_factory import rectangular 2183 2173 from shallow_water import Domain 2184 from Numeric import zeros, Float2185 2174 2186 2175 #Create basic mesh … … 2205 2194 2206 2195 answer = [0.5,2,4,5,0,1,3,4.5] 2207 assert allclose(answer,2208 quantity.get_values(location = 'unique vertices'))2196 assert numpy.allclose(answer, 2197 quantity.get_values(location = 'unique vertices')) 2209 2198 2210 2199 indices = [0,5,3] 2211 2200 answer = [0.5,1,5] 2212 assert allclose(answer,2213 quantity.get_values(indices=indices, \2214 location = 'unique vertices'))2201 assert numpy.allclose(answer, 2202 quantity.get_values(indices=indices, 2203 location = 'unique vertices')) 2215 2204 #print "quantity.centroid_values",quantity.centroid_values 2216 2205 #print "quantity.get_values(location = 'centroids') ",\ … … 2241 2230 quantity.set_values(lambda x, y: x+2*y) #2 4 4 6 2242 2231 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]])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 [4,2,6], 2238 [6,2,4], 2239 [8,4,6]]) 2240 2241 assert numpy.allclose(quantity.get_values(location='vertices', indices=[1,3]), [[4,2,6], 2242 [8,4,6]]) 2243 2244 2245 assert numpy.allclose(quantity.get_values(location='edges'), [[1,3,2], 2246 [4,5,3], 2247 [3,5,4], 2248 [5,7,6]]) 2249 assert numpy.allclose(quantity.get_values(location='edges', indices=[1,3]), 2250 [[4,5,3], 2251 [5,7,6]]) 2263 2252 2264 2253 # Check averaging over vertices … … 2280 2269 from mesh_factory import rectangular 2281 2270 from shallow_water import Domain 2282 from Numeric import zeros, Float2283 2271 2284 2272 #Create basic mesh … … 2298 2286 2299 2287 #print quantity.get_values(points=interpolation_points) 2300 assert allclose(answer, quantity.get_values(interpolation_points=interpolation_points))2288 assert numpy.allclose(answer, quantity.get_values(interpolation_points=interpolation_points)) 2301 2289 2302 2290 … … 2311 2299 #print answer 2312 2300 #print quantity.get_values(interpolation_points=interpolation_points) 2313 assert allclose(answer, quantity.get_values(interpolation_points=interpolation_points,2314 verbose=False))2301 assert numpy.allclose(answer, quantity.get_values(interpolation_points=interpolation_points, 2302 verbose=False)) 2315 2303 2316 2304 … … 2318 2306 #indices = [0,5,3] 2319 2307 #answer = [0.5,1,5] 2320 #assert allclose(answer,2321 # quantity.get_values(indices=indices, \2322 # location = 'unique vertices'))2308 #assert numpy.allclose(answer, 2309 # quantity.get_values(indices=indices, 2310 # location = 'unique vertices')) 2323 2311 2324 2312 … … 2345 2333 x, y = 2.0/3, 8.0/3 2346 2334 v = quantity.get_values(interpolation_points = [[x,y]]) 2347 assert allclose(v, 6)2335 assert numpy.allclose(v, 6) 2348 2336 2349 2337 # Then another to test that algorithm won't blindly … … 2351 2339 x, y = 4.0/3, 4.0/3 2352 2340 v = quantity.get_values(interpolation_points = [[x,y]]) 2353 assert allclose(v, 4)2341 assert numpy.allclose(v, 4) 2354 2342 2355 2343 … … 2380 2368 x, y = 2.0/3, 8.0/3 2381 2369 v = quantity.get_values(interpolation_points = [[x+xllcorner,y+yllcorner]]) 2382 assert allclose(v, 6)2370 assert numpy.allclose(v, 6) 2383 2371 2384 2372 … … 2387 2375 x, y = 4.0/3, 4.0/3 2388 2376 v = quantity.get_values(interpolation_points = [[x+xllcorner,y+yllcorner]]) 2389 assert allclose(v, 4)2377 assert numpy.allclose(v, 4) 2390 2378 2391 2379 # Try two points … … 2393 2381 [4.0/3 + xllcorner, 4.0/3 + yllcorner]] 2394 2382 v = quantity.get_values(interpolation_points=pts) 2395 assert allclose(v, [6, 4])2383 assert numpy.allclose(v, [6, 4]) 2396 2384 2397 2385 # Test it using the geospatial data format with absolute input points and default georef 2398 2386 pts = Geospatial_data(data_points=pts) 2399 2387 v = quantity.get_values(interpolation_points=pts) 2400 assert allclose(v, [6, 4])2388 assert numpy.allclose(v, [6, 4]) 2401 2389 2402 2390 … … 2405 2393 geo_reference=Geo_reference(zone,xllcorner,yllcorner)) 2406 2394 v = quantity.get_values(interpolation_points=pts) 2407 assert allclose(v, [6, 4])2395 assert numpy.allclose(v, [6, 4]) 2408 2396 2409 2397 … … 2416 2404 from mesh_factory import rectangular 2417 2405 from shallow_water import Domain 2418 from Numeric import zeros, Float2419 2406 2420 2407 #Create basic mesh … … 2438 2425 #print "quantity.get_values(location = 'centroids') ",\ 2439 2426 # quantity.get_values(location = 'centroids') 2440 assert allclose(quantity.centroid_values,2441 quantity.get_values(location = 'centroids'))2427 assert numpy.allclose(quantity.centroid_values, 2428 quantity.get_values(location = 'centroids')) 2442 2429 2443 2430 … … 2445 2432 quantity.set_values(value, indices = indices) 2446 2433 #print "1 quantity.vertex_values",quantity.vertex_values 2447 assert allclose(quantity.vertex_values, quantity.get_values())2448 2449 assert allclose(quantity.edge_values,2450 quantity.get_values(location = 'edges'))2434 assert numpy.allclose(quantity.vertex_values, quantity.get_values()) 2435 2436 assert numpy.allclose(quantity.edge_values, 2437 quantity.get_values(location = 'edges')) 2451 2438 2452 2439 # get a subset of elements 2453 2440 subset = quantity.get_values(location='centroids', indices=[0,5]) 2454 2441 answer = [quantity.centroid_values[0],quantity.centroid_values[5]] 2455 assert allclose(subset, answer)2442 assert numpy.allclose(subset, answer) 2456 2443 2457 2444 … … 2460 2447 #print "subset",subset 2461 2448 #print "answer",answer 2462 assert allclose(subset, answer)2449 assert numpy.allclose(subset, answer) 2463 2450 2464 2451 subset = quantity.get_values( indices=[1,5]) … … 2466 2453 #print "subset",subset 2467 2454 #print "answer",answer 2468 assert allclose(subset, answer)2455 assert numpy.allclose(subset, answer) 2469 2456 2470 2457 def test_smooth_vertex_values(self): … … 2474 2461 from mesh_factory import rectangular 2475 2462 from shallow_water import Domain 2476 from Numeric import zeros, Float2477 2463 2478 2464 #Create basic mesh … … 2501 2487 2502 2488 #answer = [0.5, 2, 3, 3, 3.5, 4, 4, 5, 6.5] 2503 #assert allclose(answer,2504 # quantity.get_values(location = 'unique vertices'))2489 #assert numpy.allclose(answer, 2490 # quantity.get_values(location = 'unique vertices')) 2505 2491 2506 2492 quantity.smooth_vertex_values() … … 2512 2498 [4,5,3],[3.5,3,5],[5,6.5,3.5],[4,3.5,6.5]] 2513 2499 2514 assert allclose(answer_vertex_values,2515 quantity.vertex_values)2500 assert numpy.allclose(answer_vertex_values, 2501 quantity.vertex_values) 2516 2502 #print "quantity.centroid_values",quantity.centroid_values 2517 2503 #print "quantity.get_values(location = 'centroids') ",\ … … 2522 2508 #------------------------------------------------------------- 2523 2509 if __name__ == "__main__": 2524 suite = unittest.makeSuite(Test_Quantity, 'test') 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') 2510 # suite = unittest.makeSuite(Test_Quantity, 'test') 2511 suite = unittest.makeSuite(Test_Quantity, 'test_get_extrema_1') 2530 2512 runner = unittest.TextTestRunner() 2531 2513 runner.run(suite) -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_region.py
r5211 r5892 6 6 from domain import * 7 7 from region import * 8 #from anuga.config import epsilon 9 from Numeric import allclose, average #, array, ones, Float 8 import numpy 9 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, Float47 46 48 47 #Create basic mesh … … 64 63 domain.set_region([a, b]) 65 64 #print domain.quantities['friction'].get_values() 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]])65 assert numpy.allclose(domain.quantities['friction'].get_values(), 66 [[ 0.09, 0.09, 0.09], 67 [ 0.09, 0.09, 0.09], 68 [ 0.07, 0.07, 0.07], 69 [ 0.07, 0.07, 0.07], 70 [ 1.0, 1.0, 1.0], 71 [ 1.0, 1.0, 1.0]]) 73 72 74 73 #c = Add_Value_To_region('all', 'friction', 10.0) 75 74 domain.set_region(Add_value_to_region('all', 'friction', 10.0)) 76 75 #print domain.quantities['friction'].get_values() 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]])76 assert numpy.allclose(domain.quantities['friction'].get_values(), 77 [[ 10.09, 10.09, 10.09], 78 [ 10.09, 10.09, 10.09], 79 [ 10.07, 10.07, 10.07], 80 [ 10.07, 10.07, 10.07], 81 [ 11.0, 11.0, 11.0], 82 [ 11.0, 11.0, 11.0]]) 84 83 85 84 # trying a function 86 85 domain.set_region(Set_region('top', 'friction', add_x_y)) 87 86 #print domain.quantities['friction'].get_values() 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]])87 assert numpy.allclose(domain.quantities['friction'].get_values(), 88 [[ 10.09, 10.09, 10.09], 89 [ 10.09, 10.09, 10.09], 90 [ 10.07, 10.07, 10.07], 91 [ 10.07, 10.07, 10.07], 92 [ 5./3, 2.0, 2./3], 93 [ 1.0, 2./3, 2.0]]) 95 94 96 95 domain.set_quantity('elevation', 10.0) … … 98 97 domain.set_region(Add_value_to_region('top', 'stage', 1.0,initial_quantity='elevation')) 99 98 #print domain.quantities['stage'].get_values() 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]])99 assert numpy.allclose(domain.quantities['stage'].get_values(), 100 [[ 10., 10., 10.], 101 [ 10., 10., 10.], 102 [ 10., 10., 10.], 103 [ 10., 10., 10.], 104 [ 11.0, 11.0, 11.0], 105 [ 11.0, 11.0, 11.0]]) 107 106 108 107 … … 115 114 domain.set_region(Add_quantities('top', 'elevation','stage')) 116 115 #print domain.quantities['stage'].get_values() 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.]])116 assert numpy.allclose(domain.quantities['elevation'].get_values(), 117 [[ 10., 10., 10.], 118 [ 10., 10., 10.], 119 [ 10., 10., 10.], 120 [ 10., 10., 10.], 121 [ 33., 33.0, 33.], 122 [ 33.0, 33., 33.]]) 124 123 125 124 def test_unique_vertices(self): … … 129 128 from mesh_factory import rectangular 130 129 from shallow_water import Domain 131 from Numeric import zeros, Float132 130 133 131 #Create basic mesh … … 147 145 domain.set_region(a) 148 146 #print domain.quantities['friction'].get_values() 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]])147 assert numpy.allclose(domain.quantities['friction'].get_values(),\ 148 [[ 0.09, 0.09, 0.09], 149 [ 0.09, 0.09, 0.09], 150 [ 0.09, 0.07, 0.09], 151 [ 0.07, 0.09, 0.07], 152 [ 0.07, 0.07, 0.07], 153 [ 0.07, 0.07, 0.07]]) 156 154 157 155 … … 162 160 from mesh_factory import rectangular 163 161 from shallow_water import Domain 164 from Numeric import zeros, Float165 162 166 163 #Create basic mesh … … 180 177 181 178 #print domain.quantities['friction'].get_values() 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]])179 assert numpy.allclose(domain.quantities['friction'].get_values(),\ 180 [[ 1.07, 1.07, 1.07], 181 [ 1.07, 1.07, 1.07], 182 [ 1.07, 0.07, 1.07], 183 [ 0.07, 1.07, 0.07], 184 [ 0.07, 0.07, 0.07], 185 [ 0.07, 0.07, 0.07]]) 189 186 190 187 def test_unique_vertices_average_loc_vert(self): … … 194 191 from mesh_factory import rectangular 195 192 from shallow_water import Domain 196 from Numeric import zeros, Float197 193 198 194 #Create basic mesh … … 218 214 #print domain.quantities['friction'].get_values() 219 215 frict_points = domain.quantities['friction'].get_values() 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])216 assert numpy.allclose(frict_points[0], 217 [ calc_frict, calc_frict, calc_frict]) 218 assert numpy.allclose(frict_points[1], 219 [ calc_frict, calc_frict, calc_frict]) 224 220 225 221 def test_unique_vertices_average_loc_unique_vert(self): … … 229 225 from mesh_factory import rectangular 230 226 from shallow_water import Domain 231 from Numeric import zeros, Float232 227 233 228 #Create basic mesh … … 252 247 #print domain.quantities['friction'].get_values() 253 248 frict_points = domain.quantities['friction'].get_values() 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])249 assert numpy.allclose(frict_points[0], 250 [ calc_frict, calc_frict, calc_frict]) 251 assert numpy.allclose(frict_points[1], 252 [ calc_frict, calc_frict, calc_frict]) 253 assert numpy.allclose(frict_points[2], 254 [ calc_frict, 1.0 + 2.0/3.0, calc_frict]) 255 assert numpy.allclose(frict_points[3], 256 [ 2.0/3.0,calc_frict, 1.0 + 2.0/3.0]) 262 257 263 258 … … 265 260 if __name__ == "__main__": 266 261 suite = unittest.makeSuite(Test_Region,'test') 262 ## suite = unittest.makeSuite(Test_Region,'test_unique_vertices_average_loc_unique_vert') 267 263 runner = unittest.TextTestRunner() 268 264 runner.run(suite) -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_util.py
r5657 r5892 1 1 #!/usr/bin/env python 2 2 3 4 3 import unittest 5 from Numeric import zeros, array, allclose, Float 4 import numpy 5 6 6 from math import sqrt, pi 7 7 import tempfile, os … … 91 91 92 92 #Exact linear intpolation 93 assert allclose(q[0], 2*t)93 assert numpy.allclose(q[0], 2*t) 94 94 if i%6 == 0: 95 assert allclose(q[1], t**2)96 assert allclose(q[2], sin(t*pi/600))95 assert numpy.allclose(q[1], t**2) 96 assert numpy.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 allclose( (120**2 + 60**2)/2, q[1] )103 assert allclose( (sin(120*pi/600) + sin(60*pi/600))/2, q[2] )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] ) 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 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] )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] ) 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, reshape128 127 129 128 #Create basic mesh and shallow water domain … … 148 147 149 148 # 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' 152 153 domain1.set_boundary({'left': B6, 'top': B6, 'right': B0, 'bottom': B0}) 153 154 domain1.check_integrity() 155 print 'test_util: 2' 154 156 155 157 finaltime = 8 156 158 #Evolution 157 159 t0 = -1 160 print 'test_util: 3' 161 # crash at following line 158 162 for t in domain1.evolve(yieldstep = 0.1, finaltime = finaltime): 163 print 'test_util: 4' 159 164 #print 'Timesteps: %.16f, %.16f' %(t0, t) 160 165 #if t == t0: … … 164 169 165 170 #domain1.write_time() 171 print 'test_util: 5' 166 172 167 173 … … 182 188 183 189 last_time_index = len(time)-1 #Last last_time_index 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)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) 188 194 189 195 #Reference interpolated values at midpoints on diagonal at … … 194 200 195 201 #And the midpoints are found now 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)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) 200 206 d_midpoints = (diag[1:] + diag[:-1])/2 201 207 … … 209 215 assert not T[-1] == T[-2], msg 210 216 t = time[last_time_index] 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)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) 214 220 215 221 … … 218 224 219 225 timestep = 0 #First timestep 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)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) 224 230 225 231 #Reference interpolated values at midpoints on diagonal at … … 231 237 #Let us see if the file function can find the correct 232 238 #values 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)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) 236 242 237 243 … … 240 246 241 247 timestep = 33 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)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) 246 252 247 253 #Reference interpolated values at midpoints on diagonal at … … 251 257 r2 = (D[2] + D[3])/2 252 258 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)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) 256 262 257 263 … … 261 267 262 268 timestep = 15 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)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) 267 273 268 274 #Reference interpolated values at midpoints on diagonal at … … 274 280 # 275 281 timestep = 16 276 d_stage = reshape(take(stage[timestep, :], [0,5,10,15]), (4,1))277 d_uh = reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1))278 d_vh = reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1))279 D = concatenate( (d_stage, d_uh, d_vh), axis=1)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_uh, d_vh), axis=1) 280 286 281 287 #Reference interpolated values at midpoints on diagonal at … … 290 296 r2 = (r2_0 + r2_1)/2 291 297 292 q = f((timestep - 0.5)/10., point_id=0); assert allclose(r0, q)293 q = f((timestep - 0.5)/10., point_id=1); assert allclose(r1, q)294 q = f((timestep - 0.5)/10., point_id=2); assert allclose(r2, q)298 q = f((timestep - 0.5)/10., point_id=0); assert numpy.allclose(r0, q) 299 q = f((timestep - 0.5)/10., point_id=1); assert numpy.allclose(r1, q) 300 q = f((timestep - 0.5)/10., point_id=2); assert numpy.allclose(r2, q) 295 301 296 302 ################## … … 304 310 305 311 #And the file function gives 306 q = f((timestep - 1.0/3)/10., point_id=0); assert allclose(r0, q)307 q = f((timestep - 1.0/3)/10., point_id=1); assert allclose(r1, q)308 q = f((timestep - 1.0/3)/10., point_id=2); assert allclose(r2, q)312 q = f((timestep - 1.0/3)/10., point_id=0); assert numpy.allclose(r0, q) 313 q = f((timestep - 1.0/3)/10., point_id=1); assert numpy.allclose(r1, q) 314 q = f((timestep - 1.0/3)/10., point_id=2); assert numpy.allclose(r2, q) 309 315 310 316 fid.close() … … 326 332 from shallow_water import Domain, Dirichlet_boundary 327 333 from mesh_factory import rectangular 328 from Numeric import take, concatenate, reshape329 334 330 335 … … 386 391 387 392 last_time_index = len(time)-1 #Last last_time_index 388 d_stage = reshape(take(stage[last_time_index, :], [0,5,10,15]), (4,1))389 d_uh = reshape(take(xmomentum[last_time_index, :], [0,5,10,15]), (4,1))390 d_vh = reshape(take(ymomentum[last_time_index, :], [0,5,10,15]), (4,1))391 D = concatenate( (d_stage, d_uh, d_vh), axis=1)393 d_stage = numpy.reshape(take(stage[last_time_index, :], [0,5,10,15]), (4,1)) 394 d_uh = numpy.reshape(take(xmomentum[last_time_index, :], [0,5,10,15]), (4,1)) 395 d_vh = numpy.reshape(take(ymomentum[last_time_index, :], [0,5,10,15]), (4,1)) 396 D = numpy.concatenate( (d_stage, d_uh, d_vh), axis=1) 392 397 393 398 #Reference interpolated values at midpoints on diagonal at … … 398 403 399 404 #And the midpoints are found now 400 Dx = take( reshape(x, (16,1)), [0,5,10,15])401 Dy = take( reshape(y, (16,1)), [0,5,10,15])402 403 diag = concatenate( (Dx, Dy), axis=1)405 Dx = take(numpy.reshape(x, (16,1)), [0,5,10,15]) 406 Dy = take(numpy.reshape(y, (16,1)), [0,5,10,15]) 407 408 diag = numpy.concatenate( (Dx, Dy), axis=1) 404 409 d_midpoints = (diag[1:] + diag[:-1])/2 405 410 … … 415 420 416 421 t = time[last_time_index] 417 q = f(t, point_id=0); assert allclose(r0, q)418 q = f(t, point_id=1); assert allclose(r1, q)419 q = f(t, point_id=2); assert allclose(r2, q)422 q = f(t, point_id=0); assert numpy.allclose(r0, q) 423 q = f(t, point_id=1); assert numpy.allclose(r1, q) 424 q = f(t, point_id=2); assert numpy.allclose(r2, q) 420 425 421 426 … … 424 429 425 430 timestep = 0 #First timestep 426 d_stage = reshape(take(stage[timestep, :], [0,5,10,15]), (4,1))427 d_uh = reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1))428 d_vh = reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1))429 D = concatenate( (d_stage, d_uh, d_vh), axis=1)431 d_stage = numpy.reshape(take(stage[timestep, :], [0,5,10,15]), (4,1)) 432 d_uh = numpy.reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1)) 433 d_vh = numpy.reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1)) 434 D = numpy.concatenate( (d_stage, d_uh, d_vh), axis=1) 430 435 431 436 #Reference interpolated values at midpoints on diagonal at … … 437 442 #Let us see if the file function can find the correct 438 443 #values 439 q = f(0, point_id=0); assert allclose(r0, q)440 q = f(0, point_id=1); assert allclose(r1, q)441 q = f(0, point_id=2); assert allclose(r2, q)444 q = f(0, point_id=0); assert numpy.allclose(r0, q) 445 q = f(0, point_id=1); assert numpy.allclose(r1, q) 446 q = f(0, point_id=2); assert numpy.allclose(r2, q) 442 447 443 448 … … 446 451 447 452 timestep = 33 448 d_stage = reshape(take(stage[timestep, :], [0,5,10,15]), (4,1))449 d_uh = reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1))450 d_vh = reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1))451 D = concatenate( (d_stage, d_uh, d_vh), axis=1)453 d_stage = numpy.reshape(take(stage[timestep, :], [0,5,10,15]), (4,1)) 454 d_uh = numpy.reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1)) 455 d_vh = numpy.reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1)) 456 D = numpy.concatenate( (d_stage, d_uh, d_vh), axis=1) 452 457 453 458 #Reference interpolated values at midpoints on diagonal at … … 457 462 r2 = (D[2] + D[3])/2 458 463 459 q = f(timestep/10., point_id=0); assert allclose(r0, q)460 q = f(timestep/10., point_id=1); assert allclose(r1, q)461 q = f(timestep/10., point_id=2); assert allclose(r2, q)464 q = f(timestep/10., point_id=0); assert numpy.allclose(r0, q) 465 q = f(timestep/10., point_id=1); assert numpy.allclose(r1, q) 466 q = f(timestep/10., point_id=2); assert numpy.allclose(r2, q) 462 467 463 468 … … 467 472 468 473 timestep = 15 469 d_stage = reshape(take(stage[timestep, :], [0,5,10,15]), (4,1))470 d_uh = reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1))471 d_vh = reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1))472 D = concatenate( (d_stage, d_uh, d_vh), axis=1)474 d_stage = numpy.reshape(take(stage[timestep, :], [0,5,10,15]), (4,1)) 475 d_uh = numpy.reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1)) 476 d_vh = numpy.reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1)) 477 D = numpy.concatenate( (d_stage, d_uh, d_vh), axis=1) 473 478 474 479 #Reference interpolated values at midpoints on diagonal at … … 480 485 # 481 486 timestep = 16 482 d_stage = reshape(take(stage[timestep, :], [0,5,10,15]), (4,1))483 d_uh = reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1))484 d_vh = reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1))485 D = concatenate( (d_stage, d_uh, d_vh), axis=1)487 d_stage = numpy.reshape(take(stage[timestep, :], [0,5,10,15]), (4,1)) 488 d_uh = numpy.reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1)) 489 d_vh = numpy.reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1)) 490 D = numpy.concatenate( (d_stage, d_uh, d_vh), axis=1) 486 491 487 492 #Reference interpolated values at midpoints on diagonal at … … 496 501 r2 = (r2_0 + r2_1)/2 497 502 498 q = f((timestep - 0.5)/10., point_id=0); assert allclose(r0, q)499 q = f((timestep - 0.5)/10., point_id=1); assert allclose(r1, q)500 q = f((timestep - 0.5)/10., point_id=2); assert allclose(r2, q)503 q = f((timestep - 0.5)/10., point_id=0); assert numpy.allclose(r0, q) 504 q = f((timestep - 0.5)/10., point_id=1); assert numpy.allclose(r1, q) 505 q = f((timestep - 0.5)/10., point_id=2); assert numpy.allclose(r2, q) 501 506 502 507 ################## … … 510 515 511 516 #And the file function gives 512 q = f((timestep - 1.0/3)/10., point_id=0); assert allclose(r0, q)513 q = f((timestep - 1.0/3)/10., point_id=1); assert allclose(r1, q)514 q = f((timestep - 1.0/3)/10., point_id=2); assert allclose(r2, q)517 q = f((timestep - 1.0/3)/10., point_id=0); assert numpy.allclose(r0, q) 518 q = f((timestep - 1.0/3)/10., point_id=1); assert numpy.allclose(r1, q) 519 q = f((timestep - 1.0/3)/10., point_id=2); assert numpy.allclose(r2, q) 515 520 516 521 fid.close() … … 542 547 import os, time 543 548 from anuga.config import time_format 544 from Numeric import sin, pi, exp545 549 from mesh_factory import rectangular 546 550 from shallow_water import Domain … … 584 588 domain.set_quantity('xmomentum', f2) 585 589 586 f3 = lambda x,y: x**2 + y**2 * sin(t*pi/600)590 f3 = lambda x,y: x**2 + y**2 * numpy.sin(t*numpy.pi/600) 587 591 domain.set_quantity('ymomentum', f3) 588 592 … … 604 608 605 609 #Check that FF updates fixes domain starttime 606 assert allclose(domain.starttime, start)610 assert numpy.allclose(domain.starttime, start) 607 611 608 612 #Check that domain.starttime isn't updated if later … … 611 615 quantities = domain.conserved_quantities, 612 616 interpolation_points = interpolation_points) 613 assert allclose(domain.starttime, start+1)617 assert numpy.allclose(domain.starttime, start+1) 614 618 domain.starttime = start 615 619 … … 645 649 self.failUnless( q == actual, 'Fail!') 646 650 else: 647 assert allclose(q, actual)651 assert numpy.allclose(q, actual) 648 652 649 653 … … 655 659 t = 90 #Halfway between 60 and 120 656 660 q = F(t, point_id=id) 657 assert allclose( (q120+q60)/2, q )661 assert numpy.allclose( (q120+q60)/2, q ) 658 662 659 663 t = 100 #Two thirds of the way between between 60 and 120 660 664 q = F(t, point_id=id) 661 assert allclose(q60/3 + 2*q120/3, q)665 assert numpy.allclose(q60/3 + 2*q120/3, q) 662 666 663 667 … … 670 674 quantities = domain.conserved_quantities, 671 675 interpolation_points = interpolation_points) 672 assert allclose(domain.starttime, start+delta)676 assert numpy.allclose(domain.starttime, start+delta) 673 677 674 678 … … 689 693 690 694 q = F(t-delta, point_id=id) 691 assert allclose(q, (k*q1 + (6-k)*q0)/6)695 assert numpy.allclose(q, (k*q1 + (6-k)*q0)/6) 692 696 693 697 … … 703 707 import os, time 704 708 from anuga.config import time_format 705 from Numeric import sin, pi, exp706 709 from mesh_factory import rectangular 707 710 from shallow_water import Domain … … 751 754 domain.set_quantity('xmomentum', f2) 752 755 753 f3 = lambda x,y: x**2 + y**2 * sin(t*pi/600)756 f3 = lambda x,y: x**2 + y**2 * numpy.sin(t*numpy.pi/600) 754 757 domain.set_quantity('ymomentum', f3) 755 758 … … 774 777 775 778 #Check that FF updates fixes domain starttime 776 assert allclose(domain.starttime, start)779 assert numpy.allclose(domain.starttime, start) 777 780 778 781 #Check that domain.starttime isn't updated if later … … 781 784 quantities = domain.conserved_quantities, 782 785 interpolation_points = interpolation_points) 783 assert allclose(domain.starttime, start+1)786 assert numpy.allclose(domain.starttime, start+1) 784 787 domain.starttime = start 785 788 … … 817 820 self.failUnless( q == actual, 'Fail!') 818 821 else: 819 assert allclose(q, actual)822 assert numpy.allclose(q, actual) 820 823 821 824 # now lets check points inside the mesh … … 863 866 self.failUnless( q == actual, 'Fail!') 864 867 else: 865 assert allclose(q, actual)868 assert numpy.allclose(q, actual) 866 869 867 870 … … 873 876 t = 90 #Halfway between 60 and 120 874 877 q = F(t, point_id=id) 875 assert allclose( (q120+q60)/2, q )878 assert numpy.allclose( (q120+q60)/2, q ) 876 879 877 880 t = 100 #Two thirds of the way between between 60 and 120 878 881 q = F(t, point_id=id) 879 assert allclose(q60/3 + 2*q120/3, q)882 assert numpy.allclose(q60/3 + 2*q120/3, q) 880 883 881 884 … … 888 891 quantities = domain.conserved_quantities, 889 892 interpolation_points = interpolation_points) 890 assert allclose(domain.starttime, start+delta)893 assert numpy.allclose(domain.starttime, start+delta) 891 894 892 895 … … 907 910 908 911 q = F(t-delta, point_id=id) 909 assert allclose(q, (k*q1 + (6-k)*q0)/6)912 assert numpy.allclose(q, (k*q1 + (6-k)*q0)/6) 910 913 911 914 … … 955 958 domain, 956 959 quantities = ['Attribute0', 'Attribute1', 'Attribute2']) 957 assert allclose(domain.starttime, start)960 assert numpy.allclose(domain.starttime, start) 958 961 959 962 # Check that domain.starttime is updated if too early … … 962 965 domain, 963 966 quantities = ['Attribute0', 'Attribute1', 'Attribute2']) 964 assert allclose(domain.starttime, start)967 assert numpy.allclose(domain.starttime, start) 965 968 966 969 # Check that domain.starttime isn't updated if later … … 969 972 domain, 970 973 quantities = ['Attribute0', 'Attribute1', 'Attribute2']) 971 assert allclose(domain.starttime, start+1)974 assert numpy.allclose(domain.starttime, start+1) 972 975 973 976 domain.starttime = start … … 987 990 988 991 #Exact linear intpolation 989 assert allclose(q[0], 2*t)992 assert numpy.allclose(q[0], 2*t) 990 993 if i%6 == 0: 991 assert allclose(q[1], t**2)992 assert allclose(q[2], sin(t*pi/600))994 assert numpy.allclose(q[1], t**2) 995 assert numpy.allclose(q[2], sin(t*pi/600)) 993 996 994 997 #Check non-exact … … 996 999 t = 90 #Halfway between 60 and 120 997 1000 q = F(t) 998 assert allclose( (120**2 + 60**2)/2, q[1] )999 assert allclose( (sin(120*pi/600) + sin(60*pi/600))/2, q[2] )1001 assert numpy.allclose( (120**2 + 60**2)/2, q[1] ) 1002 assert numpy.allclose( (sin(120*pi/600) + sin(60*pi/600))/2, q[2] ) 1000 1003 1001 1004 1002 1005 t = 100 #Two thirds of the way between between 60 and 120 1003 1006 q = F(t) 1004 assert allclose( 2*120**2/3 + 60**2/3, q[1] )1005 assert allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] )1007 assert numpy.allclose( 2*120**2/3 + 60**2/3, q[1] ) 1008 assert numpy.allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] ) 1006 1009 1007 1010 os.remove(filename + '.tms') … … 1052 1055 F = file_function(filename + '.tms', domain, 1053 1056 quantities = ['Attribute0', 'Attribute1', 'Attribute2']) 1054 assert allclose(domain.starttime, start+delta)1057 assert numpy.allclose(domain.starttime, start+delta) 1055 1058 1056 1059 … … 1063 1066 1064 1067 #Exact linear intpolation 1065 assert allclose(q[0], 2*t)1068 assert numpy.allclose(q[0], 2*t) 1066 1069 if i%6 == 0: 1067 assert allclose(q[1], t**2)1068 assert allclose(q[2], sin(t*pi/600))1070 assert numpy.allclose(q[1], t**2) 1071 assert numpy.allclose(q[2], sin(t*pi/600)) 1069 1072 1070 1073 #Check non-exact … … 1072 1075 t = 90 #Halfway between 60 and 120 1073 1076 q = F(t-delta) 1074 assert allclose( (120**2 + 60**2)/2, q[1] )1075 assert allclose( (sin(120*pi/600) + sin(60*pi/600))/2, q[2] )1077 assert numpy.allclose( (120**2 + 60**2)/2, q[1] ) 1078 assert numpy.allclose( (sin(120*pi/600) + sin(60*pi/600))/2, q[2] ) 1076 1079 1077 1080 1078 1081 t = 100 #Two thirds of the way between between 60 and 120 1079 1082 q = F(t-delta) 1080 assert allclose( 2*120**2/3 + 60**2/3, q[1] )1081 assert allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] )1083 assert numpy.allclose( 2*120**2/3 + 60**2/3, q[1] ) 1084 assert numpy.allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] ) 1082 1085 1083 1086 … … 1091 1094 #FIXME: Division is not expected to work for integers. 1092 1095 #This must be caught. 1093 foo = array([[1,2,3], 1094 [4,5,6]], Float) 1095 1096 bar = array([[-1,0,5], 1097 [6,1,1]], Float) 1096 foo = numpy.array([[1,2,3], [4,5,6]], numpy.float) 1097 1098 bar = numpy.array([[-1,0,5], [6,1,1]], numpy.float) 1098 1099 1099 1100 D = {'X': foo, 'Y': bar} 1100 1101 1101 1102 Z = apply_expression_to_dictionary('X+Y', D) 1102 assert allclose(Z, foo+bar)1103 assert numpy.allclose(Z, foo+bar) 1103 1104 1104 1105 Z = apply_expression_to_dictionary('X*Y', D) 1105 assert allclose(Z, foo*bar)1106 assert numpy.allclose(Z, foo*bar) 1106 1107 1107 1108 Z = apply_expression_to_dictionary('4*X+Y', D) 1108 assert allclose(Z, 4*foo+bar)1109 assert numpy.allclose(Z, 4*foo+bar) 1109 1110 1110 1111 # test zero division is OK 1111 1112 Z = apply_expression_to_dictionary('X/Y', D) 1112 assert allclose(1/Z, 1/(foo/bar)) # can't compare inf to inf1113 assert numpy.allclose(1/Z, 1/(foo/bar)) # can't compare inf to inf 1113 1114 1114 1115 # make an error for zero on zero … … 1268 1269 tris = [[0,1,2]] 1269 1270 new_verts, new_tris = remove_lone_verts(verts, tris) 1270 assert n ew_verts == verts1271 assert n ew_tris == tris1271 assert numpy.alltrue(new_verts == verts) 1272 assert numpy.alltrue(new_tris == tris) 1272 1273 1273 1274 … … 1284 1285 new_verts, new_tris = remove_lone_verts(verts, tris) 1285 1286 #print "new_verts", new_verts 1286 assert n ew_verts == [[0,0],[1,0],[0,1]]1287 assert n ew_tris == [[0,1,2]]1287 assert numpy.alltrue(new_verts == [[0,0],[1,0],[0,1]]) 1288 assert numpy.alltrue(new_tris == [[0,1,2]]) 1288 1289 1289 1290 def test_remove_lone_verts_c(self): … … 1291 1292 tris = [[0,1,3]] 1292 1293 new_verts, new_tris = remove_lone_verts(verts, tris) 1293 #print "new_verts", new_verts1294 assert n ew_verts == [[0,0],[1,0],[0,1]]1295 assert n ew_tris == [[0,1,2]]1294 print "new_verts", new_verts 1295 assert numpy.alltrue(new_verts == [[0,0],[1,0],[0,1]]) 1296 assert numpy.alltrue(new_tris == [[0,1,2]]) 1296 1297 1297 1298 def test_remove_lone_verts_b(self): … … 1299 1300 tris = [[0,1,2]] 1300 1301 new_verts, new_tris = remove_lone_verts(verts, tris) 1301 assert n ew_verts == verts[0:3]1302 assert n ew_tris == tris1302 assert numpy.alltrue(new_verts == verts[0:3]) 1303 assert numpy.alltrue(new_tris == tris) 1303 1304 1304 1305 … … 1307 1308 tris = [[0,1,2]] 1308 1309 new_verts, new_tris = remove_lone_verts(verts, tris) 1309 assert n ew_verts == verts[0:3]1310 assert n ew_tris == tris1310 assert numpy.alltrue(new_verts == verts[0:3]) 1311 assert numpy.alltrue(new_tris == tris) 1311 1312 1312 1313 def test_get_min_max_values(self): … … 1496 1497 line.append([float(row[0]),float(row[1]),float(row[2]),float(row[3]),float(row[4]),float(row[5])]) 1497 1498 #print 'assert line',line[i],'point1',point1_answers_array[i] 1498 assert allclose(line[i], point1_answers_array[i])1499 assert numpy.allclose(line[i], point1_answers_array[i]) 1499 1500 1500 1501 point2_answers_array = [[0.0,1.0,1.5,-0.5,3.0,4.0], [2.0,10.0,10.5,-0.5,3.0,4.0]] … … 1509 1510 line.append([float(row[0]),float(row[1]),float(row[2]),float(row[3]),float(row[4]),float(row[5])]) 1510 1511 #print 'assert line',line[i],'point1',point1_answers_array[i] 1511 assert allclose(line[i], point2_answers_array[i])1512 assert numpy.allclose(line[i], point2_answers_array[i]) 1512 1513 1513 1514 # clean up … … 1615 1616 line.append([float(row[0]),float(row[1]),float(row[2])]) 1616 1617 #print 'line',line[i],'point1',point1_answers_array[i] 1617 assert allclose(line[i], point1_answers_array[i])1618 assert numpy.allclose(line[i], point1_answers_array[i]) 1618 1619 1619 1620 point2_answers_array = [[0.0,1.0,-0.5], [2.0,10.0,-0.5]] … … 1628 1629 line.append([float(row[0]),float(row[1]),float(row[2])]) 1629 1630 # print 'line',line[i],'point1',point1_answers_array[i] 1630 assert allclose(line[i], point2_answers_array[i])1631 assert numpy.allclose(line[i], point2_answers_array[i]) 1631 1632 1632 1633 # clean up … … 1734 1735 line.append([float(row[0]),float(row[1]),float(row[2]),float(row[3]),float(row[4]),float(row[5])]) 1735 1736 #print 'assert line',line[i],'point1',point1_answers_array[i] 1736 assert allclose(line[i], point1_answers_array[i])1737 assert numpy.allclose(line[i], point1_answers_array[i]) 1737 1738 1738 1739 point2_answers_array = [[5.0,1.0,1.5,-0.5,3.0,4.0], [7.0,10.0,10.5,-0.5,3.0,4.0]] … … 1747 1748 line.append([float(row[0]),float(row[1]),float(row[2]),float(row[3]),float(row[4]),float(row[5])]) 1748 1749 #print 'assert line',line[i],'point1',point1_answers_array[i] 1749 assert allclose(line[i], point2_answers_array[i])1750 assert numpy.allclose(line[i], point2_answers_array[i]) 1750 1751 1751 1752 # clean up … … 1830 1831 if __name__ == "__main__": 1831 1832 suite = unittest.makeSuite(Test_Util,'test') 1832 # suite = unittest.makeSuite(Test_Util,'test_s ww2csv')1833 # suite = unittest.makeSuite(Test_Util,'test_spatio_temporal_file_function_basic') 1833 1834 # runner = unittest.TextTestRunner(verbosity=2) 1834 1835 runner = unittest.TextTestRunner(verbosity=1) -
anuga_core/source/anuga/abstract_2d_finite_volumes/util.py
r5732 r5892 15 15 16 16 from anuga.utilities.numerical_tools import ensure_numeric 17 from Numeric import arange, choose, zeros, Float, array, allclose, take, compress 17 import numpy 18 18 19 19 from anuga.geospatial_data.geospatial_data import ensure_absolute … … 237 237 from anuga.config import time_format 238 238 from Scientific.IO.NetCDF import NetCDFFile 239 from Numeric import array, zeros, Float, alltrue, concatenate, reshape239 ## from numpy.oldnumeric import array, zeros, Float, alltrue, concatenate, reshape 240 240 241 241 # Open NetCDF file … … 303 303 # Get variables 304 304 # if verbose: print 'Get variables' 305 time = fid.variables['time'][:]305 time = numpy.array(fid.variables['time'][:] ) 306 306 307 307 # Get time independent stuff … … 317 317 triangles = fid.variables['volumes'][:] 318 318 319 x = reshape(x, (len(x),1))320 y = reshape(y, (len(y),1))321 vertex_coordinates = concatenate((x,y), axis=1) #m x 2 array319 x = numpy.reshape(x, (len(x),1)) 320 y = numpy.reshape(y, (len(y),1)) 321 vertex_coordinates = numpy.concatenate((x,y), axis=1) #m x 2 array 322 322 323 323 if boundary_polygon is not None: … … 331 331 for i in range(len(boundary_polygon)): 332 332 for j in range(len(x)): 333 if allclose(vertex_coordinates[j],boundary_polygon[i],1e-4):333 if numpy.allclose(vertex_coordinates[j],boundary_polygon[i],1e-4): 334 334 #FIX ME: 335 335 #currently gauges lat and long is stored as float and … … 351 351 gauge_neighbour_id.append(-1) 352 352 gauge_neighbour_id=ensure_numeric(gauge_neighbour_id) 353 if len( compress(gauge_neighbour_id>=0,gauge_neighbour_id))!=len(temp)-1:353 if len(numpy.compress(gauge_neighbour_id>=0,gauge_neighbour_id))!=len(temp)-1: 354 354 msg='incorrect number of segments' 355 355 raise msg … … 373 373 # move time back - relative to domain's time 374 374 if domain_starttime > starttime: 375 ## print 'type(time)=%s' % type(time) 376 ## print 'type(domain_starttime)=%s' % type(domain_starttime) 377 ## print 'type(starttime)=%s' % type(starttime) 378 ## a = time - domain_starttime 375 379 time = time - domain_starttime + starttime 376 380 … … 398 402 if boundary_polygon is not None: 399 403 #removes sts points that do not lie on boundary 400 quantities[name] = take(quantities[name],gauge_id,1)404 quantities[name] = numpy.take(quantities[name], gauge_id, 1) 401 405 402 406 # Close sww, tms or sts netcdf file … … 520 524 raise 'Illegal input to get_textual_float:', value 521 525 else: 522 return format % float(value)526 return format % float(value) 523 527 524 528 … … 1036 1040 """ 1037 1041 # from math import sqrt, atan, degrees 1038 from Numeric import ones, allclose, zeros, Float, ravel1042 ## from numpy.oldnumeric import ones, allclose, zeros, Float, ravel 1039 1043 from os import sep, altsep, getcwd, mkdir, access, F_OK, environ 1040 1044 … … 1077 1081 n0 = int(n0) 1078 1082 m = len(locations) 1079 model_time = zeros((n0,m,p), Float)1080 stages = zeros((n0,m,p), Float)1081 elevations = zeros((n0,m,p), Float)1082 momenta = zeros((n0,m,p), Float)1083 xmom = zeros((n0,m,p), Float)1084 ymom = zeros((n0,m,p), Float)1085 speed = zeros((n0,m,p), Float)1086 bearings = zeros((n0,m,p), Float)1087 due_east = 90.0* ones((n0,1), Float)1088 due_west = 270.0* ones((n0,1), Float)1089 depths = zeros((n0,m,p), Float)1090 eastings = zeros((n0,m,p), Float)1083 model_time = numpy.zeros((n0,m,p), numpy.float) 1084 stages = numpy.zeros((n0,m,p), numpy.float) 1085 elevations = numpy.zeros((n0,m,p), numpy.float) 1086 momenta = numpy.zeros((n0,m,p), numpy.float) 1087 xmom = numpy.zeros((n0,m,p), numpy.float) 1088 ymom = numpy.zeros((n0,m,p), numpy.float) 1089 speed = numpy.zeros((n0,m,p), numpy.float) 1090 bearings = numpy.zeros((n0,m,p), numpy.float) 1091 due_east = 90.0*numpy.ones((n0,1), numpy.float) 1092 due_west = 270.0*numpy.ones((n0,1), numpy.float) 1093 depths = numpy.zeros((n0,m,p), numpy.float) 1094 eastings = numpy.zeros((n0,m,p), numpy.float) 1091 1095 min_stages = [] 1092 1096 max_stages = [] … … 1100 1104 min_speeds = [] 1101 1105 max_depths = [] 1102 model_time_plot3d = zeros((n0,m), Float)1103 stages_plot3d = zeros((n0,m), Float)1104 eastings_plot3d = zeros((n0,m),Float)1106 model_time_plot3d = numpy.zeros((n0,m), numpy.float) 1107 stages_plot3d = numpy.zeros((n0,m), numpy.float) 1108 eastings_plot3d = numpy.zeros((n0,m),numpy.float) 1105 1109 if time_unit is 'mins': scale = 60.0 1106 1110 if time_unit is 'hours': scale = 3600.0 … … 1202 1206 else: 1203 1207 #ax.plot_wireframe(model_time[:,:,j],eastings[:,:,j],stages[:,:,j]) 1204 ax.plot3D( ravel(eastings[:,:,j]),ravel(model_time[:,:,j]),ravel(stages[:,:,j]))1208 ax.plot3D(numpy.ravel(eastings[:,:,j]),numpy.ravel(model_time[:,:,j]),numpy.ravel(stages[:,:,j])) 1205 1209 ax.set_xlabel('time') 1206 1210 ax.set_ylabel('x') … … 1501 1505 1502 1506 # initialise the array to easily find the index of the first loner 1503 loners= arange(2*N, N, -1) # if N=3 [6,5,4]1507 loners=numpy.arange(2*N, N, -1) # if N=3 [6,5,4] 1504 1508 for t in triangles: 1505 1509 for vert in t: … … 1535 1539 #print "loners", loners 1536 1540 #print "triangles before", triangles 1537 triangles = choose(triangles,loners)1541 triangles = numpy.choose(triangles,loners) 1538 1542 #print "triangles after", triangles 1539 1543 return verts, triangles … … 1550 1554 1551 1555 1552 xc = zeros(triangles.shape[0], Float) # Space for centroid info1556 xc = numpy.zeros(triangles.shape[0], numpy.float) # Space for centroid info 1553 1557 1554 1558 for k in range(triangles.shape[0]): … … 1832 1836 #add tide to stage if provided 1833 1837 if quantity == 'stage': 1834 quantity_value[quantity]= array(quantity_value[quantity])+directory_add_tide1838 quantity_value[quantity]=numpy.array(quantity_value[quantity])+directory_add_tide 1835 1839 1836 1840 #condition to find max and mins for all the plots … … 1943 1947 #get data from dict in to list 1944 1948 #do maths to list by changing to array 1945 t=( array(directory_quantity_value[directory][filename]['time'])+directory_start_time)/seconds_in_minutes1949 t=(numpy.array(directory_quantity_value[directory][filename]['time'])+directory_start_time)/seconds_in_minutes 1946 1950 1947 1951 #finds the maximum elevation, used only as a test … … 2124 2128 from csv import reader,writer 2125 2129 from anuga.utilities.numerical_tools import ensure_numeric, mean, NAN 2126 from Numeric import array, resize, shape, Float, zeros, take, argsort, argmin2130 ## from numpy.oldnumeric import array, resize, shape, Float, zeros, take, argsort, argmin 2127 2131 import string 2128 2132 from anuga.shallow_water.data_manager import get_all_swwfiles … … 2165 2169 2166 2170 #convert to array for file_function 2167 points_array = array(points,Float)2171 points_array = numpy.array(points, numpy.float) 2168 2172 2169 2173 points_array = ensure_absolute(points_array)
Note: See TracChangeset
for help on using the changeset viewer.