Changeset 341
- Timestamp:
- Sep 22, 2004, 3:38:34 PM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/data_manager.py
r288 r341 2 2 There are two kinds of data 3 3 4 1: Constant data: Vertex coordinates and field values 5 2: Variable data: Conserved quantities 4 1: Constant data: Vertex coordinates and field values. Stored once 5 2: Variable data: Conserved quantities. Stored once per timestep. 6 6 7 7 All data is assumed to reside at vertex locations. … … 134 134 return glob.glob(pattern) 135 135 136 #Native checkpoint format.137 #Information needed to recreate a state is preserved138 #FIXME: Rethink and maybe use netcdf format139 def cpt_variable_writer(filename, t, v0, v1, v2):140 """Store all conserved quantities to file141 """142 143 M, N = v0.shape144 145 FN = create_filename(filename, 'cpt', M, t)146 #print 'Writing to %s' %FN147 148 fid = open(FN, 'w')149 for i in range(M):150 for j in range(N):151 fid.write('%.16e ' %v0[i,j])152 for j in range(N):153 fid.write('%.16e ' %v1[i,j])154 for j in range(N):155 fid.write('%.16e ' %v2[i,j])156 157 fid.write('\n')158 fid.close()159 160 161 def cpt_variable_reader(filename, t, v0, v1, v2):162 """Store all conserved quantities to file163 """164 165 M, N = v0.shape166 167 FN = create_filename(filename, 'cpt', M, t)168 #print 'Reading from %s' %FN169 170 fid = open(FN)171 172 173 for i in range(M):174 values = fid.readline().split() #Get one line175 176 for j in range(N):177 v0[i,j] = float(values[j])178 v1[i,j] = float(values[3+j])179 v2[i,j] = float(values[6+j])180 181 fid.close()182 183 def cpt_constant_writer(filename, X0, X1, X2, v0, v1, v2):184 """Writes x,y,z,z,z coordinates of triangles constituting the bed185 elevation.186 Not in use pt187 """188 189 M, N = v0.shape190 191 print X0192 import sys; sys.exit()193 FN = create_filename(filename, 'cpt', M)194 print 'Writing to %s' %FN195 196 fid = open(FN, 'w')197 for i in range(M):198 for j in range(2):199 fid.write('%.16e ' %X0[i,j]) #x, y200 for j in range(N):201 fid.write('%.16e ' %v0[i,j]) #z,z,z,202 203 for j in range(2):204 fid.write('%.16e ' %X1[i,j]) #x, y205 for j in range(N):206 fid.write('%.16e ' %v1[i,j])207 208 for j in range(2):209 fid.write('%.16e ' %X2[i,j]) #x, y210 for j in range(N):211 fid.write('%.16e ' %v2[i,j])212 213 fid.write('\n')214 fid.close()215 216 217 218 #Function for storing out to e.g. visualisation219 #FIXME: Do we want this?220 #FIXME: Not done yet for this version221 def dat_constant_writer(filename, X0, X1, X2, v0, v1, v2):222 """Writes x,y,z coordinates of triangles constituting the bed elevation.223 """224 225 M, N = v0.shape226 227 FN = create_filename(filename, 'dat', M)228 #print 'Writing to %s' %FN229 230 fid = open(FN, 'w')231 for i in range(M):232 for j in range(2):233 fid.write('%f ' %X0[i,j]) #x, y234 fid.write('%f ' %v0[i,0]) #z235 236 for j in range(2):237 fid.write('%f ' %X1[i,j]) #x, y238 fid.write('%f ' %v1[i,0]) #z239 240 for j in range(2):241 fid.write('%f ' %X2[i,j]) #x, y242 fid.write('%f ' %v2[i,0]) #z243 244 fid.write('\n')245 fid.close()246 247 248 249 def dat_variable_writer(filename, t, v0, v1, v2):250 """Store water height to file251 """252 253 M, N = v0.shape254 255 FN = create_filename(filename, 'dat', M, t)256 #print 'Writing to %s' %FN257 258 fid = open(FN, 'w')259 for i in range(M):260 fid.write('%.4f ' %v0[i,0])261 fid.write('%.4f ' %v1[i,0])262 fid.write('%.4f ' %v2[i,0])263 264 fid.write('\n')265 fid.close()266 136 267 137 … … 901 771 902 772 773 #OBSOLETE STUFF 774 #Native checkpoint format. 775 #Information needed to recreate a state is preserved 776 #FIXME: Rethink and maybe use netcdf format 777 def cpt_variable_writer(filename, t, v0, v1, v2): 778 """Store all conserved quantities to file 779 """ 780 781 M, N = v0.shape 782 783 FN = create_filename(filename, 'cpt', M, t) 784 #print 'Writing to %s' %FN 785 786 fid = open(FN, 'w') 787 for i in range(M): 788 for j in range(N): 789 fid.write('%.16e ' %v0[i,j]) 790 for j in range(N): 791 fid.write('%.16e ' %v1[i,j]) 792 for j in range(N): 793 fid.write('%.16e ' %v2[i,j]) 794 795 fid.write('\n') 796 fid.close() 797 798 799 def cpt_variable_reader(filename, t, v0, v1, v2): 800 """Store all conserved quantities to file 801 """ 802 803 M, N = v0.shape 804 805 FN = create_filename(filename, 'cpt', M, t) 806 #print 'Reading from %s' %FN 807 808 fid = open(FN) 809 810 811 for i in range(M): 812 values = fid.readline().split() #Get one line 813 814 for j in range(N): 815 v0[i,j] = float(values[j]) 816 v1[i,j] = float(values[3+j]) 817 v2[i,j] = float(values[6+j]) 818 819 fid.close() 820 821 def cpt_constant_writer(filename, X0, X1, X2, v0, v1, v2): 822 """Writes x,y,z,z,z coordinates of triangles constituting the bed 823 elevation. 824 Not in use pt 825 """ 826 827 M, N = v0.shape 828 829 print X0 830 import sys; sys.exit() 831 FN = create_filename(filename, 'cpt', M) 832 print 'Writing to %s' %FN 833 834 fid = open(FN, 'w') 835 for i in range(M): 836 for j in range(2): 837 fid.write('%.16e ' %X0[i,j]) #x, y 838 for j in range(N): 839 fid.write('%.16e ' %v0[i,j]) #z,z,z, 840 841 for j in range(2): 842 fid.write('%.16e ' %X1[i,j]) #x, y 843 for j in range(N): 844 fid.write('%.16e ' %v1[i,j]) 845 846 for j in range(2): 847 fid.write('%.16e ' %X2[i,j]) #x, y 848 for j in range(N): 849 fid.write('%.16e ' %v2[i,j]) 850 851 fid.write('\n') 852 fid.close() 853 854 855 856 #Function for storing out to e.g. visualisation 857 #FIXME: Do we want this? 858 #FIXME: Not done yet for this version 859 def dat_constant_writer(filename, X0, X1, X2, v0, v1, v2): 860 """Writes x,y,z coordinates of triangles constituting the bed elevation. 861 """ 862 863 M, N = v0.shape 864 865 FN = create_filename(filename, 'dat', M) 866 #print 'Writing to %s' %FN 867 868 fid = open(FN, 'w') 869 for i in range(M): 870 for j in range(2): 871 fid.write('%f ' %X0[i,j]) #x, y 872 fid.write('%f ' %v0[i,0]) #z 873 874 for j in range(2): 875 fid.write('%f ' %X1[i,j]) #x, y 876 fid.write('%f ' %v1[i,0]) #z 877 878 for j in range(2): 879 fid.write('%f ' %X2[i,j]) #x, y 880 fid.write('%f ' %v2[i,0]) #z 881 882 fid.write('\n') 883 fid.close() 884 885 886 887 def dat_variable_writer(filename, t, v0, v1, v2): 888 """Store water height to file 889 """ 890 891 M, N = v0.shape 892 893 FN = create_filename(filename, 'dat', M, t) 894 #print 'Writing to %s' %FN 895 896 fid = open(FN, 'w') 897 for i in range(M): 898 fid.write('%.4f ' %v0[i,0]) 899 fid.write('%.4f ' %v1[i,0]) 900 fid.write('%.4f ' %v2[i,0]) 901 902 fid.write('\n') 903 fid.close() 904
Note: See TracChangeset
for help on using the changeset viewer.