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 Time_boundary |
---|
38 | from anuga.interface import file_function |
---|
39 | |
---|
40 | from anuga.interface import create_sts_boundary |
---|
41 | from anuga.interface import csv2building_polygons |
---|
42 | from file_length import file_length |
---|
43 | |
---|
44 | from anuga.shallow_water.data_manager import start_screen_catcher |
---|
45 | from anuga.shallow_water.data_manager import copy_code_files |
---|
46 | from anuga.shallow_water.data_manager import urs2sts |
---|
47 | from anuga.utilities.polygon import read_polygon, Polygon_function |
---|
48 | |
---|
49 | # Application specific imports |
---|
50 | from setup_model import project |
---|
51 | import build_urs_boundary as bub |
---|
52 | import prepare_timeboundary as TB |
---|
53 | |
---|
54 | #------------------------------------------------------------------------------- |
---|
55 | # Copy scripts to time stamped output directory and capture screen |
---|
56 | # output to file. Copy script must be before screen_catcher |
---|
57 | #------------------------------------------------------------------------------- |
---|
58 | |
---|
59 | copy_code_files(project.output_run, __file__, |
---|
60 | os.path.join(os.path.dirname(project.__file__), |
---|
61 | project.__name__+'.py')) |
---|
62 | start_screen_catcher(project.output_run, 0, 1) |
---|
63 | |
---|
64 | #------------------------------------------------------------------------------- |
---|
65 | # Create the computational domain based on overall clipping polygon with |
---|
66 | # a tagged boundary and interior regions defined in project.py along with |
---|
67 | # resolutions (maximal area of per triangle) for each polygon |
---|
68 | #------------------------------------------------------------------------------- |
---|
69 | |
---|
70 | print 'Create computational domain' |
---|
71 | |
---|
72 | # Create the STS file |
---|
73 | print 'project.mux_data_folder=%s' % project.mux_data_folder |
---|
74 | if not os.path.exists(project.event_sts_east + '.sts'): |
---|
75 | bub.build_urs_boundary(project.mux_input_filename, project.event_sts_east, project.urs_order_east) |
---|
76 | if not os.path.exists(project.event_sts_west + '.sts'): |
---|
77 | bub.build_urs_boundary(project.mux_input_filename, project.event_sts_west, project.urs_order_west) |
---|
78 | |
---|
79 | # Read in boundary from ordered sts file |
---|
80 | event_sts_east = create_sts_boundary(project.event_sts_east) |
---|
81 | event_sts_west = create_sts_boundary(project.event_sts_west) |
---|
82 | |
---|
83 | # Reading the landward defined points, this incorporates the original clipping |
---|
84 | # polygon minus the 100m contour |
---|
85 | landward_boundary_N = read_polygon(project.landward_boundary_N) |
---|
86 | landward_boundary_S = read_polygon(project.landward_boundary_S) |
---|
87 | |
---|
88 | ##print 'land N', landward_boundary_N, ' with length ', len(landward_boundary_N) |
---|
89 | ##print 'land S', landward_boundary_S, ' with length ', len(landward_boundary_S) |
---|
90 | |
---|
91 | # Combine sts polyline with landward points |
---|
92 | bounding_polygon_sts = landward_boundary_N + event_sts_east + landward_boundary_S + event_sts_west |
---|
93 | |
---|
94 | print 'bounding polygon sts',bounding_polygon_sts,'length',len(bounding_polygon_sts) |
---|
95 | |
---|
96 | # 4 sides: north (land), east (ocean), south (land), west (ocean) |
---|
97 | num_north_points = len(landward_boundary_N) |
---|
98 | num_east_points = len(event_sts_east) |
---|
99 | num_south_points = len(landward_boundary_S) |
---|
100 | num_west_points = len(event_sts_west) |
---|
101 | |
---|
102 | # Boundary tags refer to project.landward_boundary |
---|
103 | # 4 points equals 5 segments start at N |
---|
104 | boundary_tags={'back': range(num_north_points-1) + range(num_north_points+num_east_points,num_north_points+num_east_points+num_south_points-1), |
---|
105 | 'side': [num_north_points-1, |
---|
106 | num_north_points+num_east_points-1, |
---|
107 | num_north_points+num_east_points+num_south_points-1, |
---|
108 | num_north_points+num_east_points+num_south_points+num_west_points-1], |
---|
109 | 'oceanE': range(num_north_points,num_north_points+num_east_points-1), |
---|
110 | 'oceanW': range(num_north_points+num_east_points+num_south_points,num_north_points+num_east_points+num_south_points+num_west_points-1)} |
---|
111 | |
---|
112 | ##print 'tags',boundary_tags |
---|
113 | |
---|
114 | # Build mesh and domain |
---|
115 | domain = create_domain_from_regions(bounding_polygon_sts, |
---|
116 | boundary_tags=boundary_tags, |
---|
117 | maximum_triangle_area=project.bounding_maxarea, |
---|
118 | interior_regions=project.interior_regions, |
---|
119 | mesh_filename=project.meshes, |
---|
120 | use_cache=True, |
---|
121 | verbose=True) |
---|
122 | print domain.statistics() |
---|
123 | |
---|
124 | domain.set_name(project.scenario_name) |
---|
125 | domain.set_datadir(project.output_run) |
---|
126 | domain.set_minimum_storable_height(0.01) # Don't store depth less than 1cm |
---|
127 | |
---|
128 | #------------------------------------------------------------------------------- |
---|
129 | # Setup initial conditions |
---|
130 | #------------------------------------------------------------------------------- |
---|
131 | |
---|
132 | print 'Setup initial conditions' |
---|
133 | |
---|
134 | # Set the initial stage in the offcoast region only |
---|
135 | if project.land_initial_conditions: |
---|
136 | IC = Polygon_function(project.land_initial_conditions, |
---|
137 | default=project.tide, |
---|
138 | geo_reference=domain.geo_reference) |
---|
139 | else: |
---|
140 | IC = 0 |
---|
141 | domain.set_quantity('stage', IC, use_cache=True, verbose=True) |
---|
142 | domain.set_quantity('friction', project.friction) |
---|
143 | domain.set_quantity('elevation', |
---|
144 | filename=project.combined_elevation+'.pts', |
---|
145 | use_cache=True, |
---|
146 | verbose=True, |
---|
147 | alpha=project.alpha) |
---|
148 | |
---|
149 | #------------------------------------------------------------------------------- |
---|
150 | # Setup boundary conditions |
---|
151 | #------------------------------------------------------------------------------- |
---|
152 | |
---|
153 | print 'Set boundary - available tags:', domain.get_boundary_tags() |
---|
154 | |
---|
155 | # Prepare time boundary |
---|
156 | TB.prepare_timeboundary(project.boundary_csv) |
---|
157 | f = file_function(project.boundary_csv[:-4] + '.tms') |
---|
158 | |
---|
159 | Br = Reflective_boundary(domain) |
---|
160 | Bt = Transmissive_stage_zero_momentum_boundary(domain) |
---|
161 | Bd = Dirichlet_boundary([project.tide, 0, 0]) |
---|
162 | |
---|
163 | if project.wave == 'Bf': |
---|
164 | Bfe = Field_boundary(project.event_sts_east+'.sts', |
---|
165 | domain, mean_stage=project.tide, |
---|
166 | time_thinning=1, |
---|
167 | default_boundary=Dirichlet_boundary([0, 0, 0]), |
---|
168 | boundary_polygon=bounding_polygon_sts, |
---|
169 | use_cache=True, |
---|
170 | verbose=True) |
---|
171 | Bfw = Field_boundary(project.event_sts_west+'.sts', |
---|
172 | domain, mean_stage=project.tide, |
---|
173 | time_thinning=1, |
---|
174 | default_boundary=Dirichlet_boundary([0, 0, 0]), |
---|
175 | boundary_polygon=bounding_polygon_sts, |
---|
176 | use_cache=True, |
---|
177 | verbose=True) |
---|
178 | domain.set_boundary({'back': Br, |
---|
179 | 'side': Bt, |
---|
180 | 'oceanE': Bfe, |
---|
181 | 'oceanW': Bfw}) |
---|
182 | |
---|
183 | elif project.wave == 'Tb': |
---|
184 | Tb = Time_boundary(domain,f,default_boundary=Dirichlet_boundary([0, 0, 0]) ) |
---|
185 | |
---|
186 | if project.event_side == 'east' : |
---|
187 | domain.set_boundary({'back': Br, |
---|
188 | 'side': Bt, |
---|
189 | 'oceanW': Bt, |
---|
190 | 'oceanE': Tb}) |
---|
191 | elif project.event_side == 'west' : |
---|
192 | domain.set_boundary({'back': Br, |
---|
193 | 'side': Bt, |
---|
194 | 'oceanW': Tb, |
---|
195 | 'oceanE': Bt}) |
---|
196 | else: |
---|
197 | print 'need to specify which side event is on' |
---|
198 | |
---|
199 | else: |
---|
200 | print 'No wave specified in project script (Bf or Tb)' |
---|
201 | |
---|
202 | |
---|
203 | #------------------------------------------------------------------------------- |
---|
204 | # Evolve system through time |
---|
205 | #------------------------------------------------------------------------------- |
---|
206 | |
---|
207 | t0 = time.time() |
---|
208 | for t in domain.evolve(yieldstep=project.yieldstep, |
---|
209 | finaltime=project.finaltime, |
---|
210 | skip_initial_step=False): |
---|
211 | print domain.timestepping_statistics() |
---|
212 | print domain.boundary_statistics(tags='ocean') |
---|
213 | |
---|
214 | print 'Simulation took %.2f seconds' % (time.time()-t0) |
---|