source: anuga_work/production/onslow_2006/run_onslow_grad.py @ 4672

Last change on this file since 4672 was 4672, checked in by sexton, 16 years ago

incorporating graduate survey data into revised Onslow model

File size: 9.6 KB
Line 
1"""Script for running tsunami inundation scenario for Onslow, WA, Australia.
2
3Source data such as elevation and boundary data is assumed to be available in
4directories specified by project_grad_grad.py
5The output sww file is stored in project_grad_grad.output_run_time_dir
6
7The scenario is defined by a triangular mesh created from project_grad_grad.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,umask
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 Reflective_boundary
29from anuga.shallow_water import Field_boundary
30from Numeric import allclose
31
32
33from anuga.pmesh.mesh_interface import create_mesh_from_regions
34from anuga.shallow_water.data_manager import start_screen_catcher
35from anuga.shallow_water.data_manager import copy_code_files
36from anuga.shallow_water.data_manager import store_parameters
37from anuga_parallel.parallel_api import distribute, numprocs, myid, barrier
38from anuga_parallel.parallel_abstraction import get_processor_name
39from anuga.caching import myhash
40
41from anuga.shallow_water.data_manager import export_grid
42from anuga.damage_modelling.inundation_damage import add_depth_and_momentum2csv, inundation_damage
43
44# Application specific imports
45import project_grad_grad                 # Definition of file names and polygons
46
47def run_model(**kwargs):
48   
49    tide = kwargs['tide']
50    alpha = kwargs['alpha']
51    friction = kwargs['friction']
52    time_thinning = kwargs['time_thinning']
53    scenario_name = kwargs['aa_scenario_name']
54   
55    #------------------------------------------------------------------------------
56    # Copy scripts to time stamped output directory and capture screen
57    # output to file
58    #------------------------------------------------------------------------------
59
60    #copy script must be before screen_catcher
61    print 'tide',tide
62    kwargs['est_num_trigs']=project_grad.trigs_min
63    kwargs['num_cpu']=numprocs
64    kwargs['host']=project_grad.host
65    kwargs['res_factor']=project_grad.res_factor
66    kwargs['starttime']=project_grad.starttime
67    kwargs['yieldstep']=project_grad.yieldstep
68    kwargs['finaltime']=project_grad.finaltime
69   
70    kwargs['output_dir']=project_grad.output_run_time_dir
71    kwargs['bathy_file']=project_grad.combined_dir_name + '.pts'
72#    kwargs['bathy_file']=project_grad.combined_small_dir_name + '.pts'
73    kwargs['boundary_file']=project_grad.boundary_name + '.sww'
74#    kwargs['Completed']=''
75
76    print 'output_dir',kwargs['output_dir']
77    if myid == 0:
78        copy_code_files(kwargs['output_dir'],__file__, 
79                        dirname(project_grad.__file__)+sep+project_grad.__name__+'.py' )
80
81        store_parameters(**kwargs)
82
83    barrier()
84
85    start_screen_catcher(kwargs['output_dir'], myid, numprocs)
86
87    print 'Processor Name:', get_processor_name()
88
89    #--------------------------------------------------------------------------
90    # Create the triangular mesh based on overall clipping polygon with a
91    # tagged
92    # boundary and interior regions defined in project_grad.py along with
93    # resolutions (maximal area of per triangle) for each polygon
94    #--------------------------------------------------------------------------
95
96    #IMPORTANT don't cache create_mesh_from_region and Domain(mesh....) as it
97    # causes problems with the ability to cache set quantity which takes alot of times
98
99    # FIXME (Ole): Move to build_shark_bay.py
100    if myid == 0:
101   
102        print 'start create mesh from regions'
103       
104        create_mesh_from_regions(project_grad.bounding_polygon,
105                                 boundary_tags=project_grad.boundary_tags,
106                                 maximum_triangle_area=project_grad.res_bounding_polygon,
107                                 interior_regions=project_grad.interior_regions,
108                                 filename=project_grad.mesh_name+'.msh',
109                                 use_cache=False,
110                                 verbose=True)
111
112    #-------------------------------------------------------------------------
113    # Setup computational domain
114    #-------------------------------------------------------------------------
115    print 'Setup computational domain'
116
117    #domain = cache(Domain, (mesh_name), {'use_cache':True, 'verbose':True}, verbose=True)
118    #above don't work
119    domain = Domain(project_grad.mesh_name+'.msh',
120                    use_cache=False, verbose=True)
121     
122    print domain.statistics()
123    print 'triangles',len(domain)
124   
125    kwargs['act_num_trigs']=len(domain)
126
127    #-------------------------------------------------------------------------
128    # Setup initial conditions
129    #-------------------------------------------------------------------------
130    if myid == 0:
131
132        IC = project_grad.tide
133        #if project_grad.tide == 0.0:
134        #    print 'Tide is MSL'
135        #    IC = 0.0
136        #else:   
137        #    print 'Create onshore polygon'
138        #    from polygon import Polygon_function
139        #    #following sets the stage/water to be offcoast only
140        #    IC = Polygon_function([(project_grad.onshore_polygon, -1.0)],
141        #                          default = tide,
142        #                          geo_reference = domain.geo_reference)
143           
144
145        print 'Set initial conditions'
146        domain.set_quantity('stage', IC)
147        domain.set_quantity('friction', friction)
148        print 'Set elevation'
149        domain.set_quantity('elevation', 
150                            filename = kwargs['bathy_file'],
151                            use_cache = True,
152                            verbose = True,
153                            alpha = alpha)
154       
155
156    #------------------------------------------------------
157    # Distribute domain to implement parallelism !!!
158    #------------------------------------------------------
159    barrier()
160    if numprocs > 1:
161        domain=distribute(domain)
162
163    #------------------------------------------------------
164    # Set domain parameters
165    #------------------------------------------------------
166    print 'domain id', id(domain)
167    domain.set_name(scenario_name)
168    domain.set_datadir(kwargs['output_dir'])
169    domain.set_default_order(2) # Apply second order scheme
170    domain.set_minimum_storable_height(0.01) # Don't store anything less than 1cm
171    domain.set_store_vertices_uniquely(False)
172    domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
173    domain.set_maximum_allowed_speed(0.1) # Allow a little runoff (0.1 is OK)
174    print 'domain id', id(domain)
175    domain.beta_h = 0
176    #domain.tight_slope_limiters = 1
177   
178
179    #-------------------------------------------------------------------------
180    # Setup boundary conditions
181    #-------------------------------------------------------------------------
182    print 'Available boundary tags', domain.get_boundary_tags()
183    print 'domain id', id(domain)
184    #print 'Reading Boundary file',project_grad.boundaries_dir_namea + '.sww'
185
186    Bf = Field_boundary(kwargs['boundary_file'],
187                        domain,
188                        time_thinning=time_thinning,
189                        mean_stage=tide,
190                        momentum_scale=project_grad.momentum_scale,                       
191                        use_cache=False,
192                        verbose=True)
193                   
194    kwargs['input_start_time']=domain.starttime
195
196    print 'finished reading boundary file'
197
198    Br = Reflective_boundary(domain)
199    Bd = Dirichlet_boundary([tide,0,0])
200
201    print'set_boundary'
202
203    domain.set_boundary({'back': Br,
204                         'side': Bd,
205                         'ocean': Bf})
206
207    print'finish set boundary'
208
209    #----------------------------------------------------------------------------
210    # Evolve system through time
211    #----------------------------------------------------------------------------
212
213    t0 = time.time()
214
215    for t in domain.evolve(yieldstep = 240, finaltime = kwargs['starttime']): 
216        domain.write_time()
217        domain.write_boundary_statistics(tags = 'ocean')     
218
219    for t in domain.evolve(yieldstep = kwargs['yieldstep'], finaltime = 21600
220                       ,skip_initial_step = True): 
221        domain.write_time()
222        domain.write_boundary_statistics(tags = 'ocean')     
223   
224    for t in domain.evolve(yieldstep = 240, finaltime = kwargs['finaltime']
225                       ,skip_initial_step = True): 
226        domain.write_time()
227        domain.write_boundary_statistics(tags = 'ocean')   
228
229    x, y = domain.get_maximum_inundation_location()
230    q = domain.get_maximum_inundation_elevation()
231
232    print 'Maximum runup observed at (%.2f, %.2f) with elevation %.2f' %(x,y,q)
233
234    print 'That took %.2f seconds' %(time.time()-t0)
235   
236    kwargs['completed']=str(time.time()-t0)
237   
238    store_parameters(**kwargs)
239
240#-------------------------------------------------------------
241if __name__ == "__main__":
242
243    run_model(file_name=project_grad.home+'detail.csv', aa_scenario_name=project_grad.scenario_name,
244              ab_time=project_grad.time, res_factor= project_grad.res_factor, tide=project_grad.tide, user=project_grad.user,
245              alpha = project_grad.alpha, friction=project_grad.friction,
246              time_thinning = project_grad.time_thinning,
247              dir_comment=project_grad.dir_comment)
248
249
Note: See TracBrowser for help on using the repository browser.