Ignore:
Timestamp:
Aug 28, 2007, 2:23:35 PM (17 years ago)
Author:
ole
Message:

Implemented optimisation excluding dry cells from flux calculation.
All tests pass and the script run_okushiri_profile.py reports an improvement
in compute_fluxes from 11.25s to 8.58s or 24% faster.
The overall computation was about 40s, so this optimisation improved the
total running time for the problem in question by 7%.

This partially addresses ticket:135

File:
1 edited

Legend:

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

    r4682 r4685  
    245245  soundspeed_right = sqrt(g*h_right);
    246246
    247  
    248247  s_max = max(u_left+soundspeed_left, u_right+soundspeed_right);
    249248  if (s_max < 0.0) s_max = 0.0;
    250249
    251250  s_min = min(u_left-soundspeed_left, u_right-soundspeed_right);
    252   if (s_min > 0.0) s_min = 0.0;
    253 
     251   if (s_min > 0.0) s_min = 0.0;
     252
     253 
    254254  //Flux formulas
    255255  flux_left[0] = u_left*h_left;
     
    261261  flux_right[2] = u_right*vh_right;
    262262
    263 
     263 
     264 
    264265  //Flux computation
    265266  denom = s_max-s_min;
     
    12811282                                     Xmom.explicit_update,
    12821283                                     Ymom.explicit_update,
    1283                                      already_computed_flux)
     1284                                     already_computed_flux,
     1285                                     optimise_dry_cells)                                     
    12841286
    12851287
     
    13081310    *max_speed_array; //Keeps track of max speeds for each triangle
    13091311
     1312
    13101313  // Local variables
    13111314  double timestep, max_speed, epsilon, g, H0, length, area;
     1315  int optimise_dry_cells=0; // Optimisation flag 
    13121316  double normal[2], ql[3], qr[3], zl, zr;
    13131317  double edgeflux[3]; // Work array for summing up fluxes
    13141318
    1315   int number_of_elements, k, i, j, m, n, computation_needed;
     1319  int number_of_elements, k, i, m, n; //, j, computation_needed;
     1320
    13161321  int ki, nm=0, ki2; // Index shorthands
    13171322  static long call=1; // Static local variable flagging already computed flux
     
    13191324
    13201325  // Convert Python arguments to C
    1321   if (!PyArg_ParseTuple(args, "ddddOOOOOOOOOOOOOOOOOOO",
     1326  if (!PyArg_ParseTuple(args, "ddddOOOOOOOOOOOOOOOOOOOi",
    13221327                        &timestep,
    13231328                        &epsilon,
     
    13401345                        &ymom_explicit_update,
    13411346                        &already_computed_flux,
    1342                         &max_speed_array)) {
     1347                        &max_speed_array,
     1348                        &optimise_dry_cells)) {
    13431349    PyErr_SetString(PyExc_RuntimeError, "Input arguments failed");
    13441350    return NULL;
    13451351  }
     1352 
    13461353 
    13471354  number_of_elements = stage_edge_values -> dimensions[0];
     
    13671374        // We've already computed the flux across this edge
    13681375        continue;
     1376       
    13691377       
    13701378      ql[0] = ((double *) stage_edge_values -> data)[ki];
     
    13931401     
    13941402     
    1395       // Check if flux calculation is necessary across this edge
    1396       // FIXME (Ole): Work in progress!
    1397       computation_needed = 0;
    1398       //for (j=0; j<3; j++) {     
    1399       //if (ql[j] != qr[j]) computation_needed = 1;
    1400       //}
    1401      
    1402       //if (computation_needed == 0) {
    1403         //printf("flux exemption identified\n");
     1403      if (optimise_dry_cells) {     
     1404        // Check if flux calculation is necessary across this edge
     1405        // This check will exclude dry cells.
     1406        // This will also optimise cases where zl != zr as
     1407        // long as both are dry
     1408
     1409        if ( fabs(ql[0] - zl) < epsilon &&
     1410             fabs(qr[0] - zr) < epsilon ) {
     1411          // Cell boundary is dry
     1412         
     1413          ((long *) already_computed_flux -> data)[ki] = call; // #k Done       
     1414          if (n>=0)
     1415            ((long *) already_computed_flux -> data)[nm] = call; // #n Done
    14041416       
    1405         //((long *) already_computed_flux -> data)[ki] = call; // #k Done       
    1406         //if (n>=0)
    1407         //  ((long *) already_computed_flux -> data)[nm] = call; // #n Done
    1408        
    1409         //max_speed = 0.0;
    1410         //continue;
    1411       //}
     1417          max_speed = 0.0;
     1418          continue;
     1419        }
     1420      }
    14121421     
    14131422
     
    14591468        }
    14601469      }
     1470     
    14611471    } // End edge i
    14621472   
Note: See TracChangeset for help on using the changeset viewer.