Changeset 1027


Ignore:
Timestamp:
Mar 7, 2005, 5:13:39 PM (19 years ago)
Author:
steve
Message:

Changed test files to define class with a useful name (shows up when using zeus editor)

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

Legend:

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

    r1018 r1027  
    3737
    3838         fileName = tempfile.mktemp(".tsh")
     39         print fileName
    3940         file = open(fileName,"w")
    4041         file.write("4 3 # <vertex #> <x> <y> [attributes]\n \
     
    163164
    164165
    165 
  • inundation/ga/storm_surge/pyvolution/test_shallow_water.py

    r1016 r1027  
    1515    Low speeds at center and edges
    1616    """
    17    
     17
    1818    from math import sqrt, exp, cos, pi
    1919
    2020    x = array(x)
    21     y = array(y)   
     21    y = array(y)
    2222
    2323    N = len(x)
    2424    s = 0*x  #New array
    25    
     25
    2626    for k in range(N):
    27        
     27
    2828        r = sqrt(x[k]**2 + y[k]**2)
    2929
     
    4949
    5050    x = array(x)
    51     y = array(y)   
     51    y = array(y)
    5252
    5353    N = len(x)
    5454    a = 0*x  #New array
    5555
    56     for k in range(N):   
    57         r = sqrt(x[k]**2 + y[k]**2)   
    58    
     56    for k in range(N):
     57        r = sqrt(x[k]**2 + y[k]**2)
     58
    5959        angle = atan(y[k]/x[k])
    6060
     
    6464        #Take normal direction
    6565        angle -= pi/2
    66    
    67         #Ensure positive radians   
     66
     67        #Ensure positive radians
    6868        if angle < 0:
    6969            angle += 2*pi
    7070
    7171        a[k] = angle/pi*180
    72        
     72
    7373    return a
    7474
    75        
    76 class TestCase(unittest.TestCase):
     75
     76class Test_Shallow_Water(unittest.TestCase):
    7777    def setUp(self):
    7878        pass
    79        
     79
    8080    def tearDown(self):
    8181        pass
    8282
    8383    def test_rotate(self):
    84         normal = array([0.0,-1.0])       
     84        normal = array([0.0,-1.0])
    8585
    8686        q = array([1.0,2.0,3.0])
    87      
     87
    8888        r = rotate(q, normal, direction = 1)
    8989        assert r[0] == 1
     
    9191        assert r[2] == 2
    9292
    93         w = rotate(r, normal, direction = -1)       
     93        w = rotate(r, normal, direction = -1)
    9494        assert allclose(w, q)
    9595
     
    114114    def test_flux_constants(self):
    115115        w = 2.0
    116        
    117         normal = array([1.,0])       
     116
     117        normal = array([1.,0])
    118118        ql = array([w, 0, 0])
    119119        qr = array([w, 0, 0])
    120120        zl = zr = 0.
    121121        h = w - (zl+zr)/2
    122        
     122
    123123        flux, max_speed = flux_function(normal, ql, qr, zl, zr)
    124124
    125125        assert allclose(flux, [0., 0.5*g*h**2, 0.])
    126126        assert max_speed == sqrt(g*h)
    127        
     127
    128128    #def test_flux_slope(self):
    129129    #    #FIXME: TODO
    130130    #    w = 2.0
    131     #   
    132     #    normal = array([1.,0])       
     131    #
     132    #    normal = array([1.,0])
    133133    #    ql = array([w, 0, 0])
    134134    #    qr = array([w, 0, 0])
    135135    #    zl = zr = 0.
    136136    #    h = w - (zl+zr)/2
    137     #   
     137    #
    138138    #    flux, max_speed = flux_function(normal, ql, qr, zl, zr)
    139139    #
    140140    #    assert allclose(flux, [0., 0.5*g*h**2, 0.])
    141141    #    assert max_speed == sqrt(g*h)
    142        
     142
    143143
    144144    def test_flux1(self):
    145145        #Use data from previous version of pyvolution
    146         normal = array([1.,0])       
     146        normal = array([1.,0])
    147147        ql = array([-0.2, 2, 3])
    148148        qr = array([-0.2, 2, 3])
     
    156156    def test_flux2(self):
    157157        #Use data from previous version of pyvolution
    158         normal = array([0., -1.])       
     158        normal = array([0., -1.])
    159159        ql = array([-0.075, 2, 3])
    160160        qr = array([-0.075, 2, 3])
     
    166166
    167167    def test_flux3(self):
    168         #Use data from previous version of pyvolution       
    169         normal = array([-sqrt(2)/2, sqrt(2)/2])       
     168        #Use data from previous version of pyvolution
     169        normal = array([-sqrt(2)/2, sqrt(2)/2])
    170170        ql = array([-0.075, 2, 3])
    171171        qr = array([-0.075, 2, 3])
     
    177177
    178178    def test_flux4(self):
    179         #Use data from previous version of pyvolution               
    180         normal = array([-sqrt(2)/2, sqrt(2)/2])       
     179        #Use data from previous version of pyvolution
     180        normal = array([-sqrt(2)/2, sqrt(2)/2])
    181181        ql = array([-0.34319278, 0.10254161, 0.07273855])
    182182        qr = array([-0.30683287, 0.1071986, 0.05930515])
     
    185185
    186186        assert allclose(flux, [-0.04072676, -0.07096636, -0.01604364])
    187         assert allclose(max_speed, 1.31414103233)                               
     187        assert allclose(max_speed, 1.31414103233)
    188188
    189189    def test_sw_domain_simple(self):
     
    196196
    197197        points = [a, b, c, d, e, f]
    198         #bac, bce, ecf, dbe, daf, dae 
     198        #bac, bce, ecf, dbe, daf, dae
    199199        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4], [3,0,5], [3,0,4]]
    200        
    201         domain = Domain(points, vertices)       
     200
     201        domain = Domain(points, vertices)
    202202        domain.check_integrity()
    203203
     
    207207
    208208
    209         assert domain.get_conserved_quantities(0, edge=1) == 0.   
     209        assert domain.get_conserved_quantities(0, edge=1) == 0.
    210210
    211211
    212212    def test_boundary_conditions(self):
    213        
     213
    214214        a = [0.0, 0.0]
    215215        b = [0.0, 2.0]
     
    227227                     (2, 1): 'Second',
    228228                     (3, 1): 'Second',
    229                      (3, 2): 'Third'}                                         
    230                      
     229                     (3, 2): 'Third'}
     230
    231231
    232232        domain = Domain(points, vertices, boundary)
     
    241241
    242242        domain.set_quantity('ymomentum', [[10,10,10], [20,20,20],
    243                                           [30,30,30], [40, 40, 40]])       
     243                                          [30,30,30], [40, 40, 40]])
    244244
    245245
     
    248248        R = Reflective_boundary(domain)
    249249        domain.set_boundary( {'First': D, 'Second': T, 'Third': R})
    250        
     250
    251251        domain.update_boundary()
    252252
     
    254254        assert domain.quantities['stage'].boundary_values[0] == 2.5
    255255        assert domain.quantities['stage'].boundary_values[0] ==\
    256                domain.get_conserved_quantities(0, edge=0)[0] #Reflective (2.5) 
     256               domain.get_conserved_quantities(0, edge=0)[0] #Reflective (2.5)
    257257        assert domain.quantities['stage'].boundary_values[1] == 5. #Dirichlet
    258258        assert domain.quantities['stage'].boundary_values[2] ==\
     
    275275               domain.get_conserved_quantities(3, edge=1)[1] #Transmissive
    276276        assert domain.quantities['xmomentum'].boundary_values[5] == -4.0  #Reflective
    277        
     277
    278278        #Ymomentum
    279279        assert domain.quantities['ymomentum'].boundary_values[0] == -10.0 #Reflective
     
    286286
    287287    def test_boundary_conditionsII(self):
    288        
     288
    289289        a = [0.0, 0.0]
    290290        b = [0.0, 2.0]
     
    303303                     (3, 1): 'Second',
    304304                     (3, 2): 'Third',
    305                      (0, 1): 'Internal'}                                         
    306                      
     305                     (0, 1): 'Internal'}
     306
    307307
    308308        domain = Domain(points, vertices, boundary)
     
    317317
    318318        domain.set_quantity('ymomentum', [[10,10,10], [20,20,20],
    319                                           [30,30,30], [40, 40, 40]])       
     319                                          [30,30,30], [40, 40, 40]])
    320320
    321321
     
    333333        #Do a full triangle and check that fluxes cancel out for
    334334        #the constant stage case
    335        
     335
    336336        a = [0.0, 0.0]
    337337        b = [0.0, 2.0]
     
    344344        #bac, bce, ecf, dbe
    345345        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    346        
    347         domain = Domain(points, vertices)       
     346
     347        domain = Domain(points, vertices)
    348348        domain.set_quantity('stage', [[2,2,2], [2,2,2],
    349349                                      [2,2,2], [2,2,2]])
     
    351351
    352352        assert allclose(domain.neighbours, [[-1,1,-1], [2,3,0], [-1,-1,1],[1,-1,-1]])
    353         assert allclose(domain.neighbour_edges, [[-1,2,-1], [2,0,1], [-1,-1,0],[1,-1,-1]])       
     353        assert allclose(domain.neighbour_edges, [[-1,2,-1], [2,0,1], [-1,-1,0],[1,-1,-1]])
    354354
    355355        zl=zr=0. #Assume flat bed
    356        
     356
    357357        #Flux across right edge of volume 1
    358         normal = domain.get_normal(1,0)       
     358        normal = domain.get_normal(1,0)
    359359        ql = domain.get_conserved_quantities(vol_id=1, edge=0)
    360360        qr = domain.get_conserved_quantities(vol_id=2, edge=2)
    361361        flux0, max_speed = flux_function(normal, ql, qr, zl, zr)
    362        
     362
    363363        #Check that flux seen from other triangles is inverse
    364364        tmp = qr; qr=ql; ql=tmp
    365365        normal = domain.get_normal(2,2)
    366         flux, max_speed = flux_function(normal, ql, qr, zl, zr)       
     366        flux, max_speed = flux_function(normal, ql, qr, zl, zr)
    367367        assert allclose(flux + flux0, 0.)
    368    
     368
    369369        #Flux across upper edge of volume 1
    370         normal = domain.get_normal(1,1)       
     370        normal = domain.get_normal(1,1)
    371371        ql = domain.get_conserved_quantities(vol_id=1, edge=1)
    372372        qr = domain.get_conserved_quantities(vol_id=3, edge=0)
    373373        flux1, max_speed = flux_function(normal, ql, qr, zl, zr)
    374        
     374
    375375        #Check that flux seen from other triangles is inverse
    376376        tmp = qr; qr=ql; ql=tmp
    377377        normal = domain.get_normal(3,0)
    378         flux, max_speed = flux_function(normal, ql, qr, zl, zr)       
     378        flux, max_speed = flux_function(normal, ql, qr, zl, zr)
    379379        assert allclose(flux + flux1, 0.)
    380        
     380
    381381        #Flux across lower left hypotenuse of volume 1
    382         normal = domain.get_normal(1,2)       
     382        normal = domain.get_normal(1,2)
    383383        ql = domain.get_conserved_quantities(vol_id=1, edge=2)
    384384        qr = domain.get_conserved_quantities(vol_id=0, edge=1)
    385385        flux2, max_speed = flux_function(normal, ql, qr, zl, zr)
    386        
     386
    387387        #Check that flux seen from other triangles is inverse
    388388        tmp = qr; qr=ql; ql=tmp
    389389        normal = domain.get_normal(0,1)
    390         flux, max_speed = flux_function(normal, ql, qr, zl, zr)       
     390        flux, max_speed = flux_function(normal, ql, qr, zl, zr)
    391391        assert allclose(flux + flux2, 0.)
    392392
     
    396396        e1 = domain.edgelengths[1, 1]
    397397        e2 = domain.edgelengths[1, 2]
    398        
     398
    399399        assert allclose(e0*flux0+e1*flux1+e2*flux2, 0.)
    400400
     
    410410    def test_compute_fluxes1(self):
    411411        #Use values from previous version
    412        
     412
    413413        a = [0.0, 0.0]
    414414        b = [0.0, 2.0]
     
    421421        #bac, bce, ecf, dbe
    422422        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    423        
     423
    424424        domain = Domain(points, vertices)
    425425        val0 = 2.+2.0/3
     
    427427        val2 = 8.+2.0/3
    428428        val3 = 2.+8.0/3
    429        
     429
    430430        domain.set_quantity('stage', [[val0, val0, val0], [val1, val1, val1],
    431431                                      [val2, val2, val2], [val3, val3, val3]])
     
    435435
    436436        #Flux across right edge of volume 1
    437         normal = domain.get_normal(1,0)       
     437        normal = domain.get_normal(1,0)
    438438        ql = domain.get_conserved_quantities(vol_id=1, edge=0)
    439439        qr = domain.get_conserved_quantities(vol_id=2, edge=2)
     
    444444
    445445        #Flux across upper edge of volume 1
    446         normal = domain.get_normal(1,1)       
     446        normal = domain.get_normal(1,1)
    447447        ql = domain.get_conserved_quantities(vol_id=1, edge=1)
    448448        qr = domain.get_conserved_quantities(vol_id=3, edge=0)
     
    452452
    453453        #Flux across lower left hypotenuse of volume 1
    454         normal = domain.get_normal(1,2)       
     454        normal = domain.get_normal(1,2)
    455455        ql = domain.get_conserved_quantities(vol_id=1, edge=2)
    456456        qr = domain.get_conserved_quantities(vol_id=0, edge=1)
     
    459459        assert allclose(flux2, [9.63942522, -61.59685738, -61.59685738])
    460460        assert allclose(max_speed, 7.22956891292)
    461        
     461
    462462        #Scale, add up and check that compute_fluxes is correct for vol 1
    463463        e0 = domain.edgelengths[1, 0]
     
    487487                        [-69.68888889, -166.6, 69.68888889, 0])
    488488        assert allclose(domain.quantities['ymomentum'].explicit_update,
    489                         [-69.68888889, -35.93333333, 0., 69.68888889])       
    490 
    491        
     489                        [-69.68888889, -35.93333333, 0., 69.68888889])
     490
     491
    492492        #assert allclose(domain.quantities[name].explicit_update
    493493
    494        
    495        
     494
     495
    496496
    497497
    498498    def test_compute_fluxes2(self):
    499499        #Random values, incl momentum
    500        
     500
    501501        a = [0.0, 0.0]
    502502        b = [0.0, 2.0]
     
    509509        #bac, bce, ecf, dbe
    510510        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    511        
     511
    512512        domain = Domain(points, vertices)
    513513        val0 = 2.+2.0/3
     
    519519
    520520        domain.set_quantity('elevation', zl*ones( (4,3) ))
    521        
    522        
     521
     522
    523523        domain.set_quantity('stage', [[val0, val0-1, val0-2],
    524524                                      [val1, val1+1, val1],
     
    532532        domain.set_quantity('ymomentum',
    533533                            [[1, -1, 0], [0, -3, 2],
    534                              [0, 1, 0], [-1, 2, 2]])               
    535 
    536        
     534                             [0, 1, 0], [-1, 2, 2]])
     535
     536
    537537        domain.check_integrity()
    538538
     
    540540
    541541        #Flux across right edge of volume 1
    542         normal = domain.get_normal(1,0)       
     542        normal = domain.get_normal(1,0)
    543543        ql = domain.get_conserved_quantities(vol_id=1, edge=0)
    544544        qr = domain.get_conserved_quantities(vol_id=2, edge=2)
     
    546546
    547547        #Flux across upper edge of volume 1
    548         normal = domain.get_normal(1,1)       
     548        normal = domain.get_normal(1,1)
    549549        ql = domain.get_conserved_quantities(vol_id=1, edge=1)
    550550        qr = domain.get_conserved_quantities(vol_id=3, edge=0)
     
    552552
    553553        #Flux across lower left hypotenuse of volume 1
    554         normal = domain.get_normal(1,2)       
     554        normal = domain.get_normal(1,2)
    555555        ql = domain.get_conserved_quantities(vol_id=1, edge=2)
    556556        qr = domain.get_conserved_quantities(vol_id=0, edge=1)
    557557        flux2, max_speed = flux_function(normal, ql, qr, zl, zr)
    558        
     558
    559559        #Scale, add up and check that compute_fluxes is correct for vol 1
    560560        e0 = domain.edgelengths[1, 0]
     
    564564        total_flux = -(e0*flux0+e1*flux1+e2*flux2)/domain.areas[1]
    565565
    566        
     566
    567567        domain.compute_fluxes()
    568568        for i, name in enumerate(['stage', 'xmomentum', 'ymomentum']):
    569569            assert allclose(total_flux[i],
    570                             domain.quantities[name].explicit_update[1])       
     570                            domain.quantities[name].explicit_update[1])
    571571        #assert allclose(total_flux, domain.explicit_update[1,:])
    572        
     572
    573573
    574574    def test_compute_fluxes3(self):
    575575        #Random values, incl momentum
    576        
     576
    577577        a = [0.0, 0.0]
    578578        b = [0.0, 2.0]
     
    585585        #bac, bce, ecf, dbe
    586586        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    587        
     587
    588588        domain = Domain(points, vertices)
    589589        val0 = 2.+2.0/3
     
    594594        zl=zr=-3.75 #Assume constant bed (must be less than stage)
    595595        domain.set_quantity('elevation', zl*ones( (4,3) ))
    596        
    597        
     596
     597
    598598        domain.set_quantity('stage', [[val0, val0-1, val0-2],
    599599                                      [val1, val1+1, val1],
     
    607607        domain.set_quantity('ymomentum',
    608608                            [[1, -1, 0], [0, -3, 2],
    609                              [0, 1, 0], [-1, 2, 2]])               
    610 
    611        
     609                             [0, 1, 0], [-1, 2, 2]])
     610
     611
    612612        domain.check_integrity()
    613613
     
    615615
    616616        #Flux across right edge of volume 1
    617         normal = domain.get_normal(1,0)       
     617        normal = domain.get_normal(1,0)
    618618        ql = domain.get_conserved_quantities(vol_id=1, edge=0)
    619619        qr = domain.get_conserved_quantities(vol_id=2, edge=2)
     
    621621
    622622        #Flux across upper edge of volume 1
    623         normal = domain.get_normal(1,1)       
     623        normal = domain.get_normal(1,1)
    624624        ql = domain.get_conserved_quantities(vol_id=1, edge=1)
    625625        qr = domain.get_conserved_quantities(vol_id=3, edge=0)
     
    627627
    628628        #Flux across lower left hypotenuse of volume 1
    629         normal = domain.get_normal(1,2)       
     629        normal = domain.get_normal(1,2)
    630630        ql = domain.get_conserved_quantities(vol_id=1, edge=2)
    631631        qr = domain.get_conserved_quantities(vol_id=0, edge=1)
    632632        flux2, max_speed = flux_function(normal, ql, qr, zl, zr)
    633        
     633
    634634        #Scale, add up and check that compute_fluxes is correct for vol 1
    635635        e0 = domain.edgelengths[1, 0]
     
    638638
    639639        total_flux = -(e0*flux0+e1*flux1+e2*flux2)/domain.areas[1]
    640        
     640
    641641        domain.compute_fluxes()
    642642        for i, name in enumerate(['stage', 'xmomentum', 'ymomentum']):
     
    647647
    648648    def test_catching_negative_heights(self):
    649        
     649
    650650        a = [0.0, 0.0]
    651651        b = [0.0, 2.0]
     
    658658        #bac, bce, ecf, dbe
    659659        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    660        
     660
    661661        domain = Domain(points, vertices)
    662662        val0 = 2.+2.0/3
     
    681681
    682682
    683     #####################################################   
     683    #####################################################
    684684    def test_initial_condition(self):
    685685        """Test that initial condition is output at time == 0
     
    688688        from config import g
    689689        import copy
    690        
     690
    691691        a = [0.0, 0.0]
    692692        b = [0.0, 2.0]
     
    699699        #bac, bce, ecf, dbe
    700700        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    701        
     701
    702702        domain = Domain(points, vertices)
    703703
    704         #Set up for a gradient of (3,0) at mid triangle         
     704        #Set up for a gradient of (3,0) at mid triangle
    705705        def slope(x, y):
    706706            return 3*x
     
    725725            else:
    726726                assert not allclose(stage, initial_stage)
    727                
    728      
    729        
    730 
    731     #####################################################   
     727
     728
     729
     730
     731    #####################################################
    732732    def test_gravity(self):
    733733        #Assuming no friction
    734734
    735735        from config import g
    736        
     736
    737737        a = [0.0, 0.0]
    738738        b = [0.0, 2.0]
     
    745745        #bac, bce, ecf, dbe
    746746        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    747        
     747
    748748        domain = Domain(points, vertices)
    749749
    750         #Set up for a gradient of (3,0) at mid triangle         
     750        #Set up for a gradient of (3,0) at mid triangle
    751751        def slope(x, y):
    752752            return 3*x
     
    762762            assert allclose(domain.quantities[name].explicit_update, 0)
    763763            assert allclose(domain.quantities[name].semi_implicit_update, 0)
    764            
    765         domain.compute_forcing_terms()                                   
     764
     765        domain.compute_forcing_terms()
    766766
    767767        assert allclose(domain.quantities['stage'].explicit_update, 0)
    768768        assert allclose(domain.quantities['xmomentum'].explicit_update, -g*h*3)
    769769        assert allclose(domain.quantities['ymomentum'].explicit_update, 0)
    770        
    771        
     770
     771
    772772    def test_manning_friction(self):
    773773        from config import g
    774        
     774
    775775        a = [0.0, 0.0]
    776776        b = [0.0, 2.0]
     
    783783        #bac, bce, ecf, dbe
    784784        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    785        
     785
    786786        domain = Domain(points, vertices)
    787787
    788         #Set up for a gradient of (3,0) at mid triangle         
     788        #Set up for a gradient of (3,0) at mid triangle
    789789        def slope(x, y):
    790790            return 3*x
     
    797797        domain.set_quantity('elevation', slope)
    798798        domain.set_quantity('stage', stage)
    799         domain.set_quantity('friction', eta)       
     799        domain.set_quantity('friction', eta)
    800800
    801801        for name in domain.conserved_quantities:
    802802            assert allclose(domain.quantities[name].explicit_update, 0)
    803803            assert allclose(domain.quantities[name].semi_implicit_update, 0)
    804            
    805         domain.compute_forcing_terms()                                   
     804
     805        domain.compute_forcing_terms()
    806806
    807807        assert allclose(domain.quantities['stage'].explicit_update, 0)
     
    811811        assert allclose(domain.quantities['stage'].semi_implicit_update, 0)
    812812        assert allclose(domain.quantities['xmomentum'].semi_implicit_update, 0)
    813         assert allclose(domain.quantities['ymomentum'].semi_implicit_update, 0)       
     813        assert allclose(domain.quantities['ymomentum'].semi_implicit_update, 0)
    814814
    815815        #Create some momentum for friction to work with
     
    817817        S = -g * eta**2 / h**(7.0/3)
    818818
    819         domain.compute_forcing_terms()                                   
     819        domain.compute_forcing_terms()
    820820        assert allclose(domain.quantities['stage'].semi_implicit_update, 0)
    821821        assert allclose(domain.quantities['xmomentum'].semi_implicit_update, S)
    822         assert allclose(domain.quantities['ymomentum'].semi_implicit_update, 0)       
    823 
    824         #A more complex example 
     822        assert allclose(domain.quantities['ymomentum'].semi_implicit_update, 0)
     823
     824        #A more complex example
    825825        domain.quantities['stage'].semi_implicit_update[:] = 0.0
    826826        domain.quantities['xmomentum'].semi_implicit_update[:] = 0.0
    827         domain.quantities['ymomentum'].semi_implicit_update[:] = 0.0       
    828        
     827        domain.quantities['ymomentum'].semi_implicit_update[:] = 0.0
     828
    829829        domain.set_quantity('xmomentum', 3)
    830         domain.set_quantity('ymomentum', 4)       
     830        domain.set_quantity('ymomentum', 4)
    831831
    832832        S = -g * eta**2 * 5 / h**(7.0/3)
     
    837837        assert allclose(domain.quantities['stage'].semi_implicit_update, 0)
    838838        assert allclose(domain.quantities['xmomentum'].semi_implicit_update, 3*S)
    839         assert allclose(domain.quantities['ymomentum'].semi_implicit_update, 4*S)       
     839        assert allclose(domain.quantities['ymomentum'].semi_implicit_update, 4*S)
    840840
    841841    def test_constant_wind_stress(self):
     
    854854        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    855855
    856        
     856
    857857        domain = Domain(points, vertices)
    858858
     
    860860        domain.set_quantity('elevation', 0)
    861861        domain.set_quantity('stage', 1.0)
    862         domain.set_quantity('friction', 0)       
     862        domain.set_quantity('friction', 0)
    863863
    864864        Br = Reflective_boundary(domain)
     
    870870        domain.forcing_terms = []
    871871        domain.forcing_terms.append( Wind_stress(s, phi) )
    872        
     872
    873873        domain.compute_forcing_terms()
    874874
    875875
    876876        const = eta_w*rho_a/rho_w
    877        
     877
    878878        #Convert to radians
    879879        phi = phi*pi/180
    880        
     880
    881881        #Compute velocity vector (u, v)
    882882        u = s*cos(phi)
     
    911911        domain.set_quantity('elevation', 0)
    912912        domain.set_quantity('stage', 1.0)
    913         domain.set_quantity('friction', 0)       
     913        domain.set_quantity('friction', 0)
    914914
    915915        Br = Reflective_boundary(domain)
     
    924924        domain.forcing_terms = []
    925925        domain.forcing_terms.append( Wind_stress(s = speed, phi = angle) )
    926        
     926
    927927        domain.compute_forcing_terms()
    928928
    929929        #Compute reference solution
    930930        const = eta_w*rho_a/rho_w
    931        
     931
    932932        N = domain.number_of_elements
    933933
     
    939939        s_vec = speed(t,x,y)
    940940        phi_vec = angle(t,x,y)
    941        
     941
    942942
    943943        for k in range(N):
     
    945945            phi = phi_vec[k]*pi/180
    946946            s = s_vec[k]
    947        
     947
    948948            #Compute velocity vector (u, v)
    949949            u = s*cos(phi)
     
    966966        from util import file_function
    967967        import time
    968        
     968
    969969
    970970        a = [0.0, 0.0]
     
    984984        domain.set_quantity('elevation', 0)
    985985        domain.set_quantity('stage', 1.0)
    986         domain.set_quantity('friction', 0)       
     986        domain.set_quantity('friction', 0)
    987987
    988988        Br = Reflective_boundary(domain)
     
    995995        #Take x=1 and y=0
    996996        filename = 'test_windstress_from_file.txt'
    997         start = time.mktime(time.strptime('2000', '%Y'))       
     997        start = time.mktime(time.strptime('2000', '%Y'))
    998998        fid = open(filename, 'w')
    999999        dt = 1  #One second interval
     
    10061006                                      angle(t,[1],[0])[0]))
    10071007            t += dt
    1008    
     1008
    10091009        fid.close()
    10101010
    10111011        #Setup wind stress
    10121012        F = file_function(filename)
    1013         W = Wind_stress(F) 
     1013        W = Wind_stress(F)
    10141014        domain.forcing_terms = []
    10151015        domain.forcing_terms.append(W)
    1016        
     1016
    10171017        domain.compute_forcing_terms()
    10181018
    10191019        #Compute reference solution
    10201020        const = eta_w*rho_a/rho_w
    1021        
     1021
    10221022        N = domain.number_of_elements
    10231023
     
    10261026        s = speed(t,[1],[0])[0]
    10271027        phi = angle(t,[1],[0])[0]
    1028        
     1028
    10291029        #Convert to radians
    10301030        phi = phi*pi/180
    10311031
    1032        
     1032
    10331033        #Compute velocity vector (u, v)
    10341034        u = s*cos(phi)
     
    10491049        are wrong - e.g. returns a scalar
    10501050        """
    1051        
     1051
    10521052        from config import rho_a, rho_w, eta_w
    10531053        from math import pi, cos, sin, sqrt
     
    10691069        domain.set_quantity('elevation', 0)
    10701070        domain.set_quantity('stage', 1.0)
    1071         domain.set_quantity('friction', 0)       
     1071        domain.set_quantity('friction', 0)
    10721072
    10731073        Br = Reflective_boundary(domain)
     
    10881088            msg = 'Should have raised exception'
    10891089            raise msg
    1090        
     1090
    10911091
    10921092        try:
     
    10981098            msg = 'Should have raised exception'
    10991099            raise msg
    1100        
     1100
    11011101        try:
    11021102            domain.forcing_terms.append(Wind_stress(s = speed,
     
    11071107            msg = 'Should have raised exception'
    11081108            raise msg
    1109        
     1109
    11101110
    11111111    #####################################################
    11121112    def test_first_order_extrapolator_const_z(self):
    1113        
     1113
    11141114        a = [0.0, 0.0]
    11151115        b = [0.0, 2.0]
     
    11221122        #bac, bce, ecf, dbe
    11231123        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    1124        
     1124
    11251125        domain = Domain(points, vertices)
    11261126        val0 = 2.+2.0/3
     
    11291129        val3 = 2.+8.0/3
    11301130
    1131         zl=zr=-3.75 #Assume constant bed (must be less than stage)       
     1131        zl=zr=-3.75 #Assume constant bed (must be less than stage)
    11321132        domain.set_quantity('elevation', zl*ones( (4,3) ))
    11331133        domain.set_quantity('stage', [[val0, val0-1, val0-2],
     
    11431143        #Check that centroid values were distributed to vertices
    11441144        C = domain.quantities['stage'].centroid_values
    1145         for i in range(3): 
     1145        for i in range(3):
    11461146            assert allclose( domain.quantities['stage'].vertex_values[:,i], C)
    1147        
     1147
    11481148
    11491149    def test_first_order_limiter_variable_z(self):
     
    11511151        from Numeric import alltrue, greater_equal
    11521152        from config import epsilon
    1153        
     1153
    11541154        a = [0.0, 0.0]
    11551155        b = [0.0, 2.0]
     
    11621162        #bac, bce, ecf, dbe
    11631163        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    1164        
     1164
    11651165        domain = Domain(points, vertices)
    11661166        val0 = 2.+2.0/3
     
    11771177
    11781178        E = domain.quantities['elevation'].vertex_values
    1179         L = domain.quantities['stage'].vertex_values       
    1180 
    1181        
     1179        L = domain.quantities['stage'].vertex_values
     1180
     1181
    11821182        #Check that some stages are not above elevation (within eps)
    11831183        #- so that the limiter has something to work with
    1184         assert not alltrue(alltrue(greater_equal(L,E-epsilon)))               
     1184        assert not alltrue(alltrue(greater_equal(L,E-epsilon)))
    11851185
    11861186        domain.order = 1
    1187         domain.distribute_to_vertices_and_edges()                           
     1187        domain.distribute_to_vertices_and_edges()
    11881188
    11891189        #Check that all stages are above elevation (within eps)
     
    11911191
    11921192
    1193     #####################################################   
     1193    #####################################################
    11941194    def test_distribute_basic(self):
    1195         #Using test data generated by pyvolution-2 
     1195        #Using test data generated by pyvolution-2
    11961196        #Assuming no friction and flat bed (0.0)
    1197        
     1197
    11981198        a = [0.0, 0.0]
    11991199        b = [0.0, 2.0]
     
    12061206        #bac, bce, ecf, dbe
    12071207        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    1208        
     1208
    12091209        domain = Domain(points, vertices)
    1210        
     1210
    12111211        val0 = 2.
    12121212        val1 = 4.
     
    12161216        domain.set_quantity('stage', [val0, val1, val2, val3], 'centroids')
    12171217        L = domain.quantities['stage'].vertex_values
    1218        
     1218
    12191219        #First order
    1220         domain.order = 1       
     1220        domain.order = 1
    12211221        domain.distribute_to_vertices_and_edges()
    12221222        assert allclose(L[1], val1)
    1223        
     1223
    12241224        #Second order
    1225         domain.order = 2       
     1225        domain.order = 2
    12261226        domain.distribute_to_vertices_and_edges()
    12271227        assert allclose(L[1], [2.2, 4.9, 4.9])
    1228                
    1229 
    1230        
    1231     def test_distribute_away_from_bed(self):           
    1232         #Using test data generated by pyvolution-2 
     1228
     1229
     1230
     1231    def test_distribute_away_from_bed(self):
     1232        #Using test data generated by pyvolution-2
    12331233        #Assuming no friction and flat bed (0.0)
    1234        
     1234
    12351235        a = [0.0, 0.0]
    12361236        b = [0.0, 2.0]
     
    12431243        #bac, bce, ecf, dbe
    12441244        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    1245        
     1245
    12461246        domain = Domain(points, vertices)
    1247         L = domain.quantities['stage'].vertex_values   
    1248        
     1247        L = domain.quantities['stage'].vertex_values
     1248
    12491249        def stage(x,y):
    12501250            return x**2
    1251        
     1251
    12521252        domain.set_quantity('stage', stage, 'centroids')
    1253        
    1254         a, b = domain.quantities['stage'].compute_gradients()           
     1253
     1254        a, b = domain.quantities['stage'].compute_gradients()
    12551255        assert allclose(a[1], 3.33333334)
    12561256        assert allclose(b[1], 0.0)
    1257        
     1257
    12581258        domain.order = 1
    12591259        domain.distribute_to_vertices_and_edges()
    12601260        assert allclose(L[1], 1.77777778)
    1261        
     1261
    12621262        domain.order = 2
    12631263        domain.distribute_to_vertices_and_edges()
    1264         assert allclose(L[1], [0.57777777, 2.37777778, 2.37777778])     
    1265 
    1266 
    1267        
    1268     def test_distribute_away_from_bed1(self):           
    1269         #Using test data generated by pyvolution-2 
     1264        assert allclose(L[1], [0.57777777, 2.37777778, 2.37777778])
     1265
     1266
     1267
     1268    def test_distribute_away_from_bed1(self):
     1269        #Using test data generated by pyvolution-2
    12701270        #Assuming no friction and flat bed (0.0)
    1271        
     1271
    12721272        a = [0.0, 0.0]
    12731273        b = [0.0, 2.0]
     
    12801280        #bac, bce, ecf, dbe
    12811281        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    1282        
     1282
    12831283        domain = Domain(points, vertices)
    1284         L = domain.quantities['stage'].vertex_values   
    1285        
     1284        L = domain.quantities['stage'].vertex_values
     1285
    12861286        def stage(x,y):
    12871287            return x**4+y**2
    1288        
     1288
    12891289        domain.set_quantity('stage', stage, 'centroids')
    1290         #print domain.quantities['stage'].centroid_values               
    1291        
    1292         a, b = domain.quantities['stage'].compute_gradients()           
     1290        #print domain.quantities['stage'].centroid_values
     1291
     1292        a, b = domain.quantities['stage'].compute_gradients()
    12931293        assert allclose(a[1], 25.18518519)
    12941294        assert allclose(b[1], 3.33333333)
    1295        
     1295
    12961296        domain.order = 1
    12971297        domain.distribute_to_vertices_and_edges()
    12981298        assert allclose(L[1], 4.9382716)
    1299        
     1299
    13001300        domain.order = 2
    13011301        domain.distribute_to_vertices_and_edges()
    1302         assert allclose(L[1], [1.07160494, 6.46058131, 7.28262855])     
    1303 
    1304    
    1305    
     1302        assert allclose(L[1], [1.07160494, 6.46058131, 7.28262855])
     1303
     1304
     1305
    13061306    def test_distribute_near_bed(self):
    1307         #Using test data generated by pyvolution-2 
     1307        #Using test data generated by pyvolution-2
    13081308        #Assuming no friction and flat bed (0.0)
    13091309
     
    13181318        #bac, bce, ecf, dbe
    13191319        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    1320        
     1320
    13211321        domain = Domain(points, vertices)
    13221322
    13231323
    1324         #Set up for a gradient of (3,0) at mid triangle         
     1324        #Set up for a gradient of (3,0) at mid triangle
    13251325        def slope(x, y):
    13261326            return 10*x
     
    13331333        domain.set_quantity('stage', stage, 'centroids')
    13341334
    1335         #print domain.quantities['elevation'].centroid_values   
     1335        #print domain.quantities['elevation'].centroid_values
    13361336        #print domain.quantities['stage'].centroid_values
    1337        
     1337
    13381338        E = domain.quantities['elevation'].vertex_values
    13391339        L = domain.quantities['stage'].vertex_values
    13401340
    13411341        #print E
    1342         domain.order = 1       
     1342        domain.order = 1
    13431343        domain.distribute_to_vertices_and_edges()
    13441344        ##assert allclose(L[1], [0.19999999, 20.05, 20.05])
    13451345        assert allclose(L[1], [0.1, 20.1, 20.1])
    1346        
    1347         domain.order = 2       
     1346
     1347        domain.order = 2
    13481348        domain.distribute_to_vertices_and_edges()
    13491349        assert allclose(L[1], [0.1, 20.1, 20.1])
    13501350
    13511351    def test_distribute_near_bed1(self):
    1352         #Using test data generated by pyvolution-2 
     1352        #Using test data generated by pyvolution-2
    13531353        #Assuming no friction and flat bed (0.0)
    13541354
     
    13631363        #bac, bce, ecf, dbe
    13641364        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    1365        
     1365
    13661366        domain = Domain(points, vertices)
    13671367
    13681368
    1369         #Set up for a gradient of (3,0) at mid triangle         
     1369        #Set up for a gradient of (3,0) at mid triangle
    13701370        def slope(x, y):
    13711371            return x**4+y**2
     
    13781378        domain.set_quantity('stage', stage)
    13791379
    1380         #print domain.quantities['elevation'].centroid_values   
     1380        #print domain.quantities['elevation'].centroid_values
    13811381        #print domain.quantities['stage'].centroid_values
    1382        
     1382
    13831383        E = domain.quantities['elevation'].vertex_values
    13841384        L = domain.quantities['stage'].vertex_values
     
    13881388        domain.distribute_to_vertices_and_edges()
    13891389        ##assert allclose(L[1], [4.19999999, 16.07142857, 20.02857143])
    1390         assert allclose(L[1], [4.1, 16.1, 20.1])       
    1391 
    1392         domain.order = 2       
     1390        assert allclose(L[1], [4.1, 16.1, 20.1])
     1391
     1392        domain.order = 2
    13931393        domain.distribute_to_vertices_and_edges()
    13941394        assert allclose(L[1], [4.1, 16.1, 20.1])
    13951395
    1396  
     1396
    13971397
    13981398    def test_second_order_distribute_real_data(self):
    1399         #Using test data generated by pyvolution-2 
     1399        #Using test data generated by pyvolution-2
    14001400        #Assuming no friction and flat bed (0.0)
    14011401
     
    14111411        #bae, efb, cbf, feg
    14121412        vertices = [ [1,0,4], [4,5,1], [2,1,5], [5,4,6]]
    1413        
     1413
    14141414        domain = Domain(points, vertices)
    14151415
     
    14181418
    14191419        domain.set_quantity('elevation', slope)
    1420         domain.set_quantity('stage', 
    1421                             [0.01298164, 0.00365611, 0.01440365, -0.0381856437096], 
     1420        domain.set_quantity('stage',
     1421                            [0.01298164, 0.00365611, 0.01440365, -0.0381856437096],
    14221422                            'centroids')
    1423         domain.set_quantity('xmomentum', 
     1423        domain.set_quantity('xmomentum',
    14241424                            [0.00670439, 0.01263789, 0.00647805, 0.0178180740668],
    14251425                            'centroids')
    1426         domain.set_quantity('ymomentum',                           
     1426        domain.set_quantity('ymomentum',
    14271427                            [-7.23510980e-004, -6.30413883e-005, 6.30413883e-005, 0.000200907255866],
    1428                             'centroids')                           
    1429        
     1428                            'centroids')
     1429
    14301430        E = domain.quantities['elevation'].vertex_values
    14311431        L = domain.quantities['stage'].vertex_values
    1432         X = domain.quantities['xmomentum'].vertex_values       
    1433         Y = domain.quantities['ymomentum'].vertex_values               
     1432        X = domain.quantities['xmomentum'].vertex_values
     1433        Y = domain.quantities['ymomentum'].vertex_values
    14341434
    14351435        #print E
    14361436        domain.order = 2
    1437         domain.beta_h = 0.0 #Use first order in h-limiter       
     1437        domain.beta_h = 0.0 #Use first order in h-limiter
    14381438        domain.distribute_to_vertices_and_edges()
    14391439
     
    14461446        assert allclose(Y[1,:], [-0.000117062180693, 7.94434448109e-005, -0.000151505429018])
    14471447
    1448        
    1449        
     1448
     1449
    14501450    def test_balance_deep_and_shallow(self):
    14511451        """Test that balanced limiters preserve conserved quantites.
    14521452        """
    14531453        import copy
    1454        
     1454
    14551455        a = [0.0, 0.0]
    14561456        b = [0.0, 2.0]
     
    14651465        elements = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4] ]
    14661466
    1467         mesh = Domain(points, elements)       
     1467        mesh = Domain(points, elements)
    14681468        mesh.check_integrity()
    14691469
     
    14711471        mesh.set_quantity('stage', [[3,0,3], [2,2,6], [5,3,8], [8,3,5]])
    14721472        mesh.set_quantity('elevation', 0) #Flat bed
    1473         stage = mesh.quantities['stage']       
    1474        
     1473        stage = mesh.quantities['stage']
     1474
    14751475        ref_centroid_values = copy.copy(stage.centroid_values[:]) #Copy
    1476    
     1476
    14771477        #Limit
    14781478        mesh.distribute_to_vertices_and_edges()
     
    14831483            assert allclose (ref_centroid_values[k],
    14841484                             sum(stage.vertex_values[k,:])/3)
    1485        
     1485
    14861486
    14871487        #Now try with a non-flat bed - closely hugging initial stage in places
    14881488        #This will create alphas in the range [0, 0.478260, 1]
    14891489        mesh.set_quantity('stage', [[3,0,3], [2,2,6], [5,3,8], [8,3,5]])
    1490         mesh.set_quantity('elevation', [[0,0,0], 
    1491                                         [1.8,1.9,5.9], 
    1492                                         [4.6,0,0], 
     1490        mesh.set_quantity('elevation', [[0,0,0],
     1491                                        [1.8,1.9,5.9],
     1492                                        [4.6,0,0],
    14931493                                        [0,2,4]])
    1494         stage = mesh.quantities['stage']       
    1495        
     1494        stage = mesh.quantities['stage']
     1495
    14961496        ref_centroid_values = copy.copy(stage.centroid_values[:]) #Copy
    1497         ref_vertex_values = copy.copy(stage.vertex_values[:]) #Copy     
    1498    
     1497        ref_vertex_values = copy.copy(stage.vertex_values[:]) #Copy
     1498
    14991499        #Limit
    15001500        mesh.distribute_to_vertices_and_edges()
    15011501
    1502        
     1502
    15031503        #Assert that all vertex quantities have changed
    15041504        for k in range(mesh.number_of_elements):
    1505             #print ref_vertex_values[k,:], stage.vertex_values[k,:]     
    1506             assert not allclose (ref_vertex_values[k,:], stage.vertex_values[k,:])             
     1505            #print ref_vertex_values[k,:], stage.vertex_values[k,:]
     1506            assert not allclose (ref_vertex_values[k,:], stage.vertex_values[k,:])
    15071507        #and assert that quantities are still conserved
    15081508        from Numeric import sum
     
    15101510            assert allclose (ref_centroid_values[k],
    15111511                             sum(stage.vertex_values[k,:])/3)
    1512        
    1513    
     1512
     1513
    15141514        #Also check that Python and C version produce the same
    15151515        assert allclose (stage.vertex_values,
     
    15181518                          [6.93333333, 4.53333333, 4.53333333],
    15191519                          [5.33333333, 5.33333333, 5.33333333]])
    1520                          
    1521                          
    1522 
    1523        
     1520
     1521
     1522
     1523
    15241524    def test_conservation_1(self):
    15251525        """Test that stage is conserved globally
    1526        
    1527         This one uses a flat bed, reflective bdries and a suitable 
     1526
     1527        This one uses a flat bed, reflective bdries and a suitable
    15281528        initial condition
    15291529        """
     
    15461546
    15471547        domain.set_quantity('elevation', 0)
    1548         domain.set_quantity('friction', 0)     
    1549         domain.set_quantity('stage', x_slope)   
    1550        
     1548        domain.set_quantity('friction', 0)
     1549        domain.set_quantity('stage', x_slope)
     1550
    15511551        # Boundary conditions (reflective everywhere)
    15521552        Br = Reflective_boundary(domain)
     
    15551555        domain.check_integrity()
    15561556
    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        
     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
    15621562        #print initial_xmom
    15631563
    15641564        #Evolution
    15651565        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          
     1566            volume =  domain.quantities['stage'].get_integral()
     1567            assert allclose (volume, initial_volume)
     1568
    15691569            #I don't believe that the total momentum should be the same
    15701570            #It starts with zero and ends with zero though
    1571             #xmom = domain.quantities['xmomentum'].get_integral()   
     1571            #xmom = domain.quantities['xmomentum'].get_integral()
    15721572            #print xmom
    1573             #assert allclose (xmom, initial_xmom) 
    1574        
    1575 
    1576        
     1573            #assert allclose (xmom, initial_xmom)
     1574
     1575
     1576
    15771577    def test_conservation_2(self):
    15781578        """Test that stage is conserved globally
    1579        
    1580         This one uses a slopy bed, reflective bdries and a suitable 
     1579
     1580        This one uses a slopy bed, reflective bdries and a suitable
    15811581        initial condition
    15821582        """
     
    15991599
    16001600        domain.set_quantity('elevation', x_slope)
    1601         domain.set_quantity('friction', 0)     
    1602         domain.set_quantity('stage', 0.4) #Steady       
    1603        
     1601        domain.set_quantity('friction', 0)
     1602        domain.set_quantity('stage', 0.4) #Steady
     1603
    16041604        # Boundary conditions (reflective everywhere)
    16051605        Br = Reflective_boundary(domain)
     
    16081608        domain.check_integrity()
    16091609
    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        
     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
    16151615        #print initial_xmom
    16161616
    16171617        #Evolution
    16181618        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          
     1619            volume =  domain.quantities['stage'].get_integral()
     1620            assert allclose (volume, initial_volume)
     1621
    16221622            #FIXME: What would we expect from momentum
    1623             #xmom = domain.quantities['xmomentum'].get_integral()   
     1623            #xmom = domain.quantities['xmomentum'].get_integral()
    16241624            #print xmom
    1625             #assert allclose (xmom, initial_xmom) 
    1626 
    1627            
     1625            #assert allclose (xmom, initial_xmom)
     1626
     1627
    16281628    def test_conservation_3(self):
    16291629        """Test that stage is conserved globally
    1630        
    1631         This one uses a larger grid, convoluted bed, reflective bdries and a suitable 
     1630
     1631        This one uses a larger grid, convoluted bed, reflective bdries and a suitable
    16321632        initial condition
    16331633        """
     
    16501650            z = 0*x
    16511651            for i in range(len(x)):
    1652                 if x[i] < 0.3: 
     1652                if x[i] < 0.3:
    16531653                    z[i] = x[i]/3
    1654                 if 0.3 <= x[i] < 0.5: 
     1654                if 0.3 <= x[i] < 0.5:
    16551655                    z[i] = -0.5
    1656                 if 0.5 <= x[i] < 0.7: 
    1657                     z[i] = 0.39                     
    1658                 if 0.7 <= x[i]: 
    1659                     z[i] = x[i]/3                   
    1660             return z                               
    1661                                    
    1662                    
     1656                if 0.5 <= x[i] < 0.7:
     1657                    z[i] = 0.39
     1658                if 0.7 <= x[i]:
     1659                    z[i] = x[i]/3
     1660            return z
     1661
     1662
    16631663
    16641664        domain.set_quantity('elevation', x_slope)
    1665         domain.set_quantity('friction', 0)     
    1666         domain.set_quantity('stage', 0.4) #Steady       
    1667        
     1665        domain.set_quantity('friction', 0)
     1666        domain.set_quantity('stage', 0.4) #Steady
     1667
    16681668        # Boundary conditions (reflective everywhere)
    16691669        Br = Reflective_boundary(domain)
     
    16721672        domain.check_integrity()
    16731673
    1674         #domain.visualise = True #If you want to take a sticky beak 
    1675        
    1676         initial_volume = domain.quantities['stage'].get_integral()         
    1677         initial_xmom = domain.quantities['xmomentum'].get_integral()     
    1678        
     1674        #domain.visualise = True #If you want to take a sticky beak
     1675
     1676        initial_volume = domain.quantities['stage'].get_integral()
     1677        initial_xmom = domain.quantities['xmomentum'].get_integral()
     1678
    16791679        import copy
    16801680        ref_centroid_values =\
    16811681                 copy.copy(domain.quantities['stage'].centroid_values)
    1682                                
    1683         #print 'ORG', domain.quantities['stage'].centroid_values                               
     1682
     1683        #print 'ORG', domain.quantities['stage'].centroid_values
    16841684        domain.distribute_to_vertices_and_edges()
    1685        
    1686        
     1685
     1686
    16871687        #print domain.quantities['stage'].centroid_values
    16881688        assert allclose(domain.quantities['stage'].centroid_values,
    1689                         ref_centroid_values)           
    1690        
    1691        
     1689                        ref_centroid_values)
     1690
     1691
    16921692        #Check that initial limiter doesn't violate cons quan
    16931693        assert allclose (domain.quantities['stage'].get_integral(),
    1694                          initial_volume) 
    1695        
     1694                         initial_volume)
     1695
    16961696        #Evolution
    16971697        for t in domain.evolve(yieldstep = 0.05, finaltime = 10):
    1698             volume =  domain.quantities['stage'].get_integral()         
     1698            volume =  domain.quantities['stage'].get_integral()
    16991699            #print t, volume, initial_volume
    1700             assert allclose (volume, initial_volume)       
    1701                    
    1702        
     1700            assert allclose (volume, initial_volume)
     1701
     1702
    17031703    def test_conservation_4(self):
    17041704        """Test that stage is conserved globally
    1705        
    1706         This one uses a larger grid, convoluted bed, reflective bdries and a suitable 
     1705
     1706        This one uses a larger grid, convoluted bed, reflective bdries and a suitable
    17071707        initial condition
    17081708        """
     
    17251725            z = 0*x
    17261726            for i in range(len(x)):
    1727                 if x[i] < 0.3: 
     1727                if x[i] < 0.3:
    17281728                    z[i] = x[i]/3
    1729                 if 0.3 <= x[i] < 0.5: 
     1729                if 0.3 <= x[i] < 0.5:
    17301730                    z[i] = -0.5
    17311731                if 0.5 <= x[i] < 0.7:
    1732                     #z[i] = 0.3 #OK with beta == 0.2             
     1732                    #z[i] = 0.3 #OK with beta == 0.2
    17331733                    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   
    1736                 if 0.7 <= x[i]: 
    1737                     z[i] = x[i]/3                   
    1738             return z                               
    1739                                    
    1740                    
     1734                    #z[i] = 0.35#Fails after 80 timesteps with an error
     1735                                #of the order 1.0e-5
     1736                if 0.7 <= x[i]:
     1737                    z[i] = x[i]/3
     1738            return z
     1739
     1740
    17411741
    17421742        domain.set_quantity('elevation', x_slope)
    1743         domain.set_quantity('friction', 0)     
    1744         domain.set_quantity('stage', 0.4) #Steady       
    1745        
     1743        domain.set_quantity('friction', 0)
     1744        domain.set_quantity('stage', 0.4) #Steady
     1745
    17461746        # Boundary conditions (reflective everywhere)
    17471747        Br = Reflective_boundary(domain)
     
    17501750        domain.check_integrity()
    17511751
    1752         #domain.visualise = True #If you want to take a sticky beak 
    1753        
    1754         initial_volume = domain.quantities['stage'].get_integral()         
    1755         initial_xmom = domain.quantities['xmomentum'].get_integral()     
    1756        
     1752        #domain.visualise = True #If you want to take a sticky beak
     1753
     1754        initial_volume = domain.quantities['stage'].get_integral()
     1755        initial_xmom = domain.quantities['xmomentum'].get_integral()
     1756
    17571757        import copy
    17581758        ref_centroid_values =\
    17591759                 copy.copy(domain.quantities['stage'].centroid_values)
    1760                                
     1760
    17611761        #Test limiter by itself
    17621762        domain.distribute_to_vertices_and_edges()
    1763        
     1763
    17641764        #Check that initial limiter doesn't violate cons quan
    17651765        assert allclose (domain.quantities['stage'].get_integral(),
    1766                          initial_volume) 
    1767         #NOTE: This would fail if any initial stage was less than the 
     1766                         initial_volume)
     1767        #NOTE: This would fail if any initial stage was less than the
    17681768        #corresponding bed elevation - but that is reasonable.
    1769                          
    1770                
     1769
     1770
    17711771        #Evolution
    17721772        for t in domain.evolve(yieldstep = 0.05, finaltime = 10.0):
    1773             volume =  domain.quantities['stage'].get_integral()         
     1773            volume =  domain.quantities['stage'].get_integral()
    17741774
    17751775            #print t, volume, initial_volume
    1776    
    1777            
    1778             #if not allclose (volume, initial_volume): 
     1776
     1777
     1778            #if not allclose (volume, initial_volume):
    17791779            #    print 't==4.05'
    17801780            #    for k in range(domain.number_of_elements):
    17811781            #       pass
    17821782            #       print domain.quantities['stage'].centroid_values[k] -\
    1783             #             ref_centroid_values[k] 
    1784            
    1785             assert allclose (volume, initial_volume) 
    1786        
    1787 
    1788        
    1789        
    1790        
     1783            #             ref_centroid_values[k]
     1784
     1785            assert allclose (volume, initial_volume)
     1786
     1787
     1788
     1789
     1790
    17911791    def test_conservation_5(self):
    1792         """Test that momentum is conserved globally in 
     1792        """Test that momentum is conserved globally in
    17931793        steady state scenario
    1794        
     1794
    17951795        This one uses a slopy bed, dirichlet and reflective bdries
    17961796        """
     
    18131813
    18141814        domain.set_quantity('elevation', x_slope)
    1815         domain.set_quantity('friction', 0)     
    1816         domain.set_quantity('stage', 0.4) #Steady       
    1817        
     1815        domain.set_quantity('friction', 0)
     1816        domain.set_quantity('stage', 0.4) #Steady
     1817
    18181818        # Boundary conditions (reflective everywhere)
    1819         Br = Reflective_boundary(domain)       
     1819        Br = Reflective_boundary(domain)
    18201820        Bleft = Dirichlet_boundary([0.5,0,0])
    1821         Bright = Dirichlet_boundary([0.1,0,0]) 
    1822         domain.set_boundary({'left': Bleft, 'right': Bright, 
     1821        Bright = Dirichlet_boundary([0.1,0,0])
     1822        domain.set_boundary({'left': Bleft, 'right': Bright,
    18231823                             'top': Br, 'bottom': Br})
    18241824
    18251825        domain.check_integrity()
    18261826
    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        
     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
    18321832
    18331833        #Evolution
    18341834        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            
     1835            stage =  domain.quantities['stage'].get_integral()
     1836            xmom = domain.quantities['xmomentum'].get_integral()
     1837            ymom = domain.quantities['ymomentum'].get_integral()
     1838
    18391839            if allclose(t, 6):  #Steady state reached
    18401840                steady_xmom = domain.quantities['xmomentum'].get_integral()
    18411841                steady_ymom = domain.quantities['ymomentum'].get_integral()
    1842                 steady_stage = domain.quantities['stage'].get_integral()               
    1843                
     1842                steady_stage = domain.quantities['stage'].get_integral()
     1843
    18441844            if t > 6:
    18451845                #print '%.2f %14.8f %14.8f' %(t, ymom, steady_ymom)
    1846                 assert allclose(xmom, steady_xmom)             
     1846                assert allclose(xmom, steady_xmom)
    18471847                assert allclose(ymom, steady_ymom)
    1848                 assert allclose(stage, steady_stage)           
    1849                                                
    1850            
    1851                
    1852                
     1848                assert allclose(stage, steady_stage)
     1849
     1850
     1851
     1852
    18531853    def test_second_order_flat_bed_onestep(self):
    18541854
     
    18791879        #Data from earlier version of pyvolution
    18801880        assert allclose(domain.min_timestep, 0.0396825396825)
    1881         assert allclose(domain.max_timestep, 0.0396825396825) 
     1881        assert allclose(domain.max_timestep, 0.0396825396825)
    18821882
    18831883        assert allclose(domain.quantities['stage'].centroid_values[:12],
     
    18971897                         0.00024152, 0.02656103, 0.00024152, 0.02656103,
    18981898                         0.00024152, 0.02656103, 0.00040506, 0.0272623])
    1899        
     1899
    19001900        assert allclose(domain.quantities['stage'].vertex_values[:12,2],
    19011901                        [0.00182037, 0.02656103, 0.00676264,
     
    19191919
    19201920
    1921        
     1921
    19221922    def test_second_order_flat_bed_moresteps(self):
    19231923
     
    19481948        #Data from earlier version of pyvolution
    19491949        #assert allclose(domain.min_timestep, 0.0396825396825)
    1950         #assert allclose(domain.max_timestep, 0.0396825396825) 
     1950        #assert allclose(domain.max_timestep, 0.0396825396825)
    19511951        #print domain.quantities['stage'].centroid_values
    19521952
     
    19721972        Br = Reflective_boundary(domain)
    19731973        Bd = Dirichlet_boundary([0.2,0.,0.])
    1974        
     1974
    19751975        domain.set_boundary({'left': Bd, 'right': Br, 'top': Br, 'bottom': Br})
    19761976        domain.check_integrity()
    19771977
    1978  
     1978
    19791979        #Evolution
    19801980        for t in domain.evolve(yieldstep = 0.02, finaltime = 0.5):
     
    19821982            #domain.write_time()
    19831983
    1984         #FIXME: These numbers were from version before 25/10       
     1984        #FIXME: These numbers were from version before 25/10
    19851985        #assert allclose(domain.min_timestep, 0.0140413643926)
    19861986        #assert allclose(domain.max_timestep, 0.0140947355753)
     
    19941994
    19951995            #assert allclose(domain.quantities['ymomentum'].edge_values[:4,i],
    1996             #                [-0.0060238, -0.00157404, -0.00309633, -0.0001637])                         
    1997        
     1996            #                [-0.0060238, -0.00157404, -0.00309633, -0.0001637])
     1997
    19981998    def test_flatbed_second_order(self):
    19991999        from mesh_factory import rectangular
     
    20202020        domain.set_boundary({'left': Bd, 'right': Br, 'top': Br, 'bottom': Br})
    20212021        domain.check_integrity()
    2022  
     2022
    20232023        #Evolution
    20242024        for t in domain.evolve(yieldstep = 0.01, finaltime = 0.03):
     
    20272027
    20282028        assert allclose(domain.min_timestep, 0.0210448446782)
    2029         assert allclose(domain.max_timestep, 0.0210448446782) 
     2029        assert allclose(domain.max_timestep, 0.0210448446782)
    20302030
    20312031        #print domain.quantities['stage'].vertex_values[:4,0]
     
    20362036        #assert allclose(domain.quantities['stage'].vertex_values[:4,0],
    20372037        #                [0.00101913,0.05352143,0.00104852,0.05354394])
    2038        
     2038
    20392039        assert allclose(domain.quantities['xmomentum'].vertex_values[:4,0],
    20402040                        [ 0.00064835, 0.03685719, 0.00085073, 0.03687313])
     
    20422042        #assert allclose(domain.quantities['xmomentum'].vertex_values[:4,0],
    20432043        #                [0.00090581,0.03685719,0.00088303,0.03687313])
    2044        
     2044
    20452045        assert allclose(domain.quantities['ymomentum'].vertex_values[:4,0],
    20462046                        [-0.00139463,0.0006156,-0.00060364,0.00061827])
    20472047
    20482048
    2049        
     2049
    20502050    def test_flatbed_second_order_distribute(self):
    20512051        #Use real data from pyvolution 2
     
    20782078        for V in [False, True]:
    20792079            if V:
    2080                 #Set centroids as if system had been evolved           
     2080                #Set centroids as if system had been evolved
    20812081                L = zeros(2*N*N, Float)
    20822082                L[:32] = [7.21205592e-003, 5.35214298e-002, 1.00910824e-002,
     
    20912091                          4.37962142e-005, 0.00000000e+000, 4.37962142e-005,
    20922092                          0.00000000e+000, 5.57305948e-005]
    2093        
     2093
    20942094                X = zeros(2*N*N, Float)
    20952095                X[:32] = [6.48351607e-003, 3.68571894e-002, 8.50733285e-003,
     
    21182118                        0.00000000e+000, -2.57635178e-005]
    21192119
    2120        
     2120
    21212121                domain.set_quantity('stage', L, 'centroids')
    21222122                domain.set_quantity('xmomentum', X, 'centroids')
    21232123                domain.set_quantity('ymomentum', Y, 'centroids')
    2124        
     2124
    21252125                domain.check_integrity()
    2126             else:   
     2126            else:
    21272127                #Evolution
    21282128                for t in domain.evolve(yieldstep = 0.01, finaltime = 0.03):
     
    21302130                assert allclose(domain.min_timestep, 0.0210448446782)
    21312131                assert allclose(domain.max_timestep, 0.0210448446782)
    2132        
     2132
    21332133
    21342134            #Centroids were correct but not vertices.
     
    21492149            ##print domain.quantities['xmomentum'].centroid_values[17], V
    21502150            ##print
    2151             if not V:           
     2151            if not V:
    21522152                assert allclose(domain.quantities['xmomentum'].centroid_values[17], 0.0)
    2153             else: 
    2154                 assert allclose(domain.quantities['xmomentum'].centroid_values[17], 0.00028606084)           
     2153            else:
     2154                assert allclose(domain.quantities['xmomentum'].centroid_values[17], 0.00028606084)
    21552155
    21562156            import copy
    21572157            XX = copy.copy(domain.quantities['xmomentum'].centroid_values)
    21582158            assert allclose(domain.quantities['xmomentum'].centroid_values, XX)
    2159        
     2159
    21602160            domain.distribute_to_vertices_and_edges()
    21612161
     
    21872187            #print domain.quantities['xmomentum'].vertex_values[:4,0]
    21882188            #assert allclose(domain.quantities['xmomentum'].vertex_values[:4,0],
    2189             #                [0.00090581,0.03685719,0.00088303,0.03687313])       
    2190 
    2191 
    2192 
    2193        
    2194        
     2189            #                [0.00090581,0.03685719,0.00088303,0.03687313])
     2190
     2191
     2192
     2193
     2194
    21952195    def test_bedslope_problem_first_order(self):
    21962196
     
    22282228        assert allclose(domain.max_timestep, 0.050010003001)
    22292229
    2230        
     2230
    22312231    def test_bedslope_problem_first_order_moresteps(self):
    22322232
     
    22642264        #Data from earlier version of pyvolution
    22652265        #print domain.quantities['stage'].centroid_values
    2266        
     2266
    22672267        assert allclose(domain.quantities['stage'].centroid_values,
    22682268                        [-0.02998628, -0.01520652, -0.03043492,
     
    22902290                        -0.14175896, -0.14560798, -0.13911658,
    22912291                        -0.14439383, -0.13924047, -0.14829043])
    2292                        
    2293        
     2292
     2293
    22942294    def test_bedslope_problem_second_order_one_step(self):
    22952295
     
    23492349        #print domain.quantities['stage'].extrapolate_second_order()
    23502350        #domain.distribute_to_vertices_and_edges()
    2351         #print domain.quantities['stage'].vertex_values[:,0]       
    2352        
     2351        #print domain.quantities['stage'].vertex_values[:,0]
     2352
    23532353        #Evolution
    23542354        for t in domain.evolve(yieldstep = 0.05, finaltime = 0.05):
    2355             #domain.write_time()           
     2355            #domain.write_time()
    23562356            pass
    23572357
    23582358
    2359         #print domain.quantities['stage'].centroid_values 
     2359        #print domain.quantities['stage'].centroid_values
    23602360        assert allclose(domain.quantities['stage'].centroid_values,
    23612361                 [0.01290985, 0.02356019, 0.01619096, 0.02356019, 0.01619096,
     
    23772377                  -0.25865535, -0.24776246, -0.25865535, -0.24521113])
    23782378
    2379        
     2379
    23802380
    23812381    def test_bedslope_problem_second_order_two_steps(self):
     
    23922392        domain.smooth = False
    23932393        domain.default_order=2
    2394         domain.beta_h = 0.0 #Use first order in h-limiter       
     2394        domain.beta_h = 0.0 #Use first order in h-limiter
    23952395
    23962396        #Bed-slope and friction at vertices (and interpolated elsewhere)
     
    24372437        #print domain.quantities['stage'].extrapolate_second_order()
    24382438        #domain.distribute_to_vertices_and_edges()
    2439         #print domain.quantities['stage'].vertex_values[:,0]       
    2440        
     2439        #print domain.quantities['stage'].vertex_values[:,0]
     2440
    24412441        #Evolution
    24422442        for t in domain.evolve(yieldstep = 0.05, finaltime = 0.1):
    24432443            pass
    24442444
    2445        
     2445
    24462446        #Data from earlier version of pyvolution ft=0.1
    2447         assert allclose(domain.min_timestep, 0.0376895634803) 
     2447        assert allclose(domain.min_timestep, 0.0376895634803)
    24482448        assert allclose(domain.max_timestep, 0.0415635655309)
    24492449
     
    24692469                         -0.25031463, -0.24454764, -0.24885323, -0.24286438])
    24702470
    2471        
    2472        
    2473                
     2471
     2472
     2473
    24742474    def test_bedslope_problem_second_order_two_yieldsteps(self):
    24752475
     
    24852485        domain.smooth = False
    24862486        domain.default_order=2
    2487         domain.beta_h = 0.0 #Use first order in h-limiter       
     2487        domain.beta_h = 0.0 #Use first order in h-limiter
    24882488
    24892489        #Bed-slope and friction at vertices (and interpolated elsewhere)
     
    25302530        #print domain.quantities['stage'].extrapolate_second_order()
    25312531        #domain.distribute_to_vertices_and_edges()
    2532         #print domain.quantities['stage'].vertex_values[:,0]       
    2533        
     2532        #print domain.quantities['stage'].vertex_values[:,0]
     2533
    25342534        #Evolution
    25352535        for t in domain.evolve(yieldstep = 0.05, finaltime = 0.1):   #0.05??
    2536             #domain.write_time()           
     2536            #domain.write_time()
    25372537            pass
    25382538
    25392539
    2540        
    2541         assert allclose(domain.quantities['stage'].centroid_values, 
     2540
     2541        assert allclose(domain.quantities['stage'].centroid_values,
    25422542                 [0.00855788, 0.01575204, 0.00994606, 0.01717072, 0.01005985,
    25432543                  0.01716362, 0.01005985, 0.01716299, 0.01007098, 0.01736248,
     
    25742574        domain.smooth = False
    25752575        domain.default_order=2
    2576         domain.beta_h = 0.0 #Use first order in h-limiter       
     2576        domain.beta_h = 0.0 #Use first order in h-limiter
    25772577
    25782578        #Bed-slope and friction at vertices (and interpolated elsewhere)
     
    26192619        #print domain.quantities['stage'].extrapolate_second_order()
    26202620        #domain.distribute_to_vertices_and_edges()
    2621         #print domain.quantities['stage'].vertex_values[:,0]       
    2622        
     2621        #print domain.quantities['stage'].vertex_values[:,0]
     2622
    26232623        #Evolution
    26242624        for t in domain.evolve(yieldstep = 0.05, finaltime = 0.5):
    26252625            pass
    26262626
    2627        
     2627
    26282628        assert allclose(domain.quantities['stage'].centroid_values,
    26292629     [-0.02907028, -0.01475478, -0.02973417, -0.01447186, -0.02932665, -0.01428285,
     
    26312631      -0.07597998, -0.06252591, -0.07664854, -0.06312532, -0.07638287, -0.06265139,
    26322632      -0.07571145, -0.06235231, -0.0756817,  -0.06245309, -0.07652292, -0.06289946,
    2633       -0.12367464, -0.11088981, -0.12237277, -0.11115338, -0.1218934,  -0.1107174, 
     2633      -0.12367464, -0.11088981, -0.12237277, -0.11115338, -0.1218934,  -0.1107174,
    26342634      -0.12081485, -0.11000491, -0.12038451, -0.11010335, -0.12102113, -0.11012105,
    26352635      -0.16909116, -0.15831543, -0.16730214, -0.15786249, -0.1665493,  -0.15697919,
     
    26442644       0.00788729,  0.00356522,  0.00780649,  0.00341919,  0.00693525,  0.00310375,
    26452645       0.02166196,  0.01421475,  0.02017737,  0.01316839,  0.02037015,  0.01368659,
    2646        0.02106,     0.01399161,  0.02074514,  0.01354935,  0.01887407,  0.0123113, 
     2646       0.02106,     0.01399161,  0.02074514,  0.01354935,  0.01887407,  0.0123113,
    26472647       0.03775083,  0.02855197,  0.03689337,  0.02759782,  0.03732848,  0.02812072,
    2648        0.03872545,  0.02913348,  0.03880939,  0.02803804,  0.03546499,  0.0260039, 
     2648       0.03872545,  0.02913348,  0.03880939,  0.02803804,  0.03546499,  0.0260039,
    26492649       0.0632131,   0.04730634,  0.0576324,   0.04592336,  0.05790921,  0.04690514,
    26502650       0.05986467,  0.04871165,  0.06170068,  0.04811572,  0.05657041,  0.04416292,
    2651        0.08489642,  0.07188097,  0.07835261,  0.06843406,  0.07986412,  0.0698247, 
     2651       0.08489642,  0.07188097,  0.07835261,  0.06843406,  0.07986412,  0.0698247,
    26522652       0.08201071,  0.07216756,  0.08378418,  0.07273624,  0.080399,    0.06645841,
    26532653       0.01631548,  0.04691608,  0.0206632,   0.044409,    0.02115518,  0.04560305,
    26542654       0.02160608,  0.04663725,  0.02174734,  0.04795559,  0.02281427,  0.05667111])
    26552655
    2656        
    2657         assert allclose(domain.quantities['ymomentum'].centroid_values, 
     2656
     2657        assert allclose(domain.quantities['ymomentum'].centroid_values,
    26582658     [ 1.45876601e-004, -3.24627393e-004, -1.57572719e-004, -2.92790187e-004,
    26592659      -9.90988382e-005, -3.06677335e-004, -1.62493106e-004, -3.71310004e-004,
     
    26742674      -6.17359400e-003, -5.98761937e-003, -6.00540116e-003, -5.01121966e-003,
    26752675      -4.50964850e-003, -3.06319963e-003,  6.08950810e-004, -4.79537921e-004])
    2676        
    2677 
    2678        
     2676
     2677
     2678
    26792679
    26802680    def test_temp_play(self):
     
    26912691        domain.smooth = False
    26922692        domain.default_order=2
    2693         domain.beta_h = 0.0 #Use first order in h-limiter       
     2693        domain.beta_h = 0.0 #Use first order in h-limiter
    26942694
    26952695        #Bed-slope and friction at vertices (and interpolated elsewhere)
     
    27132713        assert allclose(domain.quantities['stage'].centroid_values[:4],
    27142714                        [0.00206836, 0.01296714, 0.00363415, 0.01438924])
    2715         assert allclose(domain.quantities['xmomentum'].centroid_values[:4],                     
     2715        assert allclose(domain.quantities['xmomentum'].centroid_values[:4],
    27162716                        [0.01360154, 0.00671133, 0.01264578, 0.00648503])
    27172717        assert allclose(domain.quantities['ymomentum'].centroid_values[:4],
    2718                         [-1.19201077e-003, -7.23647546e-004, 
     2718                        [-1.19201077e-003, -7.23647546e-004,
    27192719                        -6.39083123e-005, 6.29815168e-005])
    2720        
    2721        
     2720
     2721
    27222722    def test_complex_bed(self):
    27232723        #No friction is tested here
    2724        
     2724
    27252725        from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\
    27262726             Transmissive_boundary, Time_boundary,\
     
    27292729        from mesh_factory import rectangular
    27302730        from Numeric import array
    2731    
     2731
    27322732        N = 12
    27332733        points, vertices, boundary = rectangular(N, N/2, len1=1.2,len2=0.6,
     
    27402740        domain.default_order=2
    27412741
    2742        
     2742
    27432743        inflow_stage = 0.1
    27442744        Z = Weir(inflow_stage)
     
    27572757        #print domain.quantities['stage'].centroid_values
    27582758
    2759         #FIXME: These numbers were from version before 25/10       
     2759        #FIXME: These numbers were from version before 25/10
    27602760        #assert allclose(domain.quantities['stage'].centroid_values,
    27612761# [3.95822638e-002,  5.61022588e-002,  4.66437868e-002,  5.73081011e-002,
     
    28102810        """
    28112811        import time
    2812        
    2813         #Create sww file of simple propagation from left to right
    2814         #through rectangular domain
    2815        
     2812
     2813        #Create sww file of simple propagation from left to right
     2814        #through rectangular domain
     2815
    28162816        from mesh_factory import rectangular
    28172817
     
    28212821        #Create shallow water domain
    28222822        domain1 = Domain(points, vertices, boundary)
    2823        
     2823
    28242824        from util import mean
    2825         domain1.reduction = mean 
     2825        domain1.reduction = mean
    28262826        domain1.smooth = False  #Exact result
    28272827
    28282828        domain1.default_order = 2
    2829         domain1.store = True   
     2829        domain1.store = True
    28302830        domain1.set_datadir('.')
    28312831        domain1.set_name('spatio_temporal_boundary_source' + str(time.time()))
    2832        
    2833         #FIXME: This is extremely important!
     2832
     2833        #FIXME: This is extremely important!
    28342834        #How can we test if they weren't stored?
    28352835        domain1.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum']
    28362836
    2837                
     2837
    28382838        #Bed-slope and friction at vertices (and interpolated elsewhere)
    28392839        domain1.set_quantity('elevation', 0)
    2840         domain1.set_quantity('friction', 0)     
     2840        domain1.set_quantity('friction', 0)
    28412841
    28422842        # Boundary conditions
     
    28552855
    28562856        cv1 = domain1.quantities['stage'].centroid_values
    2857        
    2858        
    2859         #Create an triangle shaped domain (reusing coordinates from domain 1),
    2860         #formed from the lower and right hand  boundaries and
    2861         #the sw-ne diagonal
    2862         #from domain 1. Call it domain2
    2863        
    2864         points = [ [0,0], [1.0/3,0], [1.0/3,1.0/3],
    2865                    [2.0/3,0], [2.0/3,1.0/3], [2.0/3,2.0/3],
    2866                    [1,0], [1,1.0/3], [1,2.0/3], [1,1]]
    2867        
    2868         vertices = [ [1,2,0],
    2869                      [3,4,1], [2,1,4], [4,5,2],
    2870                      [6,7,3], [4,3,7], [7,8,4], [5,4,8], [8,9,5]]       
     2857
     2858
     2859        #Create an triangle shaped domain (reusing coordinates from domain 1),
     2860        #formed from the lower and right hand  boundaries and
     2861        #the sw-ne diagonal
     2862        #from domain 1. Call it domain2
     2863
     2864        points = [ [0,0], [1.0/3,0], [1.0/3,1.0/3],
     2865                   [2.0/3,0], [2.0/3,1.0/3], [2.0/3,2.0/3],
     2866                   [1,0], [1,1.0/3], [1,2.0/3], [1,1]]
     2867
     2868        vertices = [ [1,2,0], [3,4,1], [2,1,4], [4,5,2],
     2869                     [6,7,3], [4,3,7], [7,8,4], [5,4,8], [8,9,5]]
    28712870
    28722871        boundary = { (0,1):'bottom', (1,1):'bottom', (4,1): 'bottom',
    28732872                     (4,2):'right', (6,2):'right', (8,2):'right',
    2874                      (0,0):'diagonal', (3,0):'diagonal', (8,0):'diagonal'}   
    2875                      
     2873                     (0,0):'diagonal', (3,0):'diagonal', (8,0):'diagonal'}
     2874
    28762875        domain2 = Domain(points, vertices, boundary)
    2877        
    2878         domain2.reduction = domain1.reduction
     2876
     2877        domain2.reduction = domain1.reduction
    28792878        domain2.smooth = False
    28802879        domain2.default_order = 2
    2881        
     2880
    28822881        #Bed-slope and friction at vertices (and interpolated elsewhere)
    28832882        domain2.set_quantity('elevation', 0)
    28842883        domain2.set_quantity('friction', 0)
    2885         domain2.set_quantity('stage', 0)       
     2884        domain2.set_quantity('stage', 0)
    28862885
    28872886        # Boundary conditions
    2888         Br = Reflective_boundary(domain2)       
    2889         Bf = Spatio_temporal_boundary(domain1.filename + '.' + domain1.format,
     2887        Br = Reflective_boundary(domain2)
     2888        Bf = Spatio_temporal_boundary(domain1.filename + '.' + domain1.format,
    28902889                                      domain2)
    28912890        domain2.set_boundary({'right':Br, 'bottom':Br, 'diagonal':Bf})
    2892         domain2.check_integrity()       
    2893        
     2891        domain2.check_integrity()
     2892
    28942893
    28952894
     
    28982897            pass
    28992898
    2900        
    2901         #Use output from domain1 as spatio-temporal boundary for domain2
    2902         #and verify that results at right hand side are close. 
     2899
     2900        #Use output from domain1 as spatio-temporal boundary for domain2
     2901        #and verify that results at right hand side are close.
    29032902
    29042903        cv2 = domain2.quantities['stage'].centroid_values
    29052904
    29062905        #print take(cv1, (12,14,16))  #Right
    2907         #print take(cv2, (4,6,8))
    2908         #print take(cv1, (0,6,12))  #Bottom     
    2909         #print take(cv2, (0,1,4))
    2910         #print take(cv1, (0,8,16))  #Diag       
    2911         #print take(cv2, (0,3,8))
    2912 
    2913         assert allclose( take(cv1, (0,8,16)), take(cv2, (0,3,8))) #Diag
    2914         assert allclose( take(cv1, (0,6,12)), take(cv2, (0,1,4))) #Bottom
     2906        #print take(cv2, (4,6,8))
     2907        #print take(cv1, (0,6,12))  #Bottom
     2908        #print take(cv2, (0,1,4))
     2909        #print take(cv1, (0,8,16))  #Diag
     2910        #print take(cv2, (0,3,8))
     2911
     2912        assert allclose( take(cv1, (0,8,16)), take(cv2, (0,3,8))) #Diag
     2913        assert allclose( take(cv1, (0,6,12)), take(cv2, (0,1,4))) #Bottom
    29152914        assert allclose( take(cv1, (12,14,16)), take(cv2, (4,6,8))) #RHS
    29162915
    29172916        #Cleanup
    2918         os.remove(domain1.filename + '.' + domain1.format)       
    2919        
    2920        
     2917        os.remove(domain1.filename + '.' + domain1.format)
     2918
     2919
    29212920
    29222921    def test_spatio_temporal_boundary_2(self):
    29232922        """Test that boundary values can be read from file and interpolated
    29242923        in both time and space.
    2925         This is a more basic test, verifying that boundary object
    2926         produces the expected results
     2924        This is a more basic test, verifying that boundary object
     2925        produces the expected results
    29272926
    29282927
    29292928        """
    29302929        import time
    2931        
    2932         #Create sww file of simple propagation from left to right
    2933         #through rectangular domain
    2934        
     2930
     2931        #Create sww file of simple propagation from left to right
     2932        #through rectangular domain
     2933
    29352934        from mesh_factory import rectangular
    29362935
     
    29402939        #Create shallow water domain
    29412940        domain1 = Domain(points, vertices, boundary)
    2942        
     2941
    29432942        from util import mean
    2944         domain1.reduction = mean 
     2943        domain1.reduction = mean
    29452944        domain1.smooth = True #To mimic MOST output
    29462945
    29472946        domain1.default_order = 2
    2948         domain1.store = True   
     2947        domain1.store = True
    29492948        domain1.set_datadir('.')
    29502949        domain1.set_name('spatio_temporal_boundary_source' + str(time.time()))
    2951        
    2952         #FIXME: This is extremely important!
     2950
     2951        #FIXME: This is extremely important!
    29532952        #How can we test if they weren't stored?
    29542953        domain1.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum']
    29552954
    2956                
     2955
    29572956        #Bed-slope and friction at vertices (and interpolated elsewhere)
    29582957        domain1.set_quantity('elevation', 0)
    2959         domain1.set_quantity('friction', 0)     
     2958        domain1.set_quantity('friction', 0)
    29602959
    29612960        # Boundary conditions
    29622961        Br = Reflective_boundary(domain1)
    2963         Bd = Dirichlet_boundary([0.3,0,0])     
     2962        Bd = Dirichlet_boundary([0.3,0,0])
    29642963        domain1.set_boundary({'left': Bd, 'top': Bd, 'right': Br, 'bottom': Br})
    29652964        #Initial condition
     
    29732972            #domain1.write_time()
    29742973
    2975        
    2976         #Create an triangle shaped domain (coinciding with some
    2977         #coordinates from domain 1), 
    2978         #formed from the lower and right hand  boundaries and
    2979         #the sw-ne diagonal
    2980         #from domain 1. Call it domain2
    2981        
    2982         points = [ [0,0], [1.0/3,0], [1.0/3,1.0/3],
     2974
     2975        #Create an triangle shaped domain (coinciding with some
     2976        #coordinates from domain 1),
     2977        #formed from the lower and right hand  boundaries and
     2978        #the sw-ne diagonal
     2979        #from domain 1. Call it domain2
     2980
     2981        points = [ [0,0], [1.0/3,0], [1.0/3,1.0/3],
    29832982                   [2.0/3,0], [2.0/3,1.0/3], [2.0/3,2.0/3],
    29842983                   [1,0], [1,1.0/3], [1,2.0/3], [1,1]]
    2985        
    2986         vertices = [ [1,2,0],
    2987                      [3,4,1], [2,1,4], [4,5,2], 
    2988                      [6,7,3], [4,3,7], [7,8,4], [5,4,8], [8,9,5]]       
     2984
     2985        vertices = [ [1,2,0],
     2986                     [3,4,1], [2,1,4], [4,5,2],
     2987                     [6,7,3], [4,3,7], [7,8,4], [5,4,8], [8,9,5]]
    29892988
    29902989        boundary = { (0,1):'bottom', (1,1):'bottom', (4,1): 'bottom',
    29912990                     (4,2):'right', (6,2):'right', (8,2):'right',
    2992                      (0,0):'diagonal', (3,0):'diagonal', (8,0):'diagonal'}   
    2993                      
     2991                     (0,0):'diagonal', (3,0):'diagonal', (8,0):'diagonal'}
     2992
    29942993        domain2 = Domain(points, vertices, boundary)
    2995        
    2996         domain2.reduction = domain1.reduction
     2994
     2995        domain2.reduction = domain1.reduction
    29972996        domain2.smooth = False
    29982997        domain2.default_order = 2
    2999        
     2998
    30002999        #Bed-slope and friction at vertices (and interpolated elsewhere)
    30013000        domain2.set_quantity('elevation', 0)
    30023001        domain2.set_quantity('friction', 0)
    3003         domain2.set_quantity('stage', 0)       
    3004 
    3005        
    3006         #Read results for specific timesteps t=1 and t=2
    3007         from Scientific.IO.NetCDF import NetCDFFile     
    3008         fid = NetCDFFile(domain1.filename + '.' + domain1.format)
    3009        
    3010         x = fid.variables['x'][:]
    3011         y = fid.variables['y'][:]       
    3012         s1 = fid.variables['stage'][1,:]
    3013         s2 = fid.variables['stage'][2,:]       
    3014         fid.close()
    3015 
    3016         from Numeric import take, reshape, concatenate 
    3017         shp = (len(x), 1)
    3018         points = concatenate( (reshape(x, shp), reshape(y, shp)), axis=1)       
    3019         #The diagonal points of domain 1 are 0, 5, 10, 15
    3020        
    3021         #print points[0], points[5], points[10], points[15]
    3022         assert allclose( take(points, [0,5,10,15]),
    3023                          [[0,0], [1.0/3, 1.0/3], [2.0/3, 2.0/3], [1,1]]) 
    3024 
    3025        
     3002        domain2.set_quantity('stage', 0)
     3003
     3004
     3005        #Read results for specific timesteps t=1 and t=2
     3006        from Scientific.IO.NetCDF import NetCDFFile
     3007        fid = NetCDFFile(domain1.filename + '.' + domain1.format)
     3008
     3009        x = fid.variables['x'][:]
     3010        y = fid.variables['y'][:]
     3011        s1 = fid.variables['stage'][1,:]
     3012        s2 = fid.variables['stage'][2,:]
     3013        fid.close()
     3014
     3015        from Numeric import take, reshape, concatenate
     3016        shp = (len(x), 1)
     3017        points = concatenate( (reshape(x, shp), reshape(y, shp)), axis=1)
     3018        #The diagonal points of domain 1 are 0, 5, 10, 15
     3019
     3020        #print points[0], points[5], points[10], points[15]
     3021        assert allclose( take(points, [0,5,10,15]),
     3022                         [[0,0], [1.0/3, 1.0/3], [2.0/3, 2.0/3], [1,1]])
     3023
     3024
    30263025        # Boundary conditions
    3027         Br = Reflective_boundary(domain2)       
    3028         Bf = Spatio_temporal_boundary(domain1.filename + '.' + domain1.format,
     3026        Br = Reflective_boundary(domain2)
     3027        Bf = Spatio_temporal_boundary(domain1.filename + '.' + domain1.format,
    30293028                                      domain2)
    30303029        domain2.set_boundary({'right':Br, 'bottom':Br, 'diagonal':Bf})
    3031         domain2.check_integrity()       
    3032 
    3033         #Test that interpolation points are the mid points of the all boundary
    3034         #segments       
    3035 
    3036         boundary_midpoints = [[1.0/6, 0], [1.0/2, 0], [5.0/6,0],
     3030        domain2.check_integrity()
     3031
     3032        #Test that interpolation points are the mid points of the all boundary
     3033        #segments
     3034
     3035        boundary_midpoints = [[1.0/6, 0], [1.0/2, 0], [5.0/6,0],
    30373036                              [1.0, 1.0/6], [1.0, 1.0/2], [1.0, 5.0/6],
    30383037                              [1.0/6, 1.0/6], [0.5, 0.5], [5.0/6, 5.0/6]]
    3039                              
     3038
    30403039        boundary_midpoints.sort()
    3041         R = Bf.F.interpolation_points.tolist() 
    3042         R.sort()
    3043         assert allclose(boundary_midpoints, R) 
    3044        
    3045         #Check spatially interpolated output at time == 1
    3046         domain2.time = 1
    3047        
    3048         #First diagonal midpoint
    3049         R0 = Bf.evaluate(0,0)
    3050         assert allclose(R0[0], (s1[0] + s1[5])/2)
    3051        
    3052         #Second diagonal midpoint
    3053         R0 = Bf.evaluate(3,0)
    3054         assert allclose(R0[0], (s1[5] + s1[10])/2)
    3055        
    3056         #First diagonal midpoint
    3057         R0 = Bf.evaluate(8,0)
    3058         assert allclose(R0[0], (s1[10] + s1[15])/2)             
    3059                
    3060         #Check spatially interpolated output at time == 2
    3061         domain2.time = 2
    3062        
    3063         #First diagonal midpoint
    3064         R0 = Bf.evaluate(0,0)
    3065         assert allclose(R0[0], (s2[0] + s2[5])/2)
    3066        
    3067         #Second diagonal midpoint
    3068         R0 = Bf.evaluate(3,0)
    3069         assert allclose(R0[0], (s2[5] + s2[10])/2)
    3070        
    3071         #First diagonal midpoint
    3072         R0 = Bf.evaluate(8,0)
    3073         assert allclose(R0[0], (s2[10] + s2[15])/2)             
    3074        
    3075        
    3076         #Now check temporal interpolation
     3040        R = Bf.F.interpolation_points.tolist()
     3041        R.sort()
     3042        assert allclose(boundary_midpoints, R)
     3043
     3044        #Check spatially interpolated output at time == 1
     3045        domain2.time = 1
     3046
     3047        #First diagonal midpoint
     3048        R0 = Bf.evaluate(0,0)
     3049        assert allclose(R0[0], (s1[0] + s1[5])/2)
     3050
     3051        #Second diagonal midpoint
     3052        R0 = Bf.evaluate(3,0)
     3053        assert allclose(R0[0], (s1[5] + s1[10])/2)
     3054
     3055        #First diagonal midpoint
     3056        R0 = Bf.evaluate(8,0)
     3057        assert allclose(R0[0], (s1[10] + s1[15])/2)
     3058
     3059        #Check spatially interpolated output at time == 2
     3060        domain2.time = 2
     3061
     3062        #First diagonal midpoint
     3063        R0 = Bf.evaluate(0,0)
     3064        assert allclose(R0[0], (s2[0] + s2[5])/2)
     3065
     3066        #Second diagonal midpoint
     3067        R0 = Bf.evaluate(3,0)
     3068        assert allclose(R0[0], (s2[5] + s2[10])/2)
     3069
     3070        #First diagonal midpoint
     3071        R0 = Bf.evaluate(8,0)
     3072        assert allclose(R0[0], (s2[10] + s2[15])/2)
     3073
     3074
     3075        #Now check temporal interpolation
    30773076
    30783077        domain2.time = 1 + 2.0/3
    3079        
    3080         #First diagonal midpoint
    3081         R0 = Bf.evaluate(0,0)
    3082         assert allclose(R0[0], ((s1[0] + s1[5])/2 + 2.0*(s2[0] + s2[5])/2)/3)
    3083        
    3084         #Second diagonal midpoint
    3085         R0 = Bf.evaluate(3,0)
    3086         assert allclose(R0[0], ((s1[5] + s1[10])/2 + 2.0*(s2[5] + s2[10])/2)/3)
    3087        
    3088         #First diagonal midpoint
    3089         R0 = Bf.evaluate(8,0)
    3090         assert allclose(R0[0], ((s1[10] + s1[15])/2 + 2.0*(s2[10] + s2[15])/2)/3)               
    3091                
    3092        
    3093                
     3078
     3079        #First diagonal midpoint
     3080        R0 = Bf.evaluate(0,0)
     3081        assert allclose(R0[0], ((s1[0] + s1[5])/2 + 2.0*(s2[0] + s2[5])/2)/3)
     3082
     3083        #Second diagonal midpoint
     3084        R0 = Bf.evaluate(3,0)
     3085        assert allclose(R0[0], ((s1[5] + s1[10])/2 + 2.0*(s2[5] + s2[10])/2)/3)
     3086
     3087        #First diagonal midpoint
     3088        R0 = Bf.evaluate(8,0)
     3089        assert allclose(R0[0], ((s1[10] + s1[15])/2 + 2.0*(s2[10] + s2[15])/2)/3)
     3090
     3091
     3092
    30943093        #Cleanup
    3095         os.remove(domain1.filename + '.' + domain1.format)                 
    3096 #-------------------------------------------------------------
     3094        os.remove(domain1.filename + '.' + domain1.format)
     3095
     3096
     3097        #-------------------------------------------------------------
    30973098if __name__ == "__main__":
    3098     suite = unittest.makeSuite(TestCase,'test')
     3099    suite = unittest.makeSuite(Test_Shallow_Water,'test')
    30993100    runner = unittest.TextTestRunner()
    31003101    runner.run(suite)
    3101 
Note: See TracChangeset for help on using the changeset viewer.