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 | from anuga_parallel.parallel_abstraction import get_processor_name |
---|
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 | print "Processor Name:",get_processor_name() |
---|
46 | |
---|
47 | # filenames |
---|
48 | #boundaries_name = project.boundaries_name |
---|
49 | meshes_dir_name = project.meshes_dir_name+'.msh' |
---|
50 | #boundaries_dir_name = project.boundaries_dir_name |
---|
51 | |
---|
52 | tide = project.tide |
---|
53 | |
---|
54 | # creates copy of code in output dir |
---|
55 | if myid == 0: |
---|
56 | copy_code_files(project.output_run_time_dir,__file__, |
---|
57 | dirname(project.__file__)+sep+ project.__name__+'.py' ) |
---|
58 | barrier() |
---|
59 | |
---|
60 | print 'USER: ', project.user |
---|
61 | print 'min triangles', project.trigs_min, |
---|
62 | print 'Note: This is generally about 20% less than the final amount' |
---|
63 | |
---|
64 | #-------------------------------------------------------------------------- |
---|
65 | # Create the triangular mesh based on overall clipping polygon with a |
---|
66 | # tagged |
---|
67 | # boundary and interior regions defined in project.py along with |
---|
68 | # resolutions (maximal area of per triangle) for each polygon |
---|
69 | #-------------------------------------------------------------------------- |
---|
70 | ''' |
---|
71 | poly = [[0,0],[0,100],[100,100],[100,0]] |
---|
72 | |
---|
73 | create_mesh_from_regions(poly, |
---|
74 | boundary_tags={'back': [0], 'side': [1,3], |
---|
75 | 'ocean': [2]}, |
---|
76 | maximum_triangle_area=1, |
---|
77 | interior_regions=None, |
---|
78 | filename=meshes_dir_name, |
---|
79 | use_cache=True, |
---|
80 | verbose=True) |
---|
81 | |
---|
82 | sys.exit() |
---|
83 | ''' |
---|
84 | if myid == 0: |
---|
85 | |
---|
86 | print 'start create mesh from regions' |
---|
87 | create_mesh_from_regions(project.poly_all, |
---|
88 | boundary_tags={'back': [2,3], 'side': [0, 1, 4], |
---|
89 | 'ocean': [5]}, |
---|
90 | maximum_triangle_area=project.res_poly_all, |
---|
91 | interior_regions=project.interior_regions, |
---|
92 | filename=meshes_dir_name, |
---|
93 | use_cache=True, |
---|
94 | verbose=True) |
---|
95 | |
---|
96 | # to sync all processors are ready |
---|
97 | barrier() |
---|
98 | |
---|
99 | #------------------------------------------------------------------------- |
---|
100 | # Setup computational domain |
---|
101 | #------------------------------------------------------------------------- |
---|
102 | print 'Setup computational domain' |
---|
103 | domain = Domain(meshes_dir_name, use_cache=True, verbose=True) |
---|
104 | print domain.statistics() |
---|
105 | boundaries_dir_name=project.boundaries_dir_name |
---|
106 | |
---|
107 | print 'starting to create boundary conditions' |
---|
108 | |
---|
109 | from anuga.shallow_water.data_manager import urs2sww |
---|
110 | |
---|
111 | # put above distribute |
---|
112 | print 'boundary file is: ',project.boundaries_dir_name |
---|
113 | from caching import cache |
---|
114 | if myid == 0: |
---|
115 | cache(urs2sww, |
---|
116 | (project.boundaries_in_dir_name, |
---|
117 | project.boundaries_dir_name), |
---|
118 | {'verbose': True, |
---|
119 | 'minlat': project.south_boundary, |
---|
120 | 'maxlat': project.north_boundary, |
---|
121 | 'minlon': project.west_boundary, |
---|
122 | 'maxlon': project.east_boundary, |
---|
123 | 'mint': 0, 'maxt': 35100, |
---|
124 | 'origin': domain.geo_reference.get_origin(), |
---|
125 | 'mean_stage': project.tide, |
---|
126 | # 'zscale': 1, #Enhance tsunami |
---|
127 | 'fail_on_NaN': False}, |
---|
128 | verbose = True, |
---|
129 | ) |
---|
130 | barrier() |
---|
131 | |
---|
132 | |
---|
133 | #------------------------------------------------------------------------- |
---|
134 | # Setup initial conditions |
---|
135 | #------------------------------------------------------------------------- |
---|
136 | if myid == 0: |
---|
137 | |
---|
138 | print 'Setup initial conditions' |
---|
139 | |
---|
140 | from polygon import * |
---|
141 | #following sets the stage/water to be offcoast only |
---|
142 | IC = Polygon_function( [(project.poly_bathy, 0.)], default = tide) |
---|
143 | domain.set_quantity('stage', IC) |
---|
144 | domain.set_quantity('friction', 0.01) |
---|
145 | print 'Start Set quantity' |
---|
146 | |
---|
147 | domain.set_quantity('elevation', |
---|
148 | # filename = project.combined_dir_name + '.pts', |
---|
149 | # MUST USE TXT FILES FOR CACHING TO WORK! |
---|
150 | filename = project.combined_dir_name + '.txt', |
---|
151 | use_cache = False, |
---|
152 | verbose = True, |
---|
153 | alpha = 0.1) |
---|
154 | print 'Finished Set quantity' |
---|
155 | barrier() |
---|
156 | |
---|
157 | |
---|
158 | #------------------------------------------------------ |
---|
159 | # Distribute domain to implement parallelism !!! |
---|
160 | #------------------------------------------------------ |
---|
161 | |
---|
162 | if numprocs > 1: |
---|
163 | domain=distribute(domain) |
---|
164 | |
---|
165 | #------------------------------------------------------ |
---|
166 | # Set domain parameters |
---|
167 | #------------------------------------------------------ |
---|
168 | |
---|
169 | domain.set_name(project.scenario_name) |
---|
170 | domain.set_datadir(project.output_run_time_dir) |
---|
171 | domain.set_default_order(2) # Apply second order scheme |
---|
172 | domain.set_minimum_storable_height(0.01) # Don't store anything less than 1cm |
---|
173 | domain.set_store_vertices_uniquely(False) |
---|
174 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
175 | domain.set_maximum_allowed_speed(0.1) # Allow a little runoff (0.1 is OK) |
---|
176 | |
---|
177 | #------------------------------------------------------------------------- |
---|
178 | # Setup boundary conditions |
---|
179 | #------------------------------------------------------------------------- |
---|
180 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
181 | print 'domain id', id(domain) |
---|
182 | print 'Reading Boundary file' |
---|
183 | Bf = File_boundary(boundaries_dir_name + '.sww', |
---|
184 | domain, time_thinning=4, use_cache=True, verbose=True) |
---|
185 | |
---|
186 | print 'finished reading boundary file' |
---|
187 | |
---|
188 | Br = Reflective_boundary(domain) |
---|
189 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
190 | |
---|
191 | print'set_boundary' |
---|
192 | ##domain.set_boundary({'back': Br, |
---|
193 | ## 'side': Bf, |
---|
194 | ## 'ocean': Bf}) |
---|
195 | domain.set_boundary({'back': Br, |
---|
196 | 'side': Bd, |
---|
197 | 'ocean': Bf}) |
---|
198 | print'finish set boundary' |
---|
199 | |
---|
200 | #---------------------------------------------------------------------------- |
---|
201 | # Evolve system through time |
---|
202 | #---------------------------------------------------------------------------- |
---|
203 | |
---|
204 | t0 = time.time() |
---|
205 | |
---|
206 | for t in domain.evolve(yieldstep = 120, finaltime = 9000): |
---|
207 | domain.write_time() |
---|
208 | domain.write_boundary_statistics(tags = 'ocean') |
---|
209 | |
---|
210 | #for t in domain.evolve(yieldstep = 120, finaltime = 9000): |
---|
211 | # domain.write_time() |
---|
212 | # domain.write_boundary_statistics(tags = 'ocean') |
---|
213 | |
---|
214 | for t in domain.evolve(yieldstep = 60, finaltime = 28800 |
---|
215 | ,skip_initial_step = True): |
---|
216 | domain.write_time() |
---|
217 | domain.write_boundary_statistics(tags = 'ocean') |
---|
218 | |
---|
219 | for t in domain.evolve(yieldstep = 120, finaltime = 34800 |
---|
220 | ,skip_initial_step = True): |
---|
221 | domain.write_time() |
---|
222 | domain.write_boundary_statistics(tags = 'ocean') |
---|
223 | |
---|
224 | x, y = domain.get_maximum_inundation_location() |
---|
225 | q = domain.get_maximum_inundation_elevation() |
---|
226 | |
---|
227 | print 'Maximum runup observed at (%.2f, %.2f) with elevation %.2f' %(x,y,q) |
---|
228 | |
---|
229 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
230 | |
---|