Changeset 705 for inundation


Ignore:
Timestamp:
Dec 14, 2004, 12:59:59 PM (20 years ago)
Author:
duncan
Message:

fixed bug in least_squares algorithm.

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

Legend:

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

    r641 r705  
    245245            #Find vertices near x
    246246            candidate_vertices = root.search(x[0], x[1])
    247 
    248247            is_more_elements = True
    249             if candidate_vertices == []:
    250                 # The point isn't even within the root cell!
    251                 is_more_elements = False
    252                 element_found = False
    253             else:
    254                 element_found, sigma0, sigma1, sigma2, k = \
    255                     self.search_triangles_of_vertices(candidate_vertices, x)
    256 
     248           
     249            element_found, sigma0, sigma1, sigma2, k = \
     250                self.search_triangles_of_vertices(candidate_vertices, x)
    257251            while not element_found and is_more_elements:
    258                 candidate_vertices = root.expand_search()
    259                 if candidate_vertices == []:
    260                     # All the triangles have been searched.
     252                candidate_vertices, branch = root.expand_search()
     253                if branch == []:
     254                    # Searching all the verts from the root cell that haven't
     255                    # been searched.  This is the last try
     256                    element_found, sigma0, sigma1, sigma2, k = \
     257                      self.search_triangles_of_vertices(candidate_vertices, x)
    261258                    is_more_elements = False
    262259                else:
    263260                    element_found, sigma0, sigma1, sigma2, k = \
    264261                      self.search_triangles_of_vertices(candidate_vertices, x)
    265                    
    266                
     262                     
    267263           
    268264            #Update interpolation matrix A if necessary     
     
    301297            sigma0 = -10.0
    302298            sigma1 = -10.0
     299            k = -10.0
    303300
    304301            #For all vertices in same cell as point x
     
    317314                    #print "PDSG - xi1", xi1
    318315                    #print "PDSG - xi2", xi2
    319                     #print "PDSG element %i verts((%f, %f),(%f, %f),(%f, %f))" \
    320                     #      % (k, xi0[0], xi0[1], xi1[0], xi1[1], xi2[0], xi2[1])
     316                   #print "PDSG element %i verts((%f, %f),(%f, %f),(%f, %f))" \
     317                    #   % (k, xi0[0], xi0[1], xi1[0], xi1[1], xi2[0], xi2[1])
    321318                   
    322319                    #Get the three normals
  • inundation/ga/storm_surge/pyvolution/quad.py

    r611 r705  
    122122                #print "cell ", cell.show()
    123123                points += cell.retrieve()
    124         return points
     124        return points, self.branch
    125125
    126126
  • inundation/ga/storm_surge/pyvolution/test_least_squares.py

    r703 r705  
    8383                      0., 0. , 0., 0., 0., 0.]]
    8484        assert allclose(interp.get_A(), answer)
    85        
     85     
     86    def test_quad_treeII(self):
     87        p0 = [-66.0, 14.0]
     88        p1 = [14.0, -66.0]
     89        p2 = [14.0, 14.0]
     90        p3 = [60.0, 20.0]
     91        p4 = [10.0, 60.0]
     92        p5 = [60.0, 60.0]
     93       
     94        points = [p0, p1, p2, p3, p4, p5]
     95        triangles = [ [0, 1, 2],
     96                      [3, 2, 1],
     97                      [0, 2, 4],
     98                      [0, 2, 4],
     99                      [4, 2, 5],
     100                      [5, 2, 3]]   
     101
     102        data = [ [-26.0,-26.0] ]
     103       
     104        interp = Interpolation(points, triangles, data, alpha = 0.0)
     105        #print "PDSG - interp.get_A()", interp.get_A()
     106        answer =  [ [ 0.5,  0.5,  0.0,  0.,
     107                      0., 0.]]
     108        assert allclose(interp.get_A(), answer)
     109        interp.set_point_coordinates([[-30, -30]]) #point outside of mesh
     110        #print "PDSG -30,-30 - interp.get_A()", interp.get_A()
     111        answer =  [ [ 0.0,  0.0,  0.0,  0.,
     112                      0., 0.]]
     113        assert allclose(interp.get_A(), answer)
     114
     115       
     116        #point outside of quad tree root cell
     117        interp.set_point_coordinates([[-70, -70]])
     118        #print "PDSG -70,-70 interp.get_A()", interp.get_A()
     119        answer =  [ [ 0.0,  0.0,  0.0,  0.,
     120                      0., 0. ]]
     121        assert allclose(interp.get_A(), answer)
     122           
    86123
    87124    def test_datapoints_at_vertices(self):
     
    158195       
    159196        interp = Interpolation(points, vertices, data)
    160 
     197        #print "interp.get_A()", interp.get_A()
    161198        assert allclose(sum(interp.get_A(), axis=1), 1.0)
    162199       
     
    793830
    794831    suite = unittest.makeSuite(TestCase,'test')
     832    #suite = unittest.makeSuite(TestCase,'test_arbitrary_datapoints')
    795833    runner = unittest.TextTestRunner(verbosity=1)
    796834    runner.run(suite)
  • inundation/ga/storm_surge/pyvolution/test_quad.py

    r484 r705  
    127127        assert type(result) in [types.ListType,types.TupleType],\
    128128                                'should be a list'
    129        
     129        #print "result",result
    130130        self.assertEqual(result, [0,1,2,3])
    131131
  • inundation/ga/storm_surge/pyvolution/wiki/issues.txt

    r685 r705  
    22OPEN ISSUES:
    33------------
     4Issue (least_squares): The current is-a-point-in-a-triangle algorithm
     5is slow if a point is outside of the mesh.  It will check each
     6triangle 3 times to see if the point is in that triangle.
     7Importance: low
     8Suggested Action: keep a list of triangles searched./ form a polygon
     9of the mesh boundary and throw out points not in the polygon.
     10
    411Issue (interpolate_sww): Give a warning if points are outside the mesh.
    512Importance: Mid
Note: See TracChangeset for help on using the changeset viewer.