Changeset 2852


Ignore:
Timestamp:
May 11, 2006, 5:17:22 PM (18 years ago)
Author:
ole
Message:

Nailed the problem with tests failing when fixing duplicate timestep issue.

Location:
inundation
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • inundation/fit_interpolate/interpolate.py

    r2802 r2852  
    461461                    raise Exception(msg)
    462462
    463 
    464         msg = 'Time interval [%s:%s]' %(self.T[0], self.T[1])
    465         msg += ' does not match model time: %s\n' %t
     463        msg = 'Time interval [%.16f:%.16f]' %(self.T[0], self.T[-1])
     464        msg += ' does not match model time: %.16f\n' %t
    466465        if t < self.T[0]: raise Exception(msg)
    467466        if t > self.T[-1]: raise Exception(msg)
  • inundation/pyvolution/data_manager.py

    r2750 r2852  
    239239        from Numeric import Int, Float, Float32
    240240
    241         self.precision = Float32 #Use single precision
     241        self.precision = Float32 #Use single precision for quantities
    242242        if hasattr(domain, 'max_size'):
    243243            self.max_size = domain.max_size #file size max is 2Gig
     
    301301                                                'number_of_vertices'))
    302302
    303             fid.createVariable('time', self.precision,
     303            fid.createVariable('time', Float,  # Always use full precision lest two timesteps
     304                                               # close to each other may appear as the same step
    304305                               ('number_of_timesteps',))
    305306
  • inundation/pyvolution/domain.py

    r2851 r2852  
    697697                if self.time > finaltime:
    698698                    #FIXME (Ole, 30 April 2006): Do we need this check?
    699                     print 'WARNING (domain.py): time overshot finaltime'
     699                    print 'WARNING (domain.py): time overshot finaltime. Contact Ole.Nielsen@ga.gov.au'
    700700                    self.time = finaltime
    701701
    702702                # Yield final time and stop
    703                 #print 'finaltime %.18f' %self.time
    704703                yield(self.time)
    705704                break
     
    714713
    715714                #Pass control on to outer loop for more specific actions
    716                 #print 'yieldtime %.18f' %self.time
    717715                yield(self.time)
    718 
    719                 #if finaltime is not None and self.time >= finaltime:
    720                 if finaltime is not None and abs(self.time - finaltime) < epsilon:
    721                     # FIXME (Ole, 30 April 2006): Maybe this will remove
    722                     # duplicate final timesteps?
    723                     # What we really need is to go back to conditions like
    724                     # if finaltime is not None and self.time >= finaltime:
    725                     # as above and then understand fully
    726                     # the two tests that break as a consequence
    727                     break
    728716
    729717                # Reinitialise
     
    733721                self.number_of_steps = 0
    734722                self.number_of_first_order_steps = 0
    735 
     723               
    736724
    737725    def evolve_to_end(self, finaltime = 1.0):
  • inundation/pyvolution/test_util.py

    r2783 r2852  
    104104
    105105       
    106     def test_spatio_temporal_file_function(self):
     106    def test_spatio_temporal_file_function_basic(self):
    107107        """Test that spatio temporal file function performs the correct
    108108        interpolations in both time and space
     
    147147        t0 = -1
    148148        for t in domain1.evolve(yieldstep = 0.1, finaltime = finaltime):
    149             #print 'Timesteps: %f, %f' %(t0, t)
     149            #print 'Timesteps: %.16f, %.16f' %(t0, t)
    150150            #if t == t0:
    151151            #    msg = 'Duplicate timestep found: %f, %f' %(t0, t)
     
    171171        #Diagonal is identified by vertices: 0, 5, 10, 15
    172172
    173         timestep = len(time)-1 #Last timestep
    174         d_stage = reshape(take(stage[timestep, :], [0,5,10,15]), (4,1))
    175         d_uh = reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1))
    176         d_vh = reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1))
     173        last_time_index = len(time)-1 #Last last_time_index
     174        d_stage = reshape(take(stage[last_time_index, :], [0,5,10,15]), (4,1))
     175        d_uh = reshape(take(xmomentum[last_time_index, :], [0,5,10,15]), (4,1))
     176        d_vh = reshape(take(ymomentum[last_time_index, :], [0,5,10,15]), (4,1))
    177177        D = concatenate( (d_stage, d_uh, d_vh), axis=1)
    178178
     
    195195                          interpolation_points = d_midpoints)
    196196
    197         q = f(timestep/10., point_id=0); assert allclose(r0, q)
    198         q = f(timestep/10., point_id=1); assert allclose(r1, q)
    199         q = f(timestep/10., point_id=2); assert allclose(r2, q)
     197        msg = 'duplicate timesteps: %.16f and %.16f' %(f.T[-1], f.T[-2])
     198        assert not f.T[-1] == f.T[-2], msg
     199        t = time[last_time_index]
     200        q = f(t, point_id=0); assert allclose(r0, q)
     201        q = f(t, point_id=1); assert allclose(r1, q)
     202        q = f(t, point_id=2); assert allclose(r2, q)
    200203
    201204
     
    371374        #Diagonal is identified by vertices: 0, 5, 10, 15
    372375
    373         timestep = len(time)-1 #Last timestep
    374         d_stage = reshape(take(stage[timestep, :], [0,5,10,15]), (4,1))
    375         d_uh = reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1))
    376         d_vh = reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1))
     376        last_time_index = len(time)-1 #Last last_time_index     
     377        d_stage = reshape(take(stage[last_time_index, :], [0,5,10,15]), (4,1))
     378        d_uh = reshape(take(xmomentum[last_time_index, :], [0,5,10,15]), (4,1))
     379        d_vh = reshape(take(ymomentum[last_time_index, :], [0,5,10,15]), (4,1))
    377380        D = concatenate( (d_stage, d_uh, d_vh), axis=1)
    378381
     
    400403                          interpolation_points = d_midpoints)
    401404
    402         q = f(timestep/10., point_id=0); assert allclose(r0, q)
    403         q = f(timestep/10., point_id=1); assert allclose(r1, q)
    404         q = f(timestep/10., point_id=2); assert allclose(r2, q)
     405        t = time[last_time_index]                         
     406        q = f(t, point_id=0); assert allclose(r0, q)
     407        q = f(t, point_id=1); assert allclose(r1, q)
     408        q = f(t, point_id=2); assert allclose(r2, q)
    405409
    406410
Note: See TracChangeset for help on using the changeset viewer.