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 | print 'hello' |
---|
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 | import sys |
---|
66 | sys.exit() |
---|
67 | #-------------------------------------------------------------------------- |
---|
68 | # Create the triangular mesh based on overall clipping polygon with a |
---|
69 | # tagged |
---|
70 | # boundary and interior regions defined in project.py along with |
---|
71 | # resolutions (maximal area of per triangle) for each polygon |
---|
72 | #-------------------------------------------------------------------------- |
---|
73 | |
---|
74 | if myid == 0: |
---|
75 | |
---|
76 | print 'start create mesh from regions' |
---|
77 | create_mesh_from_regions(project.poly_all, |
---|
78 | boundary_tags={'back': [4], 'side': [0,3], |
---|
79 | 'ocean': [1, 2]}, |
---|
80 | maximum_triangle_area=project.res_poly_all, |
---|
81 | interior_regions=project.interior_regions, |
---|
82 | # filename=meshes_time_dir_name, |
---|
83 | filename=meshes_dir_name, |
---|
84 | use_cache=True, |
---|
85 | verbose=True) |
---|
86 | |
---|
87 | # to sync all processors are ready |
---|
88 | barrier() |
---|
89 | |
---|
90 | #------------------------------------------------------------------------- |
---|
91 | # Setup computational domain |
---|
92 | #------------------------------------------------------------------------- |
---|
93 | print 'Setup computational domain' |
---|
94 | #domain = Domain(meshes_time_dir_name, use_cache=True, verbose=True) |
---|
95 | domain = Domain(meshes_dir_name, use_cache=True, verbose=True) |
---|
96 | print domain.statistics() |
---|
97 | |
---|
98 | #------------------------------------------------------------------------- |
---|
99 | # Setup initial conditions |
---|
100 | #------------------------------------------------------------------------- |
---|
101 | if myid == 0: |
---|
102 | |
---|
103 | print 'Setup initial conditions' |
---|
104 | |
---|
105 | domain.set_quantity('stage', tide) |
---|
106 | domain.set_quantity('friction', 0.01) |
---|
107 | #combined_time_dir_name = project.topographies_dir+build_time+project.combined_name |
---|
108 | print 'Start Set quantity' |
---|
109 | |
---|
110 | domain.set_quantity('elevation', |
---|
111 | filename = project.combined_dir_name+'.txt', |
---|
112 | # filename = project.combined_smaller_name_dir+'.txt', |
---|
113 | use_cache = True, |
---|
114 | verbose = True, |
---|
115 | alpha = 0.1) |
---|
116 | print 'Finished Set quantity' |
---|
117 | barrier() |
---|
118 | |
---|
119 | #------------------------------------------------------ |
---|
120 | # Distribute domain to implement parallelism !!! |
---|
121 | #------------------------------------------------------ |
---|
122 | |
---|
123 | if numprocs > 1: |
---|
124 | domain=distribute(domain) |
---|
125 | |
---|
126 | #------------------------------------------------------ |
---|
127 | # Set domain parameters |
---|
128 | #------------------------------------------------------ |
---|
129 | |
---|
130 | domain.set_name(project.scenario_name) |
---|
131 | domain.set_datadir(project.output_run_time_dir) |
---|
132 | domain.set_default_order(2) # Apply second order scheme |
---|
133 | domain.set_minimum_storable_height(0.001) # Don't store anything less than 0.1cm |
---|
134 | #domain.set_minimum_storable_height(0.01) # Don't store anything less than 1cm |
---|
135 | #domain.set_minimum_storable_height(0.1) # Don't store anything less than 10cm |
---|
136 | domain.set_store_vertices_uniquely(False) |
---|
137 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
138 | domain.set_maximum_allowed_speed(0.1) # Allow a little runoff (0.1 is OK) |
---|
139 | |
---|
140 | #------------------------------------------------------------------------- |
---|
141 | # Setup boundary conditions |
---|
142 | #------------------------------------------------------------------------- |
---|
143 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
144 | |
---|
145 | print 'Reading Boundary file' |
---|
146 | print 'domain id', id(domain) |
---|
147 | #Bf = File_boundary(boundaries_dir_name + '.sww', |
---|
148 | # domain, time_thinning=5, use_cache=True, verbose=True) |
---|
149 | |
---|
150 | print 'finished reading boundary file' |
---|
151 | Br = Reflective_boundary(domain) |
---|
152 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
153 | Bo = Dirichlet_boundary([tide+5.0,0,0]) |
---|
154 | |
---|
155 | print'set_boundary' |
---|
156 | domain.set_boundary({'back': Br, |
---|
157 | 'side': Bd, |
---|
158 | 'ocean': Bd}) |
---|
159 | print'finish set boundary' |
---|
160 | |
---|
161 | #---------------------------------------------------------------------------- |
---|
162 | # Evolve system through time |
---|
163 | #---------------------------------------------------------------------------- |
---|
164 | |
---|
165 | t0 = time.time() |
---|
166 | |
---|
167 | for t in domain.evolve(yieldstep = 60, finaltime = 10000): |
---|
168 | domain.write_time() |
---|
169 | domain.write_boundary_statistics(tags = 'ocean') |
---|
170 | if allclose(t, 120): |
---|
171 | domain.set_boundary({'back': Br, 'side': Bd, 'ocean': Bo}) |
---|
172 | |
---|
173 | if allclose(t, 1020): |
---|
174 | domain.set_boundary({'back': Br, 'side': Bd, 'ocean': Bd}) |
---|
175 | |
---|
176 | |
---|
177 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
178 | |
---|