1 | """Script for running tsunami inundation scenario for Perth, 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.geospatial_data.geospatial_data import * |
---|
34 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files |
---|
35 | from anuga_parallel.parallel_api import distribute, numprocs, myid, barrier |
---|
36 | from anuga.utilities.polygon import plot_polygons, polygon_area |
---|
37 | |
---|
38 | # Application specific imports |
---|
39 | import project # Definition of file names and polygons |
---|
40 | |
---|
41 | #------------------------------------------------------------------------------ |
---|
42 | # Copy scripts to time stamped output directory and capture screen |
---|
43 | # output to file |
---|
44 | #------------------------------------------------------------------------------ |
---|
45 | |
---|
46 | start_screen_catcher(project.output_run_time_dir, myid, numprocs) |
---|
47 | |
---|
48 | # filenames |
---|
49 | boundaries_name = project.scenario |
---|
50 | meshes_dir_name = project.meshes_dir_name+'.msh' |
---|
51 | #boundaries_time_dir_name = project.boundaries_time_dir_name |
---|
52 | boundaries_dir_name = project.boundaries_dir_name |
---|
53 | |
---|
54 | tide = project.tide |
---|
55 | |
---|
56 | # creates copy of code in output dir |
---|
57 | if myid == 0: |
---|
58 | copy_code_files(project.output_run_time_dir,__file__, |
---|
59 | dirname(project.__file__)+sep+ project.__name__+'.py' ) |
---|
60 | barrier() |
---|
61 | |
---|
62 | print 'USER: ', project.user |
---|
63 | print 'min triangles', project.trigs_min, |
---|
64 | print 'Note: This is generally about 20% less than the final amount' |
---|
65 | |
---|
66 | #-------------------------------------------------------------------------- |
---|
67 | # Create the triangular mesh based on overall clipping polygon with a |
---|
68 | # tagged |
---|
69 | # boundary and interior regions defined in project.py along with |
---|
70 | # resolutions (maximal area of per triangle) for each polygon |
---|
71 | #-------------------------------------------------------------------------- |
---|
72 | |
---|
73 | if myid == 0: |
---|
74 | |
---|
75 | print 'start create mesh from regions' |
---|
76 | # interior_regions = [[project.poly_pos20_neg20, project.res_pos20_neg20], |
---|
77 | # [project.poly_cbd, project.res_cbd], |
---|
78 | # [project.poly_penguin, project.res_penguin]] |
---|
79 | # [project.poly_interior, 1000]] |
---|
80 | |
---|
81 | # from anuga.utilities.polygon import plot_polygons |
---|
82 | # figname = project.output_run_time_dir + 'poly_pic' |
---|
83 | # plot_polygons([project.poly_coast,project.poly_pipeline,project.poly_facility, |
---|
84 | # project.bounding_polygon], |
---|
85 | # figname, |
---|
86 | # verbose = True) |
---|
87 | # import sys; sys.exit() |
---|
88 | |
---|
89 | print 'start create mesh from regions' |
---|
90 | create_mesh_from_regions(project.poly_all, |
---|
91 | boundary_tags={'back': [4], 'side': [0,3], |
---|
92 | 'ocean': [1, 2]}, |
---|
93 | maximum_triangle_area=project.res_poly_all, |
---|
94 | interior_regions=project.interior_regions, |
---|
95 | # filename=meshes_time_dir_name, |
---|
96 | filename=meshes_dir_name, |
---|
97 | use_cache=True, |
---|
98 | verbose=True) |
---|
99 | |
---|
100 | # to sync all processors are ready |
---|
101 | barrier() |
---|
102 | |
---|
103 | #------------------------------------------------------------------------- |
---|
104 | # Setup computational domain |
---|
105 | #------------------------------------------------------------------------- |
---|
106 | print 'Setup computational domain' |
---|
107 | #domain = Domain(meshes_time_dir_name, use_cache=True, verbose=True) |
---|
108 | domain = Domain(meshes_dir_name, use_cache=True, verbose=True) |
---|
109 | print domain.statistics() |
---|
110 | ''' |
---|
111 | print 'starting to create boundary conditions' |
---|
112 | boundaries_in_dir_name = project.boundaries_in_dir_name |
---|
113 | |
---|
114 | from anuga.shallow_water.data_manager import urs2sww, ferret2sww |
---|
115 | |
---|
116 | # put above distribute |
---|
117 | print 'boundary file is: ',boundaries_dir_name |
---|
118 | from caching import cache |
---|
119 | if myid == 0: |
---|
120 | cache(ferret2sww, |
---|
121 | (boundaries_in_dir_name, |
---|
122 | # boundaries_time_dir_name), |
---|
123 | boundaries_dir_name), |
---|
124 | {'verbose': True, |
---|
125 | 'minlat': project.south_boundary, |
---|
126 | 'maxlat': project.north_boundary, |
---|
127 | 'minlon': project.west_boundary, |
---|
128 | 'maxlon': project.east_boundary, |
---|
129 | # 'minlat': project.south, |
---|
130 | # 'maxlat': project.north, |
---|
131 | # 'minlon': project.west, |
---|
132 | # 'maxlon': project.east, |
---|
133 | 'mint': 0, 'maxt': 35100, |
---|
134 | 'origin': domain.geo_reference.get_origin(), |
---|
135 | 'mean_stage': project.tide, |
---|
136 | # 'zscale': 1, #Enhance tsunami |
---|
137 | 'fail_on_NaN': False}, |
---|
138 | verbose = True, |
---|
139 | ) |
---|
140 | barrier() |
---|
141 | ''' |
---|
142 | |
---|
143 | #------------------------------------------------------------------------- |
---|
144 | # Setup initial conditions |
---|
145 | #------------------------------------------------------------------------- |
---|
146 | if myid == 0: |
---|
147 | |
---|
148 | print 'Setup initial conditions' |
---|
149 | |
---|
150 | domain.set_quantity('stage', tide) |
---|
151 | domain.set_quantity('friction', 0.01) |
---|
152 | #combined_time_dir_name = project.topographies_dir+build_time+project.combined_name |
---|
153 | print 'Start Set quantity' |
---|
154 | |
---|
155 | domain.set_quantity('elevation', |
---|
156 | # filename = project.combined_dir_name+'.txt', |
---|
157 | filename = project.combined_smaller_name_dir+'.txt', |
---|
158 | use_cache = True, |
---|
159 | verbose = True, |
---|
160 | alpha = 0.1) |
---|
161 | print 'Finished Set quantity' |
---|
162 | barrier() |
---|
163 | |
---|
164 | #------------------------------------------------------ |
---|
165 | # Distribute domain to implement parallelism !!! |
---|
166 | #------------------------------------------------------ |
---|
167 | |
---|
168 | if numprocs > 1: |
---|
169 | domain=distribute(domain) |
---|
170 | |
---|
171 | #------------------------------------------------------ |
---|
172 | # Set domain parameters |
---|
173 | #------------------------------------------------------ |
---|
174 | |
---|
175 | domain.set_name(project.scenario_name) |
---|
176 | domain.set_datadir(project.output_run_time_dir) |
---|
177 | domain.set_default_order(2) # Apply second order scheme |
---|
178 | domain.set_minimum_storable_height(0.01) # Don't store anything less than 1cm |
---|
179 | domain.set_store_vertices_uniquely(False) |
---|
180 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
181 | domain.set_maximum_allowed_speed(0.1) # Allow a little runoff (0.1 is OK) |
---|
182 | |
---|
183 | #------------------------------------------------------------------------- |
---|
184 | # Setup boundary conditions |
---|
185 | #------------------------------------------------------------------------- |
---|
186 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
187 | |
---|
188 | print 'Reading Boundary file' |
---|
189 | print 'domain id', id(domain) |
---|
190 | #Bf = File_boundary(boundaries_dir_name + '.sww', |
---|
191 | # domain, time_thinning=5, use_cache=True, verbose=True) |
---|
192 | |
---|
193 | print 'finished reading boundary file' |
---|
194 | Br = Reflective_boundary(domain) |
---|
195 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
196 | Bo = Dirichlet_boundary([tide+5.0,0,0]) |
---|
197 | |
---|
198 | print'set_boundary' |
---|
199 | domain.set_boundary({'back': Br, |
---|
200 | 'side': Bd, |
---|
201 | 'ocean': Bd}) |
---|
202 | print'finish set boundary' |
---|
203 | |
---|
204 | #---------------------------------------------------------------------------- |
---|
205 | # Evolve system through time |
---|
206 | #---------------------------------------------------------------------------- |
---|
207 | |
---|
208 | t0 = time.time() |
---|
209 | |
---|
210 | for t in domain.evolve(yieldstep = 60, finaltime = 10000): |
---|
211 | domain.write_time() |
---|
212 | domain.write_boundary_statistics(tags = 'ocean') |
---|
213 | if allclose(t, 120): |
---|
214 | domain.set_boundary({'back': Br, 'side': Bd, 'ocean': Bo}) |
---|
215 | |
---|
216 | if allclose(t, 1020): |
---|
217 | domain.set_boundary({'back': Br, 'side': Bd, 'ocean': Bd}) |
---|
218 | |
---|
219 | |
---|
220 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
221 | |
---|