[4696] | 1 | """Script for running a tsunami inundation scenario for Port Kembla, NSW, Australia. |
---|
| 2 | |
---|
| 3 | Source data such as elevation and boundary data is assumed to be available in |
---|
| 4 | directories specified by project_kembla.py |
---|
| 5 | |
---|
| 6 | The scenario is defined by a triangular mesh created from project_kembla.polygon, |
---|
| 7 | the elevation data and an input wave. |
---|
| 8 | |
---|
| 9 | Ole Nielsen and Duncan Gray, GA - 2005 and Nick Bartzis and Jane Sexton, GA - 2006 |
---|
| 10 | """ |
---|
| 11 | |
---|
| 12 | #------------------------------------------------------------------------------- |
---|
| 13 | # Import necessary modules |
---|
| 14 | #------------------------------------------------------------------------------- |
---|
| 15 | |
---|
| 16 | # Standard modules |
---|
| 17 | import os |
---|
| 18 | import time |
---|
| 19 | from shutil import copy |
---|
| 20 | from os.path import dirname, basename |
---|
| 21 | from os import mkdir, access, F_OK, sep |
---|
| 22 | import sys |
---|
| 23 | |
---|
| 24 | # Related major packages |
---|
| 25 | from anuga.shallow_water import Domain, Reflective_boundary, Dirichlet_boundary, Time_boundary |
---|
| 26 | from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
| 27 | from anuga.geospatial_data.geospatial_data import * |
---|
| 28 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files |
---|
| 29 | |
---|
| 30 | # Application specific imports |
---|
| 31 | import project_kembla # Definition of file names and polygons |
---|
| 32 | |
---|
| 33 | #------------------------------------------------------------------------------- |
---|
| 34 | # Preparation of topographic data |
---|
| 35 | # |
---|
| 36 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
| 37 | #------------------------------------------------------------------------------- |
---|
| 38 | |
---|
| 39 | # filenames |
---|
| 40 | dem_name = project_kembla.dem_name |
---|
| 41 | meshname = project_kembla.meshname+'.msh' |
---|
| 42 | |
---|
| 43 | # creates DEM from asc data |
---|
| 44 | convert_dem_from_ascii2netcdf(dem_name, use_cache=True, verbose=True) |
---|
| 45 | |
---|
| 46 | #creates pts file for onshore DEM |
---|
| 47 | dem2pts(dem_name, use_cache=True, verbose=True) |
---|
| 48 | |
---|
| 49 | print 'create onshore' |
---|
| 50 | G = Geospatial_data(file_name = project_kembla.dem_name + '.pts') |
---|
| 51 | |
---|
| 52 | print 'export points' |
---|
| 53 | G.export_points_file(project_kembla.combined_dem_name + '.pts') |
---|
| 54 | #G.export_points_file(project_kembla.combined_dem_name + '.xya') |
---|
| 55 | |
---|
| 56 | #---------------------------------------------------------------------------- |
---|
| 57 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
| 58 | # boundary and interior regions defined in project.py along with |
---|
| 59 | # resolutions (maximal area of per triangle) for each polygon |
---|
| 60 | #------------------------------------------------------------------------------- |
---|
| 61 | |
---|
| 62 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
| 63 | remainder_res = 100000 |
---|
| 64 | bay_res = 5000 |
---|
| 65 | interior_regions = [[project_kembla.poly_bay, bay_res]] |
---|
| 66 | |
---|
| 67 | from caching import cache |
---|
| 68 | _ = cache(create_mesh_from_regions, |
---|
| 69 | project_kembla.polyAll, |
---|
| 70 | {'boundary_tags': {'top': [0], 'right': [1], 'bottom': [2], |
---|
| 71 | 'left': [3]}, |
---|
| 72 | 'maximum_triangle_area': remainder_res, |
---|
| 73 | 'filename': meshname, |
---|
| 74 | 'interior_regions': interior_regions}, |
---|
| 75 | verbose = True, evaluate=False) |
---|
| 76 | print 'created mesh' |
---|
| 77 | |
---|
| 78 | #------------------------------------------------------------------------------- |
---|
| 79 | # Setup computational domain |
---|
| 80 | #------------------------------------------------------------------------------- |
---|
| 81 | domain = Domain(meshname, use_cache = True, verbose = True) |
---|
| 82 | |
---|
| 83 | print 'Number of triangles = ', len(domain) |
---|
| 84 | print 'The extent is ', domain.get_extent() |
---|
| 85 | print domain.statistics() |
---|
| 86 | |
---|
| 87 | domain.set_name(project_kembla.basename) |
---|
| 88 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
| 89 | domain.set_minimum_storable_height(0.01) |
---|
| 90 | |
---|
| 91 | #------------------------------------------------------------------------------- |
---|
| 92 | # Setup initial conditions |
---|
| 93 | #------------------------------------------------------------------------------- |
---|
| 94 | |
---|
| 95 | tide = 0.0 |
---|
| 96 | domain.set_quantity('stage', tide) |
---|
| 97 | domain.set_quantity('friction', 0.0) |
---|
| 98 | domain.set_quantity('elevation', |
---|
| 99 | filename = project_kembla.combined_dem_name + '.pts', |
---|
| 100 | use_cache = True, |
---|
| 101 | verbose = True, |
---|
| 102 | alpha = 0.1 |
---|
| 103 | ) |
---|
| 104 | |
---|
| 105 | #------------------------------------------------------------------------------- |
---|
| 106 | # Setup boundary conditions |
---|
| 107 | #------------------------------------------------------------------------------- |
---|
| 108 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
| 109 | |
---|
| 110 | Br = Reflective_boundary(domain) |
---|
| 111 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
| 112 | # 10 min square wave starting at 1 min, 6m high |
---|
| 113 | Bw = Time_boundary(domain=domain, |
---|
| 114 | f=lambda t: [(60<t<660)*6, 0, 0]) |
---|
| 115 | |
---|
| 116 | domain.set_boundary( {'top': Bd, 'right': Bw, 'bottom': Bd, 'left': Bd} ) |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | #------------------------------------------------------------------------------- |
---|
| 120 | # Evolve system through time |
---|
| 121 | #------------------------------------------------------------------------------- |
---|
| 122 | import time |
---|
| 123 | t0 = time.time() |
---|
| 124 | from Numeric import allclose |
---|
| 125 | from anuga.abstract_2d_finite_volumes.quantity import Quantity |
---|
| 126 | |
---|
| 127 | for t in domain.evolve(yieldstep = 30, finaltime = 5000): |
---|
| 128 | domain.write_time() |
---|
| 129 | domain.write_boundary_statistics(tags = '') |
---|
| 130 | stagestep = domain.get_quantity('stage') |
---|
| 131 | |
---|
| 132 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 133 | |
---|
| 134 | print 'finished' |
---|