source: anuga_work/production/australia_ph2/dampier/run_dampier_ph2_250m.py @ 6217

Last change on this file since 6217 was 6217, checked in by kristy, 14 years ago

updated scripts, new poly_all (no land)

File size: 10.3 KB
Line 
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##
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], 'side': [N,N+4], 'ocean': range(N)}
97
98    if project_250m.area =='large_b10':
99        land = range (0,516)
100        sea = range (516,626)
101        bounding_polygon = project_250m.poly_all
102        boundary_tags={'back': land, 'ocean': sea}
103    elif project_250m.area =='small_b10':
104        land = range (0,276)
105        sea = range (276,294)
106        bounding_polygon = project_250m.poly_all
107        boundary_tags={'back': land, 'ocean': sea}
108    else:
109        print 'area not defined therefore bondary_tags not defined'
110
111    #--------------------------------------------------------------------------
112    # Create the triangular mesh based on overall clipping polygon with a tagged
113    # boundary and interior regions defined in project_250m.py along with
114    # resolutions (maximal area of per triangle) for each polygon
115    #--------------------------------------------------------------------------
116
117    # IMPORTANT don't cache create_mesh_from_region and Domain(mesh....) as it
118    # causes problems with the ability to cache set quantity which takes alot of times
119       
120    print 'start create mesh from regions'
121
122    create_mesh_from_regions(bounding_polygon,
123                         boundary_tags=boundary_tags,
124                         maximum_triangle_area=project_250m.res_poly_all,
125                         interior_regions=project_250m.interior_regions,
126                         filename=project_250m.meshes_dir_name,
127                         use_cache=False,
128                         verbose=True)
129   
130    #-------------------------------------------------------------------------
131    # Setup computational domain
132    #-------------------------------------------------------------------------
133    print 'Setup computational domain'
134
135    domain = Domain(project_250m.meshes_dir_name, use_cache=False, verbose=True)
136    print 'memory usage before del domain',mem_usage()
137       
138    print domain.statistics()
139    print 'triangles',len(domain)
140   
141    kwargs['act_num_trigs']=len(domain)
142
143
144    #-------------------------------------------------------------------------
145    # Setup initial conditions
146    #-------------------------------------------------------------------------
147    print 'Setup initial conditions'
148
149    # sets the initial stage in the offcoast region only
150##    IC = Polygon_function( [(project_250m.poly_mainland, 0)], default = kwargs['tide'],
151##                             geo_reference = domain.geo_reference)
152    domain.set_quantity('stage', 0)
153    #domain.set_quantity('stage',kwargs['tide'] )
154    domain.set_quantity('friction', kwargs['friction']) 
155   
156    print 'Start Set quantity',kwargs['elevation_file']
157
158    domain.set_quantity('elevation', 
159                        filename = kwargs['elevation_file'],
160                        use_cache = False,
161                        verbose = True,
162                        alpha = kwargs['alpha'])
163    print 'Finished Set quantity'
164
165##   #------------------------------------------------------
166##    # Distribute domain to implement parallelism !!!
167##    #------------------------------------------------------
168##
169##    if numprocs > 1:
170##        domain=distribute(domain)
171
172    #------------------------------------------------------
173    # Set domain parameters
174    #------------------------------------------------------
175    print 'domain id', id(domain)
176    domain.set_name(kwargs['scenario_name'])
177    domain.set_datadir(kwargs['output_dir'])
178    domain.set_default_order(2)                 # Apply second order scheme
179    domain.set_minimum_storable_height(0.01)    # Don't store anything less than 1cm
180    domain.set_store_vertices_uniquely(False)
181    domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
182    domain.tight_slope_limiters = 1
183    print 'domain id', id(domain)
184
185    #-------------------------------------------------------------------------
186    # Setup boundary conditions
187    #-------------------------------------------------------------------------
188    print 'Available boundary tags', domain.get_boundary_tags()
189    print 'domain id', id(domain)
190   
191##    boundary_urs_out=project_250m.boundaries_dir_event + sep + project_250m.scenario_name
192##    Bd = Dirichlet_boundary([kwargs['tide'],0,0])
193##    print 'Available boundary tags', domain.get_boundary_tags()
194##    Bf = Field_boundary(boundary_urs_out+'.sts',  # Change from file_boundary
195##                   domain, mean_stage= project_250m.tide,
196##                   time_thinning=1,
197##                   default_boundary=Bd,
198##                   use_cache=True,
199##                   verbose = True,
200##                   boundary_polygon=bounding_polygon)
201
202    Br = Reflective_boundary(domain)
203    Bt = Transmissive_stage_zero_momentum_boundary(domain)
204    Rb = Time_boundary (domain, f=lambda t: [(sin(t*pi/600) * exp(-(t/3600)**2)), 0.0, 0.0])   
205
206    domain.set_boundary({'back': Bt,
207                         'ocean': Rb}) 
208
209    kwargs['input_start_time']=domain.starttime
210
211    print'finish set boundary'
212
213    #----------------------------------------------------------------------------
214    # Evolve system through time
215    #--------------------------------------------------------------------
216    t0 = time.time()
217
218    for t in domain.evolve(yieldstep = project_250m.yieldstep, finaltime = kwargs['finaltime']
219                       ,skip_initial_step = False): 
220        domain.write_time()
221        domain.write_boundary_statistics(tags = 'ocean')
222
223    # these outputs should be checked with the resultant inundation map
224    x, y = domain.get_maximum_inundation_location()
225    q = domain.get_maximum_inundation_elevation()
226    print 'Maximum runup observed at (%.2f, %.2f) with elevation %.2f' %(x,y,q)
227
228    print 'Simulation took %.2f seconds' %(time.time()-t0)
229
230    #kwargs 'completed' must be added to write the final parameters to file
231    kwargs['completed']=str(time.time()-t0)
232     
233    store_parameters(**kwargs)
234     
235    print 'memory usage before del domain1',mem_usage()
236   
237   
238#-------------------------------------------------------------
239if __name__ == "__main__":
240   
241    kwargs={}
242    kwargs['file_name']=project_250m.dir_comment
243    kwargs['finaltime']=project_250m.finaltime
244    kwargs['output_dir']=project_250m.output_run_time_dir
245    kwargs['elevation_file']=project_250m.combined_dir_name+'.pts'
246    kwargs['scenario_name']=project_250m.scenario_name
247    kwargs['tide']=project_250m.tide
248    kwargs['alpha'] = project_250m.alpha
249    kwargs['friction']=project_250m.friction
250     
251    run_model(**kwargs)
252     
253   
Note: See TracBrowser for help on using the repository browser.