[2848] | 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 |
---|
| 27 | from geospatial_data import add_points_files |
---|
| 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 | onshore_dem_name = project.onshore_dem_name |
---|
| 50 | offshore_points1 = project.offshore_dem_name1 |
---|
| 51 | offshore_points2 = project.offshore_dem_name2 |
---|
| 52 | meshname = project.meshname+'.msh' |
---|
| 53 | source_dir = project.boundarydir |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | # creates copy of code in output dir if dir doesn't exist |
---|
| 57 | if access(project.outputtimedir,F_OK) == 0 : |
---|
| 58 | mkdir (project.outputtimedir) |
---|
| 59 | copy (project.codedirname, project.outputtimedir + project.codename) |
---|
| 60 | copy (project.codedir + 'run_pt_hedland.py', project.outputtimedir + 'run_pt_hedland.py') |
---|
| 61 | print'output dir', project.outputtimedir |
---|
| 62 | |
---|
| 63 | #normal screen output is stored in |
---|
| 64 | screen_output_name = project.outputtimedir + "screen_output.txt" |
---|
| 65 | screen_error_name = project.outputtimedir + "screen_error.txt" |
---|
| 66 | |
---|
| 67 | #used to catch screen output to file |
---|
| 68 | sys.stdout = Screen_Catcher(screen_output_name) |
---|
| 69 | #sys.stderr = Screen_Catcher(screen_output_name) |
---|
| 70 | #sys.stderr = Screen_Catcher(screen_error_name) |
---|
| 71 | |
---|
| 72 | ''' |
---|
| 73 | copied_files = False |
---|
| 74 | |
---|
| 75 | # files to be used |
---|
| 76 | files_used = [onshore_dem_name, offshore_points,] |
---|
| 77 | |
---|
| 78 | if sys.platform != 'win32': |
---|
| 79 | copied_files = True |
---|
| 80 | for name in file_list: |
---|
| 81 | copy(name, ) |
---|
| 82 | ''' |
---|
| 83 | #print' most file', project.MOST_dir + project.boundary_basename+'_ha.nc' |
---|
| 84 | #if access(project.MOST_dir + project.boundary_basename+'_ha.nc',F_OK) == 1 : |
---|
| 85 | # print' most file', project.MOST_dir + project.boundary_basename |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | # fine data (clipping the points file to smaller area) |
---|
| 89 | # creates DEM from asc data |
---|
| 90 | convert_dem_from_ascii2netcdf(onshore_dem_name, use_cache=True, verbose=True) |
---|
| 91 | |
---|
| 92 | #creates pts file from DEM |
---|
| 93 | dem2pts(onshore_dem_name, |
---|
| 94 | easting_min=project.eastingmin, |
---|
| 95 | easting_max=project.eastingmax, |
---|
| 96 | northing_min=project.northingmin, |
---|
| 97 | northing_max= project.northingmax, |
---|
| 98 | use_cache=True, |
---|
| 99 | verbose=True) |
---|
| 100 | |
---|
| 101 | print'create G1' |
---|
| 102 | G1 = Geospatial_data(file_name = project.offshore_dem_name1 + '.xya') |
---|
| 103 | |
---|
| 104 | print'create G2' |
---|
| 105 | G2 = Geospatial_data(file_name = project.offshore_dem_name2 + '.xya') |
---|
| 106 | |
---|
| 107 | print'create G3' |
---|
| 108 | G3 = Geospatial_data(file_name = project.onshore_dem_name + '.pts') |
---|
| 109 | |
---|
| 110 | print'add G1+G2+G3' |
---|
| 111 | G = G1 + G2 + G3 |
---|
| 112 | |
---|
| 113 | print'export G' |
---|
| 114 | G.export_points_file(project.combined_dem_name + '.pts') |
---|
| 115 | |
---|
| 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 |
---|
| 124 | |
---|
| 125 | region_res = 25000 |
---|
| 126 | coast_res = 2500 |
---|
| 127 | pt_hedland_res = 25000 |
---|
| 128 | # derive poly_coast from project.coast_name using alpha_shape |
---|
[2855] | 129 | interior_regions = []#[[project.poly_pt_hedland, pt_hedland_res]]#, |
---|
[2848] | 130 | #[project.poly_coast, coast_res], |
---|
| 131 | #[project.poly_region, region_res]] |
---|
| 132 | |
---|
| 133 | print 'number of interior regions', len(interior_regions) |
---|
| 134 | |
---|
| 135 | from caching import cache |
---|
| 136 | _ = cache(create_mesh_from_regions, |
---|
| 137 | project.polyAll, |
---|
| 138 | {'boundary_tags': {'right': [0], 'bottomright': [1], |
---|
| 139 | 'bottomleft': [2], 'left': [3], 'top': [4]}, |
---|
| 140 | 'maximum_triangle_area': 250000, |
---|
| 141 | 'filename': meshname, |
---|
| 142 | 'interior_regions': interior_regions}, |
---|
| 143 | verbose = True) |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | #------------------------------------------------------------------------------- |
---|
| 147 | # Setup computational domain |
---|
| 148 | #------------------------------------------------------------------------------- |
---|
| 149 | |
---|
| 150 | domain = pmesh_to_domain_instance(meshname, Domain, |
---|
| 151 | use_cache = False, |
---|
| 152 | verbose = True) |
---|
| 153 | |
---|
| 154 | print 'Number of triangles = ', len(domain) |
---|
| 155 | print 'The extent is ', domain.get_extent() |
---|
| 156 | print domain.statistics() |
---|
| 157 | |
---|
| 158 | domain.set_name(project.basename) |
---|
| 159 | domain.set_datadir(project.outputtimedir) |
---|
| 160 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
| 161 | |
---|
| 162 | #------------------------------------------------------------------------------- |
---|
| 163 | # Setup initial conditions |
---|
| 164 | #------------------------------------------------------------------------------- |
---|
| 165 | |
---|
| 166 | tide = 0. |
---|
| 167 | |
---|
| 168 | domain.set_quantity('stage', tide) |
---|
| 169 | domain.set_quantity('friction', 0.0) |
---|
| 170 | print 'hi and file',project.combined_dem_name + '.pts' |
---|
| 171 | |
---|
| 172 | domain.set_quantity('elevation', |
---|
| 173 | # filename = project.onshore_dem_name + '.pts', |
---|
| 174 | filename = project.combined_dem_name + '.pts', |
---|
| 175 | # filename = project.offshore_dem_name1 + '.xya', |
---|
| 176 | # filename = project.offshore_dem_name2 + '.xya', |
---|
| 177 | use_cache = True, |
---|
| 178 | verbose = True, |
---|
| 179 | alpha = 0.1 |
---|
| 180 | ) |
---|
| 181 | |
---|
| 182 | print 'hi1' |
---|
| 183 | print 'have sent quantities OK - now exiting' |
---|
| 184 | import sys; sys.exit() |
---|
| 185 | |
---|
| 186 | #------------------------------------------------------------------------------- |
---|
| 187 | # Setup boundary conditions (all reflective) |
---|
| 188 | #------------------------------------------------------------------------------- |
---|
| 189 | print 'start ferret2sww' |
---|
| 190 | from pyvolution.data_manager import ferret2sww |
---|
| 191 | |
---|
| 192 | south = project.south |
---|
| 193 | north = project.north |
---|
| 194 | west = project.west |
---|
| 195 | east = project.east |
---|
| 196 | |
---|
| 197 | #note only need to do when an SWW file for the MOST boundary doesn't exist |
---|
| 198 | cache(ferret2sww, |
---|
| 199 | (source_dir + project.boundary_basename, |
---|
| 200 | source_dir + project.boundary_basename), |
---|
| 201 | # (project.MOST_dir + project.boundary_basename, |
---|
| 202 | # source_dir + project.boundary_basename), |
---|
| 203 | {'verbose': True, |
---|
| 204 | # note didn't work with the below |
---|
| 205 | # 'minlat': south - 1, |
---|
| 206 | # 'maxlat': north + 1, |
---|
| 207 | # 'minlon': west - 1, |
---|
| 208 | # 'maxlon': east + 1, |
---|
| 209 | 'minlat': south, |
---|
| 210 | 'maxlat': north, |
---|
| 211 | 'minlon': west, |
---|
| 212 | 'maxlon': east, |
---|
| 213 | # 'origin': project.mesh_origin, |
---|
| 214 | 'origin': domain.geo_reference.get_origin(), |
---|
| 215 | 'mean_stage': tide, |
---|
| 216 | 'zscale': 1, #Enhance tsunami |
---|
| 217 | 'fail_on_NaN': False, |
---|
| 218 | 'inverted_bathymetry': True}, |
---|
| 219 | #evaluate = True, |
---|
| 220 | verbose = True) |
---|
| 221 | |
---|
| 222 | |
---|
| 223 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
| 224 | |
---|
| 225 | Bf = File_boundary(source_dir + project.boundary_basename + '.sww', |
---|
| 226 | domain, verbose = True) |
---|
| 227 | Br = Reflective_boundary(domain) |
---|
| 228 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
| 229 | |
---|
| 230 | |
---|
| 231 | # 7 min square wave starting at 1 min, 6m high |
---|
| 232 | Bw = Time_boundary(domain = domain, |
---|
| 233 | f=lambda t: [(60<t<480)*6, 0, 0]) |
---|
| 234 | |
---|
| 235 | domain.set_boundary( {'right': Br, 'bottomright': Br, |
---|
| 236 | 'bottomleft': Br, 'left': Br, 'top': Bf} ) |
---|
| 237 | |
---|
| 238 | #------------------------------------------------------------------------------- |
---|
| 239 | # Evolve system through time |
---|
| 240 | #------------------------------------------------------------------------------- |
---|
| 241 | import time |
---|
| 242 | t0 = time.time() |
---|
| 243 | |
---|
| 244 | for t in domain.evolve(yieldstep = 240, finaltime = 7201): |
---|
| 245 | domain.write_time() |
---|
| 246 | domain.write_boundary_statistics(tags = 'top') |
---|
| 247 | |
---|
| 248 | for t in domain.evolve(yieldstep = 120, finaltime = 12601 |
---|
| 249 | ,skip_initial_step = True): |
---|
| 250 | domain.write_time() |
---|
| 251 | domain.write_boundary_statistics(tags = 'top') |
---|
| 252 | |
---|
| 253 | for t in domain.evolve(yieldstep = 60, finaltime = 19801 |
---|
| 254 | ,skip_initial_step = True): |
---|
| 255 | domain.write_time() |
---|
| 256 | domain.write_boundary_statistics(tags = 'top') |
---|
| 257 | |
---|
| 258 | for t in domain.evolve(yieldstep = 120, finaltime = 25201 |
---|
| 259 | ,skip_initial_step = True): |
---|
| 260 | domain.write_time() |
---|
| 261 | domain.write_boundary_statistics(tags = 'top') |
---|
| 262 | |
---|
| 263 | for t in domain.evolve(yieldstep = 240, finaltime = 36001 |
---|
| 264 | ,skip_initial_step = True): |
---|
| 265 | domain.write_time() |
---|
| 266 | domain.write_boundary_statistics(tags = 'top') |
---|
| 267 | |
---|
| 268 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 269 | |
---|
| 270 | print 'finished' |
---|