source: inundation/ga/storm_surge/examples/beach.py @ 718

Last change on this file since 718 was 694, checked in by ole, 20 years ago
File size: 5.4 KB
Line 
1"""Example of the inundationmodel.
2
3A wave of water is washed up ontp a hypothetical beach.
4
5To run:
6
7python beach.py
8"""
9
10######################
11# Module imports
12#
13
14import sys
15from os import sep, path
16sys.path.append('..'+sep+'pyvolution')
17
18from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\
19     Transmissive_boundary, Time_boundary, Wind_stress
20
21from pmesh2domain import pmesh_to_domain_instance
22from config import data_dir
23from util import read_polygon, Polygon_function
24from math import pi
25from Numeric import choose, greater, ones, sin, exp
26import time
27
28######################
29# Domain
30name = 'beach'
31print 'Creating domain from %s.tsh' %name
32domain = pmesh_to_domain_instance(name + '.tsh', Domain)
33
34#HACK to remove internal boundary (until we get a solution)
35#Is this still necessary?
36for b in domain.boundary.keys():
37    if domain.boundary[b] == '':
38        del domain.boundary[b]
39domain = Domain(domain.coordinates, domain.triangles, domain.boundary)
40
41domain.store = True
42domain.set_name(name + '6')
43domain.default_order = 2
44print "Output being written to " + data_dir + sep + \
45      domain.filename + "_size%d." %len(domain) + domain.format
46
47
48def bathymetry(x, y):
49    cut = 75
50   
51    res = choose( greater(x, cut), ( -(x - 55)/5, -4*ones(x.shape) ))
52    res == (100-y)/50 + 1
53    #res += (100-y)/130  #Lift up southern bathymetry
54    #res -= y/1500  #Pull down northern bathymetry
55   
56    return res
57   
58
59def topography(x, y):
60
61    import RandomArray
62    #z = 4*sin(pi*x/50) + (100-y)/50 + 1 #Ridge
63   
64    z = -4.0*x/25 + 8  + (100-y)/50 #Beach
65   
66    #z += sin(pi*x/5)/4
67    #z += RandomArray.normal(0, 1, x.shape)/4
68   
69    z += 6*exp( -((x-30)/10)**2 ) * exp( -((y-50)/8)**2 )     #Mound
70    z += 4*exp( -((x-30)/4)**2 ) * exp( -((y-26)/10)**2 )     #extra ridge   
71    z += 4*exp( -((x-30)/5)**2 ) * exp( -((y-10)/8)**2 )     #extra ridge
72    z -= 4*exp( -((x-15)/6)**2 ) * exp( -((y-20)/12)**2 )     #depression
73
74    z += 1.2*exp( -((x-88)/7)**2 ) + exp( -((y-20)/25)**2 )     #Seafloor
75    return z
76
77def riverbed(x, y):
78    return (y-100)/70 - 4.0*x/25 + 8
79   
80
81shoreline = [[40,0], [100,0], [100,100], [65,100], 
82             [55,90], [55,70], [56,50], [50,25], [40,0]]       
83
84land = [[65,100], [55,90], [55,70], [56,50], [50,25], [40,0],
85        [0,0], [0,100]]
86
87
88water = [[55,0], [100,0], [100,100], [55,100]]
89all = [[0,0], [0,100], [100,100], [100,0]]
90
91                       
92             
93building1 = [[45,80], [49,78], [52,83], [46,83]]             
94building2 = [[35,75], [40,75], [40,80], [35,80]]             
95building3 = [[42,63], [46,61], [48,65], [44,67]]             
96building4 = [[28,56], [28,51], [33,51], [33,56]]             
97building5 = [[10,70], [10,65], [15,65], [15,70]]             
98building6 = [[10,50], [10,45], [15,45], [15,50]]             
99
100river = [[20,100], [18,90], [20,80], [20,60], [15,40], [11,20], [2,0], [10,0],
101         [14,10], [20,30], [24,45], [27,80], [27,85], [35,90], [39,100]]
102             
103print 'Set elevation'   
104t0 = time.time()
105domain.set_quantity('elevation',
106    Polygon_function( [(all, topography),
107                      #(shoreline, bathymetry), (land, topography),
108                      (building1, 7), (building2, 8), 
109                      (building3, 7), (building4, 13),
110                      (building5, 10), (building6, 11)]))
111                      #(river, riverbed)]))
112                     
113print 'That took %.2f seconds' %(time.time()-t0)
114                     
115print 'Set level'                     
116domain.set_quantity('level', 
117                    Polygon_function( [(water, -1.5), 
118                    (land, -10)] )) 
119                   
120print 'Set friction'                                       
121domain.set_quantity('friction', 0.08)
122
123print domain.get_extent()
124
125
126
127#Add lateral wind gusts bearing 135 degrees
128def gust(t,x,y): 
129    from math import sin, pi
130    from Numeric import zeros, ones, Float
131
132    N = len(x)
133
134    tt = sin(2*pi*t/50)
135
136    if tt > 0.98:
137        return 26000*tt*ones(N, Float)
138    else:
139        return zeros(N, Float)
140   
141domain.forcing_terms.append(Wind_stress(gust, 135))
142
143
144#Add lateral wind gusts bearing 90 degrees
145def gust2(t,x,y): 
146    from math import sin, pi
147    from Numeric import zeros, ones, Float
148
149    N = len(x)
150
151    tt = sin(2*pi*t/100)
152
153    if tt > 0.95:
154        return 22000*tt*ones(N, Float)
155    else:
156        return zeros(N, Float)
157   
158domain.forcing_terms.append(Wind_stress(gust2, 90))
159
160#Add lateral wind gusts bearing 255 degrees
161def gust3(t,x,y): 
162    from math import sin, pi
163    from Numeric import zeros, ones, Float
164
165    N = len(x)
166
167    tt = sin(2*pi*(t-30)/55)
168
169    if tt > 0.96:
170        return 24000*tt*ones(N, Float)
171    else:
172        return zeros(N, Float)
173   
174domain.forcing_terms.append(Wind_stress(gust3, 255))
175
176
177######################
178# Boundary conditions
179
180print 'Boundaries'
181Br = Reflective_boundary(domain)
182Bo = Transmissive_boundary(domain)
183
184#Constant outflow
185Bd = Dirichlet_boundary([-10, 0.0, 0.0])
186Bt = Time_boundary(domain, lambda t: [ 3.0*(1+sin(2*pi*t/100)), 0.0, 0.0])
187
188print 'Available boundary tags are', domain.get_boundary_tags()
189
190#Set boundary conditions
191tags = {}
192tags['ocean'] = Bt
193tags['wall'] = Br
194tags['wall1'] = Br
195tags['outflow'] = Bd
196tags['exterior'] = Br
197tags['external'] = Br
198#tags['land'] = Bo 
199tags['land'] = Bd 
200tags['westbank'] = None    #Riverbank
201tags['eastbank'] = None    #Riverbank
202tags['eastbankN'] = None    #Riverbank
203domain.set_boundary(tags)
204
205
206domain.check_integrity()
207
208######################
209#Evolution
210t0 = time.time()
211for t in domain.evolve(yieldstep = 0.2, finaltime = 300):
212    domain.write_time()
213print 'Simulation took %.2f seconds' %(time.time()-t0)
214   
Note: See TracBrowser for help on using the repository browser.