1 | """Simple water flow example using ANUGA |
---|
2 | |
---|
3 | Water driven towards a continental slope and into a harbour |
---|
4 | environment. Set up as per: |
---|
5 | P.L.-F Liu |
---|
6 | Effects of the Continental Shelf on Harbor Resonance, in |
---|
7 | Tsunamis - Their Science and Engineering, |
---|
8 | edited by K. Iida and T. Iwasaki, 303-314. |
---|
9 | 1983, Terra Scientific Publishing Company, Tokyo. |
---|
10 | |
---|
11 | """ |
---|
12 | |
---|
13 | #------------------------------------------------------------------------------ |
---|
14 | # Import necessary modules |
---|
15 | #------------------------------------------------------------------------------ |
---|
16 | |
---|
17 | from pmesh.mesh_interface import create_mesh_from_regions |
---|
18 | from pyvolution.shallow_water import Domain |
---|
19 | from pyvolution.shallow_water import Reflective_boundary |
---|
20 | from pyvolution.shallow_water import Dirichlet_boundary |
---|
21 | from pyvolution.shallow_water import Time_boundary |
---|
22 | from pyvolution.shallow_water import Transmissive_boundary |
---|
23 | |
---|
24 | waveheight = 1.0 |
---|
25 | harbour_length = 2000.0 |
---|
26 | shelf_length = 10000.0 |
---|
27 | bottom_length = 10000.0 |
---|
28 | harbour_width = 250.0 |
---|
29 | shelf_depth = -100. |
---|
30 | harbour_depth = -10. |
---|
31 | if harbour_depth > shelf_depth: print 'WARNING: depths not consistent' |
---|
32 | #------------------------------------------------------------------------------ |
---|
33 | # Setup computational domain |
---|
34 | #------------------------------------------------------------------------------ |
---|
35 | |
---|
36 | east = 10000.+harbour_length+shelf_length+bottom_length |
---|
37 | west = 0. |
---|
38 | south = 0. |
---|
39 | north = 5000. |
---|
40 | polygon = [[east,north],[west,north],[west,south],[east,south]] |
---|
41 | meshname = 'harbour_test.msh' |
---|
42 | |
---|
43 | create_mesh_from_regions(polygon, |
---|
44 | boundary_tags={'top': [0], |
---|
45 | 'left': [1], |
---|
46 | 'bottom': [2], |
---|
47 | 'right': [3]}, |
---|
48 | maximum_triangle_area=50000, |
---|
49 | filename=meshname) |
---|
50 | #interior_regions=interior_regions) |
---|
51 | |
---|
52 | domain = Domain(meshname,use_cache=True,verbose = True) |
---|
53 | domain.set_name('harbour') # Output to harbour.sww |
---|
54 | domain.set_datadir('.') # Use current directory for output |
---|
55 | domain.set_quantities_to_be_stored(['stage',# Store all conserved quantities |
---|
56 | 'xmomentum', |
---|
57 | 'ymomentum']) |
---|
58 | |
---|
59 | |
---|
60 | #------------------------------------------------------------------------------ |
---|
61 | # Setup initial conditions |
---|
62 | #------------------------------------------------------------------------------ |
---|
63 | # if can't do this, then can set up x = arange(west,east,xstep) |
---|
64 | # and y = arange(south,north,ystep) and use Geospatial data to set elevation |
---|
65 | |
---|
66 | def topography(x,y): |
---|
67 | from Numeric import zeros, Float |
---|
68 | z = zeros(len(x),len(y),Float) |
---|
69 | ycentre = (south+north)/2. |
---|
70 | ycentreup = ycentre+harbour_width/2. |
---|
71 | ycentredown = ycentre-harbour_width/2. |
---|
72 | for i, xi in enumerate(x): |
---|
73 | for j, yi in enumerate(y): |
---|
74 | if xi >= centre: z[i,j] = shelf_depth |
---|
75 | if xi > west and xi <= centre-harbour_length: |
---|
76 | if yi < ycentredown: z[i,j] = 0.0 |
---|
77 | if yi > ycentreup: z[i,j] = 0.0 |
---|
78 | if yi > ycentredown and yi < ycentreup: z[i,j] = harbour_depth |
---|
79 | if xi > centre-harbour_length and xi < centre: z[i,j] = harbour_depth |
---|
80 | return z |
---|
81 | |
---|
82 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
83 | domain.set_quantity('friction', 0. ) # Constant friction |
---|
84 | domain.set_quantity('stage', 0.0) # Constant initial stage |
---|
85 | |
---|
86 | #------------------------------------------------------------------------------ |
---|
87 | # Setup boundary conditions |
---|
88 | #------------------------------------------------------------------------------ |
---|
89 | |
---|
90 | from math import sin, pi |
---|
91 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
92 | Bt = Transmissive_boundary(domain) # Continue all values on boundary |
---|
93 | Bd = Dirichlet_boundary([0.,0.,0.]) # Constant boundary values |
---|
94 | Bw = Time_boundary(domain=domain, # Time dependent boundary |
---|
95 | f=lambda t: [((10<t<20)*waveheight), 0.0, 0.0]) |
---|
96 | |
---|
97 | # Associate boundary tags with boundary objects |
---|
98 | domain.set_boundary({'left': Br, 'right': Bw, 'top': Br, 'bottom': Br}) |
---|
99 | |
---|
100 | #------------------------------------------------------------------------------ |
---|
101 | # Evolve system through time |
---|
102 | #------------------------------------------------------------------------------ |
---|
103 | |
---|
104 | stagestep = [] |
---|
105 | for t in domain.evolve(yieldstep = 10, finaltime = 100.0): |
---|
106 | domain.write_time() |
---|
107 | |
---|
108 | #----------------------------------------------------------------------------- |
---|
109 | # Interrogate solution |
---|
110 | #----------------------------------------------------------------------------- |
---|
111 | |
---|
112 | # Gauge line |
---|
113 | def gauge_line(west,east,north,south): |
---|
114 | from Numeric import arange |
---|
115 | gaugex = arange(east,west,-1000.) |
---|
116 | gauges = [] |
---|
117 | gaugey = [] |
---|
118 | for x in gaugex: |
---|
119 | y = (north+south)/2. |
---|
120 | gaugey.append(y) |
---|
121 | gauges.append([x,y]) |
---|
122 | return gauges, gaugex, gaugey |
---|
123 | |
---|
124 | gauges, gaugex, gaugey = gauge_line(west,east,north,south) |
---|
125 | |
---|
126 | from pyvolution.util import file_function |
---|
127 | |
---|
128 | f = file_function('harbour.sww', |
---|
129 | quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'], |
---|
130 | interpolation_points = gauges, |
---|
131 | verbose = True, |
---|
132 | use_cache = True) |
---|
133 | |
---|
134 | from pylab import plot, xlabel, ylabel, title, ion, close, savefig, figure |
---|
135 | ion() |
---|
136 | |
---|
137 | maxw = [] |
---|
138 | minw = [] |
---|
139 | maxd = [] |
---|
140 | count = 0 |
---|
141 | for k, g in enumerate(gauges): |
---|
142 | stage = [] |
---|
143 | elevation = [] |
---|
144 | depths = [] |
---|
145 | for i, t in enumerate(f.get_time()): |
---|
146 | w = f(t, point_id = k)[0] |
---|
147 | elev = f(t, point_id = k)[1] |
---|
148 | depth = w-elev |
---|
149 | stage.append(w) |
---|
150 | elevation.append(elev) |
---|
151 | depths.append(elev) |
---|
152 | maxw.append(max(stage)) |
---|
153 | minw.append(min(stage)) |
---|
154 | maxd.append(max(depths)) |
---|
155 | |
---|
156 | filename = 'point'+str(waveheight)+'.csv' |
---|
157 | fid = open(filename,'w') |
---|
158 | s = 'Waveheight,\n' |
---|
159 | fid.write(s) |
---|
160 | |
---|
161 | figure(1) |
---|
162 | plot(gaugex[:loc],maxw[:loc],'g-') |
---|
163 | xlabel('x') |
---|
164 | ylabel('stage') |
---|
165 | title('Maximum stage for gauge line') |
---|
166 | savefig('max_stage') |
---|
167 | |
---|
168 | close('all') |
---|