Ignore:
Timestamp:
Aug 6, 2007, 9:56:50 AM (17 years ago)
Author:
duncan
Message:

checking in for benchmarking. When fitting cell data - triangle vertices and norms - are calculated the first time a point is looked for in a cell. This is to speed thing up.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/utilities/test_quad.py

    r3945 r4653  
    11import unittest
     2from Numeric import array, allclose
     3
    24from quad import Cell, build_quadtree
    3 
    4 #from domain import *
    55from anuga.abstract_2d_finite_volumes.general_mesh import General_mesh as Mesh
    66
     
    2424
    2525        points = [a, b, c, d, e, f, g, h]
     26       
    2627        #bac, bce, ecf, dbe, daf, dae
    2728        vertices = [[1,0,2], [1,3,4], [1,2,3], [5,4,7], [4,6,7]]
     
    5657        self.cell.split(4)
    5758
    58         result =  self.cell.search(x = 1, y = 101)
     59        result =  self.cell.search(x = 1, y = 101, get_vertices=True)
    5960        assert type(result) in [types.ListType,types.TupleType],\
    6061                                'should be a list'
     
    126127
    127128
    128         result = Q.search(3, 105)
     129        result = Q.search(3, 105, get_vertices=True)
    129130        assert type(result) in [types.ListType,types.TupleType],\
    130131                                'should be a list'
     
    151152        Q = build_quadtree(mesh)
    152153
     154    def test_retrieve_triangles(self):
     155
     156        cell = Cell(0, 6, 0, 6, 'cell', max_points_per_cell=4)
     157
     158        p0 = [2,1]
     159        p1 = [4,1]
     160        p2 = [4.,4]
     161        p3 = [2,4]
     162        p4 = [5,4]
     163
     164        points = [p0,p1,p2, p3, p4]
     165        #
     166        vertices = [[0,1,2],[0,2,3],[1,4,2]]
     167
     168        mesh = Mesh(points, vertices)
     169
     170        Q = build_quadtree(mesh)
     171        results = Q.search(5,1)
     172        assert len(results),2
     173        #print "results", results
     174        #print "results[0][0]", results[0][0]
     175        assert results[0],0
     176        assert results[1],2
     177        assert results[0][1],[[ 2.,  1.],
     178                     [ 4.,  1.],
     179                     [ 4.,  4.]]
     180        assert results[1][1],[[ 4.,  1.],
     181                     [ 5.,  4.],
     182                     [ 4.,  4.]]
     183        # this is the normals
     184        assert results[0][1][1],[[1.,  0.],
     185                     [-0.83205029,  0.5547002],
     186                     [ 0.,  -1.]]
     187                     
     188        # assert allclose(array(results),[[[ 2.,  1.],
     189        #[ 4.,  1.], [ 4.,  4.]], [[ 4.,  1.],[ 5.,  4.],[ 4.,  4.]]] )
     190        results = Q.search(5,4.)
     191        ### print "results",results
     192        # results_dic={}
     193        # results_dic.update(results)
     194        assert len(results),3
     195        #print "results_dic[0]", results_dic[0]
     196        assert results[0][1],[[ 2.,  1.],
     197                     [ 4.,  1.],
     198                     [ 4.,  4.]]
     199        assert results[1][1],[[ 2.,  1.],
     200                     [ 4.,  4.],
     201                     [ 2.,  4.]]
     202        assert results[2][1],[[ 4.,  1.],
     203                     [ 5.,  4.],
     204                     [ 4.,  4.]]
     205        #assert allclose(array(results),[[[ 2.,  1.],[ 4.,  1.], [ 4.,  4.]]
     206         #                               ,[[ 2.,  1.],[ 4.,  4.], [ 2.,  4.]],
     207        #[[ 4.,  1.],  [ 5.,  4.], [ 4.,  4.]],
     208         #                               [[ 4.,  1.], [ 5.,  4.], [ 4.,  4.]]])
     209       
    153210#-------------------------------------------------------------
    154211if __name__ == "__main__":
    155212
    156213    mysuite = unittest.makeSuite(Test_Quad,'test')
     214    # mysuite = unittest.makeSuite(Test_Quad,'test_retrieve_triangles')
    157215    runner = unittest.TextTestRunner()
    158216    runner.run(mysuite)
Note: See TracChangeset for help on using the changeset viewer.