1 | """Script for running a tsunami inundation scenario for busselton, WA, Australia. |
---|
2 | |
---|
3 | The scenario is defined by a triangular mesh created from project.polygon, |
---|
4 | the elevation data is compiled into a pts file through build_busselton.py |
---|
5 | and a 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_busselton.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 | # Note repeated use of domain id |
---|
19 | # Note naming of fundamental datasets and directories |
---|
20 | |
---|
21 | |
---|
22 | #------------------------------------------------------------------------------ |
---|
23 | # Import necessary modules |
---|
24 | #------------------------------------------------------------------------------ |
---|
25 | |
---|
26 | # Standard modules |
---|
27 | from os import sep |
---|
28 | import os |
---|
29 | from os.path import dirname, basename |
---|
30 | from os import mkdir, access, F_OK |
---|
31 | from shutil import copy |
---|
32 | import time |
---|
33 | import sys |
---|
34 | |
---|
35 | # Related major packages |
---|
36 | from anuga.interface import create_domain_from_regions |
---|
37 | from anuga.interface import Dirichlet_boundary |
---|
38 | from anuga.interface import Reflective_boundary |
---|
39 | from anuga.interface import Field_boundary |
---|
40 | from anuga.interface import create_sts_boundary |
---|
41 | from anuga.interface import csv2building_polygons |
---|
42 | |
---|
43 | from anuga.shallow_water.data_manager import start_screen_catcher |
---|
44 | from anuga.shallow_water.data_manager import copy_code_files |
---|
45 | from anuga.utilities.polygon import read_polygon, Polygon_function |
---|
46 | |
---|
47 | # Application specific imports |
---|
48 | import project # Definition of file names and polygons |
---|
49 | |
---|
50 | |
---|
51 | #----------------------------------------------------------------------- |
---|
52 | # Copy scripts to time stamped output directory and capture screen |
---|
53 | # output to file |
---|
54 | #----------------------------------------------------------------------- |
---|
55 | |
---|
56 | #copy script must be before screen_catcher |
---|
57 | #copy_code_files(project.output_run_time_dir, __file__, |
---|
58 | # dirname(project.__file__)+sep+ project.__name__+'.py' ) |
---|
59 | #start_screen_catcher(project.output_run_time_dir, myid, numprocs) |
---|
60 | |
---|
61 | |
---|
62 | #-------------------------------------------------------------------------- |
---|
63 | # Create the computational domain based on overall clipping polygon with |
---|
64 | # a tagged boundary and interior regions defined in project.py along with |
---|
65 | # resolutions (maximal area of per triangle) for each polygon |
---|
66 | #-------------------------------------------------------------------------- |
---|
67 | print 'Create computational domain' |
---|
68 | |
---|
69 | # Read in boundary from ordered sts file |
---|
70 | urs_bounding_polygon = create_sts_boundary(project.urs_boundary_name) |
---|
71 | |
---|
72 | # Reading the landward defined points, this incorporates the original clipping |
---|
73 | # polygon minus the 100m contour |
---|
74 | landward_bounding_polygon = read_polygon(project.landward_dir) |
---|
75 | |
---|
76 | # Combine sts polyline with landward points |
---|
77 | bounding_polygon = urs_bounding_polygon + landward_bounding_polygon |
---|
78 | |
---|
79 | # Number of boundary segments |
---|
80 | N = len(urs_bounding_polygon)-1 |
---|
81 | |
---|
82 | # Boundary tags refer to project.landward 4 points equals 5 segments start at N |
---|
83 | boundary_tags={'back': [N+1,N+2,N+3,N+4, N+5], |
---|
84 | 'side': [N,N+6], |
---|
85 | 'ocean': range(N)} |
---|
86 | |
---|
87 | # Build mesh and domain |
---|
88 | domain = create_domain_from_regions(bounding_polygon, |
---|
89 | boundary_tags=boundary_tags, |
---|
90 | maximum_triangle_area=project.res_poly_all, |
---|
91 | interior_regions=project.interior_regions, |
---|
92 | mesh_filename=project.meshes_dir_name, |
---|
93 | use_cache=True, |
---|
94 | verbose=True) |
---|
95 | print domain.statistics() |
---|
96 | |
---|
97 | |
---|
98 | domain.set_name(project.scenario_name) |
---|
99 | domain.set_datadir(project.output_run_time_dir) |
---|
100 | domain.set_minimum_storable_height(0.01) # Don't store depth less than 1cm |
---|
101 | |
---|
102 | #------------------------------------------------------------------------- |
---|
103 | # Setup initial conditions |
---|
104 | #------------------------------------------------------------------------- |
---|
105 | print 'Setup initial conditions' |
---|
106 | |
---|
107 | # Set the initial stage in the offcoast region only |
---|
108 | IC = Polygon_function([(project.poly_mainland, 0), |
---|
109 | (project.poly_marina, 0)], |
---|
110 | default=project.tide, |
---|
111 | geo_reference=domain.geo_reference) |
---|
112 | domain.set_quantity('stage', IC, use_cache=True, verbose=True) |
---|
113 | |
---|
114 | domain.set_quantity('friction', project.friction) |
---|
115 | |
---|
116 | domain.set_quantity('elevation', |
---|
117 | filename=project.combined_dir_name+'.pts', |
---|
118 | use_cache=True, |
---|
119 | verbose=True, |
---|
120 | alpha = project.alpha) |
---|
121 | |
---|
122 | |
---|
123 | #------------------------------------------------------------------------- |
---|
124 | # Setup boundary conditions |
---|
125 | #------------------------------------------------------------------------- |
---|
126 | |
---|
127 | print 'Set boundary - available tags:', domain.get_boundary_tags() |
---|
128 | |
---|
129 | boundary_urs_out=project.boundaries_dir_event + sep + project.scenario_name |
---|
130 | |
---|
131 | Br = Reflective_boundary(domain) |
---|
132 | Bd = Dirichlet_boundary([project.tide,0,0]) |
---|
133 | |
---|
134 | |
---|
135 | Bf = Field_boundary(boundary_urs_out+'.sts', |
---|
136 | domain, mean_stage=project.tide, |
---|
137 | time_thinning=1, |
---|
138 | default_boundary=Bd, |
---|
139 | boundary_polygon=bounding_polygon, |
---|
140 | use_cache=True, |
---|
141 | verbose=True) |
---|
142 | |
---|
143 | |
---|
144 | domain.set_boundary({'back': Br, |
---|
145 | 'side': Bd, |
---|
146 | 'ocean': Bf}) |
---|
147 | |
---|
148 | #------------------------------------------------------------------------- |
---|
149 | # Evolve system through time |
---|
150 | #------------------------------------------------------------------------- |
---|
151 | t0 = time.time() |
---|
152 | for t in domain.evolve(yieldstep=project.yieldstep, |
---|
153 | finaltime=project.finaltime, |
---|
154 | skip_initial_step=False): |
---|
155 | print domain.timestepping_statistics() |
---|
156 | print domain.boundary_statistics(tags='ocean') |
---|
157 | |
---|
158 | print 'Simulation took %.2f seconds' %(time.time()-t0) |
---|
159 | |
---|
160 | |
---|
161 | |
---|
162 | |
---|
163 | |
---|
164 | |
---|