Changeset 8866


Ignore:
Timestamp:
May 13, 2013, 5:09:25 PM (12 years ago)
Author:
davies
Message:

Updates to bal_dev

Location:
trunk/anuga_work/development/gareth
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_work/development/gareth/experimental/balanced_dev/swb2_domain.py

    r8865 r8866  
    6666        self.set_CFL(1.0)
    6767        self.set_use_kinematic_viscosity(False)
    68         self.timestepping_method='rk2'#'rk2'#'euler'#'rk2'
     68        self.timestepping_method='rk2'#'rk2'#'rk2'#'euler'#'rk2'
    6969        # The following allows storage of the negative depths associated with this method
    7070        self.minimum_storable_height=-99999999999.0
     
    7474        self.extrapolate_velocity_second_order=True
    7575
    76         # Note that the extrapolation method used in quantity_ext.c (e.g.
    77         # extrapolate_second_order_and_limit_by_edge) uses a constant value for
    78         # all the betas. 
    7976        self.beta_w=0.0
    8077        self.beta_w_dry=0.0
     
    8380        self.beta_vh=0.0
    8481        self.beta_vh_dry=0.0
     82
     83        #self.epsilon=1.0e-100
    8584
    8685        #self.optimise_dry_cells=True
     
    111110        self.boundary_flux_sum=numpy.ndarray(1)
    112111        self.boundary_flux_sum[0]=0.
     112
     113        self.call=1 # Integer counting how many times we call compute_fluxes_central
     114
     115        # Integer recording the order of the time-stepping scheme
     116        if(self.timestepping_method=='rk2'):
     117          self.timestep_order=2
     118        elif(self.timestepping_method=='euler'):
     119          self.timestep_order=1
     120        elif(self.timestepping_method=='rk3'):
     121          self.timestep_order=3
     122        else:
     123          err_mess='ERROR: timestepping_method= ' + self.timestepping_method +' not supported in this solver'
     124          raise Exception, err_mess
    113125
    114126        print '##########################################################################'
     
    252264        #    raise Exception, err_mess
    253265
    254         if(domain.timestepping_method=='rk2'):
    255           timestep_order=2
    256         elif(domain.timestepping_method=='euler'):
    257           timestep_order=1
     266        #if(domain.timestepping_method=='rk2'):
     267        #  timestep_order=2
     268        #elif(domain.timestepping_method=='euler'):
     269        #  timestep_order=1
    258270        #elif(domain.timestepping_method=='rk3'):
    259271        #  timestep_order=3
    260         else:
    261           err_mess='ERROR: domain.timestepping_method= ' + domain.timestepping_method +' not supported in this solver'
    262           raise Exception, err_mess
    263 
    264         #print 'timestep_order=', timestep_order
     272        #else:
     273        #  err_mess='ERROR: domain.timestepping_method= ' + domain.timestepping_method +' not supported in this solver'
     274        #  raise Exception, err_mess
     275
     276        ##print 'timestep_order=', timestep_order
    265277
    266278        Stage = domain.quantities['stage']
     
    271283        timestep = float(sys.maxint)
    272284
     285        domain.call+=1
    273286        flux_timestep = compute_fluxes_ext(timestep,
    274287                                           domain.epsilon,
     
    297310                                           domain.max_speed,
    298311                                           int(domain.optimise_dry_cells),
    299                                            timestep_order,
     312                                           domain.timestep_order,
    300313                                           Stage.centroid_values,
    301314                                           Xmom.centroid_values,
     
    304317                                           Bed.vertex_values)
    305318
    306         #import pdb
    307         #pdb.set_trace()
    308         #print 'flux timestep: ', flux_timestep, domain.timestep
     319
     320        # Update the boundary flux integral
    309321        if(domain.timestepping_method=='rk2'):
    310           if(flux_timestep == float(sys.maxint)):
     322            if(domain.call%2==1):
    311323              domain.boundary_flux_integral[0]= domain.boundary_flux_integral[0] +\
    312324                                                domain.boundary_flux_sum[0]*domain.timestep*0.5
    313325              #print 'dbfi ', domain.boundary_flux_integral, domain.boundary_flux_sum
    314326              domain.boundary_flux_sum[0]=0.
     327
     328        elif(domain.timestepping_method=='euler'):
     329            domain.boundary_flux_integral=0.
     330            # This presently doesn't work -- this section of code may need to go elsewhere
     331            #domain.boundary_flux_integral[0]= domain.boundary_flux_integral[0] +\
     332            #                                  domain.boundary_flux_sum[0]*domain.timestep
     333            #domain.boundary_flux_sum[0]=0.
     334
     335        elif(domain.timestepping_method=='rk3'):
     336            domain.boundary_flux_integral=0.
     337            # This needs to be designed
     338        else:
     339            mess='ERROR: domain.timestepping_method', domain.timestepping_method,' method not recognised'
     340            raise Exception, mess
    315341
    316342        domain.flux_timestep = flux_timestep
  • trunk/anuga_work/development/gareth/experimental/balanced_dev/swb2_domain_ext.c

    r8865 r8866  
    8585}
    8686
     87// minmod limiter
     88int _minmod(double a, double b){
     89    // Compute minmod
     90
     91    if(sign(a)!=sign(b)){
     92        return 0.0;
     93    }else{
     94        return min(fabs(a), fabs(b))*sign(a);
     95    }
     96
     97
     98}
     99
    87100// Innermost flux function (using stage w=z+h)
    88101int _flux_function_central(double *q_left, double *q_right,
     
    116129  double s_min, s_max, soundspeed_left, soundspeed_right;
    117130  double denom, inverse_denominator, z;
    118   double uint, t1, t2, t3;
     131  double uint, t1, t2, t3, min_speed;
    119132  // Workspace (allocate once, use many)
    120133  static double q_left_rotated[3], q_right_rotated[3], flux_right[3], flux_left[3];
     
    145158  if(h_left>h0){
    146159    u_left = uh_left/max(h_left, 1.0e-06);
     160    uh_left=h_left*u_left;
    147161  }else{
    148162    u_left=0.;
     163    uh_left=h_left*u_left;
    149164  }
    150165  //u_left = _compute_speed(&uh_left, &h_left,
     
    158173  if(h_right>h0){
    159174    u_right = uh_right/max(h_right, 1.0e-06);
     175    uh_right=h_right*u_right;
    160176  }else{
    161177    u_right=0.;
     178    uh_right=h_right*u_right;
    162179  }
    163180
     
    236253  // Flux computation
    237254  denom = s_max - s_min;
    238   if (denom < epsilon)
     255  //if (denom < -epsilon)
     256  if (0==1)
    239257  {
    240258    // Both wave speeds are very small
     
    242260
    243261    *max_speed = 0.0;
    244     *pressure_flux = 0.0;
    245     //*pressure_flux = 0.5*g*0.5*(h_left*h_left+h_right*h_right);
     262    //*pressure_flux = 0.0;
     263    *pressure_flux = 0.5*g*0.5*(h_left*h_left+h_right*h_right);
    246264  }
    247265  else
     
    249267    // Maximal wavespeed
    250268    *max_speed = max(s_max, -s_min);
    251    
    252     inverse_denominator = 1.0/denom;
     269    //min_speed=min(s_max, -s_min);
     270 
     271    inverse_denominator = 1.0/max(denom,1.0e-100);
    253272    for (i = 0; i < 3; i++)
    254273    {
    255274      edgeflux[i] = s_max*flux_left[i] - s_min*flux_right[i];
     275
    256276      // Standard smoothing term
    257277      //edgeflux[i] += (s_max*s_min)*(q_right_rotated[i] - q_left_rotated[i]);
     278
     279      // Adjustment to the scheme by Kurganov and Lin 2007 Communications in Computational
     280      // 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);
     286
    258287      //GD HACK: Here, we supress the 'smoothing' part of the flux -- like scaling diffusion by local wave speed
     288      //if(i!=2){
    259289      edgeflux[i] += (s_max*s_min)*(q_right_rotated[i] - q_left_rotated[i])*
    260                       (min(*max_speed/(max(speed_max_last,1e-06)),1.0));//(min(hc/h_left,min(hc_n/h_right,1.0)));
     290                     (min(*max_speed/(max(speed_max_last,1.0e-100)),1.0));//(min(hc/h_left,min(hc_n/h_right,1.0)));
     291      //}
     292
    261293      edgeflux[i] *= inverse_denominator;
    262294    }
     
    449481            // bedslope_work contains all gravity related terms -- weighting of
    450482            // conservative and non-conservative versions.
    451             if(hc> -h0){
     483            if(hc> h0){
    452484              bedslope_work = length*(g*(hc*ql[0]-0.5*max(ql[0]-zl,0.)*(ql[0]-zl)) + pressure_flux);
    453485              //bedslope_work = length*(g*(hc*stage_centroid_values[k]-0.5*max(ql[0]-zl,0.)*(ql[0]-zl)) + pressure_flux);
     
    471503                edgeflux_store[nm3 + 2 ] = edgeflux[2];
    472504
    473                 if(hc_n> -h0){
     505                if(hc_n> h0){
    474506                  bedslope_work = length*(g*(hc_n*qr[0]-0.5*max(qr[0]-zr,0.)*(qr[0]-zr)) + pressure_flux);
    475507                  //bedslope_work = length*(g*(hc_n*stage_centroid_values[n]-0.5*max(qr[0]-zr,0.)*(qr[0]-zr)) + pressure_flux);
     
    493525            if ((tri_full_flag[k] == 1) ) {
    494526
    495                 if(call%timestep_order!=0) max_speed = max_speed_array[k]; // HACK to Ensure that local timestep is the same as the last timestep
     527                if((call-2)%timestep_order!=0) max_speed = max_speed_array[k]; // HACK to Ensure that local timestep is the same as the last timestep
    496528
    497529                if (max_speed > epsilon) {
     
    585617            // GD HACK
    586618            // Option to limit advective fluxes
    587             if(hc > h0){
     619            if(hc > -h0){
    588620                stage_explicit_update[k] += edgeflux_store[ki3+0];
    589621                // Cut these terms for shallow flows, and protect stationary states from round-off error
     
    598630            if(n<0){
    599631                boundary_flux_sum[0] += edgeflux_store[ki3];
    600                 //printf("%f, %f, %d \n", boundary_flux_sum[0], timestep, ki3);
    601632            }
    602633
    603634            // GD HACK
    604635            // Compute bed slope term
    605             if(hc > h0){
     636            if(hc > -h0){
    606637                xmom_explicit_update[k] -= normals[ki2]*pressuregrad_store[ki];
    607638                ymom_explicit_update[k] -= normals[ki2+1]*pressuregrad_store[ki];
     
    621652    }  // end cell k
    622653
    623     if(call%timestep_order==0) timestep=local_timestep;
     654    if((call-2)%timestep_order==0) timestep=local_timestep; // Hack to ensure we only update the timestep on the first call within each rk2/rk3 step
    624655
    625656    // Look for 'dry' edges, and set momentum (& component of momentum_update)
     
    729760            //xmomc[k] = 0.;//xmomc[k]*hc*max(hc-minimum_allowed_height,0.)/(2.0*minimum_allowed_height*minimum_allowed_height);// 0.0;
    730761            //ymomc[k] = 0.;//ymomc[k]*hc*max(hc-minimum_allowed_height,0.)/(2.0*minimum_allowed_height*minimum_allowed_height);// 0.0;
    731             xmomc[k] = xmomc[k]*hc*max(hc-minimum_allowed_height,0.)/(2.0*minimum_allowed_height*minimum_allowed_height);// 0.0;
    732             ymomc[k] = ymomc[k]*hc*max(hc-minimum_allowed_height,0.)/(2.0*minimum_allowed_height*minimum_allowed_height);// 0.0;
     762            //xmomc[k] = xmomc[k]*hc*max(hc-minimum_allowed_height,0.)/(2.0*minimum_allowed_height*minimum_allowed_height);// 0.0;
     763            //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;
    733766
    734767        if (hc <= 0.0){
     
    805838  // Any provisional jump with magnitude < TINY does not contribute to
    806839  // the limiting process.
     840  //return 0;
    807841 
    808842  for (i=0;i<3;i++){
     
    821855  dqv[1]=dqv[1]*phi;
    822856  dqv[2]=dqv[2]*phi;
     857
     858 
     859  //printf("%lf \n ", beta_w);
    823860   
    824861  return 0;
     
    11201157              }else{
    11211158                // Constant stage extrapolation
    1122                 stage_edge_values[k3]   = stage_centroid_values[k];
    1123                 stage_edge_values[k3+1] = stage_centroid_values[k];
    1124                 stage_edge_values[k3+2] = stage_centroid_values[k];
     1159                //stage_edge_values[k3]   = stage_centroid_values[k];
     1160                //stage_edge_values[k3+1] = stage_centroid_values[k];
     1161                //stage_edge_values[k3+2] = stage_centroid_values[k];
    11251162              }
    11261163            //}else{
     
    12231260              //}
    12241261              // First order momentum / velocity extrapolation
    1225               //stage_edge_values[k3]    = stage_centroid_values[k];
    1226               //stage_edge_values[k3+1]  = stage_centroid_values[k];
    1227               //stage_edge_values[k3+2]  = stage_centroid_values[k];
     1262              stage_edge_values[k3]    = stage_centroid_values[k];
     1263              stage_edge_values[k3+1]  = stage_centroid_values[k];
     1264              stage_edge_values[k3+2]  = stage_centroid_values[k];
    12281265              xmom_edge_values[k3]    = xmom_centroid_values[k];
    12291266              xmom_edge_values[k3+1]  = xmom_centroid_values[k];
     
    12511288            //hfactor=hmin/(hmin + 0.004);
    12521289          //}
    1253           hfactor= min(2.0*max(hmin,0.0)/max(hc,max(0.5*(bedmax-bedmin),minimum_allowed_height*10.)), 1.0);
     1290          hfactor= min(2.0*max(hmin,0.0)/max(hc,max(0.5*(bedmax-bedmin),minimum_allowed_height*2.)), 1.0);
    12541291          //hfactor= min(2.0*max(hmin,0.0)/max(hc,max(0.5*(bedmax-bedmin),minimum_allowed_height)), 1.0);
    12551292         
     
    13171354          //if(count_wet_neighbours[k]>0){
    13181355          limit_gradient(dqv, qmin, qmax, beta_tmp);
     1356          //printf("%lf \n ", beta_tmp);
    13191357          //}
    13201358          //}
  • trunk/anuga_work/development/gareth/tests/runup_sinusoid/runup_sinusoid.py

    r8865 r8866  
    9494    print 'Peak velocity is: ', vv.max(), vv.argmax(), dd[vv.argmax()]
    9595    print 'Volume is', sum(dd_raw*domain.areas)   
    96     #print 'Volume less flux int', sum(dd_raw*domain.areas) - domain.boundary_flux_integral
     96    print 'Volume less flux int', sum(dd_raw*domain.areas) - domain.boundary_flux_integral
    9797
    9898
Note: See TracChangeset for help on using the changeset viewer.