1 | import util |
---|
2 | from matplotlib import pyplot as pyplot |
---|
3 | #import pylab |
---|
4 | |
---|
5 | # Time-index to plot outputs from |
---|
6 | index=900 |
---|
7 | |
---|
8 | #p2 = util.get_output('channel_floodplain1_bal_dev.sww', minimum_allowed_height=0.01) |
---|
9 | #p=p2 |
---|
10 | #p=util.get_centroids(p2, velocity_extrapolation=True) |
---|
11 | |
---|
12 | p2 = util.get_output('channel_floodplain1_bal_dev_lowvisc.sww', 0.01) |
---|
13 | p=util.get_centroids(p2, velocity_extrapolation=True) |
---|
14 | |
---|
15 | |
---|
16 | #p2 = util.get_output('channel_floodplain1_test_edge_lim.sww', minimum_allowed_height=0.01) |
---|
17 | #p2 = util.get_output('channel_floodplain1_test.sww', minimum_allowed_height=0.01) |
---|
18 | #p=util.get_centroids(p2, velocity_extrapolation=False) |
---|
19 | |
---|
20 | #p2 = util.get_output('channel_floodplain1_standard.sww', minimum_allowed_height=0.01) |
---|
21 | #p2 = util.get_output('channel_floodplain1_balanced_basic.sww', minimum_allowed_height=0.01) |
---|
22 | #p2 = util.get_output('channel_floodplain1_dev.sww') |
---|
23 | #p=util.get_centroids(p2, velocity_extrapolation=True) |
---|
24 | #p=p2 |
---|
25 | v = (p.x>6.0)*(p.x<8.0) |
---|
26 | #util.animate_1D(p.time, p.stage[:, v], p.y[v]) |
---|
27 | |
---|
28 | # Numerical results along a central channel 'slice' |
---|
29 | V1 = p.stage[index,v] - p.elev[v] |
---|
30 | V2 = p.yvel[index,v] |
---|
31 | V3 = p.xvel[index,v] |
---|
32 | |
---|
33 | ########################################################################## |
---|
34 | # Analytical solution of steady uniform 2D flow in a trapezoidal channel. |
---|
35 | ########################################################################## |
---|
36 | |
---|
37 | #Qin=6.6339 # Inflow discharge |
---|
38 | #Qin=5.2 |
---|
39 | Qin=4.6932 |
---|
40 | #Qin=4.693286 # Inflow discharge |
---|
41 | slp=1./300. # Floodplain slope (= water slope for steady uniform flow) |
---|
42 | man_n=0.03 # Manning's n |
---|
43 | Bcentral=6.0 #Flat bed width of the trapezoidal channel |
---|
44 | alpha=0.5 # Side slope of the trapezoidal banks |
---|
45 | |
---|
46 | k = (slp*(1./man_n)**2)**0.5 # At any point, the analytical solution says U = k*d^(2/3) |
---|
47 | |
---|
48 | # Function to calculate the discharge, given the channel centre depth dc, assuming |
---|
49 | # steady uniform flow |
---|
50 | def discharge_su(dc): |
---|
51 | if(alpha>0.): |
---|
52 | out = 2*k*( 3./(8.*alpha)*(dc)**(8./3.)) +Bcentral*k*(dc)**(5./3.) |
---|
53 | else: |
---|
54 | out = Bcentral*k*(dc)**(5./3.) |
---|
55 | |
---|
56 | return out |
---|
57 | |
---|
58 | # Function that will be minimized to find the depth associated with discharge Qin |
---|
59 | def minme(dc): |
---|
60 | q1 = discharge_su(dc) |
---|
61 | return (q1-Qin)**2. |
---|
62 | |
---|
63 | # Minimise the function mimne, to find the centre depth. |
---|
64 | import scipy.optimize |
---|
65 | dc_analytical = scipy.optimize.fmin(minme, x0=1.0)[0] |
---|
66 | |
---|
67 | |
---|
68 | |
---|
69 | ################################## |
---|
70 | # Plots |
---|
71 | ################################## |
---|
72 | |
---|
73 | # Analytical solution has U*abs(U)*n^2 / D^(4./3.) = Sf = bed slope |
---|
74 | # Hence, the following two variables should be equal -- I have checked that x velocities are fairly small |
---|
75 | pyplot.clf() |
---|
76 | pyplot.figure(figsize=(12.,8.)) |
---|
77 | pyplot.plot(p.y[v], (V2**2)**0.5,'o', label='computed velocity') |
---|
78 | pyplot.plot(p.y[v], V2*0+k*dc_analytical**(2./3.), 'o', label='Analytical velocity') |
---|
79 | pyplot.plot(p.y[v], V1, 'o',label='computed depth') |
---|
80 | pyplot.plot(p.y[v], V1*0. + dc_analytical, 'o', label='analytical depth') |
---|
81 | #pyplot.plot( ( (1./300.)*V1**(4./3.)*(1./0.03)**2.)**0.5,'o', label='Analytical velocity based on computed depth') |
---|
82 | pyplot.title('Mid channel velocities and depths, vs analytical velocities and depths') |
---|
83 | # But in my tests, they are not equal |
---|
84 | pyplot.legend( ('computed velocity', 'Analytical velocity', 'computed depth', 'analytical depth'), loc=4) |
---|
85 | pyplot.savefig('trapz_velocity_downstream_l0_eq_1_EL.png') |
---|
86 | |
---|
87 | # Plot velocity over the cross-section |
---|
88 | v1 = (p.y<500.0)&(p.y>490.0) |
---|
89 | |
---|
90 | pyplot.clf() |
---|
91 | analytical_stage = min(p.elev[v1]) + dc_analytical |
---|
92 | analytic_vel = ( (1./300.)*(analytical_stage-p.elev[v1])**(4./3.)*(1./0.03)**2.)**0.5 |
---|
93 | analytic_vel = analytic_vel*(analytical_stage>p.elev[v1]) |
---|
94 | pyplot.figure(figsize=(12.,8.)) |
---|
95 | pyplot.plot(p.x[v1], p.yvel[index,v1],'o', label='computed velocity (m/s)') |
---|
96 | pyplot.plot(p.x[v1], analytic_vel,'o', label='analytical velocity (m/s)') |
---|
97 | pyplot.plot(p.x[v1],p.elev[v1],'o', label='bed elevation (m)') |
---|
98 | pyplot.plot(p.x[v1],p.stage[index,v1],'o', label='computed stage (m)') |
---|
99 | pyplot.plot(p.x[v1],p.stage[index,v1]*0. + analytical_stage,'o', label='analytical stage (m)') |
---|
100 | |
---|
101 | pyplot.legend( ('computed velocity (m/s)', 'analytical velocity (m/s)', 'bed elevation (m)', 'computed stage (m)', 'analytical_stage (m)') ,loc=10) |
---|
102 | pyplot.title('Velocity (analytical and numerical) and Stage:' + '\n' +'Central channel regions (470 to 500m)' +'\n') |
---|
103 | pyplot.savefig('trapz_velocity_cross_channel_l0_eq_1_EL.png') |
---|
104 | |
---|
105 | |
---|
106 | # Plot velocity over the cross-section |
---|
107 | v1 = (p.y<800.0)&(p.y>790.0) |
---|
108 | |
---|
109 | pyplot.clf() |
---|
110 | analytical_stage = min(p.elev[v1]) + dc_analytical |
---|
111 | analytic_vel = ( (1./300.)*(analytical_stage-p.elev[v1])**(4./3.)*(1./0.03)**2.)**0.5 |
---|
112 | analytic_vel = analytic_vel*(analytical_stage>p.elev[v1]) |
---|
113 | pyplot.figure(figsize=(12.,8.)) |
---|
114 | pyplot.plot(p.x[v1], p.yvel[index,v1],'o', label='computed velocity (m/s)') |
---|
115 | pyplot.plot(p.x[v1], analytic_vel,'o', label='analytical velocity (m/s)') |
---|
116 | pyplot.plot(p.x[v1],p.elev[v1],'o', label='bed elevation (m)') |
---|
117 | pyplot.plot(p.x[v1],p.stage[index,v1],'o', label='computed stage (m)') |
---|
118 | pyplot.plot(p.x[v1],p.stage[index,v1]*0. + analytical_stage,'o', label='analytical stage (m)') |
---|
119 | |
---|
120 | pyplot.legend( ('computed velocity (m/s)', 'analytical velocity (m/s)', 'bed elevation (m)', 'computed stage (m)', 'analytical_stage (m)') ,loc=10) |
---|
121 | pyplot.title('Velocity (analytical and numerical) and Stage:' + '\n' +'Central channel regions (470 to 500m)' +'\n') |
---|
122 | pyplot.savefig('trapz_velocity_cross_channel_l0_eq_1b_EL.png') |
---|
123 | |
---|
124 | # Plot velocity over the cross-section |
---|
125 | v1 = (p.y<900.0)&(p.y>890.0) |
---|
126 | |
---|
127 | pyplot.clf() |
---|
128 | analytical_stage = min(p.elev[v1]) + dc_analytical |
---|
129 | analytic_vel = ( (1./300.)*(analytical_stage-p.elev[v1])**(4./3.)*(1./0.03)**2.)**0.5 |
---|
130 | analytic_vel = analytic_vel*(analytical_stage>p.elev[v1]) |
---|
131 | pyplot.figure(figsize=(12.,8.)) |
---|
132 | pyplot.plot(p.x[v1], p.yvel[index,v1],'o', label='computed velocity (m/s)') |
---|
133 | pyplot.plot(p.x[v1], analytic_vel,'o', label='analytical velocity (m/s)') |
---|
134 | pyplot.plot(p.x[v1],p.elev[v1],'o', label='bed elevation (m)') |
---|
135 | pyplot.plot(p.x[v1],p.stage[index,v1],'o', label='computed stage (m)') |
---|
136 | pyplot.plot(p.x[v1],p.stage[index,v1]*0. + analytical_stage,'o', label='analytical stage (m)') |
---|
137 | |
---|
138 | pyplot.legend( ('computed velocity (m/s)', 'analytical velocity (m/s)', 'bed elevation (m)', 'computed stage (m)', 'analytical_stage (m)') , loc=10) |
---|
139 | pyplot.title('Velocity (analytical and numerical) and Stage:' + '\n' +'Central channel regions (870 to 900m)' +'\n') |
---|
140 | pyplot.savefig('trapz_velocity_cross_channel_l0_eq_1c_EL.png') |
---|