source: misc/inundation-numpy-branch/examples/beach.py @ 5847

Last change on this file since 5847 was 3514, checked in by duncan, 19 years ago

Hi all,
I'm doing a change in the anuga structure, moving the code to

\anuga_core\source\anuga

After you have done an svn update, the PYTHONPATH has to be changed to;
PYTHONPATH = anuga_core/source/

This is part of changes required to make installation of anuga quicker and reducing the size of our sandpits.

If any imports are broken, try fixing them. With adding anuga. to them for example. If this seems to have really broken things, email/phone me.

Cheers
Duncan

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