source: anuga_validation/Hinwood_2008/run_dam.py @ 5689

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

Getting rmsd calc going

File size: 6.7 KB
Line 
1"""
2
3Script for running a breaking wave simulation of Jon Hinwoods wave tank.
4
5Duncan Gray, GA - 2007
6"""
7
8
9#----------------------------------------------------------------------------
10# Import necessary modules
11#----------------------------------------------------------------------------
12
13# Standard modules
14import time
15
16
17# Related major packages
18from anuga.shallow_water import Domain, Reflective_boundary, Time_boundary
19from anuga.fit_interpolate.interpolate import interpolate_sww2csv
20from anuga.abstract_2d_finite_volumes.util import file_function
21from anuga.utilities.interp import interp
22
23# Scenario specific imports
24import create_mesh
25from prepare_time_boundary import csv2tms
26
27
28def main(metadata_dic,
29         maximum_triangle_area,
30         yieldstep,
31         boundary_path=None,
32         friction=0.,  # planed wood 0.012 http://www.lmnoeng.com/manningn.htm
33         outputdir_name=None,
34         isTest=False,
35         width=1.0,
36         use_limits=True,
37         end_tag = ''):
38
39    id = metadata_dic['scenario_id']
40   
41    if isTest is True:
42        yieldstep = 1.0
43        finaltime = 15.
44        maximum_triangle_area=0.1
45        outputdir_name += '_test'         
46    else:
47        finaltime = None
48       
49    outputdir_name = paras2outputdir_tag(mta=maximum_triangle_area,
50                        yieldstep=yieldstep,
51                        width=width,
52                        use_limits=use_limits,
53                        friction=friction,
54                        end_tag=end_tag,
55                        outputdir_name=outputdir_name)
56    basename = outputdir_name   
57    metadata_dic = set_z_origin_to_water_depth(metadata_dic)   
58
59    if finaltime is None:
60        finaltime = metadata_dic['wave_times'][1] + 0.1 
61       
62    boundary_file_path = id + '_boundary.tsm'
63       
64    # Convert the boundary file, .csv to .tsm
65    csv2tms(boundary_file_path, metadata_dic['xleft'][1])
66   
67    mesh_filename =  basename + '.msh'
68
69    #-------------------------------------------------------------------------
70    # Create the triangular mesh
71    #-------------------------------------------------------------------------
72
73    create_mesh.generate(mesh_filename, metadata_dic, width=width,
74                         maximum_triangle_area=maximum_triangle_area)
75   
76    #-------------------------------------------------------------------------
77    # Setup computational domain
78    #-------------------------------------------------------------------------
79    domain = Domain(mesh_filename, use_cache = False, verbose = True) 
80
81    print 'Number of triangles = ', len(domain)
82    print 'The extent is ', domain.get_extent()
83    print domain.statistics()
84   
85    domain.set_name(basename)
86    domain.set_datadir('.')
87    domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
88    domain.set_minimum_storable_height(0.0001)
89
90    if use_limits is True:
91        domain.set_default_order(2) # Use second order spatial scheme
92        domain.set_timestepping_method('rk2')
93        domain.use_edge_limiter = True
94        domain.tight_slope_limiters = True
95       
96        domain.beta_w      = 0.6
97        domain.beta_uh     = 0.6
98        domain.beta_vh     = 0.6
99   
100
101    #-------------------------------------------------------------------------
102    # Setup initial conditions
103    #-------------------------------------------------------------------------
104
105    domain.set_quantity('stage', 0.) #the origin is the still water level
106    domain.set_quantity('friction', friction)
107    elevation_function = Elevation_function(metadata_dic)
108    domain.set_quantity('elevation', elevation_function)
109
110    function = file_function(boundary_file_path, domain, verbose=True)
111       
112    Br = Reflective_boundary(domain)
113    Bts = Time_boundary(domain, function)
114    domain.set_boundary( {'wall': Br, 'wave': Bts} )
115
116    #-------------------------------------------------------------------------
117    # Evolve system through time
118    #-------------------------------------------------------------------------
119    t0 = time.time()
120
121    for t in domain.evolve(yieldstep, finaltime):   
122        domain.write_time()
123    print 'That took %.2f seconds' %(time.time()-t0)
124    print 'finished'
125
126
127    #-------------------------------------------------------------------------
128    # Calculate gauge info
129    #-------------------------------------------------------------------------
130
131    if isTest is not True:
132        points = []
133        for gauge_x in metadata_dic['gauge_x']:
134            points.append([gauge_x, 0.0])
135
136        id =  ".csv"
137        interpolate_sww2csv(basename +".sww",
138                            points,
139                            basename + "_depth" + id,
140                            basename + "_velocity_x" + id,
141                            basename + "_velocity_y" + id,
142                            basename + "_stage" + id)
143 
144
145def paras2outputdir_tag(mta,
146                        yieldstep,
147                        width,
148                        use_limits,
149                        friction,
150                        end_tag,
151                        outputdir_name=None):
152    """
153   
154    """
155    if outputdir_name is None:
156        outputdir_name = ''
157       
158    if use_limits is True:
159        outputdir_name += '_lmts'
160    else:
161        outputdir_name += '_nolmts'
162    outputdir_name += '_wdth_' + str(width)
163    outputdir_name += '_z_' + str(friction)
164    outputdir_name += '_ys_' + str(yieldstep)
165    outputdir_name += '_mta_' + str(mta)
166    outputdir_name += end_tag
167
168    return outputdir_name
169
170
171class Elevation_function:
172    """
173    """
174    def __init__(self, slope):
175        self.xslope_position = [slope['xleft'][0],slope['xtoe'][0],
176                  slope['xbeach'][0],slope['xright'][0]]
177        self.yslope_height = [slope['xleft'][1],slope['xtoe'][1],
178                  slope['xbeach'][1],slope['xright'][1]]
179       
180    def __call__(self, x,y):       
181        z = interp(self.yslope_height, self.xslope_position, x)
182        return z
183   
184def set_z_origin_to_water_depth(metadata_dic):
185    """
186    """
187    offset = metadata_dic['offshore_water_depth']
188    keys = ['xleft', 'xtoe', 'xbeach', 'xright']
189    for x in keys:
190            metadata_dic[x][1] -= offset
191    return metadata_dic
192
193#-------------------------------------------------------------
194if __name__ == "__main__":
195   
196    from scenarios import scenarios
197
198    #scenarios = [scenarios[0]]
199   
200    width = 0.1
201    maximum_triangle_area=0.01
202    yieldstep = 0.01
203    #yieldstep = 0.5
204    friction=0.0
205    isTest=True
206    isTest=False
207   
208    for run_data in scenarios:
209        main(run_data,
210             maximum_triangle_area=maximum_triangle_area,
211             yieldstep=yieldstep,
212             width=width,
213             isTest=isTest,
214             outputdir_name=run_data['scenario_id'],
215             use_limits=False,
216             friction=friction,
217             end_tag='')
Note: See TracBrowser for help on using the repository browser.