Changeset 2679
- Timestamp:
- Apr 7, 2006, 3:49:48 PM (18 years ago)
- Location:
- inundation/pyvolution
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/test_util.py
r2526 r2679 5 5 from Numeric import zeros, array, allclose, Float 6 6 from math import sqrt, pi 7 import tempfile 7 8 8 9 from util import * … … 10 11 from data_manager import timefile2netcdf 11 12 13 from utilities.numerical_tools import INF 12 14 13 15 def test_function(x, y): … … 498 500 499 501 500 def test_spatio_temporal_file_function_time(self):502 def qtest_spatio_temporal_file_function_time(self): 501 503 """Test that File function interpolates correctly 502 504 between given times. … … 531 533 points, vertices, boundary =\ 532 534 rectangular(4, 4, 15, 30, origin = (0, -20)) 533 535 print "points", points 534 536 535 537 #print 'Number of elements', len(vertices) … … 571 573 572 574 interpolation_points = [[0,-20], [1,0], [0,1], [1.1, 3.14], [10,-12.5]] 573 574 575 575 576 576 #Deliberately set domain.starttime to too early 577 577 domain.starttime = start - 1 … … 610 610 q1 = F(t+60, point_id=id) 611 611 612 612 if q0 == INF: 613 actual = q0 614 else: 615 actual = (k*q1 + (6-k)*q0)/6 613 616 q = F(t, point_id=id) 614 617 #print i, k, t, q 615 618 #print ' ', q0 616 619 #print ' ', q1 617 #print 's', (k*q1 + (6-k)*q0)/6 620 print "q",q 621 print "actual", actual 618 622 #print 619 assert allclose(q, (k*q1 + (6-k)*q0)/6) 623 if q0 == INF: 624 self.failUnless( q == actual, 'Fail!') 625 else: 626 assert allclose(q, actual) 620 627 621 628 … … 667 674 668 675 676 677 def xtest_spatio_temporal_file_function_time(self): 678 # Test that File function interpolates correctly 679 # When some points are outside the mesh 680 681 import os, time 682 from config import time_format 683 from Numeric import sin, pi, exp 684 from mesh_factory import rectangular 685 from shallow_water import Domain 686 import data_manager 687 from pmesh.mesh_interface import create_mesh_from_regions 688 finaltime = 1200 689 690 filename = tempfile.mktemp() 691 #print "filename",filename 692 filename = 'test_file_function' 693 694 meshfilename = tempfile.mktemp(".tsh") 695 696 boundary_tags = {'walls':[0,1],'bom':[2]} 697 698 polygon_absolute = [[0,-20],[10,-20],[10,15],[-20,15]] 699 700 create_mesh_from_regions(polygon_absolute, 701 boundary_tags, 702 10000000, 703 filename=meshfilename) 704 domain = Domain(mesh_filename=meshfilename) 705 domain.smooth = False 706 domain.default_order = 2 707 domain.set_datadir('.') 708 domain.set_name(filename) 709 domain.store = True 710 domain.format = 'sww' #Native netcdf visualisation format 711 712 #print points 713 start = time.mktime(time.strptime('2000', '%Y')) 714 domain.starttime = start 715 716 717 #Store structure 718 domain.initialise_storage() 719 720 #Compute artificial time steps and store 721 dt = 60 #One minute intervals 722 t = 0.0 723 while t <= finaltime: 724 #Compute quantities 725 f1 = lambda x,y: 3*x - y**2 + 2*t + 4 726 domain.set_quantity('stage', f1) 727 728 f2 = lambda x,y: x+y+t**2 729 domain.set_quantity('xmomentum', f2) 730 731 f3 = lambda x,y: x**2 + y**2 * sin(t*pi/600) 732 domain.set_quantity('ymomentum', f3) 733 734 #Store and advance time 735 domain.time = t 736 domain.store_timestep(domain.conserved_quantities) 737 t += dt 738 739 interpolation_points = [[1,0]] 740 interpolation_points = [[100,1000]] 741 742 interpolation_points = [[0,-20], [1,0], [0,1], [1.1, 3.14], [10,-12.5], 743 [78787,78787],[7878,3432]] 744 745 #Deliberately set domain.starttime to too early 746 domain.starttime = start - 1 747 748 #Create file function 749 F = file_function(filename + '.sww', domain, 750 quantities = domain.conserved_quantities, 751 interpolation_points = interpolation_points) 752 753 #Check that FF updates fixes domain starttime 754 assert allclose(domain.starttime, start) 755 756 #Check that domain.starttime isn't updated if later 757 domain.starttime = start + 1 758 F = file_function(filename + '.sww', domain, 759 quantities = domain.conserved_quantities, 760 interpolation_points = interpolation_points) 761 assert allclose(domain.starttime, start+1) 762 domain.starttime = start 763 764 765 #Check linear interpolation in time 766 # checking points inside and outside the mesh 767 F = file_function(filename + '.sww', domain, 768 quantities = domain.conserved_quantities, 769 interpolation_points = interpolation_points) 770 771 for id in range(len(interpolation_points)): 772 x = interpolation_points[id][0] 773 y = interpolation_points[id][1] 774 775 for i in range(20): 776 t = i*10 777 k = i%6 778 779 if k == 0: 780 q0 = F(t, point_id=id) 781 q1 = F(t+60, point_id=id) 782 783 if q0 == INF: 784 actual = q0 785 else: 786 actual = (k*q1 + (6-k)*q0)/6 787 q = F(t, point_id=id) 788 #print i, k, t, q 789 #print ' ', q0 790 #print ' ', q1 791 #print "q",q 792 #print "actual", actual 793 #print 794 if q0 == INF: 795 self.failUnless( q == actual, 'Fail!') 796 else: 797 assert allclose(q, actual) 798 799 # now lets check points inside the mesh 800 interpolation_points = [[0,-20], [1,0], [0,1], [1.1, 3.14]] #, [10,-12.5]] - this point doesn't work WHY? 801 interpolation_points = [[10,-12.5]] 802 803 print "len(interpolation_points)",len(interpolation_points) 804 F = file_function(filename + '.sww', domain, 805 quantities = domain.conserved_quantities, 806 interpolation_points = interpolation_points) 807 808 domain.starttime = start 809 810 811 #Check linear interpolation in time 812 F = file_function(filename + '.sww', domain, 813 quantities = domain.conserved_quantities, 814 interpolation_points = interpolation_points) 815 for id in range(len(interpolation_points)): 816 x = interpolation_points[id][0] 817 y = interpolation_points[id][1] 818 819 for i in range(20): 820 t = i*10 821 k = i%6 822 823 if k == 0: 824 q0 = F(t, point_id=id) 825 q1 = F(t+60, point_id=id) 826 827 if q0 == INF: 828 actual = q0 829 else: 830 actual = (k*q1 + (6-k)*q0)/6 831 q = F(t, point_id=id) 832 print "############" 833 print "id, x, y ", id, x, y #k, t, q 834 print "t", t 835 #print ' ', q0 836 #print ' ', q1 837 print "q",q 838 print "actual", actual 839 #print 840 if q0 == INF: 841 self.failUnless( q == actual, 'Fail!') 842 else: 843 assert allclose(q, actual) 844 845 846 #Another check of linear interpolation in time 847 for id in range(len(interpolation_points)): 848 q60 = F(60, point_id=id) 849 q120 = F(120, point_id=id) 850 851 t = 90 #Halfway between 60 and 120 852 q = F(t, point_id=id) 853 assert allclose( (q120+q60)/2, q ) 854 855 t = 100 #Two thirds of the way between between 60 and 120 856 q = F(t, point_id=id) 857 assert allclose(q60/3 + 2*q120/3, q) 858 859 860 861 #Check that domain.starttime isn't updated if later than file starttime but earlier 862 #than file end time 863 delta = 23 864 domain.starttime = start + delta 865 F = file_function(filename + '.sww', domain, 866 quantities = domain.conserved_quantities, 867 interpolation_points = interpolation_points) 868 assert allclose(domain.starttime, start+delta) 869 870 871 872 873 #Now try interpolation with delta offset 874 for id in range(len(interpolation_points)): 875 x = interpolation_points[id][0] 876 y = interpolation_points[id][1] 877 878 for i in range(20): 879 t = i*10 880 k = i%6 881 882 if k == 0: 883 q0 = F(t-delta, point_id=id) 884 q1 = F(t+60-delta, point_id=id) 885 886 q = F(t-delta, point_id=id) 887 assert allclose(q, (k*q1 + (6-k)*q0)/6) 888 889 890 os.remove(filename + '.sww') 669 891 670 892 def test_file_function_time_with_domain(self): -
inundation/pyvolution/util.py
r2562 r2679 307 307 308 308 from least_squares import Interpolation_function 309 #from fit_interpolate.interpolate import Interpolation_function 309 310 310 311 if not spatial:
Note: See TracChangeset
for help on using the changeset viewer.