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 time |
---|
25 | |
---|
26 | # Related major packages |
---|
27 | from anuga.interface import create_domain_from_regions |
---|
28 | from anuga.interface import Transmissive_stage_zero_momentum_boundary |
---|
29 | from anuga.interface import Dirichlet_boundary |
---|
30 | from anuga.interface import Reflective_boundary |
---|
31 | from anuga.interface import Field_boundary |
---|
32 | from anuga.interface import create_sts_boundary |
---|
33 | from anuga.interface import csv2building_polygons |
---|
34 | |
---|
35 | from anuga.shallow_water.data_manager import start_screen_catcher |
---|
36 | from anuga.shallow_water.data_manager import copy_code_files |
---|
37 | from anuga.utilities.polygon import read_polygon, Polygon_function |
---|
38 | |
---|
39 | # Application specific imports |
---|
40 | import project # Definition of file names and polygons |
---|
41 | import build_urs_boundary as bub |
---|
42 | |
---|
43 | |
---|
44 | #------------------------------------------------------------------------------- |
---|
45 | # Perform (as much as possible) a sanity check on values from import of project. |
---|
46 | #------------------------------------------------------------------------------- |
---|
47 | |
---|
48 | #------------------------------------------------------------------------------- |
---|
49 | # Copy scripts to time stamped output directory and capture screen |
---|
50 | # output to file. Copy script must be before screen_catcher |
---|
51 | #------------------------------------------------------------------------------- |
---|
52 | |
---|
53 | copy_code_files(project.output_run, __file__, |
---|
54 | os.path.join(os.path.dirname(project.__file__), |
---|
55 | project.__name__+'.py')) |
---|
56 | start_screen_catcher(project.output_run, 0, 1) |
---|
57 | |
---|
58 | #------------------------------------------------------------------------------- |
---|
59 | # Create the computational domain based on overall clipping polygon with |
---|
60 | # a tagged boundary and interior regions defined in project.py along with |
---|
61 | # resolutions (maximal area of per triangle) for each polygon |
---|
62 | #------------------------------------------------------------------------------- |
---|
63 | |
---|
64 | print 'Create computational domain' |
---|
65 | |
---|
66 | # Create the STS file |
---|
67 | bub.build_urs_boundary(os.path.join(project.muxhome, 'mux'), |
---|
68 | project.mux_input_filename, |
---|
69 | os.path.join(project.event_folder, |
---|
70 | project.scenario_name)) |
---|
71 | |
---|
72 | # Read in boundary from ordered sts file |
---|
73 | event_sts = create_sts_boundary(project.event_sts) |
---|
74 | |
---|
75 | # Reading the landward defined points, this incorporates the original clipping |
---|
76 | # polygon minus the 100m contour |
---|
77 | landward_boundary = read_polygon(project.landward_boundary) |
---|
78 | |
---|
79 | # Combine sts polyline with landward points |
---|
80 | bounding_polygon_sts = event_sts + landward_boundary |
---|
81 | |
---|
82 | # Number of boundary segments |
---|
83 | N = len(event_sts) - 1 |
---|
84 | |
---|
85 | # Boundary tags refer to project.landward_boundary |
---|
86 | # 4 points equals 5 segments start at N |
---|
87 | boundary_tags={'back': [N+1, N+2, N+3, N+4, N+5, N+6, N+7], |
---|
88 | 'side': [N, N+8], |
---|
89 | 'ocean': range(N)} |
---|
90 | |
---|
91 | # Build mesh and domain |
---|
92 | domain = create_domain_from_regions(bounding_polygon_sts, |
---|
93 | boundary_tags=boundary_tags, |
---|
94 | maximum_triangle_area=project.bounding_maxarea, |
---|
95 | interior_regions=project.interior_regions, |
---|
96 | mesh_filename=project.meshes, |
---|
97 | use_cache=True, |
---|
98 | verbose=True) |
---|
99 | print domain.statistics() |
---|
100 | |
---|
101 | domain.set_name(project.scenario_name) |
---|
102 | domain.set_datadir(project.output_run) |
---|
103 | domain.set_minimum_storable_height(0.01) # Don't store depth less than 1cm |
---|
104 | |
---|
105 | #------------------------------------------------------------------------------- |
---|
106 | # Setup initial conditions |
---|
107 | #------------------------------------------------------------------------------- |
---|
108 | |
---|
109 | print 'Setup initial conditions' |
---|
110 | |
---|
111 | # Set the initial stage in the offcoast region only |
---|
112 | IC = Polygon_function(project.land_initial_conditions, |
---|
113 | default=project.tide, |
---|
114 | geo_reference=domain.geo_reference) |
---|
115 | domain.set_quantity('stage', IC, use_cache=True, verbose=True) |
---|
116 | domain.set_quantity('friction', project.friction) |
---|
117 | domain.set_quantity('elevation', |
---|
118 | filename=project.combined_elevation+'.pts', |
---|
119 | use_cache=True, |
---|
120 | verbose=True, |
---|
121 | alpha=project.alpha) |
---|
122 | |
---|
123 | #------------------------------------------------------------------------------- |
---|
124 | # Setup boundary conditions |
---|
125 | #------------------------------------------------------------------------------- |
---|
126 | |
---|
127 | print 'Set boundary - available tags:', domain.get_boundary_tags() |
---|
128 | |
---|
129 | Br = Reflective_boundary(domain) |
---|
130 | Bt = Transmissive_stage_zero_momentum_boundary(domain) |
---|
131 | Bd = Dirichlet_boundary([kwargs['tide'], 0, 0]) |
---|
132 | Bf = Field_boundary(project.event_sts+'.sts', |
---|
133 | domain, mean_stage=project.tide, |
---|
134 | time_thinning=1, |
---|
135 | default_boundary=Bd, |
---|
136 | boundary_polygon=bounding_polygon_sts, |
---|
137 | use_cache=True, |
---|
138 | verbose=True) |
---|
139 | |
---|
140 | domain.set_boundary({'back': Br, |
---|
141 | 'side': Bt, |
---|
142 | 'ocean': Bf}) |
---|
143 | |
---|
144 | #------------------------------------------------------------------------------- |
---|
145 | # Evolve system through time |
---|
146 | #------------------------------------------------------------------------------- |
---|
147 | |
---|
148 | t0 = time.time() |
---|
149 | for t in domain.evolve(yieldstep=project.yieldstep, |
---|
150 | finaltime=project.finaltime, |
---|
151 | skip_initial_step=False): |
---|
152 | print domain.timestepping_statistics() |
---|
153 | print domain.boundary_statistics(tags='ocean') |
---|
154 | |
---|
155 | print 'Simulation took %.2f seconds' % (time.time()-t0) |
---|