Changeset 9260


Ignore:
Timestamp:
Jul 11, 2014, 11:03:01 AM (11 years ago)
Author:
davies
Message:

General clean-up + removing C memory allocation in compute_fluxes_ and extrapolate_second_

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/shallow_water/shallow_water_domain.py

    r9257 r9260  
    250250        self.riverwallData=anuga.structures.riverwall.RiverWall(self)
    251251
    252         # Keep track of the fluxes through the boundaries
    253         # Only works for DE algorithms at present
     252        ## Keep track of the fluxes through the boundaries
     253        ## Only works for DE algorithms at present
    254254        max_time_substeps=3 # Maximum number of substeps supported by any timestepping method
    255         # boundary_flux_sum holds boundary fluxes on each sub-step
     255        # boundary_flux_sum holds boundary fluxes on each sub-step [unused substeps = 0.]
    256256        self.boundary_flux_sum=num.array([0.]*max_time_substeps)
    257257        from anuga.operators.boundary_flux_integral_operator import boundary_flux_integral_operator
     
    260260        self.call=1
    261261
     262        # Work arrays [avoid allocate statements in compute_fluxes or extrapolate_second_order]
     263        self.edge_flux_work=num.zeros(len(self.edge_coordinates[:,0])*3)
     264        self.pressuregrad_work=num.zeros(len(self.edge_coordinates[:,0]))
     265        self.x_centroid_work=num.zeros(len(self.edge_coordinates[:,0])/3)
     266        self.y_centroid_work=num.zeros(len(self.edge_coordinates[:,0])/3)
    262267
    263268    def set_defaults(self):
     
    15901595                                               self.riverwallData.hydraulic_properties_rowIndex,
    15911596                                               int(self.riverwallData.ncol_hydraulic_properties),
    1592                                                self.riverwallData.hydraulic_properties)
     1597                                               self.riverwallData.hydraulic_properties,
     1598                                               self.edge_flux_work,
     1599                                               self.pressuregrad_work)
    15931600
    15941601            self.flux_timestep = flux_timestep
     
    16961703                      height.vertex_values,
    16971704                      int(self.optimise_dry_cells),
    1698                       int(self.extrapolate_velocity_second_order))
     1705                      int(self.extrapolate_velocity_second_order),
     1706                      self.x_centroid_work,
     1707                      self.y_centroid_work)
    16991708        else:
    17001709            # Code for original method
     
    24112420        message = '---------------------------\n'       
    24122421        message += 'Volumetric balance report:\n'
     2422        message += 'Note: Boundary fluxes are not exact\n'
     2423        message += 'See get_boundary_flux_integral for exact computation\n'
    24132424        message += '--------------------------\n'
    24142425        message += 'Total boundary inflow [m^3/s]: %.2f\n' % total_boundary_inflow
  • trunk/anuga_core/source/anuga/shallow_water/swDE1_domain_ext.c

    r9257 r9260  
    448448    double newFlux;
    449449    // Following constants control the 'blending' with the shallow water solution
    450     // They are now user-defined 
     450    // They are now user-defined
    451451    //double s1=0.9; // At this submergence ratio, begin blending with shallow water solution
    452452    //double s2=0.95; // At this submergence ratio, completely use shallow water solution
     
    474474    }
    475475
    476     //printf("%e, %e \n", rw, edgeflux[0]);
    477 
    478476    if( (hdRat<s2) & (hdWrRat< h2) ){
    479477        // Rescale the edge fluxes so that the mass flux = desired flux
     
    489487        // Weighted average constants to transition to shallow water eqn flow
    490488        w1=min( max(hdRat-s1,0.)/(s2-s1), 1.0);
    491         //w2=1.0-w1;
    492         //
     489       
    493490        // Adjust again when the head is too deep relative to the weir height
    494491        w2=min( max(hdWrRat-h1,0.)/(h2-h1), 1.0);
    495         //w2=1.0-w1;
    496492
    497493        newFlux=(rw*(1.0-w1)+w1*edgeflux[0])*(1.0-w2) + w2*edgeflux[0];
     
    505501            edgeflux[2]*=scaleFlux;
    506502        }else{
    507             // Can't divide by edgeflux
     503            // Can't divide by edgeflux, so enforce 'newFlux' directly
     504            //
    508505            // FIXME: This is fluxing mass but not momentum
    509506            //        It might be ok, but,.........
     
    522519        }
    523520    }
    524 
    525     //printf("%e, %e, %e, %e , %e, %e \n", weir_height, h_left, h_right, edgeflux[0], w1, w2);
    526521
    527522    return 0;
     
    563558        double* bed_centroid_values,
    564559        double* height_centroid_values,
    565         //double* bed_vertex_values,
    566560        long* edge_flux_type,
    567561        double* riverwall_elevation,
    568562        long* riverwall_rowIndex,
    569563        int ncol_riverwall_hydraulic_properties,
    570         double* riverwall_hydraulic_properties) {
     564        double* riverwall_hydraulic_properties,
     565        double* edge_flux_work,
     566        double* pressuregrad_work) {
    571567    // Local variables
    572568    double max_speed, length, inv_area, zl, zr;
    573     //double h0 = H0*H0;//H0*H0;//H0*0.1;//H0*H0;//H0*H0; // This ensures a good balance when h approaches H0.
    574569    double h_left, h_right, z_half ;  // For andusse scheme
    575570    // FIXME: limiting_threshold is not used for DE1
    576     double limiting_threshold = 10*H0;//10 * H0 ;//H0; //10 * H0; // Avoid applying limiter below this
    577     // threshold for performance reasons.
    578     // See ANUGA manual under flux limiting
     571    double limiting_threshold = 10*H0;
     572    //
    579573    int k, i, m, n,j, ii;
    580574    int ki, nm = 0, ki2,ki3, nm3; // Index shorthands
    581     //int num_hydraulic_properties=1; // FIXME: Move to function call
    582575    // Workspace (making them static actually made function slightly slower (Ole))
    583576    double ql[3], qr[3], edgeflux[3]; // Work array for summing up fluxes
     
    592585    double speed_max_last, vol, smooth, local_speed, weir_height;
    593586
    594     double *edgeflux_store, *pressuregrad_store;
    595 
    596     edgeflux_store = malloc(number_of_elements*9*sizeof(double));
    597     pressuregrad_store = malloc(number_of_elements*3*sizeof(double));
    598 
    599587    call++; // Flag 'id' of flux calculation for this timestep
    600588
     
    604592    memset((char*) xmom_explicit_update, 0, number_of_elements * sizeof (double));
    605593    memset((char*) ymom_explicit_update, 0, number_of_elements * sizeof (double));
     594    memset((char*) edge_flux_work, 0, 9*number_of_elements * sizeof (double));
     595    memset((char*) pressuregrad_work, 0, 3*number_of_elements * sizeof (double));
    606596
    607597    local_timestep=timestep;
     
    680670                z_half=max(riverwall_elevation[RiverWall_count-1], z_half) ;
    681671
    682                 //if(min(ql[0], qr[0]) < z_half){
    683                 //    // Since there is a wall blocking the flow connection, use first order extrapolation for this edge
    684                 //    ql[0]=stage_centroid_values[k];
    685                 //    ql[1]=xmom_centroid_values[k];
    686                 //    ql[2]=ymom_centroid_values[k];
    687                 //    hle=hc;
    688                 //    zl=zc;
    689 
    690                 //    if(n>=0){
    691                 //      qr[0]=stage_centroid_values[n];
    692                 //      qr[1]=xmom_centroid_values[n];
    693                 //      qr[2]=ymom_centroid_values[n];
    694                 //      hre=hc_n;
    695                 //      zr = zc_n;
    696                 //    }else{
    697                 //      hre=hc;
    698                 //      zr = zc;
    699                 //    }
    700                 //    // Re-set central bed to riverwall elevation
    701                 //    z_half=max(riverwall_elevation[RiverWall_count-1], max(zl, zr)) ;
    702                 //}
    703 
    704672            }
    705673
     
    720688            // Force weir discharge to match weir theory
    721689            if(edge_flux_type[ki]==1){
    722                 //printf("%e \n", z_half);
    723690                weir_height=max(riverwall_elevation[RiverWall_count-1]-min(zl,zr), 0.); // Reference weir height 
    724                 //weir_height=max(z_half-max(zl,zr), 0.); // Reference weir height 
    725691                // If the weir height is zero, avoid the weir compuattion entirely
    726692                if(weir_height>0.){
     
    728694                    ii=riverwall_rowIndex[RiverWall_count-1]*ncol_riverwall_hydraulic_properties;
    729695                    Qfactor=riverwall_hydraulic_properties[ii];
    730                     //printf("%e \n", Qfactor);
    731696                    // Get s1, submergence ratio at which we start blending with the shallow water solution
    732697                    ii+=1;
     
    742707                    h2=riverwall_hydraulic_properties[ii];
    743708                   
    744                     //adjust_edgeflux_with_weir(edgeflux, h_left, h_right, g,
    745                     //                          weir_height, Qfactor,
    746                     //                          s1, s2, h1, h2);
    747 
    748709                    // Use first-order h's for weir -- as the 'upstream/downstream' heads are
    749710                    //  measured away from the weir itself
     
    759720                                              s1, s2, h1, h2);
    760721                    // NOTE: Should perhaps also adjust the wave-speed here?? Small chance of instability??
    761                     //printf("%e \n", edgeflux[0]);
    762722                }
    763723            }
     
    770730
    771731
    772             //// Don't allow an outward advective flux if the cell centroid stage
    773             //// is < the edge value. Is this important (??)
     732            //// Don't allow an outward advective flux if the cell centroid
     733            ////   stage is < the edge value. Is this important (??). Seems not
     734            ////   to be with DE algorithms
    774735            //if((hc<H0) && edgeflux[0] > 0.){
    775736            //    edgeflux[0] = 0.;
     
    788749            //}
    789750
    790             edgeflux_store[ki3 + 0 ] = -edgeflux[0];
    791             edgeflux_store[ki3 + 1 ] = -edgeflux[1];
    792             edgeflux_store[ki3 + 2 ] = -edgeflux[2];
     751            edge_flux_work[ki3 + 0 ] = -edgeflux[0];
     752            edge_flux_work[ki3 + 1 ] = -edgeflux[1];
     753            edge_flux_work[ki3 + 2 ] = -edgeflux[2];
    793754
    794755            // bedslope_work contains all gravity related terms
    795756            bedslope_work=length*(-g*0.5*(h_left*h_left - hle*hle -(hle+hc)*(zl-zc))+pressure_flux);
    796757
    797             pressuregrad_store[ki]=bedslope_work;
     758            pressuregrad_work[ki]=bedslope_work;
    798759           
    799760            already_computed_flux[ki] = call; // #k Done
     
    802763            if (n >= 0) {
    803764
    804                 edgeflux_store[nm3 + 0 ] = edgeflux[0];
    805                 edgeflux_store[nm3 + 1 ] = edgeflux[1];
    806                 edgeflux_store[nm3 + 2 ] = edgeflux[2];
     765                edge_flux_work[nm3 + 0 ] = edgeflux[0];
     766                edge_flux_work[nm3 + 1 ] = edgeflux[1];
     767                edge_flux_work[nm3 + 2 ] = edgeflux[2];
    807768                bedslope_work=length*(-g*0.5*(h_right*h_right-hre*hre-(hre+hc_n)*(zr-zc_n))+pressure_flux);
    808                 pressuregrad_store[nm]=bedslope_work;
     769                pressuregrad_work[nm]=bedslope_work;
    809770
    810771                already_computed_flux[nm] = call; // #n Done
     
    815776            // steps, NOT within them (since a constant timestep is used within
    816777            // each rk2/rk3 sub-step)
    817             if ((tri_full_flag[k] == 1) & ( (call-2)%timestep_fluxcalls==0)) {
     778            if ((tri_full_flag[k] == 1) & (substep_count==0)) {
    818779
    819780                speed_max_last=max(speed_max_last, max_speed);
     
    833794            }
    834795       
    835         // Keep track of maximal speeds
    836         //max_speed_array[k] = max(max_speed_array[k],max_speed);
    837 
    838796        } // End edge i (and neighbour n)
    839797        // Keep track of maximal speeds
     
    843801    } // End triangle k
    844802 
    845     //// GD HACK
    846803    //// Limit edgefluxes, for mass conservation near wet/dry cells
    847804    //// This doesn't seem to be needed anymore
     
    855812    //            outgoing_mass_edges=0.0;
    856813    //            for(useint=0; useint<3; useint++){
    857     //                if(edgeflux_store[3*(3*k+useint)]< 0.){
     814    //                if(edge_flux_work[3*(3*k+useint)]< 0.){
    858815    //                    //outgoing_mass_edges+=1.0;
    859     //                    outgoing_mass_edges+=(edgeflux_store[3*(3*k+useint)]);
     816    //                    outgoing_mass_edges+=(edge_flux_work[3*(3*k+useint)]);
    860817    //                }
    861818    //            }
     
    871828    //        // total_outgoing_flux <= cell volume = Area_triangle*hc
    872829    //        vol=areas[k]*hc;
    873     //        if((edgeflux_store[ki3]< 0.0) && (-outgoing_mass_edges> vol)){
     830    //        if((edge_flux_work[ki3]< 0.0) && (-outgoing_mass_edges> vol)){
    874831    //           
    875832    //            // This bound could be improved (e.g. we could actually sum the
     
    880837    //            tmp = vol/(-(outgoing_mass_edges)) ;
    881838    //            if(tmp< 1.0){
    882     //                edgeflux_store[ki3+0]*=tmp;
    883     //                edgeflux_store[ki3+1]*=tmp;
    884     //                edgeflux_store[ki3+2]*=tmp;
     839    //                edge_flux_work[ki3+0]*=tmp;
     840    //                edge_flux_work[ki3+1]*=tmp;
     841    //                edge_flux_work[ki3+2]*=tmp;
    885842
    886843    //                // Compute neighbour edge index
     
    889846    //                    nm = 3*n + neighbour_edges[ki];
    890847    //                    nm3 = nm*3;
    891     //                    edgeflux_store[nm3+0]*=tmp;
    892     //                    edgeflux_store[nm3+1]*=tmp;
    893     //                    edgeflux_store[nm3+2]*=tmp;
     848    //                    edge_flux_work[nm3+0]*=tmp;
     849    //                    edge_flux_work[nm3+1]*=tmp;
     850    //                    edge_flux_work[nm3+2]*=tmp;
    894851    //                }
    895852    //            }
     
    897854    //    }
    898855    // }
    899 
    900     ////printf("%e \n", edgeflux_store[3*30*3]);
    901856
    902857    // Now add up stage, xmom, ymom explicit updates
     
    916871            // Option to limit advective fluxes
    917872            //if(hc > H0){
    918                 stage_explicit_update[k] += edgeflux_store[ki3+0];
    919                 xmom_explicit_update[k] += edgeflux_store[ki3+1];
    920                 ymom_explicit_update[k] += edgeflux_store[ki3+2];
     873                stage_explicit_update[k] += edge_flux_work[ki3+0];
     874                xmom_explicit_update[k] += edge_flux_work[ki3+1];
     875                ymom_explicit_update[k] += edge_flux_work[ki3+2];
    921876            //}else{
    922             //    stage_explicit_update[k] += edgeflux_store[ki3+0];
     877            //    stage_explicit_update[k] += edge_flux_work[ki3+0];
    923878            //}
    924879
     
    930885                // boundary_flux_sum is an array with length = timestep_fluxcalls
    931886                // For each sub-step, we put the boundary flux sum in.
    932                 boundary_flux_sum[substep_count] += edgeflux_store[ki3];
     887                boundary_flux_sum[substep_count] += edge_flux_work[ki3];
    933888            }
     889   
    934890            // GD HACK
    935891            // Compute bed slope term
    936892            //if(hc > H0){
    937                 xmom_explicit_update[k] -= normals[ki2]*pressuregrad_store[ki];
    938                 ymom_explicit_update[k] -= normals[ki2+1]*pressuregrad_store[ki];
     893                xmom_explicit_update[k] -= normals[ki2]*pressuregrad_work[ki];
     894                ymom_explicit_update[k] -= normals[ki2+1]*pressuregrad_work[ki];
    939895            //}else{
    940896            //    xmom_explicit_update[k] *= 0.;
     
    953909    }  // end cell k
    954910
    955     // Hack to ensure we only update the timestep on the first call within each rk2/rk3 step
     911    // Ensure we only update the timestep on the first call within each rk2/rk3 step
    956912    if(substep_count==0) timestep=local_timestep;
    957913           
    958     free(edgeflux_store);
    959     free(pressuregrad_store);
    960 
    961914    return timestep;
    962915}
     
    1045998
    1046999int limit_gradient(double *dqv, double qmin, double qmax, double beta_w){
    1047   // Given provisional jumps dqv from the FV triangle centroid to its 
    1048   // vertices and jumps qmin (qmax) between the centroid of the FV
    1049   // triangle and the minimum (maximum) of the values at the centroid of
    1050   // the FV triangle and the auxiliary triangle vertices,
    1051   // calculate a multiplicative factor phi by which the provisional
    1052   // vertex jumps are to be limited
     1000  // Given provisional jumps dqv from the FV triangle centroid to its
     1001  // vertices/edges, and jumps qmin (qmax) between the centroid of the FV
     1002  // triangle and the minimum (maximum) of the values at the auxiliary triangle
     1003  // vertices (which are centroids of neighbour mesh triangles), calculate a
     1004  // multiplicative factor phi by which the provisional vertex jumps are to be
     1005  // limited
    10531006 
    10541007  int i;
     
    11111064                                 double* height_vertex_values,
    11121065                                 int optimise_dry_cells,
    1113                                  int extrapolate_velocity_second_order) {
     1066                                 int extrapolate_velocity_second_order,
     1067                                 double* x_centroid_work,
     1068                                 double* y_centroid_work) {
    11141069                 
    11151070  // Local variables
     
    11221077  double dk, dv0, dv1, dv2, de[3], demin, dcmax, r0scale, vel_norm, l1, l2, a_tmp, b_tmp, c_tmp,d_tmp;
    11231078 
    1124   double *xmom_centroid_store, *ymom_centroid_store; // , *min_elevation_edgevalue, *max_elevation_edgevalue;
    1125   //double *cell_wetness_scale;
    1126   //int *count_wet_neighbours;
    1127 
    1128   // Use malloc to avoid putting these variables on the stack, which can cause
    1129   // segfaults in large model runs
    1130   xmom_centroid_store = malloc(number_of_elements*sizeof(double));
    1131   ymom_centroid_store = malloc(number_of_elements*sizeof(double));
    1132   //min_elevation_edgevalue = malloc(number_of_elements*sizeof(double));
    1133   //max_elevation_edgevalue = malloc(number_of_elements*sizeof(double));
    1134   //cell_wetness_scale = malloc(number_of_elements*sizeof(double));
    1135   //count_wet_neighbours = malloc(number_of_elements*sizeof(int));
    1136  
    1137   //
    1138   // Compute some useful statistics on wetness/dryness
    1139   //
    1140   //for(k=0; k<number_of_elements;k++){
    1141   //    //cell_wetness_scale[k] = 0.;
    1142   //    //// Check if cell k is wet
    1143   //    ////if(stage_centroid_values[k] > elevation_centroid_values[k]){
    1144   //    //if(stage_centroid_values[k] > elevation_centroid_values[k] + 1.0*minimum_allowed_height){
    1145   //    ////if(stage_centroid_values[k] > max_elevation_edgevalue[k] + minimum_allowed_height+epsilon){
    1146   //    //    cell_wetness_scale[k] = 1.; 
    1147   //    //}
    1148 
    1149   //    //min_elevation_edgevalue[k] = min(elevation_edge_values[3*k],
    1150   //    //                                 min(elevation_edge_values[3*k+1],
    1151   //    //                                     elevation_edge_values[3*k+2]));
    1152   //    //max_elevation_edgevalue[k] = max(elevation_edge_values[3*k],
    1153   //    //                                 max(elevation_edge_values[3*k+1],
    1154   //    //                                     elevation_edge_values[3*k+2]));
    1155   //}
    1156 
    1157   //// Alternative 'PROTECT' step
    1158   //for(k=0; k<number_of_elements;k++){
    1159   //  //if((cell_wetness_scale[k]==0. ) ){
    1160   //  //    xmom_centroid_values[k]=0.;
    1161   //  //    ymom_centroid_values[k]=0.;
    1162   //  //    //xmom_centroid_values[k]*=0.9;
    1163   //  //    //ymom_centroid_values[k]*=0.9;
    1164 
    1165   //  //}
    1166 
    1167   // 
    1168   //  ////// Try some Froude-number limiting in shallow depths
    1169   //  //dpth=max(stage_centroid_values[k] - elevation_centroid_values[k], 0.0);
    1170   //  ////
    1171   //  //if(dpth< max(max_elevation_edgevalue[k]-min_elevation_edgevalue[k],10*minimum_allowed_height)){
    1172   //  //    // momnorm = momentum^2
    1173   //  //    momnorm=(xmom_centroid_values[k]*xmom_centroid_values[k]+
    1174   //  //             ymom_centroid_values[k]*ymom_centroid_values[k]);
    1175   //  //   
    1176   //  //    // vel^2 < constant*g*dpth [-- then multiply both sides by dpth^2]
    1177   //  //    if(momnorm > 4*9.81*dpth*dpth*dpth){
    1178   //  //        // Down-scale momentum so that Froude number < constant
    1179   //  //        tmp=sqrt((4*9.81*dpth*dpth*dpth)/momnorm);
    1180   //  //        xmom_centroid_values[k] *=tmp;
    1181   //  //        ymom_centroid_values[k] *=tmp;
    1182   //  //    }
    1183   //  //}
    1184   //}
    1185 
     1079
     1080  memset((char*) x_centroid_work, 0, number_of_elements * sizeof (double));
     1081  memset((char*) y_centroid_work, 0, number_of_elements * sizeof (double));
     1082 
    11861083 
    11871084  if(extrapolate_velocity_second_order==1){
     
    11951092          dk = height_centroid_values[k];
    11961093          if(dk>minimum_allowed_height){
    1197               xmom_centroid_store[k] = xmom_centroid_values[k];
     1094              x_centroid_work[k] = xmom_centroid_values[k];
    11981095              xmom_centroid_values[k] = xmom_centroid_values[k]/dk;
    11991096
    1200               ymom_centroid_store[k] = ymom_centroid_values[k];
     1097              y_centroid_work[k] = ymom_centroid_values[k];
    12011098              ymom_centroid_values[k] = ymom_centroid_values[k]/dk;
    12021099          }else{
    1203               xmom_centroid_store[k] = 0.;
     1100              x_centroid_work[k] = 0.;
    12041101              xmom_centroid_values[k] = 0.;
    1205               ymom_centroid_store[k] = 0.;
     1102              y_centroid_work[k] = 0.;
    12061103              ymom_centroid_values[k] = 0.;
    12071104
     
    12241121         (height_centroid_values[k1] < minimum_allowed_height | k1==k) &
    12251122         (height_centroid_values[k2] < minimum_allowed_height | k2==k)){
    1226               xmom_centroid_store[k] = 0.;
     1123              x_centroid_work[k] = 0.;
    12271124              xmom_centroid_values[k] = 0.;
    1228               ymom_centroid_store[k] = 0.;
     1125              y_centroid_work[k] = 0.;
    12291126              ymom_centroid_values[k] = 0.;
    12301127
     
    13131210      k2 = surrogate_neighbours[k3 + 2];
    13141211
    1315       //if(cell_wetness_scale[k0]==0 && cell_wetness_scale[k1]==0 && cell_wetness_scale[k2]==0){
    1316       //    xmom_centroid_store[k]=0.;
    1317       //    ymom_centroid_store[k]=0.;
    1318       //    xmom_centroid_values[k] = 0.;
    1319       //    ymom_centroid_values[k] = 0.;
    1320       //}
    1321      
    1322       // Test to see whether we accept the surrogate neighbours
    1323       // Note that if ki is replaced with k in more than 1 neighbour, then the
    1324       // triangle area will be zero, and a first order extrapolation will be
    1325       // used
    1326       // FIXME: Remove cell_wetness_scale if you don't need it
    1327       //if( (cell_wetness_scale[k2]==0.0 && stage_centroid_values[k]<max_elevation_edgevalue[k]+100.)){
    1328       //    k2 = k ;
    1329       //}
    1330       //if((cell_wetness_scale[k0]==0.0 && stage_centroid_values[k]<max_elevation_edgevalue[k])+100.){
    1331       //    k0 = k ;
    1332       //}
    1333       //if((cell_wetness_scale[k1]==0.0 && stage_centroid_values[k]<max_elevation_edgevalue[k])+100.){
    1334       //    k1 = k ;
    1335       //}
    1336 
    1337       // Take note if the max neighbour bed elevation is greater than the min
    1338       // neighbour stage -- suggests a 'steep' bed relative to the flow
    1339       //bedmax = max(elevation_centroid_values[k],
    1340       //             max(elevation_centroid_values[k0],
    1341       //                 max(elevation_centroid_values[k1],
    1342       //                     elevation_centroid_values[k2])));
    1343       //bedmin = min(elevation_centroid_values[k],
    1344       //             min(elevation_centroid_values[k0],
    1345       //                 min(elevation_centroid_values[k1],
    1346       //                     elevation_centroid_values[k2])));
    1347       //stagemin = min(max(stage_centroid_values[k], elevation_centroid_values[k]),
    1348       //               min(max(stage_centroid_values[k0], elevation_centroid_values[k0]),
    1349       //                   min(max(stage_centroid_values[k1], elevation_centroid_values[k1]),
    1350       //                       max(stage_centroid_values[k2], elevation_centroid_values[k2]))));
    1351 
    13521212      // Get the auxiliary triangle's vertex coordinates
    13531213      // (really the centroids of neighbouring triangles)
     
    13771237       
    13781238      //// Treat triangles with no neighbours (area2 <=0.)
    1379       if ((area2 <= 0.))//|( cell_wetness_scale[k2]==0. && cell_wetness_scale[k1]==0. && cell_wetness_scale[k0]==0.))//|| (cell_wetness_scale[k]==0.)) //|(count_wet_neighbours[k]==0))
     1239      if ((area2 <= 0.))
    13801240      {
    13811241
     
    14001260          //xmom_centroid_values[k]=0.;
    14011261          //ymom_centroid_values[k]=0.;
    1402           //xmom_centroid_store[k] = 0.;
    1403           //ymom_centroid_store[k] = 0.;
     1262          //x_centroid_work[k] = 0.;
     1263          //y_centroid_work[k] = 0.;
    14041264
    14051265          xmom_edge_values[k3]    = xmom_centroid_values[k];
     
    14141274     
    14151275      // Calculate heights of neighbouring cells
    1416       hc = height_centroid_values[k];//stage_centroid_values[k]  - elevation_centroid_values[k];
    1417       h0 = height_centroid_values[k0];// - elevation_centroid_values[k0];
    1418       h1 = height_centroid_values[k1];// - elevation_centroid_values[k1];
    1419       h2 = height_centroid_values[k2];// - elevation_centroid_values[k2];
     1276      hc = height_centroid_values[k];
     1277      h0 = height_centroid_values[k0];
     1278      h1 = height_centroid_values[k1];
     1279      h2 = height_centroid_values[k2];
    14201280     
    14211281      hmin = min(min(h0, min(h1, h2)), hc);
     
    14281288      //       but is also more 'artefacty' in important cases (tendency for high velocities, etc).
    14291289      //       
    1430       //hfactor=1.0;
    14311290      a_tmp=0.3; // Highest depth ratio with hfactor=1
    14321291      b_tmp=0.1; // Highest depth ratio with hfactor=0
    14331292      c_tmp=1.0/(a_tmp-b_tmp);
    14341293      d_tmp= 1.0-(c_tmp*a_tmp);
     1294      // So hfactor = depth_ratio*(c_tmp) + d_tmp, but is clipped between 0 and 1.
    14351295      hfactor= max(0., min(c_tmp*max(hmin,0.0)/max(hc,1.0e-06)+d_tmp,
    14361296                           min(c_tmp*max(hc,0.)/max(hmax,1.0e-06)+d_tmp, 1.0))
    14371297                  );
    1438       //printf("%e, %e, \n", c_tmp, d_tmp);
    1439       //hfactor= max(0., min(5.0*max(hmin,0.0)/max(hmax,1.0e-06)-0.5, 1.0)
    1440       //            );
    1441       //hfactor=1.0;
    14421298      // Set hfactor to zero smothly as hmin--> minimum_allowed_height. This
    14431299      // avoids some 'chatter' for very shallow flows
     
    14751331   
    14761332      beta_tmp = beta_w_dry + (beta_w - beta_w_dry) * hfactor;
    1477       //beta_tmp = beta_w_dry*0. + (beta_w - beta_w_dry*0.) * hfactor;
    1478       //beta_tmp=1.0;
    1479    
    14801333     
    14811334      // Limit the gradient
     
    14901343      // height
    14911344      //-----------------------------------
    1492       //hfactor=1.0;
    1493       //hfactor= max(0., min(5.0*max(hmin,0.0)/max(hc,1.0e-06)-0.5,
    1494       //                     min(5.0*max(hc,0.)/max(hmax,1.0e-06)-0.5, 1.0))
    1495       //            );
    14961345       
    14971346      // Calculate the difference between vertex 0 of the auxiliary
     
    15221371   
    15231372      // Limit the gradient
     1373      // Same beta_tmp as for stage
    15241374      //beta_tmp = beta_uh_dry + (beta_uh - beta_uh_dry) * hfactor;
    15251375      limit_gradient(dqv, qmin, qmax, beta_tmp);
     
    15311381      height_edge_values[k3+2] = height_centroid_values[k] + dqv[2];
    15321382
    1533 
    1534       // REDEFINE hfactor for momentum terms -- make MORE first order
    1535       // Reduce beta linearly from 1-0 between depth ratio of 0.6-0.4
    1536       //hfactor= max(0., min(5*max(hmin,0.0)/max(hc,1.0e-06)-2.0,
    1537       //                     min(5*max(hc,0.)/max(hmax,1.0e-06)-2.0, 1.0))
    1538       //            );
    1539       //hfactor= max(0., min(5*max(hmin,0.0)/max(hmax,1.0e-06)-2.0,
    1540       //                      1.0));
    1541       //hfactor=min( max(hmin,0.)/(max(hmin,0.)+10.*minimum_allowed_height), hfactor);
    1542       //hfactor=1.0;
    1543      
    15441383      //-----------------------------------
    15451384      // xmomentum
     
    18441683      if(extrapolate_velocity_second_order==1){
    18451684          //Convert velocity back to momenta at centroids
    1846           xmom_centroid_values[k] = xmom_centroid_store[k];
    1847           ymom_centroid_values[k] = ymom_centroid_store[k];
     1685          xmom_centroid_values[k] = x_centroid_work[k];
     1686          ymom_centroid_values[k] = y_centroid_work[k];
    18481687     
    18491688          // Re-compute momenta at edges
     
    18781717   
    18791718  }
    1880 
    1881   free(xmom_centroid_store);
    1882   free(ymom_centroid_store);
    1883   //free(min_elevation_edgevalue);
    1884   //free(max_elevation_edgevalue);
    1885   //free(cell_wetness_scale);
    1886   //free(count_wet_neighbours);
    18871719
    18881720  return 0;
     
    19781810    *riverwall_elevation,
    19791811    *riverwall_rowIndex,
    1980     *riverwall_hydraulic_properties;
     1812    *riverwall_hydraulic_properties,
     1813    *edge_flux_work,
     1814    *pressuregrad_work;
    19811815   
    19821816  double timestep, epsilon, H0, g;
     
    19841818   
    19851819  // Convert Python arguments to C
    1986   if (!PyArg_ParseTuple(args, "ddddOOOOOOOOOOOOOOOOOOOOOOiiOOOOOOOOiO",
     1820  if (!PyArg_ParseTuple(args, "ddddOOOOOOOOOOOOOOOOOOOOOOiiOOOOOOOOiOOO",
    19871821            &timestep,
    19881822            &epsilon,
     
    20211855            &riverwall_rowIndex,
    20221856            &ncol_riverwall_hydraulic_properties,
    2023             &riverwall_hydraulic_properties
     1857            &riverwall_hydraulic_properties,
     1858            &edge_flux_work,
     1859            &pressuregrad_work
    20241860            )) {
    20251861    report_python_error(AT, "could not parse input arguments");
     
    20591895  CHECK_C_CONTIG(riverwall_rowIndex);
    20601896  CHECK_C_CONTIG(riverwall_hydraulic_properties);
     1897  CHECK_C_CONTIG(edge_flux_work);
     1898  CHECK_C_CONTIG(pressuregrad_work);
    20611899
    20621900  int number_of_elements = stage_edge_values -> dimensions[0];
     
    21031941                     (long*)   riverwall_rowIndex-> data,
    21041942                     ncol_riverwall_hydraulic_properties,
    2105                      (double*) riverwall_hydraulic_properties ->data);
     1943                     (double*) riverwall_hydraulic_properties ->data,
     1944                     (double*) edge_flux_work-> data,
     1945                     (double*) pressuregrad_work->data);
    21061946  // Return updated flux timestep
    21071947  return Py_BuildValue("d", timestep);
     
    22742114    *ymom_vertex_values,
    22752115    *elevation_vertex_values,
    2276     *height_vertex_values;
     2116    *height_vertex_values,
     2117    *x_centroid_work,
     2118    *y_centroid_work;
    22772119 
    22782120  PyObject *domain;
     
    22842126 
    22852127  // Convert Python arguments to C
    2286   if (!PyArg_ParseTuple(args, "OOOOOOOOOOOOOOOOOOOOOii",
     2128  if (!PyArg_ParseTuple(args, "OOOOOOOOOOOOOOOOOOOOOiiOO",
    22872129            &domain,
    22882130            &surrogate_neighbours,
     
    23072149            &height_vertex_values,
    23082150            &optimise_dry_cells,
    2309             &extrapolate_velocity_second_order)) {         
     2151            &extrapolate_velocity_second_order,
     2152            &x_centroid_work,
     2153            &y_centroid_work)) {         
    23102154
    23112155    report_python_error(AT, "could not parse input arguments");
     
    23342178  CHECK_C_CONTIG(elevation_vertex_values);
    23352179  CHECK_C_CONTIG(height_vertex_values);
     2180  CHECK_C_CONTIG(x_centroid_work);
     2181  CHECK_C_CONTIG(y_centroid_work);
    23362182 
    23372183  // Get the safety factor beta_w, set in the config.py file.
     
    23842230                   (double*) height_vertex_values -> data,
    23852231                   optimise_dry_cells,
    2386                    extrapolate_velocity_second_order);
     2232                   extrapolate_velocity_second_order,
     2233                   (double*) x_centroid_work -> data,
     2234                   (double*) y_centroid_work -> data);
    23872235
    23882236  if (e == -1) {
  • trunk/anuga_work/development/gareth/tests/runup_sinusoid/runup_sinusoid.py

    r9257 r9260  
    2020domain.set_name('runup_sinusoid_v2')                         # Output to file runup.sww
    2121#domain.set_store_centroids(True)
    22 domain.set_flow_algorithm('DE0')
     22domain.set_flow_algorithm('DE1')
    2323domain.set_quantities_to_be_stored({'stage': 2, 'xmomentum': 2,
    2424         'ymomentum': 2, 'elevation': 2})
Note: See TracChangeset for help on using the changeset viewer.