Changeset 1753 for inundation/pyvolution/test_quantity.py
- Timestamp:
- Aug 24, 2005, 1:49:47 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/test_quantity.py
r1752 r1753 276 276 277 277 278 278 279 279 280 def test_set_vertex_values_using_least_squares(self): 280 from least_squares import Interpolation, fit_to_mesh 281 281 282 282 283 quantity = Quantity(self.mesh4) … … 297 298 [ 3.0, 1.0]] 298 299 299 300 interp = Interpolation(quantity.domain.coordinates, quantity.domain.triangles,301 data_points, alpha=0.0)302 303 300 z = linear_function(data_points) 304 answer = linear_function(quantity.domain.coordinates) 305 306 f = interp.fit(z) 307 301 302 #Obsoleted bit 303 #interp = Interpolation(quantity.domain.coordinates, 304 # quantity.domain.triangles, 305 # data_points, alpha=0.0) 306 # 307 #answer = linear_function(quantity.domain.coordinates) 308 # 309 #f = interp.fit(z) 310 # 308 311 #print "f",f 309 312 #print "answer",answer 310 assert allclose(f, answer) 311 312 313 quantity.set_values(f) 314 315 313 #assert allclose(f, answer) 314 315 316 #Use built-in least squares fit 317 quantity.set_values(points = data_points, values = z, alpha = 0) 316 318 answer = linear_function(quantity.domain.get_vertex_coordinates(obj = True)) 317 319 #print quantity.vertex_values, answer 318 320 assert allclose(quantity.vertex_values.flat, answer) 319 321 320 #Now try using the general interface 321 322 323 #Now try by setting the same values directly 324 from least_squares import fit_to_mesh 322 325 vertex_attributes = fit_to_mesh(quantity.domain.coordinates, 323 326 quantity.domain.triangles, … … 329 332 #print vertex_attributes 330 333 quantity.set_values(vertex_attributes) 334 assert allclose(quantity.vertex_values.flat, answer) 335 336 337 def test_set_values_from_file(self): 338 quantity = Quantity(self.mesh4) 339 340 #Get (enough) datapoints 341 data_points = [[ 0.66666667, 0.66666667], 342 [ 1.33333333, 1.33333333], 343 [ 2.66666667, 0.66666667], 344 [ 0.66666667, 2.66666667], 345 [ 0.0, 1.0], 346 [ 0.0, 3.0], 347 [ 1.0, 0.0], 348 [ 1.0, 1.0], 349 [ 1.0, 2.0], 350 [ 1.0, 3.0], 351 [ 2.0, 1.0], 352 [ 3.0, 0.0], 353 [ 3.0, 1.0]] 354 355 z = linear_function(data_points) 356 357 358 #Create pts file 359 from data_manager import write_ptsfile 360 ptsfile = 'testptsfile.pts' 361 att = 'spam_and_eggs' 362 write_ptsfile(ptsfile, data_points, z, attribute_name = att) 363 364 #Check that values can be set from file 365 quantity.set_values(filename = ptsfile, 366 attribute_name = att, alpha = 0) 367 answer = linear_function(quantity.domain.get_vertex_coordinates(obj = True)) 368 #print quantity.vertex_values, answer 369 assert allclose(quantity.vertex_values.flat, answer) 370 371 372 #Check that values can be set from file using default attribute 373 quantity.set_values(filename = ptsfile, alpha = 0) 331 374 assert allclose(quantity.vertex_values.flat, answer) 332 375 376 #Cleanup 377 import os 378 os.remove(ptsfile) 379 333 380 334 381 … … 832 879 indices = [1] 833 880 quantity.set_values(value, 834 835 881 location = 'centroids', 882 indices = indices) 836 883 #print "quantity.centroid_values",quantity.centroid_values 837 884 assert allclose(quantity.centroid_values, [1,7,3,4,5,6])
Note: See TracChangeset
for help on using the changeset viewer.