source: anuga_work/production/dampier_2006/run_dampier.py @ 4282

Last change on this file since 4282 was 4282, checked in by nick, 17 years ago

update to dampier

File size: 9.2 KB
Line 
1"""Script for running tsunami inundation scenario for Dampier, WA, Australia.
2
3Source data such as elevation and boundary data is assumed to be available in
4directories specified by project.py
5The output sww file is stored in project.output_run_time_dir
6
7The scenario is defined by a triangular mesh created from project.polygon,
8the elevation data and a simulated tsunami generated with URS code.
9
10Ole 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
18from os import sep
19from os.path import dirname, basename
20from os import mkdir, access, F_OK
21from shutil import copy
22import time
23import sys
24
25# Related major packages
26from anuga.shallow_water import Domain
27from anuga.shallow_water import Dirichlet_boundary
28from anuga.shallow_water import File_boundary
29from anuga.shallow_water import Reflective_boundary
30from Numeric import allclose
31
32from anuga.pmesh.mesh_interface import create_mesh_from_regions
33from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files
34from anuga_parallel.parallel_api import distribute, numprocs, myid, barrier
35from anuga_parallel.parallel_abstraction import get_processor_name
36from anuga.caching import myhash
37# Application specific imports
38import project                 # Definition of file names and polygons
39
40#------------------------------------------------------------------------------
41# Copy scripts to time stamped output directory and capture screen
42# output to file
43#------------------------------------------------------------------------------
44
45start_screen_catcher(project.output_run_time_dir, myid, numprocs)
46print "Processor Name:",get_processor_name()
47
48# filenames
49#boundaries_name = project.boundaries_name
50meshes_dir_name = project.meshes_dir_name+'.msh'
51#boundaries_dir_name = project.boundaries_dir_name
52
53tide = project.tide
54
55# creates copy of code in output dir
56if myid == 0:
57    copy_code_files(project.output_run_time_dir,__file__, 
58                 dirname(project.__file__)+sep+ project.__name__+'.py' )
59barrier()
60
61print 'USER: ', project.user
62print 'min triangles', project.trigs_min,
63print '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'''
72poly = [[0,0],[0,100],[100,100],[100,0]]
73
74create_mesh_from_regions(poly,
75                             boundary_tags={'back': [0], 'side': [1,3],
76                                            'ocean': [2]},
77                             maximum_triangle_area=1,
78                             interior_regions=None,
79                             filename=meshes_dir_name,
80                             use_cache=True,
81                             verbose=True)
82
83sys.exit()
84
85if myid == 0:
86   
87    print 'start create mesh from regions'
88#    print 'project.res_poly_all',project.res_poly_all
89#    print 'project.interior_regions_test',project.interior_regions_test
90#    print 'meshes_dir_name',meshes_dir_name
91    create_mesh_from_regions(project.poly_all,
92                             boundary_tags={'back': [2,3], 'side': [0, 1, 4],
93                                            'ocean': [5]},
94                             maximum_triangle_area=project.res_poly_all,
95                             interior_regions=project.interior_regions_test,
96                             filename=meshes_dir_name,
97                             use_cache=True,
98                             verbose=True)
99
100# to sync all processors are ready
101barrier()
102'''
103create_mesh_from_regions(project.poly_all,
104                             boundary_tags={'back': [2,3], 'side': [0, 1, 4],
105                                            'ocean': [5]},
106                             maximum_triangle_area=project.res_poly_all,
107                             interior_regions=project.interior_regions_test,
108                             filename=meshes_dir_name,
109                             use_cache=True,
110                             verbose=True)
111
112#-------------------------------------------------------------------------
113# Setup computational domain
114#-------------------------------------------------------------------------
115print 'Setup computational domain'
116from caching import cache
117domain = cache(Domain, (meshes_dir_name), {'use_cache':True, 'verbose':True}, verbose=True)
118print 'domain id', id(domain) 
119print 'myhash', myhash(domain)     
120       
121print domain.statistics()
122
123boundaries_dir_name=project.boundaries_dir_name
124
125print 'starting to create boundary conditions'
126
127from anuga.shallow_water.data_manager import urs2sww
128'''
129# put above distribute
130print 'boundary file is: ',project.boundaries_dir_name
131from caching import cache
132if myid == 0:
133    cache(urs2sww,
134          (project.boundaries_in_dir_name,
135           project.boundaries_dir_name),
136          {'verbose': True,
137           'minlat': project.south_boundary,
138           'maxlat': project.north_boundary,
139           'minlon': project.west_boundary,
140           'maxlon': project.east_boundary,
141           'mint': 0, 'maxt': 35100,
142           'origin': domain.geo_reference.get_origin(),
143           'mean_stage': project.tide,
144#           'zscale': 1,                 #Enhance tsunami
145           'fail_on_NaN': False},
146           verbose = True,
147           )
148barrier()
149'''
150
151#-------------------------------------------------------------------------
152# Setup initial conditions
153#-------------------------------------------------------------------------
154if myid == 0:
155
156    print 'Setup initial conditions'
157
158    from polygon import *
159    #following sets the stage/water to be offcoast only
160    IC = Polygon_function( [(project.poly_bathy, 0.)], default = tide)
161    domain.set_quantity('stage', IC)
162    domain.set_quantity('friction', 0.01) 
163    print 'Start Set quantity'
164
165    domain.set_quantity('elevation', 
166#                    filename = project.combined_dir_name + '.pts',
167# MUST USE TXT FILES FOR CACHING TO WORK!
168                    filename = project.combined_smaller_dir_name + '.txt',
169                    use_cache = True,
170                    verbose = True,
171                    alpha = 0.1)
172    print 'Finished Set quantity'
173barrier()
174
175
176#------------------------------------------------------
177# Distribute domain to implement parallelism !!!
178#------------------------------------------------------
179
180if numprocs > 1:
181    domain=distribute(domain)
182
183#------------------------------------------------------
184# Set domain parameters
185#------------------------------------------------------
186print 'domain id', id(domain)
187domain.set_name(project.scenario_name)
188domain.set_datadir(project.output_run_time_dir)
189domain.set_default_order(2) # Apply second order scheme
190domain.set_minimum_storable_height(0.01) # Don't store anything less than 1cm
191domain.set_store_vertices_uniquely(False)
192domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
193domain.set_maximum_allowed_speed(0.1) # Allow a little runoff (0.1 is OK)
194print 'domain id', id(domain)
195domain.beta_h = 0
196domain.limit2007 = 1
197
198#-------------------------------------------------------------------------
199# Setup boundary conditions
200#-------------------------------------------------------------------------
201print 'Available boundary tags', domain.get_boundary_tags()
202print 'domain id', id(domain)
203print 'Reading Boundary file',project.boundaries_dir_name4 + '.sww'
204#Bf = File_boundary(boundaries_dir_name + '.sww',
205Bf = File_boundary(project.boundaries_dir_name4 + '.sww',
206                  domain, time_thinning=4, use_cache=True, verbose=True)
207
208print 'finished reading boundary file'
209
210Br = Reflective_boundary(domain)
211Bd = Dirichlet_boundary([tide,0,0])
212
213print'set_boundary'
214##domain.set_boundary({'back': Br,
215##                     'side': Bf,
216##                     'ocean': Bf})
217domain.set_boundary({'back': Br,
218                     'side': Bd,
219                     'ocean': Bf}) 
220print'finish set boundary'
221
222#----------------------------------------------------------------------------
223# Evolve system through time
224#----------------------------------------------------------------------------
225
226t0 = time.time()
227
228for t in domain.evolve(yieldstep = 60, finaltime = 9000):
229    domain.write_time()
230    domain.write_boundary_statistics(tags = 'ocean')
231
232#for t in domain.evolve(yieldstep = 120, finaltime = 9000):
233#    domain.write_time()
234#    domain.write_boundary_statistics(tags = 'ocean')
235     
236for t in domain.evolve(yieldstep = 60, finaltime = 28800
237                       ,skip_initial_step = True):
238    domain.write_time()
239    domain.write_boundary_statistics(tags = 'ocean')   
240
241for t in domain.evolve(yieldstep = 120, finaltime = 34800
242                       ,skip_initial_step = True): 
243    domain.write_time()
244    domain.write_boundary_statistics(tags = 'ocean')   
245
246x, y = domain.get_maximum_inundation_location()
247q = domain.get_maximum_inundation_elevation()
248
249print 'Maximum runup observed at (%.2f, %.2f) with elevation %.2f' %(x,y,q)
250
251print 'That took %.2f seconds' %(time.time()-t0)
252
Note: See TracBrowser for help on using the repository browser.