source: anuga_work/production/busselton/run_busselton.py @ 5578

Last change on this file since 5578 was 5578, checked in by kristy, 16 years ago

updated sts boundary

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