Changeset 7347


Ignore:
Timestamp:
Aug 9, 2009, 6:04:28 PM (15 years ago)
Author:
ole
Message:

First unit test for variable bed elevation being stored.
I am about to hop on a plane now, but I hope to expand on this test soon.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/shallow_water/test_shallow_water_domain.py

    r7342 r7347  
    66716671            ref_volume += ys * outflow           
    66726672
    6673        
     6673
     6674    def test_variable_elevation(self):           
     6675        """test_variable_elevation
     6676
     6677        This will test that elevagtion van be stored in sww files
     6678        as a time dependent quantity.
     6679       
     6680        It will also chck that storage of other quantities
     6681        can be controlled this way.
     6682        """
     6683
     6684        #---------------------------------------------------------------------
     6685        # Import necessary modules
     6686        #---------------------------------------------------------------------
     6687        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
     6688        from anuga.shallow_water import Domain
     6689        from anuga.shallow_water import Reflective_boundary
     6690        from anuga.shallow_water import Dirichlet_boundary
     6691        from anuga.shallow_water import Time_boundary
     6692
     6693        #---------------------------------------------------------------------
     6694        # Setup computational domain
     6695        #---------------------------------------------------------------------
     6696        length = 8.
     6697        width = 6.
     6698        dx = dy = 1    # Resolution: Length of subdivisions on both axes
     6699       
     6700        inc = 0.05 # Elevation increment
     6701
     6702        points, vertices, boundary = rectangular_cross(int(length/dx),
     6703                                                       int(width/dy),
     6704                                                       len1=length,
     6705                                                       len2=width)
     6706        domain = Domain(points, vertices, boundary)
     6707        domain.set_name('channel_variable_test')  # Output name
     6708        domain.set_quantities_to_be_stored({'elevation': 2,
     6709                                            'stage': 2})
     6710
     6711        #---------------------------------------------------------------------
     6712        # Setup initial conditions
     6713        #---------------------------------------------------------------------
     6714
     6715        def pole_increment(x,y):
     6716            """This provides a small increment to a pole located mid stream
     6717            For use with variable elevation data
     6718            """
     6719           
     6720            z = 0.0*x
     6721
     6722            N = len(x)
     6723            for i in range(N):
     6724                # Pole
     6725                if (x[i] - 4)**2 + (y[i] - 2)**2 < 1.0**2:
     6726                    z[i] += inc
     6727            return z
     6728           
     6729        domain.set_quantity('elevation', 0.0)    # Flat bed initially
     6730        domain.set_quantity('friction', 0.01)    # Constant friction
     6731        domain.set_quantity('stage', 0.0)        # Dry initial condition
     6732
     6733        #------------------------------------------------------------------
     6734        # Setup boundary conditions
     6735        #------------------------------------------------------------------
     6736        Bi = Dirichlet_boundary([0.4, 0, 0])          # Inflow
     6737        Br = Reflective_boundary(domain)              # Solid reflective wall
     6738        Bo = Dirichlet_boundary([-5, 0, 0])           # Outflow
     6739
     6740        domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br})
     6741
     6742        #-------------------------------------------------------------------
     6743        # Evolve system through time
     6744        #-------------------------------------------------------------------
     6745
     6746        for t in domain.evolve(yieldstep=1, finaltime=3.0):
     6747            #print domain.timestepping_statistics()
     6748
     6749            domain.add_quantity('elevation', pole_increment)
     6750       
     6751           
     6752        # Check that quantities have been stored correctly   
     6753        from Scientific.IO.NetCDF import NetCDFFile
     6754        fid = NetCDFFile(domain.get_name() + '.sww')
     6755
     6756        x = fid.variables['x'][:]
     6757        y = fid.variables['y'][:]
     6758        stage = fid.variables['stage'][:]
     6759        elevation = fid.variables['elevation'][:]
     6760        fid.close()
     6761                   
     6762        assert len(stage.shape) == 2
     6763        assert len(elevation.shape) == 2       
     6764       
     6765        M, N = stage.shape
    66746766               
     6767        for i in range(M):
     6768            # For each timestep
     6769            assert num.allclose(max(elevation[i,:]), i * inc)
    66756770       
    66766771    def test_inflow_using_flowline(self):
     
    71287223
    71297224if __name__ == "__main__":
     7225    #suite = unittest.makeSuite(Test_Shallow_Water, 'test_variable_elevation')
    71307226    suite = unittest.makeSuite(Test_Shallow_Water, 'test')
    71317227    runner = unittest.TextTestRunner(verbosity=1)
Note: See TracChangeset for help on using the changeset viewer.