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