source: anuga_work/production/geraldton/run_geraldton.py @ 5714

Last change on this file since 5714 was 5669, checked in by kristy, 17 years ago

Updated

File size: 11.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
19import os
20from os.path import dirname, basename
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
43from anuga.geospatial_data.geospatial_data import find_optimal_smoothing_parameter
44from Scientific.IO.NetCDF import NetCDFFile
45
46# Application specific imports
47import project                 # Definition of file names and polygons
48numprocs = 1
49myid = 0
50
51def run_model(**kwargs):
52   
53
54    #------------------------------------------------------------------------------
55    # Copy scripts to time stamped output directory and capture screen
56    # output to file
57    #------------------------------------------------------------------------------
58    print "Processor Name:",get_processor_name()
59
60    #copy script must be before screen_catcher
61    #print kwargs
62
63    print 'output_dir',kwargs['output_dir']
64    if myid == 0:
65        copy_code_files(kwargs['output_dir'],__file__, 
66                 dirname(project.__file__)+sep+ project.__name__+'.py' )
67
68        store_parameters(**kwargs)
69
70   # barrier()
71
72    start_screen_catcher(kwargs['output_dir'], myid, numprocs)
73
74    print "Processor Name:",get_processor_name()
75
76   
77    #-----------------------------------------------------------------------
78    # Domain definitions
79    #-----------------------------------------------------------------------
80##
81##    # Read in boundary from ordered sts file
82##    urs_bounding_polygon=create_sts_boundary(os.path.join(project.boundaries_dir,project.scenario_name))
83##
84##    # Reading the landward defined points, this incorporates the original clipping
85##    # polygon minus the 100m contour
86##    landward_bounding_polygon = read_polygon(project.boundaries_dir+'landward_boundary.txt')
87##
88##    # Combine sts polyline with landward points
89##    bounding_polygon = urs_bounding_polygon + landward_bounding_polygon
90##   
91##    # counting segments
92##    N = len(urs_bounding_polygon)-1
93##    boundary_tags={'back': [N+2,N+3], 'side': [N,N+1,N+4],'ocean': range(N)}
94
95    bounding_polygon = project.poly_all
96   
97
98   
99    #--------------------------------------------------------------------------
100    # Create the triangular mesh based on overall clipping polygon with a
101    # tagged
102    # boundary and interior regions defined in project.py along with
103    # resolutions (maximal area of per triangle) for each polygon
104    #--------------------------------------------------------------------------
105
106    #IMPORTANT don't cache create_mesh_from_region and Domain(mesh....) as it
107    # causes problems with the ability to cache set quantity which takes alot of times
108    if myid == 0:
109   
110        print 'start create mesh from regions'
111
112        create_mesh_from_regions(bounding_polygon,
113                             boundary_tags=project.boundary_tags,
114                             maximum_triangle_area=project.res_poly_all,
115                             interior_regions=project.interior_regions,
116                             filename=project.meshes_dir_name+'.msh',
117                             use_cache=True,
118                             verbose=True)
119   # barrier()
120
121##        covariance_value,alpha = find_optimal_smoothing_parameter (data_file= kwargs['elevation_file'],
122##                                alpha_list=[0.001, 0.01, 0.1, 0.15, 0.2, 0.25, 0.3, 0.4, 0.5],
123##                                mesh_file = project.meshes_dir_name+'.msh')
124##        print 'optimal alpha', covariance_value,alpha       
125
126    #-------------------------------------------------------------------------
127    # Setup computational domain
128    #-------------------------------------------------------------------------
129    print 'Setup computational domain'
130
131    domain = Domain(project.meshes_dir_name+'.msh', use_cache=False, verbose=True)
132    print 'memory usage before del domain',mem_usage()
133       
134    print domain.statistics()
135    print 'triangles',len(domain)
136   
137    kwargs['act_num_trigs']=len(domain)
138
139
140    #-------------------------------------------------------------------------
141    # Setup initial conditions
142    #-------------------------------------------------------------------------
143    if myid == 0:
144
145        print 'Setup initial conditions'
146
147        from polygon import Polygon_function
148        #following sets the stage/water to be offcoast only
149        IC = Polygon_function( [(project.poly_mainland, 0)], default = kwargs['tide'],
150                                 geo_reference = domain.geo_reference)
151        domain.set_quantity('stage', IC)
152        #domain.set_quantity('stage',kwargs['tide'] )
153        domain.set_quantity('friction', kwargs['friction']) 
154       
155        print 'Start Set quantity',kwargs['elevation_file']
156
157        domain.set_quantity('elevation', 
158                            filename = kwargs['elevation_file'],
159                            use_cache = False,
160                            verbose = True,
161                            alpha = kwargs['alpha'])
162        print 'Finished Set quantity'
163    #barrier()
164
165##    #------------------------------------------------------
166##    # Create x,y,z file of mesh vertex!!!
167##    #------------------------------------------------------
168##        coord = domain.get_vertex_coordinates()
169##        depth = domain.get_quantity('elevation')
170##       
171##        # Write vertex coordinates to file
172##        filename=project.vertex_filename
173##        fid=open(filename,'w')
174##        fid.write('x (m), y (m), z(m)\n')
175##        for i in range(len(coord)):
176##            pt=coord[i]
177##            x=pt[0]
178##            y=pt[1]
179##            z=depth[i]
180##            fid.write('%.6f,%.6f,%.6f\n' %(x, y, z))
181##
182
183    #------------------------------------------------------
184    # Distribute domain to implement parallelism !!!
185    #------------------------------------------------------
186
187    if numprocs > 1:
188        domain=distribute(domain)
189
190    #------------------------------------------------------
191    # Set domain parameters
192    #------------------------------------------------------
193    print 'domain id', id(domain)
194    domain.set_name(kwargs['aa_scenario_name'])
195    domain.set_datadir(kwargs['output_dir'])
196    domain.set_default_order(2) # Apply second order scheme
197    domain.set_minimum_storable_height(0.01) # Don't store anything less than 1cm
198    domain.set_store_vertices_uniquely(False)
199    domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
200    domain.tight_slope_limiters = 1
201    print 'domain id', id(domain)
202
203    #-------------------------------------------------------------------------
204    # Setup boundary conditions
205    #-------------------------------------------------------------------------
206    print 'Available boundary tags', domain.get_boundary_tags()
207    print 'domain id', id(domain)
208   
209    boundary_urs_out=project.boundaries_dir_name
210   
211    print 'Available boundary tags', domain.get_boundary_tags()
212    Bf = Field_boundary(boundary_urs_out+'.sts',  # Change from file_boundary
213                   domain, mean_stage= project.tide,
214                   time_thinning=1,
215                   use_cache=True,
216                   verbose = True,
217                   boundary_polygon=bounding_polygon)
218
219   
220    Br = Reflective_boundary(domain)
221    Bd = Dirichlet_boundary([kwargs['tide'],0,0])
222
223##    Bf = Field_boundary(kwargs['boundary_file'],
224##                domain, time_thinning=kwargs['time_thinning'], mean_stage=kwargs['tide'],
225##                use_cache=False, verbose=True)
226
227    domain.set_boundary({'back': Br,
228                         'side': Bd,
229                         'ocean': Bd}) # change baxk to Bf when running properly
230
231    kwargs['input_start_time']=domain.starttime
232
233    print'finish set boundary'
234
235    #----------------------------------------------------------------------------
236    # Evolve system through time
237    #--------------------------------------------------------------------
238    t0 = time.time()
239
240    for t in domain.evolve(yieldstep = project.yieldstep, finaltime = kwargs['finaltime']
241                       ,skip_initial_step = False): 
242        domain.write_time()
243        domain.write_boundary_statistics(tags = 'ocean')
244
245           
246    x, y = domain.get_maximum_inundation_location()
247    q = domain.get_maximum_inundation_elevation()
248
249    print 'Maximum runup observed at (%.2f, %.2f) with elevation %.2f' %(x,y,q)
250
251    print 'That took %.2f seconds' %(time.time()-t0)
252
253    #kwargs 'completed' must be added to write the final parameters to file
254    kwargs['completed']=str(time.time()-t0)
255   
256    if myid==0:
257        store_parameters(**kwargs)
258   # barrier
259   
260    print 'memory usage before del domain1',mem_usage()
261   
262   
263#-------------------------------------------------------------
264if __name__ == "__main__":
265   
266    kwargs={}
267    kwargs['est_num_trigs']=project.trigs_min
268    kwargs['num_cpu']=numprocs
269    kwargs['host']=project.host
270    kwargs['res_factor']=project.res_factor
271    kwargs['starttime']=project.starttime
272    kwargs['yieldstep']=project.yieldstep
273    kwargs['finaltime']=project.finaltime
274   
275    kwargs['output_dir']=project.output_run_time_dir
276    kwargs['elevation_file']=project.combined_dir_name+'.pts'
277    kwargs['file_name']=project.home+'detail.csv'
278    kwargs['aa_scenario_name']=project.scenario_name
279    kwargs['ab_time']=project.time
280    kwargs['res_factor']= project.res_factor
281    kwargs['tide']=project.tide
282    kwargs['user']=project.user
283    kwargs['alpha'] = project.alpha
284    kwargs['friction']=project.friction
285    kwargs['time_thinning'] = project.time_thinning
286    kwargs['dir_comment']=project.dir_comment
287    kwargs['export_cellsize']=project.export_cellsize
288   
289
290    run_model(**kwargs)
291     
292    if myid==0:
293        export_model(**kwargs)
294    #barrier
Note: See TracBrowser for help on using the repository browser.