Changeset 3505
 Timestamp:
 Aug 17, 2006, 5:56:35 PM (18 years ago)
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

documentation/user_manual/examples/runup.py
r3486 r3505 49 49 # 50 50 51 from math import sin, pi 51 from math import sin, pi, exp 52 52 Br = Reflective_boundary(domain) # Solid reflective wall 53 53 Bt = Transmissive_boundary(domain) # Continue all values on boundary 54 54 Bd = Dirichlet_boundary([0.2,0.,0.]) # Constant boundary values 55 55 Bw = Time_boundary(domain=domain, # Time dependent boundary 56 f=lambda t: [(.1*sin(t*2*pi)0.3) , 0.0, 0.0])56 f=lambda t: [(.1*sin(t*2*pi)0.3) * exp(t), 0.0, 0.0]) 57 57 58 58 # Associate boundary tags with boundary objects 
documentation/user_manual/examples/runup_convergence.py
r3487 r3505 2 2 3 3 Water driven up a linear slope and time varying boundary, 4 similar to a beach environment 4 similar to a beach environment. 5 6 The study area is discretised as a regular triangular grid 100m x 100m 5 7 """ 6 8 … … 10 12 # 11 13 14 import sys 15 16 from pmesh.mesh_interface import create_mesh_from_regions 12 17 from pyvolution.mesh_factory import rectangular_cross 13 18 from pyvolution.shallow_water import Domain … … 15 20 from pyvolution.shallow_water import Dirichlet_boundary 16 21 from pyvolution.shallow_water import Time_boundary 17 from pyvolution.shallow_water import Transmissive_boundary 22 from pyvolution.shallow_water import Transmissive_Momentum_Set_Stage_boundary 23 from pyvolution.util import file_function 24 from pylab import plot, xlabel, ylabel, title, ion, close, savefig, figure, axis 25 ion() 26 27 28 # 29 # Model constants 30 31 slope = 0.02 # 1:50 Slope 32 highest_point = 3 # Highest elevation (m) 33 sea_level = 2 # Mean sea level 34 wave_height = 3 # Solitary wave height H 35 simulation_name = 'runup_convergence' 36 37 38 # Basin dimensions (m) 39 west = 0 # left boundary 40 east = 500 # right boundary 41 south = 0 # lower boundary 42 north = 100 # upper bourdary 18 43 19 44 … … 22 47 # 23 48 24 N = 10 25 waveheight=5 26 points, vertices, boundary = rectangular_cross(N, N, len1=100, len2=100) 49 # Structured mesh 50 dx = 10 # Resolution: Lenght of subdivisions on x axis (length) 51 dy = 10 # Resolution: Lenght of subdivisions on y axis (width) 52 53 length = eastwest 54 width = northsouth 55 points, vertices, boundary = rectangular_cross(length/dx, width/dy, len1=length, len2=width, 56 origin = (west, south)) 27 57 28 58 domain = Domain(points, vertices, boundary) # Create domain 29 domain.set_name('runup_convergence') # Output to bedslope.sww 59 60 61 62 # Unstructured mesh 63 #polygon = [[east,north],[west,north],[west,south],[east,south]] 64 #meshname = simulation_name + '.msh' 65 #create_mesh_from_regions(polygon, 66 # boundary_tags={'top': [0], 'left': [1], 'bottom': [2], 'right': [3]}, 67 # maximum_triangle_area=dx*dy/2, 68 # filename=meshname) 69 # #interior_regions=interior_regions) 70 #domain = Domain(meshname, use_cache=True, verbose = True) 71 72 73 74 domain.set_name(simulation_name) 30 75 31 76 … … 35 80 36 81 def topography(x,y): 37 slope = 0.02 38 elevation = 10 39 return slope*x+elevation # linear bed slope 82 return slope*x+highest_point # Return linear bed slope bathymetry as vector 40 83 41 84 domain.set_quantity('elevation', topography) # Use function for elevation 42 domain.set_quantity('friction', 0. ) # Constant friction 43 domain.set_quantity('stage', 0.0) # Constant initial stage 85 domain.set_quantity('friction', 0.0 ) # Constant friction 86 domain.set_quantity('stage', sea_level) # Constant initial stage 87 44 88 45 89 # … … 47 91 # 48 92 49 from math import sin, pi 93 from math import sin, pi, cosh, sqrt 50 94 Br = Reflective_boundary(domain) # Solid reflective wall 51 Bt = Transmissive_boundary(domain) # Continue all values on boundary52 95 Bd = Dirichlet_boundary([0.,0.,0.]) # Constant boundary values 96 97 def waveform(t): 98 return wave_height/cosh(t5)**2 99 53 100 Bw = Time_boundary(domain=domain, # Time dependent boundary 54 f=lambda t: [((10<t<20)*waveheight), 0.0, 0.0]) 101 f=lambda t: [waveform(t), 0.0, 0.0]) 102 103 # Time dependent boundary for stage, where momentum is set automatically 104 Bts = Transmissive_Momentum_Set_Stage_boundary(domain, waveform) 105 55 106 56 107 # Associate boundary tags with boundary objects 57 domain.set_boundary({'left': Br, 'right': B w, 'top': Br, 'bottom': Br})108 domain.set_boundary({'left': Br, 'right': Bts, 'top': Br, 'bottom': Br}) 58 109 59 110 … … 63 114 64 115 stagestep = [] 65 for t in domain.evolve(yieldstep = 1 0, finaltime = 100):116 for t in domain.evolve(yieldstep = 1, finaltime = 100): 66 117 domain.write_time() 118 67 119 68 120 # … … 70 122 # 71 123 124 125 # Define line of gauges through center of domain 126 def gauge_line(west,east,north,south): 127 from Numeric import arange 128 x_vector = arange(west, (eastwest)/2, 10) # Gauges every 1 meter from west to midpt 129 y = (north+south)/2. 130 131 gauges = [] 132 for x in x_vector: 133 gauges.append([x,y]) 134 135 return gauges, x_vector 136 137 gauges, x_vector = gauge_line(west,east,north,south) 138 139 # Obtain interpolated timeseries at gauges 140 f = file_function(domain.get_name()+'.sww', 141 quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'], 142 interpolation_points = gauges, 143 verbose = True, 144 use_cache = True) 145 146 147 # Find runup distance from western boundary through a linear search 148 max_stage = [] 149 min_stage = [] 150 runup_point = west 151 coastline = east 152 for k, g in enumerate(gauges): 153 z = f(0, point_id=k)[1] # Elevation 154 155 min_w = sys.maxint 156 max_w = min_w 157 for i, t in enumerate(f.get_time()): 158 w = f(t, point_id = k)[0] 159 if w > max_w: max_w = w 160 if w < min_w: min_w = w 161 162 if max_wz <= 0.01: # Find first gauge where max depth > eps (runup) 163 runup_point = g[0] 164 165 if min_wz <= 0.01: # Find first gauge where min depth > eps (coastline) 166 coastline = g[0] 167 168 max_stage.append(max_w) 169 min_stage.append(min_w) 170 171 172 # Print 173 174 print 'wave height [m]: ', wave_height 175 runup_height = topography(runup_point, (north+south)/2.) 176 print 'run up height [m]: ', runup_height 177 178 runup_distance = runup_pointcoastline 179 print 'run up distance from coastline [m]: ', runup_distance 180 181 print 'Coastline (meters form west): ', coastline 182 183 184 185 # Store 186 filename = 'maxrunup'+str(wave_height)+'.csv' 187 fid = open(filename,'w') 188 s = 'Depth at eastern boundary,Waveheight,Runup distance,Runup height\n' 189 fid.write(s) 190 191 s = '%.2f,%.2f,%.2f\n' %(wave_height, runup_distance, runup_height) 192 fid.write(s) 193 194 fid.close() 195 196 # Plot 197 figure(1) 198 plot(x_vector, max_stage, 'g+', 199 x_vector, min_stage, 'b+', 200 x_vector, topography(x_vector,(north+south)/2.), 'r') 201 xlabel('x') 202 ylabel('stage') 203 title('Maximum stage for gauge line') 204 #axis([33000, 47000, 1000, 3000]) 205 savefig('max_stage') 206 207 close('all') 72 208 73 209 
inundation/pyvolution/shallow_water.py
r3127 r3505 1059 1059 q = self.domain.get_conserved_quantities(vol_id, edge = edge_id) 1060 1060 value = self.function(self.domain.time) 1061 q[0] = value[0] 1061 1062 1063 try: 1064 # In case function returns a list of values 1065 val = value[0] 1066 except TypeError: 1067 val = value 1068 1069 # Assign value to first component of q (stage) 1070 try: 1071 q[0] = float(val) 1072 except: 1073 msg = 'Supplied value could not be converted to float: val=', val 1074 raise Exception, msg 1075 1076 1077 1078 1062 1079 return q 1063 1080
Note: See TracChangeset
for help on using the changeset viewer.