source: trunk/anuga_work/development/2010-projects/anuga_1d/sww/run_parabolic_canal.py @ 8189

Last change on this file since 8189 was 8189, checked in by steve, 13 years ago

Added in Sudi's most recent 1d codes

File size: 3.2 KB
Line 
1import os
2from math import sqrt, pi, sin, cos
3import numpy
4import time
5
6
7from anuga_1d.sww.sww_domain import *
8from anuga_1d.config import g, epsilon
9from anuga_1d.base.generic_mesh import uniform_mesh
10
11#===============================================================================
12# setup problem
13#===============================================================================
14
15
16z_infty = 5.0       ## max equilibrium water depth at lowest point.
17L_x = 2500.0         ## width of channel
18A0 = 0.5*L_x                  ## determines amplitudes of oscillations
19omega = sqrt(2*g*z_infty)/L_x ## angular frequency of osccilation
20
21def analytic_canal(x,t):
22    u = numpy.zeros_like(x)    ## water velocity
23    h = numpy.zeros_like(x)    ## water depth
24
25    ## Define Basin Bathymetry
26    z = numpy.zeros_like(x) ## elevation of basin
27    w = numpy.zeros_like(x)   ## elevation of water surface
28
29    z[:] = z_infty*(x**2/L_x**2)
30    u[:] = -A0*omega*sin(omega*t)
31    w[:] = numpy.maximum(z_infty+2*A0*z_infty/L_x*cos(omega*t)*(x/L_x-0.5*A0/(L_x)*cos(omega*t)),z)
32    h[:] = numpy.maximum(w-z, 0.0)
33
34    T = 2.0*pi/omega
35
36    return u,h,w,z, T
37
38
39def stage(x):
40    t=0.0
41    u,h,w,z,T = analytic_canal(x,t)
42
43    return w
44
45def elevation(x):
46    t=0.0
47    u,h,w,z,T = analytic_canal(x,t)
48
49    return z
50
51
52def height(x):
53    t=0.0
54    u,h,w,z,T = analytic_canal(x,t)
55
56    return h
57
58
59#===============================================================================
60finaltime = 1000.0
61yieldstep = 10.0
62
63
64
65N = 100
66print "Evaluating domain with %d cells" %N
67domain = Domain(*uniform_mesh(N, x_0 = -2.0*L_x, x_1 = 2.0*L_x))
68
69domain.set_spatial_order(2)
70domain.set_timestepping_method('rk2')
71domain.set_CFL(1.0)
72domain.set_limiter("minmod_kurganov")
73
74domain.set_beta(1.0)
75
76domain.set_quantity('stage', stage)
77domain.set_quantity('elevation',elevation)
78
79domain.quantities['elevation'].extrapolate_second_order()
80domain.quantities['stage'].extrapolate_second_order()
81
82Br = Reflective_boundary(domain)
83
84domain.set_boundary({'left': Br, 'right' : Br})
85
86#domain.h0=0.0001
87
88t0 = time.time()
89
90for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
91    domain.write_time()
92
93print 'That took %.2f seconds' %(time.time()-t0)
94
95
96N = float(N)
97HeightC    = domain.quantities['height'].centroid_values
98StageC     = domain.quantities['stage'].centroid_values
99BedC       = domain.quantities['elevation'].centroid_values
100C          = domain.centroids
101
102HeightV    = domain.quantities['height'].vertex_values
103StageV     = domain.quantities['stage'].vertex_values
104BedV       = domain.quantities['elevation'].vertex_values
105VelocityV  = domain.quantities['velocity'].vertex_values
106X          = domain.vertices
107
108
109import pylab
110
111pylab.hold(False)
112
113plot1 = pylab.subplot(311)
114
115pylab.plot(X.flat,BedV.flat,X.flat,StageV.flat)
116
117plot1.set_ylim([-1,40])
118
119pylab.xlabel('Position')
120pylab.ylabel('Stage')
121pylab.legend(('Analytical Solution', 'Numerical Solution'),
122           'upper right', shadow=True)
123
124
125plot2 = pylab.subplot(312)
126
127pylab.plot(X.flat,HeightV.flat)
128
129plot2.set_ylim([-1,10])
130
131pylab.xlabel('Position')
132pylab.ylabel('Height')
133
134plot3 = pylab.subplot(313)
135
136pylab.plot(X.flat,VelocityV.flat)
137plot3.set_ylim([-15,15])
138
139pylab.xlabel('Position')
140pylab.ylabel('Velocity')
141
142pylab.show()
143
144
145
146
147
148
Note: See TracBrowser for help on using the repository browser.