1 | """Script for running a tsunami inundation scenario for Onslow, 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.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 Nick Bartzis, 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 |
---|
23 | from pyvolution.shallow_water import Domain, Time_boundary |
---|
24 | from pyvolution.data_manager 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 | |
---|
28 | # Application specific imports |
---|
29 | import project # Definition of file names and polygons |
---|
30 | from smf import slump_tsunami # Function for submarine mudslide |
---|
31 | |
---|
32 | |
---|
33 | #------------------------------------------------------------------------------- |
---|
34 | # Preparation of topographic data |
---|
35 | # |
---|
36 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
37 | # Do for coarse and fine data |
---|
38 | # Fine pts file to be clipped to area of interest |
---|
39 | #------------------------------------------------------------------------------- |
---|
40 | |
---|
41 | # filenames |
---|
42 | coarsedemname = project.coarsedemname |
---|
43 | ''' |
---|
44 | #finedemname = project.finedemname |
---|
45 | ''' |
---|
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 | |
---|
63 | # combining the coarse and fine data |
---|
64 | combine_rectangular_points_files(project.finedemname + '.pts', |
---|
65 | project.coarsedemname + '.pts', |
---|
66 | project.combineddemname + '.pts') |
---|
67 | ''' |
---|
68 | |
---|
69 | #------------------------------------------------------------------------------- |
---|
70 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
71 | # boundary and interior regions defined in project.py along with |
---|
72 | # resolutions (maximal area of per triangle) for each polygon |
---|
73 | #------------------------------------------------------------------------------- |
---|
74 | |
---|
75 | from pmesh.create_mesh import create_mesh_from_regions |
---|
76 | |
---|
77 | # original |
---|
78 | interior_res = 5000 |
---|
79 | interior_regions = [[project.poly_onslow, interior_res], |
---|
80 | [project.poly_thevenard, interior_res], |
---|
81 | [project.poly_direction, interior_res]] |
---|
82 | |
---|
83 | #FIXME: Fix caching of this one once the mesh_interface is ready |
---|
84 | from caching import cache |
---|
85 | _ = cache(create_mesh_from_regions, |
---|
86 | project.polyAll, |
---|
87 | {'boundary_tags': {'top': [0], 'topleft': [1], |
---|
88 | 'left': [2], 'bottom': [3], |
---|
89 | 'bottomright': [4], 'topright': [5]}, |
---|
90 | 'resolution': 100000, |
---|
91 | 'filename': meshname, |
---|
92 | 'interior_regions': interior_regions, |
---|
93 | 'UTM': True, |
---|
94 | 'refzone': project.refzone}, |
---|
95 | verbose = True) |
---|
96 | |
---|
97 | |
---|
98 | #------------------------------------------------------------------------------- |
---|
99 | # Setup computational domain |
---|
100 | #------------------------------------------------------------------------------- |
---|
101 | |
---|
102 | domain = pmesh_to_domain_instance(meshname, Domain, |
---|
103 | use_cache = True, |
---|
104 | verbose = True) |
---|
105 | |
---|
106 | print 'Number of triangles = ', len(domain) |
---|
107 | print 'The extent is ', domain.get_extent() |
---|
108 | |
---|
109 | domain.set_name(project.basename) |
---|
110 | domain.set_datadir(project.outputdir) |
---|
111 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
112 | |
---|
113 | |
---|
114 | #------------------------------------------------------------------------------- |
---|
115 | # Set up scenario (tsunami_source is a callable object used with set_quantity) |
---|
116 | #------------------------------------------------------------------------------- |
---|
117 | ''' |
---|
118 | tsunami_source = slump_tsunami(length=30000.0, |
---|
119 | depth=400.0, |
---|
120 | slope=6.0, |
---|
121 | thickness=176.0, |
---|
122 | radius=3330, |
---|
123 | dphi=0.23, |
---|
124 | x0=project.slump_origin[0], |
---|
125 | y0=project.slump_origin[1], |
---|
126 | alpha=0.0, |
---|
127 | domain=domain) |
---|
128 | |
---|
129 | ''' |
---|
130 | #------------------------------------------------------------------------------- |
---|
131 | # Setup initial conditions |
---|
132 | #------------------------------------------------------------------------------- |
---|
133 | |
---|
134 | domain.set_quantity('stage', 0.) |
---|
135 | domain.set_quantity('friction', 0.0) |
---|
136 | domain.set_quantity('elevation', |
---|
137 | # filename = project.combineddemname + '.pts', |
---|
138 | filename = project.coarsedemname + '.pts', |
---|
139 | use_cache = True, |
---|
140 | verbose = True |
---|
141 | ) |
---|
142 | |
---|
143 | |
---|
144 | #------------------------------------------------------------------------------- |
---|
145 | # Setup boundary conditions (all reflective) |
---|
146 | #------------------------------------------------------------------------------- |
---|
147 | |
---|
148 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
149 | |
---|
150 | Br = Reflective_boundary(domain) |
---|
151 | # 10 min square wave starting at 1 min, 6m high |
---|
152 | Bw = Time_boundary(domain = domain, |
---|
153 | f=lambda t: [(50<t<800)*6, 0, 0]) |
---|
154 | |
---|
155 | domain.set_boundary( {'top': Bw, 'topleft': Br, |
---|
156 | 'left': Br, 'bottom': Br, |
---|
157 | 'bottomright': Br, 'topright': Br} ) |
---|
158 | |
---|
159 | |
---|
160 | #------------------------------------------------------------------------------- |
---|
161 | # Evolve system through time |
---|
162 | #------------------------------------------------------------------------------- |
---|
163 | |
---|
164 | import time |
---|
165 | t0 = time.time() |
---|
166 | |
---|
167 | for t in domain.evolve(yieldstep = 50, finaltime = 5000): |
---|
168 | domain.write_time() |
---|
169 | domain.write_boundary_statistics(tags = 'top') |
---|
170 | |
---|
171 | print 'That took %.2f seconds' %(time.time()-t0) |
---|