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

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

moving Honwood files around

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