"""Script for running a tsunami inundation scenario for Broome, 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.outputtimedir The scenario is defined by a triangular mesh created from project.polygon, the elevation data and a tsunami wave generated by MOST. Ole Nielsen and Duncan Gray, GA - 2005 and Nick Bartzis, GA - 2006 """ #------------------------------------------------------------------------------- # Import necessary modules #------------------------------------------------------------------------------- # Standard modules import os import time from shutil import copy from os.path import dirname, basename from os import mkdir, access, F_OK, sep import sys # Related major packages from anuga.shallow_water import Domain, Reflective_boundary, \ Dirichlet_boundary, Time_boundary, File_boundary from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts from anuga.abstract_2d_finite_volumes.combine_pts import combine_rectangular_points_files from anuga.geospatial_data.geospatial_data import * #from anuga.abstract_2d_finite_volumes.util import Screen_Catcher from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files # Application specific imports import project # Definition of file names and polygons #------------------------------------------------------------------------------- # Copy scripts to time stamped output directory and capture screen # output to file #------------------------------------------------------------------------------- # creates copy of code in output dir copy_code_files(project.outputtimedir,__file__,dirname(project.__file__)+sep+ project.__name__+'.py' ) myid = 0 numprocs = 1 start_screen_catcher(project.outputtimedir, myid, numprocs) print 'USER: ', project.user #------------------------------------------------------------------------------- # Preparation of topographic data # # Convert ASC 2 DEM 2 PTS using source data and store result in source data #------------------------------------------------------------------------------- # filenames onshore_dem_name = project.onshore_dem_name offshore_interp_dem_name = project.offshore_interp_dem_name coast_points = project.coast_dem_name meshname = project.meshname+'.msh' # creates DEM from asc data convert_dem_from_ascii2netcdf(onshore_dem_name, use_cache=True, verbose=True) #creates pts file for onshore DEM dem2pts(onshore_dem_name, use_cache=True, verbose=True) # creates DEM from asc data convert_dem_from_ascii2netcdf(offshore_interp_dem_name, use_cache=True, verbose=True) #creates pts file for offshore interpolated DEM dem2pts(offshore_interp_dem_name, use_cache=True, verbose=True) print 'create offshore' G1 = Geospatial_data(file_name = project.offshore_dem_name1 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name2 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name3 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name4 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name5 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name6 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name7 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name8 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name9 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name10 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name11 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name12 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name13 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name14 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name15 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name16 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name17 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name18 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name19 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name20 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name21 + '.xya')+\ Geospatial_data(file_name = project.offshore_dem_name22 + '.xya')+\ Geospatial_data(file_name = project.offshore_interp_dem_name + '.pts') print 'create onshore' G2 = Geospatial_data(file_name = project.onshore_dem_name + '.pts') print 'create coast' G3 = Geospatial_data(file_name = project.coast_dem_name + '.xya') print 'add' G = G1 + G2 + G3 print 'export points' G.export_points_file(project.combined_dem_name + '.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 anuga.pmesh.mesh_interface import create_mesh_from_regions remainder_res = 500000 local_res = 25000 broome_res = 5000 coast_res = 500 interior_regions = [[project.poly_broome1, local_res], [project.poly_broome2, broome_res], [project.poly_broome3, coast_res]] from project import number_mesh_triangles print 'estimate of number of triangles', \ number_mesh_triangles(interior_regions, project.polyAll, remainder_res) from caching import cache _ = cache(create_mesh_from_regions, project.polyAll, {'boundary_tags': {'e0': [0], 'e1': [1], 'e2': [2], 'e3': [3], 'e4':[4], 'e5': [5], 'e6': [6]}, 'maximum_triangle_area': remainder_res, 'filename': meshname, 'interior_regions': interior_regions}, verbose = True, evaluate=False) print 'created mesh' #------------------------------------------------------------------------------- # Setup computational domain #------------------------------------------------------------------------------- domain = Domain(meshname, 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.outputtimedir) domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) domain.set_minimum_storable_height(0.01) #------------------------------------------------------------------------------- # Setup initial conditions #------------------------------------------------------------------------------- tide = 0.0 domain.set_quantity('stage', tide) domain.set_quantity('friction', 0.0) domain.set_quantity('elevation', filename = project.combined_dem_name + '.pts', use_cache = True, verbose = True, alpha = 0.1 ) #------------------------------------------------------------------------------- # Setup boundary conditions #------------------------------------------------------------------------------- ''' print 'start urs2sww' print '', project.boundary_basename from anuga.shallow_water.data_manager import urs2sww south = project.south north = project.north west = project.west east = project.east #note only need to do when an SWW file for the MOST boundary doesn't exist cache(urs2sww, (source_dir + project.boundary_basename, source_dir + project.boundary_basename), {'verbose': True, 'minlat': south, 'maxlat': north, 'minlon': west, 'maxlon': east, #'origin': domain.geo_reference.get_origin(), 'mean_stage': tide, 'zscale': 1, #Enhance tsunami 'fail_on_NaN': False, 'inverted_bathymetry': True}, #evaluate = True, verbose = True, dependencies = source_dir + project.boundary_basename + '.sww') ''' 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]) # 7 min square wave starting at 1 min, 6m high Bw = Time_boundary(domain = domain, f=lambda t: [(60