Changeset 7339


Ignore:
Timestamp:
Aug 7, 2009, 6:46:22 PM (15 years ago)
Author:
ole
Message:

Removed hardwired references to conserved quantities from Write_sww in preparation for the ability to flexibly selecting which quantities to store and whether to do it every time step.
This is in regard to ticket:191

All tests pass.

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

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/shallow_water/data_manager.py

    r7317 r7339  
    350350        from Scientific.IO.NetCDF import NetCDFFile
    351351
    352         self.precision = netcdf_float32 #Use single precision for quantities
     352        self.precision = netcdf_float32 # Use single precision for quantities
    353353        self.recursion = recursion
    354354        self.mode = mode
    355355        if hasattr(domain, 'max_size'):
    356             self.max_size = domain.max_size #file size max is 2Gig
     356            self.max_size = domain.max_size # File size max is 2Gig
    357357        else:
    358358            self.max_size = max_size
     
    370370            description = 'Output from anuga.abstract_2d_finite_volumes ' \
    371371                          'suitable for plotting'
    372             self.writer = Write_sww()
     372            self.writer = Write_sww(['elevation'], domain.conserved_quantities)
    373373            self.writer.store_header(fid,
    374374                                     domain.starttime,
     
    32433243    starttime = times[0]
    32443244
    3245     sww = Write_sww()
     3245    sww = Write_sww(['elevation'], ['stage', 'xmomentum', 'ymomentum'])
    32463246    sww.store_header(outfile, times, number_of_volumes,
    32473247                     number_of_points, description=description,
     
    53355335    # For a different way of doing this, check out tsh2sww
    53365336    # work out sww_times and the index range this covers
    5337     sww = Write_sww()
     5337    sww = Write_sww(['elevation'], ['stage', 'xmomentum', 'ymomentum'])
    53385338    sww.store_header(outfile, times, len(volumes), len(points_utm),
    53395339                     verbose=verbose, sww_precision=netcdf_float)
     
    58505850
    58515851
    5852 ##
    58535852# @brief A class to write an SWW file.
    58545853class Write_sww:
    58555854    from anuga.shallow_water.shallow_water_domain import Domain
    58565855
    5857     # FIXME (Ole): Hardwiring the conserved quantities like
    5858     # this could be a problem. I would prefer taking them from
    5859     # the instantiation of Domain.
    5860     #
    5861     # (DSG) There is not always a Domain instance when Write_sww is used.
    5862     # Check to see if this is the same level of hardwiring as is in
    5863     # shallow water doamain.
    5864 
    5865     sww_quantities = Domain.conserved_quantities
    5866 
    58675856    RANGE = '_range'
    58685857    EXTREMA = ':extrema'
     
    58705859    ##
    58715860    # brief Instantiate the SWW writer class.
    5872     def __init__(self):
    5873         pass
     5861    def __init__(self, static_quantities, dynamic_quantities):
     5862        """Initialise SWW writer with two list af quantity names:
     5863       
     5864        static_quantities (e.g. elevation or friction):
     5865            Stored once at the beginning of the simulation in a 1D array
     5866            of length number_of_points   
     5867        dynamic_quantities (e.g stage):
     5868            Stored every timestep in a 2D array with
     5869            dimensions number_of_points X number_of_timesteps       
     5870       
     5871        """
     5872        self.static_quantities = static_quantities   
     5873        self.dynamic_quantities = dynamic_quantities
     5874
    58745875
    58755876    ##
     
    59605961        outfile.createVariable('x', sww_precision, ('number_of_points',))
    59615962        outfile.createVariable('y', sww_precision, ('number_of_points',))
    5962         outfile.createVariable('elevation', sww_precision,
    5963                                ('number_of_points',))
    5964         q = 'elevation'
    5965         outfile.createVariable(q + Write_sww.RANGE, sww_precision,
    5966                                ('numbers_in_range',))
    5967 
    5968         # Initialise ranges with small and large sentinels.
    5969         # If this was in pure Python we could have used None sensibly
    5970         outfile.variables[q+Write_sww.RANGE][0] = max_float  # Min
    5971         outfile.variables[q+Write_sww.RANGE][1] = -max_float # Max
    5972 
    5973         # FIXME: Backwards compatibility
    5974         outfile.createVariable('z', sww_precision, ('number_of_points',))
    59755963
    59765964        outfile.createVariable('volumes', netcdf_int, ('number_of_volumes',
     
    59815969                               ('number_of_timesteps',))
    59825970
    5983         for q in Write_sww.sww_quantities:
     5971                               
     5972        for q in self.static_quantities:
     5973           
     5974            outfile.createVariable(q, sww_precision,
     5975                                   ('number_of_points',))
     5976           
     5977            outfile.createVariable(q + Write_sww.RANGE, sww_precision,
     5978                                   ('numbers_in_range',))
     5979                                   
     5980            # Initialise ranges with small and large sentinels.
     5981            # If this was in pure Python we could have used None sensibly
     5982            outfile.variables[q+Write_sww.RANGE][0] = max_float  # Min
     5983            outfile.variables[q+Write_sww.RANGE][1] = -max_float # Max
     5984
     5985        # FIXME: Backwartds compat get rid of z once old view has retired       
     5986                               
     5987        outfile.createVariable('z', sww_precision,
     5988                               ('number_of_points',))                               
     5989                               
     5990        for q in self.dynamic_quantities:
    59845991            outfile.createVariable(q, sww_precision, ('number_of_timesteps',
    59855992                                                      'number_of_points'))
     
    61496156        # Also write the ranges: stage_range,
    61506157        # xmomentum_range and ymomentum_range
    6151         for q in Write_sww.sww_quantities:
     6158        for q in self.dynamic_quantities:
    61526159            if not quant.has_key(q):
    61536160                msg = 'SWW file can not write quantity %s' % q
     
    61756182        log.critical('------------------------------------------------')
    61766183        log.critical('More Statistics:')
    6177         for q in Write_sww.sww_quantities:
     6184        for q in self.dynamic_quantities:
    61786185            log.critical('  %s in [%f, %f]'
    61796186                         % (q, outfile.variables[q+Write_sww.RANGE][0],
  • anuga_core/source/anuga/shallow_water/test_data_manager.py

    r7308 r7339  
    1041910419        number_of_volumes = len(volumes)
    1042010420        number_of_points = len(points_utm)
    10421         sww = Write_sww()
     10421        sww = Write_sww(['elevation'], ['stage', 'xmomentum', 'ymomentum'])
    1042210422        sww.store_header(outfile, times, number_of_volumes,
    1042310423                         number_of_points, description='fully sick testing',
     
    1045110451        number_of_volumes = len(volumes)
    1045210452        number_of_points = len(points_utm)
    10453         sww = Write_sww()
     10453        sww = Write_sww(['elevation'], ['stage', 'xmomentum', 'ymomentum'])       
    1045410454        sww.store_header(outfile, times, number_of_volumes,
    1045510455                         number_of_points, description='fully sick testing',
     
    1048710487        number_of_volumes = len(volumes)
    1048810488        number_of_points = len(points_utm)
    10489         sww = Write_sww()
     10489        sww = Write_sww(['elevation'], ['stage', 'xmomentum', 'ymomentum'])       
    1049010490        sww.store_header(outfile, times, number_of_volumes,
    1049110491                         number_of_points, description='fully sick testing',
     
    1052610526        number_of_volumes = len(volumes)
    1052710527        number_of_points = len(points_utm)
    10528         sww = Write_sww()
     10528        sww = Write_sww(['elevation'], ['stage', 'xmomentum', 'ymomentum'])       
    1052910529        sww.store_header(outfile, times, number_of_volumes,
    1053010530                         number_of_points, description='fully sick testing',
     
    1056210562        number_of_volumes = len(volumes)
    1056310563        number_of_points = len(points_utm)
    10564         sww = Write_sww()
     10564        sww = Write_sww(['elevation'], ['stage', 'xmomentum', 'ymomentum'])       
    1056510565        sww.store_header(outfile, times, number_of_volumes,
    1056610566                         number_of_points, description='fully sick testing',
Note: See TracChangeset for help on using the changeset viewer.