Changeset 8189
- Timestamp:
- Jul 1, 2011, 2:52:36 PM (14 years ago)
- Location:
- trunk/anuga_work/development/2010-projects/anuga_1d
- Files:
-
- 28 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_work/development/2010-projects/anuga_1d/base/limiters_python.py
r7930 r8189 12 12 from numpy import abs, where 13 13 14 phi = where((abs(a) < abs(b)) & (a*b > 0.0), a, 0.0)15 phi = where((abs(b) < abs(a)) & (a*b > 0.0), b, phi)14 phi = where((abs(a) < abs(b)) & (a*b >= 0.0), a, 0.0) 15 phi = where((abs(b) < abs(a)) & (a*b >= 0.0), b, phi) 16 16 17 17 return phi … … 20 20 from numpy import sign, abs, minimum, where 21 21 22 return where( (sign(a)*sign(b) > 0.0) & (sign(a)*sign(c)>0.0),22 return where( (sign(a)*sign(b) >= 0.0) & (sign(a)*sign(c)>0.0), 23 23 sign(a)*minimum(minimum(abs(a),abs(b)),abs(c)), 0.0 ) 24 24 -
trunk/anuga_work/development/2010-projects/anuga_1d/base/quantity_ext.c
r7930 r8189 88 88 89 89 phi = 0.0; 90 if ((fabs(a) < fabs(b)) & (a*b > 0.0 )) {90 if ((fabs(a) < fabs(b)) & (a*b >= 0.0 )) { 91 91 phi = a; 92 92 } 93 if ((fabs(b) < fabs(a)) & (a*b > 0.0 )) {93 if ((fabs(b) < fabs(a)) & (a*b >= 0.0 )) { 94 94 phi = b; 95 95 } … … 191 191 192 192 phi = 0.0; 193 if ((sign(a)*sign(b) > 0.0) & (sign(a)*sign(c) > 0.0 )) {193 if ((sign(a)*sign(b) > 0.0) & (sign(a)*sign(c) >= 0.0 )) { 194 194 phi = sign(a)*min(theta*min(fabs(a),fabs(b)),fabs(c)); 195 195 } -
trunk/anuga_work/development/2010-projects/anuga_1d/sww/run_parabolic_canal.py
r8073 r8189 1 1 import os 2 2 from math import sqrt, pi, sin, cos 3 from shallow_water_vel_domain import * 4 from Numeric import allclose, array, zeros, ones, Float, take, sqrt 5 from config import g, epsilon 6 7 def analytic_cannal(C,t): 8 N = len(C) 9 u = zeros(N,Float) ## water velocity 10 h = zeros(N,Float) ## water depth 11 x = C 12 g = 9.81 13 ## Define Basin Bathymetry 14 z_b = zeros(N,Float) ## elevation of basin 15 z = zeros(N,Float) ## elevation of water surface 16 z_infty = 10.0 ## max equilibrium water depth at lowest point. 17 L_x = 2500.0 ## width of channel 18 A0 = 0.5*L_x ## determines amplitudes of oscillations 19 omega = sqrt(2*g*z_infty)/L_x ## angular frequency of osccilation 20 for i in range(N): 21 z_b[i] = z_infty*(x[i]**2/L_x**2) 22 u[i] = -A0*omega*sin(omega*t) 23 z[i] = z_infty+2*A0*z_infty/L_x*cos(omega*t)*(x[i]/L_x-0.5*A0/(L_x)*cos(omega*t)) 24 h = z-z_b 25 T = 2.0*pi/omega 26 return u,h,z,z_b, T 3 import numpy 4 import time 27 5 28 6 29 L_x = 2500.0 # Length of channel (m) 30 N = 1000 # Number of compuational cells 31 cell_len = 4*L_x/N # Origin = 0.0 7 from anuga_1d.sww.sww_domain import * 8 from anuga_1d.config import g, epsilon 9 from anuga_1d.base.generic_mesh import uniform_mesh 32 10 33 points = zeros(N+1,Float) 34 for i in range(N+1): 35 points[i] = -2*L_x +i*cell_len 11 #=============================================================================== 12 # setup problem 13 #=============================================================================== 14 15 16 z_infty = 5.0 ## max equilibrium water depth at lowest point. 17 L_x = 2500.0 ## width of channel 18 A0 = 0.5*L_x ## determines amplitudes of oscillations 19 omega = sqrt(2*g*z_infty)/L_x ## angular frequency of osccilation 20 21 def analytic_canal(x,t): 22 u = numpy.zeros_like(x) ## water velocity 23 h = numpy.zeros_like(x) ## water depth 24 25 ## Define Basin Bathymetry 26 z = numpy.zeros_like(x) ## elevation of basin 27 w = numpy.zeros_like(x) ## elevation of water surface 28 29 z[:] = z_infty*(x**2/L_x**2) 30 u[:] = -A0*omega*sin(omega*t) 31 w[:] = numpy.maximum(z_infty+2*A0*z_infty/L_x*cos(omega*t)*(x/L_x-0.5*A0/(L_x)*cos(omega*t)),z) 32 h[:] = numpy.maximum(w-z, 0.0) 33 34 T = 2.0*pi/omega 35 36 return u,h,w,z, T 37 36 38 37 39 def stage(x): 38 z_infty = 10.0 ## max equilibrium water depth at lowest point.39 L_x = 2500.0 ## width of channel40 A0 = 0.5*L_x ## determines amplitudes of oscillations41 omega = sqrt(2*g*z_infty)/L_x ## angular frequency of osccilation42 40 t=0.0 43 y = zeros(len(x),Float) 44 for i in range(len(x)): 45 y[i] = z_infty+2*A0*z_infty/L_x*cos(omega*t)*(x[i]/L_x-0.5*A0/(L_x)*cos(omega*t)) 46 #y[i] = 12.0 47 return y 41 u,h,w,z,T = analytic_canal(x,t) 42 43 return w 48 44 49 45 def elevation(x): 50 N = len(x) 51 z_infty = 10.0 52 z = zeros(N,Float) 53 L_x = 2500.0 54 A0 = 0.5*L_x 55 omega = sqrt(2*g*z_infty)/L_x 56 for i in range(N): 57 z[i] = z_infty*(x[i]**2/L_x**2) 46 t=0.0 47 u,h,w,z,T = analytic_canal(x,t) 48 58 49 return z 59 50 51 60 52 def height(x): 61 z_infty = 10.0 ## max equilibrium water depth at lowest point.62 L_x = 2500.0 ## width of channel63 A0 = 0.5*L_x ## determines amplitudes of oscillations64 omega = sqrt(2*g*z_infty)/L_x ## angular frequency of osccilation65 53 t=0.0 66 y = zeros(len(x),Float) 67 for i in range(len(x)): 68 y[i] = max(z_infty+2*A0*z_infty/L_x*cos(omega*t)*(x[i]/L_x-0.5*A0/(L_x)*cos(omega*t))-z_infty*(x[i]**2/L_x**2),0.0) 69 return y 54 u,h,w,z,T = analytic_canal(x,t) 70 55 71 domain = Domain(points) 72 domain.order = 2 73 domain.set_timestepping_method('euler') 56 return h 57 58 59 #=============================================================================== 60 finaltime = 1000.0 61 yieldstep = 10.0 62 63 64 65 N = 100 66 print "Evaluating domain with %d cells" %N 67 domain = Domain(*uniform_mesh(N, x_0 = -2.0*L_x, x_1 = 2.0*L_x)) 68 69 domain.set_spatial_order(2) 70 domain.set_timestepping_method('rk2') 74 71 domain.set_CFL(1.0) 75 domain.beta = 1.0 76 domain.set_limiter("vanleer") 72 domain.set_limiter("minmod_kurganov") 77 73 78 74 domain.set_beta(1.0) 75 79 76 domain.set_quantity('stage', stage) 80 77 domain.set_quantity('elevation',elevation) 81 domain.set_boundary({'exterior': Reflective_boundary(domain)})82 83 X = domain.vertices84 u,h,z,z_b,T = analytic_cannal(X.flat,domain.time)85 print 'T = ',T86 78 87 yieldstep = finaltime = 10.0 #T/2.0 88 StageQ = domain.quantities['stage'].vertex_values 89 XmomQ = domain.quantities['xmomentum'].vertex_values 79 domain.quantities['elevation'].extrapolate_second_order() 80 domain.quantities['stage'].extrapolate_second_order() 90 81 91 import time 82 Br = Reflective_boundary(domain) 83 84 domain.set_boundary({'left': Br, 'right' : Br}) 85 86 #domain.h0=0.0001 87 92 88 t0 = time.time() 89 93 90 for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): 94 91 domain.write_time() 95 print "integral", domain.quantities['stage'].get_integral()96 if t>0.0:97 98 x = X.flat99 print 'domain.time=',domain.time100 101 w_V = domain.quantities['stage'].vertex_values.flat102 uh_V = domain.quantities['xmomentum'].vertex_values.flat103 u_V = domain.quantities['velocity'].vertex_values.flat104 h_V = domain.quantities['height'].vertex_values.flat105 106 u,h,z,z_b,T = analytic_cannal(x,domain.time)107 w = z108 for k in range(len(h)):109 if h[k] < 0.0:110 h[k] = 0.0111 w[k] = z_b[k]112 113 from pylab import plot,title,xlabel,ylabel,legend,savefig,show,hold,subplot114 hold(False)115 92 116 #print 'size X',X.shape 117 #print 'size w',w.shape 118 signh = (h_V>0) 93 print 'That took %.2f seconds' %(time.time()-t0) 119 94 120 plot1 = subplot(311)121 #plot(x,w, x,w_V, x,z_b)122 plot(x,signh)123 plot1.set_xlim([-6000,6000])124 xlabel('Position')125 ylabel('Stage')126 legend(('Analytic Solution', 'Numerical Solution', 'Bed'),127 'upper center', shadow=True)128 95 129 130 plot2 = subplot(312) 131 plot(x,u*h,x,uh_V) 132 #plot2.set_ylim([-1,25]) 133 xlabel('Position') 134 ylabel('Xmomentum') 96 N = float(N) 97 HeightC = domain.quantities['height'].centroid_values 98 StageC = domain.quantities['stage'].centroid_values 99 BedC = domain.quantities['elevation'].centroid_values 100 C = domain.centroids 135 101 136 print u_V 137 138 plot3 = subplot(313) 139 plot(x,u, x,u_V) 140 #plot2.set_ylim([-1,25]) 141 xlabel('Position') 142 ylabel('Velocity') 143 show() 144 raw_input("Press the return key!") 102 HeightV = domain.quantities['height'].vertex_values 103 StageV = domain.quantities['stage'].vertex_values 104 BedV = domain.quantities['elevation'].vertex_values 105 VelocityV = domain.quantities['velocity'].vertex_values 106 X = domain.vertices 107 108 109 import pylab 110 111 pylab.hold(False) 112 113 plot1 = pylab.subplot(311) 114 115 pylab.plot(X.flat,BedV.flat,X.flat,StageV.flat) 116 117 plot1.set_ylim([-1,40]) 118 119 pylab.xlabel('Position') 120 pylab.ylabel('Stage') 121 pylab.legend(('Analytical Solution', 'Numerical Solution'), 122 'upper right', shadow=True) 123 124 125 plot2 = pylab.subplot(312) 126 127 pylab.plot(X.flat,HeightV.flat) 128 129 plot2.set_ylim([-1,10]) 130 131 pylab.xlabel('Position') 132 pylab.ylabel('Height') 133 134 plot3 = pylab.subplot(313) 135 136 pylab.plot(X.flat,VelocityV.flat) 137 plot3.set_ylim([-15,15]) 138 139 pylab.xlabel('Position') 140 pylab.ylabel('Velocity') 141 142 pylab.show() 143 144 145 146 147 148 -
trunk/anuga_work/development/2010-projects/anuga_1d/sww/sww_comp_flux_ext.c
r7884 r8189 3 3 #include "math.h" 4 4 #include <stdio.h> 5 5 6 const double pi = 3.14159265358979; 6 7 -
trunk/anuga_work/development/2010-projects/anuga_1d/sww/sww_domain.py
r7884 r8189 237 237 h_C[:] = w_C - z_C 238 238 u_C[:] = uh_C/(h_C + h0/h_C) 239 239 240 #print 'domain.order', domain.order 241 240 242 for name in [ 'velocity', 'stage' ]: 241 243 Q = domain.quantities[name] … … 258 260 259 261 h_V[:,:] = stage_V - bed_V 262 263 264 #print 'any' ,numpy.any( h_V[:,0] < 0.0) 265 #print 'any' ,numpy.any( h_V[:,1] < 0.0) 266 267 268 h_0 = numpy.where(h_V[:,0] < 0.0, 0.0, h_V[:,0]) 269 h_1 = numpy.where(h_V[:,0] < 0.0, h_V[:,1]+h_V[:,0], h_V[:,1]) 270 271 h_V[:,0] = h_0 272 h_V[:,1] = h_1 273 274 275 h_0 = numpy.where(h_V[:,1] < 0.0, h_V[:,1]+h_V[:,0], h_V[:,0]) 276 h_1 = numpy.where(h_V[:,1] < 0.0, 0.0, h_V[:,1]) 277 278 h_V[:,0] = h_0 279 h_V[:,1] = h_1 280 281 #print 'any' ,numpy.any( h_V[:,0] < 0.0) 282 #print 'any' ,numpy.any( h_V[:,1] < 0.0) 283 284 #h00 = 1e-12 285 #print h00 286 287 h_V[:,:] = numpy.where (h_V <= h0, 0.0, h_V) 288 u_V[:,:] = numpy.where (h_V <= h0, 0.0, u_V) 260 289 261 290 # # protect from edge values going negative -
trunk/anuga_work/development/2010-projects/anuga_1d/test_all.py
r7884 r8189 23 23 24 24 # Directories that should not be searched for test files. 25 exclude_dirs = [ 'channel','.svn']25 exclude_dirs = [ '.svn'] 26 26 27 27
Note: See TracChangeset
for help on using the changeset viewer.