Changeset 8068


Ignore:
Timestamp:
Nov 11, 2010, 11:55:52 AM (8 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:
trunk/anuga_core/source/anuga
Files:
11 edited

Legend:

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

    r8065 r8068  
    6262                       full_send_dict=None,
    6363                       ghost_recv_dict=None,
     64                       starttime=0.0,
    6465                       processor=0,
    6566                       numproc=1,
     
    253254
    254255        # Model time
    255         self.time = 0.0
    256256        self.finaltime = None
    257257        self.recorded_min_timestep = self.recorded_max_timestep = 0.0
    258         self.starttime = 0 # Physical starttime if any
    259                            # (0 is 1 Jan 1970 00:00:00)
     258        self.starttime = starttime # Physical starttime if any
     259        self.time = self.starttime
    260260        self.timestep = 0.0
    261261        self.flux_timestep = 0.0
     
    499499        """Get the absolute model time (seconds)."""
    500500
    501         return self.time + self.starttime
    502 
     501        return self.time
    503502
    504503    ##
     
    10161015
    10171016        model_time = self.get_time()
     1017 
    10181018        if self.recorded_min_timestep == self.recorded_max_timestep:
    10191019            msg += 'Time = %.4f, delta t = %.8f, steps=%d' \
     
    12251225        # Observe time interval restriction if any
    12261226        if self.monitor_time_interval is not None and\
    1227                (self.time < self.monitor_time_interval[0] or\
    1228                self.time > self.monitor_time_interval[1]):
     1227               (self.get_time() < self.monitor_time_interval[0] or\
     1228               self.get_time() > self.monitor_time_interval[1]):
    12291229            return
    12301230
     
    12491249                maxloc = Q.get_maximum_location()
    12501250                info_block['max_location'] = maxloc
    1251                 info_block['max_time'] = self.time
     1251                info_block['max_time'] = self.get_time()
    12521252
    12531253            # Update minimum
     
    12581258                minloc = Q.get_minimum_location()
    12591259                info_block['min_location'] = minloc
    1260                 info_block['min_time'] = self.time
     1260                info_block['min_time'] = self.get_time()
    12611261
    12621262    ##
     
    13761376    def set_starttime(self, time):
    13771377        self.starttime = float(time)
     1378        self.set_time(self.starttime)
     1379       
    13781380
    13791381################################################################################
     
    14271429                   % self.get_boundary_tags())
    14281430        assert hasattr(self, 'boundary_objects'), msg
    1429 
     1431       
     1432        if self.get_time() != self.get_starttime():
     1433            self.set_time(self.get_starttime())
     1434       
    14301435        if yieldstep is None:
    14311436            yieldstep = self.evolve_max_timestep
     
    14351440        self._order_ = self.default_order
    14361441
     1442        assert finaltime > self.get_starttime(), 'finaltime is less than starttime!'
     1443       
    14371444        if finaltime is not None and duration is not None:
    14381445            msg = 'Only one of finaltime and duration may be specified'
     
    14451452
    14461453        N = len(self)                             # Number of triangles
    1447         self.yieldtime = self.time + yieldstep    # set next yield time
     1454        self.yieldtime = self.get_time() + yieldstep    # set next yield time
    14481455
    14491456        # Initialise interval of timestep sizes (for reporting only)
     
    14671474        self.update_extrema()
    14681475
    1469 
    1470 
    14711476        # Or maybe restore from latest checkpoint
    14721477        if self.checkpoint is True:
     
    14741479
    14751480        if skip_initial_step is False:
    1476             yield(self.time)      # Yield initial values
     1481            yield(self.get_time())      # Yield initial values
    14771482
    14781483        while True:
    14791484
    1480             initial_time = self.time
     1485            initial_time = self.get_time()
    14811486
    14821487            #==========================================
     
    14841489            #==========================================
    14851490            if self.get_timestepping_method() == 'euler':
    1486                 self.evolve_one_euler_step(yieldstep, finaltime)
     1491                self.evolve_one_euler_step(yieldstep, self.finaltime)
    14871492
    14881493            elif self.get_timestepping_method() == 'rk2':
    1489                 self.evolve_one_rk2_step(yieldstep, finaltime)
     1494                self.evolve_one_rk2_step(yieldstep, self.finaltime)
    14901495
    14911496            elif self.get_timestepping_method() == 'rk3':
    1492                 self.evolve_one_rk3_step(yieldstep, finaltime)
     1497                self.evolve_one_rk3_step(yieldstep, self.finaltime)
    14931498
    14941499            #==========================================
     
    15031508
    15041509            # Update time
    1505             self.time = initial_time + self.timestep
     1510            self.set_time(initial_time + self.timestep)
    15061511
    15071512            # Update vertex and edge values
     
    15191524
    15201525            # Yield results
    1521             if finaltime is not None and self.time >= finaltime-epsilon:
    1522                 if self.time > finaltime:
     1526            if self.finaltime is not None and self.get_time() >= self.finaltime-epsilon:
     1527               
     1528                if self.get_time() > self.finaltime:
    15231529                    # FIXME (Ole, 30 April 2006): Do we need this check?
    15241530                    # Probably not (Ole, 18 September 2008).
    15251531                    # Now changed to Exception.
    1526                     msg = ('WARNING (domain.py): time overshot finaltime. '
    1527                            'Contact Ole.Nielsen@ga.gov.au')
     1532                    msg = ('WARNING (domain.py): time overshot finaltime. ')
    15281533                    raise Exception, msg
    15291534
    15301535                # Log and then Yield final time and stop
    1531                 self.time = finaltime
     1536                self.set_time(self.finaltime)
    15321537                self.log_operator_timestepping_statistics()
    1533                 yield(self.time)
     1538                yield(self.get_time())
    15341539                break
    15351540
    15361541            # if we are at the next yield point
    1537             if self.time >= self.yieldtime:
     1542            if self.get_time() >= self.yieldtime:
    15381543                # Yield (intermediate) time and allow inspection of domain
    15391544                if self.checkpoint is True:
     
    15431548                # Log and then Pass control on to outer loop for more specific actions
    15441549                self.log_operator_timestepping_statistics()
    1545                 yield(self.time)
     1550                yield(self.get_time())
    15461551
    15471552                # Reinitialise
     
    16141619
    16151620        # Update time
    1616         self.time += self.timestep
     1621        self.set_time(self.get_time() + self.timestep)
    16171622
    16181623        # Update vertex and edge values
     
    16631668        self.backup_conserved_quantities()
    16641669
    1665         initial_time = self.time
     1670        initial_time = self.get_time()
    16661671
    16671672        ######
     
    16851690
    16861691        # Update time
    1687         self.time += self.timestep
     1692        self.set_time(self.time + self.timestep)
    16881693
    16891694        # Update vertex and edge values
     
    17211726
    17221727        # Set substep time
    1723         self.time = initial_time + self.timestep*0.5
     1728        self.set_time(initial_time + self.timestep*0.5)
    17241729
    17251730        # Update vertex and edge values
     
    17541759
    17551760        # Set new time
    1756         self.time = initial_time + self.timestep
     1761        self.set_time(initial_time + self.timestep)
    17571762
    17581763
     
    19411946
    19421947        # Ensure that final time is not exceeded
    1943         if finaltime is not None and self.time + timestep > finaltime :
    1944             timestep = finaltime-self.time
     1948        if finaltime is not None and self.get_time() + timestep > finaltime :
     1949            timestep = finaltime - self.get_time()
    19451950
    19461951        # Ensure that model time is aligned with yieldsteps
    1947         if self.time + timestep > self.yieldtime:
    1948             timestep = self.yieldtime - self.time
     1952        if self.get_time() + timestep > self.yieldtime:
     1953            timestep = self.yieldtime - self.get_time()
    19491954
    19501955        self.timestep = timestep
     
    20752080            for i in range(self.number_of_full_triangles):
    20762081                if self.max_speed[i] > bins[-1]:
    2077                     msg = 'Time=%f: Ignoring isolated high ' % self.time
     2082                    msg = 'Time=%f: Ignoring isolated high ' % self.get_time()
    20782083                    msg += 'speed triangle '
    20792084                    msg += '#%d of %d with max speed=%f' \
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/test_gauge.py

    r8063 r8068  
    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)
  • trunk/anuga_core/source/anuga/file/sww.py

    r7862 r8068  
    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()
     
    952952
    953953    domain.geo_reference = geo_reference
    954 
    955     domain.starttime = float(starttime) + float(t)
    956     domain.time = 0.0
    957954
    958955    for quantity in other_quantities:
  • trunk/anuga_core/source/anuga/file/test_read_sww.py

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

    r7872 r8068  
    103103        #Now evolve them both, just to be sure
    104104        ######################################x
    105         domain.time = 0.
    106105        from time import sleep
    107106
     
    116115            pass
    117116
    118         final = final - (domain2.starttime-domain.starttime)
    119117        #BUT since domain1 gets time hacked back to 0:
    120         final = final + (domain2.starttime-domain.starttime)
     118       
     119        final = final + (domain2.get_starttime() - domain.get_starttime())
    121120
    122121        domain2.smooth = False
  • trunk/anuga_core/source/anuga/file_conversion/test_urs2sts.py

    r7866 r8068  
    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)
  • trunk/anuga_core/source/anuga/shallow_water/shallow_water_domain.py

    r8047 r8068  
    106106                 full_send_dict=None,
    107107                 ghost_recv_dict=None,
     108                 starttime=0,
    108109                 processor=0,
    109110                 numproc=1,
     
    140141            other_quantities = ['elevation', 'friction']
    141142       
     143       
    142144        Generic_Domain.__init__(self,
    143145                            coordinates,
     
    155157                            full_send_dict,
    156158                            ghost_recv_dict,
     159                            starttime,
    157160                            processor,
    158161                            numproc,
     
    563566        self.distribute_to_vertices_and_edges()
    564567
    565         if self.store is True and self.time == 0.0:
     568        if self.store is True and self.get_time() == self.get_starttime():
    566569            self.initialise_storage()
    567570
  • trunk/anuga_core/source/anuga/shallow_water/test_data_manager.py

    r7872 r8068  
    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   
  • trunk/anuga_core/source/anuga/shallow_water/test_forcing.py

    r7844 r8068  
    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)
  • trunk/anuga_core/source/anuga/shallow_water/test_forcing_terms.py

    r7814 r8068  
    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)
     957
    971958
    972959        assert num.allclose(domain.quantities['stage'].explicit_update[0], 0)
  • trunk/anuga_core/source/anuga/shallow_water/test_system.py

    r7778 r8068  
    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.