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