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.outputdir |
---|
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 | |
---|
21 | # Related major packages |
---|
22 | from anuga.pyvolution.shallow_water import Domain, Reflective_boundary, \ |
---|
23 | Dirichlet_boundary, Time_boundary, File_boundary |
---|
24 | from anuga.pyvolution.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
25 | from anuga.pyvolution.combine_pts import combine_rectangular_points_files |
---|
26 | from anuga.pyvolution.pmesh2domain import pmesh_to_domain_instance |
---|
27 | from anuga.fit_interpolate.fit import fit_to_mesh_file |
---|
28 | |
---|
29 | # Application specific imports |
---|
30 | import project # Definition of file names and polygons |
---|
31 | from smf import slump_tsunami # Function for submarine mudslide |
---|
32 | |
---|
33 | from shutil import copy |
---|
34 | from os import mkdir, access, F_OK |
---|
35 | |
---|
36 | from anuga.geospatial_data.geospatial_data import * |
---|
37 | |
---|
38 | #------------------------------------------------------------------------------- |
---|
39 | # Preparation of topographic data |
---|
40 | # |
---|
41 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
42 | # Do for coarse and fine data |
---|
43 | # Fine pts file to be clipped to area of interest |
---|
44 | #------------------------------------------------------------------------------- |
---|
45 | |
---|
46 | # filenames |
---|
47 | coarsedemname = project.coarsedemname |
---|
48 | |
---|
49 | onshore_dem_name = project.onshore_dem_name |
---|
50 | |
---|
51 | offshore_points = project.offshore_dem_name |
---|
52 | |
---|
53 | meshname = project.meshname+'.msh' |
---|
54 | |
---|
55 | source_dir = project.boundarydir |
---|
56 | |
---|
57 | # creates copy of code in output dir |
---|
58 | if access(project.outputdir,F_OK) == 0 : |
---|
59 | mkdir (project.outputdir) |
---|
60 | copy (project.codedirname, project.outputdir + project.codename) |
---|
61 | copy (project.codedir + 'run_onslow.py', project.outputdir + 'run_onslow.py') |
---|
62 | |
---|
63 | |
---|
64 | ''' |
---|
65 | # coarse data |
---|
66 | convert_dem_from_ascii2netcdf(coarsedemname, use_cache=True, verbose=True) |
---|
67 | dem2pts(coarsedemname, use_cache=True, verbose=True) |
---|
68 | |
---|
69 | |
---|
70 | # fine data (clipping the points file to smaller area) |
---|
71 | convert_dem_from_ascii2netcdf(onshore_dem_name, use_cache=True, verbose=True) |
---|
72 | dem2pts(onshore_dem_name, |
---|
73 | easting_min=project.eastingmin, |
---|
74 | easting_max=project.eastingmax, |
---|
75 | northing_min=project.northingmin, |
---|
76 | northing_max= project.northingmax, |
---|
77 | use_cache=True, |
---|
78 | verbose=True) |
---|
79 | |
---|
80 | ''' |
---|
81 | print'create G1' |
---|
82 | G1 = Geospatial_data(file_name = project.offshore_dem_name + '.xya') |
---|
83 | |
---|
84 | print'create G2' |
---|
85 | G2 = Geospatial_data(file_name = project.onshore_dem_name + '.pts') |
---|
86 | |
---|
87 | print'add G1+G2' |
---|
88 | G = G1 + G2 |
---|
89 | |
---|
90 | print'export G' |
---|
91 | G.export_points_file(project.combined_dem_name + '.pts') |
---|
92 | |
---|
93 | |
---|
94 | #------------------------------------------------------------------------------- |
---|
95 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
96 | # boundary and interior regions defined in project.py along with |
---|
97 | # resolutions (maximal area of per triangle) for each polygon |
---|
98 | #------------------------------------------------------------------------------- |
---|
99 | |
---|
100 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
101 | |
---|
102 | # original |
---|
103 | interior_res = 1000000 |
---|
104 | |
---|
105 | from caching import cache |
---|
106 | _ = cache(create_mesh_from_regions, |
---|
107 | project.polyAll, |
---|
108 | {'boundary_tags': {'top': [0], 'topleft': [1], |
---|
109 | 'left': [2], 'bottom': [3], |
---|
110 | 'bottomright': [4], 'topright': [5]}, |
---|
111 | 'maximum_triangle_area': 10000000, |
---|
112 | 'filename': meshname}, |
---|
113 | verbose = True) |
---|
114 | |
---|
115 | mesh_elevname = meshname[:-4] + '_elv' + meshname[-4:] |
---|
116 | |
---|
117 | cache(fit_to_mesh_file,(meshname, |
---|
118 | project.combined_dem_name + '.pts', |
---|
119 | mesh_elevname), |
---|
120 | {'verbose': True} |
---|
121 | #,evaluate = True |
---|
122 | ,verbose = False |
---|
123 | ) |
---|
124 | |
---|
125 | #------------------------------------------------------------------------------- |
---|
126 | # Setup computational domain |
---|
127 | #------------------------------------------------------------------------------- |
---|
128 | |
---|
129 | domain = pmesh_to_domain_instance(mesh_elevname, Domain, |
---|
130 | use_cache = True, |
---|
131 | verbose = True) |
---|
132 | |
---|
133 | print 'Number of triangles = ', len(domain) |
---|
134 | print 'The extent is ', domain.get_extent() |
---|
135 | print domain.statistics() |
---|
136 | |
---|
137 | domain.set_name(project.basename) |
---|
138 | domain.set_datadir(project.outputdir) |
---|
139 | domain.set_quantities_to_be_stored(['stage']) |
---|
140 | |
---|
141 | |
---|
142 | #------------------------------------------------------------------------------- |
---|
143 | # Setup initial conditions |
---|
144 | #------------------------------------------------------------------------------- |
---|
145 | |
---|
146 | tide = 0. |
---|
147 | |
---|
148 | domain.set_quantity('stage', tide) |
---|
149 | domain.set_quantity('friction', 0.0) |
---|
150 | print 'hi and file',project.combined_dem_name + '.pts' |
---|
151 | #domain.set_quantity('elevation', |
---|
152 | # 0. |
---|
153 | # filename = project.onshore_dem_name + '.pts', |
---|
154 | # filename = project.combined_dem_name + '.pts', |
---|
155 | # filename = project.offshore_dem_name + '.pts', |
---|
156 | # use_cache = False, |
---|
157 | # verbose = True, |
---|
158 | # alpha = 0.1 |
---|
159 | # ) |
---|
160 | print 'hi1' |
---|
161 | |
---|
162 | #------------------------------------------------------------------------------- |
---|
163 | # Setup boundary conditions (all reflective) |
---|
164 | #------------------------------------------------------------------------------- |
---|
165 | |
---|
166 | from anuga.pyvolution.data_manager import ferret2sww |
---|
167 | |
---|
168 | south = project.south |
---|
169 | north = project.north |
---|
170 | west = project.west |
---|
171 | east = project.east |
---|
172 | |
---|
173 | cache(ferret2sww, |
---|
174 | (source_dir + project.boundary_basename, |
---|
175 | source_dir + project.boundary_basename), |
---|
176 | {'verbose': True, |
---|
177 | 'minlat': south, |
---|
178 | 'maxlat': north, |
---|
179 | 'minlon': west, |
---|
180 | 'maxlon': east, |
---|
181 | 'origin': domain.geo_reference.get_origin(), |
---|
182 | 'mean_stage': tide, |
---|
183 | 'zscale': 1, #Enhance tsunami |
---|
184 | 'fail_on_NaN': False, |
---|
185 | 'inverted_bathymetry': True}, |
---|
186 | #evaluate = True, |
---|
187 | verbose = True) |
---|
188 | |
---|
189 | |
---|
190 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
191 | |
---|
192 | Bf = File_boundary(source_dir + project.boundary_basename + '.sww', |
---|
193 | domain, verbose = True) |
---|
194 | Br = Reflective_boundary(domain) |
---|
195 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
196 | |
---|
197 | |
---|
198 | # 7 min square wave starting at 1 min, 6m high |
---|
199 | Bw = Time_boundary(domain = domain, |
---|
200 | f=lambda t: [(60<t<480)*6, 0, 0]) |
---|
201 | |
---|
202 | domain.set_boundary( {'top': Bf, 'topleft': Bf, |
---|
203 | 'left': Br, 'bottom': Br, |
---|
204 | 'bottomright': Br, 'topright': Bf} ) |
---|
205 | |
---|
206 | |
---|
207 | #------------------------------------------------------------------------------- |
---|
208 | # Evolve system through time |
---|
209 | #------------------------------------------------------------------------------- |
---|
210 | import time |
---|
211 | t0 = time.time() |
---|
212 | |
---|
213 | for t in domain.evolve(yieldstep = 50, finaltime = 100): |
---|
214 | domain.write_time() |
---|
215 | domain.write_boundary_statistics(tags = 'top') |
---|
216 | |
---|
217 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
218 | |
---|
219 | print 'finished' |
---|