source: anuga_work/production/australia_ph2/sydney/comparisons/run_sydney_250m.py @ 6295

Last change on this file since 6295 was 6295, checked in by jgriffin, 15 years ago

Scripts to run comparisons between different model extents to assess boundary effects and discretisation errors.

File size: 11.0 KB
RevLine 
[6295]1"""Script for running a tsunami inundation scenario for Perth, WA, Australia.
2
3The scenario is defined by a triangular mesh created from project_250m.polygon,
4the elevation data is compiled into a pts file through build_perth.py
5and a simulated tsunami is generated through an sts file from build_boundary.py.
6
7Input: sts file (build_boundary.py for respective event)
8       pts file (build_perth.py)
9       information from project file
10Outputs: sww file stored in project_250m.output_run_time_dir
11The export_results_all.py and get_timeseries.py is reliant
12on the outputs of this script
13
14Ole Nielsen and Duncan Gray, GA - 2005, Jane Sexton, Nick Bartzis, GA - 2006
15Ole Nielsen, Jane Sexton and Kristy Van Putten - 2008
16"""
17
18#------------------------------------------------------------------------------
19# Import necessary modules
20#------------------------------------------------------------------------------
21
22# Standard modules
23from os import sep
24import os
25from os.path import dirname, basename
26from os import mkdir, access, F_OK
27from shutil import copy
28from math import pi, sin, exp
29import time
30import sys
31
32# Related major packages
33from anuga.shallow_water import Domain
34from anuga.shallow_water.shallow_water_domain import Transmissive_stage_zero_momentum_boundary
35from anuga.shallow_water import Dirichlet_boundary
36from anuga.shallow_water import File_boundary
37from anuga.shallow_water import Reflective_boundary
38from anuga.shallow_water import Field_boundary
39from anuga.shallow_water import Time_boundary
40from Numeric import allclose
41from anuga.shallow_water.data_manager import export_grid, create_sts_boundary
42from anuga.pmesh.mesh_interface import create_mesh_from_regions
43from anuga.shallow_water.data_manager import start_screen_catcher, copy_code_files,store_parameters
44from anuga_parallel.parallel_abstraction import get_processor_name
45from anuga.caching import myhash
46from anuga.damage_modelling.inundation_damage import add_depth_and_momentum2csv, inundation_damage
47from anuga.fit_interpolate.benchmark_least_squares import mem_usage
48from anuga.utilities.polygon import read_polygon, plot_polygons, polygon_area, is_inside_polygon
49from anuga.geospatial_data.geospatial_data import find_optimal_smoothing_parameter
50from polygon import Polygon_function
51   
52# Application specific imports
53import project_250m  # Definition of file names and polygons
54numprocs = 1
55myid = 0
56
57def run_model(**kwargs):
58   
59    #------------------------------------------------------------------------------
60    # Copy scripts to time stamped output directory and capture screen
61    # output to file
62    #------------------------------------------------------------------------------
63    print "Processor Name:",get_processor_name()
64
65    #copy script must be before screen_catcher
66
67    print 'output_dir',kwargs['output_dir']
68   
69    copy_code_files(kwargs['output_dir'],__file__, 
70             dirname(project_250m.__file__)+sep+ project_250m.__name__+'.py' )
71
72    store_parameters(**kwargs)
73
74    start_screen_catcher(kwargs['output_dir'], myid, numprocs)
75
76    print "Processor Name:",get_processor_name()
77   
78    #-----------------------------------------------------------------------
79    # Domain definitions
80    #-----------------------------------------------------------------------
81##
82##    # Read in boundary from ordered sts file
83##    urs_bounding_polygon=create_sts_boundary(os.path.join(project_250m.boundaries_dir_event,project_250m.scenario_name))
84##
85##    # Reading the landward defined points, this incorporates the original clipping
86##    # polygon minus the 100m contour
87##    landward_bounding_polygon = read_polygon(project_250m.landward_dir)
88##
89##    # Combine sts polyline with landward points
90##    bounding_polygon = urs_bounding_polygon + landward_bounding_polygon
91##   
92##    # counting segments
93##    N = len(urs_bounding_polygon)-1
94##    print 'N'+str(N)
95##    # boundary tags refer to project_250m.landward 4 points equals 5 segments start at N
96##    boundary_tags={'back': [N+1,N+2,N+3,N+4,N+5,N+6,N+7,N+8,N+9,N+10,N+11,N+12,N+13,N+14,N+15,N+16,N+17,N+18,N+19], 'side': [N,N+20], 'ocean': range(N)}
97    if project_250m.area =='large':
98        land = [2,3,4,]
99        sea = [0]
100        side1 = [1]
101        side2 = [5]
102        bounding_polygon = project_250m.poly_all
103        boundary_tags={'back': land, 'ocean': sea, 'side1':side1,'side2':side2}
104    elif project_250m.area =='small':
105        land = [2,3,4,]
106        sea = [0]
107        side1 = [1]
108        side2 = [5]
109        bounding_polygon = project_250m.poly_all
110        boundary_tags={'back': land, 'ocean': sea, 'side1':side1,'side2':side2}
111    elif project_250m.area =='medium':
112        land = [2,3,4]
113        sea = [0]
114        side1 = [1]
115        side2 = [5]
116        bounding_polygon = project_250m.poly_all
117        boundary_tags={'back': land, 'ocean': sea, 'side1':side1,'side2':side2}
118    elif project_250m.area =='vlarge':
119        land = [9,10,11,12,13,14]
120        sea = [0,1,2,3,4,5,6,7]
121        side1 = [8]
122        side2 = [15]
123        bounding_polygon = project_250m.poly_all
124        boundary_tags={'back': land, 'ocean': sea, 'side1':side1,'side2':side2} 
125    else:
126        print 'area not defined therefore bondary_tags not defined'
127    #--------------------------------------------------------------------------
128    # Create the triangular mesh based on overall clipping polygon with a tagged
129    # boundary and interior regions defined in project_250m.py along with
130    # resolutions (maximal area of per triangle) for each polygon
131    #--------------------------------------------------------------------------
132
133    # IMPORTANT don't cache create_mesh_from_region and Domain(mesh....) as it
134    # causes problems with the ability to cache set quantity which takes alot of times
135       
136    print 'start create mesh from regions'
137
138    create_mesh_from_regions(bounding_polygon,
139                         boundary_tags=boundary_tags,
140                         maximum_triangle_area=project_250m.res_poly_all,
141                         interior_regions=project_250m.interior_regions,
142                         filename=project_250m.meshes_dir_name,
143                         use_cache=False,
144                         verbose=True)
145   
146    #-------------------------------------------------------------------------
147    # Setup computational domain
148    #-------------------------------------------------------------------------
149    print 'Setup computational domain'
150
151    domain = Domain(project_250m.meshes_dir_name, use_cache=False, verbose=True)
152    print 'memory usage before del domain',mem_usage()
153       
154    print domain.statistics()
155    print 'triangles',len(domain)
156   
157    kwargs['act_num_trigs']=len(domain)
158
159
160    #-------------------------------------------------------------------------
161    # Setup initial conditions
162    #-------------------------------------------------------------------------
163    print 'Setup initial conditions'
164
165    # sets the initial stage in the offcoast region only
166    IC = Polygon_function( [(project_250m.poly_mainland, 0),(project_250m.island1,0),(project_250m.island2,0)], default = kwargs['tide'],
167                             geo_reference = domain.geo_reference)
168    domain.set_quantity('stage', IC)
169    #domain.set_quantity('stage',kwargs['tide'] )
170    domain.set_quantity('friction', kwargs['friction']) 
171   
172    print 'Start Set quantity',kwargs['elevation_file']
173
174    domain.set_quantity('elevation', 
175                        filename = kwargs['elevation_file'],
176                        use_cache = False,
177                        verbose = True,
178                        alpha = kwargs['alpha'])
179    print 'Finished Set quantity'
180
181##   #------------------------------------------------------
182##    # Distribute domain to implement parallelism !!!
183##    #------------------------------------------------------
184##
185##    if numprocs > 1:
186##        domain=distribute(domain)
187
188    #------------------------------------------------------
189    # Set domain parameters
190    #------------------------------------------------------
191    print 'domain id', id(domain)
192    domain.set_name(kwargs['scenario_name'])
193    domain.set_datadir(kwargs['output_dir'])
194    domain.set_default_order(2)                 # Apply second order scheme
195    domain.set_minimum_storable_height(0.01)    # Don't store anything less than 1cm
196    domain.set_store_vertices_uniquely(False)
197    domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
198    domain.tight_slope_limiters = 1
199    print 'domain id', id(domain)
200
201    #-------------------------------------------------------------------------
202    # Setup boundary conditions
203    #-------------------------------------------------------------------------
204    print 'Available boundary tags', domain.get_boundary_tags()
205    print 'domain id', id(domain)
206   
207    boundary_urs_out=project_250m.boundaries_dir_event + sep + project_250m.scenario_name
208
209    Br = Reflective_boundary(domain)
210    Bd = Dirichlet_boundary([kwargs['tide'],0,0])
211    Bt = Transmissive_stage_zero_momentum_boundary(domain)
212    Rb = Time_boundary (domain, f=lambda t: [(sin(t*pi/600) * exp(-(t/3600)**2)), 0.0, 0.0]) 
213##    print 'Available boundary tags', domain.get_boundary_tags()
214##    Bf = Field_boundary(boundary_urs_out+'.sts',  # Change from file_boundary
215##                   domain, mean_stage= project_250m.tide,
216##                   time_thinning=1,
217##                   default_boundary=Bd,
218##                   use_cache=False,
219##                   verbose = True,
220##                   boundary_polygon=bounding_polygon)
221
222    domain.set_boundary({'back': Br,
223                         'side1': Bt,
224                         'side2':Bt,
225                         'ocean':Rb}) 
226
227    kwargs['input_start_time']=domain.starttime
228
229    print'finish set boundary'
230
231    #----------------------------------------------------------------------------
232    # Evolve system through time
233    #--------------------------------------------------------------------
234    t0 = time.time()
235
236    for t in domain.evolve(yieldstep = project_250m.yieldstep, finaltime = kwargs['finaltime']
237                       ,skip_initial_step = False): 
238        domain.write_time()
239        domain.write_boundary_statistics(tags = 'ocean')
240
241    # these outputs should be checked with the resultant inundation map
242    x, y = domain.get_maximum_inundation_location()
243    q = domain.get_maximum_inundation_elevation()
244    print 'Maximum runup observed at (%.2f, %.2f) with elevation %.2f' %(x,y,q)
245
246    print 'Simulation took %.2f seconds' %(time.time()-t0)
247
248    #kwargs 'completed' must be added to write the final parameters to file
249    kwargs['completed']=str(time.time()-t0)
250     
251    store_parameters(**kwargs)
252     
253    print 'memory usage before del domain1',mem_usage()
254   
255   
256#-------------------------------------------------------------
257if __name__ == "__main__":
258   
259    kwargs={}
260    kwargs['finaltime']=project_250m.finaltime
261    kwargs['output_dir']=project_250m.output_run_time_dir
262    kwargs['elevation_file']=project_250m.combined_dir_name+'.pts'
263    kwargs['scenario_name']=project_250m.scenario_name
264    kwargs['tide']=project_250m.tide
265    kwargs['alpha'] = project_250m.alpha
266    kwargs['friction']=project_250m.friction
267     
268    run_model(**kwargs)
269     
270   
Note: See TracBrowser for help on using the repository browser.