Changeset 1016


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

More testing of conservation.
Checked that momentum is conserved in a steady state scenario

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

Legend:

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

    r1015 r1016  
    830830    wv = domain.quantities['stage'].vertex_values
    831831    zv = domain.quantities['elevation'].vertex_values
    832     hv = wv-zv
     832    hv = wv - zv
    833833
    834834    #Momentums at centroids
     
    842842    #Limit h
    843843    hvbar = h_limiter(domain)   
     844   
     845    #This is how one would make a first order h_limited value
     846    #as in the old balancer (pre 17 Feb 2005):
     847    #from Numeric import zeros, Float
     848    #hvbar = zeros( (len(hc), 3), Float)
     849    #for i in range(3):
     850    #    hvbar[:,i] = hc[:]
    844851
    845852    from shallow_water_ext import balance_deep_and_shallow
    846     #balance_deep_and_shallow(wc, zc, hc, wv, zv, hv,
    847     #                         xmomc, ymomc, xmomv, ymomv)
    848 
    849853    balance_deep_and_shallow(wc, zc, hc, wv, zv, hv, hvbar,
    850854                             xmomc, ymomc, xmomv, ymomv)   
  • inundation/ga/storm_surge/pyvolution/test_shallow_water.py

    r1015 r1016  
    16441644        domain.smooth = False
    16451645        domain.default_order=2
    1646         domain.beta_h = 0
     1646        domain.beta_h = 0.2
    16471647
    16481648        #IC
     
    16951695       
    16961696        #Evolution
    1697         for t in domain.evolve(yieldstep = 0.05, finaltime = 5):
     1697        for t in domain.evolve(yieldstep = 0.05, finaltime = 10):
    16981698            volume =  domain.quantities['stage'].get_integral()         
    16991699            #print t, volume, initial_volume
     
    17291729                if 0.3 <= x[i] < 0.5: 
    17301730                    z[i] = -0.5
    1731                 if 0.5 <= x[i] < 0.7: 
    1732                     z[i] = 0.34 #OK
    1733                     #z[i] = 0.35        #Fails     
     1731                if 0.5 <= x[i] < 0.7:
     1732                    #z[i] = 0.3 #OK with beta == 0.2             
     1733                    z[i] = 0.34 #OK with beta == 0.0
     1734                    #z[i] = 0.35#Fails after 80 timesteps with an error
     1735                                #of the order 1.0e-5   
    17341736                if 0.7 <= x[i]: 
    17351737                    z[i] = x[i]/3                   
     
    17531755        initial_xmom = domain.quantities['xmomentum'].get_integral()     
    17541756       
    1755        
    1756         #Let surface settle according to limiter
    1757         #FIXME: What exactly is the significance of this?
    1758         #Is it a problem that an arbitrary initial condition
    1759         #needs to respect the law of the limiters?
     1757        import copy
     1758        ref_centroid_values =\
     1759                 copy.copy(domain.quantities['stage'].centroid_values)
     1760                               
     1761        #Test limiter by itself
    17601762        domain.distribute_to_vertices_and_edges()
    1761        
    1762        
    1763         #FIXME: At this point study the centroid of individual triangles.
    17641763       
    17651764        #Check that initial limiter doesn't violate cons quan
    17661765        assert allclose (domain.quantities['stage'].get_integral(),
    17671766                         initial_volume)
    1768        
     1767        #NOTE: This would fail if any initial stage was less than the
     1768        #corresponding bed elevation - but that is reasonable.
    17691769                         
    1770                                
    1771         initial_volume = domain.quantities['stage'].get_integral()         
    17721770               
    1773         #print initial_volume
    1774        
    1775         #print initial_xmom
    1776 
    17771771        #Evolution
    17781772        for t in domain.evolve(yieldstep = 0.05, finaltime = 10.0):
    17791773            volume =  domain.quantities['stage'].get_integral()         
     1774
    17801775            #print t, volume, initial_volume
     1776   
    17811777           
     1778            #if not allclose (volume, initial_volume):
     1779            #    print 't==4.05'
     1780            #    for k in range(domain.number_of_elements):
     1781            #       pass
     1782            #       print domain.quantities['stage'].centroid_values[k] -\
     1783            #             ref_centroid_values[k]
     1784           
    17821785            assert allclose (volume, initial_volume)
    1783          
    1784             #FIXME: What would we expect from momentum
    1785             #xmom = domain.quantities['xmomentum'].get_integral()   
    1786             #print xmom
    1787             #assert allclose (xmom, initial_xmom)
    1788        
    1789        
     1786       
     1787
     1788       
     1789       
     1790       
     1791    def test_conservation_5(self):
     1792        """Test that momentum is conserved globally in
     1793        steady state scenario
     1794       
     1795        This one uses a slopy bed, dirichlet and reflective bdries
     1796        """
     1797        from mesh_factory import rectangular
     1798        from shallow_water import Domain, Reflective_boundary,\
     1799             Dirichlet_boundary, Constant_height
     1800        from Numeric import array
     1801
     1802        #Create basic mesh
     1803        points, vertices, boundary = rectangular(6, 6)
     1804
     1805        #Create shallow water domain
     1806        domain = Domain(points, vertices, boundary)
     1807        domain.smooth = False
     1808        domain.default_order=2
     1809
     1810        #IC
     1811        def x_slope(x, y):
     1812            return x/3
     1813
     1814        domain.set_quantity('elevation', x_slope)
     1815        domain.set_quantity('friction', 0)     
     1816        domain.set_quantity('stage', 0.4) #Steady       
     1817       
     1818        # Boundary conditions (reflective everywhere)
     1819        Br = Reflective_boundary(domain)       
     1820        Bleft = Dirichlet_boundary([0.5,0,0])
     1821        Bright = Dirichlet_boundary([0.1,0,0]) 
     1822        domain.set_boundary({'left': Bleft, 'right': Bright,
     1823                             'top': Br, 'bottom': Br})
     1824
     1825        domain.check_integrity()
     1826
     1827        #domain.visualise = True #If you want to take a sticky beak 
     1828       
     1829        initial_volume = domain.quantities['stage'].get_integral()         
     1830        initial_xmom = domain.quantities['xmomentum'].get_integral()     
     1831       
     1832
     1833        #Evolution
     1834        for t in domain.evolve(yieldstep = 0.05, finaltime = 15.0):
     1835            stage =  domain.quantities['stage'].get_integral()         
     1836            xmom = domain.quantities['xmomentum'].get_integral()           
     1837            ymom = domain.quantities['ymomentum'].get_integral()                   
     1838           
     1839            if allclose(t, 6):  #Steady state reached
     1840                steady_xmom = domain.quantities['xmomentum'].get_integral()
     1841                steady_ymom = domain.quantities['ymomentum'].get_integral()
     1842                steady_stage = domain.quantities['stage'].get_integral()               
     1843               
     1844            if t > 6:
     1845                #print '%.2f %14.8f %14.8f' %(t, ymom, steady_ymom)
     1846                assert allclose(xmom, steady_xmom)             
     1847                assert allclose(ymom, steady_ymom)
     1848                assert allclose(stage, steady_stage)           
     1849                                               
     1850           
     1851               
    17901852               
    17911853    def test_second_order_flat_bed_onestep(self):
Note: See TracChangeset for help on using the changeset viewer.