[3800] | 1 | """Script for running tsunami inundation scenario for Dampier, WA, Australia. |
---|
[3627] | 2 | |
---|
| 3 | Source data such as elevation and boundary data is assumed to be available in |
---|
| 4 | directories specified by project.py |
---|
[3851] | 5 | The output sww file is stored in project.output_run_time_dir |
---|
[3627] | 6 | |
---|
| 7 | The scenario is defined by a triangular mesh created from project.polygon, |
---|
[4147] | 8 | the elevation data and a simulated tsunami generated with URS code. |
---|
[3627] | 9 | |
---|
[3631] | 10 | Ole Nielsen and Duncan Gray, GA - 2005 and Jane Sexton, Nick Bartzis, GA - 2006 |
---|
[3627] | 11 | """ |
---|
[3713] | 12 | |
---|
[3627] | 13 | #------------------------------------------------------------------------------ |
---|
| 14 | # Import necessary modules |
---|
| 15 | #------------------------------------------------------------------------------ |
---|
| 16 | |
---|
| 17 | # Standard modules |
---|
| 18 | from os import sep |
---|
| 19 | from os.path import dirname, basename |
---|
[3631] | 20 | from os import mkdir, access, F_OK |
---|
| 21 | from shutil import copy |
---|
[3627] | 22 | import time |
---|
[3631] | 23 | import sys |
---|
[3627] | 24 | |
---|
| 25 | # Related major packages |
---|
| 26 | from anuga.shallow_water import Domain |
---|
| 27 | from anuga.shallow_water import Dirichlet_boundary |
---|
| 28 | from anuga.shallow_water import File_boundary |
---|
| 29 | from anuga.shallow_water import Reflective_boundary |
---|
[4373] | 30 | from anuga.shallow_water import Field_boundary |
---|
[4049] | 31 | from Numeric import allclose |
---|
[3627] | 32 | |
---|
| 33 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
[3940] | 34 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files |
---|
[3905] | 35 | from anuga_parallel.parallel_api import distribute, numprocs, myid, barrier |
---|
[4246] | 36 | from anuga_parallel.parallel_abstraction import get_processor_name |
---|
[4282] | 37 | from anuga.caching import myhash |
---|
[3627] | 38 | # Application specific imports |
---|
| 39 | import project # Definition of file names and polygons |
---|
| 40 | |
---|
| 41 | #------------------------------------------------------------------------------ |
---|
| 42 | # Copy scripts to time stamped output directory and capture screen |
---|
| 43 | # output to file |
---|
| 44 | #------------------------------------------------------------------------------ |
---|
| 45 | |
---|
[4373] | 46 | #copy script must be before screen_catcher |
---|
| 47 | if myid == 0: |
---|
| 48 | copy_code_files(project.output_run_time_dir,__file__, |
---|
| 49 | dirname(project.__file__)+sep+ project.__name__+'.py' ) |
---|
| 50 | barrier() |
---|
| 51 | |
---|
[4147] | 52 | start_screen_catcher(project.output_run_time_dir, myid, numprocs) |
---|
[4357] | 53 | |
---|
[4246] | 54 | print "Processor Name:",get_processor_name() |
---|
[4357] | 55 | barrier() |
---|
[3940] | 56 | |
---|
[3627] | 57 | # filenames |
---|
[4186] | 58 | #boundaries_name = project.boundaries_name |
---|
[3940] | 59 | meshes_dir_name = project.meshes_dir_name+'.msh' |
---|
[4186] | 60 | #boundaries_dir_name = project.boundaries_dir_name |
---|
[4147] | 61 | |
---|
[3905] | 62 | tide = project.tide |
---|
[3627] | 63 | |
---|
[3940] | 64 | # creates copy of code in output dir |
---|
[3885] | 65 | |
---|
[4373] | 66 | |
---|
[3885] | 67 | print 'USER: ', project.user |
---|
[4147] | 68 | print 'min triangles', project.trigs_min, |
---|
| 69 | print 'Note: This is generally about 20% less than the final amount' |
---|
| 70 | |
---|
[3885] | 71 | #-------------------------------------------------------------------------- |
---|
| 72 | # Create the triangular mesh based on overall clipping polygon with a |
---|
| 73 | # tagged |
---|
| 74 | # boundary and interior regions defined in project.py along with |
---|
| 75 | # resolutions (maximal area of per triangle) for each polygon |
---|
| 76 | #-------------------------------------------------------------------------- |
---|
[4193] | 77 | |
---|
[3905] | 78 | if myid == 0: |
---|
[3997] | 79 | |
---|
| 80 | print 'start create mesh from regions' |
---|
[4401] | 81 | |
---|
[4147] | 82 | create_mesh_from_regions(project.poly_all, |
---|
[4186] | 83 | boundary_tags={'back': [2,3], 'side': [0, 1, 4], |
---|
| 84 | 'ocean': [5]}, |
---|
[4147] | 85 | maximum_triangle_area=project.res_poly_all, |
---|
[4357] | 86 | interior_regions=project.interior_regions, |
---|
[4147] | 87 | filename=meshes_dir_name, |
---|
[4401] | 88 | use_cache=False, |
---|
[4147] | 89 | verbose=True) |
---|
[3885] | 90 | |
---|
[3905] | 91 | # to sync all processors are ready |
---|
| 92 | barrier() |
---|
[4401] | 93 | |
---|
[3713] | 94 | #------------------------------------------------------------------------- |
---|
| 95 | # Setup computational domain |
---|
| 96 | #------------------------------------------------------------------------- |
---|
[3851] | 97 | print 'Setup computational domain' |
---|
[4357] | 98 | #from caching import cache |
---|
| 99 | |
---|
| 100 | #domain = cache(Domain, (meshes_dir_name), {'use_cache':True, 'verbose':True}, verbose=True) |
---|
| 101 | #above don't work |
---|
[4422] | 102 | domain = Domain(meshes_dir_name, use_cache=False, verbose=True) |
---|
[4282] | 103 | print 'domain id', id(domain) |
---|
| 104 | print 'myhash', myhash(domain) |
---|
| 105 | |
---|
[3713] | 106 | print domain.statistics() |
---|
[4282] | 107 | |
---|
[4422] | 108 | #boundaries_dir_name=project.boundaries_dir_name |
---|
[3627] | 109 | |
---|
[4422] | 110 | #print 'starting to create boundary conditions' |
---|
[3905] | 111 | |
---|
[4422] | 112 | #from anuga.shallow_water.data_manager import urs2sww |
---|
[3905] | 113 | |
---|
[4401] | 114 | |
---|
[3713] | 115 | #------------------------------------------------------------------------- |
---|
| 116 | # Setup initial conditions |
---|
| 117 | #------------------------------------------------------------------------- |
---|
[4049] | 118 | if myid == 0: |
---|
[3905] | 119 | |
---|
[4049] | 120 | print 'Setup initial conditions' |
---|
[3905] | 121 | |
---|
[4172] | 122 | from polygon import * |
---|
[4193] | 123 | #following sets the stage/water to be offcoast only |
---|
[4430] | 124 | IC = Polygon_function( [(project.poly_mainland, 0.)], default = tide) |
---|
| 125 | # IC = Polygon_function( [(project.poly_mainland, 0.)], default = 200) |
---|
[4164] | 126 | domain.set_quantity('stage', IC) |
---|
[4147] | 127 | domain.set_quantity('friction', 0.01) |
---|
[4049] | 128 | print 'Start Set quantity' |
---|
| 129 | |
---|
| 130 | domain.set_quantity('elevation', |
---|
[4212] | 131 | # filename = project.combined_dir_name + '.pts', |
---|
| 132 | # MUST USE TXT FILES FOR CACHING TO WORK! |
---|
[4357] | 133 | filename = project.combined_dir_name + '.txt', |
---|
[4401] | 134 | # filename = project.combined_smallest_dir_name + '.txt', |
---|
[4282] | 135 | use_cache = True, |
---|
[3713] | 136 | verbose = True, |
---|
| 137 | alpha = 0.1) |
---|
[4049] | 138 | print 'Finished Set quantity' |
---|
| 139 | barrier() |
---|
[3627] | 140 | |
---|
[3905] | 141 | |
---|
[3877] | 142 | #------------------------------------------------------ |
---|
| 143 | # Distribute domain to implement parallelism !!! |
---|
| 144 | #------------------------------------------------------ |
---|
| 145 | |
---|
| 146 | if numprocs > 1: |
---|
| 147 | domain=distribute(domain) |
---|
| 148 | |
---|
| 149 | #------------------------------------------------------ |
---|
| 150 | # Set domain parameters |
---|
| 151 | #------------------------------------------------------ |
---|
[4282] | 152 | print 'domain id', id(domain) |
---|
[3877] | 153 | domain.set_name(project.scenario_name) |
---|
| 154 | domain.set_datadir(project.output_run_time_dir) |
---|
[3940] | 155 | domain.set_default_order(2) # Apply second order scheme |
---|
[3877] | 156 | domain.set_minimum_storable_height(0.01) # Don't store anything less than 1cm |
---|
[3940] | 157 | domain.set_store_vertices_uniquely(False) |
---|
| 158 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
[4147] | 159 | domain.set_maximum_allowed_speed(0.1) # Allow a little runoff (0.1 is OK) |
---|
[4282] | 160 | print 'domain id', id(domain) |
---|
[4422] | 161 | domain.beta_h = 0 |
---|
[4631] | 162 | #domain.tight_slope_limiters = 1 |
---|
[3877] | 163 | |
---|
[3713] | 164 | #------------------------------------------------------------------------- |
---|
| 165 | # Setup boundary conditions |
---|
| 166 | #------------------------------------------------------------------------- |
---|
[3905] | 167 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
[4147] | 168 | print 'domain id', id(domain) |
---|
[4401] | 169 | #print 'Reading Boundary file',project.boundaries_dir_namea + '.sww' |
---|
| 170 | |
---|
[4357] | 171 | Bf = Field_boundary(project.boundaries_dir_namea + '.sww', |
---|
[4430] | 172 | domain, time_thinning=12, mean_stage=tide, |
---|
[4401] | 173 | use_cache=True, verbose=True) |
---|
[3828] | 174 | |
---|
[3905] | 175 | print 'finished reading boundary file' |
---|
[3808] | 176 | |
---|
[3713] | 177 | Br = Reflective_boundary(domain) |
---|
| 178 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
[3905] | 179 | |
---|
| 180 | print'set_boundary' |
---|
[4186] | 181 | ##domain.set_boundary({'back': Br, |
---|
| 182 | ## 'side': Bf, |
---|
| 183 | ## 'ocean': Bf}) |
---|
[3713] | 184 | domain.set_boundary({'back': Br, |
---|
| 185 | 'side': Bd, |
---|
[4193] | 186 | 'ocean': Bf}) |
---|
[3905] | 187 | print'finish set boundary' |
---|
[3627] | 188 | |
---|
| 189 | #---------------------------------------------------------------------------- |
---|
| 190 | # Evolve system through time |
---|
| 191 | #---------------------------------------------------------------------------- |
---|
[3905] | 192 | |
---|
[3627] | 193 | t0 = time.time() |
---|
| 194 | |
---|
[4401] | 195 | for t in domain.evolve(yieldstep = 60, finaltime = 29950): |
---|
[4147] | 196 | domain.write_time() |
---|
[4401] | 197 | # domain.write_time(track_speeds=True) |
---|
[4147] | 198 | domain.write_boundary_statistics(tags = 'ocean') |
---|
[4373] | 199 | |
---|
[4401] | 200 | # domain.write_time(track_speeds=True) |
---|
[4147] | 201 | |
---|
| 202 | #for t in domain.evolve(yieldstep = 120, finaltime = 9000): |
---|
[3940] | 203 | # domain.write_time() |
---|
| 204 | # domain.write_boundary_statistics(tags = 'ocean') |
---|
[4308] | 205 | ''' |
---|
[4212] | 206 | for t in domain.evolve(yieldstep = 60, finaltime = 28800 |
---|
| 207 | ,skip_initial_step = True): |
---|
| 208 | domain.write_time() |
---|
| 209 | domain.write_boundary_statistics(tags = 'ocean') |
---|
[3940] | 210 | |
---|
[4212] | 211 | for t in domain.evolve(yieldstep = 120, finaltime = 34800 |
---|
| 212 | ,skip_initial_step = True): |
---|
| 213 | domain.write_time() |
---|
| 214 | domain.write_boundary_statistics(tags = 'ocean') |
---|
[4308] | 215 | ''' |
---|
[4172] | 216 | x, y = domain.get_maximum_inundation_location() |
---|
| 217 | q = domain.get_maximum_inundation_elevation() |
---|
| 218 | |
---|
| 219 | print 'Maximum runup observed at (%.2f, %.2f) with elevation %.2f' %(x,y,q) |
---|
| 220 | |
---|
[3627] | 221 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 222 | |
---|