[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 = 'con_wave_900' |
---|
| 30 | shelf = [5000, 50000, 300000] |
---|
| 31 | slope = [50000, 150000] |
---|
| 32 | wave = [-0.5] #1 returns leading depression N-wave |
---|
| 33 | #-1 returns leading crest N-wave |
---|
| 34 | N = len (shelf) |
---|
| 35 | for i in range(N): |
---|
| 36 | M = len (slope) |
---|
| 37 | for k in range (M): |
---|
| 38 | B = len(wave) |
---|
| 39 | for l in range(B): |
---|
| 40 | length = (shelf[i]+slope[k]) |
---|
| 41 | width = 800. |
---|
| 42 | A = 1 |
---|
| 43 | T = 2700 |
---|
| 44 | umask(002) |
---|
| 45 | time = strftime('%Y%m%d_%H%M%S',gmtime()) |
---|
| 46 | ## output_dir = 'C:'+sep+'anuga_data'+sep+str(name)+'_'+str(wave[l])+'_'+str(shelf[i])+'_'+str(slope[k])+sep |
---|
| 47 | output_dir = sep+'d'+sep+'sim'+sep+'1'+sep+'mpittard'+sep+'idealised_bathymetry_study'+sep+'wave_type_tester'+sep+str(name)+'_'+str(wave[l])+'_'+str(shelf[i])+'_'+str(slope[k])+sep |
---|
| 48 | |
---|
| 49 | sww_file = str(name) |
---|
| 50 | copy_code_files(output_dir,__file__,__file__) |
---|
| 51 | start_screen_catcher(output_dir) |
---|
| 52 | boundary_polygon = [[0,0],[length,0],[length,width],[0,width]] |
---|
| 53 | |
---|
| 54 | meshname = str(name)+'.msh' |
---|
| 55 | create_mesh_from_regions(boundary_polygon, |
---|
| 56 | boundary_tags={'bottom': [0], |
---|
| 57 | 'right': [1], |
---|
| 58 | 'top': [2], |
---|
| 59 | 'left': [3]}, |
---|
| 60 | maximum_triangle_area=20000, |
---|
| 61 | filename=meshname, |
---|
| 62 | use_cache=False, |
---|
| 63 | verbose=False) |
---|
| 64 | |
---|
| 65 | domain = Domain(meshname, use_cache=True, verbose=True) |
---|
| 66 | |
---|
| 67 | print 'Number of triangles = ', len(domain) |
---|
| 68 | print 'The extent is ', domain.get_extent() |
---|
| 69 | print domain.statistics() |
---|
| 70 | |
---|
| 71 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
| 72 | domain.set_minimum_storable_height(0.01) |
---|
| 73 | domain.set_default_order(2) |
---|
| 74 | domain.set_name(sww_file)# Output name |
---|
| 75 | domain.set_datadir(output_dir) |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | #------------------------------------------------------------------------------ |
---|
| 79 | # Setup initial conditions |
---|
| 80 | #------------------------------------------------------------------------------ |
---|
| 81 | |
---|
| 82 | def topography(x,y): |
---|
| 83 | """Complex topography defined by a function of vectors x and y |
---|
| 84 | """ |
---|
| 85 | o = 2500/(slope[k]*slope[k]/4) |
---|
| 86 | print str(2500/(slope[k]*slope[k]/4)) |
---|
| 87 | |
---|
| 88 | z = o*(x-(shelf[i]+slope[k]))*(x-(shelf[i]+slope[k]))-5125-10 |
---|
| 89 | S = len (x) |
---|
| 90 | for j in range(S): |
---|
| 91 | |
---|
| 92 | if x[j] < shelf[i]: |
---|
| 93 | z[j] = -125/(shelf[i]*shelf[i])*x[j]*x[j]-10 |
---|
| 94 | |
---|
| 95 | elif shelf[i] <= x[j] < (shelf[i]+slope[k]*0.5) : |
---|
| 96 | z[j] = (-o)*(x[j]-shelf[i])*(x[j]-shelf[i])-125-10 |
---|
| 97 | |
---|
| 98 | return z |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
| 103 | domain.set_quantity('friction', 0) # Constant friction |
---|
| 104 | domain.set_quantity('stage', 0) # Constant negative initial stage |
---|
| 105 | domain.tight_slope_limiters = 1 |
---|
| 106 | domain.beta_h = 0 |
---|
| 107 | |
---|
| 108 | #------------------------------------------------------------------------------ |
---|
| 109 | # Setup boundary conditions |
---|
| 110 | #------------------------------------------------------------------------------ |
---|
| 111 | |
---|
| 112 | from math import sin, pi, exp, cos, sqrt, cosh |
---|
| 113 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
| 114 | Bt = Transmissive_boundary(domain) # Continue all values on boundary |
---|
| 115 | Bd = Dirichlet_boundary([0.,0.,0.]) # Constant boundary values |
---|
| 116 | |
---|
| 117 | def waveform(t): |
---|
| 118 | return wave[l]*2.1*sin(2*pi*t/900)*exp(-t/(900)) |
---|
| 119 | Bf = Transmissive_Momentum_Set_Stage_boundary(domain, waveform) |
---|
| 120 | # Associate boundary tags with boundary objects |
---|
| 121 | domain.set_boundary({'left': Bd, 'right': Bf, 'top': Br, 'bottom': Br}) |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | #------------------------------------------------------------------------------ |
---|
| 125 | # Evolve system through time |
---|
| 126 | #------------------------------------------------------------------------------ |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | for t in domain.evolve(yieldstep = 45, finaltime = -1000+((length/50000)+1)*600+((shelf[i]/25000+1)*1000)): |
---|
| 130 | domain.write_time() |
---|
| 131 | for t in domain.evolve(yieldstep = 45, finaltime = 2700+((length/50000)+1)*600+((shelf[i]/25000+1)*1000), |
---|
| 132 | skip_initial_step = True): |
---|
| 133 | domain.write_time() |
---|
| 134 | for t in domain.evolve(yieldstep = 120, finaltime = (length/25)+2700+((length/50000)+1)*600+((shelf[i]/25000+1)*1000), |
---|
| 135 | skip_initial_step = True): |
---|
| 136 | domain.write_time() |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | """ |
---|
| 140 | Generate time series of nominated "gauges" |
---|
| 141 | Note, this script will only work if pylab is installed on the platform |
---|
| 142 | |
---|
| 143 | Inputs: |
---|
| 144 | |
---|
| 145 | production dirs: dictionary of production directories with a |
---|
| 146 | association to that simulation run, eg high tide, |
---|
| 147 | magnitude, etc. |
---|
| 148 | |
---|
| 149 | Outputs: |
---|
| 150 | |
---|
| 151 | * figures stored in same directory as sww file |
---|
| 152 | * time series data stored in csv files in same directory as sww file |
---|
| 153 | * elevation at nominated gauges (elev_output) |
---|
| 154 | """ |
---|
| 155 | |
---|
| 156 | from os import getcwd, sep, altsep, mkdir, access, F_OK, remove |
---|
| 157 | from anuga.abstract_2d_finite_volumes.util import sww2timeseries |
---|
| 158 | |
---|
| 159 | # nominate directory location of sww file with associated attribute |
---|
| 160 | production_dirs = {output_dir: str(name)} |
---|
| 161 | |
---|
| 162 | # Generate figures |
---|
| 163 | swwfiles = {} |
---|
| 164 | for label_id in production_dirs.keys(): |
---|
| 165 | file_loc = label_id |
---|
| 166 | swwfile = file_loc + str(name)+'.sww' |
---|
| 167 | swwfiles[swwfile] = label_id |
---|
| 168 | print 'hello', swwfile |
---|
| 169 | texname, elev_output = sww2timeseries(swwfiles, |
---|
| 170 | sep+'d'+sep+'sim'+sep+'1'+sep+'mpittard'+sep+'anuga'+sep+'anuga_work'+sep+'development'+sep+'idealised_bathymetry_study'+sep+'continental_shelves'+sep+'gauges.csv', |
---|
| 171 | production_dirs, |
---|
| 172 | report = False, |
---|
| 173 | reportname = '', |
---|
| 174 | plot_quantity = ['stage', 'speed'], |
---|
| 175 | generate_fig = False, |
---|
| 176 | surface = False, |
---|
| 177 | time_min = None, |
---|
| 178 | time_max = None, |
---|
| 179 | #time_unit = 'secs', |
---|
| 180 | title_on = True, |
---|
| 181 | verbose = True) |
---|
| 182 | ## print (output_dir+sep+str(name)+'.sww') |
---|
| 183 | ## remove(output_dir+sep+str(name)+'.sww') |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | |
---|