source: anuga_validation/automated_validation_tests/UQ_runup_2006/run_dam.py @ 7774

Last change on this file since 7774 was 7774, checked in by hudson, 12 years ago

Validation tests use new API.

File size: 4.3 KB
Line 
1"""Script for running a dam break simulation of UQ's dam break tank.
2
3
4Ole Nielsen and Duncan Gray, GA - 2006
5"""
6
7
8#----------------------------------------------------------------------------
9# Import necessary modules
10#----------------------------------------------------------------------------
11
12# Standard modules
13import time
14import sys
15from shutil import copy
16from os import path
17
18# Related major packages
19from anuga.shallow_water import Domain, Reflective_boundary, \
20     Dirichlet_boundary, Time_boundary, File_boundary
21from anuga.abstract_2d_finite_volumes.region import Set_region
22from anuga.fit_interpolate.interpolate import interpolate_sww2csv, \
23     file_function
24from anuga.utilities.file_utils import copy_code_files
25from anuga.file.csv_file import load_csv_as_dict
26from numerical_tools import  err 
27
28# Application specific imports
29import create_mesh
30import project
31
32def main():     
33    slope= 0
34    friction = 0.01 
35    inital_depth = 0.2
36    gate_position = 0.75
37   
38    return scenario(slope, friction, inital_depth, gate_position)
39           
40
41def scenario(slope, friction, inital_depth, gate_position):
42
43    #-------------------------------------------------------------------------
44    # Create the triangular mesh
45    #-------------------------------------------------------------------------
46
47    create_mesh.generate(project.mesh_filename,
48                         gate_position,
49                         #is_course=True) # this creates the mesh
50                         is_course=False) # this creates the mesh
51
52    head,tail = path.split(project.mesh_filename)
53   
54    #-------------------------------------------------------------------------
55    # Setup computational domain
56    #-------------------------------------------------------------------------
57    domain = Domain(project.mesh_filename, use_cache = False, verbose = False)
58    domain.set_name(project.basename)
59    domain.set_datadir('.')
60    domain.set_quantities_to_be_stored({'stage':2,
61                                        'xmomentum': 2,
62                                        'ymomentum': 2,
63                                        'elevation': 1})
64    domain.set_minimum_storable_height(0.001)
65    domain.set_store_vertices_uniquely(True)  # for writting to sww
66
67    #-------------------------------------------------------------------------
68    # Setup initial conditions
69    #-------------------------------------------------------------------------
70
71
72    def elevation_tilt(x, y):
73        return x*slope
74       
75    domain.set_quantity('stage', elevation_tilt)
76    domain.set_quantity('friction', friction) 
77    domain.set_quantity('elevation',elevation_tilt)
78
79    domain.set_region('dam','stage',inital_depth,
80                                 location = 'unique vertices') 
81
82    Br = Reflective_boundary(domain)
83    Bd = Dirichlet_boundary([0,0,0])  # to drain the water out.
84    domain.set_boundary( {'wall': Br, 'edge': Bd} )
85
86    #-------------------------------------------------------------------------
87    # Evolve system through time
88    #-------------------------------------------------------------------------
89    t0 = time.time()
90
91    for t in domain.evolve(yieldstep = 0.1, finaltime = 10):
92        pass
93
94    # Load actual experimental results
95    actual,title_index_dic = load_csv_as_dict(project.actual_filename)
96   
97    gauge_locations = [[0.4,0.2]]
98    quantities = ['stage', 'elevation']
99    file_instance = file_function( project.basename +".sww",
100                                      quantities = quantities,
101                                      interpolation_points = gauge_locations,
102                                      verbose = False,
103                                      use_cache = False)
104    # create a list of the simulated_depths at the actual data times.
105    simulated_depths = []
106    for atime in actual['time']:
107        quantities_slice = file_instance(float(atime),
108                                         point_id=0)
109        depth = quantities_slice[0] - quantities_slice[1]
110        simulated_depths.append(depth)
111    flume_depths = actual["0.4:0.2"]
112    flume_depths = [float(i) for i in flume_depths]
113    # calc the norm
114    #print "map(None, simulated_depths, flume_depths)", \
115    #      map(None, simulated_depths, flume_depths)
116    norm = err(simulated_depths,
117               flume_depths, 2, relative = True)  # 2nd norm (rel. RMS
118    return norm
119#-------------------------------------------------------------
120if __name__ == "__main__":
121    main()
122   
Note: See TracBrowser for help on using the repository browser.