"""Script for running a tsunami inundation scenario for Onslow, WA, 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 Nick Bartzis, GA - 2006 """ #------------------------------------------------------------------------------ # Import necessary modules #------------------------------------------------------------------------------ # Standard modules import os import time # Related major packages from pyvolution.shallow_water import Domain, Reflective_boundary, \ Dirichlet_boundary, Time_boundary, File_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 geospatial_data import * # Application specific imports import project # Definition of file names and polygons from smf import slump_tsunami # Function for submarine mudslide from shutil import copy from os import mkdir, access, F_OK #------------------------------------------------------------------------------ # 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 onshore_dem_name = project.onshore_dem_name meshname = project.meshname+'.msh' ############################################################# # making a copy of project and run to a time stamped directory # with the ouput source_dir = project.boundarydir #if dir doesn't exists then makes dir if access(project.outputdir,F_OK) == 0 : mkdir (project.outputdir) # creates copy of code in output dir copy (project.codedirname, project.outputdir + project.codename) copy (project.codedir + 'run_onslow.py', project.outputdir + 'run_onlsow.py') #print "copied to"+ project.outputdir + project.codename + 'and run_onlsow.py' ################################################################# ''' # coarse data convert_dem_from_ascii2netcdf(coarsedemname, use_cache=True, verbose=True) dem2pts(coarsedemname, use_cache=True, verbose=True) # fine data (clipping the points file to smaller area) convert_dem_from_ascii2netcdf(onshore_dem_name, use_cache=True, verbose=True) dem2pts(onshore_dem_name, easting_min=project.eastingmin, easting_max=project.eastingmax, northing_min=project.northingmin, northing_max= project.northingmax, use_cache=True, verbose=True) print 'before off xya to object' offshore_pts = Geospatial_data(project.offshore_dem_name + '.xya') print 'before offshore to dict' offshore_dict = geospatial_data2points_dictionary(offshore_pts) print 'offshore to pts file' export_points_file(project.offshore_dem_name + '.pts', offshore_dict) ''' # combining the coarse and fine data # NOTE MUST HAVE FINE FIRST! ''' combine_rectangular_points_files( project.onshore_dem_name + '.pts', project.coarsedemname + '.pts', project.combined_dem_name + '.pts') print 'create G1' G1 = Geospatial_data(project.onshore_dem_name + '.pts') print 'G1 dict' G1_points_dict = geospatial_data2points_dictionary(G1) print 'G1 xya file' export_points_file(project.datadir + 'offshore_dem.xya', G1_points_dict) print 'create G2' G2 = Geospatial_data(project.offshore_dem_name + '.xya') print 'G1+g2' G = G1 + G2 print 'G dict' G_points_dict = geospatial_data2points_dictionary(G) print 'G to xya' export_points_file(project.combined_dem_name + '.xya', G_points_dict) add_points_files(project.onshore_dem_name + '.pts', project.offshore_dem_name + '.xya', project.combined_dem_name + '.pts') print 'please' add_points_files(project.onshore_dem_name + '.pts', project.offshore_dem_name + '.pts', project.combined_dem_name + '.pts') print ' finished with points' ''' #------------------------------------------------------------------------------- # 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.mesh_interface import create_mesh_from_regions # original interior_res = 50000 interior_regions = [[project.poly_onslow, interior_res], [project.poly_thevenard, interior_res], [project.poly_direction, interior_res]] #[project.testpoly, interior_res]] print 'number of interior regions', len(interior_regions) from caching import cache _ = cache(create_mesh_from_regions, project.polyAll, {'boundary_tags': {'top': [0], 'topleft': [1], 'left': [2], 'bottom': [3], 'bottomright': [4], 'topright': [5]}, 'maximum_triangle_area': 1000000, 'filename': meshname, 'interior_regions': interior_regions}, verbose = True) #------------------------------------------------------------------------------ # 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.basename) domain.set_datadir(project.outputdir) domain.set_quantities_to_be_stored(['stage']) print 'hi' #------------------------------------------------------------------------------ # 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) ''' #------------------------------------------------------------------------------ # Setup initial conditions #------------------------------------------------------------------------------ tide = 0. domain.set_quantity('stage', tide) domain.set_quantity('friction', 0.0) print 'hi1', project.combined_dem_name + '.pts' domain.set_quantity('elevation', # 0. # filename = project.onshore_dem_name + '.pts', filename = project.combined_dem_name + '.pts', # filename = project.coarsedemname + '.pts', use_cache = True, verbose = True ) print 'hi2' #------------------------------------------------------------------------------ # Setup boundary conditions (all reflective) #------------------------------------------------------------------------------ ''' from pyvolution.data_manager import ferret2sww south = project.south north = project.north west = project.west east = project.east cache(ferret2sww, (source_dir + project.boundary_basename, source_dir + project.boundary_basename), {'verbose': True, # note didn't work with the below # 'minlat': south - 1, # 'maxlat': north + 1, # 'minlon': west - 1, # 'maxlon': east + 1, 'minlat': south, 'maxlat': north, 'minlon': west, 'maxlon': east, # 'origin': project.mesh_origin, 'origin': domain.geo_reference.get_origin(), 'mean_stage': tide, 'zscale': 1, #Enhance tsunami 'fail_on_NaN': False, 'inverted_bathymetry': True}, #evaluate = True, verbose = True) ''' print 'Available boundary tags', domain.get_boundary_tags() #Bf = File_boundary(source_dir + project.boundary_basename + '.sww', # domain, verbose = True) Br = Reflective_boundary(domain) Bd = Dirichlet_boundary([tide,0,0]) print 'hi3' # 7 min square wave starting at 1 min, 6m high Bw = Time_boundary(domain = domain, f=lambda t: [(60