[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 | #------------------------------------------------------------------------------ |
---|
| 24 | # Setup computational domain |
---|
| 25 | #------------------------------------------------------------------------------ |
---|
| 26 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
| 27 | |
---|
| 28 | name ='steep_smflat_sin' |
---|
| 29 | wave = [0.5, 2, -0.5, -2] |
---|
| 30 | period = [900, 2700] |
---|
| 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=True, 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 | |
---|
| 138 | def waveform_sin(t): |
---|
| 139 | return wave[l]*sin(pi*2*t/period[w]) |
---|
| 140 | |
---|
| 141 | Bf = Transmissive_Momentum_Set_Stage_boundary(domain, waveform_sin) |
---|
| 142 | # Associate boundary tags with boundary objects |
---|
| 143 | domain.set_boundary({'left': Bd, 'right': Bf, 'top': Br, 'bottom': Br}) |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | #------------------------------------------------------------------------------ |
---|
| 148 | # Evolve system through time |
---|
| 149 | #------------------------------------------------------------------------------ |
---|
| 150 | |
---|
| 151 | for t in domain.evolve(yieldstep = 5 , finaltime = 4500): |
---|
| 152 | domain.write_time() |
---|
| 153 | |
---|
| 154 | """ |
---|
| 155 | Generate time series of nominated "gauges" |
---|
| 156 | Note, this script will only work if pylab is installed on the platform |
---|
| 157 | |
---|
| 158 | Inputs: |
---|
| 159 | |
---|
| 160 | production dirs: dictionary of production directories with a |
---|
| 161 | association to that simulation run, eg high tide, |
---|
| 162 | magnitude, etc. |
---|
| 163 | |
---|
| 164 | Outputs: |
---|
| 165 | |
---|
| 166 | * figures stored in same directory as sww file |
---|
| 167 | * time series data stored in csv files in same directory as sww file |
---|
| 168 | * elevation at nominated gauges (elev_output) |
---|
| 169 | """ |
---|
| 170 | |
---|
| 171 | from os import getcwd, sep, altsep, mkdir, access, F_OK, remove |
---|
| 172 | from anuga.abstract_2d_finite_volumes.util import sww2timeseries |
---|
| 173 | |
---|
| 174 | # nominate directory location of sww file with associated attribute |
---|
| 175 | production_dirs = {output_dir: str(name)} |
---|
| 176 | |
---|
| 177 | # Generate figures |
---|
| 178 | swwfiles = {} |
---|
| 179 | for label_id in production_dirs.keys(): |
---|
| 180 | file_loc = label_id |
---|
| 181 | swwfile = file_loc + str(name)+'.sww' |
---|
| 182 | swwfiles[swwfile] = label_id |
---|
| 183 | print 'hello', swwfile |
---|
| 184 | texname, elev_output = sww2timeseries(swwfiles, |
---|
| 185 | 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', |
---|
| 186 | production_dirs, |
---|
| 187 | report = False, |
---|
| 188 | reportname = '', |
---|
| 189 | plot_quantity = ['stage', 'speed'], |
---|
| 190 | generate_fig = False, |
---|
| 191 | surface = False, |
---|
| 192 | time_min = None, |
---|
| 193 | time_max = None, |
---|
| 194 | #time_unit = 'secs', |
---|
| 195 | title_on = True, |
---|
| 196 | verbose = True) |
---|
| 197 | ## print (output_dir+sep+str(name)+'.sww') |
---|
| 198 | ## remove(output_dir+sep+str(name)+'.sww') |
---|
| 199 | ## |
---|
| 200 | |
---|
| 201 | |
---|
| 202 | |
---|
| 203 | |
---|
| 204 | |
---|