source: anuga_work/production/perth/run_perth.py @ 5415

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