Changeset 7710
- Timestamp:
- May 7, 2010, 12:25:58 PM (15 years ago)
- Location:
- anuga_core/source/anuga
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/fit_interpolate/fit.py
r7707 r7710 57 57 mesh_origin=None, 58 58 alpha = None, 59 verbose=False, 60 max_vertices_per_cell=None): 59 verbose=False): 61 60 62 61 … … 79 78 If specified vertex coordinates are assumed to be 80 79 relative to their respective origins. 81 82 max_vertices_per_cell: Number of vertices in a quad tree cell83 at which the cell is split into 4.84 80 85 81 Note: Don't supply a vertex coords as a geospatial object and … … 103 99 mesh, 104 100 mesh_origin, 105 verbose, 106 max_vertices_per_cell) 101 verbose) 107 102 108 103 m = self.mesh.number_of_nodes # Nbr of basis functions (vertices) -
anuga_core/source/anuga/fit_interpolate/general_fit_interpolate.py
r7690 r7710 54 54 mesh=None, 55 55 mesh_origin=None, 56 verbose=False, 57 max_vertices_per_cell=None): 56 verbose=False): 58 57 59 58 … … 82 81 relative to their respective origins. 83 82 84 max_vertices_per_cell: Number of vertices in a quad tree cell85 at which the cell is split into 4.86 87 83 Note: Don't supply a vertex coords as a geospatial object and 88 84 a mesh origin, since geospatial has its own mesh origin. 89 85 """ 90 86 global build_quadtree_time 91 if max_vertices_per_cell == None:92 max_vertices_per_cell = MAX_VERTICES_PER_CELL93 87 if mesh is None: 94 88 if vertex_coordinates is not None and triangles is not None: … … 113 107 #This stores indices of vertices 114 108 t0 = time.time() 115 self.root = build_quadtree(self.mesh, 116 max_points_per_cell = max_vertices_per_cell) 109 self.root = build_quadtree(self.mesh) 117 110 118 111 build_quadtree_time = time.time()-t0 -
anuga_core/source/anuga/fit_interpolate/interpolate.py
r7707 r7710 57 57 # @param interpolation_points Points to interpolate to. 58 58 # @param mesh_origin A geo_ref object or 3-tuples of UTMzone, easting, northing. 59 # @param max_vertices_per_cell Max number of vertices before splitting cell.60 59 # @param start_blocking_len Block if # of points greater than this. 61 60 # @param use_cache If True, cache. … … 66 65 interpolation_points, 67 66 mesh_origin=None, 68 max_vertices_per_cell=None,69 67 start_blocking_len=500000, 70 68 use_cache=False, … … 103 101 relative to their respective origins. 104 102 105 max_vertices_per_cell: Number of vertices in a quad tree cell106 at which the cell is split into 4.107 108 103 Note: Don't supply a vertex coords as a geospatial 109 104 object and a mesh origin, since geospatial has its … … 136 131 ensure_numeric(triangles)) 137 132 kwargs = {'mesh_origin': mesh_origin, 138 'max_vertices_per_cell': max_vertices_per_cell,139 133 'verbose': verbose} 140 134 … … 175 169 triangles, 176 170 mesh_origin=None, 177 verbose=False, 178 max_vertices_per_cell=None): 171 verbose=False): 179 172 180 173 """ Build interpolation matrix mapping from … … 209 202 triangles=triangles, 210 203 mesh_origin=mesh_origin, 211 verbose=verbose, 212 max_vertices_per_cell=max_vertices_per_cell) 204 verbose=verbose) 213 205 214 206 # Initialise variables -
anuga_core/source/anuga/fit_interpolate/test_interpolate.py
r7685 r7710 307 307 308 308 data = [ [4,4] ] 309 interp = Interpolate(points, triangles, 310 max_vertices_per_cell = 4) 309 interp = Interpolate(points, triangles) 311 310 #print "PDSG - interp.get_A()", interp.get_A() 312 311 answer = [ [ 0.06666667, 0.46666667, 0.46666667, 0., -
anuga_core/source/anuga/fit_interpolate/test_search_functions.py
r7707 r7710 50 50 mesh.check_integrity() 51 51 52 root = build_quadtree(mesh , max_points_per_cell = 1)52 root = build_quadtree(mesh) 53 53 set_last_triangle() 54 54 … … 58 58 found, s0, s1, s2, k = search_tree_of_vertices(root, mesh, [0, 0]) 59 59 assert found is True 60 61 60 61 62 62 def test_small(self): 63 63 """test_small: Two triangles … … 70 70 mesh.check_integrity() 71 71 72 root = build_quadtree(mesh , max_points_per_cell = 1)72 root = build_quadtree(mesh) 73 73 set_last_triangle() 74 74 … … 76 76 found, s0, s1, s2, k = search_tree_of_vertices(root, mesh, x) 77 77 assert k == 1 # Triangle one 78 assert found is True 79 78 assert found is True 79 80 80 def test_bigger(self): 81 81 """test_bigger … … 90 90 mesh.check_integrity() 91 91 92 root = build_quadtree(mesh , max_points_per_cell = 4)92 root = build_quadtree(mesh) 93 93 set_last_triangle() 94 94 … … 98 98 99 99 found, s0, s1, s2, k = search_tree_of_vertices(root, mesh, 100 ensure_numeric(x)) 101 100 ensure_numeric(x)) 101 102 102 if k >= 0: 103 103 V = mesh.get_vertex_coordinates(k) # nodes for triangle k … … 121 121 122 122 123 for m in range(8): 124 root = build_quadtree(mesh, max_points_per_cell = m) 125 set_last_triangle() 126 #print m, root.show() 127 128 for x in [[0.6, 0.3], [0.1, 0.2], [0.7,0.7], 129 [0.1,0.9], [0.4,0.6], [0.9,0.1], 130 [10, 3]]: 131 132 found, s0, s1, s2, k = search_tree_of_vertices(root, mesh, x) 133 134 if k >= 0: 135 V = mesh.get_vertex_coordinates(k) # nodes for triangle k 136 assert is_inside_triangle(x, V, closed=True) 137 assert is_inside_polygon(x, V) 138 assert found is True 139 else: 140 assert found is False 141 123 124 root = build_quadtree(mesh) 125 set_last_triangle() 126 #print m, root.show() 127 128 for x in [[0.6, 0.3], [0.1, 0.2], [0.7,0.7], 129 [0.1,0.9], [0.4,0.6], [0.9,0.1], 130 [10, 3]]: 142 131 143 if m == k == 0: return 132 found, s0, s1, s2, k = search_tree_of_vertices(root, mesh, x) 133 134 if k >= 0: 135 V = mesh.get_vertex_coordinates(k) # nodes for triangle k 136 assert is_inside_triangle(x, V, closed=True) 137 assert is_inside_polygon(x, V) 138 assert found is True 139 else: 140 assert found is False 141 142 143 if k == 0: return 144 144 145 145 def test_underlying_function(self): … … 150 150 mesh = Mesh(points, vertices, boundary) 151 151 152 root = build_quadtree(mesh , max_points_per_cell = 4)152 root = build_quadtree(mesh) 153 153 set_last_triangle() 154 154 … … 157 157 158 158 triangles = _trilist_from_indices(mesh, root.search(x[0], x[1])) 159 159 160 160 found, sigma0, sigma1, sigma2, k = \ 161 161 _search_triangles_of_vertices(triangles, x) -
anuga_core/source/anuga/utilities/quad.py
r7709 r7710 9 9 import string, types, sys 10 10 import anuga.utilities.log as log 11 from anuga.utilities.aabb import AABB 11 12 12 # Allow children to be slightly bigger than their parents to prevent straddling of a boundary13 SPLIT_BORDER_RATIO = 0.5514 15 class AABB:16 """Axially-aligned bounding box class.17 """18 19 def __init__(self, xmin, xmax, ymin, ymax):20 self.xmin = xmin21 self.xmax = xmax22 self.ymin = ymin23 self.ymax = ymax24 25 def __repr__(self):26 return '(xmin:%f, xmax:%f, ymin:%f, ymax:%f)' \27 % (round(self.xmin,1), round(self.xmax,1), round(self.ymin,1), round(self.ymax, 1))28 29 def size(self):30 """return size as (w,h)"""31 return self.xmax - self.xmin, self.ymax - self.ymin32 33 def split(self, border=SPLIT_BORDER_RATIO):34 """Split along shorter axis.35 return 2 subdivided AABBs.36 """37 38 width, height = self.size()39 assert width >= 0 and height >= 040 41 if (width > height):42 # split vertically43 return AABB(self.xmin, self.xmin+width*border, self.ymin, self.ymax), \44 AABB(self.xmax-width*border, self.xmax, self.ymin, self.ymax)45 else:46 # split horizontally47 return AABB(self.xmin, self.xmax, self.ymin, self.ymin+height*border), \48 AABB(self.xmin, self.xmax, self.ymax-height*border, self.ymax)49 50 def is_trivial_in(self, test):51 if (test.xmin < self.xmin) or (test.xmax > self.xmax):52 return False53 if (test.ymin < self.ymin) or (test.ymax > self.ymax):54 return False55 return True56 57 def contains(self, x, y):58 return (self.xmin <= x <= self.xmax) and (self.ymin <= y <= self.ymax)59 13 60 14 class Cell(TreeNode): … … 63 17 One cell in the plane delimited by southern, northern, 64 18 western, eastern boundaries. 65 66 Public Methods:67 insert(point)68 search(x, y)69 split()70 store()71 retrieve()72 count()73 19 """ 74 20 … … 88 34 def __repr__(self): 89 35 str = '%s: leaves: %d' \ 90 % (self.name , len(self.leaves)) 36 % (self.name , len(self.leaves)) 91 37 if self.children: 92 38 str += ', children: %d' % (len(self.children)) … … 211 157 #from anuga.pmesh.mesh import Mesh 212 158 213 def build_quadtree(mesh , max_points_per_cell = 4):159 def build_quadtree(mesh): 214 160 """Build quad tree for mesh. 215 161 216 All vert ices in mesh are stored inquadtree and a reference162 All vertex indices in mesh are stored in a quadtree and a reference 217 163 to the root is returned. 218 164 """ 219 220 221 #Make root cell 222 #print mesh.coordinates 223 224 xmin, xmax, ymin, ymax = mesh.get_extent(absolute=True) 225 226 # Ensure boundary points are fully contained in region 227 # It is a property of the cell structure that 228 # points on xmax or ymax of any given cell 229 # belong to the neighbouring cell. 230 # Hence, the root cell needs to be expanded slightly 231 ymax += (ymax-ymin)/10 232 xmax += (xmax-xmin)/10 233 234 # To avoid round off error 235 ymin -= (ymax-ymin)/10 236 xmin -= (xmax-xmin)/10 237 238 #print "xmin", xmin 239 #print "xmax", xmax 240 #print "ymin", ymin 241 #print "ymax", ymax 242 243 root = Cell(AABB(xmin, xmax, ymin, ymax)) 165 extents = AABB(*mesh.get_extent(absolute=True)) 166 extents.grow(1.001) # To avoid round off error 167 root = Cell(extents) 244 168 245 169 N = len(mesh) … … 247 171 # Get x,y coordinates for all vertices for all triangles 248 172 V = mesh.get_vertex_coordinates(absolute=True) 249 173 250 174 # Check each triangle 251 175 for i in range(N):
Note: See TracChangeset
for help on using the changeset viewer.