- Timestamp:
- Sep 20, 2004, 9:19:01 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/test_least_squares.py
r316 r321 5 5 6 6 from least_squares import * 7 from config import epsilon7 from least_squares import EPSILON 8 8 from Numeric import allclose, array 9 9 … … 28 28 data = [ [2.0/3, 2.0/3] ] #Use centroid as one data point 29 29 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]]) 32 32 33 33 … … 45 45 data = points #Use data at vertices 46 46 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.], 49 49 [0., 1., 0.], 50 50 [0., 0., 1.]]) … … 65 65 data = [ [0., 1.], [1., 0.], [1., 1.] ] 66 66 67 mesh= Interpolation(points, vertices, data)68 69 assert allclose( mesh.A_m, [[0.5, 0.5, 0.0], #Affects vertex 1 and 067 interp = Interpolation(points, vertices, data) 68 69 assert allclose(interp.A_m, [[0.5, 0.5, 0.0], #Affects vertex 1 and 0 70 70 [0.5, 0.0, 0.5], #Affects vertex 0 and 2 71 71 [0.0, 0.5, 0.5]]) #Affects vertex 1 and 2 … … 85 85 data = [ [0., 1.5], [1.5, 0.], [1.5, 0.5] ] 86 86 87 mesh= Interpolation(points, vertices, data)88 89 assert allclose( mesh.A_m, [[0.25, 0.75, 0.0], #Affects vertex 1 and 087 interp = Interpolation(points, vertices, data) 88 89 assert allclose(interp.A_m, [[0.25, 0.75, 0.0], #Affects vertex 1 and 0 90 90 [0.25, 0.0, 0.75], #Affects vertex 0 and 2 91 91 [0.0, 0.25, 0.75]]) #Affects vertex 1 and 2 … … 105 105 data = [ [0.2, 1.5], [0.123, 1.768], [1.43, 0.44] ] 106 106 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) 110 110 111 111 … … 125 125 data = [ [-3., 2.0], [-2, 1], [0.0, 1], [0, 3], [2, 3], [-1.0/3,-4./3] ] 126 126 127 mesh= Interpolation(points, triangles, data)127 interp = Interpolation(points, triangles, data) 128 128 129 129 answer = [[0.0, 0.0, 0.0, 1.0, 0.0, 0.0], #Affects point d … … 133 133 [0.25, 0.75, 0.0, 0.0, 0.0, 0.0], #Affects points a and b 134 134 [1./3, 0.0, 0.0, 0.0, 1./3, 1./3]] #Affects points a,e and f 135 #print mesh.A_m135 #print interp.A_m 136 136 #print answer 137 137 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): 141 141 a = [0.0, 0.0] 142 142 b = [0.0, 5.0] … … 153 153 data_coords = [ d1, d2, d3] #Use centroid as one data point 154 154 155 mesh= Interpolation(points, triangles, data_coords)155 interp = Interpolation(points, triangles, data_coords) 156 156 z = [z1, z2, z3] 157 f = mesh.smooth_to_mesh(z)157 f = interp.smooth_att_to_mesh(z) 158 158 answer = [0, 5., 5.] 159 159 assert allclose(f, answer) 160 160 161 def test_smooth_ to_meshII(self):161 def test_smooth_att_to_meshII(self): 162 162 a = [0.0, 0.0] 163 163 b = [0.0, 5.0] … … 171 171 data_coords = [ d1, d2, d3] 172 172 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) 175 175 answer = self.linear_function(points) 176 176 assert allclose(f, answer) 177 177 178 def test_smooth_ to_meshIII(self):178 def test_smooth_att_to_meshIII(self): 179 179 a = [-1.0, 0.0] 180 180 b = [3.0, 4.0] … … 202 202 203 203 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) 206 206 answer = self.linear_function(vertices) 207 207 assert allclose(f, answer) … … 211 211 return point[:,0]+point[:,1] 212 212 213 def test_smooth_ to_points(self):213 def test_smooth_att_to_points(self): 214 214 v0 = [0.0, 0.0] 215 215 v1 = [0.0, 5.0] … … 225 225 point_coords = [ d0, d1, d2] 226 226 227 mesh= Interpolation(vertices, triangles, point_coords)227 interp = Interpolation(vertices, triangles, point_coords) 228 228 f = self.linear_function(vertices) 229 z = mesh.smooth_to_points(f)229 z = interp.smooth_att_to_points(f) 230 230 answer = self.linear_function(point_coords) 231 231 #print "z",z … … 233 233 assert allclose(z, answer) 234 234 235 def test_smooth_ to_pointsII(self):235 def test_smooth_att_to_pointsII(self): 236 236 a = [-1.0, 0.0] 237 237 b = [3.0, 4.0] … … 258 258 [3.0,1.0]] 259 259 260 mesh= Interpolation(vertices, triangles, point_coords)260 interp = Interpolation(vertices, triangles, point_coords) 261 261 f = self.linear_function(vertices) 262 z = mesh.smooth_to_points(f)262 z = interp.smooth_att_to_points(f) 263 263 answer = self.linear_function(point_coords) 264 264 #print "z",z 265 265 #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 267 290 #------------------------------------------------------------- 268 291 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.