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

Last change on this file since 5569 was 5569, checked in by kristy, 15 years ago

updated scripts for polyline boundary

File size: 10.1 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, create_sts_boundary
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
36#from 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
41from anuga.utilities.polygon import read_polygon, plot_polygons, polygon_area, is_inside_polygon
42
43# Application specific imports
44import project                 # Definition of file names and polygons
45numprocs = 1
46myid = 0
47
48def run_model(**kwargs):
49   
50
51    #------------------------------------------------------------------------------
52    # Copy scripts to time stamped output directory and capture screen
53    # output to file
54    #------------------------------------------------------------------------------
55    print "Processor Name:",get_processor_name()
56
57    #copy script must be before screen_catcher
58    #print kwargs
59
60    print 'output_dir',kwargs['output_dir']
61    if myid == 0:
62        copy_code_files(kwargs['output_dir'],__file__, 
63                 dirname(project.__file__)+sep+ project.__name__+'.py' )
64
65        store_parameters(**kwargs)
66
67   # barrier()
68
69    start_screen_catcher(kwargs['output_dir'], myid, numprocs)
70
71    print "Processor Name:",get_processor_name()
72
73   
74    #-----------------------------------------------------------------------
75    # Domain definitions
76    #-----------------------------------------------------------------------
77
78    # Read in boundary from ordered sts file
79    urs_bounding_polygon=create_sts_boundary(project.scenario_name)
80
81    # Reading the landward defined points, this incorporates the original clipping
82    # polygon minus the 100m contour
83    landward_bounding_polygon = read_polygon(project.polygons_dir+'landward_bounding_polygon.txt')
84
85    # Combine sts polyline with landward points
86    bounding_polygon = urs_bounding_polygon + landward_bounding_polygon
87   
88    # counting segments
89    N = len(urs_bounding_polygon)-1
90    boundary_tags={'back': [N+1,N+2,N+3], 'side': [N,N+4],'ocean': range(N)}
91
92   
93    #--------------------------------------------------------------------------
94    # Create the triangular mesh based on overall clipping polygon with a
95    # tagged
96    # boundary and interior regions defined in project.py along with
97    # resolutions (maximal area of per triangle) for each polygon
98    #--------------------------------------------------------------------------
99
100    #IMPORTANT don't cache create_mesh_from_region and Domain(mesh....) as it
101    # causes problems with the ability to cache set quantity which takes alot of times
102    if myid == 0:
103   
104        print 'start create mesh from regions'
105
106        create_mesh_from_regions(bounding_polygon,
107                             boundary_tags=boundary_tags,
108                             maximum_triangle_area=project.res_poly_all,
109                             interior_regions=project.interior_regions,
110                             filename=project.meshes_dir_name+'.msh',
111                             use_cache=True,
112                             verbose=True)
113   # barrier()
114   
115
116    #-------------------------------------------------------------------------
117    # Setup computational domain
118    #-------------------------------------------------------------------------
119    print 'Setup computational domain'
120
121    domain = Domain(project.meshes_dir_name+'.msh', use_cache=False, verbose=True)
122    print 'memory usage before del domain',mem_usage()
123       
124    print domain.statistics()
125    print 'triangles',len(domain)
126   
127    kwargs['act_num_trigs']=len(domain)
128
129
130    #-------------------------------------------------------------------------
131    # Setup initial conditions
132    #-------------------------------------------------------------------------
133    if myid == 0:
134
135        print 'Setup initial conditions'
136
137        from polygon import Polygon_function
138        #following sets the stage/water to be offcoast only
139        IC = Polygon_function( [(project.poly_mainland, 0)], default = kwargs['tide'],
140                                 geo_reference = domain.geo_reference)
141        domain.set_quantity('stage', IC)
142        #domain.set_quantity('stage',kwargs['tide'] )
143        domain.set_quantity('friction', kwargs['friction']) 
144       
145        print 'Start Set quantity',kwargs['elevation_file']
146
147        domain.set_quantity('elevation', 
148                            filename = kwargs['elevation_file'],
149                            use_cache = False,
150                            verbose = True,
151                            alpha = kwargs['alpha'])
152        print 'Finished Set quantity'
153    #barrier()
154
155
156    #------------------------------------------------------
157    # Distribute domain to implement parallelism !!!
158    #------------------------------------------------------
159
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(kwargs['aa_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.tight_slope_limiters = 1
174    #domain.set_maximum_allowed_speed(0.1) # Allow a little runoff (0.1 is OK)
175    print 'domain id', id(domain)
176
177
178    #-------------------------------------------------------------------------
179    # Setup boundary conditions
180    #-------------------------------------------------------------------------
181    print 'Available boundary tags', domain.get_boundary_tags()
182    print 'domain id', id(domain)
183   
184    boundary_urs_out=project.boundaries_dir_name
185   
186    print 'Available boundary tags', domain.get_boundary_tags()
187    Bf = File_boundary(boundary_urs_out+'.sts', 
188                   domain, time_thinning=1,
189                   use_cache=True,
190                   verbose = True,
191                   boundary_polygon=bounding_polygon)
192
193    Br = Reflective_boundary(domain)
194    Bd = Dirichlet_boundary([kwargs['tide'],0,0])
195
196    print 'start reading boundary file'
197
198##    Bf = Field_boundary(kwargs['boundary_file'],
199##                domain, time_thinning=kwargs['time_thinning'], mean_stage=kwargs['tide'],
200##                use_cache=False, verbose=True)
201
202    domain.set_boundary({'back': Br,
203                         'side': Bd,
204                         'ocean': Bf}) 
205
206    kwargs['input_start_time']=domain.starttime
207
208    print'finish set boundary'
209
210    #----------------------------------------------------------------------------
211    # Evolve system through time
212    #--------------------------------------------------------------------
213    t0 = time.time()
214
215    for t in domain.evolve(yieldstep = project.yieldstep, finaltime = kwargs['finaltime']
216                       ,skip_initial_step = False): 
217        domain.write_time()
218        domain.write_boundary_statistics(tags = 'ocean')   
219
220    x, y = domain.get_maximum_inundation_location()
221    q = domain.get_maximum_inundation_elevation()
222
223    print 'Maximum runup observed at (%.2f, %.2f) with elevation %.2f' %(x,y,q)
224
225    print 'That took %.2f seconds' %(time.time()-t0)
226
227    #kwargs 'completed' must be added to write the final parameters to file
228    kwargs['completed']=str(time.time()-t0)
229   
230    if myid==0:
231        store_parameters(**kwargs)
232   # barrier
233   
234    print 'memory usage before del domain1',mem_usage()
235   
236   
237#-------------------------------------------------------------
238if __name__ == "__main__":
239   
240    kwargs={}
241    kwargs['est_num_trigs']=project.trigs_min
242    kwargs['num_cpu']=numprocs
243    kwargs['host']=project.host
244    kwargs['res_factor']=project.res_factor
245    kwargs['starttime']=project.starttime
246    kwargs['yieldstep']=project.yieldstep
247    kwargs['finaltime']=project.finaltime
248   
249    kwargs['output_dir']=project.output_run_time_dir
250    kwargs['elevation_file']=project.combined_dir_name+'.pts'
251#    kwargs['elevation_file']=project.combined_small_dir_name + '.pts'
252    kwargs['boundary_file']=project.boundaries_in_dir_name + '.sww'
253    kwargs['file_name']=project.home+'detail.csv'
254    kwargs['aa_scenario_name']=project.scenario_name
255    kwargs['ab_time']=project.time
256    kwargs['res_factor']= project.res_factor
257    kwargs['tide']=project.tide
258    kwargs['user']=project.user
259    kwargs['alpha'] = project.alpha
260    kwargs['friction']=project.friction
261    kwargs['time_thinning'] = project.time_thinning
262    kwargs['dir_comment']=project.dir_comment
263    kwargs['export_cellsize']=project.export_cellsize
264   
265
266    run_model(**kwargs)
267     
268    if myid==0:
269        export_model(**kwargs)
270    #barrier
Note: See TracBrowser for help on using the repository browser.