Changeset 6164
 Timestamp:
 Jan 14, 2009, 3:39:13 PM (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

anuga_core/source/anuga/fit_interpolate/test_interpolate.py
r6152 r6164 1260 1260 # interpolations in both time and space 1261 1261 1262 # Threetimesteps1262 # Eight timesteps 1263 1263 time = [1.0, 2.0, 4.0, 5.0, 7.0, 8.0, 9.0, 10.0] 1264 1264 1265 # Setup mesh used to represent fitted function1265 # Setup mesh used to represent fitted function 1266 1266 a = [0.0, 0.0] 1267 1267 b = [0.0, 2.0] … … 1272 1272 1273 1273 points = [a, b, c, d, e, f] 1274 # bac, bce, ecf, dbe1274 # bac, bce, ecf, dbe 1275 1275 triangles = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]] 1276 1276 1277 1277 1278 # New datapoints where interpolated values are sought1278 # New datapoints where interpolated values are sought 1279 1279 interpolation_points = [[ 0.0, 0.0], 1280 1280 [ 0.5, 0.5], … … 1284 1284 [ 2.8, 1.2]] 1285 1285 1286 # One quantity1287 Q = num.zeros( (8,6), num.Float)1288 1289 # Linear in time and space1286 # One quantity 1287 Q = num.zeros((8,6), num.Float) 1288 1289 # Linear in time and space 1290 1290 for i, t in enumerate(time): 1291 1291 Q[i, :] = t*linear_function(points) … … 1303 1303 1304 1304 t = time[0] 1305 for j in range( 50): #t in [1, 6]1305 for j in range(90): #t in [1, 10] 1306 1306 for id in range(len(interpolation_points)): 1307 1307 assert num.allclose(I(t, id), t*answer[id]) … … 1324 1324 1325 1325 t = time[0] 1326 for j in range( 50): #t in [1, 6]1326 for j in range(80): #t in [1, 9] 1327 1327 for id in range(len(interpolation_points)): 1328 1328 assert num.allclose(I(t, id), t*answer[id]) 1329 t += 0.1 1330 1331 1332 1333 def test_interpolation_interface_with_time_limit(self): 1334 """test_interpolation_interface_with_time_limit 1335 1336 Test spatiotemporal interpolation 1337 Test that spatio temporal function performs the correct 1338 interpolations in both time and space 1339 """ 1340 1341 #fixme: not done 1342 1343 # Eight timesteps 1344 time = [1.0, 2.0, 4.0, 5.0, 7.0, 8.0, 9.0, 10.0] 1345 1346 # Setup mesh used to represent fitted function 1347 a = [0.0, 0.0] 1348 b = [0.0, 2.0] 1349 c = [2.0, 0.0] 1350 d = [0.0, 4.0] 1351 e = [2.0, 2.0] 1352 f = [4.0, 0.0] 1353 1354 points = [a, b, c, d, e, f] 1355 # bac, bce, ecf, dbe 1356 triangles = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]] 1357 1358 1359 # New datapoints where interpolated values are sought 1360 interpolation_points = [[ 0.0, 0.0], 1361 [ 0.5, 0.5], 1362 [ 0.7, 0.7], 1363 [ 1.0, 0.5], 1364 [ 2.0, 0.4], 1365 [ 2.8, 1.2]] 1366 1367 # One quantity 1368 Q = zeros((8,6), num.Float) 1369 1370 # Linear in time and space 1371 for i, t in enumerate(time): 1372 Q[i, :] = t*linear_function(points) 1373 1374 # Check interpolation of one quantity using interpolaton points) using default 1375 # time_thinning of 1 1376 I = Interpolation_function(time, Q, 1377 vertex_coordinates=points, 1378 triangles=triangles, 1379 interpolation_points=interpolation_points, 1380 verbose=False) 1381 1382 answer = linear_function(interpolation_points) 1383 1384 1385 t = time[0] 1386 for j in range(90): #t in [1, 10] 1387 for id in range(len(interpolation_points)): 1388 assert allclose(I(t, id), t*answer[id]) 1389 t += 0.1 1390 1391 1392 # Now check time_thinning 1393 I = Interpolation_function(time, Q, 1394 vertex_coordinates=points, 1395 triangles=triangles, 1396 interpolation_points=interpolation_points, 1397 time_thinning=2, 1398 verbose=False) 1399 1400 1401 assert len(I.time) == 4 1402 assert( allclose(I.time, [1.0, 4.0, 7.0, 9.0] )) 1403 1404 answer = linear_function(interpolation_points) 1405 1406 t = time[0] 1407 for j in range(80): #t in [1, 9] 1408 for id in range(len(interpolation_points)): 1409 assert allclose(I(t, id), t*answer[id]) 1329 1410 t += 0.1 1330 1411
Note: See TracChangeset
for help on using the changeset viewer.