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

Last change on this file since 8990 was 8990, checked in by davies, 11 years ago

First-draft Audusse-type solver in anuga_work/gareth/development/experimental/bal_and

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