- Timestamp:
- Nov 6, 2008, 12:28:22 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source_numpy_conversion/anuga/abstract_2d_finite_volumes/quantity.py
r5866 r5899 1 ## Automatically adapted for numpy.oldnumeric Oct 28, 2008 by alter_code1.py 2 1 3 """Class Quantity - Implements values at each triangular element 2 4 … … 15 17 """ 16 18 17 from Numeric import array, zeros, Float, less, concatenate, NewAxis,\ 18 argmax, argmin, allclose, take, reshape, alltrue 19 #from numpy.oldnumeric import array, zeros, Float, less, concatenate, NewAxis,\ 20 # argmax, argmin, allclose, take, reshape, alltrue, Int 21 from numpy import array, zeros, float, less, concatenate, \ 22 argmax, argmin, allclose, take, reshape, alltrue, int 19 23 20 24 from anuga.utilities.numerical_tools import ensure_numeric, is_scalar … … 38 42 if vertex_values is None: 39 43 N = len(domain) # number_of_elements 40 self.vertex_values = zeros((N, 3), Float)44 self.vertex_values = zeros((N, 3), float) 41 45 else: 42 self.vertex_values = array(vertex_values).astype( Float)46 self.vertex_values = array(vertex_values).astype(float) 43 47 44 48 N, V = self.vertex_values.shape … … 57 61 58 62 # Allocate space for other quantities 59 self.centroid_values = zeros(N, Float)60 self.edge_values = zeros((N, 3), Float)63 self.centroid_values = zeros(N, float) 64 self.edge_values = zeros((N, 3), float) 61 65 62 66 # Allocate space for Gradient 63 self.x_gradient = zeros(N, Float)64 self.y_gradient = zeros(N, Float)67 self.x_gradient = zeros(N, float) 68 self.y_gradient = zeros(N, float) 65 69 66 70 # Allocate space for Limiter Phi 67 self.phi = zeros(N, Float)71 self.phi = zeros(N, float) 68 72 69 73 # Intialise centroid and edge_values … … 72 76 # Allocate space for boundary values 73 77 L = len(domain.boundary) 74 self.boundary_values = zeros(L, Float)78 self.boundary_values = zeros(L, float) 75 79 76 80 # Allocate space for updates of conserved quantities by … … 78 82 79 83 # 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)84 self.explicit_update = zeros(N, float ) 85 self.semi_implicit_update = zeros(N, float ) 86 self.centroid_backup_values = zeros(N, float) 83 87 84 88 self.set_beta(1.0) … … 382 386 from anuga.geospatial_data.geospatial_data import Geospatial_data 383 387 from types import FloatType, IntType, LongType, ListType, NoneType 384 from Numeric import ArrayType 388 ##NumPy from numpy.oldnumeric import ArrayType 389 from numpy import ndarray, float 385 390 386 391 # Treat special case: Polygon situation … … 448 453 449 454 msg = 'Indices must be a list or None' 450 assert type(indices) in [ListType, NoneType, ArrayType], msg 455 ##NumPy assert type(indices) in [ListType, NoneType, ArrayType], msg 456 assert type(indices) in [ListType, NoneType, ndarray], msg 451 457 452 458 … … 458 464 self.set_values_from_constant(numeric, 459 465 location, indices, verbose) 460 elif type(numeric) in [ArrayType, ListType]: 466 ##NumPy elif type(numeric) in [ArrayType, ListType]: 467 elif type(numeric) in [ndarray, ListType]: 461 468 self.set_values_from_array(numeric, 462 469 location, indices, verbose) … … 474 481 use_cache=use_cache) 475 482 else: 476 msg = 'Illegal type for argument numeric: %s' % str(numeric)477 raise msg483 msg = 'Illegal type for argument numeric: %s' % str(numeric) 484 raise TypeError, msg 478 485 479 486 elif quantity is not None: … … 610 617 """ 611 618 612 from Numeric import array, Float, Int, allclose 613 614 values = array(values).astype(Float) 619 # from numpy.oldnumeric import array, Float, Int, allclose 620 from numpy import array, float, int, allclose 621 622 values = array(values).astype(float) 615 623 616 624 if indices is not None: 617 indices = array(indices).astype( Int)625 indices = array(indices).astype(int) 618 626 msg = 'Number of values must match number of indices:' 619 627 msg += ' You specified %d values and %d indices'\ … … 643 651 'Values array must be 1d' 644 652 645 self.set_vertex_values(values. flat, indices=indices)653 self.set_vertex_values(values.ravel(), indices=indices) 646 654 647 655 else: … … 676 684 A = q.vertex_values 677 685 678 from Numeric import allclose 686 # from numpy.oldnumeric import allclose 687 from numpy import allclose 679 688 msg = 'Quantities are defined on different meshes. '+\ 680 689 'This might be a case for implementing interpolation '+\ … … 717 726 718 727 V = take(self.domain.get_centroid_coordinates(), indices) 728 print 'V=%s' % str(V) 719 729 self.set_values(f(V[:,0], V[:,1]), 720 730 location=location, … … 780 790 781 791 782 points = ensure_numeric(points, Float)783 values = ensure_numeric(values, Float)792 points = ensure_numeric(points, float) 793 values = ensure_numeric(values, float) 784 794 785 795 if location != 'vertices': … … 1118 1128 """ 1119 1129 1120 from Numeric import take 1130 # from numpy.oldnumeric import take 1131 from numpy import take 1121 1132 1122 1133 # FIXME (Ole): I reckon we should have the option of passing a … … 1143 1154 raise msg 1144 1155 1145 import types, Numeric 1146 assert type(indices) in [types.ListType, types.NoneType, 1147 Numeric.ArrayType],\ 1156 # import types, numpy.oldnumeric as Numeric 1157 import types 1158 from numpy import ndarray 1159 1160 assert type(indices) in [types.ListType, types.NoneType, ndarray], \ 1148 1161 'Indices must be a list or None' 1149 1162 … … 1196 1209 """ 1197 1210 1198 from Numeric import array, Float 1211 # from numpy.oldnumeric import array, Float 1212 from numpy import array, float 1199 1213 1200 1214 # Assert that A can be converted to a Numeric array of appropriate dim 1201 A = ensure_numeric(A, Float)1215 A = ensure_numeric(A, float) 1202 1216 1203 1217 # print 'SHAPE A', A.shape … … 1273 1287 """ 1274 1288 1275 from Numeric import concatenate, zeros, Float, Int, array, reshape 1289 # from numpy.oldnumeric import concatenate, zeros, Float, Int, array, reshape 1290 from numpy import concatenate, zeros, float, int, array, reshape 1276 1291 1277 1292 … … 1284 1299 1285 1300 if precision is None: 1286 precision = Float1301 precision = float 1287 1302 1288 1303 … … 1293 1308 V = self.domain.get_triangles() 1294 1309 N = self.domain.number_of_full_nodes # Ignore ghost nodes if any 1295 A = zeros(N, Float)1310 A = zeros(N, float) 1296 1311 points = self.domain.get_nodes() 1297 1312 … … 1343 1358 V = self.domain.get_disconnected_triangles() 1344 1359 points = self.domain.get_vertex_coordinates() 1345 A = self.vertex_values. flat.astype(precision)1360 A = self.vertex_values.ravel().astype(precision) 1346 1361 1347 1362
Note: See TracChangeset
for help on using the changeset viewer.