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_offshore10_dem_name = project_slide.on_offshore10_dem_name |
---|
55 | nsw_dem_name = project_slide.nsw_dem_name |
---|
56 | meshname = project_slide.meshname+'.msh' |
---|
57 | |
---|
58 | # creates DEM from asc data |
---|
59 | convert_dem_from_ascii2netcdf(on_offshore10_dem_name, use_cache=True, verbose=True) |
---|
60 | convert_dem_from_ascii2netcdf(nsw_dem_name, use_cache=True, verbose=True) |
---|
61 | |
---|
62 | #creates pts file for onshore DEM |
---|
63 | dem2pts(on_offshore10_dem_name, use_cache=True, verbose=True) |
---|
64 | dem2pts(nsw_dem_name, |
---|
65 | easting_min=project_slide.eastingmin_nsw, |
---|
66 | easting_max=project_slide.eastingmax_nsw, |
---|
67 | northing_min=project_slide.northingmin_nsw, |
---|
68 | northing_max= project_slide.northingmax_nsw, |
---|
69 | use_cache=True, verbose=True) |
---|
70 | |
---|
71 | print 'create offshore' |
---|
72 | G11 = Geospatial_data(file_name = project_slide.offshore_dem_name1 + '.xya') |
---|
73 | G12 = Geospatial_data(file_name = project_slide.offshore_dem_name4 + '.xya')+\ |
---|
74 | Geospatial_data(file_name = project_slide.offshore_dem_name5 + '.xya')+\ |
---|
75 | Geospatial_data(file_name = project_slide.offshore_dem_name6 + '.xya')+\ |
---|
76 | Geospatial_data(file_name = project_slide.offshore_dem_name7 + '.xya')+\ |
---|
77 | Geospatial_data(file_name = project_slide.offshore_dem_name8 + '.xya')+\ |
---|
78 | Geospatial_data(file_name = project_slide.offshore_dem_name9 + '.xya') |
---|
79 | print 'create onshore' |
---|
80 | G2 = Geospatial_data(file_name = project_slide.on_offshore10_dem_name + '.pts') |
---|
81 | G4 = Geospatial_data(file_name = project_slide.nsw_dem_name + '.pts') |
---|
82 | print 'add' |
---|
83 | G = G11.clip(Geospatial(project_slide.poly_surveyclip)) +\ |
---|
84 | G12.clip(Geospatial_data(project_slide.polyAll)) +\ |
---|
85 | G2.clip(Geospatial_data(project_slide.poly_10mclip)) +\ |
---|
86 | (G4.clip(Geospatial_data(project_slide.polyAll))).clip_outside(Geospatial_data(project_slide.poly_surveyclip)).clip_outside(Geospatial_data(project_slide.poly_10mclip)) |
---|
87 | print 'export points' |
---|
88 | G.export_points_file(project_slide.combined_dem_name + '.pts') |
---|
89 | #G.export_points_file(project_slide.combined_dem_name + '.xya') |
---|
90 | |
---|
91 | #---------------------------------------------------------------------------- |
---|
92 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
93 | # boundary and interior regions defined in project.py along with |
---|
94 | # resolutions (maximal area of per triangle) for each polygon |
---|
95 | #------------------------------------------------------------------------------- |
---|
96 | |
---|
97 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
98 | remainder_res = 500000 |
---|
99 | local_res = 25000 |
---|
100 | gong_res = 5000 |
---|
101 | coast_res = 500 |
---|
102 | interior_regions = [[project.poly_gong1, local_res], |
---|
103 | [project.poly_gong2, gong_res], |
---|
104 | [project.poly_gong3, coast_res]] |
---|
105 | |
---|
106 | from caching import cache |
---|
107 | _ = cache(create_mesh_from_regions, |
---|
108 | project.polyAll, |
---|
109 | {'boundary_tags': {'e0': [0], 'e1': [1], 'e2': [2], |
---|
110 | 'e3': [3], 'e4':[4], 'e5': [5], |
---|
111 | 'e6': [6]}, |
---|
112 | 'maximum_triangle_area': remainder_res, |
---|
113 | 'filename': meshname, |
---|
114 | 'interior_regions': interior_regions}, |
---|
115 | verbose = True, evaluate=False) |
---|
116 | print 'created mesh' |
---|
117 | |
---|
118 | #------------------------------------------------------------------------------- |
---|
119 | # Setup computational domain |
---|
120 | #------------------------------------------------------------------------------- |
---|
121 | domain = Domain(meshname, use_cache = True, verbose = True) |
---|
122 | |
---|
123 | print 'Number of triangles = ', len(domain) |
---|
124 | print 'The extent is ', domain.get_extent() |
---|
125 | print domain.statistics() |
---|
126 | |
---|
127 | domain.set_name(project.basename) |
---|
128 | domain.set_datadir(project.outputtimedir) |
---|
129 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
130 | domain.set_minimum_storable_height(0.01) |
---|
131 | |
---|
132 | #------------------------------------------------------------------------------- |
---|
133 | # Setup initial conditions |
---|
134 | #------------------------------------------------------------------------------- |
---|
135 | |
---|
136 | tide = 0.0 |
---|
137 | domain.set_quantity('stage', tide) |
---|
138 | domain.set_quantity('friction', 0.0) |
---|
139 | domain.set_quantity('elevation', |
---|
140 | filename = project.combined_dem_name + '.pts', |
---|
141 | use_cache = True, |
---|
142 | verbose = True, |
---|
143 | alpha = 0.1 |
---|
144 | ) |
---|
145 | |
---|
146 | #------------------------------------------------------------------------------- |
---|
147 | # Set up scenario (tsunami_source is a callable object used with set_quantity) |
---|
148 | #------------------------------------------------------------------------------- |
---|
149 | from smf import slide_tsunami |
---|
150 | |
---|
151 | tsunami_source = slide_tsunami(length=30000.0, |
---|
152 | depth=400.0, |
---|
153 | slope=6.0, |
---|
154 | thickness=176.0, |
---|
155 | radius=3330, |
---|
156 | dphi=0.23, |
---|
157 | x0=project.slump_origin[0], |
---|
158 | y0=project.slump_origin[1], |
---|
159 | alpha=0.0, |
---|
160 | domain=domain) |
---|
161 | |
---|
162 | #------------------------------------------------------------------------------- |
---|
163 | # Setup boundary conditions |
---|
164 | #------------------------------------------------------------------------------- |
---|
165 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
166 | |
---|
167 | Br = Reflective_boundary(domain) |
---|
168 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
169 | |
---|
170 | domain.set_boundary( {'e0': Bd, 'e1': Bd, 'e2': Bd, 'e3': Bd, 'e4': Bd, |
---|
171 | 'e5': Bd, 'e6': Bd} ) |
---|
172 | |
---|
173 | |
---|
174 | #------------------------------------------------------------------------------- |
---|
175 | # Evolve system through time |
---|
176 | #------------------------------------------------------------------------------- |
---|
177 | import time |
---|
178 | t0 = time.time() |
---|
179 | |
---|
180 | for t in domain.evolve(yieldstep = 30, finaltime = 480): |
---|
181 | domain.write_time() |
---|
182 | domain.write_boundary_statistics(tags = 'e14') |
---|
183 | stagestep = domain.get_quantity('stage') |
---|
184 | |
---|
185 | if allclose(t, 30): |
---|
186 | slide = Quantity(domain) |
---|
187 | slide.set_values(tsunami_source) |
---|
188 | domain.set_quantity('stage', slide + stagestep) |
---|
189 | |
---|
190 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
191 | |
---|
192 | print 'finished' |
---|