Ignore:
Timestamp:
Nov 11, 2010, 11:55:52 AM (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.

File:
1 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' \
Note: See TracChangeset for help on using the changeset viewer.