Ignore:
Timestamp:
Jun 26, 2008, 1:21:05 PM (16 years ago)
Author:
ole
Message:

Retired h-limiter and beta_h as per ticket:194.
All unit tests and validation tests pass.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/shallow_water/shallow_water_ext.c

    r5315 r5442  
    538538
    539539int _balance_deep_and_shallow(int N,
    540                               double beta_h,
    541540                              double* wc,
    542541                              double* zc,
     
    623622        alpha = 1.0;
    624623        for (i=0; i<3; i++) {
    625        
    626           // FIXME (Ole): Simplify (remove) when (if) hvbar gets retired
    627           if (beta_h > epsilon) {
    628             hc_k = hvbar[k3+i]; // Depth to be used at vertices
    629           }
    630624         
    631625          h_diff = hc_k - hv[i];         
     
    674668      for (i=0; i<3; i++) {
    675669     
    676         // FIXME (Ole): Simplify when (if) hvbar gets retired       
    677         if (beta_h > epsilon) {   
    678           wv[k3+i] = zv[k3+i] + (1-alpha)*hvbar[k3+i] + alpha*hv[i];
    679         } else {
    680           wv[k3+i] = zv[k3+i] + (1-alpha)*hc_k + alpha*hv[i];   
    681         }
     670        wv[k3+i] = zv[k3+i] + (1-alpha)*hc_k + alpha*hv[i];     
    682671
    683672        // Update momentum at vertices
     
    23322321  // modes.
    23332322  //
    2334   //    balance_deep_and_shallow(beta_h, wc, zc, wv, zv,
     2323  //    balance_deep_and_shallow(wc, zc, wv, zv,
    23352324  //                             xmomc, ymomc, xmomv, ymomv)
    23362325
     
    23502339   
    23512340  double alpha_balance = 2.0;
    2352   double H0, beta_h;
     2341  double H0;
    23532342
    23542343  int N, tight_slope_limiters, use_centroid_velocities; //, err;
    23552344
    23562345  // Convert Python arguments to C
    2357   if (!PyArg_ParseTuple(args, "OdOOOOOOOOO",
     2346  if (!PyArg_ParseTuple(args, "OOOOOOOOOO",
    23582347                        &domain,
    2359                         &beta_h,
    23602348                        &wc, &zc,
    23612349                        &wv, &zv, &hvbar,
     
    24112399  N = wc -> dimensions[0];
    24122400  _balance_deep_and_shallow(N,
    2413                             beta_h,
    24142401                            (double*) wc -> data,
    24152402                            (double*) zc -> data,
     
    24322419
    24332420
    2434 PyObject *h_limiter(PyObject *self, PyObject *args) {
    2435 
    2436   PyObject *domain, *Tmp;
    2437   PyArrayObject
    2438     *hv, *hc, //Depth at vertices and centroids
    2439     *hvbar,   //Limited depth at vertices (return values)
    2440     *neighbours;
    2441 
    2442   int k, i, n, N, k3;
    2443   int dimensions[2];
    2444   double beta_h; // Safety factor (see config.py)
    2445   double *hmin, *hmax, hn;
    2446 
    2447   // Convert Python arguments to C
    2448   if (!PyArg_ParseTuple(args, "OOO", &domain, &hc, &hv)) {
    2449     PyErr_SetString(PyExc_RuntimeError, "shallow_water_ext.c: h_limiter could not parse input arguments");
    2450     return NULL;
    2451   } 
    2452  
    2453   neighbours = get_consecutive_array(domain, "neighbours");
    2454 
    2455   //Get safety factor beta_h
    2456   Tmp = PyObject_GetAttrString(domain, "beta_h");
    2457   if (!Tmp) {
    2458     PyErr_SetString(PyExc_RuntimeError, "shallow_water_ext.c: h_limiter could not obtain object beta_h from domain");
    2459     return NULL;
    2460   } 
    2461   beta_h = PyFloat_AsDouble(Tmp);
    2462 
    2463   Py_DECREF(Tmp);
    2464 
    2465   N = hc -> dimensions[0];
    2466 
    2467   //Create hvbar
    2468   dimensions[0] = N;
    2469   dimensions[1] = 3;
    2470   hvbar = (PyArrayObject *) PyArray_FromDims(2, dimensions, PyArray_DOUBLE);
    2471 
    2472 
    2473   //Find min and max of this and neighbour's centroid values
    2474   hmin = malloc(N * sizeof(double));
    2475   hmax = malloc(N * sizeof(double));
    2476   for (k=0; k<N; k++) {
    2477     k3=k*3;
    2478 
    2479     hmin[k] = ((double*) hc -> data)[k];
    2480     hmax[k] = hmin[k];
    2481 
    2482     for (i=0; i<3; i++) {
    2483       n = ((long*) neighbours -> data)[k3+i];
    2484 
    2485       // Initialise hvbar with values from hv
    2486       ((double*) hvbar -> data)[k3+i] = ((double*) hv -> data)[k3+i];
    2487 
    2488       if (n >= 0) {
    2489         hn = ((double*) hc -> data)[n]; // Neighbour's centroid value
    2490 
    2491         hmin[k] = min(hmin[k], hn);
    2492         hmax[k] = max(hmax[k], hn);
    2493       }
    2494     }
    2495   }
    2496 
    2497   // Call underlying standard routine
    2498   _limit_old(N, beta_h, (double*) hc -> data, (double*) hvbar -> data, hmin, hmax);
    2499 
    2500   // // //Py_DECREF(domain); //FIXME: Necessary?
    2501   free(hmin);
    2502   free(hmax);
    2503 
    2504   // Return result using PyArray to avoid memory leak
    2505   return PyArray_Return(hvbar);
    2506 }
    2507 
    2508 PyObject *h_limiter_sw(PyObject *self, PyObject *args) {
    2509   //a faster version of h_limiter above
    2510   PyObject *domain, *Tmp;
    2511   PyArrayObject
    2512     *hv, *hc, //Depth at vertices and centroids
    2513     *hvbar,   //Limited depth at vertices (return values)
    2514     *neighbours;
    2515 
    2516   int k, i, N, k3,k0,k1,k2;
    2517   int dimensions[2];
    2518   double beta_h; //Safety factor (see config.py)
    2519   double hmin, hmax, dh[3];
    2520 // Convert Python arguments to C
    2521   if (!PyArg_ParseTuple(args, "OOO", &domain, &hc, &hv)) {
    2522     PyErr_SetString(PyExc_RuntimeError, "shallow_water_ext.c: h_limiter_sw could not parse input arguments");
    2523     return NULL;
    2524   } 
    2525   neighbours = get_consecutive_array(domain, "neighbours");
    2526 
    2527   //Get safety factor beta_h
    2528   Tmp = PyObject_GetAttrString(domain, "beta_h");
    2529   if (!Tmp) {
    2530     PyErr_SetString(PyExc_RuntimeError, "shallow_water_ext.c: h_limiter_sw could not obtain object beta_h from domain");
    2531     return NULL;
    2532   } 
    2533   beta_h = PyFloat_AsDouble(Tmp);
    2534 
    2535   Py_DECREF(Tmp);
    2536 
    2537   N = hc -> dimensions[0];
    2538 
    2539   //Create hvbar
    2540   dimensions[0] = N;
    2541   dimensions[1] = 3;
    2542   hvbar = (PyArrayObject *) PyArray_FromDims(2, dimensions, PyArray_DOUBLE);
    2543   for (k=0;k<N;k++){
    2544     k3=k*3;
    2545     //get the ids of the neighbours
    2546     k0 = ((long*) neighbours -> data)[k3];
    2547     k1 = ((long*) neighbours -> data)[k3+1];
    2548     k2 = ((long*) neighbours -> data)[k3+2];
    2549     //set hvbar provisionally
    2550     for (i=0;i<3;i++){
    2551       ((double*) hvbar -> data)[k3+i] = ((double*) hv -> data)[k3+i];
    2552       dh[i]=((double*) hvbar -> data)[k3+i]-((double*) hc -> data)[k];
    2553     }
    2554     hmin=((double*) hc -> data)[k];
    2555     hmax=hmin;
    2556     if (k0>=0){
    2557       hmin=min(hmin,((double*) hc -> data)[k0]);
    2558       hmax=max(hmax,((double*) hc -> data)[k0]);
    2559     }
    2560     if (k1>=0){
    2561       hmin=min(hmin,((double*) hc -> data)[k1]);
    2562       hmax=max(hmax,((double*) hc -> data)[k1]);
    2563     }
    2564     if (k2>=0){
    2565       hmin=min(hmin,((double*) hc -> data)[k2]);
    2566       hmax=max(hmax,((double*) hc -> data)[k2]);
    2567     }
    2568     hmin-=((double*) hc -> data)[k];
    2569     hmax-=((double*) hc -> data)[k];
    2570     limit_gradient(dh,hmin,hmax,beta_h);
    2571     for (i=0;i<3;i++)
    2572       ((double*) hvbar -> data)[k3+i] = ((double*) hc -> data)[k]+dh[i];
    2573   }
    2574   return PyArray_Return(hvbar);
    2575 }
    25762421
    25772422PyObject *assign_windfield_values(PyObject *self, PyObject *args) {
     
    26372482  {"balance_deep_and_shallow", balance_deep_and_shallow,
    26382483   METH_VARARGS, "Print out"},
    2639   {"h_limiter", h_limiter,
    2640    METH_VARARGS, "Print out"},
    2641   {"h_limiter_sw", h_limiter_sw,
    2642    METH_VARARGS, "Print out"},
    26432484  {"protect", protect, METH_VARARGS | METH_KEYWORDS, "Print out"},
    26442485  {"assign_windfield_values", assign_windfield_values,
Note: See TracChangeset for help on using the changeset viewer.