Changeset 629 for inundation/ga/storm_surge/pyvolution/test_util.py
- Timestamp:
- Nov 24, 2004, 6:55:52 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/test_util.py
r623 r629 234 234 235 235 #Check that domain.starttime isn't updated if later 236 domain.starttime = start + 1237 F = File_function(filename, domain)238 assert allclose(domain.starttime, start+1)236 #domain.starttime = start + 1 237 #F = File_function(filename, domain) 238 #assert allclose(domain.starttime, start+1) 239 239 240 240 … … 264 264 assert allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] ) 265 265 266 266 267 268 def test_file_function_time_with_domain_different_start(self): 269 """Test that File function interpolates correctly 270 between given times. No x,y dependency here. 271 Use domain with a starttime later than that of file 272 """ 273 274 #Write file 275 import os, time, calendar 276 from config import time_format 277 from math import sin, pi 278 from domain import Domain 279 280 finaltime = 1200 281 filename = 'test_file_function.txt' 282 fid = open(filename, 'w') 283 start = time.mktime(time.strptime('2000', '%Y')) 284 dt = 60 #One minute intervals 285 t = 0.0 286 while t <= finaltime: 287 t_string = time.strftime(time_format, time.gmtime(t+start)) 288 fid.write('%s, %f %f %f\n' %(t_string, 2*t, t**2, sin(t*pi/600))) 289 t += dt 290 291 fid.close() 292 293 a = [0.0, 0.0] 294 b = [4.0, 0.0] 295 c = [0.0, 3.0] 296 297 points = [a, b, c] 298 vertices = [[0,1,2]] 299 domain = Domain(points, vertices) 300 301 #Check that domain.starttime isn't updated if later 302 delta = 23 303 domain.starttime = start + delta 304 F = File_function(filename, domain) 305 assert allclose(domain.starttime, start+delta) 306 307 308 309 310 #Now try interpolation with delta offset 311 for i in range(20): 312 t = i*10 313 q = F(t-delta) 314 315 #Exact linear intpolation 316 assert allclose(q[0], 2*t) 317 if i%6 == 0: 318 assert allclose(q[1], t**2) 319 assert allclose(q[2], sin(t*pi/600)) 320 321 #Check non-exact 322 323 t = 90 #Halfway between 60 and 120 324 q = F(t-delta) 325 assert allclose( (120**2 + 60**2)/2, q[1] ) 326 assert allclose( (sin(120*pi/600) + sin(60*pi/600))/2, q[2] ) 327 328 329 t = 100 #Two thirds of the way between between 60 and 120 330 q = F(t-delta) 331 assert allclose( 2*120**2/3 + 60**2/3, q[1] ) 332 assert allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] ) 333 334 335 267 336 #------------------------------------------------------------- 268 337 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.