"""Validation of the AnuGA implementation of the shallow water wave equation. This script sets up LWRU2 benchmark with initial condition stated See also http://www.cee.cornell.edu/longwave/index.cfm?page=benchmark&problem=2 Depth at western boundary is d = 13.5 cm """ use_variable_mesh = True #Use large variable mesh generated by create_mesh.py #use_variable_mesh = False #Use small structured mesh for speed import sys from os import sep sys.path.append('..'+sep+'..'+sep) #FIXME: Shouldn't be necessary def prepare_timeboundary(filename): """Converting benchmark 2 time series to NetCDF tms file. This is a 'throw-away' code taylor made for files like 'Benchmark_2_input.txt' from the LWRU2 benchmark """ print 'Preparing time boundary from %s' %filename from Numeric import array fid = open(filename) #Skip first line line = fid.readline() #Read remaining lines lines = fid.readlines() fid.close() N = len(lines) T = zeros(N, Float) #Time Q = zeros(N, Float) #Values for i, line in enumerate(lines): fields = line.split() T[i] = float(fields[0]) Q[i] = float(fields[1]) #Create tms file from Scientific.IO.NetCDF import NetCDFFile outfile = filename[:-4] + '.tms' print 'Writing to', outfile fid = NetCDFFile(outfile, 'w') fid.institution = 'Geoscience Australia' fid.description = 'Input wave for Benchmark 2' fid.starttime = 0.0 fid.createDimension('number_of_timesteps', len(T)) fid.createVariable('time', Float, ('number_of_timesteps',)) fid.variables['time'][:] = T fid.createVariable('stage', Float, ('number_of_timesteps',)) fid.variables['stage'][:] = Q[:] fid.createVariable('xmomentum', Float, ('number_of_timesteps',)) fid.variables['xmomentum'][:] = 0.0 fid.createVariable('ymomentum', Float, ('number_of_timesteps',)) fid.variables['ymomentum'][:] = 0.0 fid.close() # Module imports from pyvolution.shallow_water import Domain, Reflective_boundary,\ File_boundary, Transmissive_Momentum_Set_Stage_boundary from pyvolution.mesh_factory import rectangular_cross from pyvolution.pmesh2domain import pmesh_to_domain_instance from Numeric import array, zeros, Float, allclose import project from caching import cache #Preparing time boundary prepare_timeboundary(project.boundary_filename) #Preparing points (Only when using original Benchmark_2_Bathymetry.txt file) #from pyvolution.data_manager import xya2pts #xya2pts(project.bathymetry_filename, verbose = True, # z_func = lambda z: -z) ####################### # Create Domain if use_variable_mesh is True: print 'Creating domain from', project.mesh_filename domain = Domain(project.mesh_filename, use_cache=True, verbose=True) else: print 'Creating regular mesh' N = 150 points, vertices, boundary = rectangular_cross(N, N/5*3, len1=5.448, len2=3.402) print 'Creating domain' #domain = Domain(points, vertices, boundary) domain = cache(Domain, (points, vertices, boundary)) import sys, os base = os.path.basename(sys.argv[0]) domain.filename, _ = os.path.splitext(base) domain.default_order = 2 domain.store = True #Store for visualisation purposes #domain.check_integrity() print 'Number of triangles = ', len(domain) print 'The extent is ', domain.get_extent() print domain.statistics() ####################### # Initial Conditions print 'Initial values' domain.set_quantity('elevation', filename = project.bathymetry_filename[:-4] + '.pts', alpha = 0.001, verbose = True, use_cache = True) domain.set_quantity('friction', 0.0) domain.set_quantity('stage', 0.0) ###################### # Boundary Conditions # print 'Boundaries' Br = Reflective_boundary(domain) from pyvolution.util import file_function function = file_function(project.boundary_filename[:-4] + '.tms', domain, verbose = True) Bts = Transmissive_Momentum_Set_Stage_boundary(domain, function) #Set boundary conditions if use_variable_mesh is True: domain.set_boundary({'wave': Bts, 'wall': Br}) else: domain.set_boundary({'left': Bts, 'right': Br, 'bottom': Br, 'top': Br}) ####################### # Evolve import time t0 = time.time() for t in domain.evolve(yieldstep = 0.05, finaltime = 22.5): domain.write_time() print 'That took %.2f seconds' %(time.time()-t0)