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