1 | """Script for running a tsunami inundation scenario for Patong Beach, Thailand. |
---|
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_patong.py |
---|
5 | and a simulated tsunami for the 2004 event is generated through |
---|
6 | an sts file from build_boundary.py. |
---|
7 | |
---|
8 | Input: sts file (build_boundary.py) |
---|
9 | pts file (build_patong.py) |
---|
10 | information from project file |
---|
11 | Outputs: sww file stored in project.output_run_time_dir |
---|
12 | The export_results_all.py and get_timeseries.py is reliant |
---|
13 | on the outputs of this script |
---|
14 | |
---|
15 | """ |
---|
16 | |
---|
17 | #------------------------------------------------------------------------------ |
---|
18 | # Import necessary modules |
---|
19 | #------------------------------------------------------------------------------ |
---|
20 | |
---|
21 | # Standard modules |
---|
22 | from os import sep |
---|
23 | import os |
---|
24 | from os.path import dirname |
---|
25 | import time |
---|
26 | |
---|
27 | # Related major packages |
---|
28 | from anuga.interface import create_domain_from_regions |
---|
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.caching import cache |
---|
36 | from anuga.shallow_water.data_manager import start_screen_catcher, copy_code_files,store_parameters |
---|
37 | from anuga.utilities.polygon import read_polygon |
---|
38 | from polygon import Polygon_function |
---|
39 | |
---|
40 | # Application specific imports |
---|
41 | import project # Definition of file names and polygons |
---|
42 | numprocs = 1 |
---|
43 | myid = 0 |
---|
44 | |
---|
45 | |
---|
46 | |
---|
47 | #------------------------------------------------------------------------------ |
---|
48 | # Copy scripts to time stamped output directory and capture screen |
---|
49 | # output to file |
---|
50 | #------------------------------------------------------------------------------ |
---|
51 | |
---|
52 | #copy script must be before screen_catcher |
---|
53 | |
---|
54 | output_dir = project.output_run_time_dir |
---|
55 | print 'output_dir', output_dir |
---|
56 | |
---|
57 | copy_code_files(output_dir,__file__, |
---|
58 | dirname(project.__file__)+sep+ project.__name__+'.py' ) |
---|
59 | |
---|
60 | start_screen_catcher(output_dir, myid, numprocs) |
---|
61 | |
---|
62 | |
---|
63 | #----------------------------------------------------------------------- |
---|
64 | # Domain definitions |
---|
65 | #----------------------------------------------------------------------- |
---|
66 | |
---|
67 | # Read in boundary from ordered sts file |
---|
68 | urs_boundary_name = os.path.join(project.boundaries_dir, |
---|
69 | project.scenario_name) |
---|
70 | urs_bounding_polygon = create_sts_boundary(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 | # Counting 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], 'side': [N,N+4], 'ocean': range(N)} |
---|
84 | |
---|
85 | #-------------------------------------------------------------------------- |
---|
86 | # Create the computational domain based on overall clipping polygon with |
---|
87 | # a tagged boundary and interior regions defined in project.py along with |
---|
88 | # resolutions (maximal area of per triangle) for each polygon |
---|
89 | #-------------------------------------------------------------------------- |
---|
90 | |
---|
91 | domain = create_domain_from_regions(bounding_polygon, |
---|
92 | boundary_tags=boundary_tags, |
---|
93 | maximum_triangle_area=project.res_poly_all, |
---|
94 | interior_regions=project.interior_regions, |
---|
95 | mesh_filename=project.meshes_dir_name, |
---|
96 | use_cache=True, |
---|
97 | verbose=True) |
---|
98 | |
---|
99 | print domain.statistics() |
---|
100 | |
---|
101 | |
---|
102 | #------------------------------------------------------------------------- |
---|
103 | # Setup initial conditions |
---|
104 | #------------------------------------------------------------------------- |
---|
105 | print 'Setup initial conditions' |
---|
106 | |
---|
107 | # sets the initial stage in the offcoast region only |
---|
108 | IC = Polygon_function([(project.poly_mainland, 0)], |
---|
109 | default=project.tide, |
---|
110 | geo_reference=domain.geo_reference) |
---|
111 | print 'stage' |
---|
112 | domain.set_quantity('stage', IC, |
---|
113 | use_cache=True, |
---|
114 | verbose=True) |
---|
115 | print 'friction' |
---|
116 | domain.set_quantity('friction', project.friction) |
---|
117 | print 'elevation' |
---|
118 | domain.set_quantity('elevation', |
---|
119 | filename=project.combined_dir_name+'.pts', |
---|
120 | alpha=project.alpha, |
---|
121 | use_cache=True, |
---|
122 | verbose=True) |
---|
123 | |
---|
124 | |
---|
125 | # Add buildings from file |
---|
126 | print 'Reading building polygons' |
---|
127 | building_polygons, building_heights = csv2building_polygons(project.building_polygon_file) |
---|
128 | #clipping_polygons=project.building_area_polygons) |
---|
129 | |
---|
130 | print 'Creating %d building polygons' % len(building_polygons) |
---|
131 | def create_polygon_function(building_polygons, geo_reference=None): |
---|
132 | L = [] |
---|
133 | for i, key in enumerate(building_polygons): |
---|
134 | if i%100==0: print i |
---|
135 | poly = building_polygons[key] |
---|
136 | elev = building_heights[key] |
---|
137 | L.append((poly, elev)) |
---|
138 | |
---|
139 | buildings = Polygon_function(L, default=0.0, |
---|
140 | geo_reference=geo_reference) |
---|
141 | return buildings |
---|
142 | |
---|
143 | buildings = cache(create_polygon_function, |
---|
144 | building_polygons, |
---|
145 | {'geo_reference': domain.geo_reference}, |
---|
146 | verbose=True) |
---|
147 | |
---|
148 | print 'Adding buildings' |
---|
149 | domain.add_quantity('elevation', |
---|
150 | buildings, |
---|
151 | use_cache=False, # FIXME(OLE): This seems to pickup the stage IC?? |
---|
152 | verbose=True) |
---|
153 | |
---|
154 | |
---|
155 | |
---|
156 | #------------------------------------------------------ |
---|
157 | # Distribute domain to implement parallelism !!! |
---|
158 | #------------------------------------------------------ |
---|
159 | |
---|
160 | # if numprocs > 1: |
---|
161 | # domain=distribute(domain) |
---|
162 | |
---|
163 | #------------------------------------------------------ |
---|
164 | # Set domain parameters |
---|
165 | #------------------------------------------------------ |
---|
166 | domain.set_name(project.scenario_name) |
---|
167 | domain.set_datadir(output_dir) |
---|
168 | domain.set_default_order(2) # Apply second order scheme |
---|
169 | domain.set_minimum_storable_height(0.01) # Don't store anything less than 1cm |
---|
170 | |
---|
171 | #------------------------------------------------------------------------- |
---|
172 | # Setup boundary conditions |
---|
173 | #------------------------------------------------------------------------- |
---|
174 | print 'Set boundary conditions' |
---|
175 | |
---|
176 | Br = Reflective_boundary(domain) |
---|
177 | Bd = Dirichlet_boundary([project.tide,0,0]) |
---|
178 | Bf = Field_boundary(urs_boundary_name+'.sts', |
---|
179 | domain, |
---|
180 | mean_stage= project.tide, |
---|
181 | time_thinning=project.time_thinning, |
---|
182 | default_boundary=Bd, |
---|
183 | use_cache=True, |
---|
184 | verbose=True, |
---|
185 | boundary_polygon=bounding_polygon) |
---|
186 | |
---|
187 | domain.set_boundary({'back': Br, |
---|
188 | 'side': Bd, |
---|
189 | 'ocean': Bf}) |
---|
190 | |
---|
191 | |
---|
192 | #---------------------------------------------------------------------------- |
---|
193 | # Evolve system through time |
---|
194 | #-------------------------------------------------------------------- |
---|
195 | t0 = time.time() |
---|
196 | |
---|
197 | for t in domain.evolve(yieldstep=project.yieldstep, |
---|
198 | finaltime=project.finaltime): |
---|
199 | print domain.timestepping_statistics() |
---|
200 | print domain.boundary_statistics(tags='ocean') |
---|
201 | |
---|
202 | print 'Simulation took %.2f seconds' %(time.time()-t0) |
---|
203 | |
---|
204 | |
---|