[2240] | 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.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, |
---|
[2407] | 8 | the elevation data and a simulated submarine landslide. |
---|
[2240] | 9 | |
---|
[2407] | 10 | Ole Nielsen and Duncan Gray, GA - 2005 and Adrian Hitchman and Jane Sexton, GA - 2006 |
---|
[2240] | 11 | """ |
---|
| 12 | |
---|
| 13 | |
---|
[2407] | 14 | #-------------------------------------------------------------------------------# Import necessary modules |
---|
| 15 | #------------------------------------------------------------------------------- |
---|
| 16 | |
---|
| 17 | # Standard modules |
---|
[2240] | 18 | import os |
---|
| 19 | import time |
---|
| 20 | |
---|
[2407] | 21 | # Related major packages |
---|
[2640] | 22 | from pyvolution.shallow_water import Domain, Reflective_boundary, Dirichlet_boundary |
---|
[2407] | 23 | from pyvolution.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
[2640] | 24 | #from pyvolution.data_manager_old import convert_dem_from_ascii2netcdf, dem2pts |
---|
[2407] | 25 | from pyvolution.combine_pts import combine_rectangular_points_files |
---|
[2292] | 26 | from pyvolution.pmesh2domain import pmesh_to_domain_instance |
---|
[2640] | 27 | from pyvolution.quantity import Quantity |
---|
| 28 | from Numeric import allclose |
---|
[2240] | 29 | |
---|
[2407] | 30 | # Application specific imports |
---|
| 31 | import project # Definition of file names and polygons |
---|
[2460] | 32 | from pyvolution.smf import slump_tsunami # Function for submarine mudslide |
---|
[2407] | 33 | |
---|
| 34 | |
---|
| 35 | #------------------------------------------------------------------------------- |
---|
| 36 | # Preparation of topographic data |
---|
| 37 | # |
---|
[2292] | 38 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
| 39 | # Do for coarse and fine data |
---|
| 40 | # Fine pts file to be clipped to area of interest |
---|
[2407] | 41 | #------------------------------------------------------------------------------- |
---|
| 42 | |
---|
| 43 | # filenames |
---|
[2292] | 44 | coarsedemname = project.coarsedemname |
---|
| 45 | finedemname = project.finedemname |
---|
[2240] | 46 | meshname = project.meshname+'.msh' |
---|
| 47 | |
---|
[2292] | 48 | # coarse data |
---|
[2407] | 49 | convert_dem_from_ascii2netcdf(coarsedemname, use_cache=True, verbose=True) |
---|
| 50 | dem2pts(coarsedemname, use_cache=True, verbose=True) |
---|
[2240] | 51 | |
---|
[2407] | 52 | # fine data (clipping the points file to smaller area) |
---|
| 53 | convert_dem_from_ascii2netcdf(finedemname, use_cache=True, verbose=True) |
---|
| 54 | dem2pts(finedemname, |
---|
| 55 | easting_min=project.eastingmin, |
---|
| 56 | easting_max=project.eastingmax, |
---|
| 57 | northing_min=project.northingmin, |
---|
| 58 | northing_max= project.northingmax, |
---|
| 59 | use_cache=True, |
---|
| 60 | verbose=True) |
---|
[2240] | 61 | |
---|
[2292] | 62 | # combining the coarse and fine data |
---|
| 63 | combine_rectangular_points_files(project.finedemname + '.pts', |
---|
| 64 | project.coarsedemname + '.pts', |
---|
| 65 | project.combineddemname + '.pts') |
---|
[2407] | 66 | |
---|
[2456] | 67 | #from pmesh.create_mesh import create_mesh_from_regions |
---|
[2640] | 68 | #new interface |
---|
[2456] | 69 | from pmesh.mesh_interface import create_mesh_from_regions |
---|
[2407] | 70 | |
---|
[2640] | 71 | # original issue to Benfield |
---|
| 72 | #interior_res = 5000 |
---|
| 73 | #interior_regions = [[project.harbour_polygon_2, interior_res], |
---|
| 74 | # [project.botanybay_polygon_2, interior_res]] |
---|
[2350] | 75 | |
---|
[2640] | 76 | # used for finer mesh |
---|
| 77 | interior_res1 = 5000 |
---|
| 78 | interior_res2 = 315 |
---|
| 79 | interior_regions = [[project.newpoly1, interior_res1], |
---|
| 80 | [project.south1, interior_res1], |
---|
| 81 | [project.finepolymanly, interior_res2], |
---|
| 82 | [project.finepolyquay, interior_res2]] |
---|
| 83 | |
---|
| 84 | print 'number of interior regions', len(interior_regions) |
---|
| 85 | |
---|
[2407] | 86 | #FIXME: Fix caching of this one once the mesh_interface is ready |
---|
| 87 | from caching import cache |
---|
[2456] | 88 | |
---|
[2640] | 89 | # original + refined region |
---|
[2407] | 90 | _ = cache(create_mesh_from_regions, |
---|
| 91 | project.diffpolygonall, |
---|
| 92 | {'boundary_tags': {'bottom': [0], |
---|
| 93 | 'right1': [1], 'right0': [2], |
---|
| 94 | 'right2': [3], 'top': [4], 'left1': [5], |
---|
| 95 | 'left2': [6], 'left3': [7]}, |
---|
[2456] | 96 | 'maximum_triangle_area': 100000, |
---|
[2407] | 97 | 'filename': meshname, |
---|
[2456] | 98 | 'interior_regions': interior_regions}, |
---|
[2407] | 99 | verbose = True) |
---|
[2350] | 100 | |
---|
[2640] | 101 | #------------------------------------------------------------------------------- |
---|
[2407] | 102 | # Setup computational domain |
---|
[2640] | 103 | #------------------------------------------------------------------------------- |
---|
[2407] | 104 | |
---|
| 105 | domain = pmesh_to_domain_instance(meshname, Domain, |
---|
| 106 | use_cache = True, |
---|
| 107 | verbose = True) |
---|
| 108 | |
---|
[2240] | 109 | print 'Number of triangles = ', len(domain) |
---|
| 110 | print 'The extent is ', domain.get_extent() |
---|
[2640] | 111 | print domain.statistics() |
---|
[2240] | 112 | |
---|
| 113 | domain.set_name(project.basename) |
---|
| 114 | domain.set_datadir(project.outputdir) |
---|
[2407] | 115 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
[2240] | 116 | |
---|
[2407] | 117 | |
---|
| 118 | #------------------------------------------------------------------------------- |
---|
| 119 | # Set up scenario (tsunami_source is a callable object used with set_quantity) |
---|
| 120 | #------------------------------------------------------------------------------- |
---|
| 121 | |
---|
| 122 | tsunami_source = slump_tsunami(length=30000.0, |
---|
| 123 | depth=400.0, |
---|
| 124 | slope=6.0, |
---|
| 125 | thickness=176.0, |
---|
| 126 | radius=3330, |
---|
| 127 | dphi=0.23, |
---|
| 128 | x0=project.slump_origin[0], |
---|
| 129 | y0=project.slump_origin[1], |
---|
| 130 | alpha=0.0, |
---|
| 131 | domain=domain) |
---|
| 132 | |
---|
| 133 | |
---|
[2640] | 134 | #------------------------------------------------------------------------------- |
---|
[2407] | 135 | # Setup initial conditions |
---|
| 136 | #------------------------------------------------------------------------------- |
---|
| 137 | |
---|
[2640] | 138 | # apply slump after 30 mins, initialise to water level of tide = 0 |
---|
| 139 | domain.set_quantity('stage', 0.0) |
---|
| 140 | domain.set_quantity('friction', 0.03) |
---|
[2407] | 141 | domain.set_quantity('elevation', |
---|
| 142 | filename = project.combineddemname + '.pts', |
---|
| 143 | use_cache = True, |
---|
| 144 | verbose = True) |
---|
[2240] | 145 | |
---|
[2407] | 146 | |
---|
| 147 | #------------------------------------------------------------------------------- |
---|
| 148 | # Setup boundary conditions (all reflective) |
---|
| 149 | #------------------------------------------------------------------------------- |
---|
| 150 | |
---|
| 151 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
| 152 | |
---|
[2240] | 153 | Br = Reflective_boundary(domain) |
---|
[2640] | 154 | Bd = Dirichlet_boundary([0, 0, 0]) |
---|
[2292] | 155 | |
---|
[2640] | 156 | # original + refined regions |
---|
| 157 | #domain.set_boundary( {'bottom': Br, 'right1': Br, 'right0': Br, |
---|
| 158 | # 'right2': Br, 'top': Br, 'left1': Br, |
---|
| 159 | # 'left2': Br, 'left3': Br} ) |
---|
[2407] | 160 | |
---|
[2640] | 161 | # enforce Dirichlet BC - from 30/03/06 Benfield visit |
---|
| 162 | domain.set_boundary( {'bottom': Bd, 'right1': Bd, 'right0': Bd, |
---|
| 163 | 'right2': Bd, 'top': Bd, 'left1': Bd, |
---|
| 164 | 'left2': Bd, 'left3': Bd} ) |
---|
| 165 | |
---|
| 166 | # increasingly finer interior regions |
---|
| 167 | #domain.set_boundary( {'bottom': Br, 'right': Br, 'left': Br, 'top': Br} ) |
---|
| 168 | |
---|
| 169 | |
---|
[2407] | 170 | #------------------------------------------------------------------------------- |
---|
| 171 | # Evolve system through time |
---|
| 172 | #------------------------------------------------------------------------------- |
---|
| 173 | |
---|
[2240] | 174 | import time |
---|
| 175 | t0 = time.time() |
---|
[2640] | 176 | thisfile = project.integraltimeseries+'.csv' |
---|
| 177 | fid = open(thisfile, 'w') |
---|
[2240] | 178 | |
---|
[2640] | 179 | for t in domain.evolve(yieldstep = 120, finaltime = 18000): |
---|
[2240] | 180 | domain.write_time() |
---|
[2640] | 181 | domain.write_boundary_statistics(tags = 'bottom') |
---|
| 182 | |
---|
| 183 | # calculate integral |
---|
| 184 | thisstagestep = domain.get_quantity('stage') |
---|
| 185 | s = '%.2f, %.2f\n' %(t, thisstagestep.get_integral()) |
---|
| 186 | fid.write(s) |
---|
| 187 | |
---|
| 188 | # add slump after 30 mins |
---|
| 189 | if allclose(t, 30*60): |
---|
| 190 | slump = Quantity(domain) |
---|
| 191 | slump.set_values(tsunami_source) |
---|
| 192 | domain.set_quantity('stage', slump + thisstagestep) |
---|
[2240] | 193 | |
---|
[2640] | 194 | |
---|
[2240] | 195 | print 'That took %.2f seconds' %(time.time()-t0) |
---|