Changeset 4771


Ignore:
Timestamp:
Oct 30, 2007, 6:25:23 PM (17 years ago)
Author:
ole
Message:

Cosmetics according to style guide.

File:
1 edited

Legend:

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

    r4735 r4771  
    190190        # Or maybe get rid of order altogether and use beta_w and beta_h
    191191        self.set_default_order(1)
    192         #self.default_order = 1
    193         #self._order_ = self.default_order
    194192
    195193        self.smallsteps = 0
     
    207205        self.finaltime = None
    208206        self.min_timestep = self.max_timestep = 0.0
    209         self.starttime = 0 #Physical starttime if any (0 is 1 Jan 1970 00:00:00)
     207        self.starttime = 0 # Physical starttime if any
     208                           # (0 is 1 Jan 1970 00:00:00)
    210209        self.timestep = 0.0
    211210        self.flux_timestep = 0.0
     
    223222        self.checkpoint = False
    224223
    225         # MH310505 To avoid calculating the flux across each edge twice, keep an integer (boolean) array,
    226         # to be used during the flux calculation
    227         N = len(self) #number_of_triangles
     224        # To avoid calculating the flux across each edge twice,
     225        # keep an integer (boolean) array, to be used during the flux
     226        # calculation
     227        N = len(self) # Number_of_triangles
    228228        self.already_computed_flux = zeros((N, 3), Int)
    229229
    230         # Storage for maximal speeds computed for each triangle by compute_fluxes
     230        # Storage for maximal speeds computed for each triangle by
     231        # compute_fluxes
    231232        # This is used for diagnostics only
    232233        self.max_speed = zeros(N, Float)
     
    246247
    247248
    248 
    249     #Public interface to Domain
     249    #---------------------------   
     250    # Public interface to Domain
     251    #---------------------------       
    250252    def get_conserved_quantities(self, vol_id, vertex=None, edge=None):
    251253        """Get conserved quantities at volume vol_id
     
    332334        """
    333335
    334         #FIXME (Ole): Allow new quantities here
    335         #from quantity import Quantity, Conserved_quantity
    336         #Create appropriate quantity object
    337         ##if name in self.conserved_quantities:
    338         ##    self.quantities[name] = Conserved_quantity(self)
    339         ##else:
    340         ##    self.quantities[name] = Quantity(self)
    341 
    342 
    343         #Do the expression stuff
     336        # Do the expression stuff
    344337        if kwargs.has_key('expression'):
    345338            expression = kwargs['expression']
     
    349342            kwargs['quantity'] = Q
    350343
    351         #Assign values
     344        # Assign values
    352345        self.quantities[name].set_values(*args, **kwargs)
    353346
     
    463456               
    464457       
    465         #FIXME: Try to remove the sorting and fix test_mesh.py
     458        # FIXME (Ole): Try to remove the sorting and fix test_mesh.py
    466459        x = self.boundary.keys()
    467460        x.sort()
    468461
    469         #Loop through edges that lie on the boundary and associate them with
    470         #callable boundary objects depending on their tags
     462        # Loop through edges that lie on the boundary and associate them with
     463        # callable boundary objects depending on their tags
    471464        self.boundary_objects = []       
    472465        for k, (vol_id, edge_id) in enumerate(x):
     
    474467
    475468            if self.boundary_map.has_key(tag):
    476                 B = self.boundary_map[tag]  #Get callable boundary object
     469                B = self.boundary_map[tag]  # Get callable boundary object
    477470
    478471                if B is not None:
     
    509502        can also be passed into this function.
    510503        """
    511         #print "*args", args
    512         #print "**kwargs", kwargs
     504
    513505        if len(args) == 1:
    514506            self._set_region(*args, **kwargs)
    515507        else:
    516             #Assume it is arguments for the region.set_region function
     508            # Assume it is arguments for the region.set_region function
    517509            func = region_set_region(*args, **kwargs)
    518510            self._set_region(func)
     
    628620       
    629621
    630 
    631     #MISC
     622    #--------------------------   
     623    # Miscellaneous diagnostics
     624    #--------------------------       
    632625    def check_integrity(self):
    633626        Mesh.check_integrity(self)
     
    638631
    639632        ##assert hasattr(self, 'boundary_objects')
     633           
    640634
    641635    def write_time(self, track_speeds=False):
     
    646640        """Return string with time stepping statistics for printing or logging
    647641
    648         Optional boolean keyword track_speeds decides whether to report location of
    649         smallest timestep as well as a histogram and percentile report.
     642        Optional boolean keyword track_speeds decides whether to report
     643        location of smallest timestep as well as a histogram and percentile
     644        report.
    650645        """
    651646
     
    672667
    673668
    674             #Setup 10 bins for speed histogram
     669            # Setup 10 bins for speed histogram
    675670            bins = create_bins(self.max_speed, 10)
    676671            hist = histogram(self.max_speed, bins)
    677672
    678673            msg += '------------------------------------------------\n'
    679             msg += '  Speeds in [%f, %f]\n' %(min(self.max_speed), max(self.max_speed))
     674            msg += '  Speeds in [%f, %f]\n' %(min(self.max_speed),
     675                                              max(self.max_speed))
    680676            msg += '  Histogram:\n'
    681677
     
    684680                lo = hi
    685681                if i+1 < len(bins):
    686                     #Open upper interval               
     682                    # Open upper interval               
    687683                    hi = bins[i+1]
    688684                    msg += '    [%f, %f[: %d\n' %(lo, hi, count)               
    689685                else:
    690                     #Closed upper interval
     686                    # Closed upper interval
    691687                    hi = max(self.max_speed)
    692688                    msg += '    [%f, %f]: %d\n' %(lo, hi, count)
     
    702698                lower = min(speed)
    703699                for i, a in enumerate(speed):       
    704                     if i % (N/10) == 0 and i != 0: #For every 10% of the sorted speeds
     700                    if i % (N/10) == 0 and i != 0:
     701                        # For every 10% of the sorted speeds
    705702                        msg += '    %d speeds in [%f, %f]\n' %(i-k, lower, a)
    706703                        lower = a
     
    711708               
    712709                     
    713            
    714710
    715711               
     
    755751
    756752        Input:
    757           quantities: either None, a string or a list of strings naming the quantities to be reported
    758           tags:       either None, a string or a list of strings naming the tags to be reported
     753          quantities: either None, a string or a list of strings naming the
     754                      quantities to be reported
     755          tags:       either None, a string or a list of strings naming the
     756                      tags to be reported
    759757
    760758
     
    767765
    768766
    769         If quantities are specified only report on those. Otherwise take all conserved quantities.
     767        If quantities are specified only report on those. Otherwise take all
     768        conserved quantities.
    770769        If tags are specified only report on those, otherwise take all tags.
    771770
     
    801800                maxwidth = w
    802801
    803         # Output stats
     802        # Output statistics
    804803        msg = 'Boundary values at time %.4f:\n' %self.time
    805804        for tag in tags:
     
    860859
    861860            # Update maximum
    862             # (n > None is always True, but we check explicitly because of the epsilon)
     861            # (n > None is always True, but we check explicitly because
     862            # of the epsilon)
    863863            maxval = Q.get_maximum_value(self.monitor_indices)
    864864            if info_block['max'] is None or\
     
    882882
    883883    def quantity_statistics(self, precision = '%.4f'):
    884         """Return string with statistics about quantities for printing or logging
     884        """Return string with statistics about quantities for
     885        printing or logging
    885886
    886887        Quantities reported are specified through method
     
    892893        maxlen = 128 # Max length of polygon string representation
    893894
    894         # Output stats
     895        # Output statistics
    895896        msg = 'Monitored quantities at time %.4f:\n' %self.time
    896897        if self.monitor_polygon is not None:
     
    904905
    905906        if self.monitor_time_interval is not None:
    906             msg += '- Restricted by time interval: %s\n' %str(self.monitor_time_interval)
     907            msg += '- Restricted by time interval: %s\n'\
     908                   %str(self.monitor_time_interval)
    907909            time_interval_start = self.monitor_time_interval[0]
    908910        else:
     
    916918                   %(time_interval_start,
    917919                     get_textual_float(info['min'], precision),
    918                      get_textual_float(info['max'], precision))                    
     920                     get_textual_float(info['max'], precision))       
    919921                     
    920922            msg += '      minimum attained at time = %s, location = %s\n'\
    921923                   %(get_textual_float(info['min_time'], precision),
    922                      get_textual_float(info['min_location'], precision))                     
    923                      
     924                     get_textual_float(info['min_location'], precision))
     925           
    924926
    925927            msg += '      maximum attained at time = %s, location = %s\n'\
    926928                   %(get_textual_float(info['max_time'], precision),
    927                      get_textual_float(info['max_location'], precision))                   
     929                     get_textual_float(info['max_location'], precision))
    928930
    929931
     
    969971
    970972
    971     #def set_defaults(self):
    972     #    """Set default values for uninitialised quantities.
    973     #    Should be overridden or specialised by specific modules
    974     #    """#
    975     #
    976     #    for name in self.conserved_quantities + self.other_quantities:
    977     #        self.set_quantity(name, 0.0)
    978 
    979 
    980     ###########################
    981     #Main components of evolve
     973    #--------------------------
     974    # Main components of evolve
     975    #--------------------------   
    982976
    983977    def evolve(self,
     
    11031097                if self.time > finaltime:
    11041098                    # FIXME (Ole, 30 April 2006): Do we need this check?
    1105                     # Probably not (Ole, 18 September 2008). Now changed to Exception
    1106                     msg = 'WARNING (domain.py): time overshot finaltime. Contact Ole.Nielsen@ga.gov.au'
     1099                    # Probably not (Ole, 18 September 2008). Now changed to
     1100                    # Exception
     1101                    msg = 'WARNING (domain.py): time overshot finaltime. '
     1102                    msg += 'Contact Ole.Nielsen@ga.gov.au'
    11071103                    raise Exception, msg
    1108                     #self.time = finaltime
    11091104                   
    11101105
     
    13311326
    13321327    def backup_conserved_quantities(self):
    1333         N = len(self) #number_of_triangles
    1334 
    1335         #backup conserved_quantities centroid values
     1328        N = len(self) # Number_of_triangles
     1329
     1330        # Backup conserved_quantities centroid values
    13361331        for name in self.conserved_quantities:
    13371332            Q = self.quantities[name]
     
    13411336        N = len(self) #number_of_triangles
    13421337
    1343         #backup conserved_quantities centroid values
     1338        # Backup conserved_quantities centroid values
    13441339        for name in self.conserved_quantities:
    13451340            Q = self.quantities[name]
     
    13561351        """
    13571352
    1358         #FIXME: Update only those that change (if that can be worked out)
    1359         #FIXME: Boundary objects should not include ghost nodes.
     1353        # FIXME: Update only those that change (if that can be worked out)
     1354        # FIXME: Boundary objects should not include ghost nodes.
    13601355        for i, ((vol_id, edge_id), B) in enumerate(self.boundary_objects):
    13611356            if B is None:
     
    14031398                    for i in range(self.number_of_full_triangles):
    14041399                        if self.max_speed[i] > bins[-1]:
    1405                             msg = 'Time=%f: Ignoring isolated high speed triangle ' %self.time
     1400                            msg = 'Time=%f: Ignoring isolated high ' %self.time
     1401                            msg += 'speed triangle '
    14061402                            msg += '#%d of %d with max speed=%f'\
    1407                                   %(i, self.number_of_full_triangles, self.max_speed[i])
    1408                             #print msg
     1403                                  %(i, self.number_of_full_triangles,
     1404                                    self.max_speed[i])
    14091405                   
    1410                             # print 'Found offending triangle', i, self.max_speed[i]
     1406                            # print 'Found offending triangle', i,
     1407                            # self.max_speed[i]
    14111408                            self.get_quantity('xmomentum').set_values(0.0, indices=[i])
    14121409                            self.get_quantity('ymomentum').set_values(0.0, indices=[i])
     
    14231420        timestep = min(self.CFL*self.flux_timestep, max_timestep)
    14241421
    1425         #Record maximal and minimal values of timestep for reporting
     1422        # Record maximal and minimal values of timestep for reporting
    14261423        self.max_timestep = max(timestep, self.max_timestep)
    14271424        self.min_timestep = min(timestep, self.min_timestep)
     
    14291426           
    14301427 
    1431         #Protect against degenerate time steps
     1428        # Protect against degenerate time steps
    14321429        if timestep < min_timestep:
    14331430
    1434             #Number of consecutive small steps taken b4 taking action
     1431            # Number of consecutive small steps taken b4 taking action
    14351432            self.smallsteps += 1
    14361433
    14371434            if self.smallsteps > self.max_smallsteps:
    1438                 self.smallsteps = 0 #Reset
     1435                self.smallsteps = 0 # Reset
    14391436
    14401437                if self._order_ == 1:
     
    14441441                           %self.max_smallsteps
    14451442                    print msg
    1446                     timestep = min_timestep  #Try enforcing min_step
    1447 
     1443                    timestep = min_timestep  # Try enforcing min_step
    14481444
    14491445                    #print self.timestepping_statistics(track_speeds=True)
    1450 
    14511446
    14521447                    raise Exception, msg
    14531448                else:
    1454                     #Try to overcome situation by switching to 1 order
     1449                    # Try to overcome situation by switching to 1 order
    14551450                    self._order_ = 1
    14561451
     
    14611456
    14621457
    1463         #Ensure that final time is not exceeded
     1458        # Ensure that final time is not exceeded
    14641459        if finaltime is not None and self.time + timestep > finaltime :
    14651460            timestep = finaltime-self.time
    14661461
    1467         #Ensure that model time is aligned with yieldsteps
     1462        # Ensure that model time is aligned with yieldsteps
    14681463        if self.yieldtime + timestep > yieldstep:
    14691464            timestep = yieldstep-self.yieldtime
     
    14911486        from Numeric import ones, sum, equal, Float
    14921487
    1493         N = len(self) #number_of_triangles
     1488        N = len(self) # Number_of_triangles
    14941489        d = len(self.conserved_quantities)
    14951490
    14961491        timestep = self.timestep
    14971492
    1498         #Compute forcing terms
     1493        # Compute forcing terms
    14991494        self.compute_forcing_terms()
    15001495
    1501         #Update conserved_quantities
     1496        # Update conserved_quantities
    15021497        for name in self.conserved_quantities:
    15031498            Q = self.quantities[name]
    15041499            Q.update(timestep)
    15051500
    1506             #Clean up
    1507             #Note that Q.explicit_update is reset by compute_fluxes
    1508 
    1509             #MH090605 commented out the following since semi_implicit_update is now re-initialized
    1510             #at the end of the _update function in quantity_ext.c (This is called by the
    1511             #preceeding Q.update(timestep) statement above).
    1512             #For run_profile.py with N=128, the time of update_conserved_quantities is cut from 14.00 secs
    1513             #to 8.35 secs
    1514 
    1515             #Q.semi_implicit_update[:] = 0.0
     1501            # Note that Q.explicit_update is reset by compute_fluxes
     1502            # Where is Q.semi_implicit_update reset?
     1503           
    15161504
    15171505    def update_ghosts(self):
     
    15511539
    15521540
    1553 ##############################################
    1554 #Initialise module
    1555 
    1556 #Optimisation with psyco
     1541#------------------
     1542# Initialise module
     1543#------------------
     1544
     1545# Optimisation with psyco
    15571546from anuga.config import use_psyco
    15581547if use_psyco:
     
    15631552        if os.name == 'posix' and os.uname()[4] == 'x86_64':
    15641553            pass
    1565             #Psyco isn't supported on 64 bit systems, but it doesn't matter
     1554            # Psyco isn't supported on 64 bit systems, but it doesn't matter
    15661555        else:
    15671556            msg = 'WARNING: psyco (speedup) could not import'+\
     
    15701559    else:
    15711560        psyco.bind(Domain.update_boundary)
    1572         #psyco.bind(Domain.update_timestep)     #Not worth it
     1561        #psyco.bind(Domain.update_timestep) # Not worth it
    15731562        psyco.bind(Domain.update_conserved_quantities)
    15741563        psyco.bind(Domain.distribute_to_vertices_and_edges)
Note: See TracChangeset for help on using the changeset viewer.