Changeset 8375


Ignore:
Timestamp:
Mar 31, 2012, 2:47:12 PM (13 years ago)
Author:
davies
Message:

balanced_dev: fixed stack overflow problem, & new 'transect plot'
routine in util.py

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

Legend:

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

    r8356 r8375  
    144144        # self.check_integrity()
    145145
     146        #print 'Into Evolve'
     147
    146148        msg = 'Attribute self.beta_w must be in the interval [0, 2]'
    147149        assert 0 <= self.beta_w <= 2.0, msg
     
    155157        if self.store is True and self.get_time() == self.get_starttime():
    156158            self.initialise_storage()
    157 
     159        #print 'Into Generic_Domain Evolve'
    158160        # Call basic machinery from parent class
    159161        for t in Generic_Domain.evolve(self, yieldstep=yieldstep,
    160162                                       finaltime=finaltime, duration=duration,
    161163                                       skip_initial_step=skip_initial_step):
     164            #print 'Out of Generic_Domain Evolve'
    162165            # Store model data, e.g. for subsequent visualisation
    163166            if self.store is True:
     
    208211        from swb2_domain_ext import compute_fluxes_ext_central \
    209212                                      as compute_fluxes_ext
     213
     214        #print "."
    210215
    211216        # Shortcuts
     
    364369
    365370        # Remove very thin layers of water
     371        #print 'Before protect'
    366372        domain.protect_against_infinitesimal_and_negative_heights()
     373        #print 'After protect'
    367374
    368375        #for name in domain.conserved_quantities:
     
    378385        #        raise Exception('Unknown order')
    379386       
     387        #print 'Before extrapolate'
    380388        domain.extrapolate_second_order_edge_sw()
     389        #print 'After extrapolate'
    381390
    382391        #balance_deep_and_shallow(domain)
  • trunk/anuga_work/development/gareth/experimental/balanced_dev/swb2_domain_ext.c

    r8359 r8375  
    787787  double dqv[3], qmin, qmax, hmin, hmax, bedmax, stagemin;
    788788  double hc, h0, h1, h2, beta_tmp, hfactor;
    789   double xmom_centroid_store[number_of_elements], ymom_centroid_store[number_of_elements], dk, dv0, dv1, dv2, de[3];
    790   double stage_centroid_store[number_of_elements];
    791    
     789  double dk, dv0, dv1, dv2, de[3];
     790  //double xmom_centroid_store[number_of_elements], ymom_centroid_store[number_of_elements]
     791  //double stage_centroid_store[number_of_elements];
     792 
     793  double *xmom_centroid_store, *ymom_centroid_store, *stage_centroid_store;
     794
     795  // Use malloc to avoid putting these variables on the stack, which can cause
     796  // segfaults in large model runs
     797  xmom_centroid_store = malloc(number_of_elements*sizeof(double));
     798  ymom_centroid_store = malloc(number_of_elements*sizeof(double));
     799  stage_centroid_store = malloc(number_of_elements*sizeof(double));
     800 
    792801  if(extrapolate_velocity_second_order==1){
    793802      // Replace momentum centroid with velocity centroid to allow velocity
     
    819828
    820829    if (number_of_boundaries[k]==3)
     830    //if (0==0)
    821831    {
    822832      // No neighbours, set gradient on the triangle to zero
     
    13661376      }
    13671377  }
     1378
     1379  free(xmom_centroid_store);
     1380  free(ymom_centroid_store);
     1381  free(stage_centroid_store);
    13681382
    13691383  return 0;
     
    18591873  number_of_elements = stage_centroid_values -> dimensions[0]; 
    18601874
     1875  //printf("In C before Extrapolate");
     1876  //e=1;
    18611877  // Call underlying computational routine
    18621878  e = _extrapolate_second_order_edge_sw(number_of_elements,
     
    18841900                   extrapolate_velocity_second_order);
    18851901
     1902  //printf("In C before edges-to-vertices");
    18861903
    18871904  //Extrapolate from edges to vertices
     
    18961913                                      (double *) elevation_vertex_values -> data,
    18971914                                      extrapolate_velocity_second_order);
     1915  //printf("In C after edges-to-vertices");
    18981916
    18991917  if (e == -1) {
  • trunk/anuga_work/development/gareth/tests/channel_floodplain/plotme.py

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

    r8353 r8375  
    7373##############
    7474
    75 def animate_1D(time, var, x, ylab=' '): #, x=range(var.shape[1]), vmin=var.min(), vmax=var.max()):
    76     # Input: time = one-dimensional time vector;
    77     #        var =  array with first dimension = len(time) ;
    78     #        x = (optional) vector width dimension equal to var.shape[1];
    79    
    80     import pylab
    81     import numpy
    82    
    83    
    84 
    85     pylab.close()
    86     pylab.ion()
    87 
    88     # Initial plot
    89     vmin=var.min()
    90     vmax=var.max()
    91     line, = pylab.plot( (x.min(), x.max()), (vmin, vmax), 'o')
    92 
    93     # Lots of plots
    94     for i in range(len(time)):
    95         line.set_xdata(x)
    96         line.set_ydata(var[i,:])
    97         pylab.draw()
    98         pylab.xlabel('x')
    99         pylab.ylabel(ylab)
    100         pylab.title('time = ' + str(time[i]))
    101    
    102     return
    10375
    10476
     
    198170#pylab.quiver(x,y,xvel[n,:],yvel[n,:])
    199171#pylab.savefig('Plot1.png')
     172
     173def animate_1D(time, var, x, ylab=' '): #, x=range(var.shape[1]), vmin=var.min(), vmax=var.max()):
     174    # Input: time = one-dimensional time vector;
     175    #        var =  array with first dimension = len(time) ;
     176    #        x = (optional) vector width dimension equal to var.shape[1];
     177   
     178    import pylab
     179    import numpy
     180   
     181   
     182
     183    pylab.close()
     184    pylab.ion()
     185
     186    # Initial plot
     187    vmin=var.min()
     188    vmax=var.max()
     189    line, = pylab.plot( (x.min(), x.max()), (vmin, vmax), 'o')
     190
     191    # Lots of plots
     192    for i in range(len(time)):
     193        line.set_xdata(x)
     194        line.set_ydata(var[i,:])
     195        pylab.draw()
     196        pylab.xlabel('x')
     197        pylab.ylabel(ylab)
     198        pylab.title('time = ' + str(time[i]))
     199   
     200    return
     201
     202def near_transect(p, point1, point2, tol=1.):
     203    # Function to get the indices of points in p less than 'tol' from the line
     204    # joining (x1,y1), and (x2,y2)
     205    # p comes from util.get_output('mysww.sww')
     206    #
     207    # e.g.
     208    # import util
     209    # #import transect_interpolate
     210    # from matplotlib import pyplot
     211    # p=util.get_output('merewether_1m.sww',0.01)
     212    # p2=util.get_centroids(p,velocity_extrapolation=True)
     213    # #xxx=transect_interpolate.near_transect(p,[95., 85.], [120.,68.],tol=2.)
     214    # xxx=util.near_transect(p,[95., 85.], [120.,68.],tol=2.)
     215    # pyplot.scatter(xxx[1],p.vel[140,xxx[0]],color='red')
     216
     217    x1=point1[0]
     218    y1=point1[1]
     219
     220    x2=point2[0]
     221    y2=point2[1]
     222
     223    # Find line equation a*x + b*y + c = 0
     224    # based on y=gradient*x +intercept
     225    if x1!=x2:
     226        gradient= (y2-y1)/(x2-x1)
     227        intercept = y1 - gradient*x1
     228
     229        a = -gradient
     230        b = 1.
     231        c = -intercept
     232    else:
     233        #print 'FIXME: Still need to treat 0 and infinite gradients'
     234        #assert 0==1
     235        a=1.
     236        b=0.
     237        c=-x2
     238
     239    # Distance formula
     240    inv_denom = 1./(a**2 + b**2)**0.5
     241    distp = abs(p.x*a + p.y*b + c)*inv_denom
     242
     243    near_points = (distp<tol).nonzero()[0]
     244   
     245    # Now find a 'local' coordinate for the point, projected onto the line
     246    # g1 = unit vector parallel to the line
     247    # g2 = vector joining (x1,y1) and (p.x,p.y)
     248    g1x = x2-x1
     249    g1y = y2-y1
     250    g1_norm = (g1x**2 + g1y**2)**0.5
     251    g1x=g1x/g1_norm
     252    g1y=g1x/g1_norm
     253
     254    g2x = p.x[near_points] - x1
     255    g2y = p.y[near_points] - y1
     256   
     257    # Dot product = projected distance == a local coordinate
     258    local_coord = g1x*g2x + g1y*g2y
     259
     260    return near_points, local_coord
Note: See TracChangeset for help on using the changeset viewer.