source: inundation/ga/storm_surge/analytical solutions/Analytical solution_wave_runup.py @ 1360

Last change on this file since 1360 was 1353, checked in by chris, 20 years ago
File size: 4.0 KB
Line 
1"""Example of shallow water wave equation analytical solution of the
2one-dimensional Thacker and Greenspan wave run-up treated as a two-dimensional solution.
3
4   Copyright 2004
5   Christopher Zoppou, Stephen Roberts, Ole Nielsen, Duncan Gray
6   Geoscience Australia
7   
8Specific methods pertaining to the 2D shallow water equation
9are imported from shallow_water
10for use with the generic finite volume framework
11
12Conserved quantities are h, uh and vh stored as elements 0, 1 and 2 in the
13numerical vector named conserved_quantities.
14"""
15
16######################
17# Module imports
18import sys
19from os import sep
20sys.path.append('..'+sep+'pyvolution')
21
22from shallow_water import Domain, Reflective_boundary, Time_boundary
23from math import sqrt, cos, sin, pi
24from mesh_factory import strang_mesh
25
26#Convenience functions
27def imag(a):
28    return a.imag
29
30def real(a):
31    return a.real
32
33
34######################
35# Domain
36# Strang_domain will search through the file and test to see if there are
37# two or three entries. Two entries are for points and three for triangles.
38
39points, elements = strang_mesh('run-up.pt')
40domain = Domain(points, elements) 
41
42domain.default_order = 2
43domain.smooth = True
44
45#Set a default tagging
46epsilon = 1.0e-12
47
48for id, face in domain.boundary:
49    domain.boundary[(id,face)] = 'external'
50   
51domain.boundary[(0,0)] = 'left'
52
53
54# Provide file name for storing output
55domain.store = True
56domain.format = 'sww'
57domain.filename = 'run-up_second_order_again'
58
59print "Number of triangles = ", len(domain)
60
61#Reduction operation for get_vertex_values             
62from util import mean
63domain.reduction = mean
64#domain.reduction = min  #Looks better near steep slopes
65
66#Define the boundary condition
67def stage_setup(x,t_star1):
68    vh = 0
69    alpha = 0.1
70    eta = 0.1
71    a = 1.5*sqrt(1.+0.9*eta)
72    l_0 = 200.
73    ii = complex(0,1)
74    g = 9.81
75    v_0 = sqrt(g*l_0*alpha)
76    v1 = 0.
77
78    sigma_max = 100.
79    sigma_min = -100.
80    for j in range (1,50):
81        sigma0 = (sigma_max+sigma_min)/2.
82        lambda_prime = 2./a*(t_star1/sqrt(l_0/alpha/g)+v1)
83        sigma_prime = sigma0/a
84        const = (1.-ii*lambda_prime)**2+sigma_prime**2
85         
86        v1 = 8.*eta/a*imag(1./const**(3./2.) \
87            -3./4.*(1.-ii*lambda_prime)/const**(5./2.))
88           
89        x1 = -v1**2/2.-a**2*sigma_prime**2/16.+eta \
90            *real(1.-2.*(5./4.-ii*lambda_prime) \
91            /const**(3./2.)+3./2.*(1.-ii*lambda_prime)**2 \
92            /const**(5./2.))
93
94        neta1 = x1 + a*a*sigma_prime**2/16.
95
96        v_star1 = v1*v_0
97        x_star1 = x1*l_0
98        neta_star1 = neta1*alpha*l_0
99        stage = neta_star1
100        z = stage - x_star1*alpha
101        uh = z*v_star1
102
103        if x_star1-x > 0:
104            sigma_max = sigma0
105        else:
106            sigma_min = sigma0
107
108        if abs(abs(sigma0)-100.) < 10:
109
110#     solution does not converge because bed is dry
111            stage = 0.
112            uh = 0.
113            z = 0.
114
115    return [stage, uh, vh]
116
117def boundary_stage(t):
118    x = -200
119    return stage_setup(x,t)
120
121
122######################
123#Initial condition
124print 'Initial condition'
125t_star1 = 0.0
126slope = -0.1
127
128#Set bed-elevation and friction(None)
129def x_slope(x,y):
130    n = x.shape[0]
131    z = 0*x
132    for i in range(n):
133        z[i] = -slope*x[i]
134    return z
135
136domain.set_quantity('elevation', x_slope)
137
138#Set the water depth
139def stage(x,y):
140    z = x_slope(x,y)
141    n = x.shape[0]
142    w = 0*x
143    for i in range(n):
144        w[i], uh, vh = stage_setup(x[i],t_star1)
145        h = w[i] - z[i]
146        if h < 0:
147            h = 0
148            w[i] = z[i]
149    return w   
150
151domain.set_quantity('stage', stage)
152
153
154#####################
155#Set up boundary conditions
156Br = Reflective_boundary(domain)
157Bw = Time_boundary(domain, boundary_stage)
158domain.set_boundary({'left': Bw, 'external': Br})
159
160
161######################
162#Evolution
163import time
164t0 = time.time()
165for t in domain.evolve(yieldstep = 1., finaltime = 100):
166    domain.write_time()
167    print boundary_stage(domain.time)
168   
169print 'That took %.2f seconds' %(time.time()-t0)
170
171   
Note: See TracBrowser for help on using the repository browser.