[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 |
---|
[4049] | 30 | from Numeric import allclose |
---|
[3627] | 31 | |
---|
| 32 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
[3940] | 33 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files |
---|
[3905] | 34 | from anuga_parallel.parallel_api import distribute, numprocs, myid, barrier |
---|
[3627] | 35 | |
---|
| 36 | # Application specific imports |
---|
| 37 | import project # Definition of file names and polygons |
---|
| 38 | |
---|
| 39 | #------------------------------------------------------------------------------ |
---|
| 40 | # Copy scripts to time stamped output directory and capture screen |
---|
| 41 | # output to file |
---|
| 42 | #------------------------------------------------------------------------------ |
---|
| 43 | |
---|
[4147] | 44 | start_screen_catcher(project.output_run_time_dir, myid, numprocs) |
---|
[3940] | 45 | |
---|
[3627] | 46 | # filenames |
---|
[3940] | 47 | build_time = '20061107_063840_build' |
---|
| 48 | bound_time = '20061102_221245_build' |
---|
[3905] | 49 | |
---|
[3851] | 50 | boundaries_name = project.boundaries_name |
---|
[3940] | 51 | meshes_dir_name = project.meshes_dir_name+'.msh' |
---|
| 52 | boundaries_dir_name = project.boundaries_dir_name |
---|
[4147] | 53 | |
---|
[3905] | 54 | tide = project.tide |
---|
[3627] | 55 | |
---|
[3940] | 56 | # creates copy of code in output dir |
---|
[3885] | 57 | if myid == 0: |
---|
[3940] | 58 | copy_code_files(project.output_run_time_dir,__file__, |
---|
| 59 | dirname(project.__file__)+sep+ project.__name__+'.py' ) |
---|
[3905] | 60 | barrier() |
---|
[3885] | 61 | |
---|
| 62 | print 'USER: ', project.user |
---|
[4147] | 63 | print 'min triangles', project.trigs_min, |
---|
| 64 | print 'Note: This is generally about 20% less than the final amount' |
---|
| 65 | |
---|
[3885] | 66 | #-------------------------------------------------------------------------- |
---|
| 67 | # Create the triangular mesh based on overall clipping polygon with a |
---|
| 68 | # tagged |
---|
| 69 | # boundary and interior regions defined in project.py along with |
---|
| 70 | # resolutions (maximal area of per triangle) for each polygon |
---|
| 71 | #-------------------------------------------------------------------------- |
---|
| 72 | |
---|
[3905] | 73 | if myid == 0: |
---|
[3997] | 74 | |
---|
| 75 | print 'start create mesh from regions' |
---|
[4147] | 76 | create_mesh_from_regions(project.poly_all, |
---|
| 77 | boundary_tags={'back': [7, 8], 'side': [0, 6], |
---|
| 78 | 'ocean': [1, 2, 3, 4, 5]}, |
---|
| 79 | maximum_triangle_area=project.res_poly_all, |
---|
| 80 | interior_regions=project.interior_regions, |
---|
| 81 | filename=meshes_dir_name, |
---|
| 82 | use_cache=True, |
---|
| 83 | verbose=True) |
---|
[3885] | 84 | |
---|
[3905] | 85 | # to sync all processors are ready |
---|
| 86 | barrier() |
---|
| 87 | |
---|
[3713] | 88 | #------------------------------------------------------------------------- |
---|
| 89 | # Setup computational domain |
---|
| 90 | #------------------------------------------------------------------------- |
---|
[3851] | 91 | print 'Setup computational domain' |
---|
[3940] | 92 | domain = Domain(meshes_dir_name, use_cache=True, verbose=True) |
---|
[3713] | 93 | print domain.statistics() |
---|
[3627] | 94 | |
---|
[4147] | 95 | """ |
---|
[3905] | 96 | print 'starting to create boundary conditions' |
---|
| 97 | boundaries_in_dir_name = project.boundaries_in_dir_name |
---|
| 98 | |
---|
[4147] | 99 | from anuga.shallow_water.data_manager import urs2sw |
---|
[3905] | 100 | |
---|
| 101 | # put above distribute |
---|
[3940] | 102 | print 'boundary file is: ',boundaries_dir_name |
---|
[3905] | 103 | from caching import cache |
---|
[3940] | 104 | if myid == 0: |
---|
[4147] | 105 | cache(urs2sww, |
---|
[3940] | 106 | (boundaries_in_dir_name, |
---|
| 107 | # boundaries_time_dir_name), |
---|
| 108 | boundaries_dir_name), |
---|
| 109 | {'verbose': True, |
---|
| 110 | 'minlat': project.south_boundary, |
---|
| 111 | 'maxlat': project.north_boundary, |
---|
| 112 | 'minlon': project.west_boundary, |
---|
| 113 | 'maxlon': project.east_boundary, |
---|
| 114 | # 'minlat': project.south, |
---|
| 115 | # 'maxlat': project.north, |
---|
| 116 | # 'minlon': project.west, |
---|
| 117 | # 'maxlon': project.east, |
---|
[4049] | 118 | 'mint': 0, 'maxt': 35100, |
---|
[3940] | 119 | 'origin': domain.geo_reference.get_origin(), |
---|
| 120 | 'mean_stage': project.tide, |
---|
| 121 | # 'zscale': 1, #Enhance tsunami |
---|
| 122 | 'fail_on_NaN': False}, |
---|
| 123 | verbose = True, |
---|
| 124 | ) |
---|
| 125 | barrier() |
---|
[4147] | 126 | """ |
---|
[3905] | 127 | |
---|
[3713] | 128 | #------------------------------------------------------------------------- |
---|
| 129 | # Setup initial conditions |
---|
| 130 | #------------------------------------------------------------------------- |
---|
[4049] | 131 | if myid == 0: |
---|
[3905] | 132 | |
---|
[4049] | 133 | print 'Setup initial conditions' |
---|
[3905] | 134 | |
---|
[4049] | 135 | domain.set_quantity('stage', tide) |
---|
[4147] | 136 | domain.set_quantity('friction', 0.01) |
---|
[4049] | 137 | #combined_time_dir_name = project.topographies_dir+build_time+project.combined_name |
---|
| 138 | print 'Start Set quantity' |
---|
| 139 | |
---|
| 140 | domain.set_quantity('elevation', |
---|
[4147] | 141 | filename = project.combined_dir_name + '.txt', |
---|
[3851] | 142 | use_cache = True, |
---|
[3713] | 143 | verbose = True, |
---|
| 144 | alpha = 0.1) |
---|
[4049] | 145 | print 'Finished Set quantity' |
---|
| 146 | barrier() |
---|
[3627] | 147 | |
---|
[3905] | 148 | |
---|
[3877] | 149 | #------------------------------------------------------ |
---|
| 150 | # Distribute domain to implement parallelism !!! |
---|
| 151 | #------------------------------------------------------ |
---|
| 152 | |
---|
| 153 | if numprocs > 1: |
---|
| 154 | domain=distribute(domain) |
---|
| 155 | |
---|
| 156 | #------------------------------------------------------ |
---|
| 157 | # Set domain parameters |
---|
| 158 | #------------------------------------------------------ |
---|
| 159 | |
---|
| 160 | domain.set_name(project.scenario_name) |
---|
| 161 | domain.set_datadir(project.output_run_time_dir) |
---|
[3940] | 162 | domain.set_default_order(2) # Apply second order scheme |
---|
[3877] | 163 | domain.set_minimum_storable_height(0.01) # Don't store anything less than 1cm |
---|
[3940] | 164 | domain.set_store_vertices_uniquely(False) |
---|
| 165 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
[4147] | 166 | domain.set_maximum_allowed_speed(0.1) # Allow a little runoff (0.1 is OK) |
---|
[3877] | 167 | |
---|
[3713] | 168 | #------------------------------------------------------------------------- |
---|
| 169 | # Setup boundary conditions |
---|
| 170 | #------------------------------------------------------------------------- |
---|
[3905] | 171 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
[4147] | 172 | print 'domain id', id(domain) |
---|
[3905] | 173 | print 'Reading Boundary file' |
---|
[4147] | 174 | #Bf = File_boundary(boundaries_dir_name + '.sww', |
---|
| 175 | # domain, time_thinning=5, use_cache=True, verbose=True) |
---|
[3828] | 176 | |
---|
[3905] | 177 | print 'finished reading boundary file' |
---|
[3808] | 178 | |
---|
[3713] | 179 | Br = Reflective_boundary(domain) |
---|
| 180 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
[3905] | 181 | |
---|
| 182 | print'set_boundary' |
---|
[3713] | 183 | domain.set_boundary({'back': Br, |
---|
| 184 | 'side': Bd, |
---|
| 185 | 'ocean': Bf}) |
---|
[3905] | 186 | print'finish set boundary' |
---|
[3627] | 187 | |
---|
| 188 | #---------------------------------------------------------------------------- |
---|
| 189 | # Evolve system through time |
---|
| 190 | #---------------------------------------------------------------------------- |
---|
[3905] | 191 | |
---|
[3627] | 192 | t0 = time.time() |
---|
| 193 | |
---|
[4147] | 194 | for t in domain.evolve(yieldstep = 60, finaltime = 34000): |
---|
| 195 | domain.write_time() |
---|
| 196 | domain.write_boundary_statistics(tags = 'ocean') |
---|
| 197 | |
---|
| 198 | #for t in domain.evolve(yieldstep = 120, finaltime = 9000): |
---|
[3940] | 199 | # domain.write_time() |
---|
| 200 | # domain.write_boundary_statistics(tags = 'ocean') |
---|
| 201 | |
---|
[4147] | 202 | #for t in domain.evolve(yieldstep = 60, finaltime = 28800 |
---|
| 203 | # ,skip_initial_step = True): |
---|
| 204 | # domain.write_time() |
---|
| 205 | # domain.write_boundary_statistics(tags = 'ocean') |
---|
[3940] | 206 | |
---|
[4147] | 207 | #for t in domain.evolve(yieldstep = 120, finaltime = 34800 |
---|
| 208 | # ,skip_initial_step = True): |
---|
| 209 | # domain.write_time() |
---|
| 210 | # domain.write_boundary_statistics(tags = 'ocean') |
---|
[3627] | 211 | |
---|
| 212 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 213 | |
---|