Changeset 4204


Ignore:
Timestamp:
Jan 31, 2007, 3:46:10 PM (17 years ago)
Author:
ole
Message:

Added histogram and percentiles to speed report

Location:
anuga_core/source/anuga/abstract_2d_finite_volumes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/abstract_2d_finite_volumes/domain.py

    r4201 r4204  
    550550        ##assert hasattr(self, 'boundary_objects')
    551551
    552     def write_time(self, track_location=False):
    553         print self.timestepping_statistics(track_location)
    554 
    555 
    556     def timestepping_statistics(self, track_location=False):
     552    def write_time(self, track_speeds=False):
     553        print self.timestepping_statistics(track_speeds)
     554
     555
     556    def timestepping_statistics(self, track_speeds=False):
    557557        """Return string with time stepping statistics for printing or logging
    558558
    559         Optional boolean keyword track_location decides whether to report location of smallest timestep.
    560         """
     559        Optional boolean keyword track_speeds decides whether to report location of
     560        smallest timestep as well as a histogram and percentile report.
     561        """
     562
     563        from anuga.utilities.numerical_tools import histogram, create_bins
     564       
    561565
    562566        msg = ''
     
    575579                     self.number_of_first_order_steps)
    576580
    577         if track_location is True:
     581        if track_speeds is True:
    578582            msg += '\n'
     583
     584
     585            #Setup 10 bins for speed histogram
     586            bins = create_bins(self.max_speed, 10)
     587            hist = histogram(self.max_speed, bins)
     588
     589            msg += '------------------------------------------------\n'
     590            msg += '  Speeds in [%f, %f]\n' %(min(self.max_speed), max(self.max_speed))
     591            msg += '  Histogram:\n'
     592
     593            hi = bins[0]
     594            for i, count in enumerate(hist):
     595                lo = hi
     596                if i+1 < len(bins):
     597                    #Open upper interval               
     598                    hi = bins[i+1]
     599                    msg += '    [%f, %f[: %d\n' %(lo, hi, count)               
     600                else:
     601                    #Closed upper interval
     602                    hi = max(self.max_speed)
     603                    msg += '    [%f, %f]: %d\n' %(lo, hi, count)
     604
     605
     606            N = len(self.max_speed)
     607            if N > 10:
     608                msg += '  Percentiles (10%):\n'
     609                speed = self.max_speed.tolist()
     610                speed.sort()
     611
     612                k = 0
     613                lower = min(speed)
     614                for i, a in enumerate(speed):       
     615                    if i % (N/10) == 0 and i != 0: #For every 10% of the sorted speeds
     616                        msg += '    %d speeds in [%f, %f]\n' %(i-k, lower, a)
     617                        lower = a
     618                        k = i
     619                       
     620                msg += '    %d speeds in [%f, %f]\n'\
     621                       %(N-k, lower, max(speed))                   
     622               
     623                     
     624           
     625
     626               
     627           
    579628            # Find index of largest computed flux speed
    580629            k = argmax(self.max_speed)
     
    582631            x, y = self.get_centroid_coordinates()[k]
    583632
    584             s = 'Triangle #%d with centroid (%.4f, %.4f) ' %(k, x, y)
    585             s += 'had the largest computed speed: %.4f m/s\n' %(self.max_speed[k])
    586             msg += s
     633            msg += '  Triangle #%d with centroid (%.4f, %.4f) ' %(k, x, y)
     634            msg += 'had the largest computed speed: %.4f m/s\n' %(self.max_speed[k])
    587635           
    588636            # Report all quantity values at vertices
     637            msg += '    Quantity \t vertex values\n'
    589638            for name in self.quantities:
    590639                q = self.quantities[name]
    591640                X,Y,A,V = q.get_vertex_values()               
    592641               
    593                 s = '  %s (vertex values):\t %.4f, %.4f, %.4f\n'\
     642                s = '    %s:\t %.4f, %.4f, %.4f\n'\
    594643                    %(name, A[3*k], A[3*k+1], A[3*k+2])
    595644
  • anuga_core/source/anuga/abstract_2d_finite_volumes/show_balanced_limiters.py

    r4200 r4204  
    8282#Evolve
    8383for t in domain.evolve(yieldstep = 0.1, finaltime = 30):
    84     domain.write_time(track_location=True)
     84    domain.write_time(track_speeds=True)
    8585    domain.write_boundary_statistics(['stage'],'left')
    8686
Note: See TracChangeset for help on using the changeset viewer.