1 | """Read in sww file, interpolate at specified locations and |
---|
2 | Cross section at specified T |
---|
3 | |
---|
4 | """ |
---|
5 | from os import sep |
---|
6 | import Numeric |
---|
7 | import project |
---|
8 | from pyvolution.util import file_function |
---|
9 | from create_buildings import WidtH |
---|
10 | # from run_friction import fric |
---|
11 | from pylab import * |
---|
12 | |
---|
13 | fric = 'mid_limit_0' # FILE LABEL |
---|
14 | #swwfile = project.newoutputname + '.sww' |
---|
15 | #swwfile = project.outputname |
---|
16 | |
---|
17 | #swwfile_B = project.outputdir + sep + 'Buildings_3790.sww' |
---|
18 | swwfile_B = project.outputdir + sep + 'buildings_Str_D=5.8_976.sww' |
---|
19 | #swwfile_F = project.outputdir + sep + 'buildings_Str_half_Off_D=6.89_1116.sww' |
---|
20 | #swwfile_B = project.outputdir + sep + 'friction_n=6_3135.sww' |
---|
21 | swwfile_F = project.outputdir + sep + 'friction_n=0.9_3135.sww' |
---|
22 | |
---|
23 | # gauge_depth = Numeric.arrayrange(51, 1.5*WidtH, 25) # Random special |
---|
24 | |
---|
25 | #gauge_depth = Numeric.arrayrange(0, 5*WidtH, 5) |
---|
26 | gauge_depth = [49.600000000000001, 74.6, 99.6, 124.6, 149.6, 174.6, 199.6, 224.6, 240.00999999999999] |
---|
27 | |
---|
28 | gauge_breadth = 100 |
---|
29 | gauge_locations = [] |
---|
30 | |
---|
31 | for GD in gauge_depth: |
---|
32 | gauge_location = [GD,gauge_breadth] |
---|
33 | gauge_locations.append(gauge_location) |
---|
34 | |
---|
35 | |
---|
36 | #Read model output |
---|
37 | quantities = ['stage', 'xmomentum', 'ymomentum'] |
---|
38 | |
---|
39 | f_B = file_function(swwfile_B, |
---|
40 | quantities = quantities, |
---|
41 | interpolation_points = gauge_locations, |
---|
42 | verbose = True, |
---|
43 | use_cache = False) |
---|
44 | |
---|
45 | f_F = file_function(swwfile_F, |
---|
46 | quantities = quantities, |
---|
47 | interpolation_points = gauge_locations, |
---|
48 | verbose = True, |
---|
49 | use_cache = False) |
---|
50 | |
---|
51 | |
---|
52 | T = Numeric.arrayrange(700,1000,10) |
---|
53 | #T = [ 20, 50, 100, 150, 200 ] |
---|
54 | |
---|
55 | for t in T: |
---|
56 | model_time = [] |
---|
57 | stages_B = [] |
---|
58 | stages_F = [] |
---|
59 | elevations = [] |
---|
60 | momenta = [] |
---|
61 | velocity = [] |
---|
62 | for i, GL in enumerate(gauge_depth): |
---|
63 | |
---|
64 | # mines data from specified time values in sww file |
---|
65 | wB = f_B(t, point_id = i)[0] |
---|
66 | uhB = f_B(t, point_id = i)[1] |
---|
67 | vhB = f_B(t, point_id = i)[2] |
---|
68 | |
---|
69 | wF = f_F(t, point_id = i)[0] |
---|
70 | uhF = f_B(t, point_id = i)[1] |
---|
71 | vhF = f_B(t, point_id = i)[2] |
---|
72 | #m = sqrt(uh*uh + vh*vh) #Absolute momentum |
---|
73 | velB = sqrt(uhB*uhB + vhB*vhB) / (wB + 1.e-30) #Absolute velocity |
---|
74 | velF = sqrt(uhF*uhF + vhF*vhF) / (wF + 1.e-30) #Absolute velocity |
---|
75 | #print velB, "buiding velocity" |
---|
76 | #print velF, "friction velocity" |
---|
77 | |
---|
78 | stages_B.append(wB) |
---|
79 | stages_F.append(wF) |
---|
80 | #elevations.append(zB) #Should be constant over time |
---|
81 | #momenta.append(mB) |
---|
82 | #velocityB.append(velB) |
---|
83 | #velocityF.append(velF) |
---|
84 | |
---|
85 | #print len(stages), "stages" |
---|
86 | diff = abs(Numeric.array(stages_B) - Numeric.array(stages_F)) |
---|
87 | #print diff, "difference" |
---|
88 | |
---|
89 | |
---|
90 | ion() |
---|
91 | hold(True) |
---|
92 | subplot(211) |
---|
93 | |
---|
94 | plot(gauge_depth, stages_B, '-b',gauge_depth,stages_F,'-r') |
---|
95 | title('Stage@Time_%d_ vs Gauge length (m)[red: fric, blue: buildings] ' %t) |
---|
96 | xlabel('gauge length(m)') |
---|
97 | ylabel('water depths (m)') |
---|
98 | #savefig('Comp_Time%d_B_vs_F' %t) |
---|
99 | hold(False) |
---|
100 | |
---|
101 | print stages_F, " stages" |
---|
102 | print gauge_depth, " gauge depths" |
---|
103 | diff_area_F = trapz(gauge_depth,stages_F) |
---|
104 | diff_area_B = trapz(gauge_depth,stages_B) |
---|
105 | diff_area = abs(diff_area_F) - abs(diff_area_B) |
---|
106 | print diff_area, " <<< diff area*********" |
---|
107 | #savefig('Final_comp_n=%s' %fric) |
---|
108 | subplot(212) |
---|
109 | subplots_adjust(hspace = 0.4) |
---|
110 | plot(gauge_depth, diff, 'g') |
---|
111 | title('Final Differences in water levels') |
---|
112 | xlabel('gauge length(m)') |
---|
113 | ylabel('water differences (m)') |
---|
114 | savefig('Final_Water_diff_n=%s' %fric) |
---|
115 | print "finished" |
---|
116 | |
---|
117 | |
---|