1 | """Script for running a tsunami inundation scenario for Karratha, 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 boundary data obtained from a tsunami simulation done with MOST. |
---|
9 | |
---|
10 | Ole Nielsen, GA - 2005 |
---|
11 | """ |
---|
12 | |
---|
13 | #tide = 0.75 #HMWS estimate by Colin French, GA |
---|
14 | tide = 0 #HMW |
---|
15 | |
---|
16 | |
---|
17 | import os |
---|
18 | import time |
---|
19 | |
---|
20 | |
---|
21 | from anuga.pyvolution.shallow_water import Domain, Reflective_boundary, File_boundary,\ |
---|
22 | Dirichlet_boundary, Time_boundary, Transmissive_boundary |
---|
23 | from anuga.pyvolution.data_manager import convert_dem_from_ascii2netcdf,\ |
---|
24 | dem2pts, ferret2sww |
---|
25 | from anuga.pyvolution.pmesh2domain import pmesh_to_domain_instance |
---|
26 | from caching import cache |
---|
27 | import project |
---|
28 | |
---|
29 | #Data preparation |
---|
30 | #Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
31 | demname = project.demname |
---|
32 | |
---|
33 | cache(convert_dem_from_ascii2netcdf, demname, {'verbose': True}, |
---|
34 | dependencies = [demname + '.asc'], |
---|
35 | verbose = True) |
---|
36 | #evaluate = True) |
---|
37 | |
---|
38 | cache(dem2pts, demname, {'verbose': True}, |
---|
39 | dependencies = [demname + '.dem'], |
---|
40 | verbose = True) |
---|
41 | |
---|
42 | |
---|
43 | #Convert MOST boundary |
---|
44 | source_dir = project.boundarydir |
---|
45 | |
---|
46 | from anuga.pyvolution.data_manager import ferret2sww |
---|
47 | |
---|
48 | south = project.south |
---|
49 | north = project.north |
---|
50 | west = project.west |
---|
51 | east = project.east |
---|
52 | |
---|
53 | |
---|
54 | #Howard: Ignore this |
---|
55 | #cache(ferret2sww, |
---|
56 | # (source_dir+project.boundary_basename, |
---|
57 | # project.boundary_basename), |
---|
58 | # {'verbose': True, |
---|
59 | # 'minlat': south-1, |
---|
60 | # 'maxlat': north+1, |
---|
61 | # 'minlon': west-1, |
---|
62 | # 'maxlon': east+1, |
---|
63 | # 'origin': project.mesh_origin, |
---|
64 | # 'mean_stage': tide, |
---|
65 | # 'zscale': 1, #Enhance tsunami |
---|
66 | # 'fail_on_NaN': False, |
---|
67 | # 'inverted_bathymetry': True}, |
---|
68 | # #evaluate = True, |
---|
69 | # verbose = True) |
---|
70 | ##FIXME: Dependencies |
---|
71 | |
---|
72 | |
---|
73 | #ferret2sww(source_dir+project.boundary_basename, |
---|
74 | # project.boundary_basename, |
---|
75 | # verbose=True, |
---|
76 | # minlat=south-1, maxlat=north+1, |
---|
77 | # minlon=west-1, maxlon=east+1, |
---|
78 | # origin = project.mesh_origin, |
---|
79 | # mean_stage = tide, |
---|
80 | # zscale = 1, |
---|
81 | # fail_on_NaN = False, |
---|
82 | # inverted_bathymetry = True) |
---|
83 | |
---|
84 | |
---|
85 | #Create Triangular Mesh |
---|
86 | from anuga.pmesh.create_mesh import create_mesh_from_regions |
---|
87 | |
---|
88 | resolution = 4000 |
---|
89 | interior_regions = [#[project.karratha_polygon, 25000], |
---|
90 | #[project.dampier_polygon, 2000], |
---|
91 | #[project.refinery_polygon, 2000], |
---|
92 | #[project.point_polygon, 2000]] |
---|
93 | [project.neil1_polygon, resolution], |
---|
94 | [project.neil2_polygon, 64000]] |
---|
95 | |
---|
96 | #For visualisation |
---|
97 | #interior_regions = [[project.wb_polygon, 400], |
---|
98 | # [project.lwb_polygon, 8000]] |
---|
99 | |
---|
100 | |
---|
101 | |
---|
102 | meshname = project.meshname + '_%d.msh' %resolution |
---|
103 | m = cache(create_mesh_from_regions, |
---|
104 | project.polygon, |
---|
105 | {'boundary_tags': {'back': [7, 8], 'side': [0, 6], |
---|
106 | 'ocean': [1, 2, 3, 4, 5]}, |
---|
107 | 'resolution': 100000, |
---|
108 | #'filename': project.meshname + '.msh', |
---|
109 | 'filename': meshname, |
---|
110 | 'interior_regions': interior_regions}, |
---|
111 | #verbose = True) |
---|
112 | verbose = True, |
---|
113 | evaluate = True) |
---|
114 | |
---|
115 | |
---|
116 | #Setup domain |
---|
117 | |
---|
118 | #domain = cache(pmesh_to_domain_instance, (meshname, Domain), |
---|
119 | # dependencies = [meshname], |
---|
120 | # verbose = True) |
---|
121 | |
---|
122 | |
---|
123 | #This is how it will be Howard! |
---|
124 | domain = pmesh_to_domain_instance(meshname, Domain, use_cache=True) |
---|
125 | |
---|
126 | |
---|
127 | domain.set_name(project.basename + '_%d' %resolution) |
---|
128 | domain.set_datadir(project.outputdir) |
---|
129 | domain.store = True |
---|
130 | #domain.smooth = False |
---|
131 | |
---|
132 | |
---|
133 | #domain.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum'] |
---|
134 | domain.quantities_to_be_stored = ['stage'] |
---|
135 | |
---|
136 | print 'Number of triangles = ', len(domain) |
---|
137 | print 'The extent is ', domain.get_extent() |
---|
138 | |
---|
139 | |
---|
140 | |
---|
141 | #Setup Initial Conditions |
---|
142 | domain.set_quantity('friction', 0) |
---|
143 | domain.set_quantity('stage', tide) |
---|
144 | domain.set_quantity('elevation', |
---|
145 | filename = demname + '.pts', |
---|
146 | use_cache = True, |
---|
147 | verbose = True) |
---|
148 | |
---|
149 | |
---|
150 | |
---|
151 | #Setup Boundary Conditions |
---|
152 | print domain.get_boundary_tags() |
---|
153 | |
---|
154 | |
---|
155 | #File boundary. |
---|
156 | # |
---|
157 | #Takes a arbitrary simulation output in the form of an sww file and use it to provide a boundary. |
---|
158 | #Values at every boundary point at every timestep are established by interpolation from the |
---|
159 | #values in the sww boundary file. |
---|
160 | #Boundary values at arbitrary timesteps needed in evolve are obtained by linear interpolation |
---|
161 | # |
---|
162 | #See also docstring for File_boundary in generic_boundary_conditions.py |
---|
163 | # |
---|
164 | Bf = File_boundary(project.boundary_basename + '.sww', domain, verbose = True) |
---|
165 | #domain.starttime = 3000 #Obtained from MOST |
---|
166 | domain.starttime = 0 #Obtained from MOST |
---|
167 | |
---|
168 | Br = Reflective_boundary(domain) |
---|
169 | Bt = Transmissive_boundary(domain) |
---|
170 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
171 | Bw = Time_boundary(domain=domain, |
---|
172 | f=lambda t: [(60<t<660)*4, 0, 0]) |
---|
173 | |
---|
174 | |
---|
175 | domain.set_boundary( {'back': Br,'side': Bd, 'ocean': Bf} ) #MOST tsunami |
---|
176 | |
---|
177 | #domain.set_boundary( {'back': Bd,'side': Bd, 'ocean': Bd} ) #Nothing |
---|
178 | |
---|
179 | |
---|
180 | #Evolve |
---|
181 | import time |
---|
182 | t0 = time.time() |
---|
183 | |
---|
184 | #for t in domain.evolve(yieldstep = 1000, finaltime = 14000): |
---|
185 | # domain.write_time() |
---|
186 | # domain.write_boundary_statistics(tags = 'ocean') #quantities = 'stage') |
---|
187 | |
---|
188 | #for t in domain.evolve(yieldstep = 20, finaltime = 15000, |
---|
189 | # skip_initial_step = True): |
---|
190 | # domain.write_time() |
---|
191 | # domain.write_boundary_statistics(tags = 'ocean') #quantities = 'stage') |
---|
192 | |
---|
193 | #for t in domain.evolve(yieldstep = 10, finaltime = 40000, |
---|
194 | # skip_initial_step = True): |
---|
195 | # domain.write_time() |
---|
196 | # domain.write_boundary_statistics(tags = 'ocean') #quantities = 'stage') |
---|
197 | |
---|
198 | for t in domain.evolve(yieldstep = 60, finaltime = 40000): |
---|
199 | # skip_initial_step = True): |
---|
200 | domain.write_time() |
---|
201 | domain.write_boundary_statistics(tags = 'ocean') #quantities = 'stage') |
---|
202 | |
---|
203 | print 'That took %.2f seconds' %(time.time()-t0) |
---|