Ignore:
Timestamp:
Sep 20, 2004, 9:19:01 AM (20 years ago)
Author:
duncan
Message:

adding a general mesh file, that pyvolution mesh inherits from

File:
1 edited

Legend:

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

    r316 r321  
    55
    66from least_squares import *
    7 from config import epsilon
     7from least_squares import EPSILON
    88from Numeric import allclose, array
    99
     
    2828        data = [ [2.0/3, 2.0/3] ] #Use centroid as one data point       
    2929       
    30         mesh = Interpolation(points, vertices, data)
    31         assert allclose(mesh.A_m, [[1./3, 1./3, 1./3]])
     30        interp = Interpolation(points, vertices, data)
     31        assert allclose(interp.A_m, [[1./3, 1./3, 1./3]])
    3232       
    3333
     
    4545        data = points #Use data at vertices       
    4646       
    47         mesh = Interpolation(points, vertices, data)
    48         assert allclose(mesh.A_m, [[1., 0., 0.],
     47        interp = Interpolation(points, vertices, data)
     48        assert allclose(interp.A_m, [[1., 0., 0.],
    4949                                      [0., 1., 0.],
    5050                                      [0., 0., 1.]])
     
    6565        data = [ [0., 1.], [1., 0.], [1., 1.] ]
    6666       
    67         mesh = Interpolation(points, vertices, data)
    68        
    69         assert allclose(mesh.A_m, [[0.5, 0.5, 0.0],  #Affects vertex 1 and 0       
     67        interp = Interpolation(points, vertices, data)
     68       
     69        assert allclose(interp.A_m, [[0.5, 0.5, 0.0],  #Affects vertex 1 and 0       
    7070                                      [0.5, 0.0, 0.5],  #Affects vertex 0 and 2
    7171                                      [0.0, 0.5, 0.5]]) #Affects vertex 1 and 2
     
    8585        data = [ [0., 1.5], [1.5, 0.], [1.5, 0.5] ]
    8686       
    87         mesh = Interpolation(points, vertices, data)
    88        
    89         assert allclose(mesh.A_m, [[0.25, 0.75, 0.0],  #Affects vertex 1 and 0     
     87        interp = Interpolation(points, vertices, data)
     88       
     89        assert allclose(interp.A_m, [[0.25, 0.75, 0.0],  #Affects vertex 1 and 0     
    9090                                      [0.25, 0.0, 0.75],  #Affects vertex 0 and 2
    9191                                      [0.0, 0.25, 0.75]]) #Affects vertex 1 and 2
     
    105105        data = [ [0.2, 1.5], [0.123, 1.768], [1.43, 0.44] ]
    106106       
    107         mesh = Interpolation(points, vertices, data)
    108 
    109         assert allclose(sum(mesh.A_m, axis=1), 1.0)
     107        interp = Interpolation(points, vertices, data)
     108
     109        assert allclose(sum(interp.A_m, axis=1), 1.0)
    110110       
    111111
     
    125125        data = [ [-3., 2.0], [-2, 1], [0.0, 1], [0, 3], [2, 3], [-1.0/3,-4./3] ]
    126126
    127         mesh = Interpolation(points, triangles, data)
     127        interp = Interpolation(points, triangles, data)
    128128       
    129129        answer = [[0.0, 0.0, 0.0,  1.0, 0.0, 0.0],  #Affects point d     
     
    133133                  [0.25, 0.75, 0.0, 0.0, 0.0, 0.0], #Affects points a and b
    134134                  [1./3, 0.0, 0.0, 0.0, 1./3, 1./3]] #Affects points a,e and f       
    135         #print mesh.A_m
     135        #print interp.A_m
    136136        #print answer
    137137       
    138         assert allclose(mesh.A_m, answer)
    139 
    140     def test_smooth_to_mesh(self):
     138        assert allclose(interp.A_m, answer)
     139
     140    def test_smooth_att_to_mesh(self):
    141141        a = [0.0, 0.0]
    142142        b = [0.0, 5.0]
     
    153153        data_coords = [ d1, d2, d3] #Use centroid as one data point       
    154154       
    155         mesh = Interpolation(points, triangles, data_coords)
     155        interp = Interpolation(points, triangles, data_coords)
    156156        z = [z1, z2, z3]
    157         f =  mesh.smooth_to_mesh(z)
     157        f =  interp.smooth_att_to_mesh(z)
    158158        answer = [0, 5., 5.]
    159159        assert allclose(f, answer)
    160160       
    161     def test_smooth_to_meshII(self):
     161    def test_smooth_att_to_meshII(self):
    162162        a = [0.0, 0.0]
    163163        b = [0.0, 5.0]
     
    171171        data_coords = [ d1, d2, d3]       
    172172        z = self.linear_function(data_coords)
    173         mesh = Interpolation(points, triangles, data_coords)
    174         f =  mesh.smooth_to_mesh(z)
     173        interp = Interpolation(points, triangles, data_coords)
     174        f =  interp.smooth_att_to_mesh(z)
    175175        answer = self.linear_function(points)
    176176        assert allclose(f, answer)
    177177   
    178     def test_smooth_to_meshIII(self):
     178    def test_smooth_att_to_meshIII(self):
    179179        a = [-1.0, 0.0]
    180180        b = [3.0, 4.0]
     
    202202       
    203203        z = self.linear_function(point_coords)
    204         mesh = Interpolation(vertices, triangles, point_coords)
    205         f =  mesh.smooth_to_mesh(z)
     204        interp = Interpolation(vertices, triangles, point_coords)
     205        f =  interp.smooth_att_to_mesh(z)
    206206        answer = self.linear_function(vertices)
    207207        assert allclose(f, answer)
     
    211211        return point[:,0]+point[:,1]
    212212   
    213     def test_smooth_to_points(self):
     213    def test_smooth_att_to_points(self):
    214214        v0 = [0.0, 0.0]
    215215        v1 = [0.0, 5.0]
     
    225225        point_coords = [ d0, d1, d2]
    226226       
    227         mesh = Interpolation(vertices, triangles, point_coords)
     227        interp = Interpolation(vertices, triangles, point_coords)
    228228        f = self.linear_function(vertices)
    229         z =  mesh.smooth_to_points(f)
     229        z =  interp.smooth_att_to_points(f)
    230230        answer = self.linear_function(point_coords)
    231231        #print "z",z
     
    233233        assert allclose(z, answer)
    234234       
    235     def test_smooth_to_pointsII(self):
     235    def test_smooth_att_to_pointsII(self):
    236236        a = [-1.0, 0.0]
    237237        b = [3.0, 4.0]
     
    258258                        [3.0,1.0]]
    259259       
    260         mesh = Interpolation(vertices, triangles, point_coords)
     260        interp = Interpolation(vertices, triangles, point_coords)
    261261        f = self.linear_function(vertices)
    262         z =  mesh.smooth_to_points(f)
     262        z =  interp.smooth_att_to_points(f)
    263263        answer = self.linear_function(point_coords)
    264264        #print "z",z
    265265        #print "answer",answer
    266         assert allclose(z, answer)
     266        assert allclose(z, answer)
     267
     268       
     269    def test_smooth_atts_to_mesh(self):
     270        a = [0.0, 0.0]
     271        b = [0.0, 5.0]
     272        c = [5.0, 0.0]
     273        points = [a, b, c]
     274        triangles = [ [1,0,2] ]   #bac
     275         
     276        d1 = [1.0, 1.0]
     277        d2 = [1.0, 3.0]
     278        d3 = [3.0,1.0]
     279        z1 = [2,4]
     280        z2 = [4,8]
     281        z3 = [4,8]
     282        data_coords = [ d1, d2, d3] #Use centroid as one data point       
     283       
     284        interp = Interpolation(points, triangles, data_coords)
     285        z = [z1, z2, z3]
     286        f =  interp.smooth_att_to_mesh(z)
     287        answer = [[0,0], [5., 10.], [5., 10.]]
     288        assert allclose(f, answer)
     289       
    267290#-------------------------------------------------------------
    268291if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.