1 | """Script for running a tsunami inundation scenario for Onslow, WA, 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.outputtimedir |
---|
6 | |
---|
7 | The scenario is defined by a triangular mesh created from project.polygon, |
---|
8 | the elevation data and a simulated submarine landslide. |
---|
9 | |
---|
10 | Ole Nielsen and Duncan Gray, GA - 2005 and Nick Bartzis, GA - 2006 |
---|
11 | """ |
---|
12 | |
---|
13 | |
---|
14 | #-------------------------------------------------------------------------------# Import necessary modules |
---|
15 | #------------------------------------------------------------------------------- |
---|
16 | |
---|
17 | # Standard modules |
---|
18 | import os |
---|
19 | |
---|
20 | from os import sep |
---|
21 | from os.path import dirname, basename |
---|
22 | |
---|
23 | import time |
---|
24 | |
---|
25 | # Related major packages |
---|
26 | from pyvolution.shallow_water import Domain, Reflective_boundary, \ |
---|
27 | Dirichlet_boundary, Time_boundary, File_boundary |
---|
28 | from pyvolution.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
29 | from pyvolution.combine_pts import combine_rectangular_points_files |
---|
30 | from pyvolution.pmesh2domain import pmesh_to_domain_instance |
---|
31 | #from geospatial_data import add_points_files |
---|
32 | |
---|
33 | # Application specific imports |
---|
34 | import project # Definition of file names and polygons |
---|
35 | from smf import slump_tsunami # Function for submarine mudslide |
---|
36 | |
---|
37 | from shutil import copy |
---|
38 | from os import mkdir, access, F_OK |
---|
39 | |
---|
40 | from geospatial_data import * |
---|
41 | import sys |
---|
42 | from pyvolution.util import Screen_Catcher |
---|
43 | |
---|
44 | #------------------------------------------------------------------------------- |
---|
45 | # Preparation of topographic data |
---|
46 | # |
---|
47 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
48 | # Do for coarse and fine data |
---|
49 | # Fine pts file to be clipped to area of interest |
---|
50 | #------------------------------------------------------------------------------- |
---|
51 | |
---|
52 | # filenames |
---|
53 | onshore_dem_name = project.onshore_dem_name |
---|
54 | offshore_points1 = project.offshore_dem_name1 |
---|
55 | offshore_points2 = project.offshore_dem_name2 |
---|
56 | meshname = project.meshname+'.msh' |
---|
57 | source_dir = project.boundarydir |
---|
58 | |
---|
59 | |
---|
60 | |
---|
61 | |
---|
62 | #import sys; sys.exit() |
---|
63 | |
---|
64 | # creates copy of code in output dir if dir doesn't exist |
---|
65 | if access(project.outputtimedir,F_OK) == 0 : |
---|
66 | mkdir (project.outputtimedir) |
---|
67 | copy (dirname(project.__file__) +sep+ project.__name__+'.py', project.outputtimedir + project.__name__+'.py') |
---|
68 | copy (__file__, project.outputtimedir + basename(__file__)) |
---|
69 | |
---|
70 | |
---|
71 | #normal screen output is stored in |
---|
72 | screen_output_name = project.outputtimedir + "screen_output.txt" |
---|
73 | screen_error_name = project.outputtimedir + "screen_error.txt" |
---|
74 | |
---|
75 | #used to catch screen output to file |
---|
76 | #sys.stdout = Screen_Catcher(screen_output_name) |
---|
77 | #sys.stderr = Screen_Catcher(screen_error_name) |
---|
78 | |
---|
79 | |
---|
80 | ''' |
---|
81 | # fine data (clipping the points file to smaller area) |
---|
82 | # creates DEM from asc data |
---|
83 | convert_dem_from_ascii2netcdf(onshore_dem_name, use_cache=True, verbose=True) |
---|
84 | |
---|
85 | #creates pts file from DEM |
---|
86 | dem2pts(onshore_dem_name, |
---|
87 | easting_min=project.eastingmin, |
---|
88 | easting_max=project.eastingmax, |
---|
89 | northing_min=project.northingmin, |
---|
90 | northing_max= project.northingmax, |
---|
91 | use_cache=True, |
---|
92 | verbose=True) |
---|
93 | |
---|
94 | print'create G1' |
---|
95 | G1 = Geospatial_data(file_name = project.offshore_dem_name1 + '.xya') |
---|
96 | |
---|
97 | print'create G2' |
---|
98 | G2 = Geospatial_data(file_name = project.offshore_dem_name2 + '.xya') |
---|
99 | |
---|
100 | print'create G3' |
---|
101 | G3 = Geospatial_data(file_name = project.onshore_dem_name + '.pts') |
---|
102 | |
---|
103 | print'add G1+G2+G3' |
---|
104 | G = G1 + G2 + G3 |
---|
105 | |
---|
106 | print'export G' |
---|
107 | G.export_points_file(project.combined_dem_name + '.pts') |
---|
108 | |
---|
109 | ''' |
---|
110 | #------------------------------------------------------------------------------- |
---|
111 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
112 | # boundary and interior regions defined in project.py along with |
---|
113 | # resolutions (maximal area of per triangle) for each polygon |
---|
114 | #------------------------------------------------------------------------------- |
---|
115 | |
---|
116 | from pmesh.mesh_interface import create_mesh_from_regions |
---|
117 | |
---|
118 | region_res = 100000 |
---|
119 | coast_res = 2500 |
---|
120 | pt_hedland_res = 500 |
---|
121 | # derive poly_coast from project.coast_name using alpha_shape |
---|
122 | interior_regions = [[project.poly_pt_hedland, pt_hedland_res], |
---|
123 | [project.poly_coast, coast_res]] |
---|
124 | # [project.poly_region, region_res]] |
---|
125 | |
---|
126 | print 'number of interior regions', len(interior_regions) |
---|
127 | |
---|
128 | from utilities.polygon import inside_polygon, plot_polygons |
---|
129 | |
---|
130 | bounding_polygon = project.polyAll |
---|
131 | count = 0 |
---|
132 | for i in range(len(interior_regions)): |
---|
133 | region = interior_regions[i] |
---|
134 | interior_polygon = region[0] |
---|
135 | if len(inside_polygon(interior_polygon, bounding_polygon, |
---|
136 | closed = True, verbose = False)) <> len(interior_polygon): |
---|
137 | print 'WARNING: interior polygon %d is outside bounding polygon' %(i) |
---|
138 | count += 1 |
---|
139 | |
---|
140 | figname = 'pt_hedland_polys' |
---|
141 | print'pt_hedland_polys' |
---|
142 | #plot_polygons([project.polyAll, project.poly_pt_hedland, project.poly_region], |
---|
143 | plot_polygons([project.poly_coast], |
---|
144 | figname, |
---|
145 | verbose = True) |
---|
146 | |
---|
147 | if count == 0: |
---|
148 | print 'interior regions OK' |
---|
149 | else: |
---|
150 | print 'check out your interior polygons' |
---|
151 | print 'check %s in production directory' %figname |
---|
152 | import sys; sys.exit() |
---|
153 | |
---|
154 | print 'start create mesh from regions' |
---|
155 | from caching import cache |
---|
156 | _ = cache(create_mesh_from_regions, |
---|
157 | project.polyAll, |
---|
158 | # {'boundary_tags': {'right': [0], 'bottomright': [1], |
---|
159 | # 'bottomleft': [2], 'left': [3], 'top': [4]}, |
---|
160 | {'boundary_tags': {'topright': [0], 'top': [1],'topleft': [2], 'left': [3], |
---|
161 | 'bottomleft': [4], 'bottomright': [5], 'right': [6]}, |
---|
162 | 'maximum_triangle_area': 10000000, |
---|
163 | 'filename': meshname, |
---|
164 | 'interior_regions': interior_regions}, |
---|
165 | verbose = True) |
---|
166 | |
---|
167 | |
---|
168 | #------------------------------------------------------------------------------- |
---|
169 | # Setup computational domain |
---|
170 | #------------------------------------------------------------------------------- |
---|
171 | ''' |
---|
172 | domain = pmesh_to_domain_instance(meshname, Domain, |
---|
173 | use_cache = False, |
---|
174 | verbose = True) |
---|
175 | ''' |
---|
176 | |
---|
177 | domain = Domain(meshname, use_cache = False, verbose = True) |
---|
178 | |
---|
179 | print 'Number of triangles = ', len(domain) |
---|
180 | print 'The extent is ', domain.get_extent() |
---|
181 | print domain.statistics() |
---|
182 | |
---|
183 | domain.set_name(project.basename) |
---|
184 | domain.set_datadir(project.outputtimedir) |
---|
185 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
186 | |
---|
187 | #------------------------------------------------------------------------------- |
---|
188 | # Setup initial conditions |
---|
189 | #------------------------------------------------------------------------------- |
---|
190 | |
---|
191 | tide = 0. |
---|
192 | |
---|
193 | domain.set_quantity('stage', tide) |
---|
194 | domain.set_quantity('friction', 0.0) |
---|
195 | print 'hi and file',project.combined_dem_name + '.pts' |
---|
196 | |
---|
197 | domain.set_quantity('elevation', |
---|
198 | filename = project.combined_dem_name + '.pts', |
---|
199 | use_cache = True, |
---|
200 | verbose = True, |
---|
201 | alpha = 0.1 |
---|
202 | ) |
---|
203 | |
---|
204 | #print 'have sent quantities OK - now exiting' |
---|
205 | #import sys; sys.exit() |
---|
206 | |
---|
207 | #------------------------------------------------------------------------------- |
---|
208 | # Setup boundary conditions (all reflective) |
---|
209 | #------------------------------------------------------------------------------- |
---|
210 | print 'start ferret2sww' |
---|
211 | # skipped as results in file SU-AU_clipped is correct for all WA |
---|
212 | |
---|
213 | from pyvolution.data_manager import ferret2sww |
---|
214 | |
---|
215 | south = project.south |
---|
216 | north = project.north |
---|
217 | west = project.west |
---|
218 | east = project.east |
---|
219 | |
---|
220 | #note only need to do when an SWW file for the MOST boundary doesn't exist |
---|
221 | cache(ferret2sww, |
---|
222 | (source_dir + project.boundary_basename, |
---|
223 | source_dir + project.boundary_basename), |
---|
224 | {'verbose': True, |
---|
225 | 'minlat': south, |
---|
226 | 'maxlat': north, |
---|
227 | 'minlon': west, |
---|
228 | 'maxlon': east, |
---|
229 | # 'origin': project.mesh_origin, |
---|
230 | 'origin': domain.geo_reference.get_origin(), |
---|
231 | 'mean_stage': tide, |
---|
232 | 'zscale': 1, #Enhance tsunami |
---|
233 | 'fail_on_NaN': False, |
---|
234 | 'inverted_bathymetry': True}, |
---|
235 | #evaluate = True, |
---|
236 | verbose = True) |
---|
237 | |
---|
238 | |
---|
239 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
240 | |
---|
241 | Bf = File_boundary(source_dir + project.boundary_basename + '.sww', |
---|
242 | domain, verbose = True) |
---|
243 | Br = Reflective_boundary(domain) |
---|
244 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
245 | |
---|
246 | # 7 min square wave starting at 1 min, 6m high |
---|
247 | Bw = Time_boundary(domain = domain, |
---|
248 | f=lambda t: [(60<t<480)*6, 0, 0]) |
---|
249 | |
---|
250 | #domain.set_boundary( {'top': Bf, 'left': Br, 'bottomleft': Br, 'bottomright': Br, 'right': Br} ) |
---|
251 | # |
---|
252 | domain.set_boundary( {'topright': Bf, 'top': Bf,'topleft': Bf, 'left': Br, |
---|
253 | 'bottomleft': Br, 'bottomright': Br, 'right': Br}) |
---|
254 | |
---|
255 | #------------------------------------------------------------------------------- |
---|
256 | # Evolve system through time |
---|
257 | #------------------------------------------------------------------------------- |
---|
258 | import time |
---|
259 | t0 = time.time() |
---|
260 | |
---|
261 | for t in domain.evolve(yieldstep = 240, finaltime = 7200): |
---|
262 | domain.write_time() |
---|
263 | domain.write_boundary_statistics(tags = 'top') |
---|
264 | |
---|
265 | for t in domain.evolve(yieldstep = 120, finaltime = 12600 |
---|
266 | ,skip_initial_step = True): |
---|
267 | domain.write_time() |
---|
268 | domain.write_boundary_statistics(tags = 'top') |
---|
269 | |
---|
270 | for t in domain.evolve(yieldstep = 60, finaltime = 19800 |
---|
271 | ,skip_initial_step = True): |
---|
272 | domain.write_time() |
---|
273 | domain.write_boundary_statistics(tags = 'top') |
---|
274 | |
---|
275 | for t in domain.evolve(yieldstep = 120, finaltime = 25200 |
---|
276 | ,skip_initial_step = True): |
---|
277 | domain.write_time() |
---|
278 | domain.write_boundary_statistics(tags = 'top') |
---|
279 | |
---|
280 | for t in domain.evolve(yieldstep = 240, finaltime = 36000 |
---|
281 | ,skip_initial_step = True): |
---|
282 | domain.write_time() |
---|
283 | domain.write_boundary_statistics(tags = 'top') |
---|
284 | |
---|
285 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
286 | |
---|
287 | print 'finished' |
---|