1 | """Script for running a tsunami inundation scenario for Sydney, 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.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 Adrian Hitchman and Jane Sexton, 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 pyvolution.shallow_water import Domain, Reflective_boundary, Dirichlet_boundary |
---|
23 | from pyvolution.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
24 | #from pyvolution.data_manager_old import convert_dem_from_ascii2netcdf, dem2pts |
---|
25 | from pyvolution.combine_pts import combine_rectangular_points_files |
---|
26 | from pyvolution.pmesh2domain import pmesh_to_domain_instance |
---|
27 | from pyvolution.quantity import Quantity |
---|
28 | from Numeric import allclose |
---|
29 | |
---|
30 | # Application specific imports |
---|
31 | import project # Definition of file names and polygons |
---|
32 | from pyvolution.smf import slump_tsunami # Function for submarine mudslide |
---|
33 | |
---|
34 | |
---|
35 | #------------------------------------------------------------------------------- |
---|
36 | # Preparation of topographic data |
---|
37 | # |
---|
38 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
39 | # Do for coarse and fine data |
---|
40 | # Fine pts file to be clipped to area of interest |
---|
41 | #------------------------------------------------------------------------------- |
---|
42 | |
---|
43 | # filenames |
---|
44 | coarsedemname = project.coarsedemname |
---|
45 | finedemname = project.finedemname |
---|
46 | meshname = project.meshname+'.msh' |
---|
47 | |
---|
48 | # coarse data |
---|
49 | convert_dem_from_ascii2netcdf(coarsedemname, use_cache=True, verbose=True) |
---|
50 | dem2pts(coarsedemname, use_cache=True, verbose=True) |
---|
51 | |
---|
52 | # fine data (clipping the points file to smaller area) |
---|
53 | convert_dem_from_ascii2netcdf(finedemname, use_cache=True, verbose=True) |
---|
54 | dem2pts(finedemname, |
---|
55 | easting_min=project.eastingmin, |
---|
56 | easting_max=project.eastingmax, |
---|
57 | northing_min=project.northingmin, |
---|
58 | northing_max= project.northingmax, |
---|
59 | use_cache=True, |
---|
60 | verbose=True) |
---|
61 | |
---|
62 | # combining the coarse and fine data |
---|
63 | combine_rectangular_points_files(project.finedemname + '.pts', |
---|
64 | project.coarsedemname + '.pts', |
---|
65 | project.combineddemname + '.pts') |
---|
66 | |
---|
67 | #from pmesh.create_mesh import create_mesh_from_regions |
---|
68 | #new interface |
---|
69 | from pmesh.mesh_interface import create_mesh_from_regions |
---|
70 | |
---|
71 | # original issue to Benfield |
---|
72 | #interior_res = 5000 |
---|
73 | #interior_regions = [[project.harbour_polygon_2, interior_res], |
---|
74 | # [project.botanybay_polygon_2, interior_res]] |
---|
75 | |
---|
76 | # used for finer mesh |
---|
77 | interior_res1 = 5000 |
---|
78 | interior_res2 = 315 |
---|
79 | interior_regions = [[project.newpoly1, interior_res1], |
---|
80 | [project.south1, interior_res1], |
---|
81 | [project.finepolymanly, interior_res2], |
---|
82 | [project.finepolyquay, interior_res2]] |
---|
83 | |
---|
84 | print 'number of interior regions', len(interior_regions) |
---|
85 | |
---|
86 | #FIXME: Fix caching of this one once the mesh_interface is ready |
---|
87 | from caching import cache |
---|
88 | |
---|
89 | # original + refined region |
---|
90 | _ = cache(create_mesh_from_regions, |
---|
91 | project.diffpolygonall, |
---|
92 | {'boundary_tags': {'bottom': [0], |
---|
93 | 'right1': [1], 'right0': [2], |
---|
94 | 'right2': [3], 'top': [4], 'left1': [5], |
---|
95 | 'left2': [6], 'left3': [7]}, |
---|
96 | 'maximum_triangle_area': 100000, |
---|
97 | 'filename': meshname, |
---|
98 | 'interior_regions': interior_regions}, |
---|
99 | verbose = True) |
---|
100 | |
---|
101 | #------------------------------------------------------------------------------- |
---|
102 | # Setup computational domain |
---|
103 | #------------------------------------------------------------------------------- |
---|
104 | |
---|
105 | domain = pmesh_to_domain_instance(meshname, Domain, |
---|
106 | use_cache = True, |
---|
107 | verbose = True) |
---|
108 | |
---|
109 | print 'Number of triangles = ', len(domain) |
---|
110 | print 'The extent is ', domain.get_extent() |
---|
111 | print domain.statistics() |
---|
112 | |
---|
113 | domain.set_name(project.basename) |
---|
114 | domain.set_datadir(project.outputdir) |
---|
115 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
116 | |
---|
117 | |
---|
118 | #------------------------------------------------------------------------------- |
---|
119 | # Set up scenario (tsunami_source is a callable object used with set_quantity) |
---|
120 | #------------------------------------------------------------------------------- |
---|
121 | |
---|
122 | tsunami_source = slump_tsunami(length=30000.0, |
---|
123 | depth=400.0, |
---|
124 | slope=6.0, |
---|
125 | thickness=176.0, |
---|
126 | radius=3330, |
---|
127 | dphi=0.23, |
---|
128 | x0=project.slump_origin[0], |
---|
129 | y0=project.slump_origin[1], |
---|
130 | alpha=0.0, |
---|
131 | domain=domain) |
---|
132 | |
---|
133 | |
---|
134 | #------------------------------------------------------------------------------- |
---|
135 | # Setup initial conditions |
---|
136 | #------------------------------------------------------------------------------- |
---|
137 | |
---|
138 | # apply slump after 30 mins, initialise to water level of tide = 0 |
---|
139 | domain.set_quantity('stage', 0.0) |
---|
140 | domain.set_quantity('friction', 0.03) |
---|
141 | domain.set_quantity('elevation', |
---|
142 | filename = project.combineddemname + '.pts', |
---|
143 | use_cache = True, |
---|
144 | verbose = True) |
---|
145 | |
---|
146 | |
---|
147 | #------------------------------------------------------------------------------- |
---|
148 | # Setup boundary conditions (all reflective) |
---|
149 | #------------------------------------------------------------------------------- |
---|
150 | |
---|
151 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
152 | |
---|
153 | Br = Reflective_boundary(domain) |
---|
154 | Bd = Dirichlet_boundary([0, 0, 0]) |
---|
155 | |
---|
156 | # original + refined regions |
---|
157 | #domain.set_boundary( {'bottom': Br, 'right1': Br, 'right0': Br, |
---|
158 | # 'right2': Br, 'top': Br, 'left1': Br, |
---|
159 | # 'left2': Br, 'left3': Br} ) |
---|
160 | |
---|
161 | # enforce Dirichlet BC - from 30/03/06 Benfield visit |
---|
162 | domain.set_boundary( {'bottom': Bd, 'right1': Bd, 'right0': Bd, |
---|
163 | 'right2': Bd, 'top': Bd, 'left1': Bd, |
---|
164 | 'left2': Bd, 'left3': Bd} ) |
---|
165 | |
---|
166 | # increasingly finer interior regions |
---|
167 | #domain.set_boundary( {'bottom': Br, 'right': Br, 'left': Br, 'top': Br} ) |
---|
168 | |
---|
169 | |
---|
170 | #------------------------------------------------------------------------------- |
---|
171 | # Evolve system through time |
---|
172 | #------------------------------------------------------------------------------- |
---|
173 | |
---|
174 | import time |
---|
175 | t0 = time.time() |
---|
176 | thisfile = project.integraltimeseries+'.csv' |
---|
177 | fid = open(thisfile, 'w') |
---|
178 | |
---|
179 | for t in domain.evolve(yieldstep = 120, finaltime = 18000): |
---|
180 | domain.write_time() |
---|
181 | domain.write_boundary_statistics(tags = 'bottom') |
---|
182 | |
---|
183 | # calculate integral |
---|
184 | thisstagestep = domain.get_quantity('stage') |
---|
185 | s = '%.2f, %.2f\n' %(t, thisstagestep.get_integral()) |
---|
186 | fid.write(s) |
---|
187 | |
---|
188 | # add slump after 30 mins |
---|
189 | if allclose(t, 30*60): |
---|
190 | slump = Quantity(domain) |
---|
191 | slump.set_values(tsunami_source) |
---|
192 | domain.set_quantity('stage', slump + thisstagestep) |
---|
193 | |
---|
194 | |
---|
195 | print 'That took %.2f seconds' %(time.time()-t0) |
---|