1 | """ |
---|
2 | Script for running a breaking wave simulation of Jon Hinwoods wave tank. |
---|
3 | Note: this is based on the frinction_ua_flume_2006 structure. |
---|
4 | |
---|
5 | |
---|
6 | Duncan Gray, GA - 2007 |
---|
7 | |
---|
8 | """ |
---|
9 | |
---|
10 | |
---|
11 | #---------------------------------------------------------------------------- |
---|
12 | # Import necessary modules |
---|
13 | #---------------------------------------------------------------------------- |
---|
14 | |
---|
15 | from Scientific.IO.NetCDF import NetCDFFile |
---|
16 | from Numeric import zeros, Float |
---|
17 | |
---|
18 | from anuga.utilities.numerical_tools import ensure_numeric |
---|
19 | from anuga.utilities.interp import interp |
---|
20 | |
---|
21 | |
---|
22 | def csv2tms(filename, offshore_bed_elevation): |
---|
23 | """Convert benchmark 2 time series to NetCDF tms file. |
---|
24 | the filename is the name of the output tms file, eg 'hi.tsm'. |
---|
25 | There must be an equivalent .csv file, eg 'hi.csv'. |
---|
26 | |
---|
27 | """ |
---|
28 | print 'Creating', filename |
---|
29 | |
---|
30 | # Read the ascii (.csv) version of this file |
---|
31 | fid = open(filename[:-4] + '.csv') |
---|
32 | |
---|
33 | # Read remaining lines |
---|
34 | lines = fid.readlines() |
---|
35 | fid.close() |
---|
36 | |
---|
37 | N = len(lines) |
---|
38 | T = zeros(N, Float) #Time |
---|
39 | Q = zeros(N, Float) #Stage |
---|
40 | X = zeros(N, Float) #XMomentum |
---|
41 | Y = zeros(N, Float) #YMomentum |
---|
42 | |
---|
43 | for i, line in enumerate(lines): |
---|
44 | fields = line.split(',') |
---|
45 | |
---|
46 | T[i] = float(fields[0]) |
---|
47 | Q[i] = float(fields[1]) |
---|
48 | depth = Q[i] - offshore_bed_elevation |
---|
49 | X[i] = float(fields[2]) * depth |
---|
50 | Y[i] = float(fields[3]) * depth |
---|
51 | |
---|
52 | # Create tms NetCDF file |
---|
53 | fid = NetCDFFile(filename, 'w') |
---|
54 | fid.institution = 'Geoscience Australia' |
---|
55 | fid.description = 'Input wave for Benchmark 2' |
---|
56 | fid.starttime = 0.0 |
---|
57 | fid.createDimension('number_of_timesteps', len(T)) |
---|
58 | fid.createVariable('time', Float, ('number_of_timesteps',)) |
---|
59 | fid.variables['time'][:] = T |
---|
60 | |
---|
61 | fid.createVariable('stage', Float, ('number_of_timesteps',)) |
---|
62 | fid.variables['stage'][:] = Q[:] |
---|
63 | |
---|
64 | fid.createVariable('xmomentum', Float, ('number_of_timesteps',)) |
---|
65 | fid.variables['xmomentum'][:] = X[:] |
---|
66 | |
---|
67 | fid.createVariable('ymomentum', Float, ('number_of_timesteps',)) |
---|
68 | fid.variables['ymomentum'][:] = Y[:] |
---|
69 | |
---|
70 | fid.close() |
---|