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 | import time |
---|
20 | from shutil import copy |
---|
21 | from os import mkdir, access, F_OK |
---|
22 | import sys |
---|
23 | |
---|
24 | # Related major packages |
---|
25 | from anuga.shallow_water import Domain, Reflective_boundary, \ |
---|
26 | Dirichlet_boundary, Time_boundary, File_boundary |
---|
27 | from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
28 | from anuga.abstract_2d_finite_volumes.combine_pts import combine_rectangular_points_files |
---|
29 | from anuga.geospatial_data.geospatial_data import * |
---|
30 | from anuga.abstract_2d_finite_volumes.util import Screen_Catcher |
---|
31 | |
---|
32 | # Application specific imports |
---|
33 | import project # Definition of file names and polygons |
---|
34 | |
---|
35 | #------------------------------------------------------------------------------- |
---|
36 | # Copy scripts to time stamped output directory and capture screen |
---|
37 | # output to file |
---|
38 | #------------------------------------------------------------------------------- |
---|
39 | |
---|
40 | # creates copy of code in output dir if dir doesn't exist |
---|
41 | if access(project.outputtimedir,F_OK) == 0 : |
---|
42 | mkdir (project.outputtimedir) |
---|
43 | copy (project.codedirname, project.outputtimedir + project.codename) |
---|
44 | copy (project.codedir + 'run_onslow.py', project.outputtimedir + 'run_onslow.py') |
---|
45 | print'output dir', project.outputtimedir |
---|
46 | |
---|
47 | #normal screen output is stored in |
---|
48 | screen_output_name = project.outputtimedir + "screen_output.txt" |
---|
49 | screen_error_name = project.outputtimedir + "screen_error.txt" |
---|
50 | |
---|
51 | #used to catch screen output to file |
---|
52 | sys.stdout = Screen_Catcher(screen_output_name) |
---|
53 | #sys.stderr = Screen_Catcher(screen_output_name) |
---|
54 | sys.stderr = Screen_Catcher(screen_error_name) |
---|
55 | |
---|
56 | print 'USER: ', project.user |
---|
57 | |
---|
58 | #------------------------------------------------------------------------------- |
---|
59 | # Preparation of topographic data |
---|
60 | # |
---|
61 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
62 | # Do for coarse and fine data |
---|
63 | # Fine pts file to be clipped to area of interest |
---|
64 | #------------------------------------------------------------------------------- |
---|
65 | |
---|
66 | # filenames |
---|
67 | onshore_dem_name = project.onshore_dem_name |
---|
68 | islands_dem_name = project.islands_dem_name |
---|
69 | coast_points = project.coast_dem_name |
---|
70 | offshore_points = project.offshore_dem_name |
---|
71 | meshname = project.meshname+'.msh' |
---|
72 | source_dir = project.boundarydir |
---|
73 | |
---|
74 | copied_files = False |
---|
75 | |
---|
76 | # files to be used |
---|
77 | files_used = [onshore_dem_name, offshore_points, coast_points,] |
---|
78 | |
---|
79 | # fine data (clipping the points file to smaller area) |
---|
80 | # creates DEM from asc data |
---|
81 | convert_dem_from_ascii2netcdf(onshore_dem_name, use_cache=True, verbose=True) |
---|
82 | |
---|
83 | #creates pts file for onshore DEM |
---|
84 | dem2pts(onshore_dem_name, |
---|
85 | easting_min=project.eastingmin, |
---|
86 | easting_max=project.eastingmax, |
---|
87 | northing_min=project.northingmin, |
---|
88 | northing_max= project.northingmax, |
---|
89 | use_cache=True, |
---|
90 | verbose=True) |
---|
91 | |
---|
92 | convert_dem_from_ascii2netcdf(islands_dem_name, use_cache=True, verbose=True) |
---|
93 | |
---|
94 | #creates pts file for islands DEM |
---|
95 | dem2pts(islands_dem_name, use_cache=True, verbose=True) |
---|
96 | |
---|
97 | print'create G1' |
---|
98 | G1 = Geospatial_data(file_name = project.offshore_dem_name + '.xya') |
---|
99 | print'create G2' |
---|
100 | G2 = Geospatial_data(file_name = project.onshore_dem_name + '.pts') |
---|
101 | print'create G3' |
---|
102 | G3 = Geospatial_data(file_name = project.coast_dem_name + '.xya') |
---|
103 | print'create G4' |
---|
104 | G4 = Geospatial_data(file_name = project.islands_dem_name + '.pts') |
---|
105 | print'add G1+G2+G3+G4' |
---|
106 | G = G1 + G2 + G3 + G4 |
---|
107 | print'export G' |
---|
108 | G.export_points_file(project.combined_dem_name + '.pts') |
---|
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 anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
117 | |
---|
118 | #new |
---|
119 | region_res = 200000 |
---|
120 | coast_res = 25000 |
---|
121 | onslow_res = 5000 |
---|
122 | interior_regions = [[project.poly_onslow, onslow_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 caching import cache |
---|
129 | _ = cache(create_mesh_from_regions, |
---|
130 | project.polyAll, |
---|
131 | {'boundary_tags': {'top': [0], 'topleft': [1], |
---|
132 | 'topleft1': [2], 'bottomleft': [3], |
---|
133 | 'bottom': [4], 'bottomright': [5], |
---|
134 | 'topright':[6]}, |
---|
135 | 'maximum_triangle_area': 100000, |
---|
136 | 'filename': meshname, |
---|
137 | 'interior_regions': interior_regions}, |
---|
138 | verbose = True, evaluate=True) |
---|
139 | |
---|
140 | |
---|
141 | #------------------------------------------------------------------------------- |
---|
142 | # Setup computational domain |
---|
143 | #------------------------------------------------------------------------------- |
---|
144 | |
---|
145 | #domain = pmesh_to_domain_instance(meshname, Domain, |
---|
146 | # use_cache = False, |
---|
147 | # verbose = True) |
---|
148 | |
---|
149 | domain = Domain(meshname, use_cache = False, verbose = True) |
---|
150 | |
---|
151 | print 'Number of triangles = ', len(domain) |
---|
152 | print 'The extent is ', domain.get_extent() |
---|
153 | print domain.statistics() |
---|
154 | |
---|
155 | domain.set_name(project.basename) |
---|
156 | domain.set_datadir(project.outputtimedir) |
---|
157 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
158 | |
---|
159 | |
---|
160 | #------------------------------------------------------------------------------- |
---|
161 | # Setup initial conditions |
---|
162 | #------------------------------------------------------------------------------- |
---|
163 | |
---|
164 | tide = 0.0 |
---|
165 | |
---|
166 | domain.set_quantity('stage', tide) |
---|
167 | domain.set_quantity('friction', 0.0) |
---|
168 | print 'hi and file',project.combined_dem_name + '.pts' |
---|
169 | |
---|
170 | domain.set_quantity('elevation', |
---|
171 | # 0. |
---|
172 | # filename = project.onshore_dem_name + '.pts', |
---|
173 | filename = project.combined_dem_name + '.pts', |
---|
174 | # filename = project.offshore_dem_name + '.pts', |
---|
175 | use_cache = True, |
---|
176 | verbose = True, |
---|
177 | alpha = 0.1 |
---|
178 | ) |
---|
179 | |
---|
180 | print 'hi1' |
---|
181 | |
---|
182 | #------------------------------------------------------------------------------- |
---|
183 | # Setup boundary conditions (all reflective) |
---|
184 | #------------------------------------------------------------------------------- |
---|
185 | print 'start ferret2sww' |
---|
186 | from anuga.pyvolution.data_manager import ferret2sww |
---|
187 | |
---|
188 | south = project.south |
---|
189 | north = project.north |
---|
190 | west = project.west |
---|
191 | east = project.east |
---|
192 | |
---|
193 | #note only need to do when an SWW file for the MOST boundary doesn't exist |
---|
194 | cache(ferret2sww, |
---|
195 | (source_dir + project.boundary_basename, |
---|
196 | source_dir + project.boundary_basename), |
---|
197 | # (project.MOST_dir + project.boundary_basename, |
---|
198 | # source_dir + project.boundary_basename), |
---|
199 | {'verbose': True, |
---|
200 | # note didn't work with the below |
---|
201 | # 'minlat': south - 1, |
---|
202 | # 'maxlat': north + 1, |
---|
203 | # 'minlon': west - 1, |
---|
204 | # 'maxlon': east + 1, |
---|
205 | 'minlat': south, |
---|
206 | 'maxlat': north, |
---|
207 | 'minlon': west, |
---|
208 | 'maxlon': east, |
---|
209 | # 'origin': project.mesh_origin, |
---|
210 | 'origin': domain.geo_reference.get_origin(), |
---|
211 | 'mean_stage': tide, |
---|
212 | 'zscale': 1, #Enhance tsunami |
---|
213 | 'fail_on_NaN': False, |
---|
214 | 'inverted_bathymetry': True}, |
---|
215 | #evaluate = True, |
---|
216 | verbose = True, |
---|
217 | dependencies = source_dir + project.boundary_basename + '.sww') |
---|
218 | |
---|
219 | |
---|
220 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
221 | |
---|
222 | Bf = File_boundary(source_dir + project.boundary_basename + '.sww', |
---|
223 | domain, verbose = True) |
---|
224 | Br = Reflective_boundary(domain) |
---|
225 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
226 | |
---|
227 | |
---|
228 | # 7 min square wave starting at 1 min, 6m high |
---|
229 | Bw = Time_boundary(domain = domain, |
---|
230 | f=lambda t: [(60<t<480)*6, 0, 0]) |
---|
231 | |
---|
232 | domain.set_boundary( {'top': Bf, 'topleft': Bf, |
---|
233 | 'topleft1': Bf, 'bottomleft': Bd, |
---|
234 | 'bottom': Br, 'bottomright': Br, 'topright': Bd} ) |
---|
235 | |
---|
236 | #------------------------------------------------------------------------------- |
---|
237 | # Evolve system through time |
---|
238 | #------------------------------------------------------------------------------- |
---|
239 | import time |
---|
240 | t0 = time.time() |
---|
241 | |
---|
242 | for t in domain.evolve(yieldstep = 240, finaltime = 7200): |
---|
243 | domain.write_time() |
---|
244 | domain.write_boundary_statistics(tags = 'top') |
---|
245 | |
---|
246 | for t in domain.evolve(yieldstep = 120, finaltime = 12600 |
---|
247 | ,skip_initial_step =True): |
---|
248 | domain.write_time() |
---|
249 | domain.write_boundary_statistics(tags = 'top') |
---|
250 | |
---|
251 | for t in domain.evolve(yieldstep = 60, finaltime = 19800 |
---|
252 | ,skip_initial_step = True): |
---|
253 | domain.write_time() |
---|
254 | domain.write_boundary_statistics(tags = 'top') |
---|
255 | |
---|
256 | for t in domain.evolve(yieldstep = 120, finaltime = 25200 |
---|
257 | ,skip_initial_step = True): |
---|
258 | domain.write_time() |
---|
259 | domain.write_boundary_statistics(tags = 'top') |
---|
260 | |
---|
261 | for t in domain.evolve(yieldstep = 240, finaltime = 36000 |
---|
262 | ,skip_initial_step = True): |
---|
263 | domain.write_time() |
---|
264 | domain.write_boundary_statistics(tags = 'top') |
---|
265 | |
---|
266 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
267 | |
---|
268 | print 'finished' |
---|