Changeset 5139 for anuga_work/production/tonga/tongatapu.py
- Timestamp:
- Mar 7, 2008, 4:37:36 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_work/production/tonga/tongatapu.py
r5134 r5139 1 """Script for running a tsunami inundation scenario for Cairns, QLDAustralia.1 """Script for running tsunami inundation scenario for Dampier, WA, Australia. 2 2 3 3 Source data such as elevation and boundary data is assumed to be available in 4 4 directories specified by project.py 5 The output sww file is stored in directory named after the scenario, i.e 6 slide or fixed_wave. 5 The output sww file is stored in project.output_run_time_dir 7 6 8 7 The scenario is defined by a triangular mesh created from project.polygon, 9 the elevation data and a tsunami wave generated by a submarine mass failure. 10 11 Ole Nielsen and Duncan Gray, GA - 2005 and Jane Sexton and 12 Nick Bartzis, GA - 2006 8 the elevation data and a simulated tsunami generated with URS code. 9 10 Ole Nielsen and Duncan Gray, GA - 2005 and Jane Sexton, Nick Bartzis, GA - 2006 13 11 """ 14 12 … … 18 16 19 17 # Standard modules 20 import os 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 21 22 import time 22 23 import sys … … 24 25 # Related major packages 25 26 from anuga.shallow_water import Domain 27 from anuga.shallow_water import Dirichlet_boundary 28 from anuga.shallow_water import File_boundary 26 29 from anuga.shallow_water import Reflective_boundary 27 from anuga.shallow_water import Dirichlet_boundary 28 from anuga.shallow_water import Time_boundary 29 from anuga.shallow_water import File_boundary 30 from anuga.shallow_water import Field_boundary 31 from Numeric import allclose 32 from anuga.shallow_water.data_manager import export_grid 33 30 34 from anuga.pmesh.mesh_interface import create_mesh_from_regions 31 from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf 32 from anuga.shallow_water.data_manager import dem2pts 35 from anuga.shallow_water.data_manager import start_screen_catcher, copy_code_files,store_parameters 36 from anuga_parallel.parallel_api import distribute, numprocs, myid, barrier 37 from anuga_parallel.parallel_abstraction import get_processor_name 38 from anuga.caching import myhash 39 from anuga.damage_modelling.inundation_damage import add_depth_and_momentum2csv, inundation_damage 40 from anuga.fit_interpolate.benchmark_least_squares import mem_usage 33 41 34 42 # Application specific imports 35 43 import project # Definition of file names and polygons 36 44 37 38 #------------------------------------------------------------------------------ 39 # Define scenario as either slide or fixed_wave. 40 #------------------------------------------------------------------------------ 41 scenario = 'slide' 42 #scenario = 'fixed_wave' 43 44 if os.access(scenario, os.F_OK) == 0: 45 os.mkdir(scenario) 46 basename = scenario + 'source' 47 48 49 #------------------------------------------------------------------------------ 50 # Preparation of topographic data 51 # Convert ASC 2 DEM 2 PTS using source data and store result in source data 52 #------------------------------------------------------------------------------ 53 54 # Filenames 55 dem_name = 'tongatapu_10mgrid' 56 meshname = 'tongatapu.msh' 57 58 # Create DEM from asc data 59 convert_dem_from_ascii2netcdf(dem_name, use_cache=True, verbose=True) 60 61 # Create pts file for onshore DEM 62 dem2pts(dem_name, use_cache=True, verbose=True) 63 64 65 #------------------------------------------------------------------------------ 66 # Create the triangular mesh based on overall clipping polygon with a tagged 67 # boundary and interior regions defined in project.py along with 68 # resolutions (maximal area of per triangle) for each polygon 69 #------------------------------------------------------------------------------ 70 71 remainder_res = 1000000 72 islands_res = 5000 73 cairns_res = 5000 74 interior_regions = [[project.poly_tongatapu, tongatapu_res], 75 [project.poly_island1, islands_res], 76 [project.poly_island2, islands_res], 77 [project.poly_island3, islands_res], 78 [project.poly_island4, islands_res], 79 [project.poly_island5, islands_res], 80 [project.poly_island6, islands_res], 81 [project.poly_island7, islands_res], 82 [project.poly_island8, islands_res], 83 [project.poly_island9, islands_res], 84 [project.poly_island10, islands_res], 85 [project.poly_island11, islands_res], 86 [project.poly_island12, islands_res], 87 [project.poly_island13, islands_res]] 88 89 create_mesh_from_regions(project.bounding_polygon, 90 boundary_tags={'top': [0], 91 'ocean_east': [1], 92 'bottom': [2], 93 'onshore': [3]}, 94 maximum_triangle_area=remainder_res, 95 filename=meshname, 96 interior_regions=interior_regions, 97 use_cache=True, 98 verbose=True) 99 100 101 #------------------------------------------------------------------------------ 102 # Setup computational domain 103 #------------------------------------------------------------------------------ 104 105 domain = Domain(meshname, use_cache=True, verbose=True) 106 107 print 'Number of triangles = ', len(domain) 108 print 'The extent is ', domain.get_extent() 109 print domain.statistics() 110 111 domain.set_name(basename) 112 domain.set_datadir(scenario) 113 domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) 114 domain.set_minimum_storable_height(0.01) 115 116 #print 'domain.tight_slope_limiters', domain.tight_slope_limiters 117 domain.tight_slope_limiters = 0 118 print 'domain.tight_slope_limiters', domain.tight_slope_limiters 119 120 121 122 #------------------------------------------------------------------------------ 123 # Setup initial conditions 124 #------------------------------------------------------------------------------ 125 126 tide = 0.0 127 domain.set_quantity('stage', tide) 128 domain.set_quantity('friction', 0.0) 129 domain.set_quantity('elevation', 130 filename=dem_name + '.pts', 131 use_cache=True, 132 verbose=True, 133 alpha=0.1) 134 135 136 137 #------------------------------------------------------------------------------ 138 # Setup information for slide scenario (to be applied 1 min into simulation 139 #------------------------------------------------------------------------------ 140 141 if scenario == 'slide': 142 # Function for submarine slide 143 from anuga.shallow_water.smf import slide_tsunami 144 tsunami_source = slide_tsunami(length=35000.0, 145 depth=project.slide_depth, 146 slope=6.0, 147 thickness=500.0, 148 x0=project.slide_origin[0], 149 y0=project.slide_origin[1], 150 alpha=0.0, 151 domain=domain, 152 verbose=True) 153 154 155 #------------------------------------------------------------------------------ 156 # Setup boundary conditions 157 #------------------------------------------------------------------------------ 158 159 print 'Available boundary tags', domain.get_boundary_tags() 160 161 Br = Reflective_boundary(domain) 162 Bd = Dirichlet_boundary([tide,0,0]) 163 164 # 60 min square wave starting at 1 min, 50m high 165 if scenario == 'fixed_wave': 45 def run_model(**kwargs): 46 47 48 #------------------------------------------------------------------------------ 49 # Copy scripts to time stamped output directory and capture screen 50 # output to file 51 #------------------------------------------------------------------------------ 52 print "Processor Name:",get_processor_name() 53 54 #copy script must be before screen_catcher 55 #print kwargs 56 57 print 'output_dir',kwargs['output_dir'] 58 if myid == 0: 59 copy_code_files(kwargs['output_dir'],__file__, 60 dirname(project.__file__)+sep+ project.__name__+'.py' ) 61 62 store_parameters(**kwargs) 63 64 barrier() 65 66 start_screen_catcher(kwargs['output_dir'], myid, numprocs) 67 68 print "Processor Name:",get_processor_name() 69 70 # filenames 71 # meshes_dir_name = project.meshes_dir_name+'.msh' 72 73 # creates copy of code in output dir 74 print 'min triangles', project.trigs_min, 75 print 'Note: This is generally about 20% less than the final amount' 76 77 #-------------------------------------------------------------------------- 78 # Create the triangular mesh based on overall clipping polygon with a 79 # tagged 80 # boundary and interior regions defined in project.py along with 81 # resolutions (maximal area of per triangle) for each polygon 82 #-------------------------------------------------------------------------- 83 84 #IMPORTANT don't cache create_mesh_from_region and Domain(mesh....) as it 85 # causes problems with the ability to cache set quantity which takes alot of times 86 87 if myid == 0: 88 89 print 'start create mesh from regions' 90 91 create_mesh_from_regions(project.poly_all, 92 boundary_tags=project.boundary_tags, 93 maximum_triangle_area=project.res_poly_all, 94 interior_regions=project.interior_regions, 95 filename=project.meshes_dir_name+'.msh', 96 use_cache=False, 97 verbose=True) 98 barrier() 99 100 #------------------------------------------------------------------------- 101 # Setup computational domain 102 #------------------------------------------------------------------------- 103 print 'Setup computational domain' 104 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: 119 120 print 'Setup initial conditions' 121 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'] 132 133 domain.set_quantity('elevation', 134 filename = kwargs['bathy_file'], 135 use_cache = True, 136 verbose = True, 137 alpha = kwargs['alpha']) 138 print 'Finished Set quantity' 139 barrier() 140 141 #------------------------------------------------------ 142 # Distribute domain to implement parallelism !!! 143 #------------------------------------------------------ 144 145 if numprocs > 1: 146 domain=distribute(domain) 147 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) 161 domain.beta_h = 0 162 163 #------------------------------------------------------------------------------ 164 # Setup information for slide scenario (to be applied 1 min into simulation 165 #------------------------------------------------------------------------------ 166 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, 172 slope=6.0, 173 thickness=500.0, 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' 186 187 Br = Reflective_boundary(domain) 188 Bd = Dirichlet_boundary([kwargs['tide'],0,0]) 189 Bo = Dirichlet_boundary([kwargs['tide']+5.0,0,0]) 190 191 if scenario == 'fixed_wave': 166 192 # FIXME (Ole): Change this to Transmissive Momentum as 167 193 # suggested by Rajaraman (ticket:208) 168 Bw = Time_boundary(domain = domain, 169 f=lambda t: [(60<t<3660)*50, 0, 0]) 170 domain.set_boundary({'ocean_east': Bw, 171 'bottom': Bd, 172 'onshore': Bd, 173 'top': Bd}) 174 175 # boundary conditions for slide scenario 176 if scenario == 'slide': 177 domain.set_boundary({'ocean_east': Bd, 178 'bottom': Bd, 179 'onshore': Bd, 180 'top': Bd}) 181 182 183 #------------------------------------------------------------------------------ 184 # Evolve system through time 185 #------------------------------------------------------------------------------ 186 187 import time 188 t0 = time.time() 189 190 from Numeric import allclose 191 from anuga.abstract_2d_finite_volumes.quantity import Quantity 192 193 if scenario == 'slide': 194 195 for t in domain.evolve(yieldstep = 10, finaltime = 60): 194 Bw = Time_boundary(domain = domain, 195 f=lambda t: [(60<t<3660)*100, 0, 0]) 196 domain.set_boundary({'ocean_east': Bw, 197 'ocean_southeast': Bd, 198 'land': Bd, 199 'ocean_north': Bd, 200 'ocean_west':}) 201 202 # boundary conditions for slide scenario 203 if scenario == 'slide': 204 domain.set_boundary({'ocean_east': Bd, 205 'ocean_southeast': Bd, 206 'land': Bd, 207 'ocean_north': Bd, 208 'ocean_west':}) 209 210 #---------------------------------------------------------------------------- 211 # Evolve system through time 212 #-------------------------------------------------------------------- 213 t0 = time.time() 214 215 for t in domain.evolve(yieldstep = 240, finaltime = kwargs['finaltime']): 196 216 domain.write_time() 197 217 domain.write_boundary_statistics(tags = 'ocean_east') 198 199 # add slide 200 thisstagestep = domain.get_quantity('stage') 201 if allclose(t, 60): 202 slide = Quantity(domain) 203 slide.set_values(tsunami_source) 204 domain.set_quantity('stage', slide + thisstagestep) 205 206 for t in domain.evolve(yieldstep = 10, finaltime = 5000, 207 skip_initial_step = True): 208 domain.write_time() 209 domain.write_boundary_statistics(tags = 'ocean_east') 210 211 if scenario == 'fixed_wave': 212 213 # save every two mins leading up to wave approaching land 214 for t in domain.evolve(yieldstep = 120, finaltime = 5000): 215 domain.write_time() 216 domain.write_boundary_statistics(tags = 'ocean_east') 217 218 # save every 30 secs as wave starts inundating ashore 219 for t in domain.evolve(yieldstep = 10, finaltime = 10000, 220 skip_initial_step = True): 221 domain.write_time() 222 domain.write_boundary_statistics(tags = 'ocean_east') 223 224 print 'That took %.2f seconds' %(time.time()-t0) 218 219 x, y = domain.get_maximum_inundation_location() 220 q = domain.get_maximum_inundation_elevation() 221 222 print 'Maximum runup observed at (%.2f, %.2f) with elevation %.2f' %(x,y,q) 223 224 print 'That took %.2f seconds' %(time.time()-t0) 225 226 #kwargs 'completed' must be added to write the final parameters to file 227 kwargs['completed']=str(time.time()-t0) 228 229 if myid==0: 230 store_parameters(**kwargs) 231 barrier 232 233 print 'memory usage before del domain1',mem_usage() 234 235 def export_model(**kwargs): 236 #store_parameters(**kwargs) 237 238 # print 'memory usage before del domain',mem_usage() 239 #del domain 240 print 'memory usage after del domain',mem_usage() 241 242 swwfile = kwargs['output_dir']+kwargs['scenario_name'] 243 print'swwfile',swwfile 244 245 export_grid(swwfile, extra_name_out = 'town', 246 quantities = ['speed','depth','elevation','stage'], # '(xmomentum**2 + ymomentum**2)**0.5' defaults to elevation 247 #quantities = ['speed','depth'], # '(xmomentum**2 + ymomentum**2)**0.5' defaults to elevation 248 timestep = None, 249 reduction = max, 250 cellsize = kwargs['export_cellsize'], 251 NODATA_value = -1E-030, 252 easting_min = project.eastingmin, 253 easting_max = project.eastingmax, 254 northing_min = project.northingmin, 255 northing_max = project.northingmax, 256 verbose = False, 257 origin = None, 258 datum = 'WGS84', 259 format = 'txt') 260 261 #------------------------------------------------------------- 262 if __name__ == "__main__": 263 264 kwargs={} 265 kwargs['est_num_trigs']=project.trigs_min 266 kwargs['num_cpu']=numprocs 267 kwargs['host']=project.host 268 kwargs['res_factor']=project.res_factor 269 kwargs['starttime']=project.starttime 270 kwargs['yieldstep']=project.yieldstep 271 kwargs['midtime']=project.midtime 272 kwargs['finaltime']=project.finaltime 273 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 290 291 run_model(**kwargs) 292 293 if myid==0: 294 export_model(**kwargs) 295 barrier
Note: See TracChangeset
for help on using the changeset viewer.