Changeset 3247
- Timestamp:
- Jun 27, 2006, 6:10:14 PM (18 years ago)
- Location:
- documentation/user_manual/examples
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
documentation/user_manual/examples/harbour.py
r3224 r3247 51 51 52 52 domain = Domain(meshname,use_cache=True,verbose = True) 53 domain.set_name(' test') # Output to test.sww53 domain.set_name('harbour') # Output to harbour.sww 54 54 domain.set_datadir('.') # Use current directory for output 55 55 domain.set_quantities_to_be_stored(['stage',# Store all conserved quantities … … 76 76 if yi < ycentredown: z[i,j] = 0.0 77 77 if yi > ycentreup: z[i,j] = 0.0 78 if yi > ycentredown and yi < ycentreup: z[i,j] = 79 harbour_depth 80 if xi > centre-harbour_length and xi < centre: z[i,j] = 81 harbour_depth 78 if yi > ycentredown and yi < ycentreup: z[i,j] = harbour_depth 79 if xi > centre-harbour_length and xi < centre: z[i,j] = harbour_depth 82 80 return z 83 81 … … 108 106 domain.write_time() 109 107 108 #----------------------------------------------------------------------------- 109 # Interrogate solution 110 #----------------------------------------------------------------------------- 111 110 112 # Gauge line 111 113 def gauge_line(west,east,north,south): … … 118 120 return gauges 119 121 120 #-----------------------------------------------------------------------------121 # Interrogate solution122 #-----------------------------------------------------------------------------123 124 122 gauges = gauge_line(west,east,north,south) 125 123 126 f = file_function(gauges) 124 from pyvolution.util import file_function 125 126 f = file_function('harbour.sww', 127 quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'], 128 interpolation_points = gauges, 129 verbose = True, 130 use_cache = True) 131 127 132 maxw = 0.0 128 133 themaxw = maxw … … 130 135 for k, g in enumerate(gauges): 131 136 for i, t in enumerate(f.get_time()): 132 if w > maxw: maxw = w 137 w = f(t, point_id = k)[0] 138 elevation = f(t, point_id = k)[1] 139 if w > maxw: maxw = w 133 140 maxws.append(maxw) 134 if themaxw < maxw: 135 themaxw = maxw136 gaugeloc = k141 if themaxw < maxw: 142 themaxw = maxw 143 gaugeloc = k 137 144 138 from pylab import plot, xlabel, ylabel, title 145 from pylab import plot, xlabel, ylabel, title, ion, close, savefig 146 ion() 139 147 plot(gaugex,maxws,'g-',gaugestar[0],gaugestar[1],'r*') 140 148 xlabel('x') 141 149 ylabel('stage') 142 150 title('Maximum stage for gauge line') 151 savefig('max_stage_harbour') 152 close('all') -
documentation/user_manual/examples/runuptest.py
r3224 r3247 17 17 from pyvolution.shallow_water import Transmissive_boundary 18 18 19 waveheight = 1.0 19 20 20 #------------------------------------------------------------------------------ 21 21 # Setup computational domain 22 22 #------------------------------------------------------------------------------ 23 23 24 west = 340000. 25 east = 380000. 26 south = 6265000. 27 north = 6250000. 24 waveheight = 1000.0 25 depth_east_edge = -4000. 26 west = 0. 27 east = 80000. 28 south = 0. 29 north = 5000. 28 30 polygon = [[east,north],[west,north],[west,south],[east,south]] 29 31 meshname = 'test.msh' … … 34 36 'bottom': [2], 35 37 'right': [3]}, 36 maximum_triangle_area= 50000,38 maximum_triangle_area=100000, 37 39 filename=meshname) 38 40 #interior_regions=interior_regions) … … 51 53 52 54 def topography(x,y): 53 slope = -1./400.54 c = 850.055 return slope*x+c 55 slope = depth_east_edge/((east-west)/2.) 56 c = -(west+east)/2.*slope 57 return slope*x+c # linear bed slope 56 58 57 59 domain.set_quantity('elevation', topography) # Use function for elevation … … 79 81 80 82 stagestep = [] 81 for t in domain.evolve(yieldstep = 10, finaltime = 100 .0):83 for t in domain.evolve(yieldstep = 10, finaltime = 1000.0): 82 84 domain.write_time() 83 84 # Gauge line85 def gauge_line(west,east,north,south):86 from Numeric import arange87 gaugex = arange(west,east,1000.)88 gauges = []89 for x in gaugex:90 y = (north+south)/2.91 gauges.append([x,y])92 return gauges93 85 94 86 #----------------------------------------------------------------------------- … … 96 88 #----------------------------------------------------------------------------- 97 89 98 gauges = gauge_line(west,east,north,south) 90 # Gauge line 91 def gauge_line(west,east,north,south): 92 from Numeric import arange 93 gaugex = arange(east,west,-1000.) 94 gauges = [] 95 gaugey = [] 96 for x in gaugex: 97 y = (north+south)/2. 98 gaugey.append(y) 99 gauges.append([x,y]) 100 return gauges, gaugex, gaugey 99 101 100 f = file_function(gauges) 101 maxw = 0.0 102 themaxw = maxw 103 maxws = [] 102 gauges, gaugex, gaugey = gauge_line(west,east,north,south) 103 104 from pyvolution.util import file_function 105 106 f = file_function('test.sww', 107 quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'], 108 interpolation_points = gauges, 109 verbose = True, 110 use_cache = True) 111 112 from pylab import plot, xlabel, ylabel, title, ion, close, savefig, figure 113 ion() 114 115 maxw = [] 116 minw = [] 117 maxd = [] 118 count = 0 104 119 for k, g in enumerate(gauges): 120 stage = [] 121 elevation = [] 122 depths = [] 105 123 for i, t in enumerate(f.get_time()): 106 if elevation > 0: 107 if w > maxw: maxw = w 108 maxws.append(maxw) 109 if elevation > 0: 110 if themaxw < maxw: 111 themaxw = maxw 112 gaugeloc = k 124 w = f(t, point_id = k)[0] 125 elev = f(t, point_id = k)[1] 126 depth = w-elev 127 stage.append(w) 128 elevation.append(elev) 129 depths.append(elev) 130 if g[0] < (west+east)/2. and depth <= 0 and count == 0: 131 count += 1 132 posx = g[0] 133 loc = k 134 maxw.append(max(stage)) 135 minw.append(min(stage)) 136 maxd.append(max(depths)) 113 137 114 filename = 'maxrunup'+ waveheight+'.csv'138 filename = 'maxrunup'+str(waveheight)+str(depth_east_edge)+'.csv' 115 139 fid = open(filename,'w') 116 s = ' Waveheight,Runup distance,Runup height\n'140 s = 'Depth at eastern boundary,Waveheight,Runup distance,Runup height\n' 117 141 fid.write(s) 118 gaugestar = gauges[gaugeloc] 119 s = '%.2f, %.2f/n' %(waveheight,gaugestar[0],gaugestar[1]) 142 runup_distance = posx 143 runup_height = topography(runup_distance,(north+south)/2.) 144 print 'run up height: ', runup_height 145 if runup_distance < (east+west)/2.: 146 runup_distance_from_coast = (east+west)/2.-runup_distance 147 else: 148 runup_distance_from_coast = runup_distance-(east+west)/2. 149 print 'run up distance from coastline: ', runup_distance_from_coast 150 s = '%.2f,%.2f,%.2f,%.2f\n' %(depth_east_edge,waveheight,runup_distance_from_coast,runup_height) 120 151 fid.write(s) 121 152 122 f rom pylab import plot, xlabel, ylabel, title123 plot(gaugex ,maxws,'g-',gaugestar[0],gaugestar[1],'r*')153 figure(1) 154 plot(gaugex[:loc],maxw[:loc],'g-') 124 155 xlabel('x') 125 156 ylabel('stage') 126 157 title('Maximum stage for gauge line') 158 savefig('max_stage') 159 160 close('all')
Note: See TracChangeset
for help on using the changeset viewer.