Changeset 8018


Ignore:
Timestamp:
Sep 16, 2010, 2:09:13 PM (14 years ago)
Author:
steve
Message:

Added logging to file for fractional step operators. There needs to an member function log_timestepping_statistics() implemented for each operator.

Location:
trunk/anuga_core/source/anuga
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/generic_domain.py

    r7967 r8018  
    15281528                    raise Exception, msg
    15291529
    1530                 # Yield final time and stop
     1530                # Log and then Yield final time and stop
    15311531                self.time = finaltime
     1532                self.log_operator_timestepping_statistics()
    15321533                yield(self.time)
    15331534                break
     
    15401541                    self.delete_old_checkpoints()
    15411542
    1542                 # Pass control on to outer loop for more specific actions
     1543                # Log and then Pass control on to outer loop for more specific actions
     1544                self.log_operator_timestepping_statistics()
    15431545                yield(self.time)
    15441546
     
    18601862        for operator in self.fractional_step_operators:
    18611863            operator()
     1864
     1865
     1866
     1867    ##
     1868    # @brief log_timestepping_statistics.
     1869    # Goes through all fractional step operators and logs timestepping statistics
     1870    def log_operator_timestepping_statistics(self):
     1871        for operator in self.fractional_step_operators:
     1872            operator.log_timestepping_statistics()
     1873
     1874    ##
     1875    # @brief print_timestepping_statistics.
     1876    # Goes through all fractional step operators and logs timestepping statistics
     1877    def print_operator_timestepping_statistics(self):
     1878        for operator in self.fractional_step_operators:
     1879            operator.print_timestepping_statistics()
     1880
    18621881
    18631882    ##
  • trunk/anuga_core/source/anuga/structures/boyd_box_operator.py

    r8008 r8018  
    1212    Input: Two points, pipe_size (either diameter or width, height),
    1313    mannings_rougness,
    14     """
     14    """
     15
    1516
    1617    def __init__(self,
     
    2728                 use_velocity_head=True,
    2829                 description=None,
     30                 label=None,
     31                 structure_type='boyd_box',
     32                 logging=False,
    2933                 verbose=False):
     34
    3035                     
    3136        anuga.Structure_operator.__init__(self,
     
    3944                                          enquiry_gap,                                                       
    4045                                          description,
    41                                           verbose)           
     46                                          label,
     47                                          structure_type,
     48                                          logging,
     49                                          verbose)     
    4250       
    4351       
     
    5765
    5866        self.max_velocity = 10.0
    59         self.log_filename = None
    6067
    6168        self.inlets = self.get_inlets()
  • trunk/anuga_core/source/anuga/structures/boyd_pipe_operator.py

    r8008 r8018  
    2626                 use_velocity_head=True,
    2727                 description=None,
     28                 label=None,
     29                 structure_type='boyd_pipe',
     30                 logging=False,
    2831                 verbose=False):
     32
     33
    2934                     
    3035        anuga.Structure_operator.__init__(self,
     
    3843                                          enquiry_gap=enquiry_gap,                                                       
    3944                                          description=description,
     45                                          label=label,
     46                                          structure_type=structure_type,
     47                                          logging=logging,
    4048                                          verbose=verbose)           
    4149
     
    5563
    5664        self.max_velocity = 10.0
    57         self.log_filename = None
    5865
    5966        self.inlets = self.get_inlets()
     
    7784            # Water has risen above inlet
    7885
    79             if self.log_filename is not None:
    80                 s = 'Specific energy  = %f m' % self.inflow.get_enquiry_specific_energy()
    81                 log_to_file(self.log_filename, s)
    8286
    8387            msg = 'Specific energy at inlet is negative'
     
    108112            # Water has risen above inlet
    109113
    110             if self.log_filename is not None:
    111                 s = 'Specific energy  = %f m' % self.inflow.get_average_specific_energy()
    112                 log_to_file(self.log_filename, s)
    113114
    114115            msg = 'Specific energy at inlet is negative'
     
    120121            # Note for to SUBMERGED TO OCCUR self.inflow.get_average_specific_energy() should be > 1.2 x diameter.... Should Check !!!
    121122
    122             if self.log_filename is not None:
    123                 s = 'Q_inlet_unsubmerged = %.6f, Q_inlet_submerged = %.6f' % (Q_inlet_unsubmerged, Q_inlet_submerged)
    124                 log_to_file(self.log_filename, s)
     123
    125124            Q = min(Q_inlet_unsubmerged, Q_inlet_submerged)
    126125
     
    205204            hyd_rad = flow_area/perimeter
    206205
    207             if self.log_filename is not None:
    208                 s = 'hydraulic radius at outlet = %f' %hyd_rad
    209                 log_to_file(self.log_filename, s)
     206
    210207
    211208            # Outlet control velocity using tail water
     
    222219                anuga.log.critical('VELOCITY = %s' % str(culvert_velocity))
    223220                anuga.log.critical('Outlet Ctrl Q = %s' % str(Q_outlet_tailwater))
    224             if self.log_filename is not None:
    225                 s = 'Q_outlet_tailwater = %.6f' %Q_outlet_tailwater
    226                 log_to_file(self.log_filename, s)
     221
    227222            Q = min(Q, Q_outlet_tailwater)
    228223            if local_debug =='true':
  • trunk/anuga_core/source/anuga/structures/structure_operator.py

    r8008 r8018  
    44import inlet
    55
     6from anuga.utilities.system_tools import log_to_file
     7
     8
    69class Structure_operator:
    710    """Structure Operator - transfer water from one rectangular box to another.
     
    1417    mannings_rougness,
    1518    """
     19
     20    counter = 0
    1621
    1722    def __init__(self,
     
    2530                 enquiry_gap,
    2631                 description,
     32                 label,
     33                 structure_type,
     34                 logging,
    2735                 verbose):
    2836       
     
    3038        self.domain.set_fractional_step_operator(self)
    3139        self.end_points = [end_point0, end_point1]
     40
     41       
    3242       
    3343        if height is None:
     
    4252        self.manning = manning
    4353        self.enquiry_gap = enquiry_gap
    44         self.description = description
     54
     55        if description == None:
     56            self.description = ' '
     57        else:
     58            self.description = description
     59       
     60
     61        if label == None:
     62            self.label = "structure_%g" % Structure_operator.counter
     63        else:
     64            self.label = label
     65        print label
     66
     67        if structure_type == None:
     68            self.structure_type = 'generic structure'
     69        else:
     70            self.structure_type = structure_type
     71           
    4572        self.verbose = verbose
    4673
     74       
     75       
     76        # Keep count of structures
     77        Structure_operator.counter += 1
     78
     79        # Slots for recording current statistics
    4780        self.discharge = 0.0
    4881        self.velocity = 0.0
     
    6396        self.inlets.append(inlet.Inlet(self.domain, polygon1, exchange_polygon1, outward_vector1))
    6497
     98        self.set_logging(logging)
    6599
    66100    def __call__(self):
     
    221255           
    222256
    223     def print_stats(self):
    224 
    225         print '====================================='
    226         print 'Generic Culvert Operator'
    227         print '====================================='
    228 
    229         print 'Culvert'
    230         print self.culvert
    231 
    232         print 'Culvert Routine'
    233         print self.routine
     257    def structure_statistics(self):
     258
     259
     260        message  = '=====================================\n'
     261        message += 'Structure Operator: %s\n' % self.label
     262        message += '=====================================\n'
     263
     264        message += 'Structure Type: %s\n' % self.structure_type
     265
     266        message += 'Description\n'
     267        message += '%s' % self.description
     268        message += '\n'
    234269       
    235270        for i, inlet in enumerate(self.inlets):
    236             print '-------------------------------------'
    237             print 'Inlet %i' % i
    238             print '-------------------------------------'
    239 
    240             print 'inlet triangle indices and centres'
    241             print inlet.triangle_indices
    242             print self.domain.get_centroid_coordinates()[inlet.triangle_indices]
    243        
    244             print 'polygon'
    245             print inlet.polygon
    246 
    247         print '====================================='
    248 
    249 
    250     def structure_statistics(self):
     271            message += '-------------------------------------\n'
     272            message +=  'Inlet %i\n' % i
     273            message += '-------------------------------------\n'
     274
     275            message += 'inlet triangle indices and centres\n'
     276            message += '%s' % inlet.triangle_indices
     277            message += '\n'
     278           
     279            message += '%s' % self.domain.get_centroid_coordinates()[inlet.triangle_indices]
     280            message += '\n'
     281
     282            message += 'polygon\n'
     283            message += '%s' % inlet.polygon
     284            message += '\n'
     285
     286        message += '=====================================\n'
     287
     288        return message
     289
     290
     291    def print_structure_statistics(self):
     292
     293        print self.structure_statistics()
     294
     295
     296    def print_timestepping_statistics(self):
    251297
    252298        message = '---------------------------\n'
    253         message += 'Structure report for structure %s:\n' % self.description
     299        message += 'Structure report for %s:\n' % self.label
    254300        message += '--------------------------\n'
     301        message += 'Type: %s\n' % self.structure_type
    255302        message += 'Discharge [m^3/s]: %.2f\n' % self.discharge
    256303        message += 'Velocity  [m/s]: %.2f\n' % self.velocity
     
    258305        message += 'delta total energy %.2f\n' % self.delta_total_energy
    259306
     307        print message
     308
     309
     310    def set_logging(self, flag=True):
     311
     312        self.logging = flag
     313
     314        # If flag is true open file with mode = "w" to form a clean file for logging
     315        if self.logging:
     316            self.log_filename = self.label + '.log'
     317            log_to_file(self.log_filename, self.structure_statistics(), mode='w')
     318            log_to_file(self.log_filename, 'time,discharge,velocity,driving_energy,delta_total_energy')
     319
     320            #log_to_file(self.log_filename, self.culvert_type)
     321
     322
     323    def timestepping_statistics(self):
     324
     325        message  = '%.5f, ' % self.domain.get_time()
     326        message += '%.5f, ' % self.discharge
     327        message += '%.5f, ' % self.velocity
     328        message += '%.5f, ' % self.driving_energy
     329        message += '%.5f' % self.delta_total_energy
     330
    260331        return message
    261332
     333    def log_timestepping_statistics(self):
     334
     335         if self.logging:
     336             log_to_file(self.log_filename, self.timestepping_statistics())
     337
    262338
    263339    def get_inlets(self):
  • trunk/anuga_core/source/anuga/structures/test_Outlet_Ctrl.py

    r7998 r8018  
    159159
    160160culverts = []
    161 number_of_culverts = 1
     161number_of_culverts = 2
    162162for i in range(number_of_culverts):
    163163    culvert_width = 50.0/number_of_culverts
     
    175175                            use_velocity_head=True,
    176176                            manning=0.013,
     177                            logging=True,
    177178                            verbose=False))
    178179
     
    204205
    205206
     207
    206208#------------------------------------------------------------------------------
    207209# Evolve system through time
     
    210212for t in domain.evolve(yieldstep = 1, finaltime = 100):
    211213    print domain.timestepping_statistics()
    212     print domain.volumetric_balance_statistics()
    213     for culvert in culverts:
    214         print culvert.structure_statistics()
    215 
     214
     215    domain.print_operator_timestepping_statistics()
     216
  • trunk/anuga_core/source/anuga/utilities/system_tools.py

    r7486 r8018  
    2121
    2222
    23 def log_to_file(filename, s, verbose=False):
     23def log_to_file(filename, s, verbose=False, mode='a'):
    2424    """Log string to file name
    2525    """
    2626
    27     fid = open(filename, 'a')
     27    fid = open(filename, mode)
    2828    if verbose: print s
    2929    fid.write(s + '\n')
Note: See TracChangeset for help on using the changeset viewer.