1 | """Run a tsunami inundation scenario for Busselton, WA, Australia. |
---|
2 | |
---|
3 | The scenario is defined by a triangular mesh created from project.polygon, the |
---|
4 | elevation data is compiled into a pts file through build_elevation.py and a |
---|
5 | simulated tsunami is generated through an sts file from build_boundary.py. |
---|
6 | |
---|
7 | Input: sts file (build_boundary.py for respective event) |
---|
8 | pts file (build_elevation.py) |
---|
9 | information from project file |
---|
10 | Outputs: sww file stored in project.output_run_time_dir |
---|
11 | The export_results_all.py and get_timeseries.py is reliant |
---|
12 | on the outputs of this script |
---|
13 | |
---|
14 | Ole Nielsen and Duncan Gray, GA - 2005, Jane Sexton, Nick Bartzis, GA - 2006 |
---|
15 | Ole Nielsen, Jane Sexton and Kristy Van Putten - 2008 |
---|
16 | """ |
---|
17 | |
---|
18 | #------------------------------------------------------------------------------ |
---|
19 | # Import necessary modules |
---|
20 | #------------------------------------------------------------------------------ |
---|
21 | |
---|
22 | # Standard modules |
---|
23 | import os |
---|
24 | import os.path |
---|
25 | import time |
---|
26 | from time import localtime, strftime, gmtime |
---|
27 | |
---|
28 | # Related major packages |
---|
29 | from Scientific.IO.NetCDF import NetCDFFile |
---|
30 | import Numeric as num |
---|
31 | |
---|
32 | from anuga.interface import create_domain_from_regions |
---|
33 | from anuga.interface import Transmissive_stage_zero_momentum_boundary |
---|
34 | from anuga.interface import Dirichlet_boundary |
---|
35 | from anuga.interface import Reflective_boundary |
---|
36 | from anuga.interface import Field_boundary |
---|
37 | from anuga.interface import create_sts_boundary |
---|
38 | from anuga.interface import csv2building_polygons |
---|
39 | from anuga.utilities.system_tools import file_length |
---|
40 | |
---|
41 | from anuga.shallow_water.data_manager import start_screen_catcher |
---|
42 | from anuga.shallow_water.data_manager import copy_code_files |
---|
43 | from anuga.shallow_water.data_manager import urs2sts |
---|
44 | from anuga.utilities.polygon import read_polygon, Polygon_function |
---|
45 | from anuga.caching import cache |
---|
46 | |
---|
47 | # Application specific imports |
---|
48 | from setup_model import project |
---|
49 | import build_urs_boundary as bub |
---|
50 | |
---|
51 | #------------------------------------------------------------------------------- |
---|
52 | # Copy scripts to time stamped output directory and capture screen |
---|
53 | # output to file. Copy script must be before screen_catcher |
---|
54 | #------------------------------------------------------------------------------- |
---|
55 | |
---|
56 | copy_code_files(project.output_run, |
---|
57 | [__file__, |
---|
58 | os.path.join(os.path.dirname(project.__file__), |
---|
59 | project.__name__+'.py'), |
---|
60 | os.path.join(os.path.dirname(project.__file__), |
---|
61 | 'setup_model.py')], |
---|
62 | verbose=True |
---|
63 | ) |
---|
64 | #start_screen_catcher(project.output_run, 0, 1) |
---|
65 | |
---|
66 | #------------------------------------------------------------------------------- |
---|
67 | # Create the computational domain based on overall clipping polygon with |
---|
68 | # a tagged boundary and interior regions defined in project.py along with |
---|
69 | # resolutions (maximal area of per triangle) for each polygon |
---|
70 | #------------------------------------------------------------------------------- |
---|
71 | |
---|
72 | print 'Create computational domain' |
---|
73 | |
---|
74 | # Create the STS file |
---|
75 | # FIXME (Ole): This is deadly dangerous if buildcode changes (as was the case 24th March 2009) |
---|
76 | # We need to use caching instead! |
---|
77 | |
---|
78 | print 'project.mux_data_folder=%s' % project.mux_data_folder |
---|
79 | if not os.path.exists(project.event_sts + '.sts'): |
---|
80 | bub.build_urs_boundary(project.mux_input_filename, project.event_sts) |
---|
81 | |
---|
82 | # Read in boundary from ordered sts file |
---|
83 | event_sts = create_sts_boundary(project.event_sts) |
---|
84 | |
---|
85 | # Reading the landward defined points, this incorporates the original clipping |
---|
86 | # polygon minus the 100m contour |
---|
87 | landward_boundary = read_polygon(project.landward_boundary) |
---|
88 | |
---|
89 | # Combine sts polyline with landward points |
---|
90 | bounding_polygon_sts = event_sts + landward_boundary |
---|
91 | |
---|
92 | # Number of boundary segments |
---|
93 | num_ocean_segments = len(event_sts) - 1 |
---|
94 | # Number of landward_boundary points |
---|
95 | num_land_points = file_length(project.landward_boundary) |
---|
96 | |
---|
97 | # Boundary tags refer to project.landward_boundary |
---|
98 | # 4 points equals 5 segments start at N |
---|
99 | boundary_tags={'back': range(num_ocean_segments+1, |
---|
100 | num_ocean_segments+num_land_points), |
---|
101 | 'side': [num_ocean_segments, |
---|
102 | num_ocean_segments+num_land_points], |
---|
103 | 'ocean': range(num_ocean_segments)} |
---|
104 | |
---|
105 | # Build mesh and domain |
---|
106 | domain = create_domain_from_regions(bounding_polygon_sts, |
---|
107 | boundary_tags=boundary_tags, |
---|
108 | maximum_triangle_area=project.bounding_maxarea, |
---|
109 | interior_regions=project.interior_regions, |
---|
110 | mesh_filename=project.meshes, |
---|
111 | use_cache=True, |
---|
112 | verbose=True) |
---|
113 | print domain.statistics() |
---|
114 | |
---|
115 | # FIXME(Ole): How can we make this more automatic? |
---|
116 | domain.geo_reference.zone = project.zone |
---|
117 | |
---|
118 | |
---|
119 | domain.set_name(project.scenario_name) |
---|
120 | domain.set_datadir(project.output_run) |
---|
121 | domain.set_minimum_storable_height(0.01) # Don't store depth less than 1cm |
---|
122 | |
---|
123 | #------------------------------------------------------------------------------- |
---|
124 | # Setup initial conditions |
---|
125 | #------------------------------------------------------------------------------- |
---|
126 | |
---|
127 | print 'Setup initial conditions' |
---|
128 | |
---|
129 | # Set the initial stage in the offcoast region only |
---|
130 | if project.land_initial_conditions: |
---|
131 | IC = Polygon_function(project.land_initial_conditions, |
---|
132 | default=project.tide, |
---|
133 | geo_reference=domain.geo_reference) |
---|
134 | else: |
---|
135 | IC = 0 |
---|
136 | domain.set_quantity('stage', IC, use_cache=True, verbose=True) |
---|
137 | domain.set_quantity('friction', project.friction) |
---|
138 | domain.set_quantity('elevation', |
---|
139 | filename=project.combined_elevation+'.pts', |
---|
140 | use_cache=True, |
---|
141 | verbose=True, |
---|
142 | alpha=project.alpha) |
---|
143 | |
---|
144 | if project.use_buildings: |
---|
145 | # Add buildings from file |
---|
146 | print 'Reading building polygons' |
---|
147 | building_polygons, building_heights = csv2building_polygons(project.building_polygon) |
---|
148 | #clipping_polygons=project.building_area_polygons) |
---|
149 | |
---|
150 | print 'Creating %d building polygons' % len(building_polygons) |
---|
151 | def create_polygon_function(building_polygons, geo_reference=None): |
---|
152 | L = [] |
---|
153 | for i, key in enumerate(building_polygons): |
---|
154 | if i%100==0: print i |
---|
155 | poly = building_polygons[key] |
---|
156 | elev = building_heights[key] |
---|
157 | L.append((poly, elev)) |
---|
158 | |
---|
159 | buildings = Polygon_function(L, default=0.0, |
---|
160 | geo_reference=geo_reference) |
---|
161 | return buildings |
---|
162 | |
---|
163 | print 'Creating %d building polygons' % len(building_polygons) |
---|
164 | buildings = cache(create_polygon_function, |
---|
165 | building_polygons, |
---|
166 | {'geo_reference': domain.geo_reference}, |
---|
167 | verbose=True) |
---|
168 | |
---|
169 | print 'Adding buildings' |
---|
170 | domain.add_quantity('elevation', |
---|
171 | buildings, |
---|
172 | use_cache=True, |
---|
173 | verbose=True) |
---|
174 | |
---|
175 | |
---|
176 | #------------------------------------------------------------------------------- |
---|
177 | # Setup boundary conditions |
---|
178 | #------------------------------------------------------------------------------- |
---|
179 | |
---|
180 | print 'Set boundary - available tags:', domain.get_boundary_tags() |
---|
181 | |
---|
182 | Br = Reflective_boundary(domain) |
---|
183 | Bs = Transmissive_stage_zero_momentum_boundary(domain) |
---|
184 | Bf = Field_boundary(project.event_sts+'.sts', |
---|
185 | domain, |
---|
186 | mean_stage=project.tide, |
---|
187 | time_thinning=1, |
---|
188 | default_boundary=Dirichlet_boundary([0, 0, 0]), |
---|
189 | boundary_polygon=bounding_polygon_sts, |
---|
190 | use_cache=True, |
---|
191 | verbose=True) |
---|
192 | |
---|
193 | domain.set_boundary({'back': Br, |
---|
194 | 'side': Bs, |
---|
195 | 'ocean': Bf}) |
---|
196 | |
---|
197 | #------------------------------------------------------------------------------- |
---|
198 | # Evolve system through time |
---|
199 | #------------------------------------------------------------------------------- |
---|
200 | |
---|
201 | t0 = time.time() |
---|
202 | |
---|
203 | # Skip over the first 6000 seconds |
---|
204 | for t in domain.evolve(yieldstep=2000, |
---|
205 | finaltime=6000): |
---|
206 | print domain.timestepping_statistics() |
---|
207 | print domain.boundary_statistics(tags='ocean') |
---|
208 | |
---|
209 | # Start detailed model |
---|
210 | for t in domain.evolve(yieldstep=project.yieldstep, |
---|
211 | finaltime=project.finaltime, |
---|
212 | skip_initial_step=True): |
---|
213 | print domain.timestepping_statistics() |
---|
214 | print domain.boundary_statistics(tags='ocean') |
---|
215 | |
---|
216 | print 'Simulation took %.2f seconds' %(time.time()-t0) |
---|
217 | |
---|