1 | |
---|
2 | """Script for running a tsunami inundation scenario for Cairns, QLD Australia. |
---|
3 | |
---|
4 | Source data such as elevation and boundary data is assumed to be available in |
---|
5 | directories specified by project.py |
---|
6 | The output sww file is stored in directory named after the scenario, i.e |
---|
7 | slide or fixed_wave. |
---|
8 | |
---|
9 | The scenario is defined by a triangular mesh created from project.polygon, |
---|
10 | the elevation data and a tsunami wave generated by a submarine mass failure. |
---|
11 | |
---|
12 | Ole Nielsen and Duncan Gray, GA - 2005 and Jane Sexton and |
---|
13 | Nick Bartzis, GA - 2006 |
---|
14 | """ |
---|
15 | |
---|
16 | #------------------------------------------------------------------------------ |
---|
17 | # Import necessary modules |
---|
18 | #------------------------------------------------------------------------------ |
---|
19 | |
---|
20 | # Standard modules |
---|
21 | import os |
---|
22 | import time |
---|
23 | import sys |
---|
24 | |
---|
25 | # Related major packages |
---|
26 | from anuga.shallow_water import Domain |
---|
27 | from anuga.shallow_water import Reflective_boundary |
---|
28 | from anuga.shallow_water import Dirichlet_boundary |
---|
29 | from anuga.shallow_water import Time_boundary |
---|
30 | from anuga.shallow_water import File_boundary |
---|
31 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
32 | from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf |
---|
33 | from anuga.shallow_water.data_manager import dem2pts |
---|
34 | from anuga.fit_interpolate.search_functions import search_times, \ |
---|
35 | reset_search_times |
---|
36 | from anuga.fit_interpolate.general_fit_interpolate import \ |
---|
37 | get_build_quadtree_time |
---|
38 | |
---|
39 | # Application specific imports |
---|
40 | import project # Definition of file names and polygons |
---|
41 | |
---|
42 | |
---|
43 | #------------------------------------------------------------------------------ |
---|
44 | # Define scenario as either slide or fixed_wave. |
---|
45 | #------------------------------------------------------------------------------ |
---|
46 | scenario = 'slide' |
---|
47 | #scenario = 'fixed_wave' |
---|
48 | |
---|
49 | if os.access(scenario, os.F_OK) == 0: |
---|
50 | os.mkdir(scenario) |
---|
51 | basename = scenario + 'source' |
---|
52 | |
---|
53 | |
---|
54 | #------------------------------------------------------------------------------ |
---|
55 | # Preparation of topographic data |
---|
56 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
57 | #------------------------------------------------------------------------------ |
---|
58 | |
---|
59 | # Filenames |
---|
60 | dem_name = 'cairns' |
---|
61 | meshname = 'cairns.msh' |
---|
62 | |
---|
63 | # Create DEM from asc data |
---|
64 | convert_dem_from_ascii2netcdf(dem_name, use_cache=True, verbose=True) |
---|
65 | |
---|
66 | # Create pts file for onshore DEM |
---|
67 | dem2pts(dem_name, use_cache=True, verbose=True) |
---|
68 | |
---|
69 | |
---|
70 | #------------------------------------------------------------------------------ |
---|
71 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
72 | # boundary and interior regions defined in project.py along with |
---|
73 | # resolutions (maximal area of per triangle) for each polygon |
---|
74 | #------------------------------------------------------------------------------ |
---|
75 | |
---|
76 | remainder_res = 10000000 |
---|
77 | islands_res = 100000 |
---|
78 | cairns_res = 100000 |
---|
79 | shallow_res = 500000 |
---|
80 | interior_regions = [[project.poly_cairns, cairns_res], |
---|
81 | [project.poly_island0, islands_res], |
---|
82 | [project.poly_island1, islands_res], |
---|
83 | [project.poly_island2, islands_res], |
---|
84 | [project.poly_island3, islands_res], |
---|
85 | [project.poly_shallow, shallow_res]] |
---|
86 | |
---|
87 | create_mesh_from_regions(project.bounding_polygon, |
---|
88 | boundary_tags={'top': [0], |
---|
89 | 'ocean_east': [1], |
---|
90 | 'bottom': [2], |
---|
91 | 'onshore': [3]}, |
---|
92 | maximum_triangle_area=remainder_res, |
---|
93 | filename=meshname, |
---|
94 | interior_regions=interior_regions, |
---|
95 | use_cache=True, |
---|
96 | verbose=True) |
---|
97 | |
---|
98 | |
---|
99 | #------------------------------------------------------------------------------ |
---|
100 | # Setup computational domain |
---|
101 | #------------------------------------------------------------------------------ |
---|
102 | |
---|
103 | from anuga.abstract_2d_finite_volumes.pmesh2domain import pmesh_to_domain_instance |
---|
104 | from anuga.caching import cache |
---|
105 | |
---|
106 | ##domain = cache(Domain(meshname, use_cache=True, verbose=True) |
---|
107 | |
---|
108 | domain = cache(pmesh_to_domain_instance, |
---|
109 | (meshname, Domain), |
---|
110 | dependencies = [meshname]) |
---|
111 | |
---|
112 | print 'Number of triangles = ', len(domain) |
---|
113 | print 'The extent is ', domain.get_extent() |
---|
114 | print domain.statistics() |
---|
115 | |
---|
116 | domain.set_name(basename) |
---|
117 | domain.set_datadir(scenario) |
---|
118 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
119 | domain.set_minimum_storable_height(0.01) |
---|
120 | |
---|
121 | #print 'domain.tight_slope_limiters', domain.tight_slope_limiters |
---|
122 | domain.tight_slope_limiters = 0 |
---|
123 | print 'domain.tight_slope_limiters', domain.tight_slope_limiters |
---|
124 | |
---|
125 | |
---|
126 | |
---|
127 | domain.points_file_block_line_size = 50000 |
---|
128 | |
---|
129 | #------------------------------------------------------------------------------ |
---|
130 | # Setup initial conditions |
---|
131 | #------------------------------------------------------------------------------ |
---|
132 | |
---|
133 | tide = 0.0 |
---|
134 | domain.set_quantity('stage', tide) |
---|
135 | domain.set_quantity('friction', 0.0) |
---|
136 | |
---|
137 | |
---|
138 | t0 = time.time() |
---|
139 | domain.set_quantity('elevation', |
---|
140 | filename=dem_name + '.pts', |
---|
141 | use_cache=False, |
---|
142 | verbose=True, |
---|
143 | alpha=0.1) |
---|
144 | |
---|
145 | print 'Fitting the elevation data took %.2f seconds' %(time.time()-t0) |
---|
146 | |
---|
147 | search_one_cell_time, search_more_cells_time = search_times() |
---|
148 | reset_search_times() |
---|
149 | print "search_one_cell_time",search_one_cell_time |
---|
150 | print "search_more_cells_time", search_more_cells_time |
---|
151 | print "build_quadtree_time", get_build_quadtree_time() |
---|
152 | import sys; sys.exit() |
---|
153 | #------------------------------------------------------------------------------ |
---|
154 | # Setup information for slide scenario (to be applied 1 min into simulation |
---|
155 | #------------------------------------------------------------------------------ |
---|
156 | |
---|
157 | if scenario == 'slide': |
---|
158 | # Function for submarine slide |
---|
159 | from anuga.shallow_water.smf import slide_tsunami |
---|
160 | tsunami_source = slide_tsunami(length=35000.0, |
---|
161 | depth=project.slide_depth, |
---|
162 | slope=6.0, |
---|
163 | thickness=500.0, |
---|
164 | x0=project.slide_origin[0], |
---|
165 | y0=project.slide_origin[1], |
---|
166 | alpha=0.0, |
---|
167 | domain=domain, |
---|
168 | verbose=True) |
---|
169 | |
---|
170 | |
---|
171 | #------------------------------------------------------------------------------ |
---|
172 | # Setup boundary conditions |
---|
173 | #------------------------------------------------------------------------------ |
---|
174 | |
---|
175 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
176 | |
---|
177 | Br = Reflective_boundary(domain) |
---|
178 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
179 | |
---|
180 | # 60 min square wave starting at 1 min, 50m high |
---|
181 | if scenario == 'fixed_wave': |
---|
182 | Bw = Transmissive_Momentum_Set_Stage_boundary(domain = domain, |
---|
183 | f=lambda t: [(60<t<3660)*50, 0, 0]) |
---|
184 | domain.set_boundary({'ocean_east': Bw, |
---|
185 | 'bottom': Bd, |
---|
186 | 'onshore': Bd, |
---|
187 | 'top': Bd}) |
---|
188 | |
---|
189 | # boundary conditions for slide scenario |
---|
190 | if scenario == 'slide': |
---|
191 | domain.set_boundary({'ocean_east': Bd, |
---|
192 | 'bottom': Bd, |
---|
193 | 'onshore': Bd, |
---|
194 | 'top': Bd}) |
---|
195 | |
---|
196 | |
---|
197 | #------------------------------------------------------------------------------ |
---|
198 | # Evolve system through time |
---|
199 | #------------------------------------------------------------------------------ |
---|
200 | |
---|
201 | t0 = time.time() |
---|
202 | |
---|
203 | from Numeric import allclose |
---|
204 | from anuga.abstract_2d_finite_volumes.quantity import Quantity |
---|
205 | |
---|
206 | if scenario == 'slide': |
---|
207 | |
---|
208 | for t in domain.evolve(yieldstep = 10, finaltime = 60): |
---|
209 | domain.write_time() |
---|
210 | domain.write_boundary_statistics(tags = 'ocean_east') |
---|
211 | |
---|
212 | # add slide |
---|
213 | thisstagestep = domain.get_quantity('stage') |
---|
214 | if allclose(t, 60): |
---|
215 | slide = Quantity(domain) |
---|
216 | slide.set_values(tsunami_source) |
---|
217 | domain.set_quantity('stage', slide + thisstagestep) |
---|
218 | |
---|
219 | for t in domain.evolve(yieldstep = 10, finaltime = 5000, |
---|
220 | skip_initial_step = True): |
---|
221 | domain.write_time() |
---|
222 | domain.write_boundary_statistics(tags = 'ocean_east') |
---|
223 | |
---|
224 | if scenario == 'fixed_wave': |
---|
225 | |
---|
226 | # save every two mins leading up to wave approaching land |
---|
227 | for t in domain.evolve(yieldstep = 120, finaltime = 5000): |
---|
228 | domain.write_time() |
---|
229 | domain.write_boundary_statistics(tags = 'ocean_east') |
---|
230 | |
---|
231 | # save every 30 secs as wave starts inundating ashore |
---|
232 | for t in domain.evolve(yieldstep = 10, finaltime = 10000, |
---|
233 | skip_initial_step = True): |
---|
234 | domain.write_time() |
---|
235 | domain.write_boundary_statistics(tags = 'ocean_east') |
---|
236 | |
---|
237 | print 'That took %.2f seconds' %(time.time()-t0) |
---|