source: branches/anuga_1_1/anuga_work/production/hobart_2006/run_hobart_clipdata_refine.py @ 7799

Last change on this file since 7799 was 4063, checked in by sexton, 17 years ago

updates for nsw slide modelling and cairns demo

File size: 8.1 KB
Line 
1"""Script for running a tsunami inundation scenario for Hobart, TAS, 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.outputtimedir
6
7The scenario is defined by a triangular mesh created from project.polygon,
8the elevation data and a tsunami wave generated by MOST.
9
10Ole Nielsen and Duncan Gray, GA - 2005 and Nick Bartzis, GA - 2006
11"""
12#-------------------------------------------------------------------------------# Import necessary modules
13#-------------------------------------------------------------------------------
14
15# Standard modules
16import os
17import time
18from shutil import copy
19from os import mkdir, access, F_OK
20import sys
21
22# Related major packages
23from anuga.shallow_water import Domain, Reflective_boundary, \
24                            Dirichlet_boundary, Time_boundary, File_boundary
25from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts
26from anuga.abstract_2d_finite_volumes.combine_pts import combine_rectangular_points_files
27from anuga.geospatial_data.geospatial_data import *
28
29# Application specific imports
30import project                 # Definition of file names and polygons
31
32#-------------------------------------------------------------------------------
33# Copy scripts to time stamped output directory and capture screen
34# output to file
35#-------------------------------------------------------------------------------
36
37# creates copy of code in output dir if dir doesn't exist
38if access(project.outputtimedir,F_OK) == 0 :
39    mkdir (project.outputtimedir)
40copy (project.codedirname, project.outputtimedir + project.codename)
41copy (project.codedir + 'run_hobart_clipdata_refine.py', project.outputtimedir + 'run_hobart_clipdata_refine.py')
42print'output dir', project.outputtimedir
43
44print 'USER:    ', project.user
45
46#-------------------------------------------------------------------------------
47# Preparation of topographic data
48#
49# Convert ASC 2 DEM 2 PTS using source data and store result in source data
50#-------------------------------------------------------------------------------
51
52# filenames
53#onshore_dem_name = project.onshore_dem_name
54onshore_offshore_dem_name = project.onshore_offshore_dem_name
55onshore_offshore_dem_name_25 = project.onshore_offshore_dem_name_25
56meshname = project.meshname+'.msh'
57source_dir = project.boundarydir
58
59copied_files = False
60
61# create DEM from 50m asc data
62convert_dem_from_ascii2netcdf(onshore_offshore_dem_name, use_cache=True, verbose=True)
63
64# creates pts file for combined 50m DEM and make a Geospatial data object
65dem2pts(onshore_offshore_dem_name, use_cache=True, verbose=True)
66G = Geospatial_data(file_name = project.onshore_offshore_dem_name + '.pts')
67
68# clip 50m pts based on interior regions - want 50m data OUTSIDE of these polygons
69clip_regions = [project.poly_hobart1, project.poly_hobart2, \
70                project.poly_hobart3]
71
72# set up initial value as Geospatial data object
73U = Geospatial_data(clip_regions[0])
74allG = G.clip_outside(U)
75for j in clip_regions[1:]:
76    U = Geospatial_data(j)
77    allG += G.clip_outside(U)
78
79print 'created outside clipping'
80# clip 50m to be inside bounding polygon
81allG = allG.clip(Geospatial_data(project.polyAll))
82print 'finished 50m clipping'
83
84# create DEM from asc data - 25m data
85convert_dem_from_ascii2netcdf(onshore_offshore_dem_name_25, use_cache=True, verbose=True)
86
87# creates pts file for onshore DEM - 25 and make a Geospatial data object
88dem2pts(onshore_offshore_dem_name_25,
89        easting_min=project.eastingmin25_3,
90        easting_max=project.eastingmax25_3,
91        northing_min=project.northingmin25_3,
92        northing_max= project.northingmax25_3,
93        use_cache=True, verbose=True)
94G = Geospatial_data(file_name = project.onshore_offshore_dem_name_25 + '.pts')
95
96# clip 25m pts based on interior regions - want 25m data INSIDE these polygons
97for j in clip_regions[1:]:
98    allG += G.clip(j)
99
100print 'finished 25m clipping'
101
102allG.export_points_file(project.combined_dem_name_3 + '.pts')
103print 'exported points'
104
105#----------------------------------------------------------------------------
106# Create the triangular mesh based on overall clipping polygon with a tagged
107# boundary and interior regions defined in project.py along with
108# resolutions (maximal area of per triangle) for each polygon
109#-------------------------------------------------------------------------------
110
111from anuga.pmesh.mesh_interface import create_mesh_from_regions
112
113# use 75 for onshore components (12.5m DEM)
114hobart_res = 7500
115bathy_res = 50000
116refine_res = 500
117refine_res2 = 250
118interior_regions = [[project.poly_site13, refine_res],
119                    [project.poly_kingston, refine_res],
120                    [project.poly_bruny, refine_res],
121                    [project.poly_hobart5, bathy_res]]
122
123print 'number of interior regions', len(interior_regions)
124
125from caching import cache
126_ = cache(create_mesh_from_regions,
127          project.polyAll,
128           {'boundary_tags': {'e0': [0], 'e1': [1], 'e2': [2],
129                              'e3': [3], 'e4':[4], 'e5': [5],
130                              'e6': [6], 'e7': [7], 'e8': [8],
131                              'e9': [9], 'e10': [10], 'e11': [11],
132                              'e12': [12], 'e13': [13], 'e14': [14]},
133           'maximum_triangle_area': 750000,
134           'filename': meshname,           
135           'interior_regions': interior_regions},
136          verbose = True, evaluate=True)
137
138
139#-------------------------------------------------------------------------------                                 
140# Setup computational domain
141#-------------------------------------------------------------------------------                                 
142domain = Domain(meshname, use_cache = False, verbose = True)
143
144print 'Number of triangles = ', len(domain)
145print 'The extent is ', domain.get_extent()
146print domain.statistics()
147
148domain.set_name(project.basename)
149domain.set_datadir(project.outputtimedir)
150domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
151domain.set_minimum_storable_height(0.01)
152domain.set_maximum_allowed_speed(0.1)
153
154#-------------------------------------------------------------------------------                                 
155# Setup initial conditions
156#-------------------------------------------------------------------------------
157
158tide = 0.0
159domain.set_quantity('stage', tide)
160domain.set_quantity('friction', 0.0) 
161domain.set_quantity('elevation', 
162                    filename = project.combined_dem_name + '.pts',
163                    use_cache = True,
164                    verbose = True,
165                    alpha = 0.01
166                    )
167
168#-------------------------------------------------------------------------------                                 
169# Setup boundary conditions
170#-------------------------------------------------------------------------------
171
172print 'Available boundary tags', domain.get_boundary_tags()
173
174Bf = File_boundary(source_dir + project.boundary_basename + '.sww', 
175                    domain, verbose = True)
176Br = Reflective_boundary(domain)
177Bd = Dirichlet_boundary([tide,0,0])
178# 7 min square wave starting at 1 min, 6m high
179Bw = Time_boundary(domain = domain,
180                   f=lambda t: [(60<t<480)*10, 0, 0])
181
182#
183domain.set_boundary( {'e0': Bd,  'e1': Bd, 'e2': Bd, 'e3': Bd, 'e4': Bd,
184                      'e5': Bd,  'e6': Bd, 'e7': Bd, 'e8': Bd, 'e9': Bd,
185                      'e10': Bd, 'e11': Bd, 'e12': Bf, 'e13': Bf, 'e14': Bf} )
186
187#-------------------------------------------------------------------------------                                 
188# Evolve system through time
189#-------------------------------------------------------------------------------
190import time
191t0 = time.time()
192
193for t in domain.evolve(yieldstep = 240, finaltime = 6800): 
194    domain.write_time()
195    domain.write_boundary_statistics(tags = 'e14')     
196
197for t in domain.evolve(yieldstep = 30, finaltime = 15000
198                       ,skip_initial_step = True): 
199    domain.write_time()
200    domain.write_boundary_statistics(tags = 'e14')     
201
202for t in domain.evolve(yieldstep = 240, finaltime = 20000
203                       ,skip_initial_step = True): 
204    domain.write_time()
205    domain.write_boundary_statistics(tags = 'e14') 
206   
207print 'That took %.2f seconds' %(time.time()-t0)
208
209print 'finished'
Note: See TracBrowser for help on using the repository browser.