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