"""Script for running a tsunami inundation scenario for Sydney, NSW, Australia. Source data such as elevation and boundary data is assumed to be available in directories specified by project.py The output sww file is stored in project.outputdir The scenario is defined by a triangular mesh created from project.polygon, the elevation data and a simulated submarine landslide. Ole Nielsen and Duncan Gray, GA - 2005 and Adrian Hitchman and Jane Sexton, GA - 2006 """ #-------------------------------------------------------------------------------# Import necessary modules #------------------------------------------------------------------------------- # Standard modules import os import time # Related major packages from pyvolution.shallow_water import Domain, Reflective_boundary, Time_boundary from pyvolution.data_manager import convert_dem_from_ascii2netcdf, dem2pts from pyvolution.combine_pts import combine_rectangular_points_files from pyvolution.pmesh2domain import pmesh_to_domain_instance from pyvolution.quantity import Quantity from geospatial_data import * # Application specific imports import project # Definition of file names and polygons from smf import slump_tsunami # Function for submarine mudslide #------------------------------------------------------------------------------- # Preparation of topographic data # # Convert ASC 2 DEM 2 PTS using source data and store result in source data # Do for coarse and fine data # Fine pts file to be clipped to area of interest #------------------------------------------------------------------------------- # filenames coarsedemname = project.coarsedemname finedemname = project.finedemname # coarse data convert_dem_from_ascii2netcdf(coarsedemname, use_cache=True, verbose=True) #dem2pts(coarsedemname, use_cache=True, verbose=True) dem2pts(coarsedemname, easting_min=project.eastingmin, easting_max=project.eastingmax, northing_min=project.northingmin, northing_max= project.northingmax, use_cache=True, verbose=True) # fine data (clipping the points file to smaller area) convert_dem_from_ascii2netcdf(finedemname, use_cache=True, verbose=True) dem2pts(finedemname, easting_min=project.eastingmin, easting_max=project.eastingmax, northing_min=project.northingmin, northing_max= project.northingmax, use_cache=True, verbose=True) # combining the coarse and fine data combine_rectangular_points_files(project.finedemname + '.pts', project.coarsedemname + '.pts', project.combineddemname + '.pts') #------------------------------------------------------------------------------- # Create the triangular mesh based on overall clipping polygon with a tagged # boundary and interior regions defined in project.py along with # resolutions (maximal area of per triangle) for each polygon #------------------------------------------------------------------------------- #from pmesh.create_mesh import create_mesh_from_regions from pmesh.mesh_interface import create_mesh_from_regions meshname = project.meshname4+'.msh' interior_res1 = 25000 interior_res2 = 1315 print 'interior resolution', interior_res1, interior_res2 # Read in files containing polygon points (generated by GIS) # and construct list of interior polygons into interior_regions. def get_polygon_from_file(filename): """ Function to read in output from GIS determined polygon """ fid = open(filename) lines = fid.readlines() fid.close() polygon = [] for line in lines[1:]: fields = line.split(',') x = float(fields[1]) y = float(fields[2]) polygon.append([x, y]) return polygon num_polygons = 3 fileext = '.csv' filename = project.polygonptsfile interior_regions = [] for p in range(3, num_polygons+1): thefilename = filename + str(p) + fileext print 'reading in polygon points', thefilename interior_polygon = get_polygon_from_file(thefilename) interior_regions.append([interior_polygon, interior_res1]) print 'number of interior polygons: ', len(interior_regions) #print 'Number of interior polygons: ', len(interior_regions) # original #interior_regions = [] #interior_regions = [[project.harbour_polygon_2, interior_res1], # [project.botanybay_polygon_2, interior_res1]] # finer set #interior_regions = [[project.newpoly1, interior_res1], # #[project.parrariver, interior_res1], #remove for second run # [project.south1, interior_res1], # [project.finepolymanly, interior_res2], # [project.finepolyquay, interior_res2]] #FIXME: Fix caching of this one once the mesh_interface is ready from caching import cache #_ = cache(create_mesh_from_regions, # project.diffpolygonall, # {'boundary_tags': {'bottom': [0], # 'right1': [1], 'right0': [2], # 'right2': [3], 'top': [4], 'left1': [5], # 'left2': [6], 'left3': [7]}, # 'maximum_triangle_area': 100000, # 'filename': meshname, # 'interior_regions': interior_regions}, # verbose = True) _ = cache(create_mesh_from_regions, project.diffpolygonall_test, {'boundary_tags': {'bottom': [0], 'right': [1], 'top': [2], 'left': [3]}, 'maximum_triangle_area': 100000, 'filename': meshname, 'interior_regions': interior_regions}, verbose = True) #mesh_geo_reference: #------------------------------------------------------------------------------- # Setup computational domain #------------------------------------------------------------------------------- domain = pmesh_to_domain_instance(meshname, Domain, use_cache = True, verbose = True) print 'Number of triangles = ', len(domain) print 'The extent is ', domain.get_extent() print domain.statistics() domain.set_name(project.basename4) domain.set_datadir(project.outputdir) domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) #------------------------------------------------------------------------------- # Set up scenario (tsunami_source is a callable object used with set_quantity) #------------------------------------------------------------------------------- tsunami_source = slump_tsunami(length=30000.0, depth=400.0, slope=6.0, thickness=176.0, radius=3330, dphi=0.23, x0=project.slump_origin[0], y0=project.slump_origin[1], alpha=0.0, domain=domain) #print 'testing', tsunami_source.get_integral() #------------------------------------------------------------------------------- # Setup initial conditions #------------------------------------------------------------------------------- G = Geospatial_data(project.test_pts, project.test_elev) #points, attributes domain.set_quantity('stage', 0) #tsunami_source) domain.set_quantity('friction', 0.0) # supplied by Benfield, initial value 0.03 domain.set_quantity('elevation', alpha = 10.0,#G, alpha = 550.0, #filename = project.combineddemname + '.pts', filename = project.coarsedemname + '.pts', use_cache = False, verbose = True) from pyvolution.least_squares import fit_to_mesh_file, DEFAULT_ALPHA #Add elevation data to the mesh #fit_to_mesh_file(mesh_file, point_file, mesh_output_file, DEFAULT_ALPHA, # verbose=True, expand_search=True, precrop=True) #pointname = project.coarsedemname + '.pts' #mesh_elevname = project.meshelevname #cache(fit_to_mesh_file,(meshname, # pointname, # mesh_elevname, # DEFAULT_ALPHA), # {'verbose': True, # 'expand_search': True, # 'precrop': True} # ,dependencies = [meshname, pointname] # #,evaluate = True # ,verbose = False # ) #------------------------------------------------------------------------------- # Setup boundary conditions (all reflective) #------------------------------------------------------------------------------- print 'Available boundary tags', domain.get_boundary_tags() Br = Reflective_boundary(domain) #domain.set_boundary( {'bottom': Br, 'right1': Br, 'right0': Br, # 'right2': Br, 'top': Br, 'left1': Br, # 'left2': Br, 'left3': Br} ) domain.set_boundary( {'bottom': Br, 'right': Br, 'left': Br, 'top': Br} ) #domain.set_boundary( {'bottom': Br, 'right1': Br, 'right0': Br, # 'right2': Br, 'top': Br, 'left1': Br, # 'left2': Br, 'left3': Br} ) #------------------------------------------------------------------------------- # Evolve system through time #------------------------------------------------------------------------------- import time t0 = time.time() thisfile = project.integraltimeseries+'.csv' fid = open(thisfile, 'w') # original for t in domain.evolve(yieldstep = 1, finaltime = 10): domain.write_time() domain.write_boundary_statistics(tags = 'bottom') stagestep = domain.get_quantity('stage') s = '%.2f, %.2f\n' %(t, stagestep.get_integral()) fid.write(s) print 'That took %.2f seconds' %(time.time()-t0)