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 anuga.shallow_water import Field_boundary |
---|
28 | from Numeric import allclose |
---|
29 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
30 | from anuga.geospatial_data.geospatial_data import * |
---|
31 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files |
---|
32 | from anuga_parallel.parallel_api import distribute, numprocs, myid, barrier |
---|
33 | from anuga.utilities.polygon import plot_polygons, polygon_area |
---|
34 | from anuga_parallel.parallel_abstraction import get_processor_name |
---|
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 | if myid == 0: |
---|
45 | copy_code_files(project.output_run_time_dir,__file__, |
---|
46 | dirname(project.__file__)+sep+ project.__name__+'.py' ) |
---|
47 | barrier() |
---|
48 | |
---|
49 | start_screen_catcher(project.output_run_time_dir, myid, numprocs) |
---|
50 | |
---|
51 | # filenames |
---|
52 | boundaries_name = project.scenario |
---|
53 | meshes_dir_name = project.meshes_dir_name+'.msh' |
---|
54 | boundaries_dir_name = project.boundaries_dir_name |
---|
55 | |
---|
56 | tide = project.tide |
---|
57 | |
---|
58 | # creates copy of code in output dir |
---|
59 | print "Processor Name:",get_processor_name() |
---|
60 | |
---|
61 | print 'USER: ', project.user |
---|
62 | print 'min triangles', project.trigs_min, |
---|
63 | print 'Note: This is generally about 20% less than the final amount' |
---|
64 | |
---|
65 | #-------------------------------------------------------------------------- |
---|
66 | # Create the triangular mesh based on overall clipping polygon with a |
---|
67 | # tagged |
---|
68 | # boundary and interior regions defined in project.py along with |
---|
69 | # resolutions (maximal area of per triangle) for each polygon |
---|
70 | #-------------------------------------------------------------------------- |
---|
71 | |
---|
72 | if myid == 0: |
---|
73 | |
---|
74 | print 'start create mesh from regions' |
---|
75 | create_mesh_from_regions(project.poly_all, |
---|
76 | # boundary_tags={'back': [1, 2], 'side': [0,3], |
---|
77 | # 'ocean': [4, 5, 6]}, |
---|
78 | boundary_tags={'back': [1, 2], 'side': [0,3], |
---|
79 | 'ocean': [4]}, |
---|
80 | maximum_triangle_area=project.res_poly_all, |
---|
81 | interior_regions=project.interior_regions, |
---|
82 | filename=meshes_dir_name, |
---|
83 | use_cache=False, |
---|
84 | verbose=True) |
---|
85 | |
---|
86 | # to sync all processors are ready |
---|
87 | barrier() |
---|
88 | |
---|
89 | #------------------------------------------------------------------------- |
---|
90 | # Setup computational domain |
---|
91 | #------------------------------------------------------------------------- |
---|
92 | print 'Setup computational domain' |
---|
93 | #domain = Domain(meshes_time_dir_name, use_cache=True, verbose=True) |
---|
94 | domain = Domain(meshes_dir_name, use_cache=False, verbose=True) |
---|
95 | print domain.statistics() |
---|
96 | |
---|
97 | #------------------------------------------------------------------------- |
---|
98 | # Setup initial conditions |
---|
99 | #------------------------------------------------------------------------- |
---|
100 | if myid == 0: |
---|
101 | |
---|
102 | print 'Setup initial conditions' |
---|
103 | |
---|
104 | from polygon import Polygon_function |
---|
105 | #following sets the stage/water to be offcoast only |
---|
106 | IC = Polygon_function( [(project.poly_mainland, -1.0)], default = tide, |
---|
107 | geo_reference = domain.geo_reference) |
---|
108 | domain.set_quantity('stage', IC) |
---|
109 | #combined_time_dir_name = project.topographies_dir+build_time+project.combined_name |
---|
110 | print 'Start Set quantity' |
---|
111 | print 'project.combined_dir_name_unclipped1',project.combined_dir_name_unclipped1+'.txt' |
---|
112 | domain.set_quantity('elevation', |
---|
113 | # filename = project.combined_dir_name+'.txt', |
---|
114 | filename = project.combined_dir_name_unclipped1+'.txt', |
---|
115 | # filename = project.combined_smaller_name_dir+'.xya', |
---|
116 | use_cache = True, |
---|
117 | verbose = True, |
---|
118 | alpha = 0.1) |
---|
119 | print 'Finished Set quantity' |
---|
120 | barrier() |
---|
121 | |
---|
122 | #------------------------------------------------------ |
---|
123 | # Distribute domain to implement parallelism !!! |
---|
124 | #------------------------------------------------------ |
---|
125 | |
---|
126 | if numprocs > 1: |
---|
127 | domain=distribute(domain) |
---|
128 | |
---|
129 | #------------------------------------------------------ |
---|
130 | # Set domain parameters |
---|
131 | #------------------------------------------------------ |
---|
132 | |
---|
133 | domain.set_name(project.scenario_name) |
---|
134 | domain.set_datadir(project.output_run_time_dir) |
---|
135 | domain.set_default_order(2) # Apply second order scheme |
---|
136 | domain.set_minimum_storable_height(0.01) # Don't store anything less than 1cm |
---|
137 | domain.set_store_vertices_uniquely(False) |
---|
138 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
139 | domain.set_maximum_allowed_speed(0.1) # Allow a little runoff (0.1 is OK) |
---|
140 | |
---|
141 | #------------------------------------------------------------------------- |
---|
142 | # Setup boundary conditions |
---|
143 | #------------------------------------------------------------------------- |
---|
144 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
145 | |
---|
146 | print 'Reading Boundary file' |
---|
147 | print 'domain id', id(domain) |
---|
148 | #Bf = File_boundary(boundaries_dir_name + '.sww', |
---|
149 | # domain, time_thinning=12, use_cache=True, verbose=True) |
---|
150 | Bf = Field_boundary(boundaries_dir_name + '.sww', |
---|
151 | domain, time_thinning=1, mean_stage=tide, |
---|
152 | use_cache=True, verbose=True) |
---|
153 | |
---|
154 | print 'finished reading boundary file' |
---|
155 | Br = Reflective_boundary(domain) |
---|
156 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
157 | Bo = Dirichlet_boundary([tide+5.0,0,0]) |
---|
158 | |
---|
159 | print'set_boundary' |
---|
160 | domain.set_boundary({'back': Br, |
---|
161 | 'side': Bd, |
---|
162 | 'ocean': Bf}) |
---|
163 | # 'ocean': Bd}) |
---|
164 | print'finish set boundary' |
---|
165 | |
---|
166 | #---------------------------------------------------------------------------- |
---|
167 | # Evolve system through time |
---|
168 | #---------------------------------------------------------------------------- |
---|
169 | |
---|
170 | t0 = time.time() |
---|
171 | |
---|
172 | for t in domain.evolve(yieldstep = 60, finaltime = 30000): |
---|
173 | domain.write_time() |
---|
174 | domain.write_boundary_statistics(tags = 'ocean') |
---|
175 | # if allclose(t, 120): |
---|
176 | # domain.set_boundary({'back': Br, 'side': Bd, 'ocean': Bo}) |
---|
177 | |
---|
178 | # if allclose(t, 1020): |
---|
179 | # domain.set_boundary({'back': Br, 'side': Bd, 'ocean': Bd}) |
---|
180 | |
---|
181 | |
---|
182 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
183 | |
---|