Changeset 750
- Timestamp:
- Jan 20, 2005, 11:18:13 AM (19 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/domain.py
r659 r750 262 262 msg = 'Conserved quantities must be a subset of all quantities' 263 263 assert quantity in self.quantities, msg 264 265 ##assert hasattr(self, 'boundary_objects') 264 266 265 267 def write_time(self): … … 313 315 from config import min_timestep, max_timestep, epsilon 314 316 315 317 #FIXME: Maybe lump into a larger check prior to evolving 318 msg = 'Boundary tags must be bound to boundary objects before evolving system, ' 319 msg += 'e.g. using the method set_boundary.\n' 320 msg += 'This system has the boundary tags %s ' %self.get_boundary_tags() 321 assert hasattr(self, 'boundary_objects'), msg 322 316 323 ##self.set_defaults() 317 324 -
inundation/ga/storm_surge/pyvolution/shallow_water.py
r715 r750 196 196 197 197 #Store vertices and connectivity 198 self.writer.store_connectivity() 198 self.writer.store_connectivity() 199 199 200 200 201 def store_timestep(self, name): … … 206 207 self.writer.store_timestep(name) 207 208 209 208 210 #Rotation of momentum vector 209 211 def rotate(q, normal, direction = 1): … … 949 951 """ 950 952 951 def __init__(self, s, phi):953 def __init__(self, *args, **kwargs): 952 954 """Initialise windfield from wind speed s [m/s] 953 955 and wind direction phi [degrees] … … 983 985 Alternatively, one vector valued function for (speed, angle) 984 986 can be applied, providing both quantities simultaneously. 985 FIXME: Not yet implemented 987 As in 988 W = Wind_stress(F), where returns (speed, angle) for each t. 986 989 987 990 domain.forcing_terms.append(W) … … 991 994 from Numeric import array, Float 992 995 996 if len(args) == 2: 997 s = args[0] 998 phi = args[1] 999 elif len(args) == 1: 1000 #Assume vector function returning (s, phi)(t,x,y) 1001 vector_function = args[0] 1002 s = lambda t,x,y: vector_function(t,x,y)[0] 1003 phi = lambda t,x,y: vector_function(t,x,y)[1] 1004 else: 1005 #Assume info is in 2 keyword arguments 1006 1007 if len(kwargs) == 2: 1008 s = kwargs['s'] 1009 phi = kwargs['phi'] 1010 else: 1011 raise 'Assumes two keyword arguments: s=..., phi=....' 1012 993 1013 self.speed = check_forcefield(s) 994 1014 self.phi = check_forcefield(phi) 995 1015 996 1016 self.const = eta_w*rho_a/rho_w 997 1017 -
inundation/ga/storm_surge/pyvolution/test_data_manager.py
r353 r750 3 3 4 4 import unittest 5 import copy 5 6 from Numeric import zeros, array, allclose, Float 6 7 from util import mean … … 50 51 51 52 domain.set_quantity('level', level) 53 self.initial_level = copy.copy(domain.quantities['level'].vertex_values) 52 54 53 55 domain.distribute_to_vertices_and_edges() … … 366 368 #Check contents 367 369 #Get NetCDF 368 fid = NetCDFFile(sww.filename, 'r') #Open existing file for append370 fid = NetCDFFile(sww.filename, 'r') 369 371 370 372 … … 400 402 401 403 404 def test_sync(self): 405 """Test info stored at each timestep is as expected (incl initial condition) 406 """ 407 408 import time, os, config 409 from Numeric import array, zeros, allclose, Float, concatenate 410 from Scientific.IO.NetCDF import NetCDFFile 411 412 self.domain.filename = 'synctest' 413 self.domain.format = 'sww' 414 self.domain.smooth = False 415 self.domain.store = True 416 417 #Evolution 418 print 419 for t in self.domain.evolve(yieldstep = 1.0, finaltime = 4.0): 420 level = self.domain.quantities['level'].vertex_values 421 422 #Get NetCDF 423 fid = NetCDFFile(self.domain.writer.filename, 'r') 424 stage = fid.variables['stage'] 425 426 if t == 0.0: 427 assert allclose(level, self.initial_level) 428 assert allclose(stage[:], level.flat) 429 else: 430 assert not allclose(level, self.initial_level) 431 assert not allclose(stage[:], level.flat) 432 433 434 435 402 436 def test_sww_DSG(self): 403 437 """Not a test, rather a look at the sww format -
inundation/ga/storm_surge/pyvolution/test_shallow_water.py
r648 r750 1 1 #!/usr/bin/env python 2 2 3 import unittest 3 import unittest, os 4 4 from math import sqrt, pi 5 5 … … 18 18 from math import sqrt, exp, cos, pi 19 19 20 x = array(x) 21 y = array(y) 22 20 23 N = len(x) 21 24 s = 0*x #New array … … 45 48 from math import sqrt, atan, pi 46 49 50 x = array(x) 51 y = array(y) 47 52 48 53 N = len(x) … … 649 654 pass 650 655 656 657 658 659 ##################################################### 660 def test_initial_condition(self): 661 """Test that initial condition is output at time == 0 662 """ 663 664 from config import g 665 import copy 666 667 a = [0.0, 0.0] 668 b = [0.0, 2.0] 669 c = [2.0, 0.0] 670 d = [0.0, 4.0] 671 e = [2.0, 2.0] 672 f = [4.0, 0.0] 673 674 points = [a, b, c, d, e, f] 675 #bac, bce, ecf, dbe 676 vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]] 677 678 domain = Domain(points, vertices) 679 680 #Set up for a gradient of (3,0) at mid triangle 681 def slope(x, y): 682 return 3*x 683 684 h = 0.1 685 def level(x,y): 686 return slope(x,y)+h 687 688 domain.set_quantity('elevation', slope) 689 domain.set_quantity('level', level) 690 691 initial_level = copy.copy(domain.quantities['level'].vertex_values) 692 693 domain.set_boundary({'exterior': Reflective_boundary(domain)}) 694 695 #Evolution 696 for t in domain.evolve(yieldstep = 1.0, finaltime = 2.0): 697 level = domain.quantities['level'].vertex_values 698 699 if t == 0.0: 700 assert allclose(level, initial_level) 701 else: 702 assert not allclose(level, initial_level) 703 704 705 706 651 707 ##################################################### 652 708 def test_gravity(self): … … 879 935 880 936 937 938 def test_windfield_from_file(self): 939 from config import rho_a, rho_w, eta_w 940 from math import pi, cos, sin, sqrt 941 from config import time_format 942 from util import File_function 943 import time 944 945 946 a = [0.0, 0.0] 947 b = [0.0, 2.0] 948 c = [2.0, 0.0] 949 d = [0.0, 4.0] 950 e = [2.0, 2.0] 951 f = [4.0, 0.0] 952 953 points = [a, b, c, d, e, f] 954 #bac, bce, ecf, dbe 955 vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]] 956 957 domain = Domain(points, vertices) 958 959 #Flat surface with 1m of water 960 domain.set_quantity('elevation', 0) 961 domain.set_quantity('level', 1.0) 962 domain.set_quantity('friction', 0) 963 964 Br = Reflective_boundary(domain) 965 domain.set_boundary({'exterior': Br}) 966 967 968 domain.time = 7 #Take a time that is represented in file (not zero) 969 970 #Write wind stress file (ensure that domain.time is covered) 971 #Take x=1 and y=0 972 filename = 'test_windstress_from_file.txt' 973 start = time.mktime(time.strptime('2000', '%Y')) 974 fid = open(filename, 'w') 975 dt = 1 #One second interval 976 t = 0.0 977 while t <= 10.0: 978 t_string = time.strftime(time_format, time.gmtime(t+start)) 979 980 fid.write('%s, %f %f\n' %(t_string, 981 speed(t,[1],[0])[0], 982 angle(t,[1],[0])[0])) 983 t += dt 984 985 fid.close() 986 987 #Setup wind stress 988 F = File_function(filename) 989 W = Wind_stress(F) 990 domain.forcing_terms = [] 991 domain.forcing_terms.append(W) 992 993 domain.compute_forcing_terms() 994 995 #Compute reference solution 996 const = eta_w*rho_a/rho_w 997 998 N = domain.number_of_elements 999 1000 t = domain.time 1001 1002 s = speed(t,[1],[0])[0] 1003 phi = angle(t,[1],[0])[0] 1004 1005 #Convert to radians 1006 phi = phi*pi/180 1007 1008 1009 #Compute velocity vector (u, v) 1010 u = s*cos(phi) 1011 v = s*sin(phi) 1012 1013 #Compute wind stress 1014 S = const * sqrt(u**2 + v**2) 1015 1016 for k in range(N): 1017 assert allclose(domain.quantities['level'].explicit_update[k], 0) 1018 assert allclose(domain.quantities['xmomentum'].explicit_update[k], S*u) 1019 assert allclose(domain.quantities['ymomentum'].explicit_update[k], S*v) 1020 1021 os.remove(filename) 881 1022 882 1023 def test_wind_stress_error_condition(self): -
inundation/ga/storm_surge/pyvolution/util.py
r671 r750 301 301 time [DD/MM/YY hh:mm:ss], x, y, value0 value1 value2 ... 302 302 303 In either case, the callable ob ejct will return a tuple of303 In either case, the callable object will return a tuple of 304 304 interpolated values, one each value stated in the file. 305 305 … … 442 442 """Evaluate f(t,x,y) 443 443 444 FIXME: x, y dependency not yet implemented 444 FIXME: x, y dependency not yet implemented except that 445 result is a vector of same length as x and y 445 446 """ 446 447 … … 473 474 (self.T[self.index+1] - self.T[self.index]) 474 475 475 #Compute interpolated values for values476 #Compute interpolated values 476 477 q = self.Q[self.index,:] +\ 477 478 ratio*(self.Q[self.index+1,:] - self.Q[self.index,:]) 478 479 479 480 #Return vector of interpolated values 480 return q 481 if x == None and y == None: 482 return q 483 else: 484 from Numeric import ones, Float 485 #Create one constant column for each value 486 N = len(x) 487 assert len(y) == N, 'x and y must have same length' 488 489 res = [] 490 for col in q: 491 res.append(col*ones(N, Float)) 492 493 return res 481 494 482 495
Note: See TracChangeset
for help on using the changeset viewer.