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

Last change on this file since 8375 was 8375, checked in by davies, 13 years ago

balanced_dev: fixed stack overflow problem, & new 'transect plot'
routine in util.py

File size: 6.3 KB
Line 
1import util
2from matplotlib import pyplot as pyplot
3#import pylab
4
5# Time-index to plot outputs from
6index=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
12p2 = util.get_output('channel_floodplain1_bal_dev_lowvisc.sww', 0.01)
13p=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
25v = (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'
29V1 = p.stage[index,v] - p.elev[v]
30V2 = p.yvel[index,v]
31V3 = 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
39Qin=4.6932
40#Qin=4.693286 # Inflow discharge
41slp=1./300. # Floodplain slope (= water slope for steady uniform flow)
42man_n=0.03  # Manning's n
43Bcentral=6.0 #Flat bed width of the trapezoidal channel
44alpha=0.5  # Side slope of the trapezoidal banks
45
46k = (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
50def 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
59def minme(dc):
60    q1 = discharge_su(dc)
61    return (q1-Qin)**2.
62
63# Minimise the function mimne, to find the centre depth.
64import scipy.optimize
65dc_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
75pyplot.clf()
76pyplot.figure(figsize=(12.,8.))
77pyplot.plot(p.y[v], (V2**2)**0.5,'o', label='computed velocity')
78pyplot.plot(p.y[v], V2*0+k*dc_analytical**(2./3.), 'o', label='Analytical velocity')
79pyplot.plot(p.y[v], V1, 'o',label='computed depth')
80pyplot.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')
82pyplot.title('Mid channel velocities and depths, vs analytical velocities and depths')
83# But in my tests, they are not equal
84pyplot.legend( ('computed velocity', 'Analytical velocity', 'computed depth', 'analytical depth'), loc=4)
85pyplot.savefig('trapz_velocity_downstream_l0_eq_1_EL.png')
86
87# Plot velocity over the cross-section
88v1 = (p.y<500.0)&(p.y>490.0)
89
90pyplot.clf()
91analytical_stage = min(p.elev[v1]) + dc_analytical
92analytic_vel = ( (1./300.)*(analytical_stage-p.elev[v1])**(4./3.)*(1./0.03)**2.)**0.5
93analytic_vel = analytic_vel*(analytical_stage>p.elev[v1])
94pyplot.figure(figsize=(12.,8.))
95pyplot.plot(p.x[v1], p.yvel[index,v1],'o', label='computed velocity (m/s)')
96pyplot.plot(p.x[v1], analytic_vel,'o', label='analytical velocity (m/s)')
97pyplot.plot(p.x[v1],p.elev[v1],'o', label='bed elevation (m)')
98pyplot.plot(p.x[v1],p.stage[index,v1],'o', label='computed stage (m)')
99pyplot.plot(p.x[v1],p.stage[index,v1]*0. + analytical_stage,'o', label='analytical stage (m)')
100
101pyplot.legend( ('computed velocity (m/s)', 'analytical velocity (m/s)', 'bed elevation (m)', 'computed stage (m)', 'analytical_stage (m)') ,loc=10)
102pyplot.title('Velocity (analytical and numerical) and Stage:' + '\n' +'Central channel regions (470 to 500m)' +'\n')
103pyplot.savefig('trapz_velocity_cross_channel_l0_eq_1_EL.png') 
104
105
106# Plot velocity over the cross-section
107v1 = (p.y<800.0)&(p.y>790.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 (470 to 500m)' +'\n')
122pyplot.savefig('trapz_velocity_cross_channel_l0_eq_1b_EL.png') 
123
124# Plot velocity over the cross-section
125v1 = (p.y<900.0)&(p.y>890.0)
126
127pyplot.clf()
128analytical_stage = min(p.elev[v1]) + dc_analytical
129analytic_vel = ( (1./300.)*(analytical_stage-p.elev[v1])**(4./3.)*(1./0.03)**2.)**0.5
130analytic_vel = analytic_vel*(analytical_stage>p.elev[v1])
131pyplot.figure(figsize=(12.,8.))
132pyplot.plot(p.x[v1], p.yvel[index,v1],'o', label='computed velocity (m/s)')
133pyplot.plot(p.x[v1], analytic_vel,'o', label='analytical velocity (m/s)')
134pyplot.plot(p.x[v1],p.elev[v1],'o', label='bed elevation (m)')
135pyplot.plot(p.x[v1],p.stage[index,v1],'o', label='computed stage (m)')
136pyplot.plot(p.x[v1],p.stage[index,v1]*0. + analytical_stage,'o', label='analytical stage (m)')
137
138pyplot.legend( ('computed velocity (m/s)', 'analytical velocity (m/s)', 'bed elevation (m)', 'computed stage (m)', 'analytical_stage (m)') , loc=10)
139pyplot.title('Velocity (analytical and numerical) and Stage:' + '\n' +'Central channel regions (870 to 900m)' +'\n')
140pyplot.savefig('trapz_velocity_cross_channel_l0_eq_1c_EL.png') 
Note: See TracBrowser for help on using the repository browser.