[5786] | 1 | """Script for running a tsunami inundation scenario for busselton, WA, Australia. |
---|
[5000] | 2 | |
---|
| 3 | The scenario is defined by a triangular mesh created from project.polygon, |
---|
[5786] | 4 | the elevation data is compiled into a pts file through build_busselton.py |
---|
| 5 | and a simulated tsunami is generated through an sts file from build_boundary.py. |
---|
[5000] | 6 | |
---|
[5786] | 7 | Input: sts file (build_boundary.py for respective event) |
---|
| 8 | pts file (build_busselton.py) |
---|
| 9 | information from project file |
---|
| 10 | Outputs: sww file stored in project.output_run_time_dir |
---|
| 11 | The export_results_all.py and get_timeseries.py is reliant |
---|
| 12 | on the outputs of this script |
---|
| 13 | |
---|
| 14 | Ole Nielsen and Duncan Gray, GA - 2005, Jane Sexton, Nick Bartzis, GA - 2006 |
---|
| 15 | Ole Nielsen, Jane Sexton and Kristy Van Putten - 2008 |
---|
[5000] | 16 | """ |
---|
| 17 | |
---|
| 18 | #------------------------------------------------------------------------------ |
---|
| 19 | # Import necessary modules |
---|
| 20 | #------------------------------------------------------------------------------ |
---|
| 21 | |
---|
| 22 | # Standard modules |
---|
| 23 | from os import sep |
---|
[5786] | 24 | import os |
---|
[5000] | 25 | from os.path import dirname, basename |
---|
| 26 | from os import mkdir, access, F_OK |
---|
| 27 | from shutil import copy |
---|
| 28 | import time |
---|
| 29 | import sys |
---|
| 30 | |
---|
| 31 | # Related major packages |
---|
| 32 | from anuga.shallow_water import Domain |
---|
[6562] | 33 | from anuga.shallow_water.shallow_water_domain import Transmissive_stage_zero_momentum_boundary |
---|
[5000] | 34 | from anuga.shallow_water import Dirichlet_boundary |
---|
| 35 | from anuga.shallow_water import File_boundary |
---|
| 36 | from anuga.shallow_water import Reflective_boundary |
---|
| 37 | from anuga.shallow_water import Field_boundary |
---|
| 38 | from Numeric import allclose |
---|
[5578] | 39 | from anuga.shallow_water.data_manager import export_grid, create_sts_boundary |
---|
[5000] | 40 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
| 41 | from anuga.shallow_water.data_manager import start_screen_catcher, copy_code_files,store_parameters |
---|
| 42 | from anuga_parallel.parallel_abstraction import get_processor_name |
---|
| 43 | from anuga.caching import myhash |
---|
| 44 | from anuga.damage_modelling.inundation_damage import add_depth_and_momentum2csv, inundation_damage |
---|
| 45 | from anuga.fit_interpolate.benchmark_least_squares import mem_usage |
---|
[5575] | 46 | from anuga.utilities.polygon import read_polygon, plot_polygons, polygon_area, is_inside_polygon |
---|
[5609] | 47 | from anuga.geospatial_data.geospatial_data import find_optimal_smoothing_parameter |
---|
[5786] | 48 | from polygon import Polygon_function |
---|
| 49 | |
---|
[5000] | 50 | # Application specific imports |
---|
[5786] | 51 | import project # Definition of file names and polygons |
---|
[5480] | 52 | numprocs = 1 |
---|
| 53 | myid = 0 |
---|
| 54 | |
---|
[5000] | 55 | def run_model(**kwargs): |
---|
| 56 | |
---|
| 57 | #------------------------------------------------------------------------------ |
---|
| 58 | # Copy scripts to time stamped output directory and capture screen |
---|
| 59 | # output to file |
---|
| 60 | #------------------------------------------------------------------------------ |
---|
| 61 | print "Processor Name:",get_processor_name() |
---|
| 62 | |
---|
| 63 | #copy script must be before screen_catcher |
---|
| 64 | |
---|
| 65 | print 'output_dir',kwargs['output_dir'] |
---|
[5786] | 66 | |
---|
| 67 | copy_code_files(kwargs['output_dir'],__file__, |
---|
| 68 | dirname(project.__file__)+sep+ project.__name__+'.py' ) |
---|
[5000] | 69 | |
---|
[5786] | 70 | store_parameters(**kwargs) |
---|
[5000] | 71 | |
---|
| 72 | start_screen_catcher(kwargs['output_dir'], myid, numprocs) |
---|
| 73 | |
---|
| 74 | print "Processor Name:",get_processor_name() |
---|
[5786] | 75 | |
---|
[5575] | 76 | #----------------------------------------------------------------------- |
---|
| 77 | # Domain definitions |
---|
| 78 | #----------------------------------------------------------------------- |
---|
[5000] | 79 | |
---|
[5575] | 80 | # Read in boundary from ordered sts file |
---|
[5786] | 81 | urs_bounding_polygon=create_sts_boundary(os.path.join(project.boundaries_dir_event,project.scenario_name)) |
---|
[5000] | 82 | |
---|
[5575] | 83 | # Reading the landward defined points, this incorporates the original clipping |
---|
| 84 | # polygon minus the 100m contour |
---|
[5786] | 85 | landward_bounding_polygon = read_polygon(project.landward_dir) |
---|
[5575] | 86 | |
---|
| 87 | # Combine sts polyline with landward points |
---|
| 88 | bounding_polygon = urs_bounding_polygon + landward_bounding_polygon |
---|
| 89 | |
---|
| 90 | # counting segments |
---|
| 91 | N = len(urs_bounding_polygon)-1 |
---|
| 92 | |
---|
[5786] | 93 | # boundary tags refer to project.landward 4 points equals 5 segments start at N |
---|
[6562] | 94 | boundary_tags={'back': [N+1,N+2,N+3,N+4, N+5, N+6, N+7], 'side': [N,N+8], 'ocean': range(N)} |
---|
[5786] | 95 | |
---|
[5000] | 96 | #-------------------------------------------------------------------------- |
---|
[5786] | 97 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
[5000] | 98 | # boundary and interior regions defined in project.py along with |
---|
| 99 | # resolutions (maximal area of per triangle) for each polygon |
---|
| 100 | #-------------------------------------------------------------------------- |
---|
| 101 | |
---|
[5786] | 102 | # IMPORTANT don't cache create_mesh_from_region and Domain(mesh....) as it |
---|
[5000] | 103 | # causes problems with the ability to cache set quantity which takes alot of times |
---|
[5381] | 104 | |
---|
[5786] | 105 | print 'start create mesh from regions' |
---|
[5000] | 106 | |
---|
[5786] | 107 | create_mesh_from_regions(bounding_polygon, |
---|
| 108 | boundary_tags=boundary_tags, |
---|
| 109 | maximum_triangle_area=project.res_poly_all, |
---|
| 110 | interior_regions=project.interior_regions, |
---|
| 111 | filename=project.meshes_dir_name, |
---|
[6562] | 112 | use_cache=False, |
---|
| 113 | verbose=False) |
---|
[5786] | 114 | |
---|
[5000] | 115 | #------------------------------------------------------------------------- |
---|
| 116 | # Setup computational domain |
---|
| 117 | #------------------------------------------------------------------------- |
---|
| 118 | print 'Setup computational domain' |
---|
| 119 | |
---|
[5786] | 120 | domain = Domain(project.meshes_dir_name, use_cache=False, verbose=True) |
---|
[5000] | 121 | print 'memory usage before del domain',mem_usage() |
---|
| 122 | |
---|
| 123 | print domain.statistics() |
---|
| 124 | print 'triangles',len(domain) |
---|
| 125 | |
---|
| 126 | kwargs['act_num_trigs']=len(domain) |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | #------------------------------------------------------------------------- |
---|
| 130 | # Setup initial conditions |
---|
| 131 | #------------------------------------------------------------------------- |
---|
[5786] | 132 | print 'Setup initial conditions' |
---|
[5000] | 133 | |
---|
[5786] | 134 | # sets the initial stage in the offcoast region only |
---|
[6062] | 135 | IC = Polygon_function( [(project.poly_mainland, 0),(project.poly_marina, 0)], default = kwargs['tide'], |
---|
[5786] | 136 | geo_reference = domain.geo_reference) |
---|
| 137 | domain.set_quantity('stage', IC) |
---|
| 138 | #domain.set_quantity('stage',kwargs['tide'] ) |
---|
| 139 | domain.set_quantity('friction', kwargs['friction']) |
---|
| 140 | |
---|
| 141 | print 'Start Set quantity',kwargs['elevation_file'] |
---|
[5000] | 142 | |
---|
[5786] | 143 | domain.set_quantity('elevation', |
---|
| 144 | filename = kwargs['elevation_file'], |
---|
| 145 | use_cache = False, |
---|
| 146 | verbose = True, |
---|
| 147 | alpha = kwargs['alpha']) |
---|
| 148 | print 'Finished Set quantity' |
---|
[5000] | 149 | |
---|
[5786] | 150 | ## #------------------------------------------------------ |
---|
| 151 | ## # Distribute domain to implement parallelism !!! |
---|
| 152 | ## #------------------------------------------------------ |
---|
| 153 | ## |
---|
| 154 | ## if numprocs > 1: |
---|
| 155 | ## domain=distribute(domain) |
---|
[5000] | 156 | |
---|
| 157 | #------------------------------------------------------ |
---|
| 158 | # Set domain parameters |
---|
| 159 | #------------------------------------------------------ |
---|
| 160 | print 'domain id', id(domain) |
---|
[5786] | 161 | domain.set_name(kwargs['scenario_name']) |
---|
[5000] | 162 | domain.set_datadir(kwargs['output_dir']) |
---|
[5786] | 163 | domain.set_default_order(2) # Apply second order scheme |
---|
| 164 | domain.set_minimum_storable_height(0.01) # Don't store anything less than 1cm |
---|
[5000] | 165 | domain.set_store_vertices_uniquely(False) |
---|
| 166 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
[5121] | 167 | domain.tight_slope_limiters = 1 |
---|
[5000] | 168 | print 'domain id', id(domain) |
---|
| 169 | |
---|
| 170 | #------------------------------------------------------------------------- |
---|
| 171 | # Setup boundary conditions |
---|
| 172 | #------------------------------------------------------------------------- |
---|
| 173 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
| 174 | print 'domain id', id(domain) |
---|
[5575] | 175 | |
---|
[5786] | 176 | boundary_urs_out=project.boundaries_dir_event + sep + project.scenario_name |
---|
[5669] | 177 | |
---|
| 178 | Br = Reflective_boundary(domain) |
---|
[6562] | 179 | Bt = Transmissive_stage_zero_momentum_boundary(domain) |
---|
[5669] | 180 | Bd = Dirichlet_boundary([kwargs['tide'],0,0]) |
---|
[5575] | 181 | |
---|
| 182 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
[5786] | 183 | Bf = Field_boundary(boundary_urs_out+'.sts', # Change from file_boundary |
---|
| 184 | domain, mean_stage= project.tide, |
---|
[5609] | 185 | time_thinning=1, |
---|
[5669] | 186 | default_boundary=Bd, |
---|
[5575] | 187 | use_cache=True, |
---|
[5626] | 188 | verbose = True, |
---|
| 189 | boundary_polygon=bounding_polygon) |
---|
[5786] | 190 | |
---|
| 191 | domain.set_boundary({'back': Br, |
---|
[6562] | 192 | 'side': Bt, |
---|
[5786] | 193 | 'ocean': Bf}) |
---|
[5000] | 194 | |
---|
[5381] | 195 | kwargs['input_start_time']=domain.starttime |
---|
[5000] | 196 | |
---|
| 197 | print'finish set boundary' |
---|
| 198 | |
---|
| 199 | #---------------------------------------------------------------------------- |
---|
| 200 | # Evolve system through time |
---|
| 201 | #-------------------------------------------------------------------- |
---|
| 202 | t0 = time.time() |
---|
| 203 | |
---|
[5415] | 204 | for t in domain.evolve(yieldstep = project.yieldstep, finaltime = kwargs['finaltime'] |
---|
[5786] | 205 | ,skip_initial_step = False): |
---|
[5000] | 206 | domain.write_time() |
---|
[5415] | 207 | domain.write_boundary_statistics(tags = 'ocean') |
---|
[5000] | 208 | |
---|
[5786] | 209 | # these outputs should be checked with the resultant inundation map |
---|
[5000] | 210 | x, y = domain.get_maximum_inundation_location() |
---|
| 211 | q = domain.get_maximum_inundation_elevation() |
---|
| 212 | print 'Maximum runup observed at (%.2f, %.2f) with elevation %.2f' %(x,y,q) |
---|
| 213 | |
---|
[5786] | 214 | print 'Simulation took %.2f seconds' %(time.time()-t0) |
---|
[5000] | 215 | |
---|
| 216 | #kwargs 'completed' must be added to write the final parameters to file |
---|
| 217 | kwargs['completed']=str(time.time()-t0) |
---|
[5786] | 218 | |
---|
| 219 | store_parameters(**kwargs) |
---|
| 220 | |
---|
| 221 | print 'memory usage before del domain1',mem_usage() |
---|
[5000] | 222 | |
---|
| 223 | |
---|
[5786] | 224 | #------------------------------------------------------------- |
---|
[5000] | 225 | if __name__ == "__main__": |
---|
| 226 | |
---|
| 227 | kwargs={} |
---|
[6023] | 228 | kwargs['file_name']=project.dir_comment |
---|
[5000] | 229 | kwargs['finaltime']=project.finaltime |
---|
| 230 | kwargs['output_dir']=project.output_run_time_dir |
---|
[5786] | 231 | kwargs['elevation_file']=project.combined_dir_name+'.pts' |
---|
| 232 | kwargs['scenario_name']=project.scenario_name |
---|
[5000] | 233 | kwargs['tide']=project.tide |
---|
| 234 | kwargs['alpha'] = project.alpha |
---|
| 235 | kwargs['friction']=project.friction |
---|
[5786] | 236 | #kwargs['num_cpu']=numprocs |
---|
| 237 | #kwargs['host']=project.host |
---|
| 238 | #kwargs['starttime']=project.starttime |
---|
| 239 | #kwargs['yieldstep']=project.yieldstep |
---|
| 240 | #kwargs['user']=project.user |
---|
| 241 | #kwargs['time_thinning'] = project.time_thinning |
---|
| 242 | |
---|
[5000] | 243 | run_model(**kwargs) |
---|
| 244 | |
---|
[5786] | 245 | |
---|