source: trunk/anuga_work/development/gareth/tests/channel_floodplain/plotme.py @ 9252

Last change on this file since 9252 was 9252, checked in by davies, 10 years ago

Code to read list of riverwall input files

File size: 5.4 KB
Line 
1from anuga.utilities import plot_utils as util
2from matplotlib import pyplot as pyplot
3
4# Time-index to plot outputs from
5index=900
6
7p2 = util.get_output('channel_floodplain1.sww', 0.001)
8p=util.get_centroids(p2, velocity_extrapolation=True)
9
10
11v = (p.x>5.0)*(p.x<9.0)
12
13# Numerical results along a central channel 'slice'
14V1 = p.stage[index,v] - p.elev[v]
15V2 = p.yvel[index,v]
16V3 = p.xvel[index,v]
17
18##########################################################################
19# Analytical solution of steady uniform 2D flow in a trapezoidal channel.
20##########################################################################
21
22Qin=4.5 # Inflow discharge
23slp=1./300. # Floodplain slope (= water slope for steady uniform flow)
24man_n=0.03  # Manning's n
25Bcentral=6.0 #Flat bed width of the trapezoidal channel
26alpha=0.5  # Side slope of the trapezoidal banks
27
28k = (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
32def 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
41def minme(dc):
42    q1 = discharge_su(dc)
43    return (q1-Qin)**2.
44
45# Minimise the function mimne, to find the centre depth.
46import scipy.optimize
47dc_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
57pyplot.clf()
58pyplot.figure(figsize=(12.,8.))
59pyplot.plot(p.y[v], (V2**2)**0.5,'o', label='computed velocity')
60pyplot.plot(p.y[v], V2*0+k*dc_analytical**(2./3.), 'o', label='Analytical velocity')
61pyplot.plot(p.y[v], V1, 'o',label='computed depth')
62pyplot.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')
64pyplot.title('Mid channel velocities and depths, vs analytical velocities and depths')
65# But in my tests, they are not equal
66pyplot.legend( ('computed velocity', 'Analytical velocity', 'computed depth', 'analytical depth'), loc=4)
67pyplot.savefig('trapz_velocity_downstream_l0_eq_1_EL.png')
68
69# Plot velocity over the cross-section
70v1 = (p.y<500.0)&(p.y>490.0)
71
72pyplot.clf()
73analytical_stage = min(p.elev[v1]) + dc_analytical
74analytic_vel = ( (1./300.)*(analytical_stage-p.elev[v1])**(4./3.)*(1./0.03)**2.)**0.5
75analytic_vel = analytic_vel*(analytical_stage>p.elev[v1])
76pyplot.figure(figsize=(12.,8.))
77pyplot.plot(p.x[v1], p.yvel[index,v1],'o', label='computed velocity (m/s)')
78pyplot.plot(p.x[v1], analytic_vel,'o', label='analytical velocity (m/s)')
79pyplot.plot(p.x[v1],p.elev[v1],'o', label='bed elevation (m)')
80pyplot.plot(p.x[v1],p.stage[index,v1],'o', label='computed stage (m)')
81pyplot.plot(p.x[v1],p.stage[index,v1]*0. + analytical_stage,'o', label='analytical stage (m)')
82
83pyplot.legend( ('computed velocity (m/s)', 'analytical velocity (m/s)', 'bed elevation (m)', 'computed stage (m)', 'analytical_stage (m)') ,loc=10)
84pyplot.title('Velocity (analytical and numerical) and Stage:' + '\n' +'Central channel regions (470 to 500m)' +'\n')
85pyplot.savefig('trapz_velocity_cross_channel_l0_eq_1_EL.png') 
86
87
88# Plot velocity over the cross-section
89v1 = (p.y<800.0)&(p.y>790.0)
90
91pyplot.clf()
92analytical_stage = min(p.elev[v1]) + dc_analytical
93analytic_vel = ( (1./300.)*(analytical_stage-p.elev[v1])**(4./3.)*(1./0.03)**2.)**0.5
94analytic_vel = analytic_vel*(analytical_stage>p.elev[v1])
95pyplot.figure(figsize=(12.,8.))
96pyplot.plot(p.x[v1], p.yvel[index,v1],'o', label='computed velocity (m/s)')
97pyplot.plot(p.x[v1], analytic_vel,'o', label='analytical velocity (m/s)')
98pyplot.plot(p.x[v1],p.elev[v1],'o', label='bed elevation (m)')
99pyplot.plot(p.x[v1],p.stage[index,v1],'o', label='computed stage (m)')
100pyplot.plot(p.x[v1],p.stage[index,v1]*0. + analytical_stage,'o', label='analytical stage (m)')
101
102pyplot.legend( ('computed velocity (m/s)', 'analytical velocity (m/s)', 'bed elevation (m)', 'computed stage (m)', 'analytical_stage (m)') ,loc=10)
103pyplot.title('Velocity (analytical and numerical) and Stage:' + '\n' +'Central channel regions (470 to 500m)' +'\n')
104pyplot.savefig('trapz_velocity_cross_channel_l0_eq_1b_EL.png') 
105
106# Plot velocity over the cross-section
107v1 = (p.y<900.0)&(p.y>890.0)
108
109pyplot.clf()
110analytical_stage = min(p.elev[v1]) + dc_analytical
111analytic_vel = ( (1./300.)*(analytical_stage-p.elev[v1])**(4./3.)*(1./0.03)**2.)**0.5
112analytic_vel = analytic_vel*(analytical_stage>p.elev[v1])
113pyplot.figure(figsize=(12.,8.))
114pyplot.plot(p.x[v1], p.yvel[index,v1],'o', label='computed velocity (m/s)')
115pyplot.plot(p.x[v1], analytic_vel,'o', label='analytical velocity (m/s)')
116pyplot.plot(p.x[v1],p.elev[v1],'o', label='bed elevation (m)')
117pyplot.plot(p.x[v1],p.stage[index,v1],'o', label='computed stage (m)')
118pyplot.plot(p.x[v1],p.stage[index,v1]*0. + analytical_stage,'o', label='analytical stage (m)')
119
120pyplot.legend( ('computed velocity (m/s)', 'analytical velocity (m/s)', 'bed elevation (m)', 'computed stage (m)', 'analytical_stage (m)') , loc=10)
121pyplot.title('Velocity (analytical and numerical) and Stage:' + '\n' +'Central channel regions (870 to 900m)' +'\n')
122pyplot.savefig('trapz_velocity_cross_channel_l0_eq_1c_EL.png') 
Note: See TracBrowser for help on using the repository browser.