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