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