Changeset 7707 for anuga_core/source/anuga/utilities/test_quad.py
- Timestamp:
- May 5, 2010, 4:06:02 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/test_quad.py
r7703 r7707 2 2 import numpy as num 3 3 4 from quad import Cell, build_quadtree4 from quad import AABB, Cell, build_quadtree 5 5 from anuga.abstract_2d_finite_volumes.general_mesh import General_mesh as Mesh 6 6 … … 12 12 13 13 def setUp(self): 14 15 a = [3, 107] 16 b = [5, 107] 17 c = [5, 105] 18 d = [7, 107] 19 e = [15, 115] 20 f = [15, 130] 21 g = [30, 110] 22 h = [30, 130] 14 pass 15 16 def tearDown(self): 17 pass 18 19 def test_AABB_contains(self): 20 box = AABB(1, 21, 1, 11) 21 assert box.contains(10, 5) 22 assert box.contains(1, 1) 23 assert box.contains(20, 6) 24 assert not box.contains(-1, -1) 25 assert not box.contains(5, 70) 26 assert not box.contains(6, -70) 27 assert not box.contains(-1, 6) 28 assert not box.contains(50, 6) 29 30 def test_AABB_split_vert(self): 31 parent = AABB(1, 21, 1, 11) 32 33 child1, child2 = parent.split(0.6) 34 35 self.assertEqual(child1.xmin, 1) 36 self.assertEqual(child1.xmax, 13) 37 self.assertEqual(child1.ymin, 1) 38 self.assertEqual(child1.ymax, 11) 39 40 self.assertEqual(child2.xmin, 9) 41 self.assertEqual(child2.xmax, 21) 42 self.assertEqual(child2.ymin, 1) 43 self.assertEqual(child2.ymax, 11) 44 45 def test_AABB_split_horiz(self): 46 parent = AABB(1, 11, 1, 41) 47 48 child1, child2 = parent.split(0.6) 49 50 self.assertEqual(child1.xmin, 1) 51 self.assertEqual(child1.xmax, 11) 52 self.assertEqual(child1.ymin, 1) 53 self.assertEqual(child1.ymax, 25) 54 55 self.assertEqual(child2.xmin, 1) 56 self.assertEqual(child2.xmax, 11) 57 self.assertEqual(child2.ymin, 17) 58 self.assertEqual(child2.ymax, 41) 59 60 def test_add_data(self): 61 cell = Cell(AABB(0,10, 0,5)) 62 cell.insert([(AABB(1,3, 1, 3), 111), (AABB(8,9, 1, 2), 222), \ 63 (AABB(7, 8, 3, 4), 333), (AABB(1, 10, 0, 1), 444)]) 64 65 result = cell.retrieve() 66 assert type(result) in [types.ListType,types.TupleType],\ 67 'should be a list' 68 69 self.assertEqual(len(result),4) 70 71 def test_search(self): 72 test_region = (AABB(8,9, 1, 2), 222) 73 cell = Cell(AABB(0,10, 0,5)) 74 cell.insert([(AABB(1,3, 1, 3), 111), test_region, \ 75 (AABB(7, 8, 3, 4), 333), (AABB(1, 10, 0, 1), 444)]) 76 77 result = cell.search(x = 8.5, y = 1.5, get_vertices=True) 78 assert type(result) in [types.ListType,types.TupleType],\ 79 'should be a list' 80 self.assertEqual(result, [test_region], 'only 1 point should intersect') 81 82 83 def test_clear_1(self): 84 cell = Cell(AABB(0,10, 0,5)) 85 cell.insert([(AABB(1,3, 1, 3), 111), (AABB(8,9, 1, 2), 222), \ 86 (AABB(7, 8, 3, 4), 333), (AABB(1, 10, 0, 1), 444)]) 87 88 assert len(cell.retrieve()) == 4 89 cell.clear() 90 91 assert len(cell.retrieve()) == 0 92 93 def test_build_quadtree(self): 94 95 a = [3, 7] 96 b = [5, 7] 97 c = [5, 5] 98 d = [7, 7] 99 e = [15, 15] 100 f = [15, 30] 101 g = [30, 10] 102 h = [30, 30] 23 103 24 104 points = [a, b, c, d, e, f, g, h] … … 27 107 vertices = [[1,0,2], [1,3,4], [1,2,3], [5,4,7], [4,6,7]] 28 108 29 mesh = Mesh(points, vertices) 30 self.mesh = mesh 31 self.cell = Cell(100, 140, 0, 40, mesh, 'cell') 32 33 def tearDown(self): 34 pass 35 36 def test_add_points_2_cell(self): 37 self.cell.insert(0) 38 self.cell.insert(1) 39 40 result = self.cell.retrieve() 41 assert type(result) in [types.ListType,types.TupleType],\ 42 'should be a list' 43 self.assertEqual(len(result),2) 44 45 def test_add_points_2_cellII(self): 46 self.cell.insert([0,1,2,3,4,5,6,7]) 47 48 result = self.cell.retrieve() 49 assert type(result) in [types.ListType,types.TupleType],\ 50 'should be a list' 51 self.assertEqual(len(result),8) 52 53 54 def test_search(self): 55 self.cell.insert([0,1,2,3,4,5,6,7]) 56 self.cell.split(4) 57 58 result = self.cell.search(x = 1, y = 101, get_vertices=True) 59 assert type(result) in [types.ListType,types.TupleType],\ 60 'should be a list' 61 self.assertEqual(result, [0,1,2,3]) 62 63 64 def test_clear_1(self): 65 self.cell.insert([0,1,2,3,4,5,6,7]) 66 assert self.cell.count() == 8 67 self.cell.clear() 68 69 #This one actually revealed a bug :-) 70 assert self.cell.count() == 0 71 72 def test_clear_2(self): 73 self.cell.insert([0,1,2,3,4,5,6,7]) 74 assert self.cell.count() == 8 75 self.cell.split(2) 76 assert self.cell.count() == 8 77 78 self.cell.clear() 79 assert self.cell.count() == 0 80 81 82 83 def test_split(self): 84 self.cell.insert([0,1,2,3,4,5,6,7], split = False) 85 86 #No children yet 87 assert self.cell.children is None 88 assert self.cell.count() == 8 89 90 #Split 91 self.cell.split(4) 92 #self.cell.show() 93 #self.cell.show_all() 94 95 96 #Now there are children 97 assert self.cell.children is not None 98 assert self.cell.count() == 8 99 100 101 def test_build_quadtree(self): 102 103 Q = build_quadtree(self.mesh) 109 mesh = Mesh(points, vertices) 110 111 Q = build_quadtree(mesh) 104 112 #Q.show() 105 113 #print Q.count() 106 assert Q.count() == 8 107 108 109 110 result = Q.search(3, 105, get_vertices=True) 114 self.assertEqual(Q.count(), len(vertices)) 115 116 # test a point that falls within a triangle 117 result = Q.search(10, 10, get_vertices=True) 111 118 assert type(result) in [types.ListType,types.TupleType],\ 112 113 #print "result",result114 self.assertEqual( result, [0,1,2,3])119 'should be a list' 120 pos, index = result[0] 121 self.assertEqual(index, 1) 115 122 116 123 117 124 def test_build_quadtreeII(self): 118 125 119 self.cell = Cell( 100, 140, 0, 40, 'cell')126 self.cell = Cell(AABB(100, 140, 0, 40), 'cell') 120 127 121 128 p0 = [34.6292076111,-7999.92529297] … … 128 135 vertices = [[0,1,2],[0,2,3]] 129 136 130 137 mesh = Mesh(points, vertices) 131 138 132 139 #This was causing round off error 133 140 Q = build_quadtree(mesh) 134 141 135 def test_interpolate_one_point_many_triangles(self):142 def NOtest_interpolate_one_point_many_triangles(self): 136 143 # this test has 10 triangles that share the same vert. 137 144 # If the number of points per cell in a quad tree is less … … 175 182 ] 176 183 177 184 mesh = Mesh(vertices, triangles) 178 185 try: 179 186 Q = build_quadtree(mesh, max_points_per_cell = 9) … … 186 193 def test_retrieve_triangles(self): 187 194 188 cell = Cell( 0, 6, 0, 6, 'cell', max_points_per_cell=4)195 cell = Cell(AABB(0, 6, 0, 6), 'cell') 189 196 190 197 p0 = [2,1] … … 198 205 vertices = [[0,1,2],[0,2,3],[1,4,2]] 199 206 200 207 mesh = Mesh(points, vertices) 201 208 202 209 Q = build_quadtree(mesh) 203 results = Q.search(5,1) 204 assert len(results),2 205 #print "results", results 206 #print "results[0][0]", results[0][0] 207 assert results[0],0 208 assert results[1],2 209 assert results[0][1],[[ 2., 1.], 210 [ 4., 1.], 211 [ 4., 4.]] 212 assert results[1][1],[[ 4., 1.], 213 [ 5., 4.], 214 [ 4., 4.]] 215 # this is the normals 216 assert results[0][1][1],[[1., 0.], 217 [-0.83205029, 0.5547002], 218 [ 0., -1.]] 219 220 # assert num.allclose(num.array(results),[[[ 2., 1.], 221 #[ 4., 1.], [ 4., 4.]], [[ 4., 1.],[ 5., 4.],[ 4., 4.]]] ) 210 results = Q.search(4.5, 3) 211 assert len(results) == 1 212 self.assertEqual(results[0], 2) 222 213 results = Q.search(5,4.) 223 ### print "results",results 224 # results_dic={} 225 # results_dic.update(results) 226 assert len(results),3 227 #print "results_dic[0]", results_dic[0] 228 assert results[0][1],[[ 2., 1.], 229 [ 4., 1.], 230 [ 4., 4.]] 231 assert results[1][1],[[ 2., 1.], 232 [ 4., 4.], 233 [ 2., 4.]] 234 assert results[2][1],[[ 4., 1.], 235 [ 5., 4.], 236 [ 4., 4.]] 237 #assert allclose(array(results),[[[ 2., 1.],[ 4., 1.], [ 4., 4.]] 238 # ,[[ 2., 1.],[ 4., 4.], [ 2., 4.]], 239 #[[ 4., 1.], [ 5., 4.], [ 4., 4.]], 240 # [[ 4., 1.], [ 5., 4.], [ 4., 4.]]]) 241 214 self.assertEqual(len(results),1) 215 self.assertEqual(results[0], 2) 242 216 ################################################################################ 243 217
Note: See TracChangeset
for help on using the changeset viewer.