Ignore:
Timestamp:
Oct 4, 2006, 11:00:56 AM (18 years ago)
Author:
ole
Message:

Added functionality for getting arbitrary interpolated values in Quantity as well as calculating inundation height and location. This work was done at SUT during the last week of September 2006.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/fit_interpolate/test_interpolate.py

    r3563 r3689  
    105105        assert allclose(interp._build_interpolation_matrix_A(data).todense(),
    106106                        [[1./3, 1./3, 1./3]])
     107
     108
     109
     110    def test_simple_interpolation_example(self):
     111       
     112        from mesh_factory import rectangular
     113        from shallow_water import Domain
     114        from Numeric import zeros, Float
     115        from abstract_2d_finite_volumes.quantity import Quantity
     116
     117        #Create basic mesh
     118        points, vertices, boundary = rectangular(1, 3)
     119
     120        #Create shallow water domain
     121        domain = Domain(points, vertices, boundary)
     122
     123        #---------------
     124        #Constant values
     125        #---------------       
     126        quantity = Quantity(domain,[[0,0,0],[1,1,1],[2,2,2],[3,3,3],
     127                                    [4,4,4],[5,5,5]])
     128
     129
     130        x, y, vertex_values, triangles = quantity.get_vertex_values(xy=True, smooth=False)
     131        vertex_coordinates = concatenate( (x[:, NewAxis], y[:, NewAxis]), axis=1 )
     132        # FIXME: This concat should roll into get_vertex_values
     133
     134
     135        # Get interpolated values at centroids
     136        interpolation_points = domain.get_centroid_coordinates()
     137        answer = quantity.get_values(location='centroids')
     138
     139        I = Interpolate(vertex_coordinates, triangles)
     140        result = I.interpolate(vertex_values, interpolation_points)
     141        assert allclose(result, answer)
     142
     143
     144        #---------------
     145        #Variable values
     146        #---------------
     147        quantity = Quantity(domain,[[0,1,2],[3,1,7],[2,1,2],[3,3,7],
     148                                    [1,4,-9],[2,5,0]])
     149       
     150        x, y, vertex_values, triangles = quantity.get_vertex_values(xy=True, smooth=False)
     151        vertex_coordinates = concatenate( (x[:, NewAxis], y[:, NewAxis]), axis=1 )
     152        # FIXME: This concat should roll into get_vertex_values
     153
     154
     155        # Get interpolated values at centroids
     156        interpolation_points = domain.get_centroid_coordinates()
     157        answer = quantity.get_values(location='centroids')
     158
     159        I = Interpolate(vertex_coordinates, triangles)
     160        result = I.interpolate(vertex_values, interpolation_points)
     161        assert allclose(result, answer)       
     162       
    107163
    108164    def test_quad_tree(self):
     
    770826
    771827       
    772     def test_interpolate_reuse(self):
     828    def test_interpolate_reuse_if_None(self):
    773829        a = [-1.0, 0.0]
    774830        b = [3.0, 4.0]
     
    827883        except:
    828884            pass
     885       
     886    def xxtest_interpolate_reuse_if_same(self):
     887
     888        # This on tests that repeated identical interpolation
     889        # points makes use of precomputed matrix (Ole)
     890        # This is not really a test and is disabled for now
     891       
     892        a = [-1.0, 0.0]
     893        b = [3.0, 4.0]
     894        c = [4.0, 1.0]
     895        d = [-3.0, 2.0] #3
     896        e = [-1.0, -2.0]
     897        f = [1.0, -2.0] #5
     898
     899        vertices = [a, b, c, d,e,f]
     900        triangles = [[0,1,3], [1,0,2], [0,4,5], [0,5,2]] #abd bac aef afc
     901
     902
     903        point_coords = [[-2.0, 2.0],
     904                        [-1.0, 1.0],
     905                        [0.0, 2.0],
     906                        [1.0, 1.0],
     907                        [2.0, 1.0],
     908                        [0.0, 0.0],
     909                        [1.0, 0.0],
     910                        [0.0, -1.0],
     911                        [-0.2, -0.5],
     912                        [-0.9, -1.5],
     913                        [0.5, -1.9],
     914                        [3.0, 1.0]]
     915
     916        interp = Interpolate(vertices, triangles)
     917        f = array([linear_function(vertices),2*linear_function(vertices) ])
     918        f = transpose(f)
     919        z = interp.interpolate(f, point_coords)
     920        answer = [linear_function(point_coords),
     921                  2*linear_function(point_coords) ]
     922        answer = transpose(answer)
     923
     924        assert allclose(z, answer)
     925        assert allclose(interp._A_can_be_reused, True)
     926
     927
     928        z = interp.interpolate(f)    # None
     929        assert allclose(z, answer)       
     930        z = interp.interpolate(f, point_coords) # Repeated (not really a test)       
     931        assert allclose(z, answer)
    829932       
    830933
     
    14691572
    14701573    suite = unittest.makeSuite(Test_Interpolate,'test')
    1471     #suite = unittest.makeSuite(Test_Interpolate,'test_interpolate_sww2csv')
     1574    #suite = unittest.makeSuite(Test_Interpolate,'test_interpolation_function_outside_point')
    14721575    runner = unittest.TextTestRunner(verbosity=1)
    14731576    runner.run(suite)
Note: See TracChangeset for help on using the changeset viewer.