Changeset 282


Ignore:
Timestamp:
Sep 8, 2004, 3:13:52 PM (21 years ago)
Author:
ole
Message:

Storing of sww format OK and tested

Location:
inundation/ga/storm_surge/pyvolution
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/quantity.py

    r281 r282  
    315315
    316316            #Create connectivity
    317             tmp = reshape(array(range(m)).astype(Int), (m,1))
    318             V = concatenate( (tmp, tmp+m, tmp+2*m), axis = 1 )
    319 
     317            V = reshape(array(range(M)).astype(Int), (m,3))
     318           
    320319            #Do vertex coordinates   
    321320            if xy is True:               
    322321                C = self.domain.get_vertex_coordinates()
    323322
    324                 #X = C[:,0:6:2].copy()
    325                 #Y = C[:,1:6:2].copy()               
    326 
    327                 X = concatenate((C[:,0], C[:,2], C[:,4]),
    328                                 axis=0).astype(precision)
    329                 Y = concatenate((C[:,1], C[:,3], C[:,5]),
    330                                 axis=0).astype(precision)
    331                
    332                
    333                
     323                X = C[:,0:6:2].copy()
     324                Y = C[:,1:6:2].copy()               
     325
    334326                return X.flat, Y.flat, A, V           
    335327            else:
  • inundation/ga/storm_surge/pyvolution/show_balanced_limiters.py

    r281 r282  
    3535domain = Domain(points, vertices, boundary)
    3636domain.smooth = False
    37 #domain.visualise = False
     37domain.visualise = False
    3838domain.visualise = True
    3939domain.default_order = 2
  • inundation/ga/storm_surge/pyvolution/test_data_manager.py

    r281 r282  
    5656        self.domain = domain
    5757
    58         self.X = domain.get_vertex_coordinates()
    59         self.X0 = self.X[:,0]
    60         self.Y0 = self.X[:,1]
    61         self.X1 = self.X[:,2]
    62         self.Y1 = self.X[:,3]
    63         self.X2 = self.X[:,4]
    64         self.Y2 = self.X[:,5]               
     58        C = domain.get_vertex_coordinates()
     59        self.X = C[:,0:6:2].copy()
     60        self.Y = C[:,1:6:2].copy()
    6561       
    6662        self.F = bed
     
    155151        volumes = fid.variables['volumes']       
    156152
    157         #print z[:]
    158         #print self.F.flat
    159         #print concatenate( (self.X0, self.X1, self.X2))
    160                        
    161         assert allclose (x[:], concatenate( (self.X0, self.X1, self.X2) ))
    162         assert allclose (y[:], concatenate( (self.Y0, self.Y1, self.Y2) ))
     153
     154        assert allclose (x[:], self.X.flat)
     155        assert allclose (y[:], self.Y.flat)
    163156        assert allclose (z[:], self.F.flat)
    164157
     
    167160        P = len(self.domain)
    168161        for k in range(P):
    169              assert V[k,0] == V[k,1] - P
    170              assert V[k,1] == V[k,2] - P
    171      
    172 
    173 
     162            assert V[k, 0] == 3*k
     163            assert V[k, 1] == 3*k+1
     164            assert V[k, 2] == 3*k+2           
     165     
    174166     
    175167        fid.close()
     
    184176        """
    185177
    186 
    187178        import time, os
    188179        from Numeric import array, zeros, allclose, Float, concatenate
     
    231222     
    232223     
    233 
    234 
    235224     
    236225        fid.close()
     
    295284       
    296285       
    297 #     def test_sww_variable2(self):
    298 #         """Test that sww information can be written correctly
    299 #         multiple timesteps. Use average as reduction operator
    300 #         """
    301 
    302 #         import time, os
    303 #         from Numeric import array, zeros, allclose, Float, concatenate
    304 #         from Scientific.IO.NetCDF import NetCDFFile
    305 
    306 #         self.domain.filename = 'datatest' + str(time.time())
    307 #         self.domain.format = 'sww'
    308 #         self.domain.smooth = True
    309 
    310 #         self.domain.reduction = mean     
    311        
    312 #         sww = get_dataobject(self.domain)
    313 #         sww.store_all()
    314 #         sww.store_timestep()
    315        
    316 #         self.domain.evolve_to_end(max_timestep = 0.01, finaltime = 0.01)
    317 #         sww.store_timestep()
    318 
    319 
    320 
    321 #         #Check contents
    322 #         #Get NetCDF
    323 #         fid = NetCDFFile(sww.filename, 'r')  #Open existing file for append
    324        
    325 
    326 #         # Get the variables
    327 #         x = fid.variables['x']
    328 #         y = fid.variables['y']
    329 #         z = fid.variables['z']
    330 #         time = fid.variables['time']
    331 #         stage = fid.variables['stage']       
    332 
    333 #         #Check values
    334 
    335 #         Q0 = self.domain.volume_class.conserved_quantities_vertex0
    336 #         Q1 = self.domain.volume_class.conserved_quantities_vertex1
    337 #         Q2 = self.domain.volume_class.conserved_quantities_vertex2       
    338 
    339 #         A = stage[1,:]
    340 #         assert allclose(A[0], (Q2[0,0] + Q1[1,0])/2) 
    341 #         assert allclose(A[1], (Q0[1,0] + Q1[3,0] + Q2[2,0])/3)
    342 #         assert allclose(A[2], Q0[3,0])
    343 #         assert allclose(A[3], (Q0[0,0] + Q1[5,0] + Q2[4,0])/3)
    344 
    345 #         #Center point
    346 #         assert allclose(A[4], (Q1[0,0] + Q2[1,0] + Q0[2,0] +\
    347 #                                  Q0[5,0] + Q2[6,0] + Q1[7,0])/6)
    348                                  
    349        
    350        
    351            
    352        
    353 #         fid.close()
    354        
    355 #         #Cleanup
    356 #         os.remove(sww.filename)
    357        
    358 #     def test_sww_variable3(self):
    359 #         """Test that sww information can be written correctly
    360 #         multiple timesteps using a different reduction operator (min)
    361 #         """
    362 
    363 #         import time, os
    364 #         from Numeric import array, zeros, allclose, Float, concatenate
    365 #         from Scientific.IO.NetCDF import NetCDFFile
    366 
    367 #         self.domain.filename = 'datatest' + str(time.time())
    368 #         self.domain.format = 'sww'
    369 #         self.domain.smooth = True
    370 #         self.domain.reduction = min
    371        
    372 #         sww = get_dataobject(self.domain)
    373 #         sww.store_all()
    374 #         sww.store_timestep()
    375        
    376 #         self.domain.evolve_to_end(max_timestep = 0.01, finaltime = 0.01)
    377 #         sww.store_timestep()
    378 
    379 
    380 
    381 #         #Check contents
    382 #         #Get NetCDF
    383 #         fid = NetCDFFile(sww.filename, 'r')  #Open existing file for append
    384        
    385 
    386 #         # Get the variables
    387 #         x = fid.variables['x']
    388 #         y = fid.variables['y']
    389 #         z = fid.variables['z']
    390 #         time = fid.variables['time']
    391 #         stage = fid.variables['stage']       
    392 
    393 #         #Check values
    394 
    395 #         Q0 = self.domain.volume_class.conserved_quantities_vertex0
    396 #         Q1 = self.domain.volume_class.conserved_quantities_vertex1
    397 #         Q2 = self.domain.volume_class.conserved_quantities_vertex2       
    398 
    399 #         A = stage[1,:]
    400 #         assert allclose(A[0], min(Q2[0,0], Q1[1,0]) ) 
    401 #         assert allclose(A[1], min(Q0[1,0], Q1[3,0], Q2[2,0]) )
    402 #         assert allclose(A[2], Q0[3,0])
    403 #         assert allclose(A[3], min(Q0[0,0], Q1[5,0], Q2[4,0]) )
    404 
    405 #         #Center point
    406 #         assert allclose(A[4], min(Q1[0,0], Q2[1,0], Q0[2,0],
    407 #                                   Q0[5,0], Q2[6,0], Q1[7,0]) )
    408                                  
    409        
    410        
    411            
    412        
    413 #         fid.close()
    414        
    415 #         #Cleanup
    416 #         os.remove(sww.filename)
    417 
    418 
    419     def test_dummy(self):
    420         pass
     286    def test_sww_variable2(self):
     287        """Test that sww information can be written correctly
     288        multiple timesteps. Use average as reduction operator
     289        """
     290
     291        import time, os
     292        from Numeric import array, zeros, allclose, Float, concatenate
     293        from Scientific.IO.NetCDF import NetCDFFile
     294
     295        self.domain.filename = 'datatest' + str(time.time())
     296        self.domain.format = 'sww'
     297        self.domain.smooth = True
     298
     299        self.domain.reduction = mean     
     300     
     301        sww = get_dataobject(self.domain)
     302        sww.store_connectivity()
     303        sww.store_timestep('level')     
     304        self.domain.evolve_to_end(finaltime = 0.01)
     305        sww.store_timestep('level')
     306
     307
     308        #Check contents
     309        #Get NetCDF
     310        fid = NetCDFFile(sww.filename, 'r')  #Open existing file for append
     311
     312        # Get the variables
     313        x = fid.variables['x']
     314        y = fid.variables['y']
     315        z = fid.variables['z']
     316        time = fid.variables['time']
     317        stage = fid.variables['stage']       
     318
     319        #Check values
     320        Q = self.domain.quantities['level']     
     321        Q0 = Q.vertex_values[:,0]
     322        Q1 = Q.vertex_values[:,1]
     323        Q2 = Q.vertex_values[:,2]
     324
     325        A = stage[1,:]
     326        assert allclose(A[0], (Q2[0] + Q1[1])/2) 
     327        assert allclose(A[1], (Q0[1] + Q1[3] + Q2[2])/3)
     328        assert allclose(A[2], Q0[3])
     329        assert allclose(A[3], (Q0[0] + Q1[5] + Q2[4])/3)
     330
     331        #Center point
     332        assert allclose(A[4], (Q1[0] + Q2[1] + Q0[2] +\
     333                                 Q0[5] + Q2[6] + Q1[7])/6)
     334                               
     335     
     336     
     337         
     338     
     339        fid.close()
     340     
     341        #Cleanup
     342        os.remove(sww.filename)
     343       
     344    def test_sww_variable3(self):
     345        """Test that sww information can be written correctly
     346        multiple timesteps using a different reduction operator (min)
     347        """
     348
     349        import time, os
     350        from Numeric import array, zeros, allclose, Float, concatenate
     351        from Scientific.IO.NetCDF import NetCDFFile
     352
     353        self.domain.filename = 'datatest' + str(time.time())
     354        self.domain.format = 'sww'
     355        self.domain.smooth = True
     356        self.domain.reduction = min
     357     
     358        sww = get_dataobject(self.domain)
     359        sww.store_connectivity()
     360        sww.store_timestep('level')
     361     
     362        self.domain.evolve_to_end(finaltime = 0.01)
     363        sww.store_timestep('level')
     364
     365
     366
     367        #Check contents
     368        #Get NetCDF
     369        fid = NetCDFFile(sww.filename, 'r')  #Open existing file for append
     370     
     371
     372        # Get the variables
     373        x = fid.variables['x']
     374        y = fid.variables['y']
     375        z = fid.variables['z']
     376        time = fid.variables['time']
     377        stage = fid.variables['stage']       
     378
     379        #Check values
     380        #Check values
     381        Q = self.domain.quantities['level']     
     382        Q0 = Q.vertex_values[:,0]
     383        Q1 = Q.vertex_values[:,1]
     384        Q2 = Q.vertex_values[:,2]
     385
     386        A = stage[1,:]
     387        assert allclose(A[0], min(Q2[0], Q1[1])) 
     388        assert allclose(A[1], min(Q0[1], Q1[3], Q2[2]))
     389        assert allclose(A[2], Q0[3])
     390        assert allclose(A[3], min(Q0[0], Q1[5], Q2[4]))
     391
     392        #Center point
     393        assert allclose(A[4], min(Q1[0], Q2[1], Q0[2],\
     394                                  Q0[5], Q2[6], Q1[7]))
     395                               
     396     
     397        fid.close()
     398     
     399        #Cleanup
     400        os.remove(sww.filename)
     401
    421402
    422403#-------------------------------------------------------------
  • inundation/ga/storm_surge/pyvolution/test_quantity.py

    r281 r282  
    458458        Q = level.vertex_values
    459459
     460       
    460461        assert A.shape[0] == 9 
    461462        assert V.shape[0] == 8 
     
    520521        domain.set_quantity('friction', 0.03)
    521522
     523
     524        ######################
     525        #Initial condition - with jumps
     526
     527        bed = domain.quantities['elevation'].vertex_values
     528        level = zeros(bed.shape, Float)
     529
     530        h = 0.03
     531        for i in range(level.shape[0]):
     532            if i % 2 == 0:           
     533                level[i,:] = bed[i,:] + h
     534            else:
     535                level[i,:] = bed[i,:]
     536               
     537        domain.set_quantity('level', level)
     538
    522539        #Get level
    523540        level = domain.quantities['level']       
    524541        A, V = level.get_vertex_values(xy=False, smooth=False)
    525         Q = level.vertex_values
     542        Q = level.vertex_values.flat
    526543
    527544        for k in range(8):
    528545            assert allclose(A[k], Q[k])
    529546
     547           
     548        for k in range(8):
     549            assert V[k, 0] == 3*k
     550            assert V[k, 1] == 3*k+1
     551            assert V[k, 2] == 3*k+2           
     552           
     553
     554
    530555        X, Y, A1, V1 = level.get_vertex_values(xy=True, smooth=False)
    531556
     
    535560
    536561        #Check XY
    537        
    538         #FIXME: Do this test
    539         print X
    540        
    541         #assert allclose(X[1], 0.5)
    542         #assert allclose(Y[1], 0.5)
    543         #assert allclose(X[4], 0.0)
    544         #assert allclose(Y[4], 0.0)
    545         #assert allclose(X[12], 1.0)
    546         #assert allclose(Y[12], 0.0)               
     562        assert allclose(X[1], 0.5)
     563        assert allclose(Y[1], 0.5)
     564        assert allclose(X[4], 0.0)
     565        assert allclose(Y[4], 0.0)
     566        assert allclose(X[12], 1.0)
     567        assert allclose(Y[12], 0.0)               
    547568       
    548569       
Note: See TracChangeset for help on using the changeset viewer.