1 | """Example of the inundationmodel. |
---|
2 | |
---|
3 | A wave of water is washed up ontp a hypothetical beach. |
---|
4 | |
---|
5 | To run: |
---|
6 | |
---|
7 | python beach.py |
---|
8 | """ |
---|
9 | |
---|
10 | ###################### |
---|
11 | # Module imports |
---|
12 | # |
---|
13 | |
---|
14 | import sys |
---|
15 | from os import sep, path |
---|
16 | sys.path.append('..'+sep+'pyvolution') |
---|
17 | |
---|
18 | from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\ |
---|
19 | Transmissive_boundary, Time_boundary, Wind_stress |
---|
20 | |
---|
21 | from pmesh2domain import pmesh_to_domain_instance |
---|
22 | from config import data_dir |
---|
23 | from util import read_polygon, Polygon_function |
---|
24 | from math import pi |
---|
25 | from Numeric import choose, greater, ones, sin |
---|
26 | |
---|
27 | |
---|
28 | ###################### |
---|
29 | # Domain |
---|
30 | name = 'beach' |
---|
31 | print 'Creating domain from %s.tsh' %name |
---|
32 | domain = pmesh_to_domain_instance(name + '.tsh', Domain) |
---|
33 | |
---|
34 | #HACK to remove internal boundary (until we get a solution) |
---|
35 | for b in domain.boundary.keys(): |
---|
36 | if domain.boundary[b] == '': |
---|
37 | del domain.boundary[b] |
---|
38 | |
---|
39 | domain = Domain(domain.coordinates, domain.triangles, domain.boundary) |
---|
40 | |
---|
41 | domain.store = True |
---|
42 | domain.set_name(name) |
---|
43 | print "Output being written to " + data_dir + sep + \ |
---|
44 | domain.filename + "_size%d." %len(domain) + domain.format |
---|
45 | |
---|
46 | |
---|
47 | def 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 | |
---|
56 | def topography(x, y): |
---|
57 | return 4*sin(pi*x/50) + 1 |
---|
58 | |
---|
59 | def riverbed(x, y): |
---|
60 | #return (y-100)/10 + 5*x/100 |
---|
61 | return (y-100)/50 + 4.4 |
---|
62 | |
---|
63 | |
---|
64 | shoreline = [[40,0], [100,0], [100,100], [65,100], |
---|
65 | [55,90], [55,70], [56,50], [50,25], [40,0]] |
---|
66 | |
---|
67 | land = [[65,100], [55,90], [55,70], [56,50], [50,25], [40,0], |
---|
68 | [0,0], [0,100]] |
---|
69 | |
---|
70 | building1 = [[45,80], [50,78], [52,83], [45,83]] |
---|
71 | building2 = [[35,75], [40,75], [40,80], [35,80]] |
---|
72 | building3 = [[42,63], [47,63], [50,68], [37,68]] |
---|
73 | building4 = [[28,70], [28,60], [33,60], [33,70]] |
---|
74 | building5 = [[10,70], [10,60], [15,60], [15,70]] |
---|
75 | building6 = [[10,60], [10,50], [15,50], [15,60]] |
---|
76 | |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | river = [[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 | |
---|
83 | print 'Set elevation' |
---|
84 | domain.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 | |
---|
91 | print 'Set level' |
---|
92 | domain.set_quantity('level', |
---|
93 | Polygon_function( [(shoreline, -1.5), |
---|
94 | (land, -10)] )) |
---|
95 | |
---|
96 | print 'Set friction' |
---|
97 | domain.set_quantity('friction', 0.03) |
---|
98 | |
---|
99 | print domain.get_extent() |
---|
100 | |
---|
101 | |
---|
102 | |
---|
103 | #Add lateral wind gusts bearing 135 degrees |
---|
104 | def 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 | |
---|
117 | domain.forcing_terms.append(Wind_stress(gust, 135)) |
---|
118 | |
---|
119 | |
---|
120 | ###################### |
---|
121 | # Boundary conditions |
---|
122 | |
---|
123 | print 'Boundaries' |
---|
124 | Br = Reflective_boundary(domain) |
---|
125 | Bo = Transmissive_boundary(domain) |
---|
126 | |
---|
127 | #Constant inflow |
---|
128 | Bd = Dirichlet_boundary([0.0, -1.0, 0.0]) |
---|
129 | Bt = Time_boundary(domain, lambda t: [ 3.0*(1+sin(2*pi*t/100)), 0.0, 0.0]) |
---|
130 | |
---|
131 | print 'Available boundary tags are', domain.get_boundary_tags() |
---|
132 | |
---|
133 | #Set boundary conditions |
---|
134 | tags = {} |
---|
135 | tags['ocean'] = Bt |
---|
136 | tags['wall'] = Br |
---|
137 | tags['outflow'] = Bo |
---|
138 | tags['exterior'] = Br |
---|
139 | tags['external'] = Br |
---|
140 | domain.set_boundary(tags) |
---|
141 | |
---|
142 | |
---|
143 | domain.check_integrity() |
---|
144 | |
---|
145 | ###################### |
---|
146 | #Evolution |
---|
147 | for t in domain.evolve(yieldstep = 0.2, finaltime = 500): |
---|
148 | domain.write_time() |
---|
149 | |
---|
150 | print 'Done' |
---|
151 | |
---|
152 | |
---|