[4036] | 1 | """Script for running a tsunami inundation scenario for Newcastle, NSW, Australia. |
---|
| 2 | |
---|
| 3 | Source data such as elevation and boundary data is assumed to be available in |
---|
[4063] | 4 | directories specified by project_slide.py |
---|
| 5 | The output sww file is stored in project_slide.outputtimedir |
---|
[4036] | 6 | |
---|
[4063] | 7 | The scenario is defined by a triangular mesh created from project_slide.polygon, |
---|
[4036] | 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 | |
---|
| 31 | # Application specific imports |
---|
| 32 | import project_slide # Definition of file names and polygons |
---|
| 33 | |
---|
| 34 | #------------------------------------------------------------------------------- |
---|
| 35 | # Copy scripts to time stamped output directory and capture screen |
---|
| 36 | # output to file |
---|
| 37 | #------------------------------------------------------------------------------- |
---|
| 38 | |
---|
| 39 | # creates copy of code in output dir |
---|
[4063] | 40 | copy_code_files(project_slide.outputtimedir,__file__,dirname(project_slide.__file__)+sep+ project_slide.__name__+'.py' ) |
---|
[4036] | 41 | myid = 0 |
---|
| 42 | numprocs = 1 |
---|
[4063] | 43 | start_screen_catcher(project_slide.outputtimedir, myid, numprocs) |
---|
[4036] | 44 | |
---|
[4063] | 45 | print 'USER: ', project_slide.user |
---|
[4036] | 46 | |
---|
| 47 | #------------------------------------------------------------------------------- |
---|
| 48 | # Preparation of topographic data |
---|
| 49 | # |
---|
| 50 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
| 51 | #------------------------------------------------------------------------------- |
---|
| 52 | |
---|
| 53 | # filenames |
---|
[4058] | 54 | nsw_dem_name = project_slide.nsw_dem_name |
---|
| 55 | meshname = project_slide.meshname+'.msh' |
---|
[4036] | 56 | |
---|
| 57 | # creates DEM from asc data |
---|
[4058] | 58 | convert_dem_from_ascii2netcdf(nsw_dem_name, use_cache=True, verbose=True) |
---|
[4036] | 59 | |
---|
| 60 | #creates pts file for onshore DEM |
---|
[4058] | 61 | dem2pts(nsw_dem_name, |
---|
| 62 | easting_min=project_slide.eastingmin_nsw, |
---|
| 63 | easting_max=project_slide.eastingmax_nsw, |
---|
| 64 | northing_min=project_slide.northingmin_nsw, |
---|
| 65 | northing_max= project_slide.northingmax_nsw, |
---|
| 66 | use_cache=True, verbose=True) |
---|
[4036] | 67 | |
---|
| 68 | print 'create offshore' |
---|
[4058] | 69 | G11 = Geospatial_data(file_name = project_slide.offshore_dem_name2 + '.xya')+\ |
---|
| 70 | Geospatial_data(file_name = project_slide.offshore_dem_name3 + '.xya') |
---|
| 71 | G12 = Geospatial_data(file_name = project_slide.offshore_dem_name4 + '.xya')+\ |
---|
| 72 | Geospatial_data(file_name = project_slide.offshore_dem_name5 + '.xya')+\ |
---|
| 73 | Geospatial_data(file_name = project_slide.offshore_dem_name6 + '.xya')+\ |
---|
| 74 | Geospatial_data(file_name = project_slide.offshore_dem_name7 + '.xya')+\ |
---|
| 75 | Geospatial_data(file_name = project_slide.offshore_dem_name8 + '.xya')+\ |
---|
| 76 | Geospatial_data(file_name = project_slide.offshore_dem_name9 + '.xya') |
---|
[4036] | 77 | print 'create onshore' |
---|
[4058] | 78 | G4 = Geospatial_data(file_name = project_slide.nsw_dem_name + '.pts') |
---|
[4036] | 79 | print 'add' |
---|
[4058] | 80 | G = G11.clip(Geospatial_data(project_slide.poly_surveyclip)) +\ |
---|
[4063] | 81 | G12.clip(Geospatial_data(project_slide.polyAll)) +\ |
---|
| 82 | (G4.clip(Geospatial_data(project_slide.polyAll)).clip_outside(Geospatial_data(project_slide.poly_surveyclip))) |
---|
[4036] | 83 | print 'export points' |
---|
[4058] | 84 | G.export_points_file(project_slide.combined_dem_name + '.pts') |
---|
| 85 | #G.export_points_file(project_slide.combined_dem_name + '.xya') |
---|
[4036] | 86 | |
---|
[4058] | 87 | |
---|
[4036] | 88 | #---------------------------------------------------------------------------- |
---|
| 89 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
[4063] | 90 | # boundary and interior regions defined in project_slide.py along with |
---|
[4036] | 91 | # resolutions (maximal area of per triangle) for each polygon |
---|
| 92 | #------------------------------------------------------------------------------- |
---|
| 93 | |
---|
| 94 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
| 95 | remainder_res = 500000 |
---|
[4063] | 96 | local_res = 50000 |
---|
| 97 | newcastle_res = 1000 |
---|
| 98 | interior_regions = [[project_slide.poly_local, local_res], |
---|
| 99 | [project_slide.poly_newcastle, newcastle_res]] |
---|
[4036] | 100 | |
---|
| 101 | from caching import cache |
---|
| 102 | _ = cache(create_mesh_from_regions, |
---|
[4063] | 103 | project_slide.polyAll, |
---|
[4036] | 104 | {'boundary_tags': {'e0': [0], 'e1': [1], 'e2': [2], |
---|
[4063] | 105 | 'e3': [3], 'e4':[4]}, |
---|
[4036] | 106 | 'maximum_triangle_area': remainder_res, |
---|
| 107 | 'filename': meshname, |
---|
| 108 | 'interior_regions': interior_regions}, |
---|
| 109 | verbose = True, evaluate=False) |
---|
| 110 | print 'created mesh' |
---|
| 111 | |
---|
| 112 | #------------------------------------------------------------------------------- |
---|
| 113 | # Setup computational domain |
---|
| 114 | #------------------------------------------------------------------------------- |
---|
| 115 | domain = Domain(meshname, use_cache = True, verbose = True) |
---|
| 116 | |
---|
| 117 | print 'Number of triangles = ', len(domain) |
---|
| 118 | print 'The extent is ', domain.get_extent() |
---|
| 119 | print domain.statistics() |
---|
| 120 | |
---|
[4063] | 121 | domain.set_name(project_slide.basename) |
---|
| 122 | domain.set_datadir(project_slide.outputtimedir) |
---|
[4036] | 123 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
| 124 | domain.set_minimum_storable_height(0.01) |
---|
| 125 | |
---|
| 126 | #------------------------------------------------------------------------------- |
---|
| 127 | # Setup initial conditions |
---|
| 128 | #------------------------------------------------------------------------------- |
---|
| 129 | |
---|
| 130 | tide = 0.0 |
---|
| 131 | domain.set_quantity('stage', tide) |
---|
| 132 | domain.set_quantity('friction', 0.0) |
---|
| 133 | domain.set_quantity('elevation', |
---|
[4063] | 134 | filename = project_slide.combined_dem_name + '.pts', |
---|
[4036] | 135 | use_cache = True, |
---|
| 136 | verbose = True, |
---|
| 137 | alpha = 0.1 |
---|
| 138 | ) |
---|
| 139 | |
---|
| 140 | #------------------------------------------------------------------------------- |
---|
| 141 | # Set up scenario (tsunami_source is a callable object used with set_quantity) |
---|
| 142 | #------------------------------------------------------------------------------- |
---|
| 143 | from smf import slide_tsunami |
---|
| 144 | |
---|
[4063] | 145 | tsunami_source = slide_tsunami(length=project_slide.bulli_length, |
---|
| 146 | width=project_slide.bulli_width, |
---|
| 147 | depth=project_slide.bulli_depth, |
---|
| 148 | slope=project_slide.bulli_slope, |
---|
| 149 | thickness=project_slide.bulli_thickness, |
---|
| 150 | x0=project_slide.slide_origin_c[0], |
---|
| 151 | y0=project_slide.slide_origin_c[1], |
---|
| 152 | alpha=project_slide.bulli_alpha, |
---|
[4036] | 153 | domain=domain) |
---|
| 154 | |
---|
| 155 | #------------------------------------------------------------------------------- |
---|
| 156 | # Setup boundary conditions |
---|
| 157 | #------------------------------------------------------------------------------- |
---|
| 158 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
| 159 | |
---|
| 160 | Br = Reflective_boundary(domain) |
---|
| 161 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
| 162 | |
---|
[4063] | 163 | domain.set_boundary( {'e0': Bd, 'e1': Bd, 'e2': Bd, 'e3': Bd, 'e4': Bd} ) |
---|
[4036] | 164 | |
---|
| 165 | |
---|
| 166 | #------------------------------------------------------------------------------- |
---|
| 167 | # Evolve system through time |
---|
| 168 | #------------------------------------------------------------------------------- |
---|
| 169 | import time |
---|
| 170 | t0 = time.time() |
---|
| 171 | |
---|
| 172 | for t in domain.evolve(yieldstep = 30, finaltime = 480): |
---|
| 173 | domain.write_time() |
---|
| 174 | domain.write_boundary_statistics(tags = 'e14') |
---|
| 175 | stagestep = domain.get_quantity('stage') |
---|
| 176 | |
---|
| 177 | if allclose(t, 30): |
---|
| 178 | slide = Quantity(domain) |
---|
| 179 | slide.set_values(tsunami_source) |
---|
| 180 | domain.set_quantity('stage', slide + stagestep) |
---|
| 181 | |
---|
| 182 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 183 | |
---|
| 184 | print 'finished' |
---|