Ignore:
Timestamp:
Sep 14, 2012, 9:56:39 PM (13 years ago)
Author:
steve
Message:

Added extra unit tests for set_stage and set_elevation operators

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/fit_interpolate/fit.py

    r8536 r8578  
    4646
    4747import numpy as num
     48import sys
    4849
    4950
     
    100101                 triangles,
    101102                 mesh,
    102                  mesh_origin,
    103                  verbose)
     103                 mesh_origin=mesh_origin,
     104                 verbose=verbose)
    104105       
    105106        m = self.mesh.number_of_nodes # Nbr of basis functions (vertices)
     
    110111        self.point_count = 0
    111112        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')
    115117        bd_poly = self.mesh.get_boundary_polygon()   
    116118        self.mesh_boundary_polygon = ensure_numeric(bd_poly)
     119
     120        if verbose: log.critical('Fit: Done')
     121
    117122           
    118123    def _build_coefficient_matrix_B(self,
     
    126131        """
    127132
     133        if verbose:
     134            print 'Fit: Build Coefficient Matrix B'
     135
     136
    128137        if self.alpha <> 0:
    129138            #if verbose: log.critical('Building smoothing matrix')
    130139            #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.
    131143            self.B = self.AtA + self.alpha*self.D
    132144        else:
    133145            self.B = self.AtA
    134146
     147
     148        if verbose:
     149            print 'Fit: Convert Coefficient Matrix B to Sparse_CSR'
     150           
    135151        # Convert self.B matrix to CSR format for faster matrix vector
    136152        self.B = Sparse_CSR(self.B)
    137153
    138     def _build_smoothing_matrix_D(self):
     154    def _build_smoothing_matrix_D(self, verbose=False):
    139155        """Build m x m smoothing matrix, where
    140156        m is the number of basis functions phi_k (one per vertex)
     
    169185        self.D = Sparse(m,m)
    170186
     187        if verbose :
     188            print '['+60*' '+']',
     189            sys.stdout.flush()
     190
     191        N = len(self.mesh)
     192        M = N/60
     193
    171194        # 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()
    173201
    174202            # Get area
     
    212240            self.D[v2,v0] += e20
    213241            self.D[v0,v2] += e20
     242
     243        if verbose:
     244            print ''
    214245
    215246    def get_D(self):
     
    242273        The number of attributes of the data points does not change
    243274        """
    244        
     275
     276
     277        if verbose:
     278            print 'Fit: Build Matrix AtA Atz'
     279
    245280        # Build n x m interpolation matrix
    246281        if self.AtA == None:
     
    271306        # Compute matrix elements for points inside the mesh
    272307        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]
    274319            # For each data_coordinate point
    275320            # if verbose and d%((n+10)/10)==0: log.critical('Doing %d of %d'
    276321                                                            # %(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]
    278330           
    279331            element_found, sigma0, sigma1, sigma2, k = \
     
    302354               
    303355                # data point has fallen within a hole - so ignore it.
    304                
     356
     357
     358        if verbose:
     359            print ''
     360           
    305361        self.AtA = AtA
    306362
     
    324380         
    325381        """
    326        
     382
     383
     384        if verbose:
     385            print 'Fit.fit: Initializing'
     386
    327387        # Use blocking to load in the point info
    328388        if isinstance(point_coordinates_or_filename, basestring):
     
    357417                points = geo_block.get_data_points(absolute=True)
    358418                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)
    360420
    361421                # FIXME(Ole): I thought this test would make sense here
     
    368428        else:
    369429            point_coordinates =  point_coordinates_or_filename
    370            
     430
     431
     432
    371433        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')
    373435            msg = 'No interpolation matrix.'
    374436            assert self.AtA is not None, msg
     
    381443            # if isinstance(point_coordinates,Geospatial_data) and z is None:
    382444            # 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
    384450
    385451        # Check sanity
     
    393459            msg += 'positive value,\ne.g. 1.0e-3.'
    394460            raise TooFewPointsError(msg)
     461
    395462
    396463        self._build_coefficient_matrix_B(verbose)
     
    408475            #raise VertsWithNoTrianglesError(msg)
    409476       
    410        
     477        if verbose:
     478            print 'Fit.fit: Solve Fitting Equation'
     479
    411480        return conjugate_gradient(self.B, self.Atz, self.Atz,
    412481                                  imax=2*len(self.Atz) )
     
    575644
    576645        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
    579648   
    580649   
     
    648717        old_title_list = mesh_dict['vertex_attribute_titles']
    649718
    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)
    651720
    652721    # load in the points file
     
    668737        mesh_origin = None
    669738
    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")
    672741    f = fit_to_mesh(point_coordinates,
    673742                    vertex_coordinates,
     
    679748                    data_origin = None,
    680749                    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")
    682751
    683752    # convert array to list of lists
     
    688757        old_title_list.extend(title_list)
    689758        #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)):
    691760            old_point_attributes[i].extend(new_point_attributes[i])
    692761        mesh_dict['vertex_attributes'] = old_point_attributes
     
    696765        mesh_dict['vertex_attribute_titles'] = title_list
    697766
    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)
    699768
    700769    try:
Note: See TracChangeset for help on using the changeset viewer.