Changeset 610
- Timestamp:
- Nov 22, 2004, 4:43:09 PM (20 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 2 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/shallow_water.py
r609 r610 924 924 return phi 925 925 926 926 where x and y are vectors. 927 927 928 928 and then pass the functions in … … 950 950 951 951 from math import pi, cos, sin, sqrt 952 from Numeric import Float, ones 952 953 953 954 xmom_update = domain.quantities['xmomentum'].explicit_update … … 955 956 956 957 N = domain.number_of_elements 957 958 if callable(self.s) or callable(self.phi): 959 xc = domain.get_centroid_coordinates() 960 t = domain.time 961 962 maxphi = -100 963 minphi = 100 964 for k in range(N): 965 x, y = xc[k,:] 966 967 if callable(self.s): 968 s = self.s(x,y,t) 969 else: 970 s = self.s 971 972 if callable(self.phi): 973 phi = self.phi(x,y,t) 974 else: 975 phi = self.phi 976 977 978 979 #Convert to radians 980 phi = phi*pi/180 981 982 983 #Compute velocity vector (u, v) 984 u = s*cos(phi) 985 v = s*sin(phi) 986 987 #Compute wind stress 988 S = self.const * sqrt(u**2 + v**2) 989 xmom_update[k] += S*u 990 ymom_update[k] += S*v 991 992 958 t = domain.time 959 960 if callable(self.s): 961 xc = domain.get_centroid_coordinates() 962 x = xc[:,0] 963 y = xc[:,1] 964 965 s_vec = self.s(x,y,t) 993 966 else: 994 #Constants 995 967 #Assume s is a scalar 968 969 try: 970 s_vec = self.s * ones(N, Float) 971 except: 972 msg = 'Speed must be either callable or a scalar: %s' %self.s 973 raise msg 974 975 976 if callable(self.phi): 977 xc = domain.get_centroid_coordinates() 978 x = xc[:,0] 979 y = xc[:,1] 980 981 phi_vec = self.phi(x,y,t) 982 else: 983 #Assume phi is a scalar 984 985 try: 986 phi_vec = self.phi * ones(N, Float) 987 except: 988 msg = 'Angle must be either callable or a scalar: %s' %self.phi 989 raise msg 990 991 #This is the bit that should be written in C 992 for k in range(N): 993 s = s_vec[k] 994 phi = phi_vec[k] 995 996 996 #Convert to radians 997 phi = self.phi*pi/180998 997 phi = phi*pi/180 998 999 999 #Compute velocity vector (u, v) 1000 u = s elf.s*cos(phi)1001 v = s elf.s*sin(phi)1000 u = s*cos(phi) 1001 v = s*sin(phi) 1002 1002 1003 1003 #Compute wind stress 1004 1004 S = self.const * sqrt(u**2 + v**2) 1005 xmom_update += S*u 1006 ymom_update += S*v 1007 1008 1005 xmom_update[k] += S*u 1006 ymom_update[k] += S*v 1007 1009 1008 1010 1009 class Wind_stress_from_file: … … 1015 1014 1016 1015 FIXME: This class may be incorporated in the generic Wind_stress class 1017 """ 1018 1016 SUperseded 1017 """ 1018 1019 1019 1020 def __init__(self, filename): 1020 1021 """Initialise windfield from a file with the following format -
inundation/ga/storm_surge/pyvolution/test_shallow_water.py
r609 r610 17 17 18 18 from math import sqrt, exp, cos, pi 19 20 N = len(x) 21 s = 0*x #New array 19 22 20 r = sqrt(x**2 + y**2) 21 22 factor = exp( -(r-0.15)**2 ) 23 24 return 4000 * factor * (cos(t*2*pi/150) + 2) 23 for k in range(N): 24 25 r = sqrt(x[k]**2 + y[k]**2) 26 27 factor = exp( -(r-0.15)**2 ) 28 29 s[k] = 4000 * factor * (cos(t*2*pi/150) + 2) 30 31 return s 25 32 26 33 … … 30 37 from math import sqrt, atan, pi 31 38 32 r = sqrt(x**2 + y**2) 39 40 N = len(x) 41 a = 0*x #New array 42 43 for k in range(N): 44 r = sqrt(x[k]**2 + y[k]**2) 33 45 34 angle = atan(y/x)35 36 if x< 0:37 angle+=pi #atan in ]-pi/2; pi/2[38 39 #Take normal direction40 angle -= pi/246 angle = atan(y[k]/x[k]) 47 48 if x[k] < 0: 49 angle+=pi #atan in ]-pi/2; pi/2[ 50 51 #Take normal direction 52 angle -= pi/2 41 53 42 #Ensure positive radians 43 if angle < 0: 44 angle += 2*pi 45 46 return angle/pi*180 47 54 #Ensure positive radians 55 if angle < 0: 56 angle += 2*pi 57 58 a[k] = angle/pi*180 59 60 return a 48 61 49 62 … … 791 804 t = domain.time 792 805 806 x = xc[:,0] 807 y = xc[:,1] 808 s_vec = speed(x,y,t) 809 phi_vec = angle(x,y,t) 810 811 793 812 for k in range(N): 794 x, y = xc[k,:]795 796 s = speed(x,y,t)797 phi = angle(x,y,t)798 799 800 813 #Convert to radians 801 phi = phi*pi/180 814 phi = phi_vec[k]*pi/180 815 s = s_vec[k] 802 816 803 817 #Compute velocity vector (u, v)
Note: See TracChangeset
for help on using the changeset viewer.