Ignore:
Timestamp:
Mar 19, 2009, 1:43:34 PM (15 years ago)
Author:
rwilson
Message:

Merged trunk into numpy, all tests and validations work.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/numpy/anuga/fit_interpolate/test_search_functions.py

    r6360 r6553  
    55from search_functions import search_tree_of_vertices, set_last_triangle
    66from search_functions import _search_triangles_of_vertices
     7from search_functions import compute_interpolation_values
    78
    89from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh
     
    1011from anuga.utilities.polygon import is_inside_polygon
    1112from anuga.utilities.quad import build_quadtree, Cell
    12 
     13from anuga.utilities.numerical_tools import ensure_numeric
     14from anuga.utilities.polygon import is_inside_polygon, is_inside_triangle   
     15
     16import numpy as num
    1317
    1418class Test_search_functions(unittest.TestCase):
     
    4953
    5054        x = [0.2, 0.7]
    51         found, s0, s1, s2, k = search_tree_of_vertices(root, mesh, x)
     55        found, s0, s1, s2, k = search_tree_of_vertices(root, x)
    5256        assert k == 1 # Triangle one
    5357        assert found is True
    5458
    5559    def test_bigger(self):
    56         """test_larger mesh
     60        """test_bigger
     61       
     62        test larger mesh
    5763        """
    5864
     
    6975                  [0.1,0.9], [0.4,0.6], [0.9,0.1],
    7076                  [10, 3]]:
    71                
    72             found, s0, s1, s2, k = search_tree_of_vertices(root, mesh, x)
     77           
     78            found, s0, s1, s2, k = search_tree_of_vertices(root,
     79                                                           ensure_numeric(x))
    7380
    7481            if k >= 0:
     
    102109                      [10, 3]]:
    103110               
    104                 found, s0, s1, s2, k = search_tree_of_vertices(root, mesh, x)
     111                found, s0, s1, s2, k = search_tree_of_vertices(root, x)
    105112
    106113                if k >= 0:
     
    111118                    assert found is False               
    112119
    113                
     120           
     121                if m == k == 0: return   
    114122
    115123    def test_underlying_function(self):
     
    124132
    125133        # One point
    126         x = [0.5, 0.5]
     134        x = ensure_numeric([0.5, 0.5])
    127135        candidate_vertices = root.search(x[0], x[1])
    128136
    129137        #print x, candidate_vertices
    130138        found, sigma0, sigma1, sigma2, k = \
    131                _search_triangles_of_vertices(mesh,
    132                                              candidate_vertices,
     139               _search_triangles_of_vertices(candidate_vertices,
    133140                                             x)
    134141
     
    151158            #print x, candidate_vertices
    152159            found, sigma0, sigma1, sigma2, k = \
    153                    _search_triangles_of_vertices(mesh,
    154                                                  candidate_vertices,
    155                                                  x)
     160                   _search_triangles_of_vertices(candidate_vertices,
     161                                                 ensure_numeric(x))
    156162            if k >= 0:
    157163                V = mesh.get_vertex_coordinates(k) # nodes for triangle k
     
    199205        x = [2.5, 1.5]
    200206        element_found, sigma0, sigma1, sigma2, k = \
    201                        search_tree_of_vertices(root, mesh, x)
     207                       search_tree_of_vertices(root, x)
    202208        # One point
    203209        x = [3.00005, 2.999994]
    204210        element_found, sigma0, sigma1, sigma2, k = \
    205                        search_tree_of_vertices(root, mesh, x)
     211                       search_tree_of_vertices(root, x)
    206212        assert element_found is True
    207213        assert k == 1
    208214       
    209 ################################################################################
    210 
     215       
     216    def test_compute_interpolation_values(self):
     217        """test_compute_interpolation_values
     218       
     219        Test that interpolation values are correc
     220       
     221        This test used to check element_found as output from
     222        find_triangle_compute_interpolation(triangle, n0, n1, n2, x)
     223        and that failed before 18th March 2009.
     224       
     225        Now this function no longer returns this flag, so the test
     226        is merely checknig the sigmas.
     227       
     228        """
     229       
     230        triangle = num.array([[306951.77151059, 6194462.14596986],
     231                              [306952.58403545, 6194459.65001246],
     232                              [306953.55109034, 6194462.0041216]])
     233
     234
     235        n0 = [0.92499377, -0.37998227]
     236        n1 = [0.07945684,  0.99683831]
     237        n2 = [-0.95088404, -0.30954732]
     238       
     239        x = [306953.344, 6194461.5]
     240       
     241        # Test that point is indeed inside triangle
     242        assert is_inside_polygon(x, triangle,
     243                                 closed=True, verbose=False)
     244        assert is_inside_triangle(x, triangle,
     245                                  closed=True, verbose=False)                                 
     246       
     247        sigma0, sigma1, sigma2 = \
     248            compute_interpolation_values(triangle, n0, n1, n2, x)
     249           
     250        msg = 'Point which is clearly inside triangle was not found'
     251        assert abs(sigma0 + sigma1 + sigma2 - 1) < 1.0e-6, msg
     252
     253#-------------------------------------------------------------
    211254if __name__ == "__main__":
    212     suite = unittest.makeSuite(Test_search_functions,'test')
    213     runner = unittest.TextTestRunner() #verbosity=1)
     255    suite = unittest.makeSuite(Test_search_functions, 'test')
     256    runner = unittest.TextTestRunner(verbosity=1)
    214257    runner.run(suite)
    215258   
Note: See TracChangeset for help on using the changeset viewer.