[2773] | 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.outputtimedir |
---|
| 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 |
---|
[3276] | 20 | from shutil import copy |
---|
| 21 | from os import mkdir, access, F_OK |
---|
| 22 | import sys |
---|
[2773] | 23 | |
---|
| 24 | # Related major packages |
---|
[3514] | 25 | from anuga.pyvolution.shallow_water import Domain, Reflective_boundary, \ |
---|
[2773] | 26 | Dirichlet_boundary, Time_boundary, File_boundary |
---|
[3514] | 27 | from anuga.pyvolution.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
| 28 | from anuga.pyvolution.combine_pts import combine_rectangular_points_files |
---|
| 29 | from anuga.pyvolution.pmesh2domain import pmesh_to_domain_instance |
---|
| 30 | from anuga.geospatial_data.geospatial_data import * |
---|
| 31 | from anuga.pyvolution.util import Screen_Catcher |
---|
[2773] | 32 | |
---|
| 33 | # Application specific imports |
---|
| 34 | import project # Definition of file names and polygons |
---|
| 35 | |
---|
| 36 | #------------------------------------------------------------------------------- |
---|
[3276] | 37 | # Copy scripts to time stamped output directory and capture screen |
---|
| 38 | # output to file |
---|
[2773] | 39 | #------------------------------------------------------------------------------- |
---|
| 40 | |
---|
| 41 | # creates copy of code in output dir if dir doesn't exist |
---|
| 42 | if access(project.outputtimedir,F_OK) == 0 : |
---|
| 43 | mkdir (project.outputtimedir) |
---|
| 44 | copy (project.codedirname, project.outputtimedir + project.codename) |
---|
| 45 | copy (project.codedir + 'run_onslow.py', project.outputtimedir + 'run_onslow.py') |
---|
| 46 | print'output dir', project.outputtimedir |
---|
| 47 | |
---|
| 48 | #normal screen output is stored in |
---|
| 49 | screen_output_name = project.outputtimedir + "screen_output.txt" |
---|
| 50 | screen_error_name = project.outputtimedir + "screen_error.txt" |
---|
| 51 | |
---|
| 52 | #used to catch screen output to file |
---|
| 53 | sys.stdout = Screen_Catcher(screen_output_name) |
---|
| 54 | #sys.stderr = Screen_Catcher(screen_output_name) |
---|
| 55 | sys.stderr = Screen_Catcher(screen_error_name) |
---|
| 56 | |
---|
[3276] | 57 | print 'USER: ', project.user |
---|
[3261] | 58 | |
---|
[3276] | 59 | #------------------------------------------------------------------------------- |
---|
| 60 | # Preparation of topographic data |
---|
| 61 | # |
---|
| 62 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
| 63 | # Do for coarse and fine data |
---|
| 64 | # Fine pts file to be clipped to area of interest |
---|
| 65 | #------------------------------------------------------------------------------- |
---|
| 66 | |
---|
| 67 | # filenames |
---|
| 68 | onshore_dem_name = project.onshore_dem_name |
---|
| 69 | islands_dem_name = project.islands_dem_name |
---|
| 70 | coast_points = project.coast_dem_name |
---|
| 71 | offshore_points = project.offshore_dem_name |
---|
| 72 | meshname = project.meshname+'.msh' |
---|
| 73 | source_dir = project.boundarydir |
---|
| 74 | |
---|
[2773] | 75 | copied_files = False |
---|
| 76 | |
---|
| 77 | # files to be used |
---|
[3261] | 78 | files_used = [onshore_dem_name, offshore_points, coast_points,] |
---|
[2773] | 79 | |
---|
| 80 | # fine data (clipping the points file to smaller area) |
---|
| 81 | # creates DEM from asc data |
---|
| 82 | convert_dem_from_ascii2netcdf(onshore_dem_name, use_cache=True, verbose=True) |
---|
| 83 | |
---|
[3261] | 84 | #creates pts file for onshore DEM |
---|
[2773] | 85 | dem2pts(onshore_dem_name, |
---|
| 86 | easting_min=project.eastingmin, |
---|
| 87 | easting_max=project.eastingmax, |
---|
| 88 | northing_min=project.northingmin, |
---|
| 89 | northing_max= project.northingmax, |
---|
| 90 | use_cache=True, |
---|
| 91 | verbose=True) |
---|
| 92 | |
---|
[3261] | 93 | convert_dem_from_ascii2netcdf(islands_dem_name, use_cache=True, verbose=True) |
---|
| 94 | |
---|
| 95 | #creates pts file for islands DEM |
---|
| 96 | dem2pts(islands_dem_name, use_cache=True, verbose=True) |
---|
| 97 | |
---|
[2773] | 98 | print'create G1' |
---|
| 99 | G1 = Geospatial_data(file_name = project.offshore_dem_name + '.xya') |
---|
| 100 | print'create G2' |
---|
| 101 | G2 = Geospatial_data(file_name = project.onshore_dem_name + '.pts') |
---|
[3261] | 102 | print'create G3' |
---|
| 103 | G3 = Geospatial_data(file_name = project.coast_dem_name + '.xya') |
---|
| 104 | print'create G4' |
---|
| 105 | G4 = Geospatial_data(file_name = project.islands_dem_name + '.pts') |
---|
| 106 | print'add G1+G2+G3+G4' |
---|
| 107 | G = G1 + G2 + G3 + G4 |
---|
[2773] | 108 | print'export G' |
---|
| 109 | G.export_points_file(project.combined_dem_name + '.pts') |
---|
| 110 | |
---|
| 111 | #------------------------------------------------------------------------------- |
---|
| 112 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
| 113 | # boundary and interior regions defined in project.py along with |
---|
| 114 | # resolutions (maximal area of per triangle) for each polygon |
---|
| 115 | #------------------------------------------------------------------------------- |
---|
| 116 | |
---|
[3535] | 117 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
[3276] | 118 | |
---|
[2773] | 119 | #new |
---|
[3276] | 120 | region_res = 200000 |
---|
| 121 | coast_res = 25000 |
---|
| 122 | onslow_res = 5000 |
---|
[2773] | 123 | interior_regions = [[project.poly_onslow, onslow_res], |
---|
[3261] | 124 | [project.poly_coast, coast_res], |
---|
| 125 | [project.poly_region, region_res]] |
---|
[2773] | 126 | |
---|
| 127 | print 'number of interior regions', len(interior_regions) |
---|
| 128 | |
---|
| 129 | from caching import cache |
---|
| 130 | _ = cache(create_mesh_from_regions, |
---|
| 131 | project.polyAll, |
---|
| 132 | {'boundary_tags': {'top': [0], 'topleft': [1], |
---|
| 133 | 'topleft1': [2], 'bottomleft': [3], |
---|
| 134 | 'bottom': [4], 'bottomright': [5], |
---|
| 135 | 'topright':[6]}, |
---|
[3264] | 136 | 'maximum_triangle_area': 100000, |
---|
[2773] | 137 | 'filename': meshname, |
---|
| 138 | 'interior_regions': interior_regions}, |
---|
[3249] | 139 | verbose = True, evaluate=True) |
---|
[2773] | 140 | |
---|
| 141 | |
---|
| 142 | #------------------------------------------------------------------------------- |
---|
| 143 | # Setup computational domain |
---|
| 144 | #------------------------------------------------------------------------------- |
---|
| 145 | |
---|
| 146 | domain = pmesh_to_domain_instance(meshname, Domain, |
---|
| 147 | use_cache = False, |
---|
| 148 | verbose = True) |
---|
| 149 | |
---|
| 150 | print 'Number of triangles = ', len(domain) |
---|
| 151 | print 'The extent is ', domain.get_extent() |
---|
| 152 | print domain.statistics() |
---|
| 153 | |
---|
| 154 | domain.set_name(project.basename) |
---|
| 155 | domain.set_datadir(project.outputtimedir) |
---|
| 156 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | #------------------------------------------------------------------------------- |
---|
| 160 | # Setup initial conditions |
---|
| 161 | #------------------------------------------------------------------------------- |
---|
| 162 | |
---|
[2863] | 163 | tide = 0.0 |
---|
[2773] | 164 | |
---|
| 165 | domain.set_quantity('stage', tide) |
---|
| 166 | domain.set_quantity('friction', 0.0) |
---|
| 167 | print 'hi and file',project.combined_dem_name + '.pts' |
---|
| 168 | |
---|
| 169 | domain.set_quantity('elevation', |
---|
| 170 | # 0. |
---|
| 171 | # filename = project.onshore_dem_name + '.pts', |
---|
| 172 | filename = project.combined_dem_name + '.pts', |
---|
| 173 | # filename = project.offshore_dem_name + '.pts', |
---|
| 174 | use_cache = True, |
---|
| 175 | verbose = True, |
---|
| 176 | alpha = 0.1 |
---|
| 177 | ) |
---|
| 178 | |
---|
| 179 | print 'hi1' |
---|
| 180 | |
---|
| 181 | #------------------------------------------------------------------------------- |
---|
| 182 | # Setup boundary conditions (all reflective) |
---|
| 183 | #------------------------------------------------------------------------------- |
---|
| 184 | print 'start ferret2sww' |
---|
[3514] | 185 | from anuga.pyvolution.data_manager import ferret2sww |
---|
[2773] | 186 | |
---|
| 187 | south = project.south |
---|
| 188 | north = project.north |
---|
| 189 | west = project.west |
---|
| 190 | east = project.east |
---|
| 191 | |
---|
| 192 | #note only need to do when an SWW file for the MOST boundary doesn't exist |
---|
| 193 | cache(ferret2sww, |
---|
| 194 | (source_dir + project.boundary_basename, |
---|
| 195 | source_dir + project.boundary_basename), |
---|
| 196 | # (project.MOST_dir + project.boundary_basename, |
---|
| 197 | # source_dir + project.boundary_basename), |
---|
| 198 | {'verbose': True, |
---|
| 199 | # note didn't work with the below |
---|
| 200 | # 'minlat': south - 1, |
---|
| 201 | # 'maxlat': north + 1, |
---|
| 202 | # 'minlon': west - 1, |
---|
| 203 | # 'maxlon': east + 1, |
---|
| 204 | 'minlat': south, |
---|
| 205 | 'maxlat': north, |
---|
| 206 | 'minlon': west, |
---|
| 207 | 'maxlon': east, |
---|
| 208 | # 'origin': project.mesh_origin, |
---|
| 209 | 'origin': domain.geo_reference.get_origin(), |
---|
| 210 | 'mean_stage': tide, |
---|
| 211 | 'zscale': 1, #Enhance tsunami |
---|
| 212 | 'fail_on_NaN': False, |
---|
| 213 | 'inverted_bathymetry': True}, |
---|
| 214 | #evaluate = True, |
---|
[3276] | 215 | verbose = True, |
---|
| 216 | dependencies = source_dir + project.boundary_basename + '.sww') |
---|
[2773] | 217 | |
---|
| 218 | |
---|
| 219 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
| 220 | |
---|
| 221 | Bf = File_boundary(source_dir + project.boundary_basename + '.sww', |
---|
| 222 | domain, verbose = True) |
---|
| 223 | Br = Reflective_boundary(domain) |
---|
| 224 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
| 225 | |
---|
| 226 | |
---|
| 227 | # 7 min square wave starting at 1 min, 6m high |
---|
| 228 | Bw = Time_boundary(domain = domain, |
---|
| 229 | f=lambda t: [(60<t<480)*6, 0, 0]) |
---|
| 230 | |
---|
| 231 | domain.set_boundary( {'top': Bf, 'topleft': Bf, |
---|
[3276] | 232 | 'topleft1': Bf, 'bottomleft': Bd, |
---|
| 233 | 'bottom': Br, 'bottomright': Br, 'topright': Bd} ) |
---|
[2773] | 234 | |
---|
| 235 | #------------------------------------------------------------------------------- |
---|
| 236 | # Evolve system through time |
---|
| 237 | #------------------------------------------------------------------------------- |
---|
| 238 | import time |
---|
| 239 | t0 = time.time() |
---|
| 240 | |
---|
[3276] | 241 | for t in domain.evolve(yieldstep = 240, finaltime = 7200): |
---|
[2773] | 242 | domain.write_time() |
---|
| 243 | domain.write_boundary_statistics(tags = 'top') |
---|
| 244 | |
---|
[3276] | 245 | for t in domain.evolve(yieldstep = 120, finaltime = 12600 |
---|
[2773] | 246 | ,skip_initial_step = True): |
---|
| 247 | domain.write_time() |
---|
| 248 | domain.write_boundary_statistics(tags = 'top') |
---|
| 249 | |
---|
[3276] | 250 | for t in domain.evolve(yieldstep = 60, finaltime = 19800 |
---|
[2773] | 251 | ,skip_initial_step = True): |
---|
| 252 | domain.write_time() |
---|
| 253 | domain.write_boundary_statistics(tags = 'top') |
---|
| 254 | |
---|
[3276] | 255 | for t in domain.evolve(yieldstep = 120, finaltime = 25200 |
---|
| 256 | ,skip_initial_step = True): |
---|
| 257 | domain.write_time() |
---|
| 258 | domain.write_boundary_statistics(tags = 'top') |
---|
| 259 | |
---|
| 260 | for t in domain.evolve(yieldstep = 240, finaltime = 36000 |
---|
| 261 | ,skip_initial_step = True): |
---|
| 262 | domain.write_time() |
---|
| 263 | domain.write_boundary_statistics(tags = 'top') |
---|
| 264 | |
---|
[2773] | 265 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 266 | |
---|
| 267 | print 'finished' |
---|