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

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

Current Hinwood scenario calculating RMSD's

File size: 10.6 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, join  #, basename
25from Numeric import zeros, size, Float
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      file_function
35from anuga.shallow_water.data_manager import copy_code_files
36from anuga.abstract_2d_finite_volumes.generic_boundary_conditions\
37     import File_boundary_time
38
39# Scenario specific imports
40import project                 # Definition of file names and polygons
41import create_mesh
42from prepare_time_boundary import prepare_time_boundary
43from interp import interp
44
45
46class Elevation_function:
47    def __init__(self, slope):
48        self.xslope_position = [slope['xleft'][0],slope['xtoe'][0],
49                  slope['xbeach'][0],slope['xright'][0]]
50        self.yslope_height = [slope['xleft'][1],slope['xtoe'][1],
51                  slope['xbeach'][1],slope['xright'][1]]
52       
53    def __call__(self, x,y):
54       
55        z = interp(self.yslope_height, self.xslope_position, x)
56        return z
57
58def main(boundary_file,
59         metadata_dic,
60         boundary_path=None,
61         friction=0.012,  # planed wood. http://www.lmnoeng.com/manningn.htm
62         outputdir_name=None,
63         run_type=0,
64         width=1.0,
65         use_limits=True,
66         end_tag = '_limiterD'):
67
68   
69    basename = 'zz_' + metadata_dic['scenario_id']
70   
71    if run_type == 1:
72        yieldstep = 1.0
73        finaltime = 15.
74        maximum_triangle_area=0.1
75        outputdir_name += '_test'
76       
77    elif run_type == 2:
78        yieldstep = 0.5
79        finaltime = None
80        maximum_triangle_area=0.01
81        outputdir_name += '_test_long_time'
82       
83    elif run_type == 3:
84        yieldstep = 0.1
85        finaltime = None       
86        maximum_triangle_area=0.01
87        #outputdir_name += '_yieldstep_0.1'
88       
89    elif run_type == 4:
90        # this is not a test
91        # Output will go to a file
92        # The sww file will be interpolated
93        yieldstep = 0.01
94        finaltime = None       
95        maximum_triangle_area=0.01
96        #outputdir_name += '_good'
97       
98    elif run_type == 5:
99        # this is not a test
100        # Output will go to a file
101        # The sww file will be interpolated
102        yieldstep = 0.01
103        finaltime = None       
104        maximum_triangle_area=0.001
105        #outputdir_name += '_good'
106       
107    elif run_type == 6:
108        # this is not a test
109        # Output will go to a file
110        # The sww file will be interpolated
111        yieldstep = 0.01
112        finaltime = None       
113        maximum_triangle_area=0.0001
114        #outputdir_name += '_good'
115       
116    if use_limits is True:
117        outputdir_name += '_lmts'
118    else:
119        outputdir_name += '_nolmts'
120    outputdir_name += '_wdth_' + str(width)
121    outputdir_name += '_z_' + str(friction)
122    outputdir_name += '_ys_' + str(yieldstep)
123    outputdir_name += '_mta_' + str(maximum_triangle_area)
124    outputdir_name += end_tag
125   
126    metadata_dic = set_z_origin_to_water_depth(metadata_dic)   
127       
128    pro_instance = project.Project(['data','flumes','Hinwood_2008'],
129                                   outputdir_name=outputdir_name)
130    print "The output dir is", pro_instance.outputdir
131    copy_code_files(pro_instance.outputdir,__file__,
132                    dirname(project.__file__) \
133                    + sep + project.__name__+'.py')
134    copy (pro_instance.codedir + 'run_dam.py',
135          pro_instance.outputdir + 'run_dam.py')
136    copy (pro_instance.codedir + 'create_mesh.py',
137          pro_instance.outputdir + 'create_mesh.py')
138
139    boundary_final_time = prepare_time_boundary(metadata_dic,
140                                       pro_instance.raw_data_dir,
141                                       pro_instance.boundarydir)
142    #return pro_instance
143    if finaltime is None:
144        finaltime = boundary_final_time - 0.1 # Edge boundary problems
145    # Boundary file manipulation
146    if boundary_path is None:
147        boundary_path = pro_instance.boundarydir
148    boundary_file_path = join(boundary_path, boundary_file)
149   #  # Convert the boundary file, .csv to .tsm
150#     try:
151#         temp = open(boundary_file_path)
152#         temp.close()
153#     except IOError:
154#         prepare_time_boundary(boundary_file_path)
155   
156    mesh_filename = pro_instance.meshdir + basename + '.msh'
157
158    #--------------------------------------------------------------------------
159    # Copy scripts to output directory and capture screen
160    # output to file
161    #--------------------------------------------------------------------------
162
163    # creates copy of code in output dir
164    if run_type >= 2:
165        #start_screen_catcher(pro_instance.outputdir, rank, pypar.size())
166        start_screen_catcher(pro_instance.outputdir)
167
168    print 'USER:    ', pro_instance.user
169    #-------------------------------------------------------------------------
170    # Create the triangular mesh
171    #-------------------------------------------------------------------------
172
173    # this creates the mesh
174    #gate_position = 12.0
175    create_mesh.generate(mesh_filename, metadata_dic, width=width,
176                         maximum_triangle_area=maximum_triangle_area)
177
178    head,tail = path.split(mesh_filename)
179    copy (mesh_filename,
180          pro_instance.outputdir + tail )
181    #-------------------------------------------------------------------------
182    # Setup computational domain
183    #-------------------------------------------------------------------------
184    domain = Domain(mesh_filename, use_cache = False, verbose = True)
185   
186
187    print 'Number of triangles = ', len(domain)
188    print 'The extent is ', domain.get_extent()
189    print domain.statistics()
190
191   
192    domain.set_name(basename)
193    domain.set_datadir(pro_instance.outputdir)
194    domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
195    domain.set_minimum_storable_height(0.0001)
196
197    if use_limits is True:
198        domain.set_default_order(2) # Use second order spatial scheme
199        domain.set_timestepping_method('rk2')
200        domain.use_edge_limiter = True
201        domain.tight_slope_limiters = True
202       
203        domain.beta_w      = 0.6
204        domain.beta_uh     = 0.6
205        domain.beta_vh     = 0.6
206   
207
208    #-------------------------------------------------------------------------
209    # Setup initial conditions
210    #-------------------------------------------------------------------------
211
212    domain.set_quantity('stage', 0.) #the origin is the still water level
213    domain.set_quantity('friction', friction)
214    elevation_function = Elevation_function(metadata_dic)
215    domain.set_quantity('elevation', elevation_function)
216
217   
218    print 'Available boundary tags', domain.get_boundary_tags()
219
220    # Create boundary function from timeseries provided in file
221    #function = file_function(project.boundary_file, domain, verbose=True)
222    #Bts = Transmissive_Momentum_Set_Stage_boundary(domain, function)
223    try:
224        function = file_function(boundary_file_path, domain,
225                                 verbose=True)
226    except IOError:
227        msg = 'Run prepare_time_boundary.py. File "%s" could not be opened.'\
228                  %(pro_instance.boundary_file)
229        raise msg
230       
231    Br = Reflective_boundary(domain)
232    Bd = Dirichlet_boundary([0.3,0,0]) 
233    Bts = Time_boundary(domain, function)
234    domain.set_boundary( {'wall': Br, 'wave': Bts} )
235    #domain.set_boundary( {'wall': Br, 'wave': Bd} )
236
237    #-------------------------------------------------------------------------
238    # Evolve system through time
239    #-------------------------------------------------------------------------
240    t0 = time.time()
241
242    # It seems that ANUGA can't handle a starttime that is >0.
243    #domain.starttime = 1.0 #!!! what was this doing?
244    for t in domain.evolve(yieldstep, finaltime):   
245        domain.write_time()
246    print 'That took %.2f seconds' %(time.time()-t0)
247    print 'finished'
248
249    flume_y_middle = 0.0
250    points = []
251    for gauge_x in metadata_dic['gauge_x']:
252        points.append([gauge_x, flume_y_middle])
253    print "points",points
254
255
256    #-------------------------------------------------------------------------
257    # Calculate gauge info
258    #-------------------------------------------------------------------------
259
260    if run_type >= 1:
261        id = metadata_dic['scenario_id'] + ".csv"
262        interpolate_sww2csv(pro_instance.outputdir + basename +".sww",
263                            points,
264                            pro_instance.outputdir + "depth_" + id,
265                            pro_instance.outputdir + "velocity_x_" + id,
266                            pro_instance.outputdir + "velocity_y_" + id,
267                            pro_instance.outputdir + "stage_" + id,
268                            pro_instance.outputdir + "froude_" + id)
269 
270    return pro_instance
271
272def set_z_origin_to_water_depth(seabed_coords):
273    offset = seabed_coords['offshore_water_depth']
274    keys = ['xleft', 'xtoe', 'xbeach', 'xright']
275    for x in keys:
276            seabed_coords[x][1] -= offset
277    return seabed_coords
278#-------------------------------------------------------------
279if __name__ == "__main__":
280   
281    from scenarios import scenarios
282    from slope import gauges_for_slope
283    #from plot import plot
284
285    # 1 is fast and dirty
286    # 4 is 0.01
287    # 5 is 0.001
288    # 6 is 0.0001
289   
290    #run_type = 1
291    run_type = 5
292    #for run_data in [scenarios[5]]:
293    #scenarios = scenarios[2:]
294    #scenarios = [scenarios[0]]
295    width = 1.0
296    width = 0.1
297    for run_data in scenarios:
298        pro_instance = main( run_data['scenario_id'] + '_boundary.tsm'  ,
299                             run_data,
300                             width=width,
301                             run_type=run_type,
302                             outputdir_name=run_data['scenario_id'],
303                             use_limits=False,
304                             friction=0.012, 
305                             end_tag='_G')
306        #gauges_for_slope(pro_instance.outputdir,[run_data])
Note: See TracBrowser for help on using the repository browser.