1 | """ |
---|
2 | |
---|
3 | Script for running a breaking wave simulation of Jon Hinwoods wave tank. |
---|
4 | Note: this is based on the frinction_ua_flume_2006 structure. |
---|
5 | |
---|
6 | |
---|
7 | Duncan Gray, GA - 2007 |
---|
8 | |
---|
9 | |
---|
10 | |
---|
11 | """ |
---|
12 | |
---|
13 | |
---|
14 | #---------------------------------------------------------------------------- |
---|
15 | # Import necessary modules |
---|
16 | #---------------------------------------------------------------------------- |
---|
17 | |
---|
18 | from Scientific.IO.NetCDF import NetCDFFile |
---|
19 | from Numeric import array, zeros, Float |
---|
20 | |
---|
21 | from project import boundary_file |
---|
22 | |
---|
23 | def 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 | #------------------------------------------------------------- |
---|
81 | if __name__ == "__main__": |
---|
82 | prepare_timeboundary(boundary_file) |
---|