Changeset 273


Ignore:
Timestamp:
Sep 6, 2004, 11:43:36 AM (21 years ago)
Author:
ole
Message:

Implemented protect in c and noted improvement.
Pyvolution is now faster than the previous version.

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

Legend:

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

    r272 r273  
    5959
    6060use_psyco = True  #Use psyco optimisations
    61 use_psyco = False  #Do not use psyco optimisations
     61#use_psyco = False  #Do not use psyco optimisations
    6262
    6363
  • inundation/ga/storm_surge/pyvolution/shallow_water.py

    r272 r273  
    426426            #Control momentum
    427427            xmomc[k] = ymomc[k] = 0.0
     428           
     429
     430
     431def protect_against_infintesimal_and_negative_heights_c(domain):
     432    """Protect against infinitesimal heights and associated high velocities
     433    """
     434   
     435    #Shortcuts
     436    wc = domain.quantities['level'].centroid_values
     437    zc = domain.quantities['elevation'].centroid_values
     438    xmomc = domain.quantities['xmomentum'].centroid_values
     439    ymomc = domain.quantities['ymomentum'].centroid_values           
     440
     441    from shallow_water_ext import protect
     442
     443    protect(domain.minimum_allowed_height, wc, zc, xmomc, ymomc)
     444   
     445
    428446
    429447def extrapolate_first_order(domain):
     
    954972    gravity = gravity_c
    955973    manning_friction = manning_friction_c
    956     balance_deep_and_shallow = balance_deep_and_shallow_c
     974    balance_deep_and_shallow = balance_deep_and_shallow_c
     975    protect_against_infintesimal_and_negative_heights = protect_against_infintesimal_and_negative_heights_c
    957976   
    958977    #distribute_to_vertices_and_edges = distribute_to_vertices_and_edges_c
  • inundation/ga/storm_surge/pyvolution/shallow_water_ext.c

    r267 r273  
    253253  return 0;
    254254}
     255
     256
     257
     258int _protect(int N,
     259             double minimum_allowed_height,       
     260             double* wc,
     261             double* zc,
     262             double* xmomc,
     263             double* ymomc) {
     264 
     265  int k;
     266  double hc;
     267 
     268  //Compute linear combination between constant levels and and
     269  //levels parallel to the bed elevation.     
     270 
     271  for (k=0; k<N; k++) {
     272    hc = wc[k] - zc[k];
     273    if (hc < minimum_allowed_height) {
     274      if (hc < 0.0) {
     275        //Control level and height
     276        wc[k] = zc[k];
     277      }
     278
     279      //Control momentum
     280      xmomc[k] = 0.0;
     281      ymomc[k] = 0.0;
     282    }
     283  }
     284  return 0;
     285}
     286
     287
    255288
    256289///////////////////////////////////////////////////////////////////
     
    559592
    560593
     594PyObject *protect(PyObject *self, PyObject *args) {
     595  //
     596  //    protect(minimum_allowed_height, wc, zc, xmomc, ymomc)
     597 
     598
     599  PyArrayObject
     600  *wc,            //Level at centroids
     601  *zc,            //Elevation at centroids   
     602  *xmomc,         //Momentums at centroids
     603  *ymomc;
     604
     605   
     606  int N;
     607  double minimum_allowed_height;
     608 
     609  // Convert Python arguments to C 
     610  if (!PyArg_ParseTuple(args, "dOOOO", 
     611                        &minimum_allowed_height,
     612                        &wc, &zc, &xmomc, &ymomc))
     613    return NULL;
     614
     615  N = wc -> dimensions[0];
     616   
     617  _protect(N,
     618           minimum_allowed_height,
     619           (double*) wc -> data,
     620           (double*) zc -> data,
     621           (double*) xmomc -> data,
     622           (double*) ymomc -> data);
     623 
     624  return Py_BuildValue(""); 
     625}
     626
     627
     628
    561629PyObject *balance_deep_and_shallow(PyObject *self, PyObject *args) {
    562630  //
    563   //    balance_deep_and_shallow(domain.number_of_elements,
    564   //                             wc, zc, hc, wv, zv, hv,
     631  //    balance_deep_and_shallow(wc, zc, hc, wv, zv, hv,
    565632  //                             xmomc, ymomc, xmomv, ymomv)
    566633 
     
    607674
    608675
    609 
    610 
    611676//////////////////////////////////////////     
    612677// Method table for python module
     
    623688  {"balance_deep_and_shallow", balance_deep_and_shallow,
    624689   METH_VARARGS, "Print out"},         
     690  {"protect", protect, METH_VARARGS | METH_KEYWORDS, "Print out"},   
    625691  //{"distribute_to_vertices_and_edges",
    626692  // distribute_to_vertices_and_edges, METH_VARARGS},   
Note: See TracChangeset for help on using the changeset viewer.