Changeset 1011


Ignore:
Timestamp:
Mar 4, 2005, 6:07:20 PM (20 years ago)
Author:
ole
Message:

Added test for conservation of stage with various beds

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

Legend:

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

    r976 r1011  
    267267
    268268
    269 
    270 
     269    def get_area(self):
     270        """Return total area of mesh
     271        """
     272
     273        return sum(self.areas)         
     274       
  • inundation/ga/storm_surge/pyvolution/mesh.py

    r997 r1011  
    414414        return polygon
    415415       
    416            
    417 
    418        
    419416
    420417    def check_integrity(self):
  • inundation/ga/storm_surge/pyvolution/quantity.py

    r907 r1011  
    568568           
    569569
     570    def get_integral(self):
     571        """Compute the integral of quantity across entire domain
     572        """
     573        integral = 0
     574        for k in range(self.domain.number_of_elements):
     575            area = self.domain.areas[k]
     576            qc = self.centroid_values[k]     
     577            integral += qc*area
     578           
     579        return integral   
     580       
    570581
    571582class Conserved_quantity(Quantity):
  • inundation/ga/storm_surge/pyvolution/test_general_mesh.py

    r715 r1011  
    3434        assert domain.get_vertices([0,4]) == [domain.triangles[0],
    3535                                              domain.triangles[4]]
     36    def test_areas(self):
     37        from mesh_factory import rectangular
     38        from shallow_water import Domain
     39        from Numeric import zeros, Float
     40       
     41        #Create basic mesh
     42        points, vertices, boundary = rectangular(1, 3)
     43        domain = Domain(points, vertices, boundary)
     44
     45        assert domain.get_area() == 1.0         
     46
    3647
    3748    def test_get_unique_vertex_values(self):
  • inundation/ga/storm_surge/pyvolution/test_quantity.py

    r773 r1011  
    1616        a = [0.0, 0.0]
    1717        b = [0.0, 2.0]
    18         c = [2.0,0.0]
     18        c = [2.0, 0.0]
    1919        d = [0.0, 4.0]
    2020        e = [2.0, 2.0]
    21         f = [4.0,0.0]
     21        f = [4.0, 0.0]
    2222
    2323        points = [a, b, c, d, e, f]
     
    196196        assert allclose(quantity.centroid_values,
    197197                        [4.0/3, 8.0/3, 10.0/3, 10.0/3])
     198
     199
     200    def test_integral(self):
     201        quantity = Quantity(self.mesh4)
     202
     203        #Try constants first   
     204        const = 5
     205        quantity.set_values(const, location = 'vertices')       
     206        #print 'Q', quantity.get_integral()
     207               
     208        assert allclose(quantity.get_integral(),
     209                        self.mesh4.get_area() * const)
     210       
     211        #Try with a linear function
     212        def f(x, y):
     213            return x+y
     214
     215        quantity.set_values(f, location = 'vertices')
     216       
     217       
     218        ref_integral = (4.0/3 + 8.0/3 + 10.0/3 + 10.0/3) * 2
     219       
     220        assert allclose (quantity.get_integral(), ref_integral)
     221
    198222
    199223
     
    900924#-------------------------------------------------------------
    901925if __name__ == "__main__":
    902     suite = unittest.makeSuite(TestCase,'test_limiter2')
     926    suite = unittest.makeSuite(TestCase,'test')
    903927    #print "restricted test"
    904928    #suite = unittest.makeSuite(TestCase,'test_set_vertex_values_subset')
  • inundation/ga/storm_surge/pyvolution/test_shallow_water.py

    r1007 r1011  
    15221522
    15231523       
    1524        
     1524    def test_conservation_1(self):
     1525        """Test that stage is conserved globally
     1526       
     1527        This one uses a flat bed, reflective bdries and a suitable
     1528        initial condition
     1529        """
     1530        from mesh_factory import rectangular
     1531        from shallow_water import Domain, Reflective_boundary,\
     1532             Dirichlet_boundary, Constant_height
     1533        from Numeric import array
     1534
     1535        #Create basic mesh
     1536        points, vertices, boundary = rectangular(6, 6)
     1537
     1538        #Create shallow water domain
     1539        domain = Domain(points, vertices, boundary)
     1540        domain.smooth = False
     1541        domain.default_order=1
     1542
     1543        #IC
     1544        def x_slope(x, y):
     1545            return x/3
     1546
     1547        domain.set_quantity('elevation', 0)
     1548        domain.set_quantity('friction', 0)     
     1549        domain.set_quantity('stage', x_slope)   
     1550       
     1551        # Boundary conditions (reflective everywhere)
     1552        Br = Reflective_boundary(domain)
     1553        domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})
     1554
     1555        domain.check_integrity()
     1556
     1557        #domain.visualise = True #If you want to take a sticky beak 
     1558       
     1559        initial_volume = domain.quantities['stage'].get_integral()         
     1560        initial_xmom = domain.quantities['xmomentum'].get_integral()     
     1561       
     1562        #print initial_xmom
     1563
     1564        #Evolution
     1565        for t in domain.evolve(yieldstep = 0.05, finaltime = 5.0):
     1566            volume =  domain.quantities['stage'].get_integral()         
     1567            assert allclose (volume, initial_volume)
     1568         
     1569            #I don't believe that the total momentum should be the same
     1570            #It starts with zero and ends with zero though
     1571            #xmom = domain.quantities['xmomentum'].get_integral()   
     1572            #print xmom
     1573            #assert allclose (xmom, initial_xmom)
     1574       
     1575
     1576       
     1577    def test_conservation_2(self):
     1578        """Test that stage is conserved globally
     1579       
     1580        This one uses a slopy bed, reflective bdries and a suitable
     1581        initial condition
     1582        """
     1583        from mesh_factory import rectangular
     1584        from shallow_water import Domain, Reflective_boundary,\
     1585             Dirichlet_boundary, Constant_height
     1586        from Numeric import array
     1587
     1588        #Create basic mesh
     1589        points, vertices, boundary = rectangular(6, 6)
     1590
     1591        #Create shallow water domain
     1592        domain = Domain(points, vertices, boundary)
     1593        domain.smooth = False
     1594        domain.default_order=1
     1595
     1596        #IC
     1597        def x_slope(x, y):
     1598            return x/3
     1599
     1600        domain.set_quantity('elevation', x_slope)
     1601        domain.set_quantity('friction', 0)     
     1602        domain.set_quantity('stage', 0.4) #Steady       
     1603       
     1604        # Boundary conditions (reflective everywhere)
     1605        Br = Reflective_boundary(domain)
     1606        domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})
     1607
     1608        domain.check_integrity()
     1609
     1610        #domain.visualise = True #If you want to take a sticky beak 
     1611       
     1612        initial_volume = domain.quantities['stage'].get_integral()         
     1613        initial_xmom = domain.quantities['xmomentum'].get_integral()     
     1614       
     1615        #print initial_xmom
     1616
     1617        #Evolution
     1618        for t in domain.evolve(yieldstep = 0.05, finaltime = 5.0):
     1619            volume =  domain.quantities['stage'].get_integral()         
     1620            assert allclose (volume, initial_volume)
     1621         
     1622            #FIXME: What would we expect from momentum
     1623            #xmom = domain.quantities['xmomentum'].get_integral()   
     1624            #print xmom
     1625            #assert allclose (xmom, initial_xmom)
     1626       
     1627       
     1628    def test_conservation_3(self):
     1629        """Test that stage is conserved globally
     1630       
     1631        This one uses a convoluted bed, reflective bdries and a suitable
     1632        initial condition
     1633        """
     1634        from mesh_factory import rectangular
     1635        from shallow_water import Domain, Reflective_boundary,\
     1636             Dirichlet_boundary, Constant_height
     1637        from Numeric import array
     1638
     1639        #Create basic mesh
     1640        points, vertices, boundary = rectangular(6, 6)
     1641
     1642        #Create shallow water domain
     1643        domain = Domain(points, vertices, boundary)
     1644        domain.smooth = False
     1645        domain.default_order=1
     1646
     1647        #IC
     1648        def x_slope(x, y):
     1649            z = 0*x
     1650            for i in range(len(x)):
     1651                if x[i] < 0.3: 
     1652                    z[i] = x[i]/3
     1653                if 0.3 <= x[i] < 0.5: 
     1654                    z[i] = -0.5
     1655                if 0.5 <= x[i] < 0.7: 
     1656                    z[i] = 0.4
     1657                if 0.7 <= x[i]: 
     1658                    z[i] = x[i]/3                   
     1659            return z                               
     1660                                   
     1661                   
     1662
     1663        domain.set_quantity('elevation', x_slope)
     1664        domain.set_quantity('friction', 0)     
     1665        domain.set_quantity('stage', 0.4) #Steady       
     1666       
     1667        # Boundary conditions (reflective everywhere)
     1668        Br = Reflective_boundary(domain)
     1669        domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})
     1670
     1671        domain.check_integrity()
     1672
     1673        #domain.visualise = True #If you want to take a sticky beak 
     1674       
     1675        initial_volume = domain.quantities['stage'].get_integral()         
     1676        initial_xmom = domain.quantities['xmomentum'].get_integral()     
     1677       
     1678       
     1679        #Let surface settle according to limiter
     1680        #FIXME: What exactly is the significance of this?
     1681        #Is it a problem that an arbitrary initial condition
     1682        #needs to respect the law of the limiters?
     1683        domain.distribute_to_vertices_and_edges()
     1684        initial_volume = domain.quantities['stage'].get_integral()         
     1685               
     1686        #print initial_volume
     1687       
     1688        #print initial_xmom
     1689
     1690        #Evolution
     1691        for t in domain.evolve(yieldstep = 0.05, finaltime = 5.0):
     1692            volume =  domain.quantities['stage'].get_integral()         
     1693            #print t, volume, initial_volume
     1694           
     1695            assert allclose (volume, initial_volume)
     1696         
     1697            #FIXME: What would we expect from momentum
     1698            #xmom = domain.quantities['xmomentum'].get_integral()   
     1699            #print xmom
     1700            #assert allclose (xmom, initial_xmom)
     1701       
     1702       
     1703               
    15251704    def test_second_order_flat_bed_onestep(self):
    15261705
Note: See TracChangeset for help on using the changeset viewer.