"""Script for running tsunami inundation scenario for Dampier, 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.output_run_time_dir The scenario is defined by a triangular mesh created from project.polygon, the elevation data and a simulated tsunami generated with URS code. Ole Nielsen and Duncan Gray, GA - 2005 and Jane Sexton, Nick Bartzis, GA - 2006 """ #------------------------------------------------------------------------------ # Import necessary modules #------------------------------------------------------------------------------ # Standard modules from os import sep from os.path import dirname, basename from os import mkdir, access, F_OK from shutil import copy import time import sys # Related major packages from anuga.shallow_water import Time_boundary from anuga.shallow_water import Domain from anuga.shallow_water import Dirichlet_boundary, Transmissive_boundary from anuga.shallow_water import File_boundary from anuga.shallow_water import Reflective_boundary from anuga.shallow_water import Field_boundary from Numeric import allclose from anuga.shallow_water.data_manager import export_grid from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts from anuga.pmesh.mesh_interface import create_mesh_from_regions from anuga.shallow_water.data_manager import start_screen_catcher, copy_code_files,store_parameters from anuga_parallel.parallel_api import distribute, numprocs, myid, barrier from anuga_parallel.parallel_abstraction import get_processor_name from anuga.caching import myhash from anuga.damage_modelling.inundation_damage import add_depth_and_momentum2csv, inundation_damage from anuga.fit_interpolate.benchmark_least_squares import mem_usage # Application specific imports import project # Definition of file names and polygons def run_model(**kwargs): #------------------------------------------------------------------------------ # Copy scripts to time stamped output directory and capture screen # output to file #------------------------------------------------------------------------------ print "Processor Name:",get_processor_name() #copy script must be before screen_catcher #print kwargs print 'output_dir',kwargs['output_dir'] if myid == 0: copy_code_files(kwargs['output_dir'],__file__, dirname(project.__file__)+sep+ project.__name__+'.py' ) store_parameters(**kwargs) barrier() start_screen_catcher(kwargs['output_dir'], myid, numprocs) print "Processor Name:",get_processor_name() # filenames # meshes_dir_name = project.meshes_dir_name+'.msh' # creates copy of code in output dir print 'min triangles', project.trigs_min, print 'Note: This is generally about 20% less than the final amount' #-------------------------------------------------------------------------- # 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 #-------------------------------------------------------------------------- if myid == 0: print 'start create mesh from regions' create_mesh_from_regions(project.poly_all, boundary_tags=project.boundary_tags, maximum_triangle_area=project.res_poly_all, interior_regions=project.interior_regions, filename=project.meshes_dir_name+'.msh', use_cache=True, verbose=True) barrier() scenario='fixed_wave' #------------------------------------------------------------------------- # Setup computational domain #------------------------------------------------------------------------- print 'Setup computational domain' #domain = cache(Domain, (meshes_dir_name), {'use_cache':True, 'verbose':True}, verbose=True) #above don't work domain = Domain(project.meshes_dir_name+'.msh', use_cache=True, verbose=True) print 'memory usage before del domain',mem_usage() print domain.statistics() print 'triangles',len(domain) kwargs['act_num_trigs']=len(domain) #------------------------------------------------------------------------- # Setup initial conditions #------------------------------------------------------------------------- if myid == 0: print 'Setup initial conditions' from polygon import Polygon_function #following sets the stage/water to be offcoast only # IC = Polygon_function( [(project.poly_mainland, -1.0)], default = kwargs['tide'], # geo_reference = domain.geo_reference) # domain.set_quantity('stage', IC) domain.set_quantity('stage',kwargs['tide'] ) # domain.set_quantity('stage', kwargs['tide']) domain.set_quantity('friction', kwargs['friction']) print 'Start Set quantity',kwargs['bathy_file'] domain.set_quantity('elevation', filename = kwargs['bathy_file'], use_cache = False, verbose = True, alpha = kwargs['alpha']) print 'Finished Set quantity' barrier() #------------------------------------------------------ # Distribute domain to implement parallelism !!! #------------------------------------------------------ if numprocs > 1: domain=distribute(domain) #------------------------------------------------------ # Set domain parameters #------------------------------------------------------ print 'domain id', id(domain) domain.set_name(kwargs['aa_scenario_name']) domain.set_datadir(kwargs['output_dir']) domain.set_default_order(2) # Apply second order scheme domain.set_minimum_storable_height(0.01) # Don't store anything less than 1cm domain.set_store_vertices_uniquely(False) domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) domain.tight_slope_limiters = 1 #domain.set_maximum_allowed_speed(0.1) # Allow a little runoff (0.1 is OK) print 'domain id', id(domain) #------------------------------------------------------------------------------ # Setup information for slide scenario (to be applied 1 min into simulation #------------------------------------------------------------------------------ if scenario == 'slide': # Function for submarine slide from anuga.shallow_water.smf import slide_tsunami tsunami_source = slide_tsunami(length=35000.0, depth=project.slide_depth, slope=10.0, thickness=800.0, x0=project.slide_origin[0], y0=project.slide_origin[1], alpha=0.0, domain=domain, verbose=True) #------------------------------------------------------------------------- # Setup boundary conditions #------------------------------------------------------------------------- print 'Available boundary tags', domain.get_boundary_tags() print 'domain id', id(domain) #print 'Reading Boundary file',project.boundaries_dir_namea + '.sww' Bt = Transmissive_boundary(domain) Br = Reflective_boundary(domain) Bd = Dirichlet_boundary([0,0,0]) if scenario == 'fixed_wave': # FIXME (Ole): Change this to Transmissive Momentum as # suggested by Rajaraman (ticket:208) from math import sin, pi Bw = Time_boundary(domain = domain, f=lambda t: [(120