Changeset 454


Ignore:
Timestamp:
Oct 27, 2004, 12:35:39 PM (20 years ago)
Author:
duncan
Message:

bug fixes

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

Legend:

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

    r389 r454  
    7777        #Change this if you want to generalise this application -
    7878        # This is height specific
     79        print "self.stage"
    7980        point_stage =  self.interp.interpolate( self.stage)
    8081        point_bed_elevation = self.interp.interpolate( self.bed_elevation)
  • inundation/ga/storm_surge/pyvolution/least_squares.py

    r452 r454  
    212212        #self.A = zeros((n,m), Float)
    213213        self.A = Sparse(n,m)
    214 
    215         #print 'n by m ',self.A
    216214        self.AtA = Sparse(m,m)
    217215
     
    221219
    222220            x = point_coordinates[i]
    223             for k in range(len(self.mesh)):
     221            element_found = False
     222            k = 0
     223            while not element_found and k < len(self.mesh):
    224224                #For each triangle (brute force)
    225225                #FIXME: Real algorithm should only visit relevant triangles
     
    246246                #Check that this triangle contains data point
    247247                if sigma0 >= 0 and sigma1 >= 0 and sigma2 >= 0:
    248 
     248                    element_found = True
    249249                    #Assign values to matrix A
    250250
     
    266266                        for k in js:
    267267                            self.AtA[j,k] += sigmas[j]*sigmas[k]
    268 
     268                k = k+1
    269269       
    270270##         self.A   = (self.A).tocsc()
     
    272272##         self.At  =  self.A.transp()
    273273
     274
     275       
    274276    def get_A(self):
    275277        return self.A.todense()
     
    401403
    402404        #Solve and return
    403         #return solve_linear_equations(self.get_B(), Atz)
     405        return solve_linear_equations(self.get_B(), Atz)
    404406
    405407        # caused errors
    406408        #return sparse.solve(self.B,Atz)
    407409
    408         return conjugate_gradient(self.B, Atz, Atz)
     410        #return conjugate_gradient(self.B, Atz, Atz)
    409411        #FIXME: Should we store the result here for later use? (ON)       
    410412   
     
    454456            # and so will do each column separately due to problems in
    455457            # sparse matrix, 2d array multiplication
    456            
    457458            (N , M) = self.A.shape
    458459            f = array(f).astype(Float)
    459460            (m , n) = f.shape
     461            #print "m",m
     462            #print "M",M
    460463            if m != M :
     464                #print "!!self.A",self.A
     465                #print "!!self.A.todense() ",self.A.todense()
     466                #print "self.get_A()",self.get_A()
     467                #return dot(self.get_A(),f)
    461468                raise VectorShapeError, 'Mismatch between A and f dimensions'
    462469           
     
    466473                y[:,i] = self.A * f[:,i]
    467474
     475            #print "!!self.A.todense() ",self.A.todense()
    468476            return y
    469477     
  • inundation/ga/storm_surge/pyvolution/test_all.py

    r443 r454  
    1515#List files that should be excluded from the testing process.
    1616#E.g. if they are known to fail and under development
    17 exclude = ['test_least_squares.py', 'test_cg_solve.py',
    18           'test_interpolate_sww.py']
    19 
     17#exclude = ['test_least_squares.py', 'test_cg_solve.py',
     18          # 'test_interpolate_sww.py']
     19exclude = []
    2020
    2121
  • inundation/ga/storm_surge/pyvolution/test_cg_solve.py

    r438 r454  
    127127if __name__ == "__main__":
    128128     suite = unittest.makeSuite(TestCase,'test')
    129      runner = unittest.TextTestRunner(verbosity=2)
     129     runner = unittest.TextTestRunner() #(verbosity=2)
    130130     runner.run(suite)
    131131
  • inundation/ga/storm_surge/pyvolution/test_least_squares.py

    r452 r454  
    1818class TestCase(unittest.TestCase):
    1919
    20 ##     def setUp(self):
    21 ##         pass
    22        
    23 ##     def tearDown(self):
    24 ##         pass
     20    def setUp(self):
     21        pass
     22       
     23    def tearDown(self):
     24        pass
    2525
    2626
    2727    def test_datapoint_at_centroid(self):
    28        
    2928        a = [0.0, 0.0]
    3029        b = [0.0, 2.0]
     
    4140
    4241    def test_datapoints_at_vertices(self):
    43 
    44 
     42        """Test that data points coinciding with vertices yield a diagonal matrix
     43        """
     44       
    4545        a = [0.0, 0.0]
    4646        b = [0.0, 2.0]
     
    5959
    6060    def test_datapoints_on_edge_midpoints(self):
    61 
     61        """Try datapoints midway on edges -
     62        each point should affect two matrix entries equally
     63        """
     64       
    6265        a = [0.0, 0.0]
    6366        b = [0.0, 2.0]
     
    7679
    7780    def test_datapoints_on_edges(self):
     81        """Try datapoints on edges -
     82        each point should affect two matrix entries in proportion
     83        """
    7884       
    7985        a = [0.0, 0.0]
     
    9298
    9399    def test_arbitrary_datapoints(self):
    94 
     100        """Try arbitrary datapoints
     101        """
    95102
    96103        from Numeric import sum
     
    109116       
    110117
     118    # this causes a memory error in scipy.sparce       
    111119    def test_more_triangles(self):
    112 
     120       
    113121        a = [-1.0, 0.0]
    114122        b = [3.0, 4.0]
     
    122130
    123131        #Data points
    124         data_points = [ [-3., 1.9], [-2, 1], [0.0, 1], [0, 3], [2, 3],
    125                         [-1.0/3,-4./3], [-1.0,-1.5 ], [1.0,-1.0]]
     132        data_points = [ [-3., 2.0], [-2, 1], [0.0, 1], [0, 3], [2, 3], [-1.0/3,-4./3] ]
    126133        interp = Interpolation(points, triangles, data_points)
    127134
    128         #FIXME Which matrix does this refer to? AtA?
    129135        answer = [[0.0, 0.0, 0.0,  1.0, 0.0, 0.0],   #Affects point d     
    130136                  [0.5, 0.0, 0.0, 0.5, 0.0, 0.0],    #Affects points a and d
     
    134140                  [1./3, 0.0, 0.0, 0.0, 1./3, 1./3]] #Affects points a,e and f
    135141
    136 
    137         A = mat(interp.get_A())
    138         At = transpose(A)
    139         AtA = At * A
    140         AtA = AtA.asarray()
    141         #print AtA
    142 
    143         #FIXME These two matrices are not correct, recalculate
    144         assert allclose(AtA, answer)
     142        assert allclose(interp.get_A(), answer)
    145143
    146144
     
    148146
    149147    def test_smooth_attributes_to_mesh(self):
    150        
    151148        a = [0.0, 0.0]
    152149        b = [0.0, 5.0]
     
    167164        f = interp.fit(z)
    168165        answer = [0, 5., 5.]
    169         assert allclose(f, answer)
     166
     167        #print "f\n",f
     168        #print "answer\n",answer
     169       
     170        assert allclose(f, answer,atol=1e-7)
    170171       
    171172       
     
    190191   
    191192    def test_smooth_attributes_to_meshIII(self):
    192 
     193       
    193194        a = [-1.0, 0.0]
    194195        b = [3.0, 4.0]
     
    220221        f = interp.fit(z)
    221222        answer = linear_function(vertices)
     223        #print "f\n",f
     224        #print "answer\n",answer
    222225        assert allclose(f, answer)
    223226       
    224227
    225228    def test_smooth_attributes_to_meshIV(self):
    226 
     229        """ Testing 2 attributes smoothed to the mesh
     230        """
     231       
    227232        a = [0.0, 0.0]
    228233        b = [0.0, 5.0]
     
    246251       
    247252    def test_interpolate_attributes_to_points(self):
    248        
    249253        v0 = [0.0, 0.0]
    250254        v1 = [0.0, 5.0]
     
    269273       
    270274    def test_interpolate_attributes_to_pointsII(self):
    271 
    272275        a = [-1.0, 0.0]
    273276        b = [3.0, 4.0]
     
    303306   
    304307    def test_interpolate_attributes_to_pointsIII(self):
    305        
    306308        v0 = [0.0, 0.0]
    307309        v1 = [0.0, 5.0]
     
    331333   
    332334    def test_interpolate_attributes_to_pointsIV(self):
    333 
    334335        a = [-1.0, 0.0]
    335336        b = [3.0, 4.0]
     
    370371       
    371372    def test_smooth_attributes_to_mesh_function(self):
     373        """ Testing 2 attributes smoothed to the mesh
     374        """
     375        """Test multiple attributes
     376        """
    372377       
    373378        a = [0.0, 0.0]
     
    433438
    434439    def test_smoothing_matrix_more_triangles(self):
    435 
    436 
    437440        from Numeric import dot
    438441       
     
    478481
    479482    def test_fit_and_interpolation(self):
    480 
    481483        from mesh import Mesh
    482484       
     
    514516        f = interp.fit(z)
    515517
     518        #print "f",f
     519        #print "answer",answer
    516520        assert allclose(f, answer)
    517521
    518522        #Map back
    519523        z1 = interp.interpolate(f)
     524        #print "z1\n", z1
     525        #print "z\n",z
    520526        assert allclose(z, z1)
    521527
     
    555561       
    556562        f = interp.fit(z)
    557 
    558563        #f will be different from answerr due to smoothing
    559         #assert allclose(f, answer)
     564        assert allclose(f, answer,atol=5)
    560565
    561566        #Map back
     
    666671if __name__ == "__main__":
    667672    suite = unittest.makeSuite(TestCase,'test')
    668     runner = unittest.TextTestRunner(verbosity=2)
     673    runner = unittest.TextTestRunner()   #(verbosity=2)
    669674    runner.run(suite)
    670675
Note: See TracChangeset for help on using the changeset viewer.