source: trunk/anuga_work/development/uqwave/run_UQwave.py @ 8584

Last change on this file since 8584 was 8584, checked in by gray, 13 years ago

Adding example from Tom B.

File size: 5.5 KB
Line 
1"""Script for running a simulation of UQ's wave flume.
2
3
4Ole Nielsen and Duncan Gray, GA - 2006
5Modified by Matt Barnes 2012
6"""
7
8
9#----------------------------------------------------------------------------
10# Import necessary modules
11#----------------------------------------------------------------------------
12
13# Standard modules
14import time
15import sys
16from shutil import copy
17from os import path
18
19
20
21import anuga
22from anuga.abstract_2d_finite_volumes.region import Set_region 
23from anuga.fit_interpolate.interpolate import interpolate_sww2csv, \
24    file_function
25from anuga.utilities.file_utils import copy_code_files
26from anuga.file.csv_file import load_csv_as_dict
27from numerical_tools import  err
28
29# from anuga.shallow_water.data_manager import timefile2netcdf
30
31# Application specific imports
32import create_mesh
33import project                 # Definition of file names and polygons
34
35
36def main():
37
38    D = 0.2 #initial depth
39    frictions = [0.009]
40   
41    for friction in frictions:
42        scenario(D, friction)
43                       
44def scenario(D, friction):
45
46    import project
47    #-------------------------------------------------------------------------
48    # Setup archiving of simulations
49    #-------------------------------------------------------------------------
50
51    id = 'D_'+str(D)+'f_'+str(friction)
52    copy (project.codedirname, project.outputtimedir + 'project.py')
53    run_name = 'run_dam.py'
54    run_name_out = 'run_dam'+id+'.py'
55   
56    copy (project.codedirname, project.outputtimedir + 'project.py')
57    copy (project.codedir + 'run_UQwave.py', project.outputtimedir + 'run_UQwave.py')
58    copy (project.codedir + 'create_mesh.py',
59          project.outputtimedir + 'create_mesh.py')
60    print'output dir', project.outputtimedir
61
62    #FIXME this isn't working
63    #normal screen output is stored in
64    screen_output_name = project.outputtimedir + "screen_output.txt"
65    screen_error_name = project.outputtimedir + "screen_error.txt"
66
67    #-------------------------------------------------------------------------
68    # Create the triangular mesh
69    #-------------------------------------------------------------------------
70    flume_length = 7.24
71    #flume_length = 3.24
72
73
74    create_mesh.generate(project.mesh_filename,
75                         flume_length,
76                         is_course=True) # this creates the mesh
77                         #is_course=False) # this creates the mesh
78
79    head,tail = path.split(project.mesh_filename)
80    copy (project.mesh_filename,
81          project.outputtimedir + tail )
82    #-------------------------------------------------------------------------
83    # Setup computational domain
84    #-------------------------------------------------------------------------
85    domain = anuga.Domain(project.mesh_filename, use_cache = False, verbose = True)
86   
87
88    print 'Number of triangles = ', len(domain)
89    print 'The extent is ', domain.get_extent()
90    print domain.statistics()
91
92   
93    domain.set_name(project.basename + id)
94    domain.set_datadir(project.outputtimedir)
95    domain.set_quantities_to_be_stored({'stage':2,
96                                        'xmomentum': 2,
97                                        'ymomentum': 2,
98                                        'elevation': 1})
99    domain.set_minimum_storable_height(0.003)
100    domain.set_store_vertices_uniquely(True)  # for writting to sww
101
102    #-------------------------------------------------------------------------
103    # Setup initial conditions
104    #-------------------------------------------------------------------------
105
106    slope = 0.084  #beach slope
107   
108    def elevation_tilt(x, y):
109        return x*slope
110       
111    domain.set_quantity('stage', D)    #water level
112    domain.set_quantity('friction', friction) #bed friction
113    domain.set_quantity('elevation', 0)
114
115    domain.set_region('beach', 'elevation', elevation_tilt)
116                                     
117    print 'Available boundary tags', domain.get_boundary_tags()
118   
119    Br = anuga.Reflective_boundary(domain)
120    Bd = anuga.Dirichlet_boundary([0,0,0])  # to drain the water out.
121
122    #Bore file input
123
124    bore_file = 'bore'
125    #timefile2netcdf(bore_file,
126    #                quantity_names = ['stage','xmomentum', 'ymomentum'])
127    F = anuga.File_boundary(bore_file + '.tms', domain)
128   
129    domain.set_boundary( {'wall': Br, 'back':F} )
130
131    #-------------------------------------------------------------------------
132    # Evolve system through time
133    #-------------------------------------------------------------------------
134    t0 = time.time()
135
136    for t in domain.evolve(yieldstep = 0.02, finaltime = 10): #enter timestep and final time
137        domain.write_time()
138   
139        print 'That took %.2f seconds' %(time.time()-t0)
140        print 'finished'
141
142    points = []
143    for i in range(41):
144        points.append([float(i)/20 + -2.05, 0.425])
145
146    for j in range(120):
147        points.append([float(j)/20, 0.425])
148             
149    #-------------------------------------------------------------------------
150    # Calculate gauge info
151    #-------------------------------------------------------------------------
152    interpolate_sww2csv(project.outputtimedir + project.basename \
153                   + id+".sww",
154                        points,
155                        project.depth_filename + id + '.csv',
156                        project.velocity_x_filename + id + '.csv',
157                        project.velocity_y_filename + id + '.csv')
158    #-------------------------------------------------------------
159if __name__ == "__main__":
160    main()
161   
Note: See TracBrowser for help on using the repository browser.