[2437] | 1 | """Script for running a tsunami inundation scenario for Onslow, WA, Australia. |
---|
[2436] | 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 | |
---|
[2437] | 10 | Ole Nielsen and Duncan Gray, GA - 2005 and Nick Bartzis, GA - 2006 |
---|
[2436] | 11 | """ |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | #-------------------------------------------------------------------------------# Import necessary modules |
---|
| 15 | #------------------------------------------------------------------------------- |
---|
| 16 | |
---|
| 17 | # Standard modules |
---|
| 18 | import os |
---|
| 19 | import time |
---|
| 20 | |
---|
| 21 | # Related major packages |
---|
[2470] | 22 | from pyvolution.shallow_water import Domain, Reflective_boundary, \ |
---|
[2615] | 23 | Dirichlet_boundary, Time_boundary, File_boundary |
---|
[2436] | 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 |
---|
[2615] | 27 | from geospatial_data import add_points_files |
---|
[2436] | 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 | |
---|
[2615] | 33 | from shutil import copy |
---|
| 34 | from os import mkdir, access, F_OK |
---|
[2436] | 35 | |
---|
[2615] | 36 | from geospatial_data import * |
---|
| 37 | |
---|
[2436] | 38 | #------------------------------------------------------------------------------- |
---|
| 39 | # Preparation of topographic data |
---|
| 40 | # |
---|
| 41 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
| 42 | # Do for coarse and fine data |
---|
| 43 | # Fine pts file to be clipped to area of interest |
---|
| 44 | #------------------------------------------------------------------------------- |
---|
[2443] | 45 | |
---|
[2436] | 46 | # filenames |
---|
| 47 | coarsedemname = project.coarsedemname |
---|
[2615] | 48 | |
---|
| 49 | onshore_dem_name = project.onshore_dem_name |
---|
| 50 | |
---|
| 51 | offshore_points = project.offshore_dem_name |
---|
| 52 | |
---|
[2436] | 53 | meshname = project.meshname+'.msh' |
---|
[2443] | 54 | |
---|
[2615] | 55 | source_dir = project.boundarydir |
---|
| 56 | |
---|
| 57 | # creates copy of code in output dir |
---|
| 58 | if access(project.outputdir,F_OK) == 0 : |
---|
| 59 | mkdir (project.outputdir) |
---|
| 60 | copy (project.codedirname, project.outputdir + project.codename) |
---|
| 61 | copy (project.codedir + 'run_onslow.py', project.outputdir + 'run_onslow.py') |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | ''' |
---|
[2436] | 65 | # coarse data |
---|
| 66 | convert_dem_from_ascii2netcdf(coarsedemname, use_cache=True, verbose=True) |
---|
| 67 | dem2pts(coarsedemname, use_cache=True, verbose=True) |
---|
[2615] | 68 | |
---|
| 69 | |
---|
[2436] | 70 | # fine data (clipping the points file to smaller area) |
---|
[2615] | 71 | convert_dem_from_ascii2netcdf(onshore_dem_name, use_cache=True, verbose=True) |
---|
| 72 | dem2pts(onshore_dem_name, |
---|
[2436] | 73 | easting_min=project.eastingmin, |
---|
| 74 | easting_max=project.eastingmax, |
---|
| 75 | northing_min=project.northingmin, |
---|
| 76 | northing_max= project.northingmax, |
---|
| 77 | use_cache=True, |
---|
| 78 | verbose=True) |
---|
| 79 | |
---|
[2615] | 80 | ''' |
---|
| 81 | print'create G1' |
---|
| 82 | G1 = Geospatial_data(file_name = project.offshore_dem_name + '.xya') |
---|
[2436] | 83 | |
---|
[2615] | 84 | print'create G2' |
---|
| 85 | G2 = Geospatial_data(file_name = project.onshore_dem_name + '.pts') |
---|
| 86 | |
---|
| 87 | print'add G1+G2' |
---|
| 88 | G = G1 + G2 |
---|
| 89 | |
---|
| 90 | print'export G' |
---|
| 91 | G.new_export_points_file(project.combined_dem_name + '.pts') |
---|
| 92 | |
---|
[2436] | 93 | ''' |
---|
[2615] | 94 | add_points_files( |
---|
| 95 | project.offshore_dem_name + '.xya', |
---|
| 96 | project.onshore_dem_name + '.pts', |
---|
| 97 | project.combined_dem_name + '.pts') |
---|
| 98 | ''' |
---|
[2436] | 99 | #------------------------------------------------------------------------------- |
---|
| 100 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
| 101 | # boundary and interior regions defined in project.py along with |
---|
| 102 | # resolutions (maximal area of per triangle) for each polygon |
---|
| 103 | #------------------------------------------------------------------------------- |
---|
| 104 | |
---|
[2615] | 105 | from pmesh.mesh_interface import create_mesh_from_regions |
---|
[2436] | 106 | |
---|
| 107 | # original |
---|
| 108 | interior_res = 5000 |
---|
[2441] | 109 | interior_regions = [[project.poly_onslow, interior_res], |
---|
| 110 | [project.poly_thevenard, interior_res], |
---|
| 111 | [project.poly_direction, interior_res]] |
---|
[2615] | 112 | #[project.testpoly, interior_res]] |
---|
| 113 | print 'number of interior regions', len(interior_regions) |
---|
[2436] | 114 | |
---|
| 115 | from caching import cache |
---|
| 116 | _ = cache(create_mesh_from_regions, |
---|
| 117 | project.polyAll, |
---|
| 118 | {'boundary_tags': {'top': [0], 'topleft': [1], |
---|
| 119 | 'left': [2], 'bottom': [3], |
---|
| 120 | 'bottomright': [4], 'topright': [5]}, |
---|
[2615] | 121 | 'maximum_triangle_area': 100000, |
---|
[2436] | 122 | 'filename': meshname, |
---|
[2615] | 123 | 'interior_regions': interior_regions}, |
---|
[2436] | 124 | verbose = True) |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | #------------------------------------------------------------------------------- |
---|
| 128 | # Setup computational domain |
---|
| 129 | #------------------------------------------------------------------------------- |
---|
| 130 | |
---|
| 131 | domain = pmesh_to_domain_instance(meshname, Domain, |
---|
| 132 | use_cache = True, |
---|
| 133 | verbose = True) |
---|
| 134 | |
---|
| 135 | print 'Number of triangles = ', len(domain) |
---|
| 136 | print 'The extent is ', domain.get_extent() |
---|
[2615] | 137 | print domain.statistics() |
---|
[2436] | 138 | |
---|
| 139 | domain.set_name(project.basename) |
---|
| 140 | domain.set_datadir(project.outputdir) |
---|
[2615] | 141 | domain.set_quantities_to_be_stored(['stage']) |
---|
[2436] | 142 | |
---|
| 143 | |
---|
| 144 | #------------------------------------------------------------------------------- |
---|
| 145 | # Set up scenario (tsunami_source is a callable object used with set_quantity) |
---|
| 146 | #------------------------------------------------------------------------------- |
---|
| 147 | ''' |
---|
| 148 | tsunami_source = slump_tsunami(length=30000.0, |
---|
| 149 | depth=400.0, |
---|
| 150 | slope=6.0, |
---|
| 151 | thickness=176.0, |
---|
| 152 | radius=3330, |
---|
| 153 | dphi=0.23, |
---|
| 154 | x0=project.slump_origin[0], |
---|
| 155 | y0=project.slump_origin[1], |
---|
| 156 | alpha=0.0, |
---|
| 157 | domain=domain) |
---|
| 158 | |
---|
| 159 | ''' |
---|
| 160 | #------------------------------------------------------------------------------- |
---|
| 161 | # Setup initial conditions |
---|
| 162 | #------------------------------------------------------------------------------- |
---|
| 163 | |
---|
[2470] | 164 | tide = 0. |
---|
| 165 | |
---|
| 166 | domain.set_quantity('stage', tide) |
---|
[2436] | 167 | domain.set_quantity('friction', 0.0) |
---|
[2615] | 168 | print 'hi and file',project.combined_dem_name + '.pts' |
---|
[2443] | 169 | domain.set_quantity('elevation', |
---|
[2615] | 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 = False, |
---|
| 175 | verbose = True, |
---|
| 176 | alpha = 0.1 |
---|
[2436] | 177 | ) |
---|
[2615] | 178 | print 'hi1' |
---|
[2436] | 179 | |
---|
| 180 | #------------------------------------------------------------------------------- |
---|
| 181 | # Setup boundary conditions (all reflective) |
---|
| 182 | #------------------------------------------------------------------------------- |
---|
| 183 | |
---|
[2470] | 184 | from pyvolution.data_manager import ferret2sww |
---|
| 185 | |
---|
| 186 | south = project.south |
---|
| 187 | north = project.north |
---|
| 188 | west = project.west |
---|
| 189 | east = project.east |
---|
| 190 | |
---|
[2451] | 191 | cache(ferret2sww, |
---|
[2615] | 192 | (source_dir + project.boundary_basename, |
---|
| 193 | source_dir + project.boundary_basename), |
---|
[2451] | 194 | {'verbose': True, |
---|
[2615] | 195 | # note didn't work with the below |
---|
| 196 | # 'minlat': south - 1, |
---|
| 197 | # 'maxlat': north + 1, |
---|
| 198 | # 'minlon': west - 1, |
---|
| 199 | # 'maxlon': east + 1, |
---|
| 200 | 'minlat': south, |
---|
| 201 | 'maxlat': north, |
---|
| 202 | 'minlon': west, |
---|
| 203 | 'maxlon': east, |
---|
| 204 | # 'origin': project.mesh_origin, |
---|
| 205 | 'origin': domain.geo_reference.get_origin(), |
---|
[2451] | 206 | 'mean_stage': tide, |
---|
| 207 | 'zscale': 1, #Enhance tsunami |
---|
| 208 | 'fail_on_NaN': False, |
---|
| 209 | 'inverted_bathymetry': True}, |
---|
| 210 | #evaluate = True, |
---|
| 211 | verbose = True) |
---|
| 212 | |
---|
| 213 | |
---|
[2436] | 214 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
| 215 | |
---|
[2615] | 216 | Bf = File_boundary(source_dir + project.boundary_basename + '.sww', |
---|
| 217 | domain, verbose = True) |
---|
[2436] | 218 | Br = Reflective_boundary(domain) |
---|
[2470] | 219 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
| 220 | |
---|
| 221 | |
---|
| 222 | # 7 min square wave starting at 1 min, 6m high |
---|
[2437] | 223 | Bw = Time_boundary(domain = domain, |
---|
[2470] | 224 | f=lambda t: [(60<t<480)*6, 0, 0]) |
---|
[2437] | 225 | |
---|
[2615] | 226 | domain.set_boundary( {'top': Bf, 'topleft': Bf, |
---|
[2436] | 227 | 'left': Br, 'bottom': Br, |
---|
[2615] | 228 | 'bottomright': Br, 'topright': Bf} ) |
---|
[2436] | 229 | |
---|
| 230 | |
---|
| 231 | #------------------------------------------------------------------------------- |
---|
| 232 | # Evolve system through time |
---|
| 233 | #------------------------------------------------------------------------------- |
---|
| 234 | import time |
---|
| 235 | t0 = time.time() |
---|
| 236 | |
---|
[2470] | 237 | for t in domain.evolve(yieldstep = 50, finaltime = 100): |
---|
[2436] | 238 | domain.write_time() |
---|
| 239 | domain.write_boundary_statistics(tags = 'top') |
---|
| 240 | |
---|
| 241 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
[2615] | 242 | |
---|
| 243 | print 'finished' |
---|