# source:anuga_work/development/anuga_1d/parabolic_cannal_sudi.py@7818

Last change on this file since 7818 was 5827, checked in by sudi, 14 years ago

File size: 4.0 KB
Line
1import os
2from math import sqrt, pi, sin, cos
3from shallow_water_domain_suggestion1 import *
4from Numeric import allclose, array, zeros, ones, Float, take, sqrt
5from config import g, epsilon
6
7def analytic_cannal(C,t):
8    N = len(C)
9    u = zeros(N,Float)    ## water velocity
10    h = zeros(N,Float)    ## water depth
11    x = C
12    g = 9.81
13    ## Define Basin Bathymetry
14    z_b = zeros(N,Float) ## elevation of basin
15    z = zeros(N,Float)   ## elevation of water surface
16    z_infty = 10.0       ## max equilibrium water depth at lowest point.
17    L_x = 2500.0         ## width of channel
18    A0 = 0.5*L_x                  ## determines amplitudes of oscillations
19    omega = sqrt(2*g*z_infty)/L_x ## angular frequency of osccilation
20    for i in range(N):
21        z_b[i] = z_infty*(x[i]**2/L_x**2)
22        u[i] = -A0*omega*sin(omega*t)
23        z[i] = z_infty+2*A0*z_infty/L_x*cos(omega*t)*(x[i]/L_x-0.5*A0/(L_x)*cos(omega*t))
24    h = z-z_b
25    T = 2.0*pi/omega
26    return u,h,z,z_b, T
27
28
29L_x = 2500.0     # Length of channel (m)
30N = 400         # Number of compuational cells
31cell_len = 4*L_x/N   # Origin = 0.0
32
33points = zeros(N+1,Float)
34for i in range(N+1):
35        points[i] = -2*L_x +i*cell_len
36
37domain = Domain(points)
38domain.order = 2
39domain.set_timestepping_method('rk2')
40domain.cfl = 1.0
41domain.beta = 1.0
42domain.limiter = "vanleer"
43
44def stage(x):
45    z_infty = 10.0       ## max equilibrium water depth at lowest point.
46    L_x = 2500.0         ## width of channel
47    A0 = 0.5*L_x                  ## determines amplitudes of oscillations
48    omega = sqrt(2*g*z_infty)/L_x ## angular frequency of osccilation
49    t=0.0
50    y = zeros(len(x),Float)
51    for i in range(len(x)):
52        y[i] = z_infty+2*A0*z_infty/L_x*cos(omega*t)*(x[i]/L_x-0.5*A0/(L_x)*cos(omega*t))
53        #y[i] = 12.0
54    return y
55
56def elevation(x):
57    N = len(x)
58    z_infty = 10.0
59    z = zeros(N,Float)
60    L_x = 2500.0
61    A0 = 0.5*L_x
62    omega = sqrt(2*g*z_infty)/L_x
63    for i in range(N):
64        z[i] = z_infty*(x[i]**2/L_x**2)
65    return z
66
67def height(x):
68    z_infty = 10.0       ## max equilibrium water depth at lowest point.
69    L_x = 2500.0         ## width of channel
70    A0 = 0.5*L_x                  ## determines amplitudes of oscillations
71    omega = sqrt(2*g*z_infty)/L_x ## angular frequency of osccilation
72    t=0.0
73    y = zeros(len(x),Float)
74    for i in range(len(x)):
75        y[i] = max(z_infty+2*A0*z_infty/L_x*cos(omega*t)*(x[i]/L_x-0.5*A0/(L_x)*cos(omega*t))-z_infty*(x[i]**2/L_x**2),0.0)
76    return y
77
78
79domain.set_quantity('stage', stage)
80domain.set_quantity('elevation',elevation)
81domain.set_boundary({'exterior': Reflective_boundary(domain)})
82
83X = domain.vertices
84u,h,z,z_b,T = analytic_cannal(X.flat,domain.time)
85print 'T = ',T
86
87yieldstep = finaltime = T/2.0
88StageQ = domain.quantities['stage'].vertex_values
89XmomQ = domain.quantities['xmomentum'].vertex_values
90
91import time
92t0 = time.time()
93for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
94    domain.write_time()
95    print "integral", domain.quantities['stage'].get_integral()
96    if t>0.0:
97
98        print 'X=',X
99        print 'domain.time=',domain.time
100
101        StageQ = domain.quantities['stage'].vertex_values
102        XmomQ = domain.quantities['xmomentum'].vertex_values
103
104        u,h,z,z_b,T = analytic_cannal(X.flat,domain.time)
105        w = z
106        for k in range(len(h)):
107            if h[k] < 0.0:
108                h[k] = 0.0
109                w[k] = z_b[k]
110
111        from pylab import plot,title,xlabel,ylabel,legend,savefig,show,hold,subplot
112        hold(False)
113        plot1 = subplot(211)
114        plot(X,w,  X,StageQ,  X,z_b)
115        #plot1.set_ylim([4,11])
116        xlabel('Position')
117        ylabel('Stage')
118        legend(('Analytic Solution', 'Numerical Solution', 'Bed'),