1 | """Script for running a tsunami inundation scenario for Wollongong, NSW, 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 s submarine mass failure. |
---|
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, Dirichlet_boundary |
---|
27 | from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
28 | from anuga.geospatial_data.geospatial_data import * |
---|
29 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files |
---|
30 | |
---|
31 | # Application specific imports |
---|
32 | import project_slide # 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 |
---|
40 | copy_code_files(project.outputtimedir,__file__,dirname(project.__file__)+sep+ project.__name__+'.py' ) |
---|
41 | myid = 0 |
---|
42 | numprocs = 1 |
---|
43 | start_screen_catcher(project.outputtimedir, myid, numprocs) |
---|
44 | |
---|
45 | print 'USER: ', project.user |
---|
46 | |
---|
47 | #------------------------------------------------------------------------------- |
---|
48 | # Preparation of topographic data |
---|
49 | # |
---|
50 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
51 | #------------------------------------------------------------------------------- |
---|
52 | |
---|
53 | # filenames |
---|
54 | on_offshore_dem_name = project.on_offshore_dem_name |
---|
55 | meshname = project.meshname+'.msh' |
---|
56 | |
---|
57 | # creates DEM from asc data |
---|
58 | convert_dem_from_ascii2netcdf(on_offshore_dem_name, use_cache=True, verbose=True) |
---|
59 | |
---|
60 | #creates pts file for onshore DEM |
---|
61 | dem2pts(on_offshore_dem_name, use_cache=True, verbose=True) |
---|
62 | |
---|
63 | print 'create offshore' |
---|
64 | G1 = Geospatial_data(file_name = project.offshore_dem_name1 + '.xya')+\ |
---|
65 | Geospatial_data(file_name = project.offshore_dem_name2 + '.xya')+\ |
---|
66 | Geospatial_data(file_name = project.offshore_dem_name3 + '.xya')+\ |
---|
67 | Geospatial_data(file_name = project.offshore_dem_name4 + '.xya')+\ |
---|
68 | Geospatial_data(file_name = project.offshore_dem_name5 + '.xya')+\ |
---|
69 | Geospatial_data(file_name = project.offshore_dem_name6 + '.xya')+\ |
---|
70 | Geospatial_data(file_name = project.offshore_dem_name7 + '.xya')+\ |
---|
71 | Geospatial_data(file_name = project.offshore_dem_name8 + '.xya')+\ |
---|
72 | Geospatial_data(file_name = project.offshore_dem_name9 + '.xya')+\ |
---|
73 | Geospatial_data(file_name = project.offshore_dem_name10 + '.xya')+\ |
---|
74 | Geospatial_data(file_name = project.offshore_dem_name11 + '.xya')+\ |
---|
75 | Geospatial_data(file_name = project.offshore_dem_name12 + '.xya')+\ |
---|
76 | Geospatial_data(file_name = project.offshore_dem_name13 + '.xya')+\ |
---|
77 | Geospatial_data(file_name = project.offshore_dem_name14 + '.xya')+\ |
---|
78 | Geospatial_data(file_name = project.offshore_dem_name15 + '.xya')+\ |
---|
79 | Geospatial_data(file_name = project.offshore_dem_name16 + '.xya')+\ |
---|
80 | Geospatial_data(file_name = project.offshore_dem_name17 + '.xya')+\ |
---|
81 | Geospatial_data(file_name = project.offshore_dem_name18 + '.xya')+\ |
---|
82 | Geospatial_data(file_name = project.offshore_dem_name19 + '.xya')+\ |
---|
83 | Geospatial_data(file_name = project.offshore_dem_name20 + '.xya')+\ |
---|
84 | Geospatial_data(file_name = project.offshore_dem_name21 + '.xya')+\ |
---|
85 | Geospatial_data(file_name = project.offshore_dem_name22 + '.xya')+\ |
---|
86 | Geospatial_data(file_name = project.offshore_interp_dem_name + '.pts') |
---|
87 | print 'create onshore' |
---|
88 | G2 = Geospatial_data(file_name = project.on_offshore_dem_name + '.pts') |
---|
89 | print 'add' |
---|
90 | G = G1 + G2 + G3 |
---|
91 | print 'export points' |
---|
92 | G.export_points_file(project.combined_dem_name + '.pts') |
---|
93 | G.export_points_file(project.combined_dem_name + '.xya') |
---|
94 | |
---|
95 | #---------------------------------------------------------------------------- |
---|
96 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
97 | # boundary and interior regions defined in project.py along with |
---|
98 | # resolutions (maximal area of per triangle) for each polygon |
---|
99 | #------------------------------------------------------------------------------- |
---|
100 | |
---|
101 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
102 | remainder_res = 500000 |
---|
103 | local_res = 25000 |
---|
104 | gong_res = 5000 |
---|
105 | coast_res = 500 |
---|
106 | interior_regions = [[project.poly_gong1, local_res], |
---|
107 | [project.poly_gong2, gong_res], |
---|
108 | [project.poly_gong3, coast_res]] |
---|
109 | |
---|
110 | from caching import cache |
---|
111 | _ = cache(create_mesh_from_regions, |
---|
112 | project.polyAll, |
---|
113 | {'boundary_tags': {'e0': [0], 'e1': [1], 'e2': [2], |
---|
114 | 'e3': [3], 'e4':[4], 'e5': [5], |
---|
115 | 'e6': [6]}, |
---|
116 | 'maximum_triangle_area': remainder_res, |
---|
117 | 'filename': meshname, |
---|
118 | 'interior_regions': interior_regions}, |
---|
119 | verbose = True, evaluate=False) |
---|
120 | print 'created mesh' |
---|
121 | |
---|
122 | #------------------------------------------------------------------------------- |
---|
123 | # Setup computational domain |
---|
124 | #------------------------------------------------------------------------------- |
---|
125 | domain = Domain(meshname, use_cache = True, verbose = True) |
---|
126 | |
---|
127 | print 'Number of triangles = ', len(domain) |
---|
128 | print 'The extent is ', domain.get_extent() |
---|
129 | print domain.statistics() |
---|
130 | |
---|
131 | domain.set_name(project.basename) |
---|
132 | domain.set_datadir(project.outputtimedir) |
---|
133 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
134 | domain.set_minimum_storable_height(0.01) |
---|
135 | |
---|
136 | #------------------------------------------------------------------------------- |
---|
137 | # Setup initial conditions |
---|
138 | #------------------------------------------------------------------------------- |
---|
139 | |
---|
140 | tide = 0.0 |
---|
141 | domain.set_quantity('stage', tide) |
---|
142 | domain.set_quantity('friction', 0.0) |
---|
143 | domain.set_quantity('elevation', |
---|
144 | filename = project.combined_dem_name + '.pts', |
---|
145 | use_cache = True, |
---|
146 | verbose = True, |
---|
147 | alpha = 0.1 |
---|
148 | ) |
---|
149 | |
---|
150 | #------------------------------------------------------------------------------- |
---|
151 | # Set up scenario (tsunami_source is a callable object used with set_quantity) |
---|
152 | #------------------------------------------------------------------------------- |
---|
153 | from smf import slide_tsunami |
---|
154 | |
---|
155 | tsunami_source = slide_tsunami(length=30000.0, |
---|
156 | depth=400.0, |
---|
157 | slope=6.0, |
---|
158 | thickness=176.0, |
---|
159 | radius=3330, |
---|
160 | dphi=0.23, |
---|
161 | x0=project.slump_origin[0], |
---|
162 | y0=project.slump_origin[1], |
---|
163 | alpha=0.0, |
---|
164 | domain=domain) |
---|
165 | |
---|
166 | #------------------------------------------------------------------------------- |
---|
167 | # Setup boundary conditions |
---|
168 | #------------------------------------------------------------------------------- |
---|
169 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
170 | |
---|
171 | Br = Reflective_boundary(domain) |
---|
172 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
173 | |
---|
174 | domain.set_boundary( {'e0': Bd, 'e1': Bd, 'e2': Bd, 'e3': Bd, 'e4': Bd, |
---|
175 | 'e5': Bd, 'e6': Bd} ) |
---|
176 | |
---|
177 | |
---|
178 | #------------------------------------------------------------------------------- |
---|
179 | # Evolve system through time |
---|
180 | #------------------------------------------------------------------------------- |
---|
181 | import time |
---|
182 | t0 = time.time() |
---|
183 | |
---|
184 | for t in domain.evolve(yieldstep = 30, finaltime = 480): |
---|
185 | domain.write_time() |
---|
186 | domain.write_boundary_statistics(tags = 'e14') |
---|
187 | stagestep = domain.get_quantity('stage') |
---|
188 | |
---|
189 | if allclose(t, 30): |
---|
190 | slide = Quantity(domain) |
---|
191 | slide.set_values(tsunami_source) |
---|
192 | domain.set_quantity('stage', slide + stagestep) |
---|
193 | |
---|
194 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
195 | |
---|
196 | print 'finished' |
---|