Changeset 454
- Timestamp:
- Oct 27, 2004, 12:35:39 PM (20 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/interpolate_sww.py
r389 r454 77 77 #Change this if you want to generalise this application - 78 78 # This is height specific 79 print "self.stage" 79 80 point_stage = self.interp.interpolate( self.stage) 80 81 point_bed_elevation = self.interp.interpolate( self.bed_elevation) -
inundation/ga/storm_surge/pyvolution/least_squares.py
r452 r454 212 212 #self.A = zeros((n,m), Float) 213 213 self.A = Sparse(n,m) 214 215 #print 'n by m ',self.A216 214 self.AtA = Sparse(m,m) 217 215 … … 221 219 222 220 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): 224 224 #For each triangle (brute force) 225 225 #FIXME: Real algorithm should only visit relevant triangles … … 246 246 #Check that this triangle contains data point 247 247 if sigma0 >= 0 and sigma1 >= 0 and sigma2 >= 0: 248 248 element_found = True 249 249 #Assign values to matrix A 250 250 … … 266 266 for k in js: 267 267 self.AtA[j,k] += sigmas[j]*sigmas[k] 268 268 k = k+1 269 269 270 270 ## self.A = (self.A).tocsc() … … 272 272 ## self.At = self.A.transp() 273 273 274 275 274 276 def get_A(self): 275 277 return self.A.todense() … … 401 403 402 404 #Solve and return 403 #return solve_linear_equations(self.get_B(), Atz)405 return solve_linear_equations(self.get_B(), Atz) 404 406 405 407 # caused errors 406 408 #return sparse.solve(self.B,Atz) 407 409 408 return conjugate_gradient(self.B, Atz, Atz)410 #return conjugate_gradient(self.B, Atz, Atz) 409 411 #FIXME: Should we store the result here for later use? (ON) 410 412 … … 454 456 # and so will do each column separately due to problems in 455 457 # sparse matrix, 2d array multiplication 456 457 458 (N , M) = self.A.shape 458 459 f = array(f).astype(Float) 459 460 (m , n) = f.shape 461 #print "m",m 462 #print "M",M 460 463 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) 461 468 raise VectorShapeError, 'Mismatch between A and f dimensions' 462 469 … … 466 473 y[:,i] = self.A * f[:,i] 467 474 475 #print "!!self.A.todense() ",self.A.todense() 468 476 return y 469 477 -
inundation/ga/storm_surge/pyvolution/test_all.py
r443 r454 15 15 #List files that should be excluded from the testing process. 16 16 #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'] 19 exclude = [] 20 20 21 21 -
inundation/ga/storm_surge/pyvolution/test_cg_solve.py
r438 r454 127 127 if __name__ == "__main__": 128 128 suite = unittest.makeSuite(TestCase,'test') 129 runner = unittest.TextTestRunner( verbosity=2)129 runner = unittest.TextTestRunner() #(verbosity=2) 130 130 runner.run(suite) 131 131 -
inundation/ga/storm_surge/pyvolution/test_least_squares.py
r452 r454 18 18 class TestCase(unittest.TestCase): 19 19 20 ##def setUp(self):21 ##pass22 23 ##def tearDown(self):24 ##pass20 def setUp(self): 21 pass 22 23 def tearDown(self): 24 pass 25 25 26 26 27 27 def test_datapoint_at_centroid(self): 28 29 28 a = [0.0, 0.0] 30 29 b = [0.0, 2.0] … … 41 40 42 41 def test_datapoints_at_vertices(self): 43 44 42 """Test that data points coinciding with vertices yield a diagonal matrix 43 """ 44 45 45 a = [0.0, 0.0] 46 46 b = [0.0, 2.0] … … 59 59 60 60 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 62 65 a = [0.0, 0.0] 63 66 b = [0.0, 2.0] … … 76 79 77 80 def test_datapoints_on_edges(self): 81 """Try datapoints on edges - 82 each point should affect two matrix entries in proportion 83 """ 78 84 79 85 a = [0.0, 0.0] … … 92 98 93 99 def test_arbitrary_datapoints(self): 94 100 """Try arbitrary datapoints 101 """ 95 102 96 103 from Numeric import sum … … 109 116 110 117 118 # this causes a memory error in scipy.sparce 111 119 def test_more_triangles(self): 112 120 113 121 a = [-1.0, 0.0] 114 122 b = [3.0, 4.0] … … 122 130 123 131 #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] ] 126 133 interp = Interpolation(points, triangles, data_points) 127 134 128 #FIXME Which matrix does this refer to? AtA?129 135 answer = [[0.0, 0.0, 0.0, 1.0, 0.0, 0.0], #Affects point d 130 136 [0.5, 0.0, 0.0, 0.5, 0.0, 0.0], #Affects points a and d … … 134 140 [1./3, 0.0, 0.0, 0.0, 1./3, 1./3]] #Affects points a,e and f 135 141 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) 145 143 146 144 … … 148 146 149 147 def test_smooth_attributes_to_mesh(self): 150 151 148 a = [0.0, 0.0] 152 149 b = [0.0, 5.0] … … 167 164 f = interp.fit(z) 168 165 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) 170 171 171 172 … … 190 191 191 192 def test_smooth_attributes_to_meshIII(self): 192 193 193 194 a = [-1.0, 0.0] 194 195 b = [3.0, 4.0] … … 220 221 f = interp.fit(z) 221 222 answer = linear_function(vertices) 223 #print "f\n",f 224 #print "answer\n",answer 222 225 assert allclose(f, answer) 223 226 224 227 225 228 def test_smooth_attributes_to_meshIV(self): 226 229 """ Testing 2 attributes smoothed to the mesh 230 """ 231 227 232 a = [0.0, 0.0] 228 233 b = [0.0, 5.0] … … 246 251 247 252 def test_interpolate_attributes_to_points(self): 248 249 253 v0 = [0.0, 0.0] 250 254 v1 = [0.0, 5.0] … … 269 273 270 274 def test_interpolate_attributes_to_pointsII(self): 271 272 275 a = [-1.0, 0.0] 273 276 b = [3.0, 4.0] … … 303 306 304 307 def test_interpolate_attributes_to_pointsIII(self): 305 306 308 v0 = [0.0, 0.0] 307 309 v1 = [0.0, 5.0] … … 331 333 332 334 def test_interpolate_attributes_to_pointsIV(self): 333 334 335 a = [-1.0, 0.0] 335 336 b = [3.0, 4.0] … … 370 371 371 372 def test_smooth_attributes_to_mesh_function(self): 373 """ Testing 2 attributes smoothed to the mesh 374 """ 375 """Test multiple attributes 376 """ 372 377 373 378 a = [0.0, 0.0] … … 433 438 434 439 def test_smoothing_matrix_more_triangles(self): 435 436 437 440 from Numeric import dot 438 441 … … 478 481 479 482 def test_fit_and_interpolation(self): 480 481 483 from mesh import Mesh 482 484 … … 514 516 f = interp.fit(z) 515 517 518 #print "f",f 519 #print "answer",answer 516 520 assert allclose(f, answer) 517 521 518 522 #Map back 519 523 z1 = interp.interpolate(f) 524 #print "z1\n", z1 525 #print "z\n",z 520 526 assert allclose(z, z1) 521 527 … … 555 561 556 562 f = interp.fit(z) 557 558 563 #f will be different from answerr due to smoothing 559 #assert allclose(f, answer)564 assert allclose(f, answer,atol=5) 560 565 561 566 #Map back … … 666 671 if __name__ == "__main__": 667 672 suite = unittest.makeSuite(TestCase,'test') 668 runner = unittest.TextTestRunner( verbosity=2)673 runner = unittest.TextTestRunner() #(verbosity=2) 669 674 runner.run(suite) 670 675
Note: See TracChangeset
for help on using the changeset viewer.