- Timestamp:
- Jan 13, 2009, 11:51:22 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py
r5990 r6145 15 15 """ 16 16 17 from Numeric import array, zeros, Float, less, concatenate, NewAxis,\18 argmax, argmin, allclose, take, reshape, alltrue19 20 17 from anuga.utilities.numerical_tools import ensure_numeric, is_scalar 21 18 from anuga.utilities.polygon import inside_polygon … … 26 23 from anuga.config import epsilon 27 24 25 import Numeric as num 26 27 28 28 class Quantity: 29 29 … … 38 38 if vertex_values is None: 39 39 N = len(domain) # number_of_elements 40 self.vertex_values = zeros((N, 3),Float)40 self.vertex_values = num.zeros((N, 3), num.Float) 41 41 else: 42 self.vertex_values = array(vertex_values).astype(Float)42 self.vertex_values = num.array(vertex_values).astype(num.Float) 43 43 44 44 N, V = self.vertex_values.shape … … 57 57 58 58 # Allocate space for other quantities 59 self.centroid_values = zeros(N,Float)60 self.edge_values = zeros((N, 3),Float)59 self.centroid_values = num.zeros(N, num.Float) 60 self.edge_values = num.zeros((N, 3), num.Float) 61 61 62 62 # Allocate space for Gradient 63 self.x_gradient = zeros(N,Float)64 self.y_gradient = zeros(N,Float)63 self.x_gradient = num.zeros(N, num.Float) 64 self.y_gradient = num.zeros(N, num.Float) 65 65 66 66 # Allocate space for Limiter Phi 67 self.phi = zeros(N,Float)67 self.phi = num.zeros(N, num.Float) 68 68 69 69 # Intialise centroid and edge_values … … 72 72 # Allocate space for boundary values 73 73 L = len(domain.boundary) 74 self.boundary_values = zeros(L,Float)74 self.boundary_values = num.zeros(L, num.Float) 75 75 76 76 # Allocate space for updates of conserved quantities by … … 78 78 79 79 # 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)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) 83 83 84 84 self.set_beta(1.0) … … 382 382 from anuga.geospatial_data.geospatial_data import Geospatial_data 383 383 from types import FloatType, IntType, LongType, ListType, NoneType 384 from Numeric import ArrayType385 384 386 385 # Treat special case: Polygon situation … … 450 449 451 450 msg = 'Indices must be a list or None' 452 assert type(indices) in [ListType, NoneType, ArrayType], msg451 assert type(indices) in [ListType, NoneType, num.ArrayType], msg 453 452 454 453 … … 460 459 self.set_values_from_constant(numeric, 461 460 location, indices, verbose) 462 elif type(numeric) in [ ArrayType, ListType]:461 elif type(numeric) in [num.ArrayType, ListType]: 463 462 self.set_values_from_array(numeric, 464 463 location, indices, verbose) … … 612 611 """ 613 612 614 from Numeric import array, Float, Int, allclose 615 616 values = array(values).astype(Float) 613 values = num.array(values).astype(num.Float) 617 614 618 615 if indices is not None: 619 indices = array(indices).astype(Int)616 indices = num.array(indices).astype(num.Int) 620 617 msg = 'Number of values must match number of indices:' 621 618 msg += ' You specified %d values and %d indices'\ … … 642 639 643 640 elif location == 'unique vertices': 644 assert len(values.shape) == 1 or allclose(values.shape[1:], 1),\641 assert len(values.shape) == 1 or num.allclose(values.shape[1:], 1),\ 645 642 'Values array must be 1d' 646 643 … … 678 675 A = q.vertex_values 679 676 680 from Numeric import allclose681 677 msg = 'Quantities are defined on different meshes. '+\ 682 678 'This might be a case for implementing interpolation '+\ 683 679 'between different meshes.' 684 assert allclose(A.shape, self.vertex_values.shape), msg680 assert num.allclose(A.shape, self.vertex_values.shape), msg 685 681 686 682 self.set_values(A, location='vertices', … … 718 714 indices = range(len(self)) 719 715 720 V = take(self.domain.get_centroid_coordinates(), indices)716 V = num.take(self.domain.get_centroid_coordinates(), indices) 721 717 self.set_values(f(V[:,0], V[:,1]), 722 718 location=location, … … 738 734 # more robust and simple. 739 735 740 #values = reshape(values, (M,3))736 #values = num.reshape(values, (M,3)) 741 737 #self.set_values(values, 742 738 # location='vertices', … … 782 778 783 779 784 points = ensure_numeric(points, Float)785 values = ensure_numeric(values, Float)780 points = ensure_numeric(points, num.Float) 781 values = ensure_numeric(values, num.Float) 786 782 787 783 if location != 'vertices': … … 915 911 # Always return absolute indices 916 912 if mode is None or mode == 'max': 917 i = argmax(V)913 i = num.argmax(V) 918 914 elif mode == 'min': 919 i = argmin(V)915 i = num.argmin(V) 920 916 921 917 … … 1120 1116 """ 1121 1117 1122 from Numeric import take1123 1118 1124 1119 # FIXME (Ole): I reckon we should have the option of passing a … … 1145 1140 raise msg 1146 1141 1147 import types , Numeric1142 import types 1148 1143 assert type(indices) in [types.ListType, types.NoneType, 1149 Numeric.ArrayType],\1144 num.ArrayType],\ 1150 1145 'Indices must be a list or None' 1151 1146 … … 1153 1148 if (indices == None): 1154 1149 indices = range(len(self)) 1155 return take(self.centroid_values,indices)1150 return num.take(self.centroid_values,indices) 1156 1151 elif location == 'edges': 1157 1152 if (indices == None): 1158 1153 indices = range(len(self)) 1159 return take(self.edge_values,indices)1154 return num.take(self.edge_values,indices) 1160 1155 elif location == 'unique vertices': 1161 1156 if (indices == None): … … 1180 1175 sum += self.vertex_values[triangle_id, vertex_id] 1181 1176 vert_values.append(sum/len(triangles)) 1182 return Numeric.array(vert_values)1177 return num.array(vert_values) 1183 1178 else: 1184 1179 if (indices is None): 1185 1180 indices = range(len(self)) 1186 return take(self.vertex_values, indices)1181 return num.take(self.vertex_values, indices) 1187 1182 1188 1183 … … 1198 1193 """ 1199 1194 1200 from Numeric import array, Float1201 1195 1202 1196 # Assert that A can be converted to a Numeric array of appropriate dim 1203 A = ensure_numeric(A, Float)1197 A = ensure_numeric(A, num.Float) 1204 1198 1205 1199 # print 'SHAPE A', A.shape … … 1275 1269 """ 1276 1270 1277 from Numeric import concatenate, zeros, Float, Int, array, reshape1278 1279 1271 1280 1272 if smooth is None: … … 1286 1278 1287 1279 if precision is None: 1288 precision = Float1280 precision = num.Float 1289 1281 1290 1282 … … 1295 1287 V = self.domain.get_triangles() 1296 1288 N = self.domain.number_of_full_nodes # Ignore ghost nodes if any 1297 A = zeros(N,Float)1289 A = num.zeros(N, num.Float) 1298 1290 points = self.domain.get_nodes() 1299 1291
Note: See TracChangeset
for help on using the changeset viewer.