Changeset 8578 for trunk/anuga_core/source/anuga/fit_interpolate/fit.py
- Timestamp:
- Sep 14, 2012, 9:56:39 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/fit_interpolate/fit.py
r8536 r8578 46 46 47 47 import numpy as num 48 import sys 48 49 49 50 … … 100 101 triangles, 101 102 mesh, 102 mesh_origin ,103 verbose )103 mesh_origin=mesh_origin, 104 verbose=verbose) 104 105 105 106 m = self.mesh.number_of_nodes # Nbr of basis functions (vertices) … … 110 111 self.point_count = 0 111 112 if self.alpha <> 0: 112 if verbose: log.critical('Building smoothing matrix') 113 self._build_smoothing_matrix_D() 114 113 if verbose: log.critical('Fit: Building smoothing matrix') 114 self._build_smoothing_matrix_D(verbose=verbose) 115 116 if verbose: log.critical('Fit: Get Boundary Polygon') 115 117 bd_poly = self.mesh.get_boundary_polygon() 116 118 self.mesh_boundary_polygon = ensure_numeric(bd_poly) 119 120 if verbose: log.critical('Fit: Done') 121 117 122 118 123 def _build_coefficient_matrix_B(self, … … 126 131 """ 127 132 133 if verbose: 134 print 'Fit: Build Coefficient Matrix B' 135 136 128 137 if self.alpha <> 0: 129 138 #if verbose: log.critical('Building smoothing matrix') 130 139 #self._build_smoothing_matrix_D() 140 # FIXME SR: This is quite time consuming. 141 # As AtA and D have same structure it should be possible 142 # to speed this up. 131 143 self.B = self.AtA + self.alpha*self.D 132 144 else: 133 145 self.B = self.AtA 134 146 147 148 if verbose: 149 print 'Fit: Convert Coefficient Matrix B to Sparse_CSR' 150 135 151 # Convert self.B matrix to CSR format for faster matrix vector 136 152 self.B = Sparse_CSR(self.B) 137 153 138 def _build_smoothing_matrix_D(self ):154 def _build_smoothing_matrix_D(self, verbose=False): 139 155 """Build m x m smoothing matrix, where 140 156 m is the number of basis functions phi_k (one per vertex) … … 169 185 self.D = Sparse(m,m) 170 186 187 if verbose : 188 print '['+60*' '+']', 189 sys.stdout.flush() 190 191 N = len(self.mesh) 192 M = N/60 193 171 194 # For each triangle compute contributions to D = D1+D2 172 for i in range(len(self.mesh)): 195 for i in xrange(N): 196 197 if verbose and i%M == 0 : 198 #restart_line() 199 print '\r['+(i/M)*'.'+(60-(i/M))*' ' +']', 200 sys.stdout.flush() 173 201 174 202 # Get area … … 212 240 self.D[v2,v0] += e20 213 241 self.D[v0,v2] += e20 242 243 if verbose: 244 print '' 214 245 215 246 def get_D(self): … … 242 273 The number of attributes of the data points does not change 243 274 """ 244 275 276 277 if verbose: 278 print 'Fit: Build Matrix AtA Atz' 279 245 280 # Build n x m interpolation matrix 246 281 if self.AtA == None: … … 271 306 # Compute matrix elements for points inside the mesh 272 307 triangles = self.mesh.triangles # Shorthand 273 for d, i in enumerate(inside_indices): 308 309 310 if verbose : 311 print '['+60*' '+']', 312 sys.stdout.flush() 313 314 m = n/60 315 316 317 for i in xrange(n): 318 d = inside_indices[i] 274 319 # For each data_coordinate point 275 320 # if verbose and d%((n+10)/10)==0: log.critical('Doing %d of %d' 276 321 # %(d, n)) 277 x = point_coordinates[i] 322 323 324 if verbose and i%m == 0 : 325 print '\r['+(i/m)*'.'+(60-(i/m))*' '+']', 326 sys.stdout.flush() 327 328 329 x = point_coordinates[d] 278 330 279 331 element_found, sigma0, sigma1, sigma2, k = \ … … 302 354 303 355 # data point has fallen within a hole - so ignore it. 304 356 357 358 if verbose: 359 print '' 360 305 361 self.AtA = AtA 306 362 … … 324 380 325 381 """ 326 382 383 384 if verbose: 385 print 'Fit.fit: Initializing' 386 327 387 # Use blocking to load in the point info 328 388 if isinstance(point_coordinates_or_filename, basestring): … … 357 417 points = geo_block.get_data_points(absolute=True) 358 418 z = geo_block.get_attributes(attribute_name=attribute_name) 359 self.build_fit_subset(points, z, verbose=verbose)419 self.build_fit_subset(points, z, attribute_name, verbose) 360 420 361 421 # FIXME(Ole): I thought this test would make sense here … … 368 428 else: 369 429 point_coordinates = point_coordinates_or_filename 370 430 431 432 371 433 if point_coordinates is None: 372 if verbose: log.critical(' Warning: no data points in fit')434 if verbose: log.critical('Fit.fit: Warning: no data points in fit') 373 435 msg = 'No interpolation matrix.' 374 436 assert self.AtA is not None, msg … … 381 443 # if isinstance(point_coordinates,Geospatial_data) and z is None: 382 444 # z will come from the geo-ref 383 self.build_fit_subset(point_coordinates, z, verbose) 445 self.build_fit_subset(point_coordinates, z, verbose=verbose) 446 447 448 449 384 450 385 451 # Check sanity … … 393 459 msg += 'positive value,\ne.g. 1.0e-3.' 394 460 raise TooFewPointsError(msg) 461 395 462 396 463 self._build_coefficient_matrix_B(verbose) … … 408 475 #raise VertsWithNoTrianglesError(msg) 409 476 410 477 if verbose: 478 print 'Fit.fit: Solve Fitting Equation' 479 411 480 return conjugate_gradient(self.B, self.Atz, self.Atz, 412 481 imax=2*len(self.Atz) ) … … 575 644 576 645 if verbose: log.critical('FitInterpolate: Building mesh') 577 mesh = Mesh(vertex_coordinates, triangles )578 mesh.check_integrity()646 mesh = Mesh(vertex_coordinates, triangles, verbose=verbose) 647 #mesh.check_integrity() # expensive 579 648 580 649 … … 648 717 old_title_list = mesh_dict['vertex_attribute_titles'] 649 718 650 if verbose: log.critical(' tsh file %s loaded' % mesh_file)719 if verbose: log.critical('Fit_to_Mesh_File: tsh file %s loaded' % mesh_file) 651 720 652 721 # load in the points file … … 668 737 mesh_origin = None 669 738 670 if verbose: log.critical(" points file loaded")671 if verbose: log.critical(" fitting to mesh")739 if verbose: log.critical("Fit_to_Mesh_File: points file loaded") 740 if verbose: log.critical("Fit_to_Mesh_File: fitting to mesh") 672 741 f = fit_to_mesh(point_coordinates, 673 742 vertex_coordinates, … … 679 748 data_origin = None, 680 749 mesh_origin = mesh_origin) 681 if verbose: log.critical(" finished fitting to mesh")750 if verbose: log.critical("Fit_to_Mesh_File: finished fitting to mesh") 682 751 683 752 # convert array to list of lists … … 688 757 old_title_list.extend(title_list) 689 758 #FIXME can this be done a faster way? - DSG 690 for i in range(len(old_point_attributes)):759 for i in xrange(len(old_point_attributes)): 691 760 old_point_attributes[i].extend(new_point_attributes[i]) 692 761 mesh_dict['vertex_attributes'] = old_point_attributes … … 696 765 mesh_dict['vertex_attribute_titles'] = title_list 697 766 698 if verbose: log.critical(" exporting to file %s" % mesh_output_file)767 if verbose: log.critical("Fit_to_Mesh_File: exporting to file %s" % mesh_output_file) 699 768 700 769 try:
Note: See TracChangeset
for help on using the changeset viewer.