1 | """Simple water flow example using ANUGA |
---|
2 | |
---|
3 | Water driven up a linear slope and time varying boundary, |
---|
4 | similar to a beach environment |
---|
5 | """ |
---|
6 | |
---|
7 | |
---|
8 | #------------------------------------------------------------------------------ |
---|
9 | # Import necessary modules |
---|
10 | #------------------------------------------------------------------------------ |
---|
11 | |
---|
12 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross |
---|
13 | from anuga.shallow_water import Domain |
---|
14 | from anuga.shallow_water import Reflective_boundary |
---|
15 | from anuga.shallow_water import Dirichlet_boundary |
---|
16 | from anuga.shallow_water import Time_boundary |
---|
17 | from anuga.shallow_water import Transmissive_boundary |
---|
18 | from anuga.shallow_water import Transmissive_Momentum_Set_Stage_boundary |
---|
19 | from anuga.shallow_water.data_manager import start_screen_catcher, copy_code_files |
---|
20 | from time import strftime, gmtime |
---|
21 | from os import sep, environ, getenv, getcwd,umask |
---|
22 | from anuga.utilities.polygon import Polygon_function |
---|
23 | from __future__ import division |
---|
24 | #------------------------------------------------------------------------------ |
---|
25 | # Setup computational domain |
---|
26 | #------------------------------------------------------------------------------ |
---|
27 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
28 | |
---|
29 | name = 'linear_slope' |
---|
30 | shelf = [500000] |
---|
31 | slope = [250000] |
---|
32 | wave = [-0.5] #1 returns leading depression N-wave |
---|
33 | #-1 returns leading crest N-wave |
---|
34 | N = len (shelf) |
---|
35 | for i in range(N): |
---|
36 | M = len (slope) |
---|
37 | for k in range (M): |
---|
38 | B = len(wave) |
---|
39 | for l in range(B): |
---|
40 | length = (shelf[i]+slope[k]) |
---|
41 | width = 400. |
---|
42 | A = 1 |
---|
43 | T = 2700 |
---|
44 | umask(002) |
---|
45 | time = strftime('%Y%m%d_%H%M%S',gmtime()) |
---|
46 | ##output_dir = 'C:'+sep+'anuga_data'+sep+'topography'+sep+str(name)+sep+str(name)+'_'+str(wave[l])+'_'+str(shelf[i])+'_'+str(slope[k])+sep |
---|
47 | output_dir = sep+'d'+sep+'sim'+sep+'1'+sep+'mpittard'+sep+'idealised_bathymetry_study'+sep+'topography'+sep+str(name)+sep+str(name)+'_'+str(wave[l])+'_'+str(shelf[i])+'_'+str(slope[k])+sep |
---|
48 | sww_file = str(name) |
---|
49 | copy_code_files(output_dir,__file__,__file__) |
---|
50 | start_screen_catcher(output_dir) |
---|
51 | boundary_polygon = [[0,0],[length,0],[length,width],[0,width]] |
---|
52 | |
---|
53 | meshname = str(name)+'.msh' |
---|
54 | create_mesh_from_regions(boundary_polygon, |
---|
55 | boundary_tags={'bottom': [0], |
---|
56 | 'right': [1], |
---|
57 | 'top': [2], |
---|
58 | 'left': [3]}, |
---|
59 | maximum_triangle_area=20000, |
---|
60 | filename=meshname, |
---|
61 | use_cache=False, |
---|
62 | verbose=False) |
---|
63 | |
---|
64 | domain = Domain(meshname, use_cache=True, verbose=True) |
---|
65 | |
---|
66 | print 'Number of triangles = ', len(domain) |
---|
67 | print 'The extent is ', domain.get_extent() |
---|
68 | print domain.statistics() |
---|
69 | |
---|
70 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
71 | domain.set_minimum_storable_height(0.01) |
---|
72 | domain.set_default_order(2) |
---|
73 | domain.set_name(sww_file)# Output name |
---|
74 | domain.set_datadir(output_dir) |
---|
75 | |
---|
76 | |
---|
77 | #------------------------------------------------------------------------------ |
---|
78 | # Setup initial conditions |
---|
79 | #------------------------------------------------------------------------------ |
---|
80 | |
---|
81 | def topography(x,y): |
---|
82 | """Complex topography defined by a function of vectors x and y |
---|
83 | """ |
---|
84 | o = 2500/(slope[k]*slope[k]/4) |
---|
85 | print str(2500/(slope[k]*slope[k]/4)) |
---|
86 | |
---|
87 | z = o*(x-(shelf[i]+slope[k]))*(x-(shelf[i]+slope[k]))-5125-10 |
---|
88 | S = len (x) |
---|
89 | for j in range(S): |
---|
90 | |
---|
91 | if x[j] < shelf[i]: |
---|
92 | z[j] = -125*x[j]/shelf[i]-10 |
---|
93 | |
---|
94 | elif shelf[i] <= x[j] < (shelf[i]+slope[k]*0.5) : |
---|
95 | z[j] = (-o)*(x[j]-shelf[i])*(x[j]-shelf[i])-125-10 |
---|
96 | |
---|
97 | return z |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
102 | domain.set_quantity('friction', 0) # Constant friction |
---|
103 | domain.set_quantity('stage', 0) # Constant negative initial stage |
---|
104 | domain.tight_slope_limiters = 1 |
---|
105 | domain.beta_h = 0 |
---|
106 | |
---|
107 | #------------------------------------------------------------------------------ |
---|
108 | # Setup boundary conditions |
---|
109 | #------------------------------------------------------------------------------ |
---|
110 | |
---|
111 | from math import sin, pi, exp, cos, sqrt, cosh |
---|
112 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
113 | Bt = Transmissive_boundary(domain) # Continue all values on boundary |
---|
114 | Bd = Dirichlet_boundary([0.,0.,0.]) # Constant boundary values |
---|
115 | |
---|
116 | g = 9.81 |
---|
117 | offshore_depth = 5000 |
---|
118 | H_d_ratio = 0.0004 |
---|
119 | Xo = 299000 |
---|
120 | po = 12 |
---|
121 | def waveform(t): |
---|
122 | return wave[l]*offshore_depth*(sqrt(g/offshore_depth)*t-Xo/offshore_depth)*sqrt(H_d_ratio*po)*H_d_ratio/cosh(sqrt(3*H_d_ratio*po/4)*(sqrt(g/offshore_depth)*t-Xo/offshore_depth))/cosh(sqrt(3*H_d_ratio*po/4)*(sqrt(g/offshore_depth)*t-Xo/offshore_depth)) |
---|
123 | |
---|
124 | Bf = Transmissive_Momentum_Set_Stage_boundary(domain, waveform) |
---|
125 | # Associate boundary tags with boundary objects |
---|
126 | domain.set_boundary({'left': Bd, 'right': Bf, 'top': Br, 'bottom': Br}) |
---|
127 | |
---|
128 | |
---|
129 | #------------------------------------------------------------------------------ |
---|
130 | # Evolve system through time |
---|
131 | #------------------------------------------------------------------------------ |
---|
132 | |
---|
133 | for t in domain.evolve(yieldstep = 45, finaltime = -1000+((length/50000)+1)*600+((shelf[i]/25000+1)*1000)): |
---|
134 | domain.write_time() |
---|
135 | print domain.timestepping_statistics(track_speeds=True) |
---|
136 | for t in domain.evolve(yieldstep = 45, finaltime = 2700+((length/50000)+1)*600+((shelf[i]/25000+1)*1000), |
---|
137 | skip_initial_step = True): |
---|
138 | domain.write_time() |
---|
139 | for t in domain.evolve(yieldstep = 120, finaltime = (length/25)+2700+((length/50000)+1)*600+((shelf[i]/25000+1)*1000), |
---|
140 | skip_initial_step = True): |
---|
141 | domain.write_time() |
---|
142 | |
---|
143 | """ |
---|
144 | Generate time series of nominated "gauges" |
---|
145 | Note, this script will only work if pylab is installed on the platform |
---|
146 | |
---|
147 | Inputs: |
---|
148 | |
---|
149 | production dirs: dictionary of production directories with a |
---|
150 | association to that simulation run, eg high tide, |
---|
151 | magnitude, etc. |
---|
152 | |
---|
153 | Outputs: |
---|
154 | |
---|
155 | * figures stored in same directory as sww file |
---|
156 | * time series data stored in csv files in same directory as sww file |
---|
157 | * elevation at nominated gauges (elev_output) |
---|
158 | """ |
---|
159 | |
---|
160 | from os import getcwd, sep, altsep, mkdir, access, F_OK |
---|
161 | from anuga.abstract_2d_finite_volumes.util import sww2timeseries |
---|
162 | |
---|
163 | # nominate directory location of sww file with associated attribute |
---|
164 | production_dirs = {output_dir: str(name)} |
---|
165 | |
---|
166 | # Generate figures |
---|
167 | swwfiles = {} |
---|
168 | for label_id in production_dirs.keys(): |
---|
169 | file_loc = label_id |
---|
170 | swwfile = file_loc + str(name)+'.sww' |
---|
171 | swwfiles[swwfile] = label_id |
---|
172 | print 'hello', swwfile |
---|
173 | texname, elev_output = sww2timeseries(swwfiles, |
---|
174 | sep+'d'+sep+'sim'+sep+'1'+sep+'mpittard'+sep+'anuga'+sep+'anuga_work'+sep+'development'+sep+'idealised_bathymetry_study'+sep+'continental_shelves'+sep+'gauges.csv', |
---|
175 | production_dirs, |
---|
176 | report = False, |
---|
177 | reportname = '', |
---|
178 | plot_quantity = ['stage', 'speed'], |
---|
179 | generate_fig = False, |
---|
180 | surface = False, |
---|
181 | time_min = None, |
---|
182 | time_max = None, |
---|
183 | #time_unit = 'secs', |
---|
184 | title_on = True, |
---|
185 | verbose = True) |
---|
186 | ## print (output_dir+sep+str(name)+'.sww') |
---|
187 | ## remove(output_dir+sep+str(name)+'.sww') |
---|
188 | |
---|
189 | |
---|