Changeset 8069


Ignore:
Timestamp:
Nov 11, 2010, 4:47:02 PM (14 years ago)
Author:
habili
Message:

Fixed bug where starttime and duration in the evolve function did not produce correct results. Starttime is now set in the constructor of Domain and is 0 by default. time is is to starttime. Also a bug was fixed where duration did not correctly calculate the finaltime. Associated unit tests have also been fixed to reflect the change.

Location:
branches/anuga_1_2_0/anuga_core/source/anuga
Files:
12 edited

Legend:

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

    r7810 r8069  
    6262                       full_send_dict=None,
    6363                       ghost_recv_dict=None,
     64                       starttime=0.0,
    6465                       processor=0,
    6566                       numproc=1,
     
    253254        self.finaltime = None
    254255        self.recorded_min_timestep = self.recorded_max_timestep = 0.0
    255         self.starttime = 0 # Physical starttime if any
    256                            # (0 is 1 Jan 1970 00:00:00)
     256        self.starttime = starttime # Physical starttime if any
     257        self.time = self.starttime
    257258        self.timestep = 0.0
    258259        self.flux_timestep = 0.0
     
    496497        """Get the absolute model time (seconds)."""
    497498
    498         return self.time + self.starttime
     499        return self.time
     500
     501    ##
     502    # @brief Get current timestep.
     503    # @return The curent timestep (seconds).
     504    def get_timestep(self):
     505        """et current timestep (seconds)."""
     506
     507        return self.timestep
    499508
    500509    ##
     
    12131222        # Observe time interval restriction if any
    12141223        if self.monitor_time_interval is not None and\
    1215                (self.time < self.monitor_time_interval[0] or\
    1216                self.time > self.monitor_time_interval[1]):
     1224               (self.get_time() < self.monitor_time_interval[0] or\
     1225               self.get_time() > self.monitor_time_interval[1]):
    12171226            return
    12181227
     
    12371246                maxloc = Q.get_maximum_location()
    12381247                info_block['max_location'] = maxloc
    1239                 info_block['max_time'] = self.time
     1248                info_block['max_time'] = self.get_time()
    12401249
    12411250            # Update minimum
     
    12461255                minloc = Q.get_minimum_location()
    12471256                info_block['min_location'] = minloc
    1248                 info_block['min_time'] = self.time
     1257                info_block['min_time'] = self.get_time()
    12491258
    12501259    ##
     
    13641373    def set_starttime(self, time):
    13651374        self.starttime = float(time)
     1375        self.set_time(self.starttime)
     1376       
    13661377
    13671378################################################################################
     
    14151426                   % self.get_boundary_tags())
    14161427        assert hasattr(self, 'boundary_objects'), msg
    1417 
     1428       
     1429        if self.get_time() != self.get_starttime():
     1430            self.set_time(self.get_starttime())
     1431       
    14181432        if yieldstep is None:
    14191433            yieldstep = self.evolve_max_timestep
     
    14231437        self._order_ = self.default_order
    14241438
     1439        assert finaltime > self.get_starttime(), 'finaltime is less than starttime!'
     1440       
    14251441        if finaltime is not None and duration is not None:
    14261442            msg = 'Only one of finaltime and duration may be specified'
     
    14331449
    14341450        N = len(self)                             # Number of triangles
    1435         self.yieldtime = self.time + yieldstep    # set next yield time
     1451        self.yieldtime = self.get_time() + yieldstep    # set next yield time
    14361452
    14371453        # Initialise interval of timestep sizes (for reporting only)
     
    14581474
    14591475        if skip_initial_step is False:
    1460             yield(self.time)      # Yield initial values
     1476            yield(self.get_time())      # Yield initial values
    14611477
    14621478        while True:
    1463             # Evolve One Step, using appropriate timestepping method
     1479
     1480            initial_time = self.get_time()
     1481
    14641482            if self.get_timestepping_method() == 'euler':
    1465                 self.evolve_one_euler_step(yieldstep, finaltime)
     1483                self.evolve_one_euler_step(yieldstep, self.finaltime)
    14661484
    14671485            elif self.get_timestepping_method() == 'rk2':
    1468                 self.evolve_one_rk2_step(yieldstep, finaltime)
     1486                self.evolve_one_rk2_step(yieldstep, self.finaltime)
    14691487
    14701488            elif self.get_timestepping_method() == 'rk3':
    1471                 self.evolve_one_rk3_step(yieldstep, finaltime)
     1489                self.evolve_one_rk3_step(yieldstep, self.finaltime)
    14721490
    14731491            # Update extrema if necessary (for reporting)
     
    14791497
    14801498            # Yield results
    1481             if finaltime is not None and self.time >= finaltime-epsilon:
    1482                 if self.time > finaltime:
     1499            if self.finaltime is not None and self.get_time() >= self.finaltime-epsilon:
     1500               
     1501                if self.get_time() > self.finaltime:
    14831502                    # FIXME (Ole, 30 April 2006): Do we need this check?
    14841503                    # Probably not (Ole, 18 September 2008).
    14851504                    # Now changed to Exception.
    1486                     msg = ('WARNING (domain.py): time overshot finaltime. '
    1487                            'Contact Ole.Nielsen@ga.gov.au')
     1505                    msg = ('WARNING (domain.py): time overshot finaltime. ')
    14881506                    raise Exception, msg
    14891507
    1490                 # Yield final time and stop
    1491                 self.time = finaltime
    1492                 yield(self.time)
     1508                # Log and then Yield final time and stop
     1509                self.set_time(self.finaltime)
     1510                yield(self.get_time())
    14931511                break
    14941512
    14951513            # if we are at the next yield point
    1496             if self.time >= self.yieldtime:
     1514            if self.get_time() >= self.yieldtime:
    14971515                # Yield (intermediate) time and allow inspection of domain
    14981516                if self.checkpoint is True:
     
    15001518                    self.delete_old_checkpoints()
    15011519
    1502                 # Pass control on to outer loop for more specific actions
    1503                 yield(self.time)
     1520                # Log and then Pass control on to outer loop for more specific actions
     1521                yield(self.get_time())
    15041522
    15051523                # Reinitialise
     
    15781596
    15791597        # Update time
    1580         self.time += self.timestep
     1598        self.set_time(self.get_time() + self.timestep)
    15811599
    15821600        # Update vertex and edge values
     
    16321650        self.backup_conserved_quantities()
    16331651
    1634         initial_time = self.time
     1652        initial_time = self.get_time()
    16351653
    16361654        ######
     
    16541672
    16551673        # Update time
    1656         self.time += self.timestep
     1674        self.set_time(self.time + self.timestep)
    16571675
    16581676        # Update vertex and edge values
     
    16901708
    16911709        # Set substep time
    1692         self.time = initial_time + self.timestep*0.5
     1710        self.set_time(initial_time + self.timestep*0.5)
    16931711
    16941712        # Update vertex and edge values
     
    17231741
    17241742        # Set new time
    1725         self.time = initial_time + self.timestep
     1743        self.set_time(initial_time + self.timestep)
    17261744
    17271745        # Update vertex and edge values
     
    18751893
    18761894        # Ensure that final time is not exceeded
    1877         if finaltime is not None and self.time + timestep > finaltime :
    1878             timestep = finaltime-self.time
     1895        if finaltime is not None and self.get_time() + timestep > finaltime :
     1896            timestep = finaltime - self.get_time()
    18791897
    18801898        # Ensure that model time is aligned with yieldsteps
    1881         if self.time + timestep > self.yieldtime:
    1882             timestep = self.yieldtime - self.time
     1899        if self.get_time() + timestep > self.yieldtime:
     1900            timestep = self.yieldtime - self.get_time()
    18831901
    18841902        self.timestep = timestep
     
    20092027            for i in range(self.number_of_full_triangles):
    20102028                if self.max_speed[i] > bins[-1]:
    2011                     msg = 'Time=%f: Ignoring isolated high ' % self.time
     2029                    msg = 'Time=%f: Ignoring isolated high ' % self.get_time()
    20122030                    msg += 'speed triangle '
    20132031                    msg += '#%d of %d with max speed=%f' \
  • branches/anuga_1_2_0/anuga_core/source/anuga/abstract_2d_finite_volumes/test_gauge.py

    r7778 r8069  
    8484            os.remove(self.sww.filename)
    8585
    86     def _create_sww(self):
     86    def _create_sww(self,stage=10.0, timestep=2.0):
    8787        self.sww = SWW_file(self.domain)
    8888        self.sww.store_connectivity()
    8989        self.sww.store_timestep()
    90         self.domain.set_quantity('stage', 10.0) # This is automatically limited
     90        self.domain.set_quantity('stage', stage) # This is automatically limited
    9191        # so it will not be less than the elevation
    92         self.domain.time = 2.
     92        self.domain.set_time(self.domain.get_time()-self.domain.starttime+timestep)
    9393        self.sww.store_timestep()
    9494       
     
    245245       
    246246        domain = self.domain
    247         domain.set_starttime(5)
    248         self._create_sww()
     247        domain.set_starttime(1)
     248       
     249        self._create_sww(timestep=2)
    249250       
    250251        # test the function
     
    258259point2, 0.5, 2.0, 9.0\n")
    259260        file_id.close()
    260 
     261       
    261262        sww2csv_gauges(self.sww.filename,
    262263                            points_file,
     
    265266
    266267#        point1_answers_array = [[0.0,1.0,-5.0,3.0,4.0], [2.0,10.0,-5.0,3.0,4.0]]
    267         point1_answers_array = [[5.0,5.0/3600.,1.0,6.0,-5.0,3.0,4.0], [7.0,7.0/3600.,10.0,15.0,-5.0,3.0,4.0]]
     268        point1_answers_array = [[2.0,2.0/3600.,1.0,6.0,-5.0,3.0,4.0], [3.0,3.0/3600.,10.0,15.0,-5.0,3.0,4.0]]
    268269        point1_filename = 'gauge_point1.csv'
    269270        point1_handle = file(point1_filename)
     
    279280            assert num.allclose(line[i], point1_answers_array[i])
    280281
    281         point2_answers_array = [[5.0,5.0/3600.,1.0,1.5,-0.5,3.0,4.0], [7.0,7.0/3600.,10.0,10.5,-0.5,3.0,4.0]]
     282        point2_answers_array = [[2.0,2.0/3600.,1.0,1.5,-0.5,3.0,4.0], [3.0,3.0/3600.,10.0,10.5,-0.5,3.0,4.0]]
    282283        point2_filename = 'gauge_point2.csv'
    283284        point2_handle = file(point2_filename)
  • branches/anuga_1_2_0/anuga_core/source/anuga/file/sww.py

    r7862 r8069  
    941941   
    942942    try:
    943         domain = Domain(coordinates, volumes, boundary)
     943        domain = Domain(coordinates, volumes, boundary, starttime=(float(starttime) + float(t)))
    944944    except AssertionError, e:
    945945        fid.close()
  • branches/anuga_1_2_0/anuga_core/source/anuga/file/test_read_sww.py

    r7762 r8069  
    151151            new_domain.set_quantity(qname, q)   
    152152
    153 
    154         new_domain.set_starttime(sww_file.get_time())
    155153        #------------------------------------------------------------------
    156154        # Setup boundary conditions
  • branches/anuga_1_2_0/anuga_core/source/anuga/file/test_sww.py

    r7872 r8069  
    103103        #Now evolve them both, just to be sure
    104104        ######################################x
    105         domain.time = 0.
     105
    106106        from time import sleep
    107107
     
    116116            pass
    117117
    118         final = final - (domain2.starttime-domain.starttime)
    119118        #BUT since domain1 gets time hacked back to 0:
    120         final = final + (domain2.starttime-domain.starttime)
     119       
     120        final = final + (domain2.get_starttime() - domain.get_starttime())
    121121
    122122        domain2.smooth = False
  • branches/anuga_1_2_0/anuga_core/source/anuga/file_conversion/sww2dem.py

    r7841 r8069  
    7878    'elevation'. Quantity is not a list of quantities.
    7979
    80     if timestep (an index) is given, output quantity at that timestep
    81 
    82     if reduction is given and its an index, output quantity at that timestep. If reduction is given
    83     and is a built in function, use that to reduce quantity over all timesteps.
     80    If reduction is given and it's an index, sww2dem will output the quantity at that time-step.
     81    If reduction is given and it's a built in function (eg max, min, mean), then that
     82    function is used to reduce the quantity over all time-steps. If reduction is not given,
     83    reduction is set to "max" by default.
    8484
    8585    datum
  • branches/anuga_1_2_0/anuga_core/source/anuga/file_conversion/test_urs2sts.py

    r7866 r8069  
    14111411       
    14121412        domain_drchlt = Domain(meshname)
     1413        domain_drchlt.set_starttime(2.0)
    14131414        domain_drchlt.set_quantity('stage', tide)
    14141415        Br = Reflective_boundary(domain_drchlt)
     
    15541555
    15551556        domain_drchlt = Domain(meshname)
     1557        domain_drchlt.set_starttime(2.0)
    15561558        domain_drchlt.set_quantity('stage', tide)
    15571559        Br = Reflective_boundary(domain_drchlt)
     
    19191921       
    19201922        domain_drchlt = Domain(meshname)
     1923        domain_drchlt.set_starttime(2.0)
    19211924        domain_drchlt.set_quantity('stage', tide)
    19221925        Br = Reflective_boundary(domain_drchlt)
  • branches/anuga_1_2_0/anuga_core/source/anuga/shallow_water/shallow_water_domain.py

    r7870 r8069  
    106106                 full_send_dict=None,
    107107                 ghost_recv_dict=None,
     108                 starttime=0,
    108109                 processor=0,
    109110                 numproc=1,
     
    155156                            full_send_dict,
    156157                            ghost_recv_dict,
     158                            starttime,
    157159                            processor,
    158160                            numproc,
     
    561563        self.distribute_to_vertices_and_edges()
    562564
    563         if self.store is True and self.time == 0.0:
     565        if self.store is True and self.get_time() == self.get_starttime():
    564566            self.initialise_storage()
    565567
  • branches/anuga_1_2_0/anuga_core/source/anuga/shallow_water/test_data_manager.py

    r7872 r8069  
    783783       
    784784        temp_time=num.zeros(int(finaltime/yieldstep)+1,num.float)
     785       
     786        domain_time.set_starttime(domain_fbound.get_starttime())
     787       
    785788        for i, t in enumerate(domain_time.evolve(yieldstep=yieldstep,
    786789                                                   finaltime=finaltime,
     
    831834if __name__ == "__main__":
    832835    #suite = unittest.makeSuite(Test_Data_Manager, 'test_sww2domain2')
    833     suite = unittest.makeSuite(Test_Data_Manager, 'test_sww')
     836    suite = unittest.makeSuite(Test_Data_Manager, 'test')
    834837   
    835838   
  • branches/anuga_1_2_0/anuga_core/source/anuga/shallow_water/test_forcing.py

    r7844 r8069  
    591591        domain.forcing_terms.append(R)
    592592
    593         # This will test that time used in the forcing function takes
    594         # startime into account.
    595         domain.starttime = 5.0
    596 
    597         domain.time = 7.
     593        # This will test that time is set to starttime in set_starttime
     594        domain.set_starttime(5.0)
    598595
    599596        domain.compute_forcing_terms()
     
    602599                            (3*domain.get_time() + 7)/1000)
    603600        assert num.allclose(domain.quantities['stage'].explicit_update[1],
    604                             (3*(domain.time + domain.starttime) + 7)/1000)
    605 
    606         # Using internal time her should fail
    607         assert not num.allclose(domain.quantities['stage'].explicit_update[1],
    608                                 (3*domain.time + 7)/1000)
     601                            (3*domain.get_starttime() + 7)/1000)
    609602
    610603        assert num.allclose(domain.quantities['stage'].explicit_update[0], 0)
     
    657650        domain.forcing_terms.append(R)
    658651
    659         # This will test that time used in the forcing function takes
    660         # startime into account.
    661         domain.starttime = 5.0
    662 
    663         domain.time = 7.
     652        # This will test that time is set to starttime in set_starttime
     653        domain.set_starttime(5.0)
    664654
    665655        domain.compute_forcing_terms()
     
    668658                            (3*domain.get_time() + 7)/1000)
    669659        assert num.allclose(domain.quantities['stage'].explicit_update[1],
    670                             (3*(domain.time + domain.starttime) + 7)/1000)
    671 
    672         # Using internal time her should fail
    673         assert not num.allclose(domain.quantities['stage'].explicit_update[1],
    674                                 (3*domain.time + 7)/1000)
     660                            (3*domain.get_starttime() + 7)/1000)
    675661
    676662        assert num.allclose(domain.quantities['stage'].explicit_update[0], 0)
  • branches/anuga_1_2_0/anuga_core/source/anuga/shallow_water/test_forcing_terms.py

    r7814 r8069  
    887887        domain.forcing_terms.append(R)
    888888
    889         # This will test that time used in the forcing function takes
    890         # startime into account.
    891         domain.starttime = 5.0
    892 
    893         domain.time = 7.
     889        # This will test that time is set to starttime in set_starttime
     890        domain.set_starttime(5.0)
    894891
    895892        domain.compute_forcing_terms()
     
    898895                            (3*domain.get_time() + 7)/1000)
    899896        assert num.allclose(domain.quantities['stage'].explicit_update[1],
    900                             (3*(domain.time + domain.starttime) + 7)/1000)
    901 
    902         # Using internal time her should fail
    903         assert not num.allclose(domain.quantities['stage'].explicit_update[1],
    904                                 (3*domain.time + 7)/1000)
     897                            (3*domain.get_starttime() + 7)/1000)
    905898
    906899        assert num.allclose(domain.quantities['stage'].explicit_update[0], 0)
     
    953946        domain.forcing_terms.append(R)
    954947
    955         # This will test that time used in the forcing function takes
    956         # startime into account.
    957         domain.starttime = 5.0
    958 
    959         domain.time = 7.
     948        # This will test that time is set to starttime in set_starttime
     949        domain.set_starttime(5.0)
    960950
    961951        domain.compute_forcing_terms()
     
    964954                            (3*domain.get_time() + 7)/1000)
    965955        assert num.allclose(domain.quantities['stage'].explicit_update[1],
    966                             (3*(domain.time + domain.starttime) + 7)/1000)
    967 
    968         # Using internal time her should fail
    969         assert not num.allclose(domain.quantities['stage'].explicit_update[1],
    970                                 (3*domain.time + 7)/1000)
     956                            (3*domain.get_starttime() + 7)/1000)
    971957
    972958        assert num.allclose(domain.quantities['stage'].explicit_update[0], 0)
  • branches/anuga_1_2_0/anuga_core/source/anuga/shallow_water/test_system.py

    r7778 r8069  
    8383        """
    8484     
    85         boundary_starttime = 500
     85        boundary_starttime = 0
    8686        boundary_filename = self.create_sww_boundary(boundary_starttime)
    8787        filename = tempfile.mktemp(".sww")
     
    131131        """
    132132       
    133         boundary_starttime = 500
     133        boundary_starttime = 0
    134134        boundary_filename = self.create_sww_boundary(boundary_starttime)
    135135        #print "boundary_filename",boundary_filename
     
    147147        domain.set_name(senario_name)                 
    148148        domain.set_datadir(dir)
    149         new_starttime = 510.
     149        new_starttime = 0.
    150150        domain.set_starttime(new_starttime)
    151151
     
    178178        msg += "Not logic. "
    179179        msg += "It's testing that starttime is working"
    180         assert num.allclose(stage[2,0], 11.9867153168),msg
     180        assert num.allclose(stage[2,0], 4.7981238),msg
    181181       
    182182       
Note: See TracChangeset for help on using the changeset viewer.