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 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 | # Define scenario as either slump or fixed_wave. |
---|
37 | #------------------------------------------------------------------------------- |
---|
38 | scenario = 'slump' # 'fixedwave' |
---|
39 | mkdir (scenario) |
---|
40 | basename = scenario + project.basename |
---|
41 | |
---|
42 | #------------------------------------------------------------------------------- |
---|
43 | # Copy scripts to time stamped output directory and capture screen |
---|
44 | # output to file |
---|
45 | #------------------------------------------------------------------------------- |
---|
46 | |
---|
47 | # creates copy of code in output dir if dir doesn't exist |
---|
48 | if access(project.outputtimedir,F_OK) == 0 : |
---|
49 | mkdir (project.outputtimedir) |
---|
50 | copy (project.codedirname, project.outputtimedir + project.codename) |
---|
51 | copy (project.codedir + 'runcairns.py', project.outputtimedir + 'runcairns2.py') |
---|
52 | print'output dir', project.outputtimedir |
---|
53 | |
---|
54 | #normal screen output is stored in |
---|
55 | screen_output_name = project.outputtimedir + "screen_output.txt" |
---|
56 | screen_error_name = project.outputtimedir + "screen_error.txt" |
---|
57 | |
---|
58 | #used to catch screen output to file |
---|
59 | sys.stdout = Screen_Catcher(screen_output_name) |
---|
60 | sys.stderr = Screen_Catcher(screen_error_name) |
---|
61 | |
---|
62 | print 'USER: ', project.user |
---|
63 | |
---|
64 | #------------------------------------------------------------------------------- |
---|
65 | # Preparation of topographic data |
---|
66 | # |
---|
67 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
68 | #------------------------------------------------------------------------------- |
---|
69 | |
---|
70 | # filenames |
---|
71 | dem_name = project.dem_name |
---|
72 | meshname = project.meshname+'.msh' |
---|
73 | |
---|
74 | # creates DEM from asc data |
---|
75 | convert_dem_from_ascii2netcdf(dem_name, use_cache=True, verbose=True) |
---|
76 | |
---|
77 | #creates pts file for onshore DEM |
---|
78 | dem2pts(dem_name, use_cache=True, verbose=True) |
---|
79 | |
---|
80 | #---------------------------------------------------------------------------- |
---|
81 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
82 | # boundary and interior regions defined in project.py along with |
---|
83 | # resolutions (maximal area of per triangle) for each polygon |
---|
84 | #------------------------------------------------------------------------------- |
---|
85 | |
---|
86 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
87 | remainder_res = 10000000 |
---|
88 | islands_res = 100000 |
---|
89 | cairns_res = 100000 |
---|
90 | shallow_res = 500000 |
---|
91 | interior_regions = [[project.poly_cairns, cairns_res], |
---|
92 | [project.poly_island0, islands_res], |
---|
93 | [project.poly_island1, islands_res], |
---|
94 | [project.poly_island2, islands_res], |
---|
95 | [project.poly_island3, islands_res], |
---|
96 | [project.poly_shallow, shallow_res]] |
---|
97 | |
---|
98 | from caching import cache |
---|
99 | _ = cache(create_mesh_from_regions, |
---|
100 | project.polyAll, |
---|
101 | {'boundary_tags': {'top': [0], 'ocean_east': [1], |
---|
102 | 'bottom': [2], 'onshore': [3]}, |
---|
103 | 'maximum_triangle_area': remainder_res, |
---|
104 | 'filename': meshname, |
---|
105 | 'interior_regions': interior_regions}, |
---|
106 | verbose = True, evaluate=False) |
---|
107 | print 'created mesh' |
---|
108 | |
---|
109 | #------------------------------------------------------------------------------- |
---|
110 | # Setup computational domain |
---|
111 | #------------------------------------------------------------------------------- |
---|
112 | domain = Domain(meshname, use_cache = True, verbose = True) |
---|
113 | |
---|
114 | print 'Number of triangles = ', len(domain) |
---|
115 | print 'The extent is ', domain.get_extent() |
---|
116 | print domain.statistics() |
---|
117 | |
---|
118 | domain.set_name(basename) #domain.set_name(project.basename) |
---|
119 | domain.set_datadir(scenario) #domain.set_datadir(project.outputtimedir) |
---|
120 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
121 | domain.set_minimum_storable_height(0.01) |
---|
122 | |
---|
123 | #------------------------------------------------------------------------------- |
---|
124 | # Setup initial conditions |
---|
125 | #------------------------------------------------------------------------------- |
---|
126 | |
---|
127 | tide = 0.0 |
---|
128 | domain.set_quantity('stage', tide) |
---|
129 | domain.set_quantity('friction', 0.0) |
---|
130 | domain.set_quantity('elevation', |
---|
131 | filename = project.dem_name + '.pts', |
---|
132 | use_cache = True, |
---|
133 | verbose = True, |
---|
134 | alpha = 0.1 |
---|
135 | ) |
---|
136 | |
---|
137 | #------------------------------------------------------------------------------- |
---|
138 | # Setup information for slump scenario (to be applied 1 min into simulation |
---|
139 | #------------------------------------------------------------------------------- |
---|
140 | if scenario == 'slump': |
---|
141 | from anuga.shallow_water.smf import slump_tsunami # Function for submarine slump |
---|
142 | tsunami_source = slump_tsunami(length=15000.0, |
---|
143 | depth=project.slump_depth, |
---|
144 | slope=6.0, |
---|
145 | thickness=250.0, |
---|
146 | radius=3330, |
---|
147 | dphi=0.23, |
---|
148 | x0=project.slump_origin[0], |
---|
149 | y0=project.slump_origin[1], |
---|
150 | alpha=0.0, |
---|
151 | domain=domain, |
---|
152 | verbose=True) |
---|
153 | |
---|
154 | |
---|
155 | #------------------------------------------------------------------------------- |
---|
156 | # Setup boundary conditions |
---|
157 | #------------------------------------------------------------------------------- |
---|
158 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
159 | |
---|
160 | Br = Reflective_boundary(domain) |
---|
161 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
162 | |
---|
163 | # 7 min square wave starting at 1 min, 10m high |
---|
164 | if scenario == 'fixed_wave': |
---|
165 | Bw = Time_boundary(domain = domain, |
---|
166 | f=lambda t: [(60<t<480)*10, 0, 0]) |
---|
167 | domain.set_boundary( {'ocean_east': Bw, 'bottom': Bd, 'onshore': Bd, |
---|
168 | 'top': Bd} ) |
---|
169 | |
---|
170 | # boundary conditions for slump scenario |
---|
171 | if scenario == 'slump': |
---|
172 | domain.set_boundary( {'ocean_east': Bd, 'bottom': Bd, 'onshore': Bd, |
---|
173 | 'top': Bd} ) |
---|
174 | |
---|
175 | |
---|
176 | #------------------------------------------------------------------------------- |
---|
177 | # Evolve system through time |
---|
178 | #------------------------------------------------------------------------------- |
---|
179 | import time |
---|
180 | t0 = time.time() |
---|
181 | |
---|
182 | from Numeric import allclose |
---|
183 | from anuga.abstract_2d_finite_volumes.quantity import Quantity |
---|
184 | |
---|
185 | if scenario == 'slump': |
---|
186 | |
---|
187 | for t in domain.evolve(yieldstep = 30, finaltime = 60): |
---|
188 | domain.write_time() |
---|
189 | domain.write_boundary_statistics(tags = 'ocean_east') |
---|
190 | |
---|
191 | # add slump |
---|
192 | thisstagestep = domain.get_quantity('stage') |
---|
193 | if allclose(t, 60): |
---|
194 | slump = Quantity(domain) |
---|
195 | slump.set_values(tsunami_source) |
---|
196 | domain.set_quantity('stage', slump + thisstagestep) |
---|
197 | |
---|
198 | # save every two mins leading up to wave approaching land |
---|
199 | for t in domain.evolve(yieldstep = 120, finaltime = 1000, |
---|
200 | skip_initial_step = True): |
---|
201 | domain.write_time() |
---|
202 | domain.write_boundary_statistics(tags = 'ocean_east') |
---|
203 | |
---|
204 | # save every 30 secs as wave starts inundating ashore |
---|
205 | for t in domain.evolve(yieldstep = 30, finaltime = 10000, |
---|
206 | skip_initial_step = True): |
---|
207 | domain.write_time() |
---|
208 | domain.write_boundary_statistics(tags = 'ocean_east') |
---|
209 | |
---|
210 | if scenario == 'fixed_wave': |
---|
211 | |
---|
212 | # save every two mins leading up to wave approaching land |
---|
213 | for t in domain.evolve(yieldstep = 120, finaltime = 1000): |
---|
214 | domain.write_time() |
---|
215 | domain.write_boundary_statistics(tags = 'ocean_east') |
---|
216 | |
---|
217 | # save every 30 secs as wave starts inundating ashore |
---|
218 | for t in domain.evolve(yieldstep = 30, finaltime = 10000, |
---|
219 | skip_initial_step = True): |
---|
220 | domain.write_time() |
---|
221 | domain.write_boundary_statistics(tags = 'ocean_east') |
---|
222 | |
---|
223 | print 'That took %.2f seconds' %(time.time()-t0) |
---|