1 | """Script for running a tsunami inundation scenario for Hobart, TAS, 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 tsunami wave generated by MOST. |
---|
9 | |
---|
10 | Ole Nielsen and Duncan Gray, GA - 2005 and Nick Bartzis, GA - 2006 |
---|
11 | """ |
---|
12 | #------------------------------------------------------------------------------- |
---|
13 | # Import necessary modules |
---|
14 | #------------------------------------------------------------------------------- |
---|
15 | |
---|
16 | # Standard modules |
---|
17 | import os |
---|
18 | import time |
---|
19 | from shutil import copy |
---|
20 | from os import mkdir, access, F_OK |
---|
21 | import sys |
---|
22 | |
---|
23 | # Related major packages |
---|
24 | from anuga.shallow_water import Domain, Reflective_boundary, \ |
---|
25 | Dirichlet_boundary, Time_boundary, File_boundary |
---|
26 | from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
27 | from anuga.abstract_2d_finite_volumes.combine_pts import combine_rectangular_points_files |
---|
28 | from anuga.geospatial_data.geospatial_data import * |
---|
29 | from anuga.abstract_2d_finite_volumes.util import Screen_Catcher |
---|
30 | |
---|
31 | # Application specific imports |
---|
32 | import project # Definition of file names and polygons |
---|
33 | |
---|
34 | #------------------------------------------------------------------------------- |
---|
35 | # Copy scripts to time stamped output directory and capture screen |
---|
36 | # output to file |
---|
37 | #------------------------------------------------------------------------------- |
---|
38 | |
---|
39 | # creates copy of code in output dir if dir doesn't exist |
---|
40 | if access(project.outputtimedir,F_OK) == 0 : |
---|
41 | mkdir (project.outputtimedir) |
---|
42 | copy (project.codedirname, project.outputtimedir + project.codename) |
---|
43 | copy (project.codedir + 'run_hobart.py', project.outputtimedir + 'run_hobart.py') |
---|
44 | print'output dir', project.outputtimedir |
---|
45 | |
---|
46 | #normal screen output is stored in |
---|
47 | screen_output_name = project.outputtimedir + "screen_output.txt" |
---|
48 | screen_error_name = project.outputtimedir + "screen_error.txt" |
---|
49 | |
---|
50 | #used to catch screen output to file |
---|
51 | sys.stdout = Screen_Catcher(screen_output_name) |
---|
52 | sys.stderr = Screen_Catcher(screen_error_name) |
---|
53 | |
---|
54 | print 'USER: ', project.user |
---|
55 | |
---|
56 | #------------------------------------------------------------------------------- |
---|
57 | # Preparation of topographic data |
---|
58 | # |
---|
59 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
60 | #------------------------------------------------------------------------------- |
---|
61 | |
---|
62 | # filenames |
---|
63 | onshore_offshore_dem_name = project.onshore_offshore_dem_name |
---|
64 | onshore_offshore_dem_name_25 = project.onshore_offshore_dem_name_25 |
---|
65 | meshname = project.meshname+'.msh' |
---|
66 | source_dir = project.boundarydir |
---|
67 | |
---|
68 | copied_files = False |
---|
69 | |
---|
70 | # create DEM from 50m asc data |
---|
71 | convert_dem_from_ascii2netcdf(onshore_offshore_dem_name, use_cache=True, verbose=True) |
---|
72 | |
---|
73 | # creates pts file for combined 50m DEM |
---|
74 | dem2pts(onshore_offshore_dem_name, use_cache=True, verbose=True) |
---|
75 | """ |
---|
76 | # 25m data (clipping the around the Hobart area) |
---|
77 | convert_dem_from_ascii2netcdf(onshore_offshore_dem_name_25, use_cache=True, verbose=True) |
---|
78 | |
---|
79 | # creates pts file for 25m data around Hobart |
---|
80 | dem2pts(onshore_offshore_dem_name_25, project.hobart_dem_name_25, |
---|
81 | easting_min=project.eastingmin25, |
---|
82 | easting_max=project.eastingmax25, |
---|
83 | northing_min=project.northingmin25, |
---|
84 | northing_max= project.northingmax25, |
---|
85 | use_cache=True, |
---|
86 | verbose=True) |
---|
87 | |
---|
88 | # combining the 50m and Hobart 25m data |
---|
89 | combine_rectangular_points_files(project.hobart_dem_name_25 + '.pts', |
---|
90 | project.onshore_offshore_dem_name + '.pts', |
---|
91 | project.combined_dem_name + '.pts') |
---|
92 | |
---|
93 | # 25m data (clipping the around site 24 on Bruny Island) |
---|
94 | #convert_dem_from_ascii2netcdf(onshore_offshore_dem_name_25, use_cache=True, verbose=True) |
---|
95 | |
---|
96 | # creates pts file for 25m data around site 24 at Bruny Island |
---|
97 | dem2pts(onshore_offshore_dem_name_25, project.bruny_dem_name_25, |
---|
98 | easting_min=project.eastingmin25_2, |
---|
99 | easting_max=project.eastingmax25_2, |
---|
100 | northing_min=project.northingmin25_2, |
---|
101 | northing_max= project.northingmax25_2, |
---|
102 | use_cache=True, |
---|
103 | verbose=True) |
---|
104 | |
---|
105 | # combining the 50m and Hobart 25m data with Bruny Island 25m data |
---|
106 | combine_rectangular_points_files(project.bruny_dem_name_25 + '.pts', |
---|
107 | project.combined_dem_name + '.pts', |
---|
108 | project.combined_dem_name_2 + '.pts') |
---|
109 | |
---|
110 | # If working with points, then add separate datasets together here |
---|
111 | # create geospatial data set and export |
---|
112 | #G = Geospatial_data(file_name = project.onshore_offshore_dem_name + '.pts') |
---|
113 | #G.export_points_file(project.combined_dem_name + '.pts') |
---|
114 | |
---|
115 | """ |
---|
116 | #---------------------------------------------------------------------------- |
---|
117 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
118 | # boundary and interior regions defined in project.py along with |
---|
119 | # resolutions (maximal area of per triangle) for each polygon |
---|
120 | #------------------------------------------------------------------------------- |
---|
121 | |
---|
122 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
123 | |
---|
124 | # use 75 for onshore components (12.5m DEM) |
---|
125 | # Resolution refers to max triangle area in a region |
---|
126 | #island_res = 35000 |
---|
127 | hobart_res = 7000 |
---|
128 | #peninsula_res = 35000 |
---|
129 | interior_regions = [[project.poly_hobart1, hobart_res], |
---|
130 | [project.poly_hobart2, hobart_res], |
---|
131 | [project.poly_hobart3, hobart_res]] |
---|
132 | |
---|
133 | print 'number of interior regions', len(interior_regions) |
---|
134 | |
---|
135 | |
---|
136 | # Number tags correspond to number segments from bounding polygon |
---|
137 | # maximum_triangle_area refers to max triangle area in a region |
---|
138 | # Interion_regions either comment out (perhaps empty list) |
---|
139 | from caching import cache |
---|
140 | _ = cache(create_mesh_from_regions, |
---|
141 | project.polyAll, |
---|
142 | {'boundary_tags': {'e0': [0], 'e1': [1], 'e2': [2], |
---|
143 | 'e3': [3], 'e4':[4], 'e5': [5], |
---|
144 | 'e6': [6], 'e7': [7], 'e8': [8], |
---|
145 | 'e9': [9], 'e10': [10], 'e11': [11], |
---|
146 | 'e12': [12], 'e13': [13], 'e14': [14], |
---|
147 | 'e15': [15]}, |
---|
148 | 'maximum_triangle_area': 2500000, |
---|
149 | 'filename': meshname}, |
---|
150 | #'interior_regions': interior_regions}, |
---|
151 | verbose = True, evaluate=False) |
---|
152 | |
---|
153 | |
---|
154 | #------------------------------------------------------------------------------- |
---|
155 | # Setup computational domain |
---|
156 | #------------------------------------------------------------------------------- |
---|
157 | domain = Domain(meshname, use_cache = True, verbose = True) |
---|
158 | |
---|
159 | print 'Number of triangles = ', len(domain) |
---|
160 | print 'The extent is ', domain.get_extent() |
---|
161 | print domain.statistics() |
---|
162 | |
---|
163 | domain.set_name(project.basename) |
---|
164 | domain.set_datadir(project.outputtimedir) |
---|
165 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
166 | domain.set_minimum_storable_height(0.01) |
---|
167 | domain.set_store_vertices_uniquely(False) # for writting to sww |
---|
168 | |
---|
169 | |
---|
170 | #------------------------------------------------------------------------------- |
---|
171 | # Setup initial conditions |
---|
172 | #------------------------------------------------------------------------------- |
---|
173 | |
---|
174 | tide = 0.0 |
---|
175 | domain.set_quantity('stage', tide) |
---|
176 | domain.set_quantity('friction', 0.0) |
---|
177 | |
---|
178 | #domain.set_quantity('elevation', |
---|
179 | # filename = project.combined_dem_name_2 + '.pts', |
---|
180 | # filename = onshore_offshore_dem_name + '.pts', |
---|
181 | # use_cache = True, |
---|
182 | # verbose = True, |
---|
183 | # alpha = 0.1 |
---|
184 | # ) |
---|
185 | |
---|
186 | |
---|
187 | #------------------------------------------------------------------------------- |
---|
188 | # Setup boundary conditions |
---|
189 | #------------------------------------------------------------------------------- |
---|
190 | print 'start ferret2sww' |
---|
191 | print '', project.boundary_basename |
---|
192 | from anuga.shallow_water.data_manager import ferret2sww |
---|
193 | |
---|
194 | south = project.south |
---|
195 | north = project.north |
---|
196 | west = project.west |
---|
197 | east = project.east |
---|
198 | |
---|
199 | #note only need to do when an SWW file for the MOST boundary doesn't exist |
---|
200 | cache(ferret2sww, |
---|
201 | (source_dir + project.boundary_basename, |
---|
202 | source_dir + project.boundary_basename), |
---|
203 | {'verbose': True, |
---|
204 | 'minlat': south, |
---|
205 | 'maxlat': north, |
---|
206 | 'minlon': west, |
---|
207 | 'maxlon': east, |
---|
208 | # 'origin': project.mesh_origin, |
---|
209 | 'origin': domain.geo_reference.get_origin(), |
---|
210 | 'mean_stage': tide, |
---|
211 | 'zscale': 1, #Enhance tsunami |
---|
212 | 'fail_on_NaN': False, |
---|
213 | 'inverted_bathymetry': True}, |
---|
214 | #evaluate = True, |
---|
215 | verbose = True, |
---|
216 | dependencies = source_dir + project.boundary_basename + '.sww') |
---|
217 | |
---|
218 | |
---|
219 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
220 | |
---|
221 | Bf = File_boundary(source_dir + project.boundary_basename + '.sww', |
---|
222 | domain, verbose = True) |
---|
223 | Br = Reflective_boundary(domain) |
---|
224 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
225 | |
---|
226 | |
---|
227 | # 7 min square wave starting at 1 min, 6m high |
---|
228 | Bw = Time_boundary(domain = domain, |
---|
229 | f=lambda t: [(60<t<480)*10, 0, 0]) |
---|
230 | |
---|
231 | domain.set_boundary( {'e0': Bd, 'e1': Bd, 'e2': Bd, 'e3': Bd, 'e4': Bd, |
---|
232 | 'e5': Bd, 'e6': Bd, 'e7': Bd, 'e8': Bd, 'e9': Bd, |
---|
233 | 'e10': Bd, 'e11': Bd, 'e12': Bf, 'e13': Bf, 'e14': Bf, |
---|
234 | 'e15': Bf} ) |
---|
235 | |
---|
236 | |
---|
237 | #------------------------------------------------------------------------------- |
---|
238 | # Evolve system through time |
---|
239 | #------------------------------------------------------------------------------- |
---|
240 | import time |
---|
241 | t0 = time.time() |
---|
242 | |
---|
243 | for t in domain.evolve(yieldstep = 240, finaltime = 6800): |
---|
244 | domain.write_time() |
---|
245 | domain.write_boundary_statistics(tags = 'e14') |
---|
246 | |
---|
247 | for t in domain.evolve(yieldstep = 30, finaltime = 9000 |
---|
248 | ,skip_initial_step = True): |
---|
249 | domain.write_time() |
---|
250 | domain.write_boundary_statistics(tags = 'e14') |
---|
251 | |
---|
252 | for t in domain.evolve(yieldstep = 240, finaltime = 15000 |
---|
253 | ,skip_initial_step = True): |
---|
254 | domain.write_time() |
---|
255 | domain.write_boundary_statistics(tags = 'e14') |
---|
256 | |
---|
257 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
258 | |
---|
259 | print 'finished' |
---|