source: anuga_work/development/Hinwood_2008/prepare_time_boundary.py @ 5076

Last change on this file since 5076 was 5076, checked in by duncan, 16 years ago

Adding draft flume tank in preparation to see Hinwood

File size: 2.1 KB
Line 
1"""
2
3Script for running a breaking wave simulation of Jon Hinwoods wave tank.
4Note: this is based on the frinction_ua_flume_2006 structure.
5
6
7Duncan Gray, GA - 2007
8
9
10
11"""
12
13
14#----------------------------------------------------------------------------
15# Import necessary modules
16#----------------------------------------------------------------------------
17
18from Scientific.IO.NetCDF import NetCDFFile
19from Numeric import array, zeros, Float
20
21from project import boundary_file
22
23def prepare_timeboundary(filename):
24    """Convert benchmark 2 time series to NetCDF tms file.
25    This is a 'throw-away' code taylor made for files like
26    'Benchmark_2_input.txt' from the LWRU2 benchmark
27    """
28
29
30
31    print 'Creating', filename
32
33    # Read the ascii (.csv) version of this file
34    fid = open(filename[:-4] + '.csv')
35
36    # Skip first line
37    line = fid.readline()
38
39    # Read remaining lines
40    lines = fid.readlines()
41    fid.close()
42
43
44    N = len(lines)
45    T = zeros(N, Float)  #Time
46    Q = zeros(N, Float)  #Stage
47    X = zeros(N, Float)  #XMomentum
48    Y = zeros(N, Float)  #YMomentum
49
50    for i, line in enumerate(lines):
51        fields = line.split(',')
52
53        T[i] = float(fields[0])
54        Q[i] = depth = float(fields[1])
55        X[i] = float(fields[2]) * depth
56        Y[i] = float(fields[3]) * depth
57
58
59    # Create tms NetCDF file
60
61    fid = NetCDFFile(filename, 'w')
62    fid.institution = 'Geoscience Australia'
63    fid.description = 'Input wave for Benchmark 2'
64    fid.starttime = 0.0
65    fid.createDimension('number_of_timesteps', len(T))
66    fid.createVariable('time', Float, ('number_of_timesteps',))
67    fid.variables['time'][:] = T
68
69    fid.createVariable('stage', Float, ('number_of_timesteps',))
70    fid.variables['stage'][:] = Q[:]
71
72    fid.createVariable('xmomentum', Float, ('number_of_timesteps',))
73    fid.variables['xmomentum'][:] =  X[:]
74
75    fid.createVariable('ymomentum', Float, ('number_of_timesteps',))
76    fid.variables['ymomentum'][:] =  Y[:]
77
78    fid.close()
79
80#-------------------------------------------------------------
81if __name__ == "__main__":
82    prepare_timeboundary(boundary_file)
Note: See TracBrowser for help on using the repository browser.