Changeset 7590
- Timestamp:
- Dec 10, 2009, 12:43:43 PM (15 years ago)
- Location:
- anuga_core/source/anuga/abstract_2d_finite_volumes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py
r7573 r7590 1142 1142 1143 1143 1144 The returned values will have the leading dimension equal to length of the indices list or1145 N (all values) if indices is None.1144 The returned values will have the leading dimension equal to 1145 length of the indices list or N (all values) if indices is None. 1146 1146 1147 1147 In case of location == 'centroids' the dimension of returned … … 1157 1157 1158 1158 Indices is the set of element ids that the operation applies to. 1159 If indices is None (or omitted) all elements are returned as 1160 a copy of the relevant array. If performance is critical, 1161 use arrays domain.centroid_values, domain.vertex_values and 1162 domain.edge_values directly. 1159 1163 1160 1164 The values will be stored in elements following their … … 1178 1182 # Edges have already been deprecated in set_values, see changeset:5521, 1179 1183 # but *might* be useful in get_values. Any thoughts anyone? 1180 # YES (Ole): Edge values are necessary for volumetric balance check and inflow boundary. Keep them. 1184 # YES (Ole): Edge values are necessary for volumetric balance 1185 # check and inflow boundary. Keep them! 1181 1186 1182 1187 if location not in ['vertices', 'centroids', … … 1185 1190 raise Exception, msg 1186 1191 1187 import types 1188 1189 msg = "'indices' must be a list, array or None" 1192 1193 msg = '\'indices\' must be a list, array or None' 1190 1194 assert isinstance(indices, (NoneType, list, num.ndarray)), msg 1191 1195 1192 1196 if location == 'centroids': 1193 if (indices == None): 1194 indices = range(len(self)) 1195 return num.take(self.centroid_values, indices, axis=0) 1197 if indices is None: 1198 return self.centroid_values.copy() 1199 else: 1200 return num.take(self.centroid_values, indices, axis=0) 1196 1201 elif location == 'edges': 1197 if (indices == None): 1198 indices = range(len(self)) 1199 return num.take(self.edge_values, indices, axis=0) 1202 if indices is None: 1203 return self.edge_values.copy() 1204 else: 1205 return num.take(self.edge_values, indices, axis=0) 1200 1206 elif location == 'unique vertices': 1201 if (indices == None):1207 if indices is None: 1202 1208 indices=range(self.domain.get_number_of_nodes()) 1203 1209 vert_values = [] … … 1221 1227 return num.array(vert_values, num.float) 1222 1228 else: 1223 if (indices is None): 1224 indices = range(len(self)) 1225 return num.take(self.vertex_values, indices, axis=0) 1229 if indices is None: 1230 return self.vertex_values.copy() 1231 else: 1232 return num.take(self.vertex_values, indices, axis=0) 1226 1233 1227 1234 ## -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py
r7543 r7590 2165 2165 indices = [1,5] 2166 2166 quantity.set_values(value, 2167 location ='unique vertices',2168 indices =indices)2167 location='unique vertices', 2168 indices=indices) 2169 2169 #print "quantity.centroid_values",quantity.centroid_values 2170 2170 assert num.allclose(quantity.vertex_values[0], [0,7,0]) … … 2202 2202 answer = [0.5,2,4,5,0,1,3,4.5] 2203 2203 assert num.allclose(answer, 2204 quantity.get_values(location ='unique vertices'))2204 quantity.get_values(location='unique vertices')) 2205 2205 2206 2206 indices = [0,5,3] … … 2208 2208 assert num.allclose(answer, 2209 2209 quantity.get_values(indices=indices, 2210 location ='unique vertices'))2210 location='unique vertices')) 2211 2211 #print "quantity.centroid_values",quantity.centroid_values 2212 2212 #print "quantity.get_values(location = 'centroids') ",\ … … 2237 2237 quantity.set_values(lambda x, y: x+2*y) #2 4 4 6 2238 2238 2239 assert num.allclose(quantity.get_values(location='centroids'), [2,4,4,6]) 2240 assert num.allclose(quantity.get_values(location='centroids', indices=[1,3]), [4,6]) 2241 2242 2243 assert num.allclose(quantity.get_values(location='vertices'), [[4,0,2], 2244 [4,2,6], 2245 [6,2,4], 2246 [8,4,6]]) 2247 2248 assert num.allclose(quantity.get_values(location='vertices', indices=[1,3]), [[4,2,6], 2249 [8,4,6]]) 2250 2251 2252 assert num.allclose(quantity.get_values(location='edges'), [[1,3,2], 2253 [4,5,3], 2254 [3,5,4], 2255 [5,7,6]]) 2256 assert num.allclose(quantity.get_values(location='edges', indices=[1,3]), 2239 assert num.allclose(quantity.get_values(location='centroids'), 2240 [2,4,4,6]) 2241 2242 assert num.allclose(quantity.get_values(location='centroids', 2243 indices=[1,3]), [4,6]) 2244 2245 2246 assert num.allclose(quantity.get_values(location='vertices'), 2247 [[4,0,2], 2248 [4,2,6], 2249 [6,2,4], 2250 [8,4,6]]) 2251 2252 assert num.allclose(quantity.get_values(location='vertices', 2253 indices=[1,3]), [[4,2,6], 2254 [8,4,6]]) 2255 2256 2257 assert num.allclose(quantity.get_values(location='edges'), 2258 [[1,3,2], 2259 [4,5,3], 2260 [3,5,4], 2261 [5,7,6]]) 2262 assert num.allclose(quantity.get_values(location='edges', 2263 indices=[1,3]), 2257 2264 [[4,5,3], 2258 2265 [5,7,6]]) … … 2265 2272 #e: (6+6+6)/3 2266 2273 #f: 4 2267 assert num.allclose(quantity.get_values(location='unique vertices'), [0, 4, 2, 8, 6, 4]) 2268 2269 2270 2274 assert num.allclose(quantity.get_values(location='unique vertices'), 2275 [0, 4, 2, 8, 6, 4]) 2271 2276 2272 2277 … … 2306 2311 #print answer 2307 2312 #print quantity.get_values(interpolation_points=interpolation_points) 2308 assert num.allclose(answer, quantity.get_values(interpolation_points=interpolation_points, 2309 verbose=False)) 2313 assert num.allclose(answer, 2314 quantity.get_values(interpolation_points=interpolation_points, 2315 verbose=False)) 2310 2316 2311 2317 … … 2507 2513 assert num.allclose(answer_vertex_values, 2508 2514 quantity.vertex_values) 2509 #print "quantity.centroid_values",quantity.centroid_values 2510 #print "quantity.get_values(location = 'centroids') ",\ 2511 # quantity.get_values(location = 'centroids') 2515 2516 # Just another (slightly larger) test of get_values 2517 2518 assert num.allclose(quantity.get_values(location='centroids'), 2519 quantity.centroid_values) 2520 2521 2522 assert num.allclose(quantity.get_values(location='vertices'), 2523 quantity.vertex_values) 2524 2525 assert num.allclose(quantity.get_values(location='edges'), 2526 quantity.edge_values) 2527 2512 2528 2513 2529
Note: See TracChangeset
for help on using the changeset viewer.