[4968] | 1 | """Script for running a tsunami inundation scenario for Sydney, NSW, Australia. |
---|
| 2 | |
---|
| 3 | Source data such as elevation and boundary data is assumed to be available in |
---|
| 4 | directories specified by project_smf.py |
---|
| 5 | The output sww file is stored in project_smf.outputtimedir |
---|
| 6 | |
---|
| 7 | The scenario is defined by a triangular mesh created from project_smf.polygon, |
---|
| 8 | the elevation data and a tsunami wave generated by s submarine mass failure. |
---|
| 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 | from shutil import copy |
---|
| 21 | from os.path import dirname, basename |
---|
| 22 | from os import mkdir, access, F_OK, sep |
---|
| 23 | import sys |
---|
| 24 | |
---|
| 25 | # Related major packages |
---|
| 26 | from anuga.shallow_water import Domain, Reflective_boundary, Dirichlet_boundary |
---|
| 27 | from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
| 28 | from anuga.geospatial_data.geospatial_data import * |
---|
| 29 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files |
---|
| 30 | from anuga_parallel.parallel_api import distribute, numprocs, myid, barrier |
---|
| 31 | |
---|
| 32 | # Application specific imports |
---|
| 33 | import project_smf # Definition of file names and polygons |
---|
| 34 | |
---|
| 35 | #------------------------------------------------------------------------------- |
---|
| 36 | # Copy scripts to time stamped output directory and capture screen |
---|
| 37 | # output to file |
---|
| 38 | #------------------------------------------------------------------------------- |
---|
| 39 | |
---|
| 40 | # creates copy of code in output dir |
---|
| 41 | #copy_code_files(project_smf.outputtimedir,__file__,dirname(project_smf.__file__)+sep+ project_smf.__name__+'.py' ) |
---|
| 42 | myid = 0 |
---|
| 43 | numprocs = 1 |
---|
| 44 | #start_screen_catcher(project_smf.outputtimedir, myid, numprocs) |
---|
| 45 | #barrier() |
---|
| 46 | |
---|
| 47 | print 'USER: ', project_smf.user |
---|
| 48 | |
---|
| 49 | #------------------------------------------------------------------------------- |
---|
| 50 | # Preparation of topographic data |
---|
| 51 | # |
---|
| 52 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
| 53 | #------------------------------------------------------------------------------- |
---|
| 54 | |
---|
| 55 | # filenames |
---|
[5245] | 56 | onshore_250_dem_name = project_smf.onshore_250_dem_name |
---|
[4968] | 57 | meshname = project_smf.meshname+'.msh' |
---|
| 58 | |
---|
| 59 | # creates DEM from asc data |
---|
[5245] | 60 | convert_dem_from_ascii2netcdf(onshore_250_dem_name, use_cache=True, verbose=True) |
---|
[4968] | 61 | |
---|
| 62 | #creates pts file for onshore DEM |
---|
[5245] | 63 | dem2pts(onshore_250_dem_name, use_cache=True, verbose=True) |
---|
[4968] | 64 | |
---|
| 65 | print 'create offshore' |
---|
[5245] | 66 | G1 = Geospatial_data(file_name = project_smf.offshore_dem_name1 + '.txt')+\ |
---|
| 67 | Geospatial_data(file_name = project_smf.offshore_dem_name2 + '.txt')+\ |
---|
| 68 | Geospatial_data(file_name = project_smf.offshore_dem_name3 + '.txt') |
---|
[4968] | 69 | |
---|
| 70 | print 'create onshore' |
---|
[5245] | 71 | G2 = Geospatial_data(file_name = project_smf.onshore_250_dem_name + '.pts') |
---|
[4968] | 72 | |
---|
[5245] | 73 | print 'create coastline' |
---|
| 74 | G3 = Geospatial_data(file_name = project_smf.coast_line + '.txt') |
---|
| 75 | |
---|
[4968] | 76 | print 'add' |
---|
[5245] | 77 | G = G1.clip(Geospatial_data(project_smf.polyAll)) + G2 + G3 |
---|
[4968] | 78 | |
---|
| 79 | print 'export points' |
---|
| 80 | G.export_points_file(project_smf.combined_dem_name + '.pts') |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | #---------------------------------------------------------------------------- |
---|
| 84 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
| 85 | # boundary and interior regions defined in project_smf.py along with |
---|
| 86 | # resolutions (maximal area of per triangle) for each polygon |
---|
| 87 | #------------------------------------------------------------------------------- |
---|
| 88 | |
---|
| 89 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
| 90 | remainder_res = 250000. |
---|
| 91 | region_res = 50000. |
---|
| 92 | local_res = 500. |
---|
| 93 | interior_regions = [[project_smf.poly_region, region_res], |
---|
| 94 | [project_smf.poly_local, local_res]] |
---|
| 95 | |
---|
| 96 | from caching import cache |
---|
| 97 | _ = cache(create_mesh_from_regions, |
---|
| 98 | project_smf.polyAll, |
---|
| 99 | {'boundary_tags': {'e0': [0], 'e1': [1], 'e2': [2], |
---|
| 100 | 'e3': [3], 'e4':[4]}, |
---|
| 101 | 'maximum_triangle_area': remainder_res, |
---|
| 102 | 'filename': meshname, |
---|
| 103 | 'interior_regions': interior_regions}, |
---|
| 104 | verbose = True, evaluate=False) |
---|
| 105 | print 'created mesh' |
---|
| 106 | |
---|
| 107 | #------------------------------------------------------------------------------- |
---|
| 108 | # Setup computational domain |
---|
| 109 | #------------------------------------------------------------------------------- |
---|
| 110 | domain = Domain(meshname, use_cache = True, verbose = True) |
---|
| 111 | |
---|
| 112 | print 'Number of triangles = ', len(domain) |
---|
| 113 | print 'The extent is ', domain.get_extent() |
---|
| 114 | print domain.statistics() |
---|
| 115 | |
---|
| 116 | domain.set_name(project_smf.basename) |
---|
| 117 | domain.set_datadir(project_smf.outputtimedir) |
---|
| 118 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
| 119 | domain.set_minimum_storable_height(0.01) |
---|
| 120 | domain.beta_h = 0 |
---|
| 121 | domain.tight_slope_limiters = 1 |
---|
| 122 | domain.set_store_vertices_uniquely(False) |
---|
| 123 | domain.set_maximum_allowed_speed(0.1) |
---|
| 124 | |
---|
| 125 | #------------------------------------------------------------------------------- |
---|
| 126 | # Setup initial conditions |
---|
| 127 | #------------------------------------------------------------------------------- |
---|
| 128 | |
---|
| 129 | tide = 0.0 |
---|
| 130 | domain.set_quantity('stage', tide) |
---|
| 131 | domain.set_quantity('friction', 0.0) |
---|
| 132 | domain.set_quantity('elevation', |
---|
| 133 | filename = project_smf.combined_dem_name + '.pts', |
---|
| 134 | use_cache = True, |
---|
| 135 | verbose = True, |
---|
| 136 | alpha = 0.1 |
---|
| 137 | ) |
---|
| 138 | |
---|
| 139 | #------------------------------------------------------------------------------- |
---|
| 140 | # Set up scenario (tsunami_source is a callable object used with set_quantity) |
---|
| 141 | #------------------------------------------------------------------------------- |
---|
| 142 | from smf import slide_tsunami |
---|
| 143 | |
---|
| 144 | tsunami_source = slide_tsunami(length=project_smf.length, |
---|
| 145 | width=project_smf.width, |
---|
| 146 | depth=project_smf.depth, |
---|
| 147 | slope=project_smf.slope, |
---|
| 148 | thickness=project_smf.thickness, |
---|
| 149 | x0=project_smf.smf_origin[0], |
---|
| 150 | y0=project_smf.smf_origin[1], |
---|
| 151 | alpha=project_smf.alpha, |
---|
| 152 | domain=domain) |
---|
| 153 | |
---|
| 154 | #------------------------------------------------------------------------------- |
---|
| 155 | # Setup boundary conditions |
---|
| 156 | #------------------------------------------------------------------------------- |
---|
| 157 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
| 158 | |
---|
| 159 | Br = Reflective_boundary(domain) |
---|
| 160 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
| 161 | |
---|
| 162 | domain.set_boundary( {'e0': Bd, 'e1': Bd, 'e2': Bd, 'e3': Bd, 'e4': Bd} ) |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | #------------------------------------------------------------------------------- |
---|
| 166 | # Evolve system through time |
---|
| 167 | #------------------------------------------------------------------------------- |
---|
| 168 | import time |
---|
| 169 | from Numeric import allclose |
---|
| 170 | from anuga.abstract_2d_finite_volumes.quantity import Quantity |
---|
| 171 | |
---|
| 172 | t0 = time.time() |
---|
| 173 | |
---|
| 174 | for t in domain.evolve(yieldstep = 30, finaltime = 5000): |
---|
| 175 | domain.write_time() |
---|
| 176 | domain.write_boundary_statistics(tags = 'e2') |
---|
| 177 | stagestep = domain.get_quantity('stage') |
---|
| 178 | |
---|
| 179 | if allclose(t, 30): |
---|
| 180 | smf = Quantity(domain) |
---|
| 181 | smf.set_values(tsunami_source) |
---|
| 182 | domain.set_quantity('stage', smf + stagestep) |
---|
| 183 | |
---|
| 184 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 185 | |
---|
| 186 | print 'finished' |
---|