Changeset 612 for inundation/ga/storm_surge/pyvolution/shallow_water.py
- Timestamp:
- Nov 22, 2004, 5:29:10 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/shallow_water.py
r610 r612 896 896 897 897 898 def check_forcefield(f): 899 """Check that f is either 900 1: a callable object of x,y,t, where x and y are vectors 901 and that it returns an array or a list of same length 902 as x and y 903 2: a scalar 904 """ 905 906 from Numeric import ones, Float, array 907 908 909 if callable(f): 910 N = 3 911 x = ones(3, Float) 912 y = ones(3, Float) 913 try: 914 q = f(x, y, 1.0) 915 except Exception, e: 916 msg = 'Function %s could not be executed:\n%s' %(f, e) 917 raise msg 918 919 try: 920 q = array(q).astype(Float) 921 except: 922 msg = 'Return value from vector function %s could ' %f 923 msg += 'not be converted into a Numeric array of floats.\n' 924 msg += 'Specified function should return either list or array.' 925 raise msg 926 927 msg = 'Return vector from function %s' %f 928 msg += 'must have same lenght as input vectors' 929 assert len(q) == N, msg 930 931 else: 932 try: 933 f = float(f) 934 except: 935 msg = 'Force field %s must be either a scalar' %f 936 msg += ' or a vector function' 937 raise msg 938 return f 939 898 940 899 941 class Wind_stress: … … 938 980 939 981 from config import rho_a, rho_w, eta_w 940 941 self.s = s 942 self.phi = phi 982 from Numeric import array, Float 983 984 self.speed = check_forcefield(s) 985 self.phi = check_forcefield(phi) 943 986 944 987 self.const = eta_w*rho_a/rho_w … … 950 993 951 994 from math import pi, cos, sin, sqrt 952 from Numeric import Float, ones 995 from Numeric import Float, ones, ArrayType 953 996 954 997 xmom_update = domain.quantities['xmomentum'].explicit_update … … 958 1001 t = domain.time 959 1002 960 if callable(self.s ):1003 if callable(self.speed): 961 1004 xc = domain.get_centroid_coordinates() 962 x = xc[:,0] 963 y = xc[:,1] 964 965 s_vec = self.s(x,y,t) 1005 s_vec = self.speed(xc[:,0], xc[:,1], t) 966 1006 else: 967 1007 #Assume s is a scalar 968 1008 969 1009 try: 970 s_vec = self.s * ones(N, Float)1010 s_vec = self.speed * ones(N, Float) 971 1011 except: 972 1012 msg = 'Speed must be either callable or a scalar: %s' %self.s … … 976 1016 if callable(self.phi): 977 1017 xc = domain.get_centroid_coordinates() 978 x = xc[:,0] 979 y = xc[:,1] 980 981 phi_vec = self.phi(x,y,t) 1018 phi_vec = self.phi(xc[:,0], xc[:,1], t) 982 1019 else: 983 1020 #Assume phi is a scalar … … 988 1025 msg = 'Angle must be either callable or a scalar: %s' %self.phi 989 1026 raise msg 1027 990 1028 991 1029 #This is the bit that should be written in C
Note: See TracChangeset
for help on using the changeset viewer.