Changeset 5519
- Timestamp:
- Jul 17, 2008, 9:10:03 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py
r5517 r5519 403 403 def test_set_vertex_values_using_general_interface_with_subset(self): 404 404 """test_set_vertex_values_using_general_interface_with_subset(self): 405 Test that indices and polygon works 405 406 Test that indices and polygon works (for constants values) 406 407 """ 407 408 … … 435 436 436 437 437 # Another polygon (pick triangle 1 and 2 (rightmost triangles) using centroids 438 # Another polygon (pick triangle 1 and 2 (rightmost triangles) 439 # using centroids 438 440 polygon = [[2.1, 0.0], [3.5,0.1], [2,2.2], [0.2,2]] 439 441 quantity.set_values(0.0) … … 457 459 [0,0,0]]) 458 460 459 #print 'done'460 461 461 462 # Test input checking … … 694 695 695 696 696 def XXXXtest_set_values_from_file_using_polygon(self): 697 def Xtest_set_values_from_file_using_polygon(self): 698 """test_set_values_from_file_using_polygon(self): 699 700 Test that polygon restriction works for general points data 701 """ 702 697 703 quantity = Quantity(self.mesh4) 698 704 … … 729 735 file.close() 730 736 731 # Create restricting polygon (containing vertex #4 (2,2) or centroid of triangle #1 (bce) 737 # Create restricting polygon (containing node #4 (2,2) and 738 # centroid of triangle #1 (bce) 732 739 polygon = [[1.0, 1.0], [4.0, 1.0], 733 740 [4.0, 4.0], [1.0, 4.0]] … … 747 754 748 755 # Get indices for vertex coordinates in polygon 749 indices = inside_polygon(quantity.domain.get_vertex_coordinates(), polygon) 756 indices = inside_polygon(quantity.domain.get_vertex_coordinates(), 757 polygon) 750 758 points = take(quantity.domain.get_vertex_coordinates(), indices) 751 759 … … 760 768 761 769 # Check vertices outside polygon are zero 762 indices = outside_polygon(quantity.domain.get_vertex_coordinates(), polygon) 770 indices = outside_polygon(quantity.domain.get_vertex_coordinates(), 771 polygon) 763 772 assert allclose(take(quantity.vertex_values.flat, indices), 764 773 0.0) … … 771 780 772 781 773 def Cache_cache_test_set_values_from_file(self): 782 def test_cache_test_set_values_from_file(self): 783 # FIXME (Ole): What is this about? 784 # I don't think it checks anything new 774 785 quantity = Quantity(self.mesh4) 775 786 … … 789 800 [ 3.0, 1.0]] 790 801 802 georef = Geo_reference(56, 0, 0) 791 803 data_geo_spatial = Geospatial_data(data_points, 792 geo_reference = Geo_reference(56, 0, 0)) 804 geo_reference=georef) 805 793 806 data_points_absolute = data_geo_spatial.get_data_points(absolute=True) 794 807 attributes = linear_function(data_points_absolute) 795 808 att = 'spam_and_eggs' 796 809 797 # Create .txt file810 # Create .txt file 798 811 ptsfile = tempfile.mktemp(".txt") 799 812 file = open(ptsfile,"w") … … 807 820 808 821 809 #Check that values can be set from file 810 quantity.set_values(filename = ptsfile, 811 attribute_name = att, alpha = 0, use_cache=True, 812 verbose=True) 822 # Check that values can be set from file 823 quantity.set_values(filename=ptsfile, 824 attribute_name=att, 825 alpha=0, 826 use_cache=True, 827 verbose=False) 813 828 answer = linear_function(quantity.domain.get_vertex_coordinates()) 814 815 #print quantity.vertex_values.flat816 #print answer817 818 819 829 assert allclose(quantity.vertex_values.flat, answer) 820 830 821 831 822 #Check that values can be set from file using default attribute 823 quantity.set_values(filename = ptsfile, alpha = 0) 832 # Check that values can be set from file using default attribute 833 quantity.set_values(filename=ptsfile, 834 alpha=0) 824 835 assert allclose(quantity.vertex_values.flat, answer) 825 836 826 #checking cache 827 #quantity.set_values(filename = ptsfile, 828 # attribute_name = att, alpha = 0, use_cache=True, 829 # verbose=True) 837 # Check cache 838 quantity.set_values(filename=ptsfile, 839 attribute_name=att, 840 alpha=0, 841 use_cache=True, 842 verbose=False) 843 844 830 845 #Cleanup 831 846 import os … … 858 873 859 874 #Check that values can be set from file 860 quantity.set_values(filename = txt_file, 861 attribute_name = att, alpha = 0) 875 quantity.set_values(filename=txt_file, 876 attribute_name=att, 877 alpha=0) 862 878 answer = linear_function(quantity.domain.get_vertex_coordinates()) 863 879 … … 869 885 870 886 #Check that values can be set from file using default attribute 871 quantity.set_values(filename = txt_file, alpha =0)887 quantity.set_values(filename=txt_file, alpha=0) 872 888 assert allclose(quantity.vertex_values.flat, answer) 873 889 … … 902 918 903 919 #Check that values can be set from file 904 quantity.set_values(filename =txt_file,905 attribute_name = att, alpha =0)920 quantity.set_values(filename=txt_file, 921 attribute_name=att, alpha=0) 906 922 answer = linear_function(quantity.domain.get_vertex_coordinates()) 907 923 … … 913 929 914 930 #Check that values can be set from file using default attribute 915 quantity.set_values(filename = txt_file, alpha =0)931 quantity.set_values(filename=txt_file, alpha=0) 916 932 assert allclose(quantity.vertex_values.flat, answer) 917 933 … … 958 974 959 975 #Check that values can be set from file 960 quantity.set_values(filename =pts_file,961 attribute_name = att, alpha =0)976 quantity.set_values(filename=pts_file, 977 attribute_name=att, alpha=0) 962 978 answer = linear_function(quantity.domain.get_vertex_coordinates()) 963 979 #print "quantity.vertex_values.flat", quantity.vertex_values.flat … … 967 983 968 984 #Check that values can be set from file using default attribute 969 quantity.set_values(filename = txt_file, alpha =0)985 quantity.set_values(filename=txt_file, alpha=0) 970 986 assert allclose(quantity.vertex_values.flat, answer) 971 987 … … 1040 1056 1041 1057 #Check that values can be set from file 1042 quantity.set_values(filename =pts_file,1043 attribute_name = att, alpha =0)1058 quantity.set_values(filename=pts_file, 1059 attribute_name=att, alpha=0) 1044 1060 answer = linear_function(quantity.domain.get_vertex_coordinates()) 1045 1061 #print "quantity.vertex_values.flat", quantity.vertex_values.flat … … 1049 1065 1050 1066 #Check that values can be set from file using default attribute 1051 quantity.set_values(filename = txt_file, alpha =0)1067 quantity.set_values(filename=txt_file, alpha=0) 1052 1068 assert allclose(quantity.vertex_values.flat, answer) 1053 1069 … … 1120 1136 1121 1137 #Check that values can be set from file 1122 quantity.set_values(filename =ptsfile,1123 attribute_name = att, alpha =0)1138 quantity.set_values(filename=ptsfile, 1139 attribute_name=att, alpha=0) 1124 1140 answer = linear_function(quantity.domain.get_vertex_coordinates()) 1125 1141 … … 1128 1144 1129 1145 #Check that values can be set from file using default attribute 1130 quantity.set_values(filename = ptsfile, alpha =0)1146 quantity.set_values(filename=ptsfile, alpha=0) 1131 1147 assert allclose(quantity.vertex_values.flat, answer) 1132 1148 … … 1197 1213 1198 1214 #Check that values can be set from file 1199 quantity.set_values(filename =ptsfile,1200 attribute_name = att, alpha =0)1215 quantity.set_values(filename=ptsfile, 1216 attribute_name=att, alpha=0) 1201 1217 answer = linear_function(quantity.domain. \ 1202 1218 get_vertex_coordinates(absolute=True)) … … 1207 1223 1208 1224 #Check that values can be set from file using default attribute 1209 quantity.set_values(filename = ptsfile, alpha =0)1225 quantity.set_values(filename=ptsfile, alpha=0) 1210 1226 assert allclose(quantity.vertex_values.flat, answer) 1211 1227 … … 1227 1243 1228 1244 quantity2 = Quantity(self.mesh4) 1229 quantity2.set_values(quantity =quantity1)1245 quantity2.set_values(quantity=quantity1) 1230 1246 assert allclose(quantity2.vertex_values, 1231 1247 [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) … … 1247 1263 1248 1264 1265 def Xtest_set_values_from_quantity_using_polygon(self): 1266 """test_set_values_from_quantity_using_polygon(self): 1267 1268 Check that polygon can be used to restrict set_values when 1269 using another quantity as argument. 1270 """ 1271 1272 # Create restricting polygon (containing node #4 (2,2) and 1273 # centroid of triangle #1 (bce) 1274 polygon = [[1.0, 1.0], [4.0, 1.0], 1275 [4.0, 4.0], [1.0, 4.0]] 1276 assert allclose(inside_polygon(self.mesh4.nodes, polygon), 4) 1277 1278 quantity1 = Quantity(self.mesh4) 1279 quantity1.set_vertex_values([0,1,2,3,4,5]) 1280 1281 assert allclose(quantity1.vertex_values, 1282 [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 1283 1284 1285 quantity2 = Quantity(self.mesh4) 1286 quantity2.set_values(quantity=quantity1, 1287 polygon=polygon) 1288 1289 msg = 'Only node #4(e) at (2,2) should have values applied ' 1290 assert allclose(quantity2.vertex_values, 1291 [[0,0,0], [0,0,4], [4,0,0], [0,0,4]]), msg 1292 #bac, bce, ecf, dbe 1293 1249 1294 1250 1295
Note: See TracChangeset
for help on using the changeset viewer.