Changeset 614


Ignore:
Timestamp:
Nov 23, 2004, 5:55:46 PM (20 years ago)
Author:
ole
Message:

Played with wind stress + c-extension

Location:
inundation/ga/storm_surge/pyvolution
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/shallow_water.py

    r613 r614  
    10331033                            s_vec, phi_vec, const):
    10341034    """Python version of assigning wind field to update vectors.
    1035     A c version also exists for speed
     1035    A c version also exists (for speed)
    10361036    """
    10371037    from math import pi, cos, sin, sqrt
     
    10621062   
    10631063    FIXME: This class may be incorporated in the generic Wind_stress class
    1064     SUperseded
     1064    Superseded
    10651065    """
    10661066
     
    14081408    #Replace python version with c implementations
    14091409   
    1410     from shallow_water_ext import rotate
     1410    from shallow_water_ext import rotate, assign_windfield_values
    14111411    compute_fluxes = compute_fluxes_c
    14121412    gravity = gravity_c
  • inundation/ga/storm_surge/pyvolution/shallow_water_ext.c

    r518 r614  
    2020#include "util_ext.h"
    2121
     22const double pi = 3.14159265358979;
    2223
    2324// Computational function for rotation
     
    285286  return 0;
    286287}
     288
     289
     290
     291int _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}           
    287322
    288323
     
    673708
    674709
     710
     711
     712
     713
     714PyObject *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
    675754//////////////////////////////////////////     
    676755// Method table for python module
     
    688767   METH_VARARGS, "Print out"},         
    689768  {"protect", protect, METH_VARARGS | METH_KEYWORDS, "Print out"},   
     769  {"assign_windfield_values", assign_windfield_values,
     770   METH_VARARGS | METH_KEYWORDS, "Print out"},     
    690771  //{"distribute_to_vertices_and_edges",
    691772  // distribute_to_vertices_and_edges, METH_VARARGS},   
  • inundation/ga/storm_surge/pyvolution/wind_example_scalar.py

    r610 r614  
    2323domain.set_quantity('elevation', 0.0)
    2424domain.set_quantity('level', 1.0)
    25 domain.set_quantity('friction', 0.1)
     25domain.set_quantity('friction', 0.03)
    2626
    2727#Constant (quite extreme :-) windfield: 9000 m/s, bearing 120 degrees
    28 domain.forcing_terms.append( Wind_stress(s=9000, phi=135) )
     28domain.forcing_terms.append( Wind_stress(s=9000, phi=120) )
    2929
    3030######################
  • inundation/ga/storm_surge/pyvolution/wind_example_variable.py

    r613 r614  
    99#
    1010from mesh_factory import rectangular
    11 from shallow_water import Domain, Reflective_boundary, Wind_stress
     11from shallow_water import Domain, Dirichlet_boundary, Wind_stress
    1212
    1313#Create basic mesh
    14 N = 80
    15 length = 100
     14N = 120
     15length = 200
    1616points, vertices, boundary = rectangular(N, N, length, length)
    1717
     
    2525
    2626#Set initial conditions
     27h = 1.0
    2728domain.set_quantity('elevation', 0.0)
    28 domain.set_quantity('level', 2.0)
    29 domain.set_quantity('friction', 0.07)
     29domain.set_quantity('level', h)
     30domain.set_quantity('friction', 0.01)
    3031
    3132
     
    3637    """
    3738
    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
    4241
    4342    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 )
    4745
    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)
    5548
    5649
     
    5851    """Rotating field
    5952    """
    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
    6456
    6557    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)
    6861
    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   
    7169
    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
    8772
    8873   
     
    10994######################
    11095# Boundary conditions
    111 Br = Reflective_boundary(domain)
    112 domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})
     96#Br = Reflective_boundary(domain)
     97Bd = Dirichlet_boundary([h, 0, 0])
     98domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd})
    11399
    114100######################
Note: See TracChangeset for help on using the changeset viewer.