[5139] | 1 | """Script for running tsunami inundation scenario for Dampier, WA, Australia. |
---|
[5134] | 2 | |
---|
| 3 | Source data such as elevation and boundary data is assumed to be available in |
---|
| 4 | directories specified by project.py |
---|
[5139] | 5 | The output sww file is stored in project.output_run_time_dir |
---|
[5134] | 6 | |
---|
| 7 | The scenario is defined by a triangular mesh created from project.polygon, |
---|
[5139] | 8 | the elevation data and a simulated tsunami generated with URS code. |
---|
[5134] | 9 | |
---|
[5139] | 10 | Ole Nielsen and Duncan Gray, GA - 2005 and Jane Sexton, Nick Bartzis, GA - 2006 |
---|
[5134] | 11 | """ |
---|
| 12 | |
---|
| 13 | #------------------------------------------------------------------------------ |
---|
| 14 | # Import necessary modules |
---|
| 15 | #------------------------------------------------------------------------------ |
---|
| 16 | |
---|
| 17 | # Standard modules |
---|
[5139] | 18 | from os import sep |
---|
| 19 | from os.path import dirname, basename |
---|
| 20 | from os import mkdir, access, F_OK |
---|
| 21 | from shutil import copy |
---|
[5134] | 22 | import time |
---|
| 23 | import sys |
---|
| 24 | |
---|
| 25 | # Related major packages |
---|
[5194] | 26 | from anuga.shallow_water import Time_boundary |
---|
[5134] | 27 | from anuga.shallow_water import Domain |
---|
| 28 | from anuga.shallow_water import Dirichlet_boundary |
---|
| 29 | from anuga.shallow_water import File_boundary |
---|
[5139] | 30 | from anuga.shallow_water import Reflective_boundary |
---|
| 31 | from anuga.shallow_water import Field_boundary |
---|
| 32 | from Numeric import allclose |
---|
| 33 | from anuga.shallow_water.data_manager import export_grid |
---|
[5194] | 34 | from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
[5134] | 35 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
[5139] | 36 | from anuga.shallow_water.data_manager import start_screen_catcher, copy_code_files,store_parameters |
---|
| 37 | from anuga_parallel.parallel_api import distribute, numprocs, myid, barrier |
---|
| 38 | from anuga_parallel.parallel_abstraction import get_processor_name |
---|
| 39 | from anuga.caching import myhash |
---|
| 40 | from anuga.damage_modelling.inundation_damage import add_depth_and_momentum2csv, inundation_damage |
---|
| 41 | from anuga.fit_interpolate.benchmark_least_squares import mem_usage |
---|
[5134] | 42 | |
---|
| 43 | # Application specific imports |
---|
| 44 | import project # Definition of file names and polygons |
---|
| 45 | |
---|
[5139] | 46 | def run_model(**kwargs): |
---|
| 47 | |
---|
[5134] | 48 | |
---|
[5139] | 49 | #------------------------------------------------------------------------------ |
---|
| 50 | # Copy scripts to time stamped output directory and capture screen |
---|
| 51 | # output to file |
---|
| 52 | #------------------------------------------------------------------------------ |
---|
| 53 | print "Processor Name:",get_processor_name() |
---|
[5134] | 54 | |
---|
[5139] | 55 | #copy script must be before screen_catcher |
---|
| 56 | #print kwargs |
---|
[5134] | 57 | |
---|
[5139] | 58 | print 'output_dir',kwargs['output_dir'] |
---|
| 59 | if myid == 0: |
---|
| 60 | copy_code_files(kwargs['output_dir'],__file__, |
---|
| 61 | dirname(project.__file__)+sep+ project.__name__+'.py' ) |
---|
[5134] | 62 | |
---|
[5139] | 63 | store_parameters(**kwargs) |
---|
[5134] | 64 | |
---|
[5139] | 65 | barrier() |
---|
[5134] | 66 | |
---|
[5139] | 67 | start_screen_catcher(kwargs['output_dir'], myid, numprocs) |
---|
[5134] | 68 | |
---|
[5139] | 69 | print "Processor Name:",get_processor_name() |
---|
[5134] | 70 | |
---|
[5139] | 71 | # filenames |
---|
| 72 | # meshes_dir_name = project.meshes_dir_name+'.msh' |
---|
[5134] | 73 | |
---|
[5139] | 74 | # creates copy of code in output dir |
---|
| 75 | print 'min triangles', project.trigs_min, |
---|
| 76 | print 'Note: This is generally about 20% less than the final amount' |
---|
[5134] | 77 | |
---|
[5139] | 78 | #-------------------------------------------------------------------------- |
---|
| 79 | # Create the triangular mesh based on overall clipping polygon with a |
---|
| 80 | # tagged |
---|
| 81 | # boundary and interior regions defined in project.py along with |
---|
| 82 | # resolutions (maximal area of per triangle) for each polygon |
---|
| 83 | #-------------------------------------------------------------------------- |
---|
| 84 | |
---|
| 85 | if myid == 0: |
---|
| 86 | |
---|
| 87 | print 'start create mesh from regions' |
---|
[5134] | 88 | |
---|
[5139] | 89 | create_mesh_from_regions(project.poly_all, |
---|
| 90 | boundary_tags=project.boundary_tags, |
---|
| 91 | maximum_triangle_area=project.res_poly_all, |
---|
| 92 | interior_regions=project.interior_regions, |
---|
| 93 | filename=project.meshes_dir_name+'.msh', |
---|
| 94 | use_cache=False, |
---|
| 95 | verbose=True) |
---|
| 96 | barrier() |
---|
[5134] | 97 | |
---|
[5194] | 98 | scenario='fixed_wave' |
---|
| 99 | |
---|
[5139] | 100 | #------------------------------------------------------------------------- |
---|
| 101 | # Setup computational domain |
---|
| 102 | #------------------------------------------------------------------------- |
---|
| 103 | print 'Setup computational domain' |
---|
[5134] | 104 | |
---|
[5139] | 105 | #domain = cache(Domain, (meshes_dir_name), {'use_cache':True, 'verbose':True}, verbose=True) |
---|
| 106 | #above don't work |
---|
| 107 | domain = Domain(project.meshes_dir_name+'.msh', use_cache=False, verbose=True) |
---|
| 108 | print 'memory usage before del domain',mem_usage() |
---|
| 109 | |
---|
| 110 | print domain.statistics() |
---|
| 111 | print 'triangles',len(domain) |
---|
| 112 | |
---|
| 113 | kwargs['act_num_trigs']=len(domain) |
---|
| 114 | |
---|
| 115 | #------------------------------------------------------------------------- |
---|
| 116 | # Setup initial conditions |
---|
| 117 | #------------------------------------------------------------------------- |
---|
| 118 | if myid == 0: |
---|
[5134] | 119 | |
---|
[5139] | 120 | print 'Setup initial conditions' |
---|
[5134] | 121 | |
---|
[5139] | 122 | from polygon import Polygon_function |
---|
| 123 | #following sets the stage/water to be offcoast only |
---|
| 124 | # IC = Polygon_function( [(project.poly_mainland, -1.0)], default = kwargs['tide'], |
---|
| 125 | # geo_reference = domain.geo_reference) |
---|
| 126 | # domain.set_quantity('stage', IC) |
---|
| 127 | domain.set_quantity('stage',kwargs['tide'] ) |
---|
| 128 | # domain.set_quantity('stage', kwargs['tide']) |
---|
| 129 | domain.set_quantity('friction', kwargs['friction']) |
---|
| 130 | |
---|
| 131 | print 'Start Set quantity',kwargs['bathy_file'] |
---|
[5134] | 132 | |
---|
[5139] | 133 | domain.set_quantity('elevation', |
---|
| 134 | filename = kwargs['bathy_file'], |
---|
[5194] | 135 | use_cache = False, |
---|
[5139] | 136 | verbose = True, |
---|
| 137 | alpha = kwargs['alpha']) |
---|
| 138 | print 'Finished Set quantity' |
---|
| 139 | barrier() |
---|
| 140 | |
---|
| 141 | #------------------------------------------------------ |
---|
| 142 | # Distribute domain to implement parallelism !!! |
---|
| 143 | #------------------------------------------------------ |
---|
[5134] | 144 | |
---|
[5139] | 145 | if numprocs > 1: |
---|
| 146 | domain=distribute(domain) |
---|
[5134] | 147 | |
---|
[5139] | 148 | #------------------------------------------------------ |
---|
| 149 | # Set domain parameters |
---|
| 150 | #------------------------------------------------------ |
---|
| 151 | print 'domain id', id(domain) |
---|
| 152 | domain.set_name(kwargs['aa_scenario_name']) |
---|
| 153 | domain.set_datadir(kwargs['output_dir']) |
---|
| 154 | domain.set_default_order(2) # Apply second order scheme |
---|
| 155 | domain.set_minimum_storable_height(0.01) # Don't store anything less than 1cm |
---|
| 156 | domain.set_store_vertices_uniquely(False) |
---|
| 157 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
| 158 | domain.tight_slope_limiters = 1 |
---|
| 159 | #domain.set_maximum_allowed_speed(0.1) # Allow a little runoff (0.1 is OK) |
---|
| 160 | print 'domain id', id(domain) |
---|
[5134] | 161 | |
---|
[5442] | 162 | |
---|
[5139] | 163 | #------------------------------------------------------------------------------ |
---|
| 164 | # Setup information for slide scenario (to be applied 1 min into simulation |
---|
| 165 | #------------------------------------------------------------------------------ |
---|
[5134] | 166 | |
---|
[5139] | 167 | if scenario == 'slide': |
---|
| 168 | # Function for submarine slide |
---|
| 169 | from anuga.shallow_water.smf import slide_tsunami |
---|
| 170 | tsunami_source = slide_tsunami(length=35000.0, |
---|
| 171 | depth=project.slide_depth, |
---|
[5194] | 172 | slope=10.0, |
---|
| 173 | thickness=800.0, |
---|
[5139] | 174 | x0=project.slide_origin[0], |
---|
| 175 | y0=project.slide_origin[1], |
---|
| 176 | alpha=0.0, |
---|
| 177 | domain=domain, |
---|
| 178 | verbose=True) |
---|
| 179 | |
---|
| 180 | #------------------------------------------------------------------------- |
---|
| 181 | # Setup boundary conditions |
---|
| 182 | #------------------------------------------------------------------------- |
---|
| 183 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
| 184 | print 'domain id', id(domain) |
---|
| 185 | #print 'Reading Boundary file',project.boundaries_dir_namea + '.sww' |
---|
[5134] | 186 | |
---|
[5139] | 187 | Br = Reflective_boundary(domain) |
---|
| 188 | Bd = Dirichlet_boundary([kwargs['tide'],0,0]) |
---|
| 189 | Bo = Dirichlet_boundary([kwargs['tide']+5.0,0,0]) |
---|
[5134] | 190 | |
---|
[5139] | 191 | if scenario == 'fixed_wave': |
---|
| 192 | # FIXME (Ole): Change this to Transmissive Momentum as |
---|
| 193 | # suggested by Rajaraman (ticket:208) |
---|
[5194] | 194 | from math import sin, pi |
---|
[5139] | 195 | Bw = Time_boundary(domain = domain, |
---|
[5194] | 196 | f=lambda t: [5.0*sin(t*pi*1/15), 0, 0]) |
---|
| 197 | domain.set_boundary({'ocean_east':Bw, |
---|
| 198 | 'ocean_north':Bd, |
---|
| 199 | 'ocean_west':Bd, |
---|
| 200 | 'land':Bd, |
---|
| 201 | 'ocean_southeast':Bd}) |
---|
[5134] | 202 | |
---|
[5139] | 203 | # boundary conditions for slide scenario |
---|
| 204 | if scenario == 'slide': |
---|
[5194] | 205 | domain.set_boundary({'ocean_east':Bd, |
---|
| 206 | 'ocean_north':Bd, |
---|
| 207 | 'ocean_west':Bd, |
---|
| 208 | 'land':Bd, |
---|
| 209 | 'ocean_southeast':Bd}) |
---|
[5134] | 210 | |
---|
[5139] | 211 | #---------------------------------------------------------------------------- |
---|
| 212 | # Evolve system through time |
---|
| 213 | #-------------------------------------------------------------------- |
---|
| 214 | t0 = time.time() |
---|
[5134] | 215 | |
---|
[5194] | 216 | for t in domain.evolve(yieldstep = 1, finaltime = kwargs['finaltime']): |
---|
[5139] | 217 | domain.write_time() |
---|
| 218 | domain.write_boundary_statistics(tags = 'ocean_east') |
---|
[5134] | 219 | |
---|
[5139] | 220 | x, y = domain.get_maximum_inundation_location() |
---|
| 221 | q = domain.get_maximum_inundation_elevation() |
---|
[5134] | 222 | |
---|
[5139] | 223 | print 'Maximum runup observed at (%.2f, %.2f) with elevation %.2f' %(x,y,q) |
---|
[5134] | 224 | |
---|
[5139] | 225 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
[5134] | 226 | |
---|
[5139] | 227 | #kwargs 'completed' must be added to write the final parameters to file |
---|
| 228 | kwargs['completed']=str(time.time()-t0) |
---|
[5134] | 229 | |
---|
[5139] | 230 | if myid==0: |
---|
| 231 | store_parameters(**kwargs) |
---|
| 232 | barrier |
---|
| 233 | |
---|
| 234 | print 'memory usage before del domain1',mem_usage() |
---|
[5134] | 235 | |
---|
[5139] | 236 | def export_model(**kwargs): |
---|
| 237 | #store_parameters(**kwargs) |
---|
[5134] | 238 | |
---|
[5139] | 239 | # print 'memory usage before del domain',mem_usage() |
---|
| 240 | #del domain |
---|
| 241 | print 'memory usage after del domain',mem_usage() |
---|
| 242 | |
---|
[5194] | 243 | swwfile = kwargs['output_dir']+kwargs['aa_scenario_name'] |
---|
[5139] | 244 | print'swwfile',swwfile |
---|
| 245 | |
---|
[5194] | 246 | export_grid(swwfile, extra_name_out = 'tonga', |
---|
[5139] | 247 | quantities = ['speed','depth','elevation','stage'], # '(xmomentum**2 + ymomentum**2)**0.5' defaults to elevation |
---|
| 248 | #quantities = ['speed','depth'], # '(xmomentum**2 + ymomentum**2)**0.5' defaults to elevation |
---|
| 249 | timestep = None, |
---|
| 250 | reduction = max, |
---|
[5194] | 251 | cellsize = 25, |
---|
[5139] | 252 | NODATA_value = -1E-030, |
---|
| 253 | easting_min = project.eastingmin, |
---|
| 254 | easting_max = project.eastingmax, |
---|
| 255 | northing_min = project.northingmin, |
---|
| 256 | northing_max = project.northingmax, |
---|
| 257 | verbose = False, |
---|
| 258 | origin = None, |
---|
| 259 | datum = 'WGS84', |
---|
| 260 | format = 'txt') |
---|
| 261 | |
---|
| 262 | #------------------------------------------------------------- |
---|
| 263 | if __name__ == "__main__": |
---|
| 264 | |
---|
| 265 | kwargs={} |
---|
| 266 | kwargs['est_num_trigs']=project.trigs_min |
---|
| 267 | kwargs['num_cpu']=numprocs |
---|
| 268 | kwargs['host']=project.host |
---|
| 269 | kwargs['res_factor']=project.res_factor |
---|
| 270 | kwargs['starttime']=project.starttime |
---|
| 271 | kwargs['yieldstep']=project.yieldstep |
---|
| 272 | kwargs['midtime']=project.midtime |
---|
| 273 | kwargs['finaltime']=project.finaltime |
---|
| 274 | kwargs['output_dir']=project.output_run_time_dir |
---|
| 275 | kwargs['bathy_file']=project.combined_dir_name+'.txt' |
---|
| 276 | # kwargs['bathy_file']=project.combined_small_dir_name + '.pts' |
---|
| 277 | kwargs['boundary_file']=project.boundaries_in_dir_name + '.sww' |
---|
| 278 | kwargs['file_name']=project.home+'detail.csv' |
---|
| 279 | kwargs['aa_scenario_name']=project.scenario_name |
---|
| 280 | kwargs['ab_time']=project.time |
---|
| 281 | kwargs['res_factor']= project.res_factor |
---|
| 282 | kwargs['tide']=project.tide |
---|
| 283 | kwargs['user']=project.user |
---|
| 284 | kwargs['alpha'] = project.alpha |
---|
| 285 | kwargs['friction']=project.friction |
---|
| 286 | kwargs['time_thinning'] = project.time_thinning |
---|
| 287 | kwargs['dir_comment']=project.dir_comment |
---|
| 288 | kwargs['export_cellsize']=project.export_cellsize |
---|
| 289 | |
---|
[5134] | 290 | |
---|
[5139] | 291 | run_model(**kwargs) |
---|
| 292 | |
---|
| 293 | if myid==0: |
---|
| 294 | export_model(**kwargs) |
---|
| 295 | barrier |
---|