Changeset 570


Ignore:
Timestamp:
Nov 16, 2004, 5:31:53 PM (19 years ago)
Author:
ole
Message:

Fixed bug in leastsquares where sigmas may get negative within machine precision

Location:
inundation/ga/storm_surge/pyvolution
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/least_squares.py

    r569 r570  
    235235            candidate_vertices = root.search(x[0], x[1])
    236236
     237           
    237238            #Find triangle containing x:
    238239            element_found = False           
     
    254255                    n2 = self.mesh.get_normal(k, 2)               
    255256
     257                   
    256258                    #Compute interpolation
    257259                    sigma2 = dot((x-xi0), n2)/dot((xi2-xi0), n2)
     
    262264                    epsilon = 1.0e-6
    263265                    assert abs(sigma0 + sigma1 + sigma2 - 1.0) < epsilon
    264 
     266                   
    265267                    #Check that this triangle contains the data point
    266                     if sigma0 >= 0 and sigma1 >= 0 and sigma2 >= 0:
     268                   
     269                    #Sigmas can get negative within
     270                    #machine precision on some machines (e.g nautilus)
     271                    #Hence the small eps
     272                   
     273                    eps = 1.0e-15
     274                    if sigma0 >= -eps and sigma1 >= -eps and sigma2 >= -eps:
    267275                        element_found = True
    268276                        break
     
    272280                    break
    273281                   
    274 
    275             print x, element_found, k
    276282           
    277283            #Update interpolation matrix A if necessary     
     
    299305                #Ok if there is no triangle for datapoint
    300306                #(as in brute force version)
    301                 raise 'Could not find triangle for point', x
     307                #raise 'Could not find triangle for point', x
    302308
    303309
  • inundation/ga/storm_surge/pyvolution/test_least_squares.py

    r568 r570  
    682682#-------------------------------------------------------------
    683683if __name__ == "__main__":
    684     suite = unittest.makeSuite(TestCase,'test_more_tri')
     684    suite = unittest.makeSuite(TestCase,'test')
    685685    runner = unittest.TextTestRunner(verbosity=1)
    686686    runner.run(suite)
Note: See TracChangeset for help on using the changeset viewer.