source: trunk/anuga_validation/validation_tests/periodic_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.3 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, Australian National University, 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 = 'periodic_carrier_greenspan_'+time
33output_file = 'periodic_carrier_greenspan'
34
35#anuga.copy_code_files(output_dir,__file__)
36#start_screen_catcher(output_dir+'_')
37
38
39#------------------------------------------------------------------------------
40# Setup domain
41#------------------------------------------------------------------------------
42dx = 100.
43dy = dx
44L = 40000.
45W = dx
46
47# structured mesh
48points, vertices, boundary = anuga.rectangular_cross(int(L/dx), int(W/dy), L, W, (0.0, -W/2))
49domain = anuga.Domain(points, vertices, boundary) 
50
51domain.set_name(output_file)               
52domain.set_datadir(output_dir) 
53
54# The following parameters are adapted from Mungkasi & Roberts,
55# "Approximations of the Carrier-Greenspan periodic solution"
56# International Journal for Numerical Methods in Fluids, 2011
57from scipy.special import jn
58def j0(x):
59    return jn(0.0, x)
60
61def j1(x):
62    return jn(1.0, x)
63#DIMENSIONAL PARAMETERS
64L_0 = 5e3#4               # Length of channel from the origin to shoreline when still
65h_0 = 5e2               # Height at origin when the water is still
66Tp = 3600.0             # Period of oscillation
67a = 250.0                 # Amplitude at origin
68g = 9.81                # Gravity
69#DIMENSIONLESS PARAMETERS
70eps = a/h_0
71T = Tp*sqrt(g*h_0)/L_0
72A = eps/j0(4.0*pi/T)
73
74#------------------------------------------------------------------------------
75# Setup Algorithm
76#------------------------------------------------------------------------------
77domain.set_default_order(2)
78domain.set_timestepping_method(2)
79domain.set_beta(0.7)
80domain.set_CFL(0.6)
81
82
83#-----------------------
84#Define the boundary condition
85#-----------------------
86def prescribe(x,t):
87    t = t*sqrt(g*h_0)/L_0
88    from numpy import zeros
89    def fun(q): #Here q=(w, u)
90        f = zeros(2)
91        f[0] = q[0] + 0.5*q[1]**2.0 - A*j0(4.0*pi/T*(1.0+q[0]-x)**0.5)*cos(2.0*pi/T*(t+q[1]))
92        f[1] = q[1] + A*j1(4.0*pi/T*(1.0+q[0]-x)**0.5)*sin(2.0*pi/T*(t+q[1]))/(1+q[0]-x)**0.5
93        return f
94    from scipy.optimize import fsolve
95    w_0, u_0 = fsolve(fun, [0 ,0])   
96    return [w_0*h_0,  u_0*sqrt(g*h_0)*h_0,  0.0] #[stage, xmom, ymom]
97
98def boundary_stage(t):
99    return prescribe(0.0,t)
100
101
102#-------------------------------------------------------------------------------
103#Initial condition
104#-------------------------------------------------------------------------------
105#Set bed-elevation and friction(None)
106def x_slope(x,y):
107    n = x.shape[0]
108    z = 0*x
109    for i in range(n):
110        z[i] = (h_0/L_0)*x[i] - h_0
111    return z
112domain.set_quantity('elevation', x_slope)
113
114#Set the water depth
115def stage(x,y):
116    z = x_slope(x,y)
117    n = x.shape[0]
118    w = 0*x
119    for i in range(n):
120        w[i] = 0.0
121        h = w[i] - z[i]
122        if h < 0:
123            h = 0
124            w[i] = z[i]
125    return w
126domain.set_quantity('stage', stage)
127
128
129#-----------------------------------------------------------------------------
130# Setup boundary conditions
131#------------------------------------------------------------------------------
132Br = anuga.Reflective_boundary(domain)
133Bt = anuga.Time_boundary(domain, boundary_stage)
134
135# Associate boundary tags with boundary objects
136domain.set_boundary({'left': Bt, 'right': Br, 'top': Br, 'bottom': Br})
137
138##visualize = True
139##if visualize:
140##    from anuga.visualiser import RealtimeVisualiser
141##    vis = RealtimeVisualiser(domain)
142##    vis.render_quantity_height("elevation", zScale=3.0, offset = 0.01, dynamic=False)
143##    vis.render_quantity_height("stage", zScale = 3.0, dynamic=True, opacity = 0.6, wireframe=False)
144##    #vis.colour_height_quantity('stage', (lambda q:q['stage'], 1.0, 2.0))
145##    vis.colour_height_quantity('stage', (0.4, 0.6, 0.4))
146##    vis.start()
147##    time.sleep(2.0)
148
149#domain.visualise = True
150
151
152#------------------------------------------------------------------------------
153# Evolve system through time
154#------------------------------------------------------------------------------
155import time
156t0 = time.time()
157for t in domain.evolve(yieldstep = 10., finaltime = 5*Tp):
158    domain.write_time()
159    #print boundary_stage(domain.time)
160    #if visualize: vis.update()
161   
162#if visualize: vis.evolveFinished()   
163print 'That took %.2f seconds' %(time.time()-t0)
164
Note: See TracBrowser for help on using the repository browser.