1 | """Script for running a tsunami inundation scenario for Sydney, NSW, Australia. |
---|
2 | |
---|
3 | Source data such as elevation and boundary data is assumed to be available in |
---|
4 | directories specified by project.py |
---|
5 | The output sww file is stored in project.outputdir |
---|
6 | |
---|
7 | The scenario is defined by a triangular mesh created from project.polygon, |
---|
8 | the elevation data and boundary data obtained from a tsunami simulation done with MOST. |
---|
9 | |
---|
10 | Ole Nielsen, GA - 2005 and Adrian Hitchman and Jane Sexton, GA - 2006 |
---|
11 | """ |
---|
12 | |
---|
13 | tide = 0 #Australian Height Datum (mean sea level) |
---|
14 | |
---|
15 | import os |
---|
16 | import time |
---|
17 | |
---|
18 | |
---|
19 | from pyvolution.shallow_water import Domain, Reflective_boundary, File_boundary,\ |
---|
20 | Dirichlet_boundary, Time_boundary, Transmissive_boundary |
---|
21 | from pyvolution.data_manager import convert_dem_from_ascii2netcdf,\ |
---|
22 | dem2pts |
---|
23 | from pyvolution.pmesh2domain import pmesh_to_domain_instance |
---|
24 | from pyvolution.combine_pts import combine_rectangular_points_files |
---|
25 | from caching import cache |
---|
26 | import project |
---|
27 | from math import pi, sin |
---|
28 | from smf import slump_tsunami, slide_tsunami, Double_gaussian |
---|
29 | from pyvolution.least_squares import fit_to_mesh_file, DEFAULT_ALPHA |
---|
30 | |
---|
31 | # Data preparation |
---|
32 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
33 | # Do for coarse and fine data |
---|
34 | # Fine pts file to be clipped to area of interest |
---|
35 | coarsedemname = project.coarsedemname |
---|
36 | finedemname = project.finedemname |
---|
37 | meshname = project.meshname+'.msh' |
---|
38 | |
---|
39 | # coarse data |
---|
40 | cache(convert_dem_from_ascii2netcdf, coarsedemname, {'verbose': True}, |
---|
41 | dependencies = [coarsedemname + '.asc'], |
---|
42 | verbose = True) |
---|
43 | #evaluate = True) |
---|
44 | |
---|
45 | cache(dem2pts, coarsedemname, {'verbose': True}, |
---|
46 | dependencies = [coarsedemname + '.dem'], |
---|
47 | verbose = True) |
---|
48 | |
---|
49 | # fine data |
---|
50 | cache(convert_dem_from_ascii2netcdf, finedemname, {'verbose': True}, |
---|
51 | dependencies = [finedemname + '.asc'], |
---|
52 | verbose = True) |
---|
53 | #evaluate = True) |
---|
54 | |
---|
55 | # clipping the fine data |
---|
56 | cache(dem2pts, finedemname, {'verbose': True, |
---|
57 | 'easting_min': project.eastingmin, |
---|
58 | 'easting_max': project.eastingmax, |
---|
59 | 'northing_min': project.northingmin, |
---|
60 | 'northing_max': project.northingmax}, |
---|
61 | dependencies = [finedemname + '.dem'], |
---|
62 | #evaluate = True, |
---|
63 | verbose = True) |
---|
64 | |
---|
65 | # combining the coarse and fine data |
---|
66 | combine_rectangular_points_files(project.finedemname + '.pts', |
---|
67 | project.coarsedemname + '.pts', |
---|
68 | project.combineddemname + '.pts') |
---|
69 | |
---|
70 | # this allows the user to switch between different clipping polygons |
---|
71 | # print 'Which total zone are you interested in?' |
---|
72 | # mytest = int(raw_input('0 = all, 1 = harbour and 2 = botany bay ')) |
---|
73 | |
---|
74 | mytest = 0 |
---|
75 | |
---|
76 | # Create Triangular Mesh |
---|
77 | # Overall clipping polygon and interior regions defined in project.py |
---|
78 | from pmesh.create_mesh import create_mesh_from_regions |
---|
79 | |
---|
80 | if mytest == 0: |
---|
81 | # for whole region |
---|
82 | interior_res = 2000 # run at 2000 for final one |
---|
83 | interior_regions = [[project.harbour_polygon_2, interior_res], |
---|
84 | [project.botanybay_polygon_2, interior_res]] # maximal area of per triangle |
---|
85 | |
---|
86 | m = cache(create_mesh_from_regions, |
---|
87 | project.diffpolygonall, |
---|
88 | {'boundary_tags': {'bottom': [0], |
---|
89 | 'right1': [1], 'right0': [2], |
---|
90 | 'right2': [3], 'top': [4], 'left1': [5], |
---|
91 | 'left2': [6], 'left3': [7]}, |
---|
92 | 'resolution': 100000, |
---|
93 | 'filename': meshname, |
---|
94 | 'interior_regions': interior_regions}, |
---|
95 | #evaluate=True, |
---|
96 | verbose = True) |
---|
97 | #import sys; sys.exit() |
---|
98 | |
---|
99 | #Add elevation data to the mesh - this is in place of set_quantity |
---|
100 | mesh_elevname = 'elevation.msh' |
---|
101 | cache(fit_to_mesh_file,(meshname, |
---|
102 | #project.finedemname + '.pts', |
---|
103 | #project.coarsedemname + '.pts', |
---|
104 | project.combineddemname + '.pts', |
---|
105 | mesh_elevname, |
---|
106 | DEFAULT_ALPHA), |
---|
107 | {'verbose': True, 'expand_search': True, 'precrop': True}, |
---|
108 | dependencies = [meshname], |
---|
109 | #evaluate = True, |
---|
110 | verbose = False) |
---|
111 | meshname = mesh_elevname |
---|
112 | |
---|
113 | # Setup domain |
---|
114 | domain = cache(pmesh_to_domain_instance, (meshname, Domain), |
---|
115 | dependencies = [meshname], |
---|
116 | verbose = True) |
---|
117 | |
---|
118 | print 'Number of triangles = ', len(domain) |
---|
119 | print 'The extent is ', domain.get_extent() |
---|
120 | |
---|
121 | domain.set_name(project.basename) |
---|
122 | domain.set_datadir(project.outputdir) |
---|
123 | domain.store = True |
---|
124 | #domain.quantities_to_be_stored = ['stage'] |
---|
125 | domain.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum'] |
---|
126 | |
---|
127 | #print 'Do you want to run the slump scenario?' |
---|
128 | #q2 = int(raw_input('0 for yes, 1 for no ')) |
---|
129 | |
---|
130 | q2 = 0 |
---|
131 | |
---|
132 | if q2 == 0: |
---|
133 | # slump parameters |
---|
134 | # as advised by Adrian, this can be as much as 15000-30000 metres |
---|
135 | # len = 4500.0 |
---|
136 | len = 15000.0 |
---|
137 | thk = 670 #thk = 760.0 |
---|
138 | wid = 15000.0 # for slump scenario, wid=len |
---|
139 | #dep = 400 #1000.0 #d = 400 doesn't make sense with thk = 670! |
---|
140 | dep = 1000.0 |
---|
141 | rad = 3330 |
---|
142 | dp = 0.23 |
---|
143 | th = 6 |
---|
144 | alpha = 0.0 |
---|
145 | x0 = project.x0 |
---|
146 | y0 = project.y0 |
---|
147 | # slide parameters |
---|
148 | # len = 10000.0 |
---|
149 | # dep = 1200.0 |
---|
150 | # thk = 200.0 |
---|
151 | # th = 12 |
---|
152 | # Slump or Slide Initial conditions |
---|
153 | t = slump_tsunami(length=len, depth=dep, slope=th, thickness=thk, \ |
---|
154 | radius=rad, dphi=dp, x0=x0, y0=y0, alpha=alpha) |
---|
155 | #t = slide_tsunami(length=len, depth=dep, slope=th, thickness=thk, \ |
---|
156 | # x0=x0, y0=y0, alpha=alpha) |
---|
157 | domain.set_quantity('stage', t, verbose = True) |
---|
158 | |
---|
159 | if q2 == 1: |
---|
160 | domain.set_quantity('stage', tide) |
---|
161 | |
---|
162 | |
---|
163 | # These quantities are the same regardless of the initial condition |
---|
164 | domain.set_quantity('friction', 0) |
---|
165 | |
---|
166 | |
---|
167 | # Setup Boundary Conditions |
---|
168 | print domain.get_boundary_tags() |
---|
169 | |
---|
170 | Br = Reflective_boundary(domain) |
---|
171 | Bt = Transmissive_boundary(domain) |
---|
172 | Bd = Dirichlet_boundary([0,0,0]) |
---|
173 | # 10 min square wave starting at 1 min, 6m high |
---|
174 | Bw = Time_boundary(domain=domain, |
---|
175 | f=lambda t: [(6<t<606)*6, 0, 0]) |
---|
176 | |
---|
177 | # for slump scenario |
---|
178 | if q2 == 0: |
---|
179 | domain.set_boundary( {'bottom': Br, 'right1': Br, 'right0': Br, |
---|
180 | 'right2': Br, 'top': Br, 'left1': Br, |
---|
181 | 'left2': Br, 'left3': Br} ) |
---|
182 | |
---|
183 | # for square wave scenario |
---|
184 | if q2 == 1: |
---|
185 | domain.set_boundary( {'top': Br, 'bottom': Br, 'right': Bw, 'left': Br} ) |
---|
186 | |
---|
187 | # Evolve |
---|
188 | import time |
---|
189 | t0 = time.time() |
---|
190 | |
---|
191 | for t in domain.evolve(yieldstep = 120, finaltime = 10800): #120 10800 = 3hrs |
---|
192 | domain.write_time() |
---|
193 | domain.write_boundary_statistics(tags = 'bottom') #quantities = 'stage') |
---|
194 | |
---|
195 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
196 | |
---|
197 | ############################################################# |
---|
198 | # testing system on a smaller mesh |
---|
199 | #m = create_mesh_from_regions(project.harbour_polygon, |
---|
200 | # boundary_tags={'bottom': [0], 'top': [2], |
---|
201 | # 'right': [1], 'left': [3]}, |
---|
202 | # resolution=100000, filename=meshname) |
---|
203 | |
---|
204 | # This section replaced with fit_to_mesh_file above |
---|
205 | #domain.set_quantity('elevation', |
---|
206 | # #filename = project.combineddemname + '.pts', |
---|
207 | # filename = project.finedemname + '.pts', |
---|
208 | #filename = project.datadir + 'bathy_land25_orig.pts', |
---|
209 | # use_cache = True, |
---|
210 | # verbose = True) |
---|
211 | |
---|
212 | |
---|
213 | # for switching between overall clipping regions - NOT USED |
---|
214 | |
---|
215 | if mytest == 1: |
---|
216 | # for harbour region |
---|
217 | south = project.hsouth |
---|
218 | north = project.hnorth |
---|
219 | west = project.hwest |
---|
220 | east = project.heast |
---|
221 | |
---|
222 | #interior_regions = [[project.harbour_polygon, 25000]] # maximal area of per triangle |
---|
223 | # meshname = project.meshname + 'harbour.msh' |
---|
224 | m = cache(create_mesh_from_regions, |
---|
225 | project.polygon_h, |
---|
226 | {'boundary_tags': {'bottom': [0], 'top': [2], |
---|
227 | 'right': [1], 'left': [3]}, |
---|
228 | 'resolution': 50000, |
---|
229 | 'filename': meshname}, |
---|
230 | # 'interior_regions': interior_regions}, |
---|
231 | evaluate=True, |
---|
232 | verbose = True) |
---|
233 | |
---|
234 | if mytest == 2: |
---|
235 | # for botany bay region |
---|
236 | south = project.bsouth |
---|
237 | north = project.bnorth |
---|
238 | west = project.bwest |
---|
239 | east = project.beast |
---|
240 | |
---|
241 | #interior_regions = [[project.botanybay_polygon, 25000]] # maximal area of per triangle |
---|
242 | # meshname = project.meshname + 'bay.msh' |
---|
243 | m = cache(create_mesh_from_regions, |
---|
244 | project.polygon_bb, |
---|
245 | {'boundary_tags': {'bottom': [0], 'top': [2], |
---|
246 | 'right': [1], 'left': [3]}, |
---|
247 | 'resolution': 50000, |
---|
248 | 'filename': meshname}, |
---|
249 | # 'interior_regions': interior_regions}, |
---|
250 | evaluate=True, |
---|
251 | verbose = True) |
---|
252 | |
---|