1 | """Script for running tsunami inundation scenario for Dampier, WA, Australia. |
---|
2 | |
---|
3 | Source data such as elevation and boundary data is assumed to be available in |
---|
4 | directories specified by project.py |
---|
5 | The output sww file is stored in project.output_run_time_dir |
---|
6 | |
---|
7 | The scenario is defined by a triangular mesh created from project.polygon, |
---|
8 | the elevation data and a simulated tsunami generated with URS code. |
---|
9 | |
---|
10 | Ole Nielsen and Duncan Gray, GA - 2005 and Jane Sexton, Nick Bartzis, GA - 2006 |
---|
11 | """ |
---|
12 | |
---|
13 | #------------------------------------------------------------------------------ |
---|
14 | # Import necessary modules |
---|
15 | #------------------------------------------------------------------------------ |
---|
16 | |
---|
17 | # Standard modules |
---|
18 | from os import sep |
---|
19 | from os.path import dirname, basename |
---|
20 | from os import mkdir, access, F_OK |
---|
21 | from shutil import copy |
---|
22 | import time |
---|
23 | import sys |
---|
24 | |
---|
25 | # Related major packages |
---|
26 | from anuga.shallow_water import Domain |
---|
27 | from anuga.shallow_water import Dirichlet_boundary |
---|
28 | from anuga.shallow_water import File_boundary |
---|
29 | from anuga.shallow_water import Reflective_boundary |
---|
30 | from Numeric import allclose |
---|
31 | |
---|
32 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
33 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files |
---|
34 | from anuga_parallel.parallel_api import distribute, numprocs, myid, barrier |
---|
35 | |
---|
36 | # Application specific imports |
---|
37 | import project # Definition of file names and polygons |
---|
38 | |
---|
39 | #------------------------------------------------------------------------------ |
---|
40 | # Copy scripts to time stamped output directory and capture screen |
---|
41 | # output to file |
---|
42 | #------------------------------------------------------------------------------ |
---|
43 | |
---|
44 | start_screen_catcher(project.output_run_time_dir, myid, numprocs) |
---|
45 | |
---|
46 | # filenames |
---|
47 | #boundaries_name = project.boundaries_name |
---|
48 | meshes_dir_name = project.meshes_dir_name+'.msh' |
---|
49 | #boundaries_dir_name = project.boundaries_dir_name |
---|
50 | |
---|
51 | tide = project.tide |
---|
52 | |
---|
53 | # creates copy of code in output dir |
---|
54 | if myid == 0: |
---|
55 | copy_code_files(project.output_run_time_dir,__file__, |
---|
56 | dirname(project.__file__)+sep+ project.__name__+'.py' ) |
---|
57 | barrier() |
---|
58 | |
---|
59 | print 'USER: ', project.user |
---|
60 | print 'min triangles', project.trigs_min, |
---|
61 | print 'Note: This is generally about 20% less than the final amount' |
---|
62 | |
---|
63 | #-------------------------------------------------------------------------- |
---|
64 | # Create the triangular mesh based on overall clipping polygon with a |
---|
65 | # tagged |
---|
66 | # boundary and interior regions defined in project.py along with |
---|
67 | # resolutions (maximal area of per triangle) for each polygon |
---|
68 | #-------------------------------------------------------------------------- |
---|
69 | ''' |
---|
70 | poly = [[0,0],[0,100],[100,100],[100,0]] |
---|
71 | |
---|
72 | create_mesh_from_regions(poly, |
---|
73 | boundary_tags={'back': [0], 'side': [1,3], |
---|
74 | 'ocean': [2]}, |
---|
75 | maximum_triangle_area=1, |
---|
76 | interior_regions=None, |
---|
77 | filename=meshes_dir_name, |
---|
78 | use_cache=True, |
---|
79 | verbose=True) |
---|
80 | |
---|
81 | sys.exit() |
---|
82 | ''' |
---|
83 | if myid == 0: |
---|
84 | |
---|
85 | print 'start create mesh from regions' |
---|
86 | create_mesh_from_regions(project.poly_all, |
---|
87 | boundary_tags={'back': [2,3], 'side': [0, 1, 4], |
---|
88 | 'ocean': [5]}, |
---|
89 | maximum_triangle_area=project.res_poly_all, |
---|
90 | interior_regions=project.interior_regions, |
---|
91 | filename=meshes_dir_name, |
---|
92 | use_cache=True, |
---|
93 | verbose=True) |
---|
94 | |
---|
95 | # to sync all processors are ready |
---|
96 | barrier() |
---|
97 | |
---|
98 | #------------------------------------------------------------------------- |
---|
99 | # Setup computational domain |
---|
100 | #------------------------------------------------------------------------- |
---|
101 | print 'Setup computational domain' |
---|
102 | domain = Domain(meshes_dir_name, use_cache=True, verbose=True) |
---|
103 | print domain.statistics() |
---|
104 | boundaries_dir_name=project.boundaries_dir_name |
---|
105 | |
---|
106 | print 'starting to create boundary conditions' |
---|
107 | |
---|
108 | from anuga.shallow_water.data_manager import urs2sww |
---|
109 | |
---|
110 | # put above distribute |
---|
111 | print 'boundary file is: ',project.boundaries_dir_name |
---|
112 | from caching import cache |
---|
113 | if myid == 0: |
---|
114 | cache(urs2sww, |
---|
115 | (project.boundaries_in_dir_name, |
---|
116 | project.boundaries_dir_name), |
---|
117 | {'verbose': True, |
---|
118 | 'minlat': project.south_boundary, |
---|
119 | 'maxlat': project.north_boundary, |
---|
120 | 'minlon': project.west_boundary, |
---|
121 | 'maxlon': project.east_boundary, |
---|
122 | 'mint': 0, 'maxt': 35100, |
---|
123 | 'origin': domain.geo_reference.get_origin(), |
---|
124 | 'mean_stage': project.tide, |
---|
125 | # 'zscale': 1, #Enhance tsunami |
---|
126 | 'fail_on_NaN': False}, |
---|
127 | verbose = True, |
---|
128 | ) |
---|
129 | barrier() |
---|
130 | |
---|
131 | |
---|
132 | #------------------------------------------------------------------------- |
---|
133 | # Setup initial conditions |
---|
134 | #------------------------------------------------------------------------- |
---|
135 | if myid == 0: |
---|
136 | |
---|
137 | print 'Setup initial conditions' |
---|
138 | |
---|
139 | from polygon import * |
---|
140 | #following sets the stage/water to be offcoast only |
---|
141 | IC = Polygon_function( [(project.poly_bathy, 0.)], default = tide) |
---|
142 | domain.set_quantity('stage', IC) |
---|
143 | domain.set_quantity('friction', 0.01) |
---|
144 | print 'Start Set quantity' |
---|
145 | |
---|
146 | domain.set_quantity('elevation', |
---|
147 | # filename = project.combined_dir_name + '.pts', |
---|
148 | # MUST USE TXT FILES FOR CACHING TO WORK! |
---|
149 | filename = project.combined_dir_name + '.txt', |
---|
150 | use_cache = True, |
---|
151 | verbose = True, |
---|
152 | alpha = 0.1) |
---|
153 | print 'Finished Set quantity' |
---|
154 | barrier() |
---|
155 | |
---|
156 | |
---|
157 | #------------------------------------------------------ |
---|
158 | # Distribute domain to implement parallelism !!! |
---|
159 | #------------------------------------------------------ |
---|
160 | |
---|
161 | if numprocs > 1: |
---|
162 | domain=distribute(domain) |
---|
163 | |
---|
164 | #------------------------------------------------------ |
---|
165 | # Set domain parameters |
---|
166 | #------------------------------------------------------ |
---|
167 | |
---|
168 | domain.set_name(project.scenario_name) |
---|
169 | domain.set_datadir(project.output_run_time_dir) |
---|
170 | domain.set_default_order(2) # Apply second order scheme |
---|
171 | domain.set_minimum_storable_height(0.01) # Don't store anything less than 1cm |
---|
172 | domain.set_store_vertices_uniquely(False) |
---|
173 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
174 | domain.set_maximum_allowed_speed(0.1) # Allow a little runoff (0.1 is OK) |
---|
175 | |
---|
176 | #------------------------------------------------------------------------- |
---|
177 | # Setup boundary conditions |
---|
178 | #------------------------------------------------------------------------- |
---|
179 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
180 | print 'domain id', id(domain) |
---|
181 | print 'Reading Boundary file' |
---|
182 | Bf = File_boundary(boundaries_dir_name + '.sww', |
---|
183 | domain, time_thinning=1, use_cache=True, verbose=True) |
---|
184 | |
---|
185 | print 'finished reading boundary file' |
---|
186 | |
---|
187 | Br = Reflective_boundary(domain) |
---|
188 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
189 | |
---|
190 | print'set_boundary' |
---|
191 | ##domain.set_boundary({'back': Br, |
---|
192 | ## 'side': Bf, |
---|
193 | ## 'ocean': Bf}) |
---|
194 | domain.set_boundary({'back': Br, |
---|
195 | 'side': Bd, |
---|
196 | 'ocean': Bf}) |
---|
197 | print'finish set boundary' |
---|
198 | |
---|
199 | #---------------------------------------------------------------------------- |
---|
200 | # Evolve system through time |
---|
201 | #---------------------------------------------------------------------------- |
---|
202 | |
---|
203 | t0 = time.time() |
---|
204 | |
---|
205 | for t in domain.evolve(yieldstep = 120, finaltime = 9000): |
---|
206 | domain.write_time() |
---|
207 | domain.write_boundary_statistics(tags = 'ocean') |
---|
208 | |
---|
209 | #for t in domain.evolve(yieldstep = 120, finaltime = 9000): |
---|
210 | # domain.write_time() |
---|
211 | # domain.write_boundary_statistics(tags = 'ocean') |
---|
212 | |
---|
213 | for t in domain.evolve(yieldstep = 60, finaltime = 28800 |
---|
214 | ,skip_initial_step = True): |
---|
215 | domain.write_time() |
---|
216 | domain.write_boundary_statistics(tags = 'ocean') |
---|
217 | |
---|
218 | for t in domain.evolve(yieldstep = 120, finaltime = 34800 |
---|
219 | ,skip_initial_step = True): |
---|
220 | domain.write_time() |
---|
221 | domain.write_boundary_statistics(tags = 'ocean') |
---|
222 | |
---|
223 | x, y = domain.get_maximum_inundation_location() |
---|
224 | q = domain.get_maximum_inundation_elevation() |
---|
225 | |
---|
226 | print 'Maximum runup observed at (%.2f, %.2f) with elevation %.2f' %(x,y,q) |
---|
227 | |
---|
228 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
229 | |
---|