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

Last change on this file since 8547 was 8547, checked in by davies, 12 years ago

Major experimental changes to balanced_dev

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