source: trunk/anuga_core/source/anuga/pmesh/test_meshquad.py @ 8879

Last change on this file since 8879 was 8690, checked in by steve, 12 years ago

Rolling in Padarn's update to fit_interpolation

File size: 5.1 KB
Line 
1import unittest
2import numpy as num
3
4from anuga.geometry.aabb import AABB
5from quad import Cell
6from mesh_quadtree import MeshQuadtree
7from anuga.abstract_2d_finite_volumes.general_mesh import General_mesh as Mesh
8
9import sys
10
11#-------------------------------------------------------------
12
13class Test_Quad(unittest.TestCase):
14
15    def setUp(self):
16        pass
17
18    def tearDown(self):
19        pass
20
21    def test_build_quadtree(self):
22
23        a = [3, 7]
24        b = [5, 7]
25        c = [5, 5]
26        d = [7, 7]
27        e = [15, 15]
28        f = [15, 30]
29        g = [30, 10]
30        h = [30, 30]
31
32        points = [a, b, c, d, e, f, g, h]
33       
34        #bac, bce, ecf, dbe, daf, dae
35        vertices = [[1,0,2], [1,3,4], [1,2,3], [5,4,7], [4,6,7]]
36
37        mesh = Mesh(points, vertices)
38   
39        Q = MeshQuadtree(mesh)
40        #Q.show()
41        #print Q.count()
42        self.assertEqual(Q.count(), len(vertices))
43
44        # test a point that falls within a triangle
45        result = Q.search([10, 10])
46        assert isinstance(result, (list, tuple)), 'should be a list'
47         
48        # Padarn Note: The result of Q.search is no longer in
49        # the same format, and so this test fails. However, the
50        # old functionality does not seem to be needed.                   
51        #self.assertEqual(result[0][0][0], 1)
52
53
54    def test_build_quadtreeII(self):
55
56        self.cell = Cell(AABB(100, 140, 0, 40), 'cell')
57
58        p0 = [34.6292076111,-7999.92529297]
59        p1 = [8000.0, 7999.0]
60        p2 = [-7999.96630859, 7999.0]
61        p3 = [34, 7999.97021484]
62
63        points = [p0,p1,p2, p3]
64        #bac, bce, ecf, dbe, daf, dae
65        vertices = [[0,1,2],[0,2,3]]
66
67        mesh = Mesh(points, vertices)
68
69        #This was causing round off error
70        Q = MeshQuadtree(mesh)
71       
72    def NOtest_interpolate_one_point_many_triangles(self):
73        # this test has 10 triangles that share the same vert.
74        # If the number of points per cell in  a quad tree is less
75        # than 10 it should crash
76        z0 = [2.0, 5.0]
77        z1 = [2.0, 5.0]
78        z2 = [2.0, 5.0]
79        z3 = [2.0, 5.0]
80        z4 = [2.0, 5.0]
81        z5 = [2.0, 5.0]
82        z6 = [2.0, 5.0]
83        z7 = [2.0, 5.0]
84        z8 = [2.0, 5.0]
85        z9 = [2.0, 5.0]
86        z10 = [2.0, 5.0]
87       
88        v0 = [0.0, 0.0]
89        v1 = [1.0, 0.0]
90        v2 = [2.0, 0.0]
91        v3 = [3.0, 0.0]
92        v4 = [4.0, 0.0]
93        v5 = [0.0, 10.0]
94        v6 = [1.0, 10.0]
95        v7 = [2.0, 10.0]
96        v8 = [3.0, 10.0]
97        v9 = [4.0, 10.0]
98
99        vertices = [z0,v0, v1, v2, v3,v4 ,v5, v6, v7, v8, v9,
100                    z1, z2, z3, z4, z5, z6, z7, z8, z9]
101        triangles = [
102                      [11,1,2],
103                      [12,2,3],
104                      [13,3,4],
105                      [14,4,5],
106                      [7,6,15],
107                      [8,7,16],
108                      [9,8,17],
109                      [10,9,18],
110                      [6,1,19],
111                      [5,10,0]
112                      ]
113       
114        mesh = Mesh(vertices, triangles)
115        try:
116            Q = MeshQuadtree(mesh, max_points_per_cell = 9)
117        except RuntimeError:
118            pass
119        else:
120            self.failUnless(0 ==1,  'many verts at the same position no  \
121            longer causes as error')
122   
123    def test_retrieve_triangles(self):
124
125        cell = Cell(AABB(0, 6, 0, 6), 'cell')
126
127        p0 = [2,1]
128        p1 = [4,1]
129        p2 = [4.,4]
130        p3 = [2,4]
131        p4 = [5,4]
132
133        points = [p0,p1,p2, p3, p4]
134        #
135        vertices = [[0,1,2],[0,2,3],[1,4,2]]
136
137        mesh = Mesh(points, vertices)
138
139        Q = MeshQuadtree(mesh)
140        results = Q.search([4.5, 3])
141        # Padarn Note: The result of Q.search is no longer in
142        # the same format, and so this test fails. However, the
143        # old functionality does not seem to be needed.
144        #assert len(results) == 1
145        #self.assertEqual(results[0][0][0], 2)
146        #results = Q.search([5,4.])
147        #self.assertEqual(len(results),1)
148        #self.assertEqual(results[0][0][0], 2)
149       
150    def NOtest_num_visits(self):
151        """ Test optimisation code.
152        """
153        a = [3, 7]
154        b = [5, 7]
155        c = [5, 5]
156        d = [7, 7]
157        e = [15, 15]
158        f = [15, 30]
159        g = [30, 10]
160        h = [30, 30]
161
162        points = [a, b, c, d, e, f, g, h]
163       
164        #bac, bce, ecf, dbe, daf, dae
165        vertices = [[1,0,2], [1,3,4], [1,2,3], [5,4,7], [4,6,7]]
166
167        mesh = Mesh(points, vertices)
168
169        Q = MeshQuadtree(mesh)   
170
171
172        results = Q.search_fast([5.5, 5.5])
173        print 'visits: ', Q.count_visits()
174       
175        Q.clear_visits()
176        results = Q.search_fast([30, 10])
177        print 'visits: ', Q.count_visits()
178       
179        print 'second time:'
180
181        Q.clear_visits()       
182        results = Q.search_fast([5.5, 5.5])
183        print 'visits: ', Q.count_visits()
184################################################################################
185
186if __name__ == "__main__":
187    mysuite = unittest.makeSuite(Test_Quad,'test')
188    runner = unittest.TextTestRunner()
189    runner.run(mysuite)
Note: See TracBrowser for help on using the repository browser.