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 boundary data obtained from a tsunami simulation done with MOST. |
---|
9 | |
---|
10 | Ole Nielsen, GA - 2005 and Adrian Hitchman and Jane Sexton, GA - 2006 |
---|
11 | """ |
---|
12 | |
---|
13 | tide = 0 #Australian Height Datum (mean sea level) |
---|
14 | |
---|
15 | import os |
---|
16 | import time |
---|
17 | |
---|
18 | |
---|
19 | from pyvolution.shallow_water import Domain, Reflective_boundary, File_boundary,\ |
---|
20 | Dirichlet_boundary, Time_boundary, Transmissive_boundary |
---|
21 | from pyvolution.data_manager import convert_dem_from_ascii2netcdf,\ |
---|
22 | dem2pts |
---|
23 | from pyvolution.pmesh2domain import pmesh_to_domain_instance |
---|
24 | from pyvolution.combine_pts import combine_rectangular_points_files |
---|
25 | from caching import cache |
---|
26 | import project |
---|
27 | from math import pi, sin |
---|
28 | from smf import slump_tsunami, slide_tsunami, Double_gaussian |
---|
29 | from pyvolution.least_squares import fit_to_mesh_file, DEFAULT_ALPHA |
---|
30 | |
---|
31 | # Data preparation |
---|
32 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
33 | # Do for coarse and fine data |
---|
34 | # Fine pts file to be clipped to area of interest |
---|
35 | coarsedemname = project.coarsedemname |
---|
36 | finedemname = project.finedemname |
---|
37 | meshname = project.meshname+'.msh' |
---|
38 | |
---|
39 | # coarse data |
---|
40 | cache(convert_dem_from_ascii2netcdf, coarsedemname, {'verbose': True}, |
---|
41 | dependencies = [coarsedemname + '.asc'], |
---|
42 | verbose = True) |
---|
43 | #evaluate = True) |
---|
44 | |
---|
45 | cache(dem2pts, coarsedemname, {'verbose': True}, |
---|
46 | dependencies = [coarsedemname + '.dem'], |
---|
47 | verbose = True) |
---|
48 | |
---|
49 | # fine data |
---|
50 | cache(convert_dem_from_ascii2netcdf, finedemname, {'verbose': True}, |
---|
51 | dependencies = [finedemname + '.asc'], |
---|
52 | verbose = True) |
---|
53 | #evaluate = True) |
---|
54 | |
---|
55 | # clipping the fine data |
---|
56 | cache(dem2pts, finedemname, {'verbose': True, |
---|
57 | 'easting_min': project.eastingmin, |
---|
58 | 'easting_max': project.eastingmax, |
---|
59 | 'northing_min': project.northingmin, |
---|
60 | 'northing_max': project.northingmax}, |
---|
61 | dependencies = [finedemname + '.dem'], |
---|
62 | #evaluate = True, |
---|
63 | verbose = True) |
---|
64 | |
---|
65 | # combining the coarse and fine data |
---|
66 | combine_rectangular_points_files(project.finedemname + '.pts', |
---|
67 | project.coarsedemname + '.pts', |
---|
68 | project.combineddemname + '.pts') |
---|
69 | |
---|
70 | # Create Triangular Mesh |
---|
71 | # Overall clipping polygon and interior regions defined in project.py |
---|
72 | from pmesh.create_mesh import create_mesh_from_regions |
---|
73 | |
---|
74 | # for whole region |
---|
75 | interior_res = 5000 # maximal area of per triangle |
---|
76 | interior_regions = [[project.harbour_polygon_2, interior_res], |
---|
77 | [project.botanybay_polygon_2, interior_res]] |
---|
78 | |
---|
79 | m = cache(create_mesh_from_regions, |
---|
80 | project.diffpolygonall, |
---|
81 | {'boundary_tags': {'bottom': [0], |
---|
82 | 'right1': [1], 'right0': [2], |
---|
83 | 'right2': [3], 'top': [4], 'left1': [5], |
---|
84 | 'left2': [6], 'left3': [7]}, |
---|
85 | 'resolution': 100000, |
---|
86 | 'filename': meshname, |
---|
87 | 'interior_regions': interior_regions}, |
---|
88 | #evaluate=True, |
---|
89 | verbose = True) |
---|
90 | |
---|
91 | #Add elevation data to the mesh - this is in place of set_quantity |
---|
92 | #mesh_elevname = 'elevation.msh' |
---|
93 | #cache(fit_to_mesh_file,(meshname, project.combineddemname + '.pts', |
---|
94 | # mesh_elevname, DEFAULT_ALPHA), |
---|
95 | # {'verbose': True, 'expand_search': True, 'precrop': True}, |
---|
96 | # dependencies = [meshname], |
---|
97 | # #evaluate = True, |
---|
98 | # verbose = False) |
---|
99 | #meshname = mesh_elevname |
---|
100 | |
---|
101 | # Setup domain |
---|
102 | domain = cache(pmesh_to_domain_instance, (meshname, Domain), |
---|
103 | dependencies = [meshname], |
---|
104 | verbose = True) |
---|
105 | |
---|
106 | # This section replaced with fit_to_mesh_file above |
---|
107 | domain.set_quantity('elevation', |
---|
108 | filename = project.combineddemname + '.pts', |
---|
109 | # filename = project.finedemname + '.pts', |
---|
110 | use_cache = True, |
---|
111 | verbose = True) |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | print 'Number of triangles = ', len(domain) |
---|
116 | print 'The extent is ', domain.get_extent() |
---|
117 | |
---|
118 | domain.set_name(project.basename) |
---|
119 | domain.set_datadir(project.outputdir) |
---|
120 | domain.store = True |
---|
121 | domain.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum'] |
---|
122 | |
---|
123 | # slump parameters, wid=len |
---|
124 | len = 30000.0 |
---|
125 | dep = 400.0 |
---|
126 | #thk = 120.0 for scenario 1 and 176 for scenario 2 rang 0.2-0.44 of depth |
---|
127 | thk = 0.44*dep |
---|
128 | rad = 3330 |
---|
129 | dp = 0.23 |
---|
130 | th = 6 |
---|
131 | alpha = 0.0 |
---|
132 | x0 = project.x0 # slump origin |
---|
133 | y0 = project.y0 |
---|
134 | # Setup Initial conditions |
---|
135 | t = slump_tsunami(length=len, depth=dep, slope=th, thickness=thk, \ |
---|
136 | radius=rad, dphi=dp, x0=x0, y0=y0, alpha=alpha) |
---|
137 | domain.set_quantity('stage', t) |
---|
138 | domain.set_quantity('friction', 0) |
---|
139 | |
---|
140 | # Setup Boundary Conditions |
---|
141 | print domain.get_boundary_tags() |
---|
142 | |
---|
143 | Br = Reflective_boundary(domain) |
---|
144 | Bt = Transmissive_boundary(domain) |
---|
145 | Bd = Dirichlet_boundary([0,0,0]) |
---|
146 | # 10 min square wave starting at 1 min, 6m high |
---|
147 | Bw = Time_boundary(domain=domain, |
---|
148 | f=lambda t: [(6<t<606)*6, 0, 0]) |
---|
149 | |
---|
150 | domain.set_boundary( {'bottom': Br, 'right1': Br, 'right0': Br, |
---|
151 | 'right2': Br, 'top': Br, 'left1': Br, |
---|
152 | 'left2': Br, 'left3': Br} ) |
---|
153 | |
---|
154 | # Evolve |
---|
155 | import time |
---|
156 | t0 = time.time() |
---|
157 | |
---|
158 | for t in domain.evolve(yieldstep = 120, finaltime = 18000): |
---|
159 | domain.write_time() |
---|
160 | domain.write_boundary_statistics(tags = 'bottom') |
---|
161 | |
---|
162 | print 'That took %.2f seconds' %(time.time()-t0) |
---|