1 | """Script for running a dam break simulation of UQ's dam break tank. |
---|
2 | |
---|
3 | |
---|
4 | Ole Nielsen and Duncan Gray, GA - 2006 |
---|
5 | """ |
---|
6 | |
---|
7 | |
---|
8 | #---------------------------------------------------------------------------- |
---|
9 | # Import necessary modules |
---|
10 | #---------------------------------------------------------------------------- |
---|
11 | |
---|
12 | # Standard modules |
---|
13 | import time |
---|
14 | import sys |
---|
15 | from shutil import copy |
---|
16 | from os import path |
---|
17 | |
---|
18 | # Related major packages |
---|
19 | from anuga.shallow_water import Domain, Reflective_boundary, \ |
---|
20 | Dirichlet_boundary, Time_boundary, File_boundary |
---|
21 | from anuga.abstract_2d_finite_volumes.region import Set_region |
---|
22 | from anuga.fit_interpolate.interpolate import interpolate_sww2csv, \ |
---|
23 | file_function |
---|
24 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, \ |
---|
25 | copy_code_files |
---|
26 | from anuga.shallow_water.data_manager import csv2dict |
---|
27 | from numerical_tools import err # norm, corr, |
---|
28 | |
---|
29 | # Application specific imports |
---|
30 | import create_mesh |
---|
31 | import project |
---|
32 | def main(): |
---|
33 | |
---|
34 | slope= 0 |
---|
35 | friction = 0.01 |
---|
36 | inital_depth = 0.2 |
---|
37 | gate_position = 0.75 |
---|
38 | |
---|
39 | return scenario(slope, friction, inital_depth, gate_position) |
---|
40 | |
---|
41 | |
---|
42 | def scenario(slope, friction, inital_depth, gate_position): |
---|
43 | |
---|
44 | #------------------------------------------------------------------------- |
---|
45 | # Create the triangular mesh |
---|
46 | #------------------------------------------------------------------------- |
---|
47 | |
---|
48 | create_mesh.generate(project.mesh_filename, |
---|
49 | gate_position, |
---|
50 | #is_course=True) # this creates the mesh |
---|
51 | is_course=False) # this creates the mesh |
---|
52 | |
---|
53 | head,tail = path.split(project.mesh_filename) |
---|
54 | #------------------------------------------------------------------------- |
---|
55 | # Setup computational domain |
---|
56 | #------------------------------------------------------------------------- |
---|
57 | domain = Domain(project.mesh_filename, use_cache = False, verbose = False) |
---|
58 | |
---|
59 | |
---|
60 | |
---|
61 | domain.set_name(project.basename) |
---|
62 | domain.set_datadir('.') |
---|
63 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
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 = csv2dict(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 | #------------------------------------------------------------- |
---|
120 | if __name__ == "__main__": |
---|
121 | main() |
---|
122 | |
---|