source: anuga_work/development/shallow_water_1d/analytic_dam.py @ 4960

Last change on this file since 4960 was 4958, checked in by steve, 16 years ago

Changed anuga_1d to shallow_water_1d

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