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 | #------------------------------------------------------------------------------ |
---|
24 | # Setup computational domain |
---|
25 | #------------------------------------------------------------------------------ |
---|
26 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
27 | |
---|
28 | name ='steep_smflat_topography' |
---|
29 | wave = [1, -1] #1 returns leading depression N-wave |
---|
30 | #-1 returns leading crest N-wave |
---|
31 | crest =[50, 250, 450, 650] |
---|
32 | crestdepth = [1, 0, -1, -3, -5] |
---|
33 | N = len (crest) |
---|
34 | for i in range(N): |
---|
35 | M = len (crestdepth) |
---|
36 | for k in range (M): |
---|
37 | B = len(wave) |
---|
38 | for l in range(B): |
---|
39 | length = (crest[i]+1000) |
---|
40 | width = 20. |
---|
41 | A = 1 |
---|
42 | T = 2700 |
---|
43 | umask(002) |
---|
44 | time = strftime('%Y%m%d_%H%M%S',gmtime()) |
---|
45 | |
---|
46 | output_dir = sep+'d'+sep+'xrd'+sep+'gem'+sep+'5'+sep+'nhi'+sep+'inundation'+sep+'data'+sep+'idealised_bathymetry_study'+sep+'final_models'+sep+'topography'+sep+str(wave[l])+'_'+str(length)+'_'+str(A)+'_'+str(T)+'_'+str(crestdepth[k])+str(name)+sep |
---|
47 | sww_file = str(name) |
---|
48 | copy_code_files(output_dir,__file__,__file__) |
---|
49 | |
---|
50 | start_screen_catcher(output_dir) |
---|
51 | dx = dy = .5 # Resolution: Length of subdivisions on both axes |
---|
52 | boundary_polygon = [[0,0],[length,0],[length,width],[0,width]] |
---|
53 | interior_polygon = [[140,0],[780+crest[i],0],[780+crest[i],20],[140,20]] |
---|
54 | interior_polygon2 =[[790+crest[i],0],[999+crest[i],0],[999+crest[i],20],[790+crest[i],20]] |
---|
55 | interior_regions = [[interior_polygon, 8], [interior_polygon2, 50]] |
---|
56 | meshname = str(name)+'.msh' |
---|
57 | create_mesh_from_regions(boundary_polygon, |
---|
58 | boundary_tags={'bottom': [0], |
---|
59 | 'right': [1], |
---|
60 | 'top': [2], |
---|
61 | 'left': [3]}, |
---|
62 | maximum_triangle_area=50, |
---|
63 | filename=meshname, |
---|
64 | interior_regions=interior_regions, |
---|
65 | use_cache=False, |
---|
66 | verbose=False) |
---|
67 | |
---|
68 | domain = Domain(meshname, use_cache=False, verbose=True) |
---|
69 | |
---|
70 | print 'Number of triangles = ', len(domain) |
---|
71 | print 'The extent is ', domain.get_extent() |
---|
72 | print domain.statistics() |
---|
73 | |
---|
74 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
75 | domain.set_minimum_storable_height(0.01) |
---|
76 | domain.set_default_order(2) # Second order spatial approximation |
---|
77 | domain.set_name(sww_file)# Output name |
---|
78 | domain.set_datadir(output_dir) |
---|
79 | |
---|
80 | |
---|
81 | #------------------------------------------------------------------------------ |
---|
82 | # Setup initial conditions |
---|
83 | #------------------------------------------------------------------------------ |
---|
84 | |
---|
85 | def topography(x,y): |
---|
86 | """Complex topography defined by a function of vectors x and y |
---|
87 | """ |
---|
88 | |
---|
89 | z =(-0.84*x)+(0.84*(720+crest[i]))+crestdepth[k]-4 |
---|
90 | N = len (x) |
---|
91 | for j in range(N): |
---|
92 | |
---|
93 | if x[j] < 180: |
---|
94 | z[j] = -4+crestdepth[k] |
---|
95 | |
---|
96 | elif 179 < x[j] < 200: |
---|
97 | z[j] = 0.2*x[j]-40+crestdepth[k] |
---|
98 | #Reef Flat |
---|
99 | elif 199 < x[j] < 700: |
---|
100 | z[j] = -0.5+crestdepth[k] |
---|
101 | ##Crest |
---|
102 | elif 699 < x[j] < (700+crest[i]): |
---|
103 | z[j] = +crestdepth[k] |
---|
104 | |
---|
105 | #Curve down |
---|
106 | elif (699+crest[i]) < x[j] < (720+crest[i]): |
---|
107 | z[j] = -0.01*(x[j]-(699+crest[i]))*(x[j]-(699+crest[i]))+crestdepth[k] |
---|
108 | |
---|
109 | return z |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
114 | ## domain.set_quantity('friction', 0) # Constant friction |
---|
115 | domain.set_quantity('friction', Polygon_function( [(boundary_polygon, 0.05),(interior_polygon ,0.2), (interior_polygon2 , 0.05)] ) )#changing friction over two polygons |
---|
116 | domain.set_quantity('stage', 0.) # Constant negative initial stage |
---|
117 | |
---|
118 | |
---|
119 | #------------------------------------------------------------------------------ |
---|
120 | # Setup boundary conditions |
---|
121 | #------------------------------------------------------------------------------ |
---|
122 | |
---|
123 | from math import sin, pi, exp, cos, cosh, sqrt |
---|
124 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
125 | Bt = Transmissive_boundary(domain) # Continue all values on boundary |
---|
126 | Bd = Dirichlet_boundary([0.,0.,0.]) # Constant boundary values |
---|
127 | Bw = Time_boundary(domain=domain, # Time dependent boundary |
---|
128 | f=lambda t: [sin(2*pi*(t)/1010), -37, 0.0]) |
---|
129 | g = 9.81 |
---|
130 | offshore_depth = 250 |
---|
131 | H_d_ratio = 0.008 |
---|
132 | Xo = 67000 |
---|
133 | po = 0.03 |
---|
134 | def waveform(t): |
---|
135 | 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)) |
---|
136 | Bf = Transmissive_Momentum_Set_Stage_boundary(domain, waveform) |
---|
137 | # Associate boundary tags with boundary objects |
---|
138 | domain.set_boundary({'left': Bd, 'right': Bf, 'top': Br, 'bottom': Br}) |
---|
139 | |
---|
140 | |
---|
141 | #------------------------------------------------------------------------------ |
---|
142 | # Evolve system through time |
---|
143 | #------------------------------------------------------------------------------ |
---|
144 | |
---|
145 | for t in domain.evolve(yieldstep = 5 , finaltime = 4500): |
---|
146 | domain.write_time() |
---|
147 | |
---|
148 | """ |
---|
149 | Generate time series of nominated "gauges" |
---|
150 | Note, this script will only work if pylab is installed on the platform |
---|
151 | |
---|
152 | Inputs: |
---|
153 | |
---|
154 | production dirs: dictionary of production directories with a |
---|
155 | association to that simulation run, eg high tide, |
---|
156 | magnitude, etc. |
---|
157 | |
---|
158 | Outputs: |
---|
159 | |
---|
160 | * figures stored in same directory as sww file |
---|
161 | * time series data stored in csv files in same directory as sww file |
---|
162 | * elevation at nominated gauges (elev_output) |
---|
163 | """ |
---|
164 | |
---|
165 | from os import getcwd, sep, altsep, mkdir, access, F_OK, remove |
---|
166 | from anuga.abstract_2d_finite_volumes.util import sww2timeseries |
---|
167 | |
---|
168 | # nominate directory location of sww file with associated attribute |
---|
169 | production_dirs = {output_dir: str(name)} |
---|
170 | |
---|
171 | # Generate figures |
---|
172 | swwfiles = {} |
---|
173 | for label_id in production_dirs.keys(): |
---|
174 | file_loc = label_id |
---|
175 | swwfile = file_loc + str(name)+'.sww' |
---|
176 | swwfiles[swwfile] = label_id |
---|
177 | print 'hello', swwfile |
---|
178 | texname, elev_output = sww2timeseries(swwfiles, |
---|
179 | sep+'d'+sep+'cit'+sep+'1'+sep+'cit'+sep+'natural_hazard_impacts'+sep+'inundation'+sep+'sandpits'+sep+'jbrowning'+sep+'anuga'+sep+'anuga_work'+sep+'development'+sep+'idealised_bathymetry_study'+sep+'final_models'+sep+'general'+sep+'gauges_smflat.csv', |
---|
180 | production_dirs, |
---|
181 | report = False, |
---|
182 | reportname = '', |
---|
183 | plot_quantity = ['stage', 'speed'], |
---|
184 | generate_fig = False, |
---|
185 | surface = False, |
---|
186 | time_min = None, |
---|
187 | time_max = None, |
---|
188 | #time_unit = 'secs', |
---|
189 | title_on = True, |
---|
190 | verbose = True) |
---|
191 | ## remove(output_dir+sep+str(name)+'.sww') |
---|
192 | |
---|
193 | |
---|