Changeset 6304 for branches/numpy/anuga/abstract_2d_finite_volumes
- Timestamp:
- Feb 10, 2009, 11:11:04 AM (16 years ago)
- Location:
- branches/numpy
- Files:
-
- 21 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/numpy/anuga/abstract_2d_finite_volumes/domain.py
r6246 r6304 31 31 from quantity import Quantity 32 32 33 import Numericas num33 import numpy as num 34 34 35 35 … … 185 185 buffer_shape = self.full_send_dict[key][0].shape[0] 186 186 self.full_send_dict[key].append(num.zeros((buffer_shape, self.nsys), 187 num. Float))187 num.float)) 188 188 189 189 for key in self.ghost_recv_dict: 190 190 buffer_shape = self.ghost_recv_dict[key][0].shape[0] 191 191 self.ghost_recv_dict[key].append(num.zeros((buffer_shape, self.nsys), 192 num. Float))192 num.float)) 193 193 194 194 # Setup cell full flag … … 197 197 N = len(self) #number_of_elements 198 198 self.number_of_elements = N 199 self.tri_full_flag = num.ones(N, num. Int)199 self.tri_full_flag = num.ones(N, num.int) 200 200 for i in self.ghost_recv_dict.keys(): 201 201 for id in self.ghost_recv_dict[i][0]: … … 258 258 # (boolean) array, to be used during the flux calculation. 259 259 N = len(self) # Number_of_triangles 260 self.already_computed_flux = num.zeros((N, 3), num. Int)260 self.already_computed_flux = num.zeros((N, 3), num.int) 261 261 262 262 # Storage for maximal speeds computed for each triangle by 263 263 # compute_fluxes. 264 264 # This is used for diagnostics only (reset at every yieldstep) 265 self.max_speed = num.zeros(N, num. Float)265 self.max_speed = num.zeros(N, num.float) 266 266 267 267 if mesh_filename is not None: … … 375 375 raise Exception, msg 376 376 377 q = num.zeros(len(self.conserved_quantities), num. Float)377 q = num.zeros(len(self.conserved_quantities), num.float) 378 378 379 379 for i, name in enumerate(self.conserved_quantities): … … 447 447 448 448 name: Name of quantity 449 value: Compatible list, Numeric array, const or function (see below)449 value: Compatible list, numeric array, const or function (see below) 450 450 451 451 The values will be stored in elements following their internal ordering. … … 879 879 880 880 msg += '------------------------------------------------\n' 881 msg += ' Speeds in [%f, %f]\n' % (min(self.max_speed ),882 max(self.max_speed ))881 msg += ' Speeds in [%f, %f]\n' % (min(self.max_speed.flat), 882 max(self.max_speed.flat)) 883 883 msg += ' Histogram:\n' 884 884 … … 892 892 else: 893 893 # Closed upper interval 894 hi = max(self.max_speed )894 hi = max(self.max_speed.flat) 895 895 msg += ' [%f, %f]: %d\n' % (lo, hi, count) 896 896 897 N = len(self.max_speed )897 N = len(self.max_speed.flat) 898 898 if N > 10: 899 899 msg += ' Percentiles (10%):\n' … … 1357 1357 self.number_of_steps = 0 1358 1358 self.number_of_first_order_steps = 0 1359 self.max_speed = num.zeros(N, num. Float)1359 self.max_speed = num.zeros(N, num.float) 1360 1360 1361 1361 ## … … 1626 1626 # momentum 1627 1627 if self.protect_against_isolated_degenerate_timesteps is True and \ 1628 self.max_speed> 10.0: # FIXME (Ole): Make this configurable1628 num.max(self.max_speed) > 10.0: # FIXME (Ole): Make this configurable 1629 1629 1630 1630 # Setup 10 bins for speed histogram … … 1641 1641 1642 1642 # Find triangles in last bin 1643 # FIXME - speed up using Numeric1643 # FIXME - speed up using numeric package 1644 1644 d = 0 1645 1645 for i in range(self.number_of_full_triangles): -
branches/numpy/anuga/abstract_2d_finite_volumes/ermapper_grids.py
r6161 r6304 2 2 3 3 # from os import open, write, read 4 import Numericas num5 6 celltype_map = {'IEEE4ByteReal': num. Float32, 'IEEE8ByteReal': num.Float64}4 import numpy as num 5 6 celltype_map = {'IEEE4ByteReal': num.float32, 'IEEE8ByteReal': num.float64} 7 7 8 8 … … 11 11 write_ermapper_grid(ofile, data, header = {}): 12 12 13 Function to write a 2D Numeric array to an ERMapper grid. There are a series of conventions adopted within13 Function to write a 2D numeric array to an ERMapper grid. There are a series of conventions adopted within 14 14 this code, specifically: 15 15 1) The registration coordinate for the data is the SW (or lower-left) corner of the data 16 16 2) The registration coordinates refer to cell centres 17 3) The data is a 2D Numeric array with the NW-most data in element (0,0) and the SE-most data in element (N,M)17 3) The data is a 2D numeric array with the NW-most data in element (0,0) and the SE-most data in element (N,M) 18 18 where N is the last line and M is the last column 19 19 4) There has been no testng of the use of a rotated grid. Best to keep data in an NS orientation … … 163 163 return header 164 164 165 def write_ermapper_data(grid, ofile, data_format = num.Float32):165 def write_ermapper_data(grid, ofile, data_format=num.float32): 166 166 167 167 … … 193 193 194 194 195 def read_ermapper_data(ifile, data_format = num. Float32):195 def read_ermapper_data(ifile, data_format = num.float32): 196 196 # open input file in a binary format and read the input string 197 197 fid = open(ifile,'rb') … … 199 199 fid.close() 200 200 201 # convert input string to required format (Note default format is num. Float32)201 # convert input string to required format (Note default format is num.float32) 202 202 grid_as_float = num.fromstring(input_string,data_format) 203 203 return grid_as_float -
branches/numpy/anuga/abstract_2d_finite_volumes/general_mesh.py
r6191 r6304 1 import Numericas num1 import numpy as num 2 2 3 3 from anuga.coordinate_transforms.geo_reference import Geo_reference … … 10 10 which is represented as a coordinate set (x,y). 11 11 Vertices from different triangles can point to the same node. 12 The nodes are implemented as an Nx2 Numeric array containing the12 The nodes are implemented as an Nx2 numeric array containing the 13 13 x and y coordinates. 14 14 … … 19 19 where 20 20 21 nodes is either a list of 2-tuples or an Nx2 Numeric array of21 nodes is either a list of 2-tuples or an Nx2 numeric array of 22 22 floats representing all x, y coordinates in the mesh. 23 23 24 triangles is either a list of 3-tuples or an Mx3 Numeric array of24 triangles is either a list of 3-tuples or an Mx3 numeric array of 25 25 integers representing indices of all vertices in the mesh. 26 26 Each vertex is identified by its index i in [0, N-1]. … … 68 68 69 69 nodes: x,y coordinates represented as a sequence of 2-tuples or 70 a Nx2 Numeric array of floats.70 a Nx2 numeric array of floats. 71 71 72 triangles: sequence of 3-tuples or Mx3 Numeric array of72 triangles: sequence of 3-tuples or Mx3 numeric array of 73 73 non-negative integers representing indices into 74 74 the nodes array. … … 88 88 if verbose: print 'General_mesh: Building basic mesh structure in ANUGA domain' 89 89 90 self.triangles = num.array(triangles, num. Int)91 self.nodes = num.array(nodes, num. Float)90 self.triangles = num.array(triangles, num.int) 91 self.nodes = num.array(nodes, num.float) 92 92 93 93 … … 125 125 126 126 # Input checks 127 msg = 'Triangles must an Mx3 Numeric array or a sequence of 3-tuples. '127 msg = 'Triangles must an Mx3 numeric array or a sequence of 3-tuples. ' 128 128 msg += 'The supplied array has the shape: %s'\ 129 129 %str(self.triangles.shape) 130 130 assert len(self.triangles.shape) == 2, msg 131 131 132 msg = 'Nodes must an Nx2 Numeric array or a sequence of 2-tuples'132 msg = 'Nodes must an Nx2 numeric array or a sequence of 2-tuples' 133 133 msg += 'The supplied array has the shape: %s'\ 134 134 %str(self.nodes.shape) … … 144 144 max(self.nodes[:,0]), max(self.nodes[:,1]) ] 145 145 146 self.xy_extent = num.array(xy_extent, num. Float)146 self.xy_extent = num.array(xy_extent, num.float) 147 147 148 148 149 149 # Allocate space for geometric quantities 150 self.normals = num.zeros((N, 6), num. Float)151 self.areas = num.zeros(N, num. Float)152 self.edgelengths = num.zeros((N, 3), num. Float)150 self.normals = num.zeros((N, 6), num.float) 151 self.areas = num.zeros(N, num.float) 152 self.edgelengths = num.zeros((N, 3), num.float) 153 153 154 154 # Get x,y coordinates for all triangles and store … … 185 185 # - Stored as six floats n0x,n0y,n1x,n1y,n2x,n2y per triangle 186 186 187 n0 = num.array([x2 - x1, y2 - y1], num. Float)187 n0 = num.array([x2 - x1, y2 - y1], num.float) 188 188 l0 = num.sqrt(num.sum(n0**2)) 189 189 190 n1 = num.array([x0 - x2, y0 - y2], num. Float)190 n1 = num.array([x0 - x2, y0 - y2], num.float) 191 191 l1 = num.sqrt(num.sum(n1**2)) 192 192 193 n2 = num.array([x1 - x0, y1 - y0], num. Float)193 n2 = num.array([x1 - x0, y1 - y0], num.float) 194 194 l2 = num.sqrt(num.sum(n2**2)) 195 195 … … 275 275 if not self.geo_reference.is_absolute(): 276 276 return V + num.array([self.geo_reference.get_xllcorner(), 277 self.geo_reference.get_yllcorner()], num. Float)277 self.geo_reference.get_yllcorner()], num.float) 278 278 else: 279 279 return V … … 317 317 if absolute is True and not self.geo_reference.is_absolute(): 318 318 offset=num.array([self.geo_reference.get_xllcorner(), 319 self.geo_reference.get_yllcorner()], num. Float)319 self.geo_reference.get_yllcorner()], num.float) 320 320 return num.array([V[i3,:]+offset, 321 321 V[i3+1,:]+offset, 322 V[i3+2,:]+offset], num. Float)322 V[i3+2,:]+offset], num.float) 323 323 else: 324 return num.array([V[i3,:], V[i3+1,:], V[i3+2,:]], num. Float)324 return num.array([V[i3,:], V[i3+1,:], V[i3+2,:]], num.float) 325 325 326 326 … … 349 349 350 350 M = self.number_of_triangles 351 vertex_coordinates = num.zeros((3*M, 2), num. Float)351 vertex_coordinates = num.zeros((3*M, 2), num.float) 352 352 353 353 for i in range(M): … … 409 409 K = 3*M # Total number of unique vertices 410 410 411 T = num.reshape(num.arange(K, typecode=num.Int), (M,3))411 T = num.reshape(num.arange(K, dtype=num.int), (M,3)) 412 412 413 413 return T … … 416 416 417 417 def get_unique_vertices(self, indices=None): 418 """FIXME(Ole): This function needs a docstring 419 """ 418 """FIXME(Ole): This function needs a docstring""" 419 420 420 triangles = self.get_triangles(indices=indices) 421 421 unique_verts = {} 422 422 for triangle in triangles: 423 unique_verts[triangle[0]] = 0 424 unique_verts[triangle[1]] = 0 425 unique_verts[triangle[2]] = 0 423 #print 'triangle(%s)=%s' % (type(triangle), str(triangle)) 424 unique_verts[triangle[0]] = 0 425 unique_verts[triangle[1]] = 0 426 unique_verts[triangle[2]] = 0 426 427 return unique_verts.keys() 427 428 … … 452 453 triangle_list.append( (volume_id, vertex_id) ) 453 454 454 triangle_list = num.array(triangle_list, num. Int) #array default#455 triangle_list = num.array(triangle_list, num.int) #array default# 455 456 else: 456 457 # Get info for all nodes recursively. … … 529 530 530 531 # Count number of triangles per node 531 number_of_triangles_per_node = num.zeros(self.number_of_full_nodes) 532 number_of_triangles_per_node = num.zeros(self.number_of_full_nodes, 533 num.int) #array default# 532 534 for volume_id, triangle in enumerate(self.get_triangles()): 533 535 for vertex_id in triangle: … … 536 538 # Allocate space for inverted structure 537 539 number_of_entries = num.sum(number_of_triangles_per_node) 538 vertex_value_indices = num.zeros(number_of_entries )540 vertex_value_indices = num.zeros(number_of_entries, num.int) #array default# 539 541 540 542 # Register (triangle, vertex) indices for each node -
branches/numpy/anuga/abstract_2d_finite_volumes/generic_boundary_conditions.py
r6174 r6304 8 8 from anuga.fit_interpolate.interpolate import Modeltime_too_early 9 9 10 import Numericas num10 import numpy as num 11 11 12 12 … … 69 69 raise Exception, msg 70 70 71 self.conserved_quantities=num.array(conserved_quantities, num. Float)71 self.conserved_quantities=num.array(conserved_quantities, num.float) 72 72 73 73 def __repr__(self): … … 99 99 100 100 try: 101 q = num.array(q, num. Float)101 q = num.array(q, num.float) 102 102 except: 103 103 msg = 'Return value from time boundary function could ' 104 msg += 'not be converted into a Numeric array of floats.\n'104 msg += 'not be converted into a numeric array of floats.\n' 105 105 msg += 'Specified function should return either list or array.\n' 106 106 msg += 'I got %s' %str(q) … … 180 180 181 181 if verbose: print 'Find midpoint coordinates of entire boundary' 182 self.midpoint_coordinates = num.zeros((len(domain.boundary), 2), num. Float)182 self.midpoint_coordinates = num.zeros((len(domain.boundary), 2), num.float) 183 183 boundary_keys = domain.boundary.keys() 184 184 … … 200 200 201 201 # Compute midpoints 202 if edge_id == 0: m = num.array([(x1 + x2)/2, (y1 + y2)/2], num. Float)203 if edge_id == 1: m = num.array([(x0 + x2)/2, (y0 + y2)/2], num. Float)204 if edge_id == 2: m = num.array([(x1 + x0)/2, (y1 + y0)/2], num. Float)202 if edge_id == 0: m = num.array([(x1 + x2)/2, (y1 + y2)/2], num.float) 203 if edge_id == 1: m = num.array([(x0 + x2)/2, (y0 + y2)/2], num.float) 204 if edge_id == 2: m = num.array([(x1 + x0)/2, (y1 + y0)/2], num.float) 205 205 206 206 # Convert to absolute UTM coordinates … … 309 309 # See http://docs.python.org/lib/warning-filter.html 310 310 self.default_boundary_invoked = True 311 312 313 if res == NAN: 311 312 if num.any(res == NAN): 314 313 x,y=self.midpoint_coordinates[i,:] 315 314 msg = 'NAN value found in file_boundary at ' -
branches/numpy/anuga/abstract_2d_finite_volumes/mesh_factory.py
r6145 r6304 3 3 """ 4 4 5 import Numericas num5 import numpy as num 6 6 7 7 … … 94 94 index = Index(n,m) 95 95 96 points = num.zeros((Np, 2), num. Float)96 points = num.zeros((Np, 2), num.float) 97 97 98 98 for i in range(m+1): … … 106 106 107 107 108 elements = num.zeros((Nt, 3), num. Int)108 elements = num.zeros((Nt, 3), num.int) 109 109 boundary = {} 110 110 nt = -1 -
branches/numpy/anuga/abstract_2d_finite_volumes/neighbour_mesh.py
r6191 r6304 12 12 from math import pi, sqrt 13 13 14 import Numericas num14 import numpy as num 15 15 16 16 … … 24 24 coordinate set. 25 25 26 Coordinate sets are implemented as an N x 2 Numeric array containing26 Coordinate sets are implemented as an N x 2 numeric array containing 27 27 x and y coordinates. 28 28 … … 33 33 where 34 34 35 coordinates is either a list of 2-tuples or an Mx2 Numeric array of35 coordinates is either a list of 2-tuples or an Mx2 numeric array of 36 36 floats representing all x, y coordinates in the mesh. 37 37 38 triangles is either a list of 3-tuples or an Nx3 Numeric array of38 triangles is either a list of 3-tuples or an Nx3 numeric array of 39 39 integers representing indices of all vertices in the mesh. 40 40 Each vertex is identified by its index i in [0, M-1]. … … 76 76 """ 77 77 Build triangles from x,y coordinates (sequence of 2-tuples or 78 Mx2 Numeric array of floats) and triangles (sequence of 3-tuples79 or Nx3 Numeric array of non-negative integers).78 Mx2 numeric array of floats) and triangles (sequence of 3-tuples 79 or Nx3 numeric array of non-negative integers). 80 80 """ 81 81 … … 98 98 99 99 #Allocate space for geometric quantities 100 self.centroid_coordinates = num.zeros((N, 2), num. Float)101 102 self.radii = num.zeros(N, num. Float)103 104 self.neighbours = num.zeros((N, 3), num. Int)105 self.neighbour_edges = num.zeros((N, 3), num. Int)106 self.number_of_boundaries = num.zeros(N, num. Int)107 self.surrogate_neighbours = num.zeros((N, 3), num. Int)100 self.centroid_coordinates = num.zeros((N, 2), num.float) 101 102 self.radii = num.zeros(N, num.float) 103 104 self.neighbours = num.zeros((N, 3), num.int) 105 self.neighbour_edges = num.zeros((N, 3), num.int) 106 self.number_of_boundaries = num.zeros(N, num.int) 107 self.surrogate_neighbours = num.zeros((N, 3), num.int) 108 108 109 109 #Get x,y coordinates for all triangles and store … … 124 124 125 125 #Compute centroid 126 centroid = num.array([(x0 + x1 + x2)/3, (y0 + y1 + y2)/3], num. Float)126 centroid = num.array([(x0 + x1 + x2)/3, (y0 + y1 + y2)/3], num.float) 127 127 self.centroid_coordinates[i] = centroid 128 128 … … 133 133 134 134 #Midpoints 135 m0 = num.array([(x1 + x2)/2, (y1 + y2)/2], num. Float)136 m1 = num.array([(x0 + x2)/2, (y0 + y2)/2], num. Float)137 m2 = num.array([(x1 + x0)/2, (y1 + y0)/2], num. Float)135 m0 = num.array([(x1 + x2)/2, (y1 + y2)/2], num.float) 136 m1 = num.array([(x0 + x2)/2, (y0 + y2)/2], num.float) 137 m2 = num.array([(x1 + x0)/2, (y1 + y0)/2], num.float) 138 138 139 139 #The radius is the distance from the centroid of … … 394 394 #Check that all keys in given boundary exist 395 395 for tag in tagged_elements.keys(): 396 tagged_elements[tag] = num.array(tagged_elements[tag], num. Int)396 tagged_elements[tag] = num.array(tagged_elements[tag], num.int) 397 397 398 398 msg = 'Not all elements exist. ' … … 506 506 # Sanity check 507 507 if p0 is None: 508 raise Exception('Impossible')509 508 msg = 'Impossible: p0 is None!?' 509 raise Exception, msg 510 510 511 511 # Register potential paths from A to B … … 613 613 point_registry[tuple(p1)] = len(point_registry) 614 614 615 polygon.append(list(p1)) # De- Numeric each point :-)615 polygon.append(list(p1)) # De-numeric each point :-) 616 616 p0 = p1 617 617 … … 1139 1139 1140 1140 # Distances from line origin to the two intersections 1141 z0 = num.array([x0 - xi0, y0 - eta0], num. Float)1142 z1 = num.array([x1 - xi0, y1 - eta0], num. Float)1141 z0 = num.array([x0 - xi0, y0 - eta0], num.float) 1142 z1 = num.array([x1 - xi0, y1 - eta0], num.float) 1143 1143 d0 = num.sqrt(num.sum(z0**2)) 1144 1144 d1 = num.sqrt(num.sum(z1**2)) … … 1155 1155 # Normal direction: 1156 1156 # Right hand side relative to line direction 1157 vector = num.array([x1 - x0, y1 - y0], num. Float) # Segment vector1157 vector = num.array([x1 - x0, y1 - y0], num.float) # Segment vector 1158 1158 length = num.sqrt(num.sum(vector**2)) # Segment length 1159 normal = num.array([vector[1], -vector[0]], num. Float)/length1159 normal = num.array([vector[1], -vector[0]], num.float)/length 1160 1160 1161 1161 … … 1237 1237 assert isinstance(segment, Triangle_intersection), msg 1238 1238 1239 midpoint = num.sum(num.array(segment.segment, num. Float))/21239 midpoint = num.sum(num.array(segment.segment, num.float))/2 1240 1240 midpoints.append(midpoint) 1241 1241 -
branches/numpy/anuga/abstract_2d_finite_volumes/pmesh2domain.py
r6145 r6304 1 """Class pmesh2domain - Converting .tsh files to do amains1 """Class pmesh2domain - Converting .tsh files to domains 2 2 3 3 … … 8 8 9 9 import sys 10 11 import Numeric as num 12 13 14 def pmesh_instance_to_domain_instance(mesh, 15 DomainClass): 16 """ 17 Convert a pmesh instance/object into a domain instance. 18 19 Use pmesh_to_domain_instance to convert a mesh file to a domain instance. 20 """ 21 22 vertex_coordinates, vertices, tag_dict, vertex_quantity_dict \ 23 ,tagged_elements_dict, geo_reference = \ 24 pmesh_to_domain(mesh_instance=mesh) 10 import numpy as num 11 12 13 ## 14 # @brief Convert a pmesh instance to a domain instance. 15 # @param mesh The pmesh instance to convert. 16 # @param DomainClass The class to instantiate and return. 17 # @return The converted pmesh instance (as a 'DomainClass' instance). 18 def pmesh_instance_to_domain_instance(mesh, DomainClass): 19 """Convert a pmesh instance/object into a domain instance. 20 21 Uses pmesh_to_domain_instance to convert a mesh file to a domain instance. 22 """ 23 24 (vertex_coordinates, vertices, tag_dict, vertex_quantity_dict, 25 tagged_elements_dict, geo_reference) = pmesh_to_domain(mesh_instance=mesh) 26 27 # NOTE(Ole): This import cannot be at the module level 28 # due to mutual dependency with domain.py 29 from anuga.abstract_2d_finite_volumes.domain import Domain 30 31 # ensure that the required 'DomainClass' actually is an instance of Domain 32 msg = ('The class %s is not a subclass of the generic domain class %s' 33 % (DomainClass, Domain)) 34 assert issubclass(DomainClass, Domain), msg 35 36 # instantiate the result class 37 result = DomainClass(coordinates=vertex_coordinates, 38 vertices=vertices, 39 boundary=tag_dict, 40 tagged_elements=tagged_elements_dict, 41 geo_reference=geo_reference) 42 43 # set the water stage to be the elevation 44 if (vertex_quantity_dict.has_key('elevation') and 45 not vertex_quantity_dict.has_key('stage')): 46 vertex_quantity_dict['stage'] = vertex_quantity_dict['elevation'] 47 result.set_quantity_vertices_dict(vertex_quantity_dict) 48 49 return result 50 51 52 ## 53 # @brief Convert a mesh file to a Domain instance. 54 # @param file_name Name of the file to convert (TSH or MSH). 55 # @param DomainClass Class of return instance. 56 # @param use_cache True if caching is to be used. 57 # @param verbose True if this function is to be verbose. 58 # @return An instance of 'DomainClass' containing the file data. 59 def pmesh_to_domain_instance(file_name, DomainClass, use_cache=False, 60 verbose=False): 61 """Converts a mesh file(.tsh or .msh), to a Domain instance. 62 63 file_name is the name of the mesh file to convert, including the extension 64 65 DomainClass is the Class that will be returned. 66 It must be a subclass of Domain, with the same interface as domain. 67 68 use_cache: True means that caching is attempted for the computed domain. 69 """ 70 71 if use_cache is True: 72 from caching import cache 73 result = cache(_pmesh_to_domain_instance, (file_name, DomainClass), 74 dependencies=[file_name], verbose=verbose) 75 else: 76 result = apply(_pmesh_to_domain_instance, (file_name, DomainClass)) 77 78 return result 79 80 81 ## 82 # @brief Convert a mesh file to a Domain instance. 83 # @param file_name Name of the file to convert (TSH or MSH). 84 # @param DomainClass Class of return instance. 85 # @return The DomainClass instance containing the file data. 86 def _pmesh_to_domain_instance(file_name, DomainClass): 87 """Converts a mesh file(.tsh or .msh), to a Domain instance. 88 89 Internal function. See public interface pmesh_to_domain_instance for details 90 """ 91 92 (vertex_coordinates, vertices, tag_dict, vertex_quantity_dict, 93 tagged_elements_dict, geo_reference) = pmesh_to_domain(file_name=file_name) 25 94 26 95 # NOTE(Ole): This import cannot be at the module level due to mutual … … 28 97 from anuga.abstract_2d_finite_volumes.domain import Domain 29 98 30 31 32 33 msg = 'The class %s is not a subclass of the generic domain class %s'\ 34 %(DomainClass, Domain) 99 # ensure the required class is a subclass of Domain 100 msg = ('The class %s is not a subclass of the generic domain class %s' 101 % (DomainClass, Domain)) 35 102 assert issubclass(DomainClass, Domain), msg 36 37 103 38 104 domain = DomainClass(coordinates = vertex_coordinates, … … 42 108 geo_reference = geo_reference ) 43 109 44 # set the water stage to be the elevation 45 if vertex_quantity_dict.has_key('elevation') and not vertex_quantity_dict.has_key('stage'): 46 vertex_quantity_dict['stage'] = vertex_quantity_dict['elevation'] 47 48 domain.set_quantity_vertices_dict(vertex_quantity_dict) 49 #print "vertex_quantity_dict",vertex_quantity_dict 50 return domain 51 52 53 54 def pmesh_to_domain_instance(file_name, DomainClass, use_cache = False, verbose = False): 55 """ 56 Converts a mesh file(.tsh or .msh), to a Domain instance. 57 58 file_name is the name of the mesh file to convert, including the extension 59 60 DomainClass is the Class that will be returned. 61 It must be a subclass of Domain, with the same interface as domain. 62 63 use_cache: True means that caching is attempted for the computed domain. 64 """ 65 66 if use_cache is True: 67 from caching import cache 68 result = cache(_pmesh_to_domain_instance, (file_name, DomainClass), 69 dependencies = [file_name], 70 verbose = verbose) 71 72 else: 73 result = apply(_pmesh_to_domain_instance, (file_name, DomainClass)) 74 75 return result 76 77 78 79 80 def _pmesh_to_domain_instance(file_name, DomainClass): 81 """ 82 Converts a mesh file(.tsh or .msh), to a Domain instance. 83 84 Internal function. See public interface pmesh_to_domain_instance for details 85 """ 86 87 vertex_coordinates, vertices, tag_dict, vertex_quantity_dict, \ 88 tagged_elements_dict, geo_reference = \ 89 pmesh_to_domain(file_name=file_name) 90 91 92 # NOTE(Ole): This import cannot be at the module level due to mutual 93 # dependency with domain.py 94 from anuga.abstract_2d_finite_volumes.domain import Domain 95 96 97 msg = 'The class %s is not a subclass of the generic domain class %s'\ 98 %(DomainClass, Domain) 99 assert issubclass(DomainClass, Domain), msg 100 101 102 103 domain = DomainClass(coordinates = vertex_coordinates, 104 vertices = vertices, 105 boundary = tag_dict, 106 tagged_elements = tagged_elements_dict, 107 geo_reference = geo_reference ) 108 109 110 111 #FIXME (Ole): Is this really the right place to apply the a default 112 #value specific to the shallow water wave equation? 113 #The 'assert' above indicates that any subclass of Domain is acceptable. 114 #Suggestion - module shallow_water.py will eventually take care of this 115 #(when I get around to it) so it should be removed from here. 110 # FIXME (Ole): Is this really the right place to apply a default 111 # value specific to the shallow water wave equation? 112 # The 'assert' above indicates that any subclass of Domain is acceptable. 113 # Suggestion - module shallow_water.py will eventually take care of this 114 # (when I get around to it) so it should be removed from here. 116 115 117 116 # This doesn't work on the domain instance. 118 117 # This is still needed so -ve elevations don't cuase 'lakes' 119 118 # The fixme we discussed was to only create a quantity when its values 120 # are set.119 # are set. 121 120 # I think that's the way to go still 122 121 123 122 # set the water stage to be the elevation 124 if vertex_quantity_dict.has_key('elevation') and not vertex_quantity_dict.has_key('stage'): 123 if (vertex_quantity_dict.has_key('elevation') and 124 not vertex_quantity_dict.has_key('stage')): 125 125 vertex_quantity_dict['stage'] = vertex_quantity_dict['elevation'] 126 127 126 domain.set_quantity_vertices_dict(vertex_quantity_dict) 128 #print "vertex_quantity_dict",vertex_quantity_dict 127 129 128 return domain 130 129 131 130 132 def pmesh_to_domain(file_name=None, 133 mesh_instance=None, 134 use_cache=False, 131 ## 132 # @brief Convert pmesh file/instance to list(s) that can instantiate a Domain. 133 # @param file_name Path to file to convert. 134 # @param mesh_instance Instance to convert. 135 # @param use_cache True if we are to cache. 136 # @param verbose True if this function is to be verbose. 137 # @return ?? 138 def pmesh_to_domain(file_name=None, mesh_instance=None, use_cache=False, 135 139 verbose=False): 136 """ 137 Convert a pmesh file or a pmesh mesh instance to a bunch of lists 140 """Convert a pmesh file or a pmesh mesh instance to a bunch of lists 138 141 that can be used to instanciate a domain object. 139 142 … … 144 147 from caching import cache 145 148 result = cache(_pmesh_to_domain, (file_name, mesh_instance), 146 dependencies = [file_name], 147 verbose = verbose) 149 dependencies=[file_name], verbose=verbose) 148 150 149 151 else: … … 153 155 154 156 155 def _pmesh_to_domain(file_name=None, 156 mesh_instance=None, 157 use_cache=False, 157 ## 158 # @brief Convert pmesh file/instance to list(s) that can instantiate a Domain. 159 # @param file_name Path to file to convert. 160 # @param mesh_instance Instance to convert. 161 # @param use_cache True if we are to cache. 162 # @param verbose True if this function is to be verbose. 163 # @return ?? 164 def _pmesh_to_domain(file_name=None, mesh_instance=None, use_cache=False, 158 165 verbose=False): 159 """ 160 Convert a pmesh file or a pmesh mesh instance to a bunch of lists 166 """Convert a pmesh file or a pmesh mesh instance to a bunch of lists 161 167 that can be used to instanciate a domain object. 162 168 """ … … 164 170 from load_mesh.loadASCII import import_mesh_file 165 171 172 # get data from mesh instance or file 166 173 if file_name is None: 167 174 mesh_dict = mesh_instance.Mesh2IODict() 168 175 else: 169 176 mesh_dict = import_mesh_file(file_name) 170 #print "mesh_dict",mesh_dict 177 178 # extract required data from the mesh dictionary 171 179 vertex_coordinates = mesh_dict['vertices'] 172 180 volumes = mesh_dict['triangles'] 173 181 vertex_quantity_dict = {} 174 point_atts = num.transpose(mesh_dict['vertex_attributes'])182 point_atts = mesh_dict['vertex_attributes'] 175 183 point_titles = mesh_dict['vertex_attribute_titles'] 176 184 geo_reference = mesh_dict['geo_reference'] 177 if point_atts != None: 178 for quantity, value_vector in map (None, point_titles, point_atts): 185 if point_atts is not None: 186 point_atts = num.transpose(mesh_dict['vertex_attributes']) 187 for quantity, value_vector in map(None, point_titles, point_atts): 179 188 vertex_quantity_dict[quantity] = value_vector 180 189 tag_dict = pmesh_dict_to_tag_dict(mesh_dict) 181 190 tagged_elements_dict = build_tagged_elements_dictionary(mesh_dict) 182 return vertex_coordinates, volumes, tag_dict, vertex_quantity_dict, tagged_elements_dict, geo_reference 183 191 192 return (vertex_coordinates, volumes, tag_dict, vertex_quantity_dict, 193 tagged_elements_dict, geo_reference) 184 194 185 195 186 196 def build_tagged_elements_dictionary(mesh_dict): 187 197 """Build the dictionary of element tags. 198 188 199 tagged_elements is a dictionary of element arrays, 189 keyed by tag: 190 { (tag): [e1, e2, e3..] }191 """ 200 keyed by tag: { (tag): [e1, e2, e3..] } 201 """ 202 192 203 tri_atts = mesh_dict['triangle_tags'] 193 204 tagged_elements = {} … … 198 209 tagged_elements.setdefault(tri_atts[tri_att_index], 199 210 []).append(tri_att_index) 211 200 212 return tagged_elements 213 201 214 202 215 def pmesh_dict_to_tag_dict(mesh_dict): … … 204 217 to a dictionary of tags, indexed with volume id and face number. 205 218 """ 219 206 220 triangles = mesh_dict['triangles'] 207 221 sides = calc_sides(triangles) 208 222 tag_dict = {} 209 for seg, tag in map(None, mesh_dict['segments'], 210 mesh_dict['segment_tags']): 223 for seg, tag in map(None, mesh_dict['segments'], mesh_dict['segment_tags']): 211 224 v1 = int(seg[0]) 212 225 v2 = int(seg[1]) … … 222 235 223 236 def calc_sides(triangles): 224 #Build dictionary mapping from sides (2-tuple of points) 225 #to left hand side neighbouring triangle 237 '''Build dictionary mapping from sides (2-tuple of points) 238 to left hand side neighbouring triangle 239 ''' 240 226 241 sides = {} 242 227 243 for id, triangle in enumerate(triangles): 228 244 a = int(triangle[0]) 229 245 b = int(triangle[1]) 230 246 c = int(triangle[2]) 247 231 248 sides[a,b] = (id, 2) #(id, face) 232 249 sides[b,c] = (id, 0) #(id, face) 233 250 sides[c,a] = (id, 1) #(id, face) 251 234 252 return sides 253 -
branches/numpy/anuga/abstract_2d_finite_volumes/quantity.py
r6244 r6304 23 23 from anuga.caching import cache 24 24 25 import Numeric as num 25 import anuga.utilities.numerical_tools as aunt 26 27 import numpy as num 26 28 27 29 … … 43 45 if vertex_values is None: 44 46 N = len(domain) # number_of_elements 45 self.vertex_values = num.zeros((N, 3), num. Float)47 self.vertex_values = num.zeros((N, 3), num.float) 46 48 else: 47 self.vertex_values = num.array(vertex_values, num. Float)49 self.vertex_values = num.array(vertex_values, num.float) 48 50 49 51 N, V = self.vertex_values.shape … … 57 59 58 60 # Allocate space for other quantities 59 self.centroid_values = num.zeros(N, num. Float)60 self.edge_values = num.zeros((N, 3), num. Float)61 self.centroid_values = num.zeros(N, num.float) 62 self.edge_values = num.zeros((N, 3), num.float) 61 63 62 64 # Allocate space for Gradient 63 self.x_gradient = num.zeros(N, num. Float)64 self.y_gradient = num.zeros(N, num. Float)65 self.x_gradient = num.zeros(N, num.float) 66 self.y_gradient = num.zeros(N, num.float) 65 67 66 68 # Allocate space for Limiter Phi 67 self.phi = num.zeros(N, num. Float)69 self.phi = num.zeros(N, num.float) 68 70 69 71 # Intialise centroid and edge_values … … 72 74 # Allocate space for boundary values 73 75 L = len(domain.boundary) 74 self.boundary_values = num.zeros(L, num. Float)76 self.boundary_values = num.zeros(L, num.float) 75 77 76 78 # Allocate space for updates of conserved quantities by … … 78 80 79 81 # Allocate space for update fields 80 self.explicit_update = num.zeros(N, num. Float )81 self.semi_implicit_update = num.zeros(N, num. Float )82 self.centroid_backup_values = num.zeros(N, num. Float)82 self.explicit_update = num.zeros(N, num.float ) 83 self.semi_implicit_update = num.zeros(N, num.float ) 84 self.centroid_backup_values = num.zeros(N, num.float) 83 85 84 86 self.set_beta(1.0) … … 316 318 317 319 numeric: 318 Compatible list, Numeric array (see below) or constant.320 Compatible list, numeric array (see below) or constant. 319 321 If callable it will treated as a function (see below) 320 322 If instance of another Quantity it will be treated as such. … … 357 359 358 360 In case of location == 'centroids' the dimension values must 359 be a list of a Numerical array of length N,361 be a list of a numerical array of length N, 360 362 N being the number of elements. 361 363 Otherwise it must be of dimension Nx3 … … 458 460 459 461 msg = 'Indices must be a list or None' 460 assert type(indices) in [ListType, NoneType, num.ArrayType], msg 462 assert (type(indices) in [ListType, NoneType] 463 or isinstance(indices, num.ndarray)), msg 461 464 462 465 # Determine which 'set_values_from_...' to use 463 466 if numeric is not None: 464 if type(numeric) in [FloatType, IntType, LongType]: 465 self.set_values_from_constant(numeric, location, 466 indices, verbose) 467 elif type(numeric) in [num.ArrayType, ListType]: 467 if isinstance(numeric, num.ndarray) or isinstance(numeric, list): 468 468 self.set_values_from_array(numeric, location, indices, 469 469 use_cache=use_cache, verbose=verbose) … … 479 479 indices, verbose=verbose, 480 480 use_cache=use_cache) 481 # if (isinstance(numeric, float) or isinstance(numeric, int) 482 # or isinstance(numeric, long)): 481 483 else: 482 msg = 'Illegal type for argument numeric: %s' % str(numeric) 483 raise msg 484 try: 485 numeric = float(numeric) 486 except ValueError: 487 msg = ("Illegal type for variable 'numeric': " 488 "%s, shape=%s\n%s" 489 % (type(numeric), numeric.shape, str(numeric))) 490 msg += ('\ntype(numeric)==FloatType is %s' 491 % str(type(numeric)==FloatType)) 492 msg += ('\nisinstance(numeric, float)=%s' 493 % str(isinstance(numeric, float))) 494 msg += ('\nisinstance(numeric, num.ndarray)=%s' 495 % str(isinstance(numeric, num.ndarray))) 496 raise Exception, msg 497 self.set_values_from_constant(numeric, location, 498 indices, verbose) 499 elif quantity is not None: 500 if type(numeric) in [FloatType, IntType, LongType]: 501 self.set_values_from_constant(numeric, location, 502 indices, verbose) 503 else: 504 msg = ("Illegal type for variable 'numeric': %s, shape=%s\n%s" 505 % (type(numeric), numeric.shape, str(numeric))) 506 msg += ('\ntype(numeric)==FloatType is %s' 507 % str(type(numeric)==FloatType)) 508 msg += ('\nisinstance(numeric, float)=%s' 509 % str(isinstance(numeric, float))) 510 msg += ('\nisinstance(numeric, num.ndarray)=%s' 511 % str(isinstance(numeric, num.ndarray))) 512 raise Exception, msg 484 513 elif quantity is not None: 485 514 self.set_values_from_quantity(quantity, location, indices, verbose) … … 583 612 """Set values for quantity 584 613 585 values: Numeric array614 values: numeric array 586 615 location: Where values are to be stored. 587 616 Permissible options are: vertices, centroid, unique vertices … … 593 622 594 623 In case of location == 'centroid' the dimension values must 595 be a list of a Numerical array of length N, N being the number624 be a list of a numerical array of length N, N being the number 596 625 of elements. 597 626 … … 607 636 """ 608 637 609 values = num.array(values, num. Float)638 values = num.array(values, num.float) 610 639 611 640 if indices is not None: 612 indices = num.array(indices, num. Int)641 indices = num.array(indices, num.int) 613 642 msg = ('Number of values must match number of indices: You ' 614 643 'specified %d values and %d indices' … … 637 666 'Values array must be 1d') 638 667 639 self.set_vertex_values(values.flat , indices=indices,668 self.set_vertex_values(values.flatten(), indices=indices, 640 669 use_cache=use_cache, verbose=verbose) 641 670 else: … … 788 817 from anuga.coordinate_transforms.geo_reference import Geo_reference 789 818 790 points = ensure_numeric(points, num. Float)791 values = ensure_numeric(values, num. Float)819 points = ensure_numeric(points, num.float) 820 values = ensure_numeric(values, num.float) 792 821 793 822 if location != 'vertices': … … 1080 1109 1081 1110 # Ensure that interpolation points is either a list of 1082 # points, Nx2 array, or geospatial and convert to Numeric array1111 # points, Nx2 array, or geospatial and convert to numeric array 1083 1112 if isinstance(interpolation_points, Geospatial_data): 1084 1113 # Ensure interpolation points are in absolute UTM coordinates … … 1119 1148 """Get values for quantity 1120 1149 1121 Extract values for quantity as a Numeric array.1150 Extract values for quantity as a numeric array. 1122 1151 1123 1152 Inputs: … … 1137 1166 1138 1167 In case of location == 'centroids' the dimension of returned 1139 values will be a list or a Numerical array of length N, N being1168 values will be a list or a numerical array of length N, N being 1140 1169 the number of elements. 1141 1170 … … 1173 1202 'edges', 'unique vertices']: 1174 1203 msg = 'Invalid location: %s' % location 1175 raise msg1204 raise Exception, msg 1176 1205 1177 1206 import types 1178 1207 1179 1208 assert type(indices) in [types.ListType, types.NoneType, 1180 num. ArrayType], \1181 'Indices must be a list or None' 1209 num.ndarray], \ 1210 'Indices must be a list or None' #??# 1182 1211 1183 1212 if location == 'centroids': … … 1210 1239 sum += self.vertex_values[triangle_id, vertex_id] 1211 1240 vert_values.append(sum / len(triangles)) 1212 return num.array(vert_values, num. Float)1241 return num.array(vert_values, num.float) 1213 1242 else: 1214 1243 if (indices is None): … … 1236 1265 1237 1266 # Check that A can be converted to array and is of appropriate dim 1238 A = ensure_numeric(A, num. Float)1267 A = ensure_numeric(A, num.float) 1239 1268 assert len(A.shape) == 1 1240 1269 … … 1336 1365 1337 1366 if precision is None: 1338 precision = num. Float1367 precision = num.float 1339 1368 1340 1369 if smooth is True: … … 1342 1371 V = self.domain.get_triangles() 1343 1372 N = self.domain.number_of_full_nodes # Ignore ghost nodes if any 1344 A = num.zeros(N, num. Float)1373 A = num.zeros(N, num.float) 1345 1374 points = self.domain.get_nodes() 1346 1375 … … 1360 1389 if current_node == N: 1361 1390 msg = 'Current node exceeding number of nodes (%d) ' % N 1362 raise msg1391 raise Exception, msg 1363 1392 1364 1393 k += 1 … … 1381 1410 V = self.domain.get_disconnected_triangles() 1382 1411 points = self.domain.get_vertex_coordinates() 1383 A = self.vertex_values.flat .astype(precision)1412 A = self.vertex_values.flatten().astype(precision) 1384 1413 1385 1414 # Return -
branches/numpy/anuga/abstract_2d_finite_volumes/quantity_ext.c
r5897 r6304 11 11 12 12 #include "Python.h" 13 #include " Numeric/arrayobject.h"13 #include "numpy/arrayobject.h" 14 14 #include "math.h" 15 15 -
branches/numpy/anuga/abstract_2d_finite_volumes/region.py
r6145 r6304 8 8 # FIXME (DSG-DSG) add better comments 9 9 10 import Numericas num10 import numpy as num 11 11 12 12 -
branches/numpy/anuga/abstract_2d_finite_volumes/test_domain.py
r6195 r6304 7 7 from anuga.config import epsilon 8 8 9 import Numericas num9 import numpy as num 10 10 11 11 … … 65 65 66 66 67 assert domain.get_conserved_quantities(0, edge=1) == 0.67 assert num.alltrue(domain.get_conserved_quantities(0, edge=1) == 0.) 68 68 69 69 … … 345 345 346 346 347 A = num.array([[1,2,3], [5,5,-5], [0,0,9], [-6,3,3]], num. Float)348 B = num.array([[2,4,4], [3,2,1], [6,-3,4], [4,5,-1]], num. Float)347 A = num.array([[1,2,3], [5,5,-5], [0,0,9], [-6,3,3]], num.float) 348 B = num.array([[2,4,4], [3,2,1], [6,-3,4], [4,5,-1]], num.float) 349 349 350 350 #print A … … 613 613 614 614 sem = num.array([1.,1.,1.,1.])/num.array([1, 2, 3, 4]) 615 denom = num.ones(4, num. Float)-domain.timestep*sem615 denom = num.ones(4, num.float)-domain.timestep*sem 616 616 617 617 # x = array([1, 2, 3, 4]) + array( [.4,.3,.2,.1] ) -
branches/numpy/anuga/abstract_2d_finite_volumes/test_ermapper.py
r6145 r6304 7 7 from os import remove 8 8 9 import Numericas num9 import numpy as num 10 10 11 11 … … 45 45 46 46 # Write test data 47 ermapper_grids.write_ermapper_data(original_grid, filename, num. Float64)47 ermapper_grids.write_ermapper_data(original_grid, filename, num.float64) 48 48 49 49 # Read in the test data 50 new_grid = ermapper_grids.read_ermapper_data(filename, num. Float64)50 new_grid = ermapper_grids.read_ermapper_data(filename, num.float64) 51 51 52 52 # Check that the test data that has been read in matches the original data -
branches/numpy/anuga/abstract_2d_finite_volumes/test_general_mesh.py
r6174 r6304 10 10 from anuga.coordinate_transforms.geo_reference import Geo_reference 11 11 12 import Numericas num12 import numpy as num 13 13 14 14 … … 59 59 60 60 #bac, bce, ecf, dbe, daf, dae 61 triangles = num.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]], num. Int)61 triangles = num.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]], num.int) 62 62 63 63 domain = General_mesh(nodes, triangles, … … 277 277 geo_reference = geo) 278 278 node = domain.get_node(2) 279 self.assertEqual(c, node) 279 #self.assertEqual(c, node) 280 self.failUnless(num.alltrue(c == node)) 280 281 281 282 node = domain.get_node(2, absolute=True) 282 self.assertEqual(nodes_absolute[2], node) 283 #self.assertEqual(nodes_absolute[2], node) 284 self.failUnless(num.alltrue(nodes_absolute[2] == node)) 283 285 284 286 node = domain.get_node(2, absolute=True) 285 self.assertEqual(nodes_absolute[2], node) 287 #self.assertEqual(nodes_absolute[2], node) 288 self.failUnless(num.alltrue(nodes_absolute[2] == node)) 286 289 287 290 -
branches/numpy/anuga/abstract_2d_finite_volumes/test_generic_boundary_conditions.py
r6195 r6304 8 8 from anuga.config import epsilon 9 9 10 import Numericas num10 import numpy as num 11 11 12 12 -
branches/numpy/anuga/abstract_2d_finite_volumes/test_ghost.py
r6195 r6304 6 6 from anuga.abstract_2d_finite_volumes.domain import * 7 7 from anuga.config import epsilon 8 9 import numpy as num 8 10 9 11 … … 40 42 41 43 42 assert domain.get_conserved_quantities(0, edge=1) == 0.44 assert num.alltrue(domain.get_conserved_quantities(0, edge=1) == 0.) 43 45 44 46 -
branches/numpy/anuga/abstract_2d_finite_volumes/test_neighbour_mesh.py
r6174 r6304 18 18 from anuga.utilities.numerical_tools import ensure_numeric 19 19 20 import Numericas num20 import numpy as num 21 21 22 22 … … 988 988 [ 75735.4765625 , 23762.00585938], 989 989 [ 52341.70703125, 38563.39453125]] 990 991 ##points = ensure_numeric(points, Int)/1000 # Simplify for ease of interpretation992 990 993 991 triangles = [[19, 0,15], … … 1092 1090 [ 35406.3359375 , 79332.9140625 ]] 1093 1091 1094 scaled_points = ensure_numeric(points, num. Int)/1000 # Simplify for ease of interpretation1092 scaled_points = ensure_numeric(points, num.int)/1000 # Simplify for ease of interpretation 1095 1093 1096 1094 triangles = [[ 0, 1, 2], -
branches/numpy/anuga/abstract_2d_finite_volumes/test_pmesh2domain.py
r6191 r6304 14 14 from anuga.pmesh.mesh import importMeshFromFile 15 15 16 import Numericas num16 import numpy as num 17 17 18 18 -
branches/numpy/anuga/abstract_2d_finite_volumes/test_quantity.py
r6195 r6304 15 15 from anuga.utilities.polygon import * 16 16 17 import Numericas num17 import numpy as num 18 18 19 19 … … 1765 1765 quantity = Quantity(self.mesh4) 1766 1766 1767 quantity.vertex_values = num.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]], num. Float)1767 quantity.vertex_values = num.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]], num.float) 1768 1768 1769 1769 quantity.interpolate_from_vertices_to_edges() … … 1781 1781 [3., 2.5, 1.5], 1782 1782 [3.5, 4.5, 3.], 1783 [2.5, 3.5, 2]], num. Float)1783 [2.5, 3.5, 2]], num.float) 1784 1784 1785 1785 quantity.interpolate_from_edges_to_vertices() … … 1835 1835 1836 1836 sem = num.array([1.,1.,1.,1.])/num.array([1, 2, 3, 4]) 1837 denom = num.ones(4, num. Float)-timestep*sem1837 denom = num.ones(4, num.float)-timestep*sem 1838 1838 1839 1839 x = num.array([1, 2, 3, 4])/denom … … 1859 1859 1860 1860 sem = num.array([1.,1.,1.,1.])/num.array([1, 2, 3, 4]) 1861 denom = num.ones(4, num. Float)-timestep*sem1861 denom = num.ones(4, num.float)-timestep*sem 1862 1862 1863 1863 x = num.array([1., 2., 3., 4.]) … … 1901 1901 1902 1902 bed = domain.quantities['elevation'].vertex_values 1903 stage = num.zeros(bed.shape, num. Float)1903 stage = num.zeros(bed.shape, num.float) 1904 1904 1905 1905 h = 0.03 … … 1985 1985 1986 1986 bed = domain.quantities['elevation'].vertex_values 1987 stage = num.zeros(bed.shape, num. Float)1987 stage = num.zeros(bed.shape, num.float) 1988 1988 1989 1989 h = 0.03 … … 1999 1999 stage = domain.quantities['stage'] 2000 2000 A, V = stage.get_vertex_values(xy=False, smooth=False) 2001 Q = stage.vertex_values.flat 2001 Q = stage.vertex_values.flatten() 2002 2002 2003 2003 for k in range(8): … … 2511 2511 suite = unittest.makeSuite(Test_Quantity, 'test') 2512 2512 #suite = unittest.makeSuite(Test_Quantity, 'test_set_values_from_file_using_polygon') 2513 2514 #suite = unittest.makeSuite(Test_Quantity, 'test_set_vertex_values_using_general_interface_subset_and_geo')2515 #print "restricted test"2516 #suite = unittest.makeSuite(Test_Quantity,'verbose_test_set_values_from_UTM_pts')2517 2513 runner = unittest.TextTestRunner() 2518 2514 runner.run(suite) -
branches/numpy/anuga/abstract_2d_finite_volumes/test_region.py
r6145 r6304 8 8 #from anuga.config import epsilon 9 9 10 import Numericas num10 import numpy as num 11 11 12 12 … … 42 42 43 43 def test_region_tags(self): 44 """ 45 get values based on triangle lists. 46 """ 47 from mesh_factory import rectangular 48 from shallow_water import Domain 49 50 #Create basic mesh 51 points, vertices, boundary = rectangular(1, 3) 52 53 #Create shallow water domain 54 domain = Domain(points, vertices, boundary) 55 domain.build_tagged_elements_dictionary({'bottom':[0,1], 56 'top':[4,5], 57 'all':[0,1,2,3,4,5]}) 58 44 """get values based on triangle lists.""" 45 46 from mesh_factory import rectangular 47 from shallow_water import Domain 48 49 #Create basic mesh 50 points, vertices, boundary = rectangular(1, 3) 51 52 #Create shallow water domain 53 domain = Domain(points, vertices, boundary) 54 domain.build_tagged_elements_dictionary({'bottom': [0,1], 55 'top': [4,5], 56 'all': [0,1,2,3,4,5]}) 59 57 60 58 #Set friction … … 65 63 b = Set_region('top', 'friction', 1.0) 66 64 domain.set_region([a, b]) 67 #print domain.quantities['friction'].get_values() 68 assert num.allclose(domain.quantities['friction'].get_values(),\ 69 [[ 0.09, 0.09, 0.09], 70 [ 0.09, 0.09, 0.09], 71 [ 0.07, 0.07, 0.07], 72 [ 0.07, 0.07, 0.07], 73 [ 1.0, 1.0, 1.0], 74 [ 1.0, 1.0, 1.0]]) 65 66 expected = [[ 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]] 72 msg = ("\ndomain.quantities['friction']=%s\nexpected value=%s" 73 % (str(domain.quantities['friction'].get_values()), 74 str(expected))) 75 assert num.allclose(domain.quantities['friction'].get_values(), 76 expected), msg 75 77 76 78 #c = Add_Value_To_region('all', 'friction', 10.0) … … 126 128 127 129 def test_unique_vertices(self): 128 """ 129 get values based on triangle lists. 130 """ 130 """get values based on triangle lists.""" 131 131 132 from mesh_factory import rectangular 132 133 from shallow_water import Domain … … 147 148 a = Set_region('bottom', 'friction', 0.09, location = 'unique vertices') 148 149 domain.set_region(a) 149 #print domain.quantities['friction'].get_values() 150 assert num.allclose(domain.quantities['friction'].get_values(),\ 150 assert num.allclose(domain.quantities['friction'].get_values(), 151 151 [[ 0.09, 0.09, 0.09], 152 152 [ 0.09, 0.09, 0.09], … … 217 217 #print domain.quantities['friction'].get_values() 218 218 frict_points = domain.quantities['friction'].get_values() 219 assert num.allclose(frict_points[0],\ 220 [ calc_frict, calc_frict, calc_frict]) 221 assert num.allclose(frict_points[1],\ 222 [ calc_frict, calc_frict, calc_frict]) 219 expected = [calc_frict, calc_frict, calc_frict] 220 msg = ('frict_points[0]=%s\nexpected=%s' % (str(frict_points[0]), 221 str(expected))) 222 assert num.allclose(frict_points[0], expected), msg 223 msg = ('frict_points[1]=%s\nexpected=%s' % (str(frict_points[1]), 224 str(expected))) 225 assert num.allclose(frict_points[1], expected), msg 223 226 224 227 def test_unique_vertices_average_loc_unique_vert(self): … … 262 265 #------------------------------------------------------------- 263 266 if __name__ == "__main__": 264 suite = unittest.makeSuite(Test_Region, 'test')267 suite = unittest.makeSuite(Test_Region, 'test') 265 268 runner = unittest.TextTestRunner() 266 269 runner.run(suite) -
branches/numpy/anuga/abstract_2d_finite_volumes/test_util.py
r6175 r6304 22 22 import string 23 23 24 import Numericas num24 import numpy as num 25 25 26 26 … … 630 630 q1 = F(t+60, point_id=id) 631 631 632 if q0 == NAN:632 if num.alltrue(q0 == NAN): 633 633 actual = q0 634 634 else: … … 641 641 #print "actual", actual 642 642 #print 643 if q0 == NAN:644 self.failUnless( q == actual, 'Fail!')643 if num.alltrue(q0 == NAN): 644 self.failUnless(num.alltrue(q == actual), 'Fail!') 645 645 else: 646 646 assert num.allclose(q, actual) … … 1181 1181 #FIXME: Division is not expected to work for integers. 1182 1182 #This must be caught. 1183 foo = num.array([[1,2,3], [4,5,6]], num. Float)1184 1185 bar = num.array([[-1,0,5], [6,1,1]], num. Float)1183 foo = num.array([[1,2,3], [4,5,6]], num.float) 1184 1185 bar = num.array([[-1,0,5], [6,1,1]], num.float) 1186 1186 1187 1187 D = {'X': foo, 'Y': bar} … … 1201 1201 1202 1202 # make an error for zero on zero 1203 # this is really an error in Numeric, SciPy core can handle it1203 # this is really an error in numeric, SciPy core can handle it 1204 1204 # Z = apply_expression_to_dictionary('0/Y', D) 1205 1205 -
branches/numpy/anuga/abstract_2d_finite_volumes/util.py
r6194 r6304 27 27 from anuga.config import netcdf_mode_r, netcdf_mode_w, netcdf_mode_a 28 28 29 import Numericas num29 import numpy as num 30 30 31 31 … … 554 554 expression e.g. by overloading 555 555 556 Due to a limitation with Numeric, this can not evaluate 0/0556 Due to a limitation with numeric, this can not evaluate 0/0 557 557 In general, the user can fix by adding 1e-30 to the numerator. 558 558 SciPy core can handle this situation. … … 789 789 - easting, northing, name , elevation? 790 790 - OR (this is not yet done) 791 - structure which can be converted to a Numeric array,791 - structure which can be converted to a numeric array, 792 792 such as a geospatial data object 793 793 … … 1255 1255 n0 = int(n0) 1256 1256 m = len(locations) 1257 model_time = num.zeros((n0, m, p), num. Float)1258 stages = num.zeros((n0, m, p), num. Float)1259 elevations = num.zeros((n0, m, p), num. Float)1260 momenta = num.zeros((n0, m, p), num. Float)1261 xmom = num.zeros((n0, m, p), num. Float)1262 ymom = num.zeros((n0, m, p), num. Float)1263 speed = num.zeros((n0, m, p), num. Float)1264 bearings = num.zeros((n0, m, p), num. Float)1265 due_east = 90.0*num.ones((n0, 1), num. Float)1266 due_west = 270.0*num.ones((n0, 1), num. Float)1267 depths = num.zeros((n0, m, p), num. Float)1268 eastings = num.zeros((n0, m, p), num. Float)1257 model_time = num.zeros((n0, m, p), num.float) 1258 stages = num.zeros((n0, m, p), num.float) 1259 elevations = num.zeros((n0, m, p), num.float) 1260 momenta = num.zeros((n0, m, p), num.float) 1261 xmom = num.zeros((n0, m, p), num.float) 1262 ymom = num.zeros((n0, m, p), num.float) 1263 speed = num.zeros((n0, m, p), num.float) 1264 bearings = num.zeros((n0, m, p), num.float) 1265 due_east = 90.0*num.ones((n0, 1), num.float) 1266 due_west = 270.0*num.ones((n0, 1), num.float) 1267 depths = num.zeros((n0, m, p), num.float) 1268 eastings = num.zeros((n0, m, p), num.float) 1269 1269 min_stages = [] 1270 1270 max_stages = [] … … 1278 1278 min_speeds = [] 1279 1279 max_depths = [] 1280 model_time_plot3d = num.zeros((n0, m), num. Float)1281 stages_plot3d = num.zeros((n0, m), num. Float)1282 eastings_plot3d = num.zeros((n0, m),num. Float)1280 model_time_plot3d = num.zeros((n0, m), num.float) 1281 stages_plot3d = num.zeros((n0, m), num.float) 1282 eastings_plot3d = num.zeros((n0, m),num.float) 1283 1283 if time_unit is 'mins': scale = 60.0 1284 1284 if time_unit is 'hours': scale = 3600.0 … … 1832 1832 """ 1833 1833 1834 xc = num.zeros(triangles.shape[0], num. Float) # Space for centroid info1834 xc = num.zeros(triangles.shape[0], num.float) # Space for centroid info 1835 1835 1836 1836 for k in range(triangles.shape[0]): … … 2119 2119 #add tide to stage if provided 2120 2120 if quantity == 'stage': 2121 quantity_value[quantity] = num.array(quantity_value[quantity], num. Float) \2121 quantity_value[quantity] = num.array(quantity_value[quantity], num.float) \ 2122 2122 + directory_add_tide 2123 2123 … … 2469 2469 2470 2470 #convert to array for file_function 2471 points_array = num.array(points,num. Float)2471 points_array = num.array(points,num.float) 2472 2472 2473 2473 points_array = ensure_absolute(points_array)
Note: See TracChangeset
for help on using the changeset viewer.