Changeset 6236
- Timestamp:
- Jan 29, 2009, 2:37:50 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/fit_interpolate/fit.py
r6232 r6236 34 34 from anuga.fit_interpolate.general_fit_interpolate import FitInterpolate 35 35 from anuga.utilities.sparse import Sparse, Sparse_CSR 36 from anuga.utilities.polygon import in _and_outside_polygon36 from anuga.utilities.polygon import inside_polygon 37 37 from anuga.fit_interpolate.search_functions import search_tree_of_vertices 38 38 … … 46 46 47 47 import Numeric as num 48 49 50 #DEFAULT_ALPHA = 0.00151 48 52 49 … … 137 134 self.B = self.AtA 138 135 139 # Convert self.B matrix to CSR format for faster matrix vector136 # Convert self.B matrix to CSR format for faster matrix vector 140 137 self.B = Sparse_CSR(self.B) 141 138 … … 166 163 """ 167 164 168 # FIXME: algorithm might be optimised by computing local 9x9169 # "element stiffness matrices:165 # FIXME: algorithm might be optimised by computing local 9x9 166 # "element stiffness matrices: 170 167 171 168 m = self.mesh.number_of_nodes # Nbr of basis functions (1/vertex) … … 173 170 self.D = Sparse(m,m) 174 171 175 # For each triangle compute contributions to D = D1+D2172 # For each triangle compute contributions to D = D1+D2 176 173 for i in range(len(self.mesh)): 177 174 178 # Get area175 # Get area 179 176 area = self.mesh.areas[i] 180 177 181 # Get global vertex indices178 # Get global vertex indices 182 179 v0 = self.mesh.triangles[i,0] 183 180 v1 = self.mesh.triangles[i,1] 184 181 v2 = self.mesh.triangles[i,2] 185 182 186 # Get the three vertex_points183 # Get the three vertex_points 187 184 xi0 = self.mesh.get_vertex_coordinate(i, 0) 188 185 xi1 = self.mesh.get_vertex_coordinate(i, 1) 189 186 xi2 = self.mesh.get_vertex_coordinate(i, 2) 190 187 191 # Compute gradients for each vertex188 # Compute gradients for each vertex 192 189 a0, b0 = gradient(xi0[0], xi0[1], xi1[0], xi1[1], xi2[0], xi2[1], 193 190 1, 0, 0) … … 199 196 0, 0, 1) 200 197 201 # Compute diagonal contributions198 # Compute diagonal contributions 202 199 self.D[v0,v0] += (a0*a0 + b0*b0)*area 203 200 self.D[v1,v1] += (a1*a1 + b1*b1)*area 204 201 self.D[v2,v2] += (a2*a2 + b2*b2)*area 205 202 206 # Compute contributions for basis functions sharing edges203 # Compute contributions for basis functions sharing edges 207 204 e01 = (a0*a1 + b0*b1)*area 208 205 self.D[v0,v1] += e01 … … 246 243 The number of attributes of the data points does not change 247 244 """ 248 #Build n x m interpolation matrix249 245 246 # Build n x m interpolation matrix 250 247 if self.AtA == None: 251 248 # AtA and Atz need to be initialised. … … 265 262 self.point_count += point_coordinates.shape[0] 266 263 267 #if verbose: print 'Getting indices inside mesh boundary' 268 269 inside_poly_indices, outside_poly_indices = \ 270 in_and_outside_polygon(point_coordinates, 271 self.mesh_boundary_polygon, 272 closed = True, 273 verbose = False) # There's too much output if True 274 #print "self.inside_poly_indices",self.inside_poly_indices 275 #print "self.outside_poly_indices",self.outside_poly_indices 276 277 278 n = len(inside_poly_indices) 279 #if verbose: print 'Building fitting matrix from %d points' %n 280 281 #Compute matrix elements for points inside the mesh 282 triangles = self.mesh.triangles #Did this for speed, did ~nothing 283 for d, i in enumerate(inside_poly_indices): 264 265 inside_indices = inside_polygon(point_coordinates, 266 self.mesh_boundary_polygon, 267 closed=True, 268 verbose=False) # Too much output if True 269 270 271 n = len(inside_indices) 272 273 # Compute matrix elements for points inside the mesh 274 triangles = self.mesh.triangles # Shorthand 275 for d, i in enumerate(inside_indices): 284 276 # For each data_coordinate point 285 277 # if verbose and d%((n+10)/10)==0: print 'Doing %d of %d' %(d, n) … … 307 299 AtA[j,k] += sigmas[j]*sigmas[k] 308 300 else: 309 msg = 'Could not find triangle for point', x 301 msg = 'Could not find triangle for point %s. ' % str(x) 302 msg += 'Mesh boundary is %s' % str(self.mesh_boundary_polygon) 310 303 raise Exception(msg) 311 304 self.AtA = AtA 305 312 306 313 307 def fit(self, point_coordinates_or_filename=None, z=None, … … 329 323 330 324 """ 331 # use blocking to load in the point info 325 326 # Use blocking to load in the point info 332 327 if type(point_coordinates_or_filename) == types.StringType: 333 328 msg = "Don't set a point origin when reading from a file" … … 359 354 360 355 points = geo_block.get_data_points(absolute=True) 361 #print "fit points", points362 356 z = geo_block.get_attributes(attribute_name=attribute_name) 363 357 self.build_fit_subset(points, z, verbose=verbose) … … 373 367 assert self.Atz <> None 374 368 375 # FIXME (DSG) - do a message369 # FIXME (DSG) - do a message 376 370 else: 377 371 point_coordinates = ensure_absolute(point_coordinates, 378 372 geo_reference=point_origin) 379 # if isinstance(point_coordinates,Geospatial_data) and z is None:373 # if isinstance(point_coordinates,Geospatial_data) and z is None: 380 374 # z will come from the geo-ref 381 375 self.build_fit_subset(point_coordinates, z, verbose) 382 376 383 # Check sanity377 # Check sanity 384 378 m = self.mesh.number_of_nodes # Nbr of basis functions (1/vertex) 385 379 n = self.point_count … … 457 451 alpha=DEFAULT_ALPHA, 458 452 verbose=False, 459 acceptable_overshoot=1.01, # FIXME: Move to config - this value is assumed in caching test 453 acceptable_overshoot=1.01, 454 # FIXME: Move to config - this value is assumed in caching test 455 # FIXME(Ole): Just realised that this was never implemented (29 Jan 2009). I suggest removing it altogether. 460 456 mesh_origin=None, 461 457 data_origin=None,
Note: See TracChangeset
for help on using the changeset viewer.