1 | """Script for running a tsunami inundation scenario for Onslow, WA, Australia. |
---|
2 | |
---|
3 | Source data such as elevation and boundary data is assumed to be available in |
---|
4 | directories specified by project.py |
---|
5 | The output sww file is stored in project.outputdir |
---|
6 | |
---|
7 | The scenario is defined by a triangular mesh created from project.polygon, |
---|
8 | the elevation data and a simulated submarine landslide. |
---|
9 | |
---|
10 | Ole Nielsen and Duncan Gray, GA - 2005 and Nick Bartzis, GA - 2006 |
---|
11 | """ |
---|
12 | |
---|
13 | |
---|
14 | #-------------------------------------------------------------------------------# Import necessary modules |
---|
15 | #------------------------------------------------------------------------------- |
---|
16 | |
---|
17 | # Standard modules |
---|
18 | import os |
---|
19 | import time |
---|
20 | |
---|
21 | # Related major packages |
---|
22 | from anuga.pyvolution.shallow_water import Domain, Reflective_boundary, \ |
---|
23 | Dirichlet_boundary, Time_boundary, File_boundary |
---|
24 | from anuga.pyvolution.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
25 | from anuga.pyvolution.combine_pts import combine_rectangular_points_files |
---|
26 | from anuga.pyvolution.pmesh2domain import pmesh_to_domain_instance |
---|
27 | from anuga.fit_interpolate.fit import fit_to_mesh_file |
---|
28 | |
---|
29 | from anuga.caching import cache |
---|
30 | |
---|
31 | # Application specific imports |
---|
32 | import project # Definition of file names and polygons |
---|
33 | from smf import slump_tsunami # Function for submarine mudslide |
---|
34 | |
---|
35 | from shutil import copy |
---|
36 | from os import mkdir, access, F_OK |
---|
37 | |
---|
38 | from anuga.geospatial_data.geospatial_data import * |
---|
39 | |
---|
40 | #------------------------------------------------------------------------------- |
---|
41 | # Preparation of topographic data |
---|
42 | # |
---|
43 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
44 | # Do for coarse and fine data |
---|
45 | # Fine pts file to be clipped to area of interest |
---|
46 | #------------------------------------------------------------------------------- |
---|
47 | |
---|
48 | # filenames |
---|
49 | coarsedemname = project.coarsedemname |
---|
50 | |
---|
51 | onshore_dem_name = project.onshore_dem_name |
---|
52 | |
---|
53 | offshore_points = project.offshore_dem_name |
---|
54 | |
---|
55 | meshname = project.meshname+'.tsh' |
---|
56 | |
---|
57 | source_dir = project.boundarydir |
---|
58 | |
---|
59 | # creates copy of code in output dir |
---|
60 | if access(project.outputdir,F_OK) == 0 : |
---|
61 | mkdir (project.outputdir) |
---|
62 | copy (project.codedirname, project.outputdir + project.codename) |
---|
63 | copy (project.codedir + 'run_onslow.py', project.outputdir + 'run_onslow.py') |
---|
64 | |
---|
65 | |
---|
66 | |
---|
67 | #------------------------------------------------------------------------------- |
---|
68 | # Setup computational domain |
---|
69 | #------------------------------------------------------------------------------- |
---|
70 | mesh_elevname = 'mesh_source_elv.msh' |
---|
71 | domain = pmesh_to_domain_instance(mesh_elevname, Domain, |
---|
72 | use_cache = True, |
---|
73 | verbose = True) |
---|
74 | |
---|
75 | print 'Number of triangles = ', len(domain) |
---|
76 | print 'The extent is ', domain.get_extent() |
---|
77 | print domain.statistics() |
---|
78 | |
---|
79 | domain.set_name(project.basename) |
---|
80 | domain.set_datadir(project.outputdir) |
---|
81 | domain.set_quantities_to_be_stored(['stage']) |
---|
82 | |
---|
83 | |
---|
84 | #------------------------------------------------------------------------------- |
---|
85 | # Setup initial conditions |
---|
86 | #------------------------------------------------------------------------------- |
---|
87 | |
---|
88 | tide = 0. |
---|
89 | |
---|
90 | domain.set_quantity('stage', tide) |
---|
91 | domain.set_quantity('friction', 0.0) |
---|
92 | print 'hi1' |
---|
93 | |
---|
94 | #------------------------------------------------------------------------------- |
---|
95 | # Setup boundary conditions (all reflective) |
---|
96 | #------------------------------------------------------------------------------- |
---|
97 | |
---|
98 | from anuga.pyvolution.data_manager import ferret2sww |
---|
99 | |
---|
100 | south = project.south |
---|
101 | north = project.north |
---|
102 | west = project.west |
---|
103 | east = project.east |
---|
104 | |
---|
105 | cache(ferret2sww, |
---|
106 | (project.boundary_basename, |
---|
107 | project.boundary_basename), |
---|
108 | {'verbose': True, |
---|
109 | 'minlat': south, |
---|
110 | 'maxlat': north, |
---|
111 | 'minlon': west, |
---|
112 | 'maxlon': east, |
---|
113 | 'origin': domain.geo_reference.get_origin(), |
---|
114 | 'mean_stage': tide, |
---|
115 | 'zscale': 1, #Enhance tsunami |
---|
116 | 'fail_on_NaN': False, |
---|
117 | 'inverted_bathymetry': True}, |
---|
118 | #evaluate = True, |
---|
119 | verbose = True) |
---|
120 | |
---|
121 | |
---|
122 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
123 | |
---|
124 | Bf = File_boundary(project.boundary_basename + '.sww', |
---|
125 | domain, verbose = True) |
---|
126 | Br = Reflective_boundary(domain) |
---|
127 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
128 | |
---|
129 | |
---|
130 | # 7 min square wave starting at 1 min, 6m high |
---|
131 | Bw = Time_boundary(domain = domain, |
---|
132 | f=lambda t: [(60<t<480)*6, 0, 0]) |
---|
133 | |
---|
134 | domain.set_boundary( {'top': Bf, 'topleft': Bf, |
---|
135 | 'left': Br, 'bottom': Br, |
---|
136 | 'bottomright': Br, 'topright': Bf, |
---|
137 | 'exterior':Bf} ) |
---|
138 | |
---|
139 | |
---|
140 | #------------------------------------------------------------------------------- |
---|
141 | # Evolve system through time |
---|
142 | #------------------------------------------------------------------------------- |
---|
143 | import time |
---|
144 | t0 = time.time() |
---|
145 | |
---|
146 | for t in domain.evolve(yieldstep = 50, finaltime = 1000): |
---|
147 | domain.write_time() |
---|
148 | domain.write_boundary_statistics(tags = 'top') |
---|
149 | |
---|
150 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
151 | |
---|
152 | print 'finished' |
---|