""" Script for running a breaking wave simulation of Jon Hinwoods wave tank. Note: this is based on the frinction_ua_flume_2006 structure. Duncan Gray, GA - 2007 """ #---------------------------------------------------------------------------- # Import necessary modules #---------------------------------------------------------------------------- from Scientific.IO.NetCDF import NetCDFFile from Numeric import array, zeros, Float from project import boundary_file def prepare_timeboundary(filename): """Convert 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 'Creating', filename # Read the ascii (.csv) version of this file fid = open(filename[:-4] + '.csv') # 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) #Stage X = zeros(N, Float) #XMomentum Y = zeros(N, Float) #YMomentum for i, line in enumerate(lines): fields = line.split(',') T[i] = float(fields[0]) Q[i] = depth = float(fields[1]) X[i] = float(fields[2]) * depth Y[i] = float(fields[3]) * depth # Create tms NetCDF file fid = NetCDFFile(filename, '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'][:] = X[:] fid.createVariable('ymomentum', Float, ('number_of_timesteps',)) fid.variables['ymomentum'][:] = Y[:] fid.close() #------------------------------------------------------------- if __name__ == "__main__": prepare_timeboundary(boundary_file)