source: anuga_work/development/Hinwood_2008/run_dam.py @ 5350

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

Checking in Hinwood work

File size: 6.9 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
18# Standard modules
19import time
20from time import localtime, strftime
21import sys
22from shutil import copy
23from os import path, sep
24from os.path import dirname  #, basename
25
26
27# Related major packages
28from anuga.shallow_water import Domain, Reflective_boundary, \
29                            Dirichlet_boundary,  Time_boundary, \
30                            File_boundary, \
31                            Transmissive_Momentum_Set_Stage_boundary
32from anuga.fit_interpolate.interpolate import interpolate_sww2csv
33from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, \
34     copy_code_files, file_function
35from anuga.abstract_2d_finite_volumes.generic_boundary_conditions\
36     import File_boundary_time
37
38# Scenario specific imports
39import project                 # Definition of file names and polygons
40import create_mesh
41from prepare_time_boundary import prepare_time_boundary
42
43
44
45def elevation_function(x,y):
46    from Numeric import zeros, size, Float
47
48    xslope = create_mesh.xslope  #4 ## Bit of a magic Number
49    print "xslope",xslope
50    z = zeros(size(x), Float)
51    for i in range(len(x)):
52        if x[i] < xslope:
53            z[i] = 0.0  #WARNING: the code in prepare_time_boundary
54                        # that calc's momentum assumes this is 0.0
55        else:
56            z[i] = (x[i]-xslope)*(1./16.)
57    return z
58
59def main(friction=0.01, outputdir_name=None, is_trial_run=False):
60
61   
62    basename = 'zz' + str(friction)
63    if is_trial_run is True:
64        outputdir_name += '_test'
65        yieldstep = 0.1
66        finaltime = 15.
67        maximum_triangle_area=0.01
68    else:
69        yieldstep = 0.02
70        finaltime = 15.1
71        maximum_triangle_area=0.0001
72       
73        maximum_triangle_area=0.001
74       
75    pro_instance = project.Project(['data','flumes','Hinwood_2008'],
76                                   outputdir_name=outputdir_name)
77    print "The output dir is", pro_instance.outputdir
78    copy_code_files(pro_instance.outputdir,__file__,
79                    dirname(project.__file__) \
80                    + sep + project.__name__+'.py')
81    copy (pro_instance.codedir + 'run_dam.py',
82          pro_instance.outputdir + 'run_dam.py')
83    copy (pro_instance.codedir + 'create_mesh.py',
84          pro_instance.outputdir + 'create_mesh.py')
85
86   
87    # Convert the boundary file, .csv to .tsm
88    try:
89        temp = open(pro_instance.boundary_file)
90        temp.close()
91    except IOError:
92        prepare_time_boundary(pro_instance.boundary_file)
93   
94    mesh_filename = pro_instance.meshdir + basename + '.msh'
95
96    #--------------------------------------------------------------------------
97    # Copy scripts to output directory and capture screen
98    # output to file
99    #--------------------------------------------------------------------------
100
101    # creates copy of code in output dir
102    if is_trial_run is False:
103        start_screen_catcher(pro_instance.outputdir, rank, pypar.size())
104
105    print 'USER:    ', pro_instance.user
106    #-------------------------------------------------------------------------
107    # Create the triangular mesh
108    #-------------------------------------------------------------------------
109
110    # this creates the mesh
111    #gate_position = 12.0
112    create_mesh.generate(mesh_filename,
113                         maximum_triangle_area=maximum_triangle_area)
114
115    head,tail = path.split(mesh_filename)
116    copy (mesh_filename,
117          pro_instance.outputdir + tail )
118    #-------------------------------------------------------------------------
119    # Setup computational domain
120    #-------------------------------------------------------------------------
121    domain = Domain(mesh_filename, use_cache = False, verbose = True)
122   
123
124    print 'Number of triangles = ', len(domain)
125    print 'The extent is ', domain.get_extent()
126    print domain.statistics()
127
128   
129    domain.set_name(basename)
130    domain.set_datadir(pro_instance.outputdir)
131    domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
132    domain.set_minimum_storable_height(0.001)
133    #domain.set_store_vertices_uniquely(True)  # for writting to sww
134
135    #-------------------------------------------------------------------------
136    # Setup initial conditions
137    #-------------------------------------------------------------------------
138
139    domain.set_quantity('stage', 0.4)
140    domain.set_quantity('friction', friction) 
141    domain.set_quantity('elevation', elevation_function)
142
143   
144    print 'Available boundary tags', domain.get_boundary_tags()
145
146    # Create boundary function from timeseries provided in file
147    #function = file_function(project.boundary_file, domain, verbose=True)
148    #Bts = Transmissive_Momentum_Set_Stage_boundary(domain, function)
149    try:
150        function = file_function(pro_instance.boundary_file, domain,
151                                 verbose=True)
152    except IOError:
153        msg = 'Run prepare_time_boundary.py. File "%s" could not be opened.'\
154                  %(pro_instance.boundary_file)
155        raise msg
156       
157    Br = Reflective_boundary(domain)
158    #Bd = Dirichlet_boundary([0.3,0,0])
159    Bts = Time_boundary(domain, function)
160    domain.set_boundary( {'wall': Br, 'wave': Bts} )
161
162    #-------------------------------------------------------------------------
163    # Evolve system through time
164    #-------------------------------------------------------------------------
165    t0 = time.time()
166
167    for t in domain.evolve(yieldstep, finaltime):   
168        domain.write_time()
169    print 'That took %.2f seconds' %(time.time()-t0)
170    print 'finished'
171
172    flume_y_middle = 0.225
173    points = [[2.8,flume_y_middle],  #-1.8m from SWL
174              [5.1,flume_y_middle],  #0.5m from SWL
175              [6.6,flume_y_middle],  #2m from SWL
176              [6.95,flume_y_middle], #2.35m from SWL
177              [7.6,flume_y_middle],  #3m from SWL
178              [8.2,flume_y_middle],  #3.5m from SWL
179              [9.2,flume_y_middle]  #4.5m from SWL
180              ]
181
182
183    #-------------------------------------------------------------------------
184    # Calculate gauge info
185    #-------------------------------------------------------------------------
186
187    if True:
188        interpolate_sww2csv(pro_instance.outputdir + basename +".sww",
189                            points,
190                            pro_instance.outputdir + "depth_manning_"+str(friction)+".csv",
191                            pro_instance.outputdir + "velocity_x.csv",
192                            pro_instance.outputdir + "velocity_y.csv")
193 
194    return pro_instance
195
196#-------------------------------------------------------------
197if __name__ == "__main__":
198    main( is_trial_run = True,
199         outputdir_name='Hinwood_low_stage_low_velocity_draft')
Note: See TracBrowser for help on using the repository browser.