1 | """Example of shallow water wave equation analytical solution of the |
---|
2 | one-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 | |
---|
10 | Specific methods pertaining to the 2D shallow water equation |
---|
11 | are imported from shallow_water |
---|
12 | for use with the generic finite volume framework |
---|
13 | |
---|
14 | Conserved quantities are h, uh and vh stored as elements 0, 1 and 2 in the |
---|
15 | numerical vector named conserved_quantities. |
---|
16 | """ |
---|
17 | |
---|
18 | #------------------- |
---|
19 | # Module imports |
---|
20 | import sys |
---|
21 | import anuga |
---|
22 | from math import sqrt, cos, sin, pi |
---|
23 | from numpy import asarray |
---|
24 | from time import localtime, strftime, gmtime |
---|
25 | |
---|
26 | #------------------------------------------------------------------------------- |
---|
27 | # Copy scripts to time stamped output directory and capture screen |
---|
28 | # output to file |
---|
29 | #------------------------------------------------------------------------------- |
---|
30 | time = strftime('%Y%m%d_%H%M%S',localtime()) |
---|
31 | |
---|
32 | output_dir = 'periodic_carrier_greenspan_'+time |
---|
33 | output_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 | #------------------------------------------------------------------------------ |
---|
42 | dx = 100. |
---|
43 | dy = dx |
---|
44 | L = 40000. |
---|
45 | W = dx |
---|
46 | |
---|
47 | # structured mesh |
---|
48 | points, vertices, boundary = anuga.rectangular_cross(int(L/dx), int(W/dy), L, W, (0.0, -W/2)) |
---|
49 | domain = anuga.Domain(points, vertices, boundary) |
---|
50 | |
---|
51 | domain.set_name(output_file) |
---|
52 | domain.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 |
---|
57 | from scipy.special import jn |
---|
58 | def j0(x): |
---|
59 | return jn(0.0, x) |
---|
60 | |
---|
61 | def j1(x): |
---|
62 | return jn(1.0, x) |
---|
63 | #DIMENSIONAL PARAMETERS |
---|
64 | L_0 = 5e3#4 # Length of channel from the origin to shoreline when still |
---|
65 | h_0 = 5e2 # Height at origin when the water is still |
---|
66 | Tp = 3600.0 # Period of oscillation |
---|
67 | a = 250.0 # Amplitude at origin |
---|
68 | g = 9.81 # Gravity |
---|
69 | #DIMENSIONLESS PARAMETERS |
---|
70 | eps = a/h_0 |
---|
71 | T = Tp*sqrt(g*h_0)/L_0 |
---|
72 | A = eps/j0(4.0*pi/T) |
---|
73 | |
---|
74 | #------------------------------------------------------------------------------ |
---|
75 | # Setup Algorithm |
---|
76 | #------------------------------------------------------------------------------ |
---|
77 | domain.set_default_order(2) |
---|
78 | domain.set_timestepping_method(2) |
---|
79 | domain.set_beta(0.7) |
---|
80 | domain.set_CFL(0.6) |
---|
81 | |
---|
82 | |
---|
83 | #----------------------- |
---|
84 | #Define the boundary condition |
---|
85 | #----------------------- |
---|
86 | def 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 | |
---|
98 | def boundary_stage(t): |
---|
99 | return prescribe(0.0,t) |
---|
100 | |
---|
101 | |
---|
102 | #------------------------------------------------------------------------------- |
---|
103 | #Initial condition |
---|
104 | #------------------------------------------------------------------------------- |
---|
105 | #Set bed-elevation and friction(None) |
---|
106 | def 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 |
---|
112 | domain.set_quantity('elevation', x_slope) |
---|
113 | |
---|
114 | #Set the water depth |
---|
115 | def 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 |
---|
126 | domain.set_quantity('stage', stage) |
---|
127 | |
---|
128 | |
---|
129 | #----------------------------------------------------------------------------- |
---|
130 | # Setup boundary conditions |
---|
131 | #------------------------------------------------------------------------------ |
---|
132 | Br = anuga.Reflective_boundary(domain) |
---|
133 | Bt = anuga.Time_boundary(domain, boundary_stage) |
---|
134 | |
---|
135 | # Associate boundary tags with boundary objects |
---|
136 | domain.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 | #------------------------------------------------------------------------------ |
---|
155 | import time |
---|
156 | t0 = time.time() |
---|
157 | for 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() |
---|
163 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
164 | |
---|