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

Last change on this file since 668 was 668, checked in by ole, 20 years ago
File size: 3.6 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
26
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)
35for b in domain.boundary.keys():
36    if domain.boundary[b] == '':
37        del domain.boundary[b]
38
39domain = Domain(domain.coordinates, domain.triangles, domain.boundary)
40
41domain.store = True
42domain.set_name(name)
43print "Output being written to " + data_dir + sep + \
44      domain.filename + "_size%d." %len(domain) + domain.format
45
46
47def bathymetry(x, y):
48    #cut = 55
49    #return -(x - cut)/5
50
51    cut = 75
52    return choose( greater(x, cut), ( -(x - 55)/5, -4*ones(x.shape) )) 
53    ####return choose( greater(x, cut), (-20*ones(x.shape), ones(x.shape)))   
54   
55
56def topography(x, y):
57    return 4*sin(pi*x/50) + 1
58
59def riverbed(x, y):
60    #return (y-100)/10 + 5*x/100
61    return (y-100)/50 + 4.4
62   
63
64shoreline = [[40,0], [100,0], [100,100], [65,100], 
65             [55,90], [55,70], [56,50], [50,25], [40,0]]       
66
67land = [[65,100], [55,90], [55,70], [56,50], [50,25], [40,0],
68        [0,0], [0,100]]       
69             
70building1 = [[45,80], [50,78], [52,83], [45,83]]             
71building2 = [[35,75], [40,75], [40,80], [35,80]]             
72building3 = [[42,63], [47,63], [50,68], [37,68]]             
73building4 = [[28,70], [28,60], [33,60], [33,70]]             
74building5 = [[10,70], [10,60], [15,60], [15,70]]             
75building6 = [[10,60], [10,50], [15,50], [15,60]]             
76
77
78
79
80river = [[20,100], [18,90], [20,80], [20,60], [15,40], [11,20], [2,0], [10,0],
81         [14,10], [20,30], [24,45], [27,80], [27,85], [35,90], [39,100]]
82             
83print 'Set elevation'   
84domain.set_quantity('elevation',
85    Polygon_function( [(shoreline, bathymetry), (land, topography), 
86                      (building1, 3), (building2, 9), 
87                      (building3, 8), (building4, 7),
88                      (building5, 8), (building6, 6),
89                      (river, riverbed)]))
90                     
91print 'Set level'                     
92domain.set_quantity('level', 
93                    Polygon_function( [(shoreline, -1.5), 
94                    (land, -10)] )) 
95                   
96print 'Set friction'                                       
97domain.set_quantity('friction', 0.03)
98
99print domain.get_extent()
100
101
102
103#Add lateral wind gusts bearing 135 degrees
104def gust(t,x,y): 
105    from math import sin, pi
106    from Numeric import zeros, ones, Float
107
108    N = len(x)
109
110    tt = sin(2*pi*t/50)
111
112    if tt > 0.7:
113        return 10000*tt*ones(N, Float)
114    else:
115        return zeros(N, Float)
116   
117domain.forcing_terms.append(Wind_stress(gust, 135))
118
119
120######################
121# Boundary conditions
122
123print 'Boundaries'
124Br = Reflective_boundary(domain)
125Bo = Transmissive_boundary(domain)
126
127#Constant inflow
128Bd = Dirichlet_boundary([0.0, -1.0, 0.0])
129Bt = Time_boundary(domain, lambda t: [ 3.0*(1+sin(2*pi*t/100)), 0.0, 0.0])
130
131print 'Available boundary tags are', domain.get_boundary_tags()
132
133#Set boundary conditions
134tags = {}
135tags['ocean'] = Bt
136tags['wall'] = Br
137tags['outflow'] = Bo
138tags['exterior'] = Br
139tags['external'] = Br
140domain.set_boundary(tags)
141
142
143domain.check_integrity()
144
145######################
146#Evolution
147for t in domain.evolve(yieldstep = 0.2, finaltime = 500):
148    domain.write_time()
149   
150print 'Done'
151
152   
Note: See TracBrowser for help on using the repository browser.