Line | |
---|
1 | |
---|
2 | |
---|
3 | class AnalyticDam: |
---|
4 | |
---|
5 | def __init__(self, h0 = 5.0, h1 = 10.0, L = 2000.0): |
---|
6 | |
---|
7 | self.h0 = h0 # depth upstream (m) |
---|
8 | self.h1 = h1 # depth downstream (m) |
---|
9 | self.L = L # length of domain |
---|
10 | |
---|
11 | def __call__(self, C,t): |
---|
12 | |
---|
13 | from Numeric import zeros,Float |
---|
14 | from math import sqrt, pi |
---|
15 | |
---|
16 | #t = 0.0 # time (s) |
---|
17 | h0 = self.h0 |
---|
18 | h1 = self.h1 |
---|
19 | L = self.L |
---|
20 | n = len(C) # number of cells |
---|
21 | |
---|
22 | g = 9.81 # gravity (m/s^2) |
---|
23 | |
---|
24 | c0 = sqrt(g*h0) #left celerity |
---|
25 | c1 = sqrt(g*h1) #right celerity |
---|
26 | |
---|
27 | |
---|
28 | u = zeros(n,Float) |
---|
29 | h = zeros(n,Float) |
---|
30 | uh = zeros(n,Float) |
---|
31 | x = C-L/2 |
---|
32 | #x = zeros(n,Float) |
---|
33 | #for i in range(n): |
---|
34 | # x[i] = C[i]-1000.0 |
---|
35 | |
---|
36 | # Upstream and downstream boundary conditions are set to the intial water |
---|
37 | # depth for all time. |
---|
38 | |
---|
39 | # Calculate Shock Speed |
---|
40 | #h2 = 7.2692044 |
---|
41 | |
---|
42 | #S2 = 2*h2/(h2-h0)*(sqrt(g*h1)-sqrt(g*h2)) |
---|
43 | #u2 = S2 - g*h0/(4*S2)*(1+sqrt(1+8*S2*S2/(g*h0))) |
---|
44 | |
---|
45 | zmin=-100.0 |
---|
46 | zmax=101.0 |
---|
47 | for i in range(100): |
---|
48 | z=(zmin+zmax)/2.0 |
---|
49 | u2=z-c0*c0/4.0/z*(1.0+sqrt(1.0+8.0*z*z/c0/c0)) |
---|
50 | c2=c0*sqrt(0.5*(sqrt(1.0+8.0*z*z/c0/c0)-1.0)) |
---|
51 | func=2.0*c1/c0-u2/c0-2.0*c2/c0 |
---|
52 | if (func > 0.0): |
---|
53 | zmin=z |
---|
54 | else: |
---|
55 | zmax=z |
---|
56 | |
---|
57 | if( abs(z) > 99.0): |
---|
58 | print 'no convergence' |
---|
59 | |
---|
60 | h2=h0/(1.0-u2/z) |
---|
61 | |
---|
62 | print z,h2,u2 |
---|
63 | x3=(u2-c2)*t |
---|
64 | x2=z*t |
---|
65 | x1=-c1*t |
---|
66 | |
---|
67 | #t=50 |
---|
68 | #x = (-L/2:L/2) |
---|
69 | for i in range(n): |
---|
70 | # Calculate Analytical Solution at time t > 0 |
---|
71 | u3 = 2.0/3.0*(sqrt(g*h1)+x[i]/t) |
---|
72 | h3 = 4.0/(9.0*g)*(sqrt(g*h1)-x[i]/(2.0*t))*(sqrt(g*h1)-x[i]/(2.0*t)) |
---|
73 | |
---|
74 | if ( x[i] <= x1 ): |
---|
75 | u[i] = 0.0 |
---|
76 | h[i] = h1 |
---|
77 | uh[i] = u[i]*h[i] |
---|
78 | elif ( x[i] <= x3 ): |
---|
79 | u[i] = u3 |
---|
80 | h[i] = h3 |
---|
81 | uh[i] = u[i]*h[i] |
---|
82 | elif ( x[i] < x2 ): |
---|
83 | u[i] = u2 |
---|
84 | h[i] = h2 |
---|
85 | uh[i] = u[i]*h[i] |
---|
86 | else: |
---|
87 | u[i] = 0.0 |
---|
88 | h[i] = h0 |
---|
89 | uh[i] = u[i]*h[i] |
---|
90 | |
---|
91 | return h , uh |
---|
Note: See
TracBrowser
for help on using the repository browser.