source: trunk/anuga_validation/validation_tests/transient_carrier_greenspan.py @ 8427

Last change on this file since 8427 was 8427, checked in by davies, 13 years ago

Adding the trapezoidal channel validation test, and editing the ANUGA manual

File size: 5.6 KB
Line 
1"""Example of shallow water wave equation analytical solution of the
2one-dimensional Carrier 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
8   Modified by Sudi Mungkasi, ANU, 2011
9   
10Specific methods pertaining to the 2D shallow water equation
11are imported from shallow_water
12for use with the generic finite volume framework
13
14Conserved quantities are h, uh and vh stored as elements 0, 1 and 2 in the
15numerical vector named conserved_quantities.
16"""
17
18#-------------------
19# Module imports
20import sys
21import anuga
22from math import sqrt, cos, sin, pi
23from numpy import asarray
24from time import localtime, strftime, gmtime
25
26#-------------------------------------------------------------------------------
27# Copy scripts to time stamped output directory and capture screen
28# output to file
29#-------------------------------------------------------------------------------
30time = strftime('%Y%m%d_%H%M%S',localtime())
31
32output_dir = 'transient_carrier_greenspan_'+time
33output_file = 'transient_carrier_greenspan'
34
35#anuga.copy_code_files(output_dir,__file__)
36#start_screen_catcher(output_dir+'_')
37
38
39#-------------------
40#Convenience functions
41#-------------------
42def imag(a):
43    return a.imag
44
45def real(a):
46    return a.real
47
48
49#------------------------------------------------------------------------------
50# Setup domain
51#------------------------------------------------------------------------------
52dx = 10.
53dy = dx
54L = 100.
55W = 10*dx
56
57# structured mesh
58points, vertices, boundary = anuga.rectangular_cross(int(L/dx), int(W/dy), L, W, (0.0, -W/2))
59
60domain = anuga.Domain(points, vertices, boundary) 
61
62domain.set_name(output_file)               
63domain.set_datadir(output_dir) 
64
65#------------------------------------------------------------------------------
66# Setup Algorithm
67#------------------------------------------------------------------------------
68domain.set_default_order(2)
69domain.set_timestepping_method(2)
70domain.set_beta(0.7)
71domain.set_CFL(0.6)
72
73
74#-----------------------
75#Define the boundary condition
76#-----------------------
77def stage_setup(x,t):
78    vh = 0
79    alpha = 0.1
80    eta = 0.1
81    a = 1.5*sqrt(1.+0.9*eta)
82    l_0 = 200.
83    ii = complex(0,1)
84    g = 9.81
85    v_0 = sqrt(g*l_0*alpha)
86    v1 = 0.
87
88    sigma_max = 100.
89    sigma_min = -100.
90    for j in range (1,50):
91        sigma0 = (sigma_max+sigma_min)/2.
92        lambda_prime = 2./a*(t/sqrt(l_0/alpha/g)+v1)
93        sigma_prime = sigma0/a
94        const = (1.-ii*lambda_prime)**2+sigma_prime**2
95
96        v1 = 8.*eta/a*imag(1./const**(3./2.) \
97            -3./4.*(1.-ii*lambda_prime)/const**(5./2.))
98
99        x1 = -v1**2/2.-a**2*sigma_prime**2/16.+eta \
100            *real(1.-2.*(5./4.-ii*lambda_prime) \
101            /const**(3./2.)+3./2.*(1.-ii*lambda_prime)**2 \
102            /const**(5./2.))
103
104        neta1 = x1 + a*a*sigma_prime**2/16.
105
106        v_star1 = v1*v_0
107        x_star1 = x1*l_0
108        neta_star1 = neta1*alpha*l_0
109        stage = neta_star1
110        z = stage - x_star1*alpha
111        uh = z*v_star1
112
113        if x_star1-x > 0:
114            sigma_max = sigma0
115        else:
116            sigma_min = sigma0
117
118        if abs(abs(sigma0)-100.) < 10:
119            #solution does not converge because bed is dry
120            stage = 0.
121            uh = 0.
122            z = 0.
123
124    return [stage, uh, vh]
125
126def boundary_stage(t):
127    x = -200
128    return stage_setup(x,t)
129
130
131#-------------------------------------------------------------------------------
132#Initial condition
133#-------------------------------------------------------------------------------
134t_star1 = 0.0
135slope = -0.1
136
137#Set bed-elevation and friction(None)
138def x_slope(x,y):
139    n = x.shape[0]
140    z = 0*x
141    for i in range(n):
142        z[i] = -slope*x[i]
143    return z
144domain.set_quantity('elevation', x_slope)
145
146#Set the water depth
147def stage(x,y):
148    z = x_slope(x,y)
149    n = x.shape[0]
150    w = 0*x
151    for i in range(n):
152        w[i], uh, vh = stage_setup(x[i],t_star1)
153        h = w[i] - z[i]
154        if h < 0:
155            h = 0
156            w[i] = z[i]
157    return w
158domain.set_quantity('stage', stage)
159
160
161#-----------------------------------------------------------------------------
162# Setup boundary conditions
163#------------------------------------------------------------------------------
164Br = anuga.Reflective_boundary(domain)
165Bt = anuga.Time_boundary(domain, boundary_stage)
166
167# Associate boundary tags with boundary objects
168domain.set_boundary({'left': Bt, 'right': Br, 'top': Br, 'bottom': Br})
169
170##visualize = True
171##if visualize:
172##    from anuga.visualiser import RealtimeVisualiser
173##    vis = RealtimeVisualiser(domain)
174##    vis.render_quantity_height("elevation", zScale=3.0, offset = 0.01, dynamic=False)
175##    vis.render_quantity_height("stage", zScale = 3.0, dynamic=True, opacity = 0.6, wireframe=False)
176##    #vis.colour_height_quantity('stage', (lambda q:q['stage'], 1.0, 2.0))
177##    vis.colour_height_quantity('stage', (0.4, 0.6, 0.4))
178##    vis.start()
179##    time.sleep(2.0)
180
181#domain.visualise = True
182
183
184#------------------------------------------------------------------------------
185# Evolve system through time
186#------------------------------------------------------------------------------
187import time
188t0 = time.time()
189for t in domain.evolve(yieldstep = 1., finaltime = 1000):
190    domain.write_time()
191    #print boundary_stage(domain.time)
192    #if visualize: vis.update()
193   
194#if visualize: vis.evolveFinished()   
195print 'That took %.2f seconds' %(time.time()-t0)
196
Note: See TracBrowser for help on using the repository browser.