1 | """Script for running a tsunami inundation scenario for Broome, 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 tsunami wave generated by MOST. |
---|
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.path import dirname, basename |
---|
22 | from os import mkdir, access, F_OK, sep |
---|
23 | import sys |
---|
24 | |
---|
25 | # Related major packages |
---|
26 | from anuga.shallow_water import Domain, Reflective_boundary, \ |
---|
27 | Dirichlet_boundary, Time_boundary, File_boundary |
---|
28 | from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
29 | from anuga.abstract_2d_finite_volumes.combine_pts import combine_rectangular_points_files |
---|
30 | from anuga.geospatial_data.geospatial_data import * |
---|
31 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files |
---|
32 | |
---|
33 | # Application specific imports |
---|
34 | import project # Definition of file names and polygons |
---|
35 | |
---|
36 | #------------------------------------------------------------------------------- |
---|
37 | # Copy scripts to time stamped output directory and capture screen |
---|
38 | # output to file |
---|
39 | #------------------------------------------------------------------------------- |
---|
40 | |
---|
41 | # creates copy of code in output dir |
---|
42 | copy_code_files(project.outputtimedir,__file__,dirname(project.__file__)+sep+ project.__name__+'.py' ) |
---|
43 | myid = 0 |
---|
44 | numprocs = 1 |
---|
45 | start_screen_catcher(project.outputtimedir, myid, numprocs) |
---|
46 | |
---|
47 | print 'USER: ', project.user |
---|
48 | |
---|
49 | #------------------------------------------------------------------------------- |
---|
50 | # Preparation of topographic data |
---|
51 | # |
---|
52 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
53 | #------------------------------------------------------------------------------- |
---|
54 | |
---|
55 | # filenames |
---|
56 | onshore_dem_name = project.onshore_dem_name |
---|
57 | offshore_interp_dem_name = project.offshore_interp_dem_name |
---|
58 | coast_points = project.coast_dem_name |
---|
59 | meshname = project.meshname+'.msh' |
---|
60 | |
---|
61 | # creates DEM from asc data |
---|
62 | convert_dem_from_ascii2netcdf(onshore_dem_name, use_cache=True, verbose=True) |
---|
63 | |
---|
64 | #creates pts file for onshore DEM |
---|
65 | dem2pts(onshore_dem_name, use_cache=True, verbose=True) |
---|
66 | |
---|
67 | # creates DEM from asc data |
---|
68 | convert_dem_from_ascii2netcdf(offshore_interp_dem_name, use_cache=True, verbose=True) |
---|
69 | |
---|
70 | #creates pts file for offshore interpolated DEM |
---|
71 | dem2pts(offshore_interp_dem_name, use_cache=True, verbose=True) |
---|
72 | |
---|
73 | print 'create offshore' |
---|
74 | G1 = Geospatial_data(file_name = project.offshore_dem_name1 + '.xya')+\ |
---|
75 | Geospatial_data(file_name = project.offshore_dem_name2 + '.xya')+\ |
---|
76 | Geospatial_data(file_name = project.offshore_dem_name3 + '.xya')+\ |
---|
77 | Geospatial_data(file_name = project.offshore_dem_name4 + '.xya')+\ |
---|
78 | Geospatial_data(file_name = project.offshore_dem_name5 + '.xya')+\ |
---|
79 | Geospatial_data(file_name = project.offshore_dem_name6 + '.xya')+\ |
---|
80 | Geospatial_data(file_name = project.offshore_dem_name7 + '.xya')+\ |
---|
81 | Geospatial_data(file_name = project.offshore_dem_name8 + '.xya')+\ |
---|
82 | Geospatial_data(file_name = project.offshore_dem_name9 + '.xya')+\ |
---|
83 | Geospatial_data(file_name = project.offshore_dem_name10 + '.xya')+\ |
---|
84 | Geospatial_data(file_name = project.offshore_dem_name11 + '.xya')+\ |
---|
85 | Geospatial_data(file_name = project.offshore_dem_name12 + '.xya')+\ |
---|
86 | Geospatial_data(file_name = project.offshore_dem_name13 + '.xya')+\ |
---|
87 | Geospatial_data(file_name = project.offshore_dem_name14 + '.xya')+\ |
---|
88 | Geospatial_data(file_name = project.offshore_dem_name15 + '.xya')+\ |
---|
89 | Geospatial_data(file_name = project.offshore_dem_name16 + '.xya')+\ |
---|
90 | Geospatial_data(file_name = project.offshore_dem_name17 + '.xya')+\ |
---|
91 | Geospatial_data(file_name = project.offshore_dem_name18 + '.xya')+\ |
---|
92 | Geospatial_data(file_name = project.offshore_dem_name19 + '.xya')+\ |
---|
93 | Geospatial_data(file_name = project.offshore_dem_name20 + '.xya')+\ |
---|
94 | Geospatial_data(file_name = project.offshore_dem_name21 + '.xya')+\ |
---|
95 | Geospatial_data(file_name = project.offshore_dem_name22 + '.xya')+\ |
---|
96 | Geospatial_data(file_name = project.offshore_interp_dem_name + '.pts') |
---|
97 | print 'create onshore' |
---|
98 | G2 = Geospatial_data(file_name = project.onshore_dem_name + '.pts') |
---|
99 | print 'create coast' |
---|
100 | G3 = Geospatial_data(file_name = project.coast_dem_name + '.xya') |
---|
101 | print 'add' |
---|
102 | G = G1 + G2 + G3 |
---|
103 | print 'export points' |
---|
104 | G.export_points_file(project.combined_dem_name + '.pts') |
---|
105 | G.export_points_file(project.combined_dem_name + '.xya') |
---|
106 | #---------------------------------------------------------------------------- |
---|
107 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
108 | # boundary and interior regions defined in project.py along with |
---|
109 | # resolutions (maximal area of per triangle) for each polygon |
---|
110 | #------------------------------------------------------------------------------- |
---|
111 | |
---|
112 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
113 | remainder_res = 500000 |
---|
114 | local_res = 25000 |
---|
115 | broome_res = 5000 |
---|
116 | coast_res = 500 |
---|
117 | interior_regions = [[project.poly_broome1, local_res], |
---|
118 | [project.poly_broome2, broome_res], |
---|
119 | [project.poly_broome3, coast_res]] |
---|
120 | |
---|
121 | from project import number_mesh_triangles |
---|
122 | print 'estimate of number of triangles', \ |
---|
123 | number_mesh_triangles(interior_regions, project.polyAll, remainder_res) |
---|
124 | |
---|
125 | from caching import cache |
---|
126 | _ = cache(create_mesh_from_regions, |
---|
127 | project.polyAll, |
---|
128 | {'boundary_tags': {'e0': [0], 'e1': [1], 'e2': [2], |
---|
129 | 'e3': [3], 'e4':[4], 'e5': [5], |
---|
130 | 'e6': [6]}, |
---|
131 | 'maximum_triangle_area': remainder_res, |
---|
132 | 'filename': meshname, |
---|
133 | 'interior_regions': interior_regions}, |
---|
134 | verbose = True, evaluate=False) |
---|
135 | print 'created mesh' |
---|
136 | |
---|
137 | #------------------------------------------------------------------------------- |
---|
138 | # Setup computational domain |
---|
139 | #------------------------------------------------------------------------------- |
---|
140 | domain = Domain(meshname, use_cache = True, verbose = True) |
---|
141 | |
---|
142 | print 'Number of triangles = ', len(domain) |
---|
143 | print 'The extent is ', domain.get_extent() |
---|
144 | print domain.statistics() |
---|
145 | |
---|
146 | domain.set_name(project.basename) |
---|
147 | domain.set_datadir(project.outputtimedir) |
---|
148 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
149 | domain.set_minimum_storable_height(0.01) |
---|
150 | |
---|
151 | #------------------------------------------------------------------------------- |
---|
152 | # Setup initial conditions |
---|
153 | #------------------------------------------------------------------------------- |
---|
154 | |
---|
155 | tide = 0.0 |
---|
156 | domain.set_quantity('stage', tide) |
---|
157 | domain.set_quantity('friction', 0.0) |
---|
158 | domain.set_quantity('elevation', |
---|
159 | filename = project.combined_dem_name + '.pts', |
---|
160 | use_cache = True, |
---|
161 | verbose = True, |
---|
162 | alpha = 0.1 |
---|
163 | ) |
---|
164 | |
---|
165 | #------------------------------------------------------------------------------- |
---|
166 | # Setup boundary conditions |
---|
167 | #------------------------------------------------------------------------------- |
---|
168 | ''' |
---|
169 | print 'start urs2sww' |
---|
170 | print '', project.boundary_basename |
---|
171 | from anuga.shallow_water.data_manager import urs2sww |
---|
172 | |
---|
173 | south = project.south |
---|
174 | north = project.north |
---|
175 | west = project.west |
---|
176 | east = project.east |
---|
177 | |
---|
178 | #note only need to do when an SWW file for the MOST boundary doesn't exist |
---|
179 | cache(urs2sww, |
---|
180 | (source_dir + project.boundary_basename, |
---|
181 | source_dir + project.boundary_basename), |
---|
182 | {'verbose': True, |
---|
183 | 'minlat': south, |
---|
184 | 'maxlat': north, |
---|
185 | 'minlon': west, |
---|
186 | 'maxlon': east, |
---|
187 | #'origin': domain.geo_reference.get_origin(), |
---|
188 | 'mean_stage': tide, |
---|
189 | 'zscale': 1, #Enhance tsunami |
---|
190 | 'fail_on_NaN': False, |
---|
191 | 'inverted_bathymetry': True}, |
---|
192 | #evaluate = True, |
---|
193 | verbose = True, |
---|
194 | dependencies = source_dir + project.boundary_basename + '.sww') |
---|
195 | |
---|
196 | ''' |
---|
197 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
198 | |
---|
199 | #Bf = File_boundary(source_dir + project.boundary_basename + '.sww', |
---|
200 | # domain, verbose = True) |
---|
201 | Br = Reflective_boundary(domain) |
---|
202 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
203 | |
---|
204 | # 7 min square wave starting at 1 min, 6m high |
---|
205 | Bw = Time_boundary(domain = domain, |
---|
206 | f=lambda t: [(60<t<480)*10, 0, 0]) |
---|
207 | |
---|
208 | domain.set_boundary( {'e0': Bd, 'e1': Bd, 'e2': Bd, 'e3': Bd, 'e4': Bd, |
---|
209 | 'e5': Bd, 'e6': Bd} ) |
---|
210 | |
---|
211 | |
---|
212 | #------------------------------------------------------------------------------- |
---|
213 | # Evolve system through time |
---|
214 | #------------------------------------------------------------------------------- |
---|
215 | import time |
---|
216 | t0 = time.time() |
---|
217 | |
---|
218 | for t in domain.evolve(yieldstep = 240, finaltime = 480): |
---|
219 | domain.write_time() |
---|
220 | domain.write_boundary_statistics(tags = 'e14') |
---|
221 | |
---|
222 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
223 | |
---|
224 | print 'finished' |
---|