Changeset 614
- Timestamp:
- Nov 23, 2004, 5:55:46 PM (20 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/shallow_water.py
r613 r614 1033 1033 s_vec, phi_vec, const): 1034 1034 """Python version of assigning wind field to update vectors. 1035 A c version also exists for speed1035 A c version also exists (for speed) 1036 1036 """ 1037 1037 from math import pi, cos, sin, sqrt … … 1062 1062 1063 1063 FIXME: This class may be incorporated in the generic Wind_stress class 1064 S Uperseded1064 Superseded 1065 1065 """ 1066 1066 … … 1408 1408 #Replace python version with c implementations 1409 1409 1410 from shallow_water_ext import rotate 1410 from shallow_water_ext import rotate, assign_windfield_values 1411 1411 compute_fluxes = compute_fluxes_c 1412 1412 gravity = gravity_c -
inundation/ga/storm_surge/pyvolution/shallow_water_ext.c
r518 r614 20 20 #include "util_ext.h" 21 21 22 const double pi = 3.14159265358979; 22 23 23 24 // Computational function for rotation … … 285 286 return 0; 286 287 } 288 289 290 291 int _assign_wind_field_values(int N, 292 double* xmom_update, 293 double* ymom_update, 294 double* s_vec, 295 double* phi_vec, 296 double cw) { 297 298 //Assign windfield values to momentum updates 299 300 int k; 301 double S, s, phi, u, v; 302 303 for (k=0; k<N; k++) { 304 305 s = s_vec[k]; 306 phi = phi_vec[k]; 307 308 //Convert to radians 309 phi = phi*pi/180; 310 311 //Compute velocity vector (u, v) 312 u = s*cos(phi); 313 v = s*sin(phi); 314 315 //Compute wind stress 316 S = cw * sqrt(u*u + v*v); 317 xmom_update[k] += S*u; 318 ymom_update[k] += S*v; 319 } 320 return 0; 321 } 287 322 288 323 … … 673 708 674 709 710 711 712 713 714 PyObject *assign_windfield_values(PyObject *self, PyObject *args) { 715 // 716 // assign_windfield_values(xmom_update, ymom_update, 717 // s_vec, phi_vec, self.const) 718 719 720 721 PyArrayObject //(one element per triangle) 722 *s_vec, //Speeds 723 *phi_vec, //Bearings 724 *xmom_update, //Momentum updates 725 *ymom_update; 726 727 728 int N; 729 double cw; 730 731 // Convert Python arguments to C 732 if (!PyArg_ParseTuple(args, "OOOOd", 733 &xmom_update, 734 &ymom_update, 735 &s_vec, &phi_vec, 736 &cw)) 737 return NULL; 738 739 N = xmom_update -> dimensions[0]; 740 741 _assign_wind_field_values(N, 742 (double*) xmom_update -> data, 743 (double*) ymom_update -> data, 744 (double*) s_vec -> data, 745 (double*) phi_vec -> data, 746 cw); 747 748 return Py_BuildValue(""); 749 } 750 751 752 753 675 754 ////////////////////////////////////////// 676 755 // Method table for python module … … 688 767 METH_VARARGS, "Print out"}, 689 768 {"protect", protect, METH_VARARGS | METH_KEYWORDS, "Print out"}, 769 {"assign_windfield_values", assign_windfield_values, 770 METH_VARARGS | METH_KEYWORDS, "Print out"}, 690 771 //{"distribute_to_vertices_and_edges", 691 772 // distribute_to_vertices_and_edges, METH_VARARGS}, -
inundation/ga/storm_surge/pyvolution/wind_example_scalar.py
r610 r614 23 23 domain.set_quantity('elevation', 0.0) 24 24 domain.set_quantity('level', 1.0) 25 domain.set_quantity('friction', 0. 1)25 domain.set_quantity('friction', 0.03) 26 26 27 27 #Constant (quite extreme :-) windfield: 9000 m/s, bearing 120 degrees 28 domain.forcing_terms.append( Wind_stress(s=9000, phi=1 35) )28 domain.forcing_terms.append( Wind_stress(s=9000, phi=120) ) 29 29 30 30 ###################### -
inundation/ga/storm_surge/pyvolution/wind_example_variable.py
r613 r614 9 9 # 10 10 from mesh_factory import rectangular 11 from shallow_water import Domain, Reflective_boundary, Wind_stress11 from shallow_water import Domain, Dirichlet_boundary, Wind_stress 12 12 13 13 #Create basic mesh 14 N = 8015 length = 10014 N = 120 15 length = 200 16 16 points, vertices, boundary = rectangular(N, N, length, length) 17 17 … … 25 25 26 26 #Set initial conditions 27 h = 1.0 27 28 domain.set_quantity('elevation', 0.0) 28 domain.set_quantity('level', 2.0)29 domain.set_quantity('friction', 0.0 7)29 domain.set_quantity('level', h) 30 domain.set_quantity('friction', 0.01) 30 31 31 32 … … 36 37 """ 37 38 38 from math import sqrt, exp, cos, pi 39 40 N = len(x) 41 s = 0*x #New array 39 from math import pi 40 from Numeric import sqrt, exp, cos 42 41 43 42 c = (length/2, length/2) 44 45 for k in range(N): 46 r = sqrt((x[k] - c[0])**2 + (y[k] - c[1])**2) 43 r = sqrt((x - c[0])**2 + (y - c[1])**2)/length 44 factor = exp( -(r-0.15)**2 ) 47 45 48 r /= max(length,length) 49 50 factor = exp( -(r-0.15)**2 ) 51 52 s[k] = 4000 * factor * (cos(t*2*pi/150) + 2) 53 54 return s 46 #return 9000 * factor 47 return 4000 * factor * (cos(t*2*pi/150) + 2) 55 48 56 49 … … 58 51 """Rotating field 59 52 """ 60 from math import sqrt, atan, pi 61 62 N = len(x) 63 a = 0*x #New array 53 54 from math import pi 55 from Numeric import sqrt, exp, cos, arctan2, choose, less 64 56 65 57 c = (length/2, length/2) 66 for k in range(N): 67 r = sqrt((x[k] - c[0])**2 + (y[k] - c[1])**2) 58 xx = (x - c[0])/length 59 yy = (y - c[1])/length 60 angle = arctan2(yy,xx) 68 61 69 xx = (x[k] - c[0])/length 70 yy = (y[k] - c[1])/length 62 #Take normal direction (but reverse direction every 50 seconds) 63 #if sin(t*2*pi/100) < 0: 64 # sgn = -1 65 #else: 66 # sgn = 1 67 #angle += sgn*pi/2 68 angle -= pi/2 71 69 72 angle = atan(yy/xx) 73 74 if xx < 0: 75 angle+=pi #atan in ]-pi/2; pi/2[ 76 77 #Take normal direction 78 angle -= pi/2 79 80 #Ensure positive radians 81 if angle < 0: 82 angle += 2*pi 83 84 a[k] = angle/pi*180 85 86 return a 70 #Convert to degrees and return 71 return angle/pi*180 87 72 88 73 … … 109 94 ###################### 110 95 # Boundary conditions 111 Br = Reflective_boundary(domain) 112 domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br}) 96 #Br = Reflective_boundary(domain) 97 Bd = Dirichlet_boundary([h, 0, 0]) 98 domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd}) 113 99 114 100 ######################
Note: See TracChangeset
for help on using the changeset viewer.