Changeset 8867


Ignore:
Timestamp:
May 16, 2013, 8:57:00 PM (11 years ago)
Author:
davies
Message:

Updated to bal_dev

Location:
trunk/anuga_work/development/gareth
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_work/development/gareth/experimental/balanced_dev/swb2_domain_ext.c

    r8866 r8867  
    108108                           double *edgeflux, double *max_speed,
    109109                           double *pressure_flux, double hc,
    110                            double hc_n,
    111                            double speed_max_last)
     110                           double hc_n, double speed_max_last,
     111                           double smooth)
    112112{
    113113
     
    129129  double s_min, s_max, soundspeed_left, soundspeed_right;
    130130  double denom, inverse_denominator, z;
    131   double uint, t1, t2, t3, min_speed;
     131  double uint, t1, t2, t3, min_speed, tmp;
    132132  // Workspace (allocate once, use many)
    133133  static double q_left_rotated[3], q_right_rotated[3], flux_right[3], flux_left[3];
     
    277277      //edgeflux[i] += (s_max*s_min)*(q_right_rotated[i] - q_left_rotated[i]);
    278278
     279      // Standard smoothing term, scaled
     280      //edgeflux[i] += (s_max*s_min)*(q_right_rotated[i] - q_left_rotated[i])*smooth;
     281
    279282      // Adjustment to the scheme by Kurganov and Lin 2007 Communications in Computational
    280283      // Physics 2:141-163
    281       //uint = (s_max*q_right_rotated[i] - s_min*q_left_rotated[i] - (flux_right[i] - flux_left[i]))*inverse_denominator;
    282       //t1 = (q_right_rotated[i] - uint);
    283       //t2 = (-q_left_rotated[i] + uint);
    284       //t3 = _minmod(t1,t2);
    285       //edgeflux[i] += (s_max*s_min)*(q_right_rotated[i] - q_left_rotated[i]-t3);
     284      uint = (s_max*q_right_rotated[i] - s_min*q_left_rotated[i] - (flux_right[i] - flux_left[i]))*inverse_denominator;
     285      t1 = (q_right_rotated[i] - uint);
     286      t2 = (-q_left_rotated[i] + uint);
     287      t3 = _minmod(t1,t2);
     288      edgeflux[i] += (s_max*s_min)*(q_right_rotated[i] - q_left_rotated[i]-t3);
     289
     290      // test this
     291      //edgeflux[i] += (s_max*s_min)*(q_right_rotated[i] - q_left_rotated[i])*pow(min(hc/(hc_n+epsilon), hc_n/(hc+epsilon)),1.0);
     292   
     293      // test this
     294      //tmp=min(fabs(q_right_rotated[i])/(fabs(q_left_rotated[i])+epsilon) , fabs(q_left_rotated[i])/(fabs(q_right_rotated[i])+epsilon));
     295      //edgeflux[i] += (s_max*s_min)*(q_right_rotated[i] - q_left_rotated[i]-t3)*pow(tmp,1.0);
    286296
    287297      //GD HACK: Here, we supress the 'smoothing' part of the flux -- like scaling diffusion by local wave speed
     298      // This is a bad idea! E.g. oscillations in landslide wave runup case
     299      // However, it does supress the growth of some wet-dry instabilities (e.g. PNG).
    288300      //if(i!=2){
    289       edgeflux[i] += (s_max*s_min)*(q_right_rotated[i] - q_left_rotated[i])*
    290                      (min(*max_speed/(max(speed_max_last,1.0e-100)),1.0));//(min(hc/h_left,min(hc_n/h_right,1.0)));
     301      //edgeflux[i] += (s_max*s_min)*(q_right_rotated[i] - q_left_rotated[i])*
     302      //               (min(*max_speed/(max(speed_max_last,1.0e-100)),1.0));//(min(hc/h_left,min(hc_n/h_right,1.0)));
    291303      //}
    292304
     
    357369    double stage_edge_lim, outgoing_mass_edges, bedtop, bedbot, pressure_flux, hc, hc_n, tmp, tmp2;
    358370    static long call = 1; // Static local variable flagging already computed flux
    359     double speed_max_last, vol;
    360 
    361     double *max_bed_edgevalue, *min_bed_edgevalue, *edgeflux_store, *pressuregrad_store;
    362 
    363     max_bed_edgevalue = malloc(number_of_elements*sizeof(double));
     371    double speed_max_last, vol, smooth;
     372
     373    double *count_wet_edges, *count_wet_neighbours, *edgeflux_store, *pressuregrad_store;
     374
     375    count_wet_neighbours = malloc(number_of_elements*sizeof(double));
     376    count_wet_edges = malloc(number_of_elements*sizeof(double));
    364377    edgeflux_store = malloc(number_of_elements*9*sizeof(double));
    365378    pressuregrad_store = malloc(number_of_elements*3*sizeof(double));
     
    379392    speed_max_last=0.0;
    380393    for (k = 0; k < number_of_elements; k++){
    381         max_bed_edgevalue[k] = max(bed_edge_values[3*k],
    382                                    max(bed_edge_values[3*k+1], bed_edge_values[3*k+2]));
     394       
     395        count_wet_edges[k] = 0.;
     396        count_wet_neighbours[k] = 0.;
     397        for (i =0; i<3; i++){
     398            ki=3*k+i;
     399            if(stage_edge_values[ki] > bed_edge_values[ki]+epsilon) count_wet_edges[k]+=1.0;
     400           
     401            n=neighbours[ki];
     402            if(n<0 || stage_centroid_values[n] > bed_centroid_values[n]+h0+epsilon) count_wet_neighbours[k]+=1.0;
     403        }
     404
    383405        speed_max_last=max(speed_max_last, max_speed_array[k]);
    384 
    385         //if(stage_centroid_values[k]<bed_centroid_values[k]){
    386         //    printf("Stage < bed");
    387         //}
    388406    }
    389 
    390     //printf("SML: %.12lf, %.12lf, %.12lf \n", speed_max_last, fabs(-speed_max_last), max(speed_max_last*2.0, 0.5*speed_max_last)/2.0);
    391 
    392     //printf("SPM: %lf \n", speed_max_last);
    393407
    394408    // For all triangles
     
    459473            //}
    460474
     475            smooth=1.0;
     476            //if((count_wet_edges[k]<=1.0 | count_wet_neighbours[k]<=1.0) &
     477            //    (n>=0 && (count_wet_edges[n]<=1.0 | count_wet_neighbours[n]<=1.0))){
     478            //    smooth=0.0;
     479            //}
     480           
    461481            // Edge flux computation (triangle k, edge i)
    462482            _flux_function_central(ql, qr, zl, zr,
     
    464484                    epsilon, h0, limiting_threshold, g,
    465485                    edgeflux, &max_speed, &pressure_flux, hc, hc_n,
    466                     speed_max_last);
     486                    speed_max_last, smooth);
    467487
    468488           
     
    478498
    479499            // Update triangle k with flux from edge i
    480 
    481500            // bedslope_work contains all gravity related terms -- weighting of
    482501            // conservative and non-conservative versions.
    483502            if(hc> h0){
     503            //if(stage_centroid_values[k] > count_wet_edges[k]){
    484504              bedslope_work = length*(g*(hc*ql[0]-0.5*max(ql[0]-zl,0.)*(ql[0]-zl)) + pressure_flux);
    485               //bedslope_work = length*(g*(hc*stage_centroid_values[k]-0.5*max(ql[0]-zl,0.)*(ql[0]-zl)) + pressure_flux);
     505              //bedslope_work = length*(g*(hc*stage_centroid_values[k]*0.-
     506              //                           0.5*max(stage_centroid_values[k]-zl,0.)*(stage_centroid_values[k]-zl))
     507              //                        + pressure_flux);
    486508              //bedslope_work+= (1.0-tmp)*length*g*hc*ql[0]; // Non-conservative water surface slope
    487509              pressuregrad_store[ki] = bedslope_work;
    488510            }else{
     511              // NOTE: When hc<h0, pressure_flux is entirely computed from the
     512              // other side of the edge. Hence, we can't necessarily satisfy
     513              // well-balancing by just assuming that the 2nd and 3rd terms in
     514              // bedslope_work cancel. So, we force it here -- equivalent to
     515              // using the water surface gravity term
    489516              bedslope_work = length*(g*(hc*ql[0]-0.0*max(ql[0]-zl,0.)*(ql[0]-zl)) + 0.0*pressure_flux);
    490517              //bedslope_work = length*(g*(hc*stage_centroid_values[k]-0.0*max(ql[0]-zl,0.)*(ql[0]-zl)) + 0.0*pressure_flux);
     
    492519              pressuregrad_store[ki] = bedslope_work;
    493520            }
    494            
     521
     522            //if(count_wet_edges[k]<=1.0) pressuregrad_store[ki]=0.0;
     523
    495524            already_computed_flux[ki] = call; // #k Done
    496525
     
    504533
    505534                if(hc_n> h0){
     535                //if(stage_centroid_values[n] > count_wet_edges[n]){
    506536                  bedslope_work = length*(g*(hc_n*qr[0]-0.5*max(qr[0]-zr,0.)*(qr[0]-zr)) + pressure_flux);
    507                   //bedslope_work = length*(g*(hc_n*stage_centroid_values[n]-0.5*max(qr[0]-zr,0.)*(qr[0]-zr)) + pressure_flux);
     537                  //bedslope_work = length*(g*(hc_n*stage_centroid_values[n]*0.-0.5*max(stage_centroid_values[n]-zr,0.)*
     538                  //                                (stage_centroid_values[n]-zr)) + pressure_flux);
    508539                  //bedslope_work+= (1.-tmp)*length*g*hc_n*qr[0]; 
    509540                  pressuregrad_store[nm] = bedslope_work;
    510541                }else{
     542                  // NOTE: When hc<h0, pressure_flux is entirely computed from the
     543                  // other side of the edge. Hence, we can't necessarily satisfy
     544                  // well-balancing by just assuming that the 2nd and 3rd terms in
     545                  // bedslope_work cancel. So, we force it here -- equivalent to
     546                  // using the water surface gravity term
    511547                  bedslope_work = length*(g*(hc_n*qr[0]-0.0*max(qr[0]-zr,0.)*(qr[0]-zr)) + 0.0*pressure_flux);
    512548                  //bedslope_work = length*(g*(hc_n*stage_centroid_values[n]-0.0*max(qr[0]-zr,0.)*(qr[0]-zr)) + 0.0*pressure_flux);
     
    514550                  pressuregrad_store[nm] = bedslope_work;
    515551                }
     552           
     553                //if(count_wet_edges[n]<=1.0) pressuregrad_store[nm]=0.0;
    516554
    517555                already_computed_flux[nm] = call; // #n Done
    518556            }
    519557
     558            //if(n==576 | n==579) pressuregrad_store[nm]=0.;
    520559            // Update timestep based on edge i and possibly neighbour n
    521560            // GD HACK:
     
    709748    //return -1;
    710749//
    711     free(max_bed_edgevalue);
    712     //free(min_bed_edgevalue);
     750    free(count_wet_edges);
     751    free(count_wet_neighbours);
    713752    free(edgeflux_store);
    714753    free(pressuregrad_store);
     
    739778  // distance between the bed_centroid_value and the max bed_edge_value of
    740779  // every triangle.
    741   double minimum_relative_height=0.0;
     780  double minimum_relative_height=0.1;
    742781  int mass_added=0;
    743782
     
    747786      hc = wc[k] - zc[k];
    748787      // Definine the maximum bed edge value on triangle k.
    749       //bmax = 0.5*max((zv[3*k]+zv[3*k+1]),max((zv[3*k+1]+zv[3*k+2]),(zv[3*k+2]+zv[3*k])));
     788      bmax = 0.5*max((zv[3*k]+zv[3*k+1]),max((zv[3*k+1]+zv[3*k+2]),(zv[3*k+2]+zv[3*k])));
    750789
    751790      //if (hc < max(minimum_relative_height*(bmax-zc[k]), minimum_allowed_height)) {
     
    755794
    756795
    757       //if (hc < max(minimum_relative_height*(bmax-zc[k]), minimum_allowed_height)) {
    758       if (hc < minimum_allowed_height*2.0) {
     796      //if (hc < minimum_allowed_height*2.0 | hc < minimum_relative_height*(bmax-zc[k]) ){
     797      if (hc < minimum_allowed_height*2.0 ){
    759798            // Set momentum to zero and ensure h is non negative
    760             //xmomc[k] = 0.;//xmomc[k]*hc*max(hc-minimum_allowed_height,0.)/(2.0*minimum_allowed_height*minimum_allowed_height);// 0.0;
    761             //ymomc[k] = 0.;//ymomc[k]*hc*max(hc-minimum_allowed_height,0.)/(2.0*minimum_allowed_height*minimum_allowed_height);// 0.0;
     799            xmomc[k] = 0.;//xmomc[k]*hc*max(hc-minimum_allowed_height,0.)/(2.0*minimum_allowed_height*minimum_allowed_height);// 0.0;
     800            ymomc[k] = 0.;//ymomc[k]*hc*max(hc-minimum_allowed_height,0.)/(2.0*minimum_allowed_height*minimum_allowed_height);// 0.0;
    762801            //xmomc[k] = xmomc[k]*hc*max(hc-minimum_allowed_height,0.)/(2.0*minimum_allowed_height*minimum_allowed_height);// 0.0;
    763802            //ymomc[k] = ymomc[k]*hc*max(hc-minimum_allowed_height,0.)/(2.0*minimum_allowed_height*minimum_allowed_height);// 0.0;
    764             xmomc[k] = xmomc[k]*max(hc-minimum_allowed_height,0.)/(minimum_allowed_height);// 0.0;
    765             ymomc[k] = ymomc[k]*max(hc-minimum_allowed_height,0.)/(minimum_allowed_height);// 0.0;
     803            //xmomc[k] = xmomc[k]*max(hc-minimum_allowed_height,0.)/(minimum_allowed_height);// 0.0;
     804            //ymomc[k] = ymomc[k]*max(hc-minimum_allowed_height,0.)/(minimum_allowed_height);// 0.0;
    766805
    767806        if (hc <= 0.0){
     
    19652004  PyArrayObject *normal, *ql, *qr,  *edgeflux;
    19662005  double g, epsilon, max_speed, H0, zl, zr;
    1967   double h0, limiting_threshold, pressure_flux;
     2006  double h0, limiting_threshold, pressure_flux, smooth;
    19682007
    19692008  if (!PyArg_ParseTuple(args, "OOOddOddd",
     
    19812020 
    19822021  pressure_flux = 0.0; // Store the water pressure related component of the flux
     2022  smooth = 1.0 ; // term to scale diffusion in riemann solver
     2023
    19832024  _flux_function_central((double*) ql -> data,
    19842025                         (double*) qr -> data,
     
    19942035                         ((double*) normal -> data)[0],
    19952036                         ((double*) normal -> data)[1],
    1996                          ((double*) normal -> data)[1]
     2037                         ((double*) normal -> data)[1],
     2038             smooth
    19972039             );
    19982040 
  • trunk/anuga_work/development/gareth/tests/channel_floodplain/plotme.py

    r8774 r8867  
    44
    55# Time-index to plot outputs from
    6 index=600
     6index=900
    77
    88#p2 = util.get_output('channel_floodplain1_bal_dev.sww', minimum_allowed_height=0.01)
  • trunk/anuga_work/development/gareth/tests/dam_break/plotme.py

    r8865 r8867  
    99p2_st=util.get_centroids(p_st)
    1010
    11 p_dev = util.get_output('dam_break_20130504_145918/dam_break.sww', 0.001)
     11p_dev = util.get_output('dam_break_20130514_201704/dam_break.sww', 0.001)
    1212p2_dev=util.get_centroids(p_dev, velocity_extrapolation=True)
    1313
  • trunk/anuga_work/development/gareth/tests/runup_sinusoid/runup_sinusoid.py

    r8866 r8867  
    2828# Define topography
    2929#------------------
    30 scale_me=1.0
    31 boundary_ws=-0.1
     30
     31### Pathological
     32scale_me=100.0
     33boundary_ws=-0.1999
    3234init_ws=-0.2
    33 bumpiness=10. # Higher = shorter wavelength oscillations in topography
     35bumpiness=50. # Higher = shorter wavelength oscillations in topography
     36tstep=0.002
     37lasttime=1.1
     38
     39### Sensible
     40#scale_me=1.0
     41#boundary_ws=-0.1
     42#init_ws=-0.2
     43#bumpiness=50. # Higher = shorter wavelength oscillations in topography
     44#tstep=0.2
     45#lasttime=40.
     46
    3447#domain.minimum_allowed_height=domain.minimum_allowed_height*scale_me # Seems needed to make the algorithms behave
    3548
     
    8295#------------------------------
    8396
    84 for t in domain.evolve(yieldstep=0.2,finaltime=120.00):
     97for t in domain.evolve(yieldstep=tstep,finaltime=lasttime):
     98#for t in domain.evolve(yieldstep=0.2,finaltime=60.):
    8599    print domain.timestepping_statistics()
    86100    #print domain.boundary_flux_integral
  • trunk/anuga_work/development/gareth/tests/wave_runup/plotme.py

    r8751 r8867  
    22import util
    33from matplotlib import pyplot as pyplot
    4 import numpy
     4import scipy, numpy
    55
    66p= util.get_output('runup_v2.sww')
     
    3939
    4040    pyplot.plot(p2.x[v], p2.elev[v], '--', color='green')
    41     pyplot.title('Time ' + str(round(t,2)))
     41    pyplot.title('Stage (red is analytical): Time ' + str(round(t,2)))
    4242    pyplot.ylim((-25,20))
    4343    pyplot.savefig('figure_stage_'+str(i)+'.png')
     
    5252        pyplot.plot(t220[:,0], t220[:,2],'-',color='red')
    5353    pyplot.ylim((-25,20))
    54     pyplot.title('Time ' + str(round(t,2)))
     54    pyplot.title('Velocity (red is analytical): Time ' + str(round(t,2)))
    5555    pyplot.savefig('figure_vel_'+str(i)+'.png')
    5656    pyplot.clf()
     
    5959model_shore_x=p2.time*0.
    6060model_shore_u=p2.time*0.
     61
     62# Hacks to identify the location of the shoreline
     63shoreline_depth_thresh1=0.01
     64shoreline_depth_thresh2=0.4
     65
    6166for i in range(len(model_shore_x)):
    6267    # Compute index of shoreline
    63     vtmp = p2.stage[i,:]>p2.elev+0.002
    64     # FIXME -- introduced a bug here
     68    vtmp = p2.stage[i,:]>p2.elev+shoreline_depth_thresh1
     69   
    6570    model_shore_x[i]=p2.x[vtmp].min()
    66     #v_ind=p2.x[vtmp].argmin()
     71    #v_ind=(p2.stage[i,vtmp]-p2.elev[vtmp]).argmin()
    6772    # Store x and xvel
    6873    #model_shore_x[i]=p2.x[vtmp[v_ind]]
    6974    #model_shore_u[i]=p2.xvel[i,vtmp[v_ind]]
    7075
     76    # Extract shoreline velocity. It is tricky, to avoid getting
     77    # zero velocity points -- might be a better way to do it?
     78    vtmp2= (p2.stage[i,:]>p2.elev+shoreline_depth_thresh1)*\
     79           (p2.stage[i,:]<p2.elev+shoreline_depth_thresh2)
     80    mloc=abs(p2.xvel[i,vtmp2]).argmax()
     81    #print abs(p2.xvel[i,vtmp2]).max(), mloc
     82    model_shore_u[i]=p2.xvel[i,vtmp2][mloc]
     83    #vtmp2 = (p2.stage[i,:]>p2.elev+0.01)
     84    #mloc= (vtmp2*(p2.stage[i,:]-p2.elev)).argmin()
     85    #model_shore_u[i] = p2.xvel[i,mloc]
     86
    7187pyplot.plot(p2.time, model_shore_x-200.,'-o')
    7288pyplot.plot(shoreline[:,0], shoreline[:,1],'-', color='red')
     89pyplot.title('Shoreline position (where depth >'+str(shoreline_depth_thresh1)+')')
    7390pyplot.savefig('Shoreline_position.png')
    7491
    7592# Can plot velocity as well -- but notice that velocity at the shoreline
    7693# keeps being set to zero, so the model result is constant zeros
    77 # pyplot.plot(p2.time, model_shore_u,'-o')
    78 # pyplot.plot(shoreline[:,0], shoreline[:,2],'-',color='red')
     94pyplot.clf()
     95pyplot.plot(p2.time, model_shore_u,'-o')
     96pyplot.plot(shoreline[:,0], shoreline[:,2],'-',color='red')
     97pyplot.title('Shoreline velocity: Peak speed where depth >'\
     98             + str(shoreline_depth_thresh1) + ' and depth < '\
     99             + str(shoreline_depth_thresh2))
     100pyplot.savefig('Shoreline_velocity.png')
Note: See TracChangeset for help on using the changeset viewer.