[2181] | 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, |
---|
| 8 | the elevation data and boundary data obtained from a tsunami simulation done with MOST. |
---|
| 9 | |
---|
[2188] | 10 | Ole Nielsen, GA - 2005 and Jane Sexton, GA - 2006 |
---|
[2181] | 11 | """ |
---|
| 12 | |
---|
| 13 | tide = 0 #Australian Height Datum (mean sea level) |
---|
| 14 | |
---|
| 15 | import os |
---|
| 16 | import time |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | from pyvolution.shallow_water import Domain, Reflective_boundary, File_boundary,\ |
---|
| 20 | Dirichlet_boundary, Time_boundary, Transmissive_boundary |
---|
| 21 | from pyvolution.data_manager import convert_dem_from_ascii2netcdf,\ |
---|
| 22 | dem2pts |
---|
| 23 | from pyvolution.pmesh2domain import pmesh_to_domain_instance |
---|
| 24 | from caching import cache |
---|
| 25 | import project |
---|
| 26 | from math import pi, sin |
---|
| 27 | |
---|
| 28 | #Data preparation |
---|
| 29 | #Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
| 30 | demname = project.demname |
---|
| 31 | meshname = project.meshname+'.msh' |
---|
| 32 | |
---|
| 33 | cache(convert_dem_from_ascii2netcdf, demname, {'verbose': True}, |
---|
| 34 | dependencies = [demname + '.asc'], |
---|
| 35 | verbose = True) |
---|
| 36 | #evaluate = True) |
---|
| 37 | |
---|
| 38 | cache(dem2pts, demname, {'verbose': True}, |
---|
| 39 | dependencies = [demname + '.dem'], |
---|
| 40 | verbose = True) |
---|
| 41 | |
---|
[2188] | 42 | #this allows the user to switch between different clipping polygons |
---|
| 43 | print 'Which total zone are you interested in?' |
---|
| 44 | mytest = int(raw_input('0 = all, 1 = harbour and 2 = botany bay ')) |
---|
[2181] | 45 | |
---|
| 46 | #Create Triangular Mesh |
---|
| 47 | from pmesh.create_mesh import create_mesh_from_regions |
---|
| 48 | |
---|
[2186] | 49 | if mytest == 0: |
---|
| 50 | # for whole region |
---|
| 51 | south = project.south |
---|
| 52 | north = project.north |
---|
| 53 | west = project.west |
---|
| 54 | east = project.east |
---|
[2181] | 55 | |
---|
[2186] | 56 | interior_regions = [[project.harbour_polygon, 25000], |
---|
| 57 | [project.botanybay_polygon, 25000]] # maximal area of per triangle |
---|
| 58 | |
---|
| 59 | m = cache(create_mesh_from_regions, |
---|
| 60 | project.polygonall, |
---|
| 61 | {'boundary_tags': {'bottom': [0], 'top': [2], |
---|
| 62 | 'right': [1], 'left': [3]}, |
---|
| 63 | 'resolution': 100000, |
---|
| 64 | 'filename': meshname, |
---|
[2188] | 65 | 'interior_regions': interior_regions}, |
---|
| 66 | evaluate=True, |
---|
[2186] | 67 | verbose = True) |
---|
[2188] | 68 | #import sys; sys.exit() |
---|
[2181] | 69 | |
---|
[2186] | 70 | if mytest == 1: |
---|
| 71 | # for harbour region |
---|
| 72 | south = project.hsouth |
---|
| 73 | north = project.hnorth |
---|
| 74 | west = project.hwest |
---|
| 75 | east = project.heast |
---|
| 76 | |
---|
[2188] | 77 | #interior_regions = [[project.harbour_polygon, 25000]] # maximal area of per triangle |
---|
[2186] | 78 | |
---|
| 79 | m = cache(create_mesh_from_regions, |
---|
| 80 | project.polygon_h, |
---|
| 81 | {'boundary_tags': {'bottom': [0], 'top': [2], |
---|
| 82 | 'right': [1], 'left': [3]}, |
---|
[2188] | 83 | 'resolution': 50000, |
---|
| 84 | 'filename': meshname}, |
---|
| 85 | # 'interior_regions': interior_regions}, |
---|
| 86 | evaluate=True, |
---|
[2186] | 87 | verbose = True) |
---|
| 88 | |
---|
| 89 | if mytest == 2: |
---|
| 90 | # for botany bay region |
---|
| 91 | south = project.bsouth |
---|
| 92 | north = project.bnorth |
---|
| 93 | west = project.bwest |
---|
| 94 | east = project.beast |
---|
| 95 | |
---|
[2188] | 96 | #interior_regions = [[project.botanybay_polygon, 25000]] # maximal area of per triangle |
---|
[2186] | 97 | |
---|
| 98 | m = cache(create_mesh_from_regions, |
---|
| 99 | project.polygon_bb, |
---|
| 100 | {'boundary_tags': {'bottom': [0], 'top': [2], |
---|
| 101 | 'right': [1], 'left': [3]}, |
---|
[2188] | 102 | 'resolution': 50000, |
---|
| 103 | 'filename': meshname}, |
---|
| 104 | # 'interior_regions': interior_regions}, |
---|
| 105 | evaluate=True, |
---|
[2186] | 106 | verbose = True) |
---|
| 107 | |
---|
[2181] | 108 | #Setup domain |
---|
| 109 | |
---|
| 110 | domain = cache(pmesh_to_domain_instance, (meshname, Domain), |
---|
| 111 | dependencies = [meshname], |
---|
| 112 | verbose = True) |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | domain.set_name(project.basename) |
---|
| 116 | domain.set_datadir(project.outputdir) |
---|
| 117 | domain.store = True |
---|
| 118 | |
---|
| 119 | #domain.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum'] |
---|
| 120 | domain.quantities_to_be_stored = ['stage'] |
---|
| 121 | |
---|
| 122 | print 'Number of triangles = ', len(domain) |
---|
| 123 | print 'The extent is ', domain.get_extent() |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | #Setup Initial Conditions |
---|
| 128 | domain.set_quantity('friction', 0) |
---|
| 129 | domain.set_quantity('stage', tide) |
---|
| 130 | domain.set_quantity('elevation', |
---|
| 131 | filename = demname + '.pts', |
---|
| 132 | use_cache = True, |
---|
| 133 | verbose = True) |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | #Setup Boundary Conditions |
---|
| 138 | print domain.get_boundary_tags() |
---|
| 139 | |
---|
| 140 | Br = Reflective_boundary(domain) |
---|
| 141 | Bt = Transmissive_boundary(domain) |
---|
| 142 | Bd = Dirichlet_boundary([0,0,0]) |
---|
[2188] | 143 | # 10 min square wave starting at 1 min, 6m high |
---|
[2181] | 144 | Bw = Time_boundary(domain=domain, |
---|
[2188] | 145 | f=lambda t: [(60<t<660)*6, 0, 0]) |
---|
[2181] | 146 | |
---|
| 147 | |
---|
[2186] | 148 | domain.set_boundary( {'top': Br, 'bottom': Br, 'right': Bw, 'left': Br} ) |
---|
[2181] | 149 | |
---|
| 150 | |
---|
| 151 | #Evolve |
---|
| 152 | import time |
---|
| 153 | t0 = time.time() |
---|
| 154 | |
---|
[2188] | 155 | for t in domain.evolve(yieldstep = 1, finaltime = 3600): |
---|
[2181] | 156 | domain.write_time() |
---|
| 157 | domain.write_boundary_statistics(tags = 'right') #quantities = 'stage') |
---|
| 158 | |
---|
| 159 | print 'That took %.2f seconds' %(time.time()-t0) |
---|