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

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

Hinwood - fix for line overrunning graph in anuga report

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