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