Ignore:
Timestamp:
Jan 13, 2009, 11:51:22 AM (15 years ago)
Author:
rwilson
Message:

Change Numeric imports to general form - ready to change to NumPy?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_domain.py

    r6129 r6145  
    66from domain import *
    77from anuga.config import epsilon
    8 from Numeric import allclose, array, ones, Float
     8
     9import Numeric as num
    910
    1011
     
    9596        #Centroids
    9697        q = domain.get_conserved_quantities(0)
    97         assert allclose(q, [2., 2., 0.])
     98        assert num.allclose(q, [2., 2., 0.])
    9899
    99100        q = domain.get_conserved_quantities(1)
    100         assert allclose(q, [5., 5., 0.])
     101        assert num.allclose(q, [5., 5., 0.])
    101102
    102103        q = domain.get_conserved_quantities(2)
    103         assert allclose(q, [3., 3., 0.])
     104        assert num.allclose(q, [3., 3., 0.])
    104105
    105106        q = domain.get_conserved_quantities(3)
    106         assert allclose(q, [0., 0., 0.])
     107        assert num.allclose(q, [0., 0., 0.])
    107108
    108109
    109110        #Edges
    110111        q = domain.get_conserved_quantities(0, edge=0)
    111         assert allclose(q, [2.5, 2.5, 0.])
     112        assert num.allclose(q, [2.5, 2.5, 0.])
    112113        q = domain.get_conserved_quantities(0, edge=1)
    113         assert allclose(q, [2., 2., 0.])
     114        assert num.allclose(q, [2., 2., 0.])
    114115        q = domain.get_conserved_quantities(0, edge=2)
    115         assert allclose(q, [1.5, 1.5, 0.])
     116        assert num.allclose(q, [1.5, 1.5, 0.])
    116117
    117118        for i in range(3):
    118119            q = domain.get_conserved_quantities(1, edge=i)
    119             assert allclose(q, [5, 5, 0.])
     120            assert num.allclose(q, [5, 5, 0.])
    120121
    121122
    122123        q = domain.get_conserved_quantities(2, edge=0)
    123         assert allclose(q, [4.5, 4.5, 0.])
     124        assert num.allclose(q, [4.5, 4.5, 0.])
    124125        q = domain.get_conserved_quantities(2, edge=1)
    125         assert allclose(q, [4.5, 4.5, 0.])
     126        assert num.allclose(q, [4.5, 4.5, 0.])
    126127        q = domain.get_conserved_quantities(2, edge=2)
    127         assert allclose(q, [0., 0., 0.])
     128        assert num.allclose(q, [0., 0., 0.])
    128129
    129130
    130131        q = domain.get_conserved_quantities(3, edge=0)
    131         assert allclose(q, [3., 3., 0.])
     132        assert num.allclose(q, [3., 3., 0.])
    132133        q = domain.get_conserved_quantities(3, edge=1)
    133         assert allclose(q, [-1.5, -1.5, 0.])
     134        assert num.allclose(q, [-1.5, -1.5, 0.])
    134135        q = domain.get_conserved_quantities(3, edge=2)
    135         assert allclose(q, [-1.5, -1.5, 0.])
     136        assert num.allclose(q, [-1.5, -1.5, 0.])
    136137
    137138
     
    179180        Q = domain.create_quantity_from_expression(expression)
    180181
    181         assert allclose(Q.vertex_values, [[2,3,4], [6,6,6],
    182                                       [1,1,10], [-5, 4, 4]])
     182        assert num.allclose(Q.vertex_values, [[2,3,4], [6,6,6],
     183                                              [1,1,10], [-5, 4, 4]])
    183184
    184185        expression = '(xmomentum*xmomentum + ymomentum*ymomentum)**0.5'
     
    188189        Y = domain.quantities['ymomentum'].vertex_values
    189190
    190         assert allclose(Q.vertex_values, (X**2 + Y**2)**0.5)
     191        assert num.allclose(Q.vertex_values, (X**2 + Y**2)**0.5)
    191192
    192193
     
    314315        Q = domain.quantities['depth']
    315316
    316         assert allclose(Q.vertex_values, [[2,3,4], [6,6,6],
    317                                       [1,1,10], [-5, 4, 4]])
     317        assert num.allclose(Q.vertex_values, [[2,3,4], [6,6,6],
     318                                              [1,1,10], [-5, 4, 4]])
    318319
    319320
     
    344345
    345346
    346         A = array([[1,2,3], [5,5,-5], [0,0,9], [-6,3,3]], 'f')
    347         B = array([[2,4,4], [3,2,1], [6,-3,4], [4,5,-1]], 'f')
     347        A = num.array([[1,2,3], [5,5,-5], [0,0,9], [-6,3,3]], 'f')
     348        B = num.array([[2,4,4], [3,2,1], [6,-3,4], [4,5,-1]], 'f')
    348349       
    349350        #print A
     
    359360        domain.set_quantity('elevation', A)
    360361        domain.add_quantity('elevation', B)
    361         assert allclose(elevation.vertex_values, A+B)
     362        assert num.allclose(elevation.vertex_values, A+B)
    362363       
    363364        domain.add_quantity('elevation', 4)
    364         assert allclose(elevation.vertex_values, A+B+4)       
     365        assert num.allclose(elevation.vertex_values, A+B+4)       
    365366       
    366367       
     
    370371        domain.set_quantity('depth', 1.0)                                     
    371372        domain.add_quantity('depth', expression = 'stage - elevation')       
    372         assert allclose(depth.vertex_values, stage.vertex_values-elevation.vertex_values+1)
     373        assert num.allclose(depth.vertex_values, stage.vertex_values-elevation.vertex_values+1)
    373374               
    374375       
     
    376377        reference = 2*stage.vertex_values - depth.vertex_values
    377378        domain.add_quantity('stage', expression = 'stage - depth')               
    378         assert allclose(stage.vertex_values, reference)       
     379        assert num.allclose(stage.vertex_values, reference)       
    379380                                     
    380381
     
    388389       
    389390        domain.add_quantity('depth', f)
    390         assert allclose(stage.vertex_values, depth.vertex_values)               
     391        assert num.allclose(stage.vertex_values, depth.vertex_values)               
    391392         
    392393           
     
    458459        domain.check_integrity()
    459460
    460         assert allclose(domain.neighbours, [[-1,-2,-3]])
     461        assert num.allclose(domain.neighbours, [[-1,-2,-3]])
    461462
    462463
     
    547548                                      [0,0,9], [-6, 3, 3]])
    548549
    549         assert allclose( domain.quantities['stage'].centroid_values,
    550                          [2,5,3,0] )
     550        assert num.allclose( domain.quantities['stage'].centroid_values,
     551                             [2,5,3,0] )
    551552
    552553        domain.set_quantity('xmomentum', [[1,1,1], [2,2,2],
     
    560561
    561562        #First order extrapolation
    562         assert allclose( domain.quantities['stage'].vertex_values,
    563                          [[ 2.,  2.,  2.],
    564                           [ 5.,  5.,  5.],
    565                           [ 3.,  3.,  3.],
    566                           [ 0.,  0.,  0.]])
     563        assert num.allclose( domain.quantities['stage'].vertex_values,
     564                             [[ 2.,  2.,  2.],
     565                              [ 5.,  5.,  5.],
     566                              [ 3.,  3.,  3.],
     567                              [ 0.,  0.,  0.]])
    567568
    568569
     
    603604
    604605        for name in domain.conserved_quantities:
    605             domain.quantities[name].explicit_update = array([4.,3.,2.,1.])
    606             domain.quantities[name].semi_implicit_update = array([1.,1.,1.,1.])
     606            domain.quantities[name].explicit_update = num.array([4.,3.,2.,1.])
     607            domain.quantities[name].semi_implicit_update = num.array([1.,1.,1.,1.])
    607608
    608609
     
    611612        domain.update_conserved_quantities()
    612613
    613         sem = array([1.,1.,1.,1.])/array([1, 2, 3, 4])
    614         denom = ones(4, Float)-domain.timestep*sem
     614        sem = num.array([1.,1.,1.,1.])/num.array([1, 2, 3, 4])
     615        denom = num.ones(4, num.Float)-domain.timestep*sem
    615616
    616617#        x = array([1, 2, 3, 4]) + array( [.4,.3,.2,.1] )
    617618#        x /= denom
    618619
    619         x = array([1., 2., 3., 4.])
     620        x = num.array([1., 2., 3., 4.])
    620621        x /= denom
    621         x += domain.timestep*array( [4,3,2,1] )
     622        x += domain.timestep*num.array( [4,3,2,1] )
    622623
    623624        for name in domain.conserved_quantities:
    624             assert allclose(domain.quantities[name].centroid_values, x)
     625            assert num.allclose(domain.quantities[name].centroid_values, x)
    625626
    626627
     
    654655                                      [0,0,9], [-6, 3, 3]])
    655656
    656         assert allclose( domain.quantities['stage'].centroid_values,
    657                          [2,5,3,0] )
     657        assert num.allclose( domain.quantities['stage'].centroid_values,
     658                             [2,5,3,0] )
    658659
    659660        domain.set_quantity('xmomentum', [[1,1,1], [2,2,2],
     
    667668
    668669        #First order extrapolation
    669         assert allclose( domain.quantities['stage'].vertex_values,
    670                          [[ 2.,  2.,  2.],
    671                           [ 5.,  5.,  5.],
    672                           [ 3.,  3.,  3.],
    673                           [ 0.,  0.,  0.]])
     670        assert num.allclose( domain.quantities['stage'].vertex_values,
     671                             [[ 2.,  2.,  2.],
     672                              [ 5.,  5.,  5.],
     673                              [ 3.,  3.,  3.],
     674                              [ 0.,  0.,  0.]])
    674675
    675676        domain.build_tagged_elements_dictionary({'mound':[0,1]})
     
    686687        from mesh_factory import rectangular
    687688        from shallow_water import Domain
    688         from Numeric import zeros, Float
    689689
    690690        #Create basic mesh
     
    703703        from mesh_factory import rectangular
    704704        from shallow_water import Domain
    705         from Numeric import zeros, Float
    706705
    707706        #Create basic mesh
     
    721720        domain.set_region([set_bottom_friction, set_top_friction])
    722721        #print domain.quantities['friction'].get_values()
    723         assert allclose(domain.quantities['friction'].get_values(),\
    724                         [[ 0.09,  0.09,  0.09],
    725                          [ 0.09,  0.09,  0.09],
    726                          [ 0.07,  0.07,  0.07],
    727                          [ 0.07,  0.07,  0.07],
    728                          [ 1.0,  1.0,  1.0],
    729                          [ 1.0,  1.0,  1.0]])
     722        assert num.allclose(domain.quantities['friction'].get_values(),\
     723                            [[ 0.09,  0.09,  0.09],
     724                             [ 0.09,  0.09,  0.09],
     725                             [ 0.07,  0.07,  0.07],
     726                             [ 0.07,  0.07,  0.07],
     727                             [ 1.0,  1.0,  1.0],
     728                             [ 1.0,  1.0,  1.0]])
    730729
    731730        domain.set_region([set_all_friction])
    732731        #print domain.quantities['friction'].get_values()
    733         assert allclose(domain.quantities['friction'].get_values(),
    734                         [[ 10.09, 10.09, 10.09],
    735                          [ 10.09, 10.09, 10.09],
    736                          [ 10.07, 10.07, 10.07],
    737                          [ 10.07, 10.07, 10.07],
    738                          [ 11.0,  11.0,  11.0],
    739                          [ 11.0,  11.0,  11.0]])
     732        assert num.allclose(domain.quantities['friction'].get_values(),
     733                            [[ 10.09, 10.09, 10.09],
     734                             [ 10.09, 10.09, 10.09],
     735                             [ 10.07, 10.07, 10.07],
     736                             [ 10.07, 10.07, 10.07],
     737                             [ 11.0,  11.0,  11.0],
     738                             [ 11.0,  11.0,  11.0]])
    740739
    741740
     
    746745        from mesh_factory import rectangular
    747746        from shallow_water import Domain
    748         from Numeric import zeros, Float
    749747
    750748        #Create basic mesh
     
    766764       
    767765        #print domain.quantities['friction'].get_values()
    768         assert allclose(domain.quantities['friction'].get_values(),\
    769                         [[ 0.09,  0.09,  0.09],
    770                          [ 0.09,  0.09,  0.09],
    771                          [ 0.07,  0.07,  0.07],
    772                          [ 0.07,  0.07,  0.07],
    773                          [ 1.0,  1.0,  1.0],
    774                          [ 1.0,  1.0,  1.0]])
     766        assert num.allclose(domain.quantities['friction'].get_values(),
     767                            [[ 0.09,  0.09,  0.09],
     768                             [ 0.09,  0.09,  0.09],
     769                             [ 0.07,  0.07,  0.07],
     770                             [ 0.07,  0.07,  0.07],
     771                             [ 1.0,  1.0,  1.0],
     772                             [ 1.0,  1.0,  1.0]])
    775773       
    776774        domain.set_region([set_bottom_friction, set_top_friction])
    777775        #print domain.quantities['friction'].get_values()
    778         assert allclose(domain.quantities['friction'].get_values(),\
    779                         [[ 0.09,  0.09,  0.09],
    780                          [ 0.09,  0.09,  0.09],
    781                          [ 0.07,  0.07,  0.07],
    782                          [ 0.07,  0.07,  0.07],
    783                          [ 1.0,  1.0,  1.0],
    784                          [ 1.0,  1.0,  1.0]])
     776        assert num.allclose(domain.quantities['friction'].get_values(),
     777                            [[ 0.09,  0.09,  0.09],
     778                             [ 0.09,  0.09,  0.09],
     779                             [ 0.07,  0.07,  0.07],
     780                             [ 0.07,  0.07,  0.07],
     781                             [ 1.0,  1.0,  1.0],
     782                             [ 1.0,  1.0,  1.0]])
    785783
    786784        domain.set_region([set_all_friction])
    787785        #print domain.quantities['friction'].get_values()
    788         assert allclose(domain.quantities['friction'].get_values(),
    789                         [[ 10.09, 10.09, 10.09],
    790                          [ 10.09, 10.09, 10.09],
    791                          [ 10.07, 10.07, 10.07],
    792                          [ 10.07, 10.07, 10.07],
    793                          [ 11.0,  11.0,  11.0],
    794                          [ 11.0,  11.0,  11.0]])
     786        assert num.allclose(domain.quantities['friction'].get_values(),
     787                            [[ 10.09, 10.09, 10.09],
     788                             [ 10.09, 10.09, 10.09],
     789                             [ 10.07, 10.07, 10.07],
     790                             [ 10.07, 10.07, 10.07],
     791                             [ 11.0,  11.0,  11.0],
     792                             [ 11.0,  11.0,  11.0]])
    795793
    796794#-------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.