import os import time from math import sqrt, sin, cos, pi, exp from shallow_water_domain_suggestion2 import * from Numeric import zeros, Float from pylab import plot,title,xlabel,ylabel,legend,savefig,show,hold,subplot print "TEST 1D-SOLUTION I" L=2000.0 N=200 cell_len=L/N points=zeros(N+1, Float) for i in range(N+1): points[i]=i*cell_len domain=Domain(points) domain.order = 2 domain.set_timestepping_method('rk2') domain.cfl = 1.0 domain.limiter = "vanleer" def stage_flat(x): y=zeros(len(x), Float) for i in range(len(x)): y[i]=4.0 return y def elevation_arbitrary(x): y=zeros(len(x), Float) for i in range(len(x)): if 0 <= x[i] < 200.0: y[i] = -0.01*(x[i]-200) + 4.0 elif 200.0 <= x[i] < 300.0: y[i] = -0.02*(x[i]-200) + 4.0 elif 300.0 <= x[i] < 400.0: y[i] = -0.01*(x[i]-300) + 2.0 elif 400.0 <= x[i] < 550.0: y[i] = (-1/75.0)*(x[i]-400.0) + 2.0 elif 550.0 <= x[i] < 700.0: y[i] = (1/11250)*(x[i]-550)*(x[i]-550) elif 700.0 <= x[i] < 800.0: y[i] = 0.03*(x[i]-700) elif 800.0 <= x[i] < 900.0: y[i] = -0.03*(x[i]-800) + 3.0 elif 900.0 <= x[i] < 1000.0: y[i] = 6.0 elif 1000.0 <= x[i] < 1400.0: y[i] = (-1.0/20000)*(x[i]-1000)*(x[i]-1400) elif 1400.0 <= x[i] < 1500.0: y[i] = 0.0 elif 1500.0 <= x[i] < 1700.0: y[i] = 3.0 elif 1700.0 <= x[i] < 1800.0: y[i] = -0.03*(x[i]-1700) + 3.0 else: y[i] = (3.0/40000)*(x[i]-1800)*(x[i]-1800) + 2.0 return y def elevation_arbitrary1(x): y=zeros(len(x), Float) for i in range(len(x)): if 0 <= x[i] < 200.0: y[i] = -0.01*(x[i]-200) + 5.0 elif 200.0 <= x[i] < 900.0: y[i] = 0.0 elif 900.0 <= x[i] < 1000.0: # This is the island y[i] = 5.0 elif 1000.0 <= x[i] < 1800.0: y[i] = 0.0 else: y[i] = 0.03*(x[i]-1700) + 3.0 return y def elevation_arbitrary2(x): y=zeros(len(x), Float) for i in range(len(x)): if 0 <= x[i] < 1000.0: # This is the island y[i] = 5.0 else: y[i] = 0.0 return y domain.set_quantity('stage',stage_flat) domain.set_quantity('elevation',elevation_arbitrary) domain.set_boundary({'exterior':Reflective_boundary(domain)}) X=domain.vertices.flat C=domain.centroids.flat t0=time.time() yieldstep=finaltime=60.0 while finaltime < 60.2: for t in domain.evolve(yieldstep=yieldstep, finaltime=finaltime): domain.write_time() print "t=",t print "integral", domain.quantities['height'].get_integral() StageQ=domain.quantities['stage'].vertex_values.flat MomentumQ=domain.quantities['xmomentum'].vertex_values.flat ElevationQ=domain.quantities['elevation'].vertex_values.flat VelocityQ=domain.quantities['velocity'].vertex_values.flat hold(False) plot1 = subplot(311) plot(X,StageQ, X,ElevationQ) plot1.set_ylim([-1.0,8.0]) xlabel('Position') ylabel('Stage') legend( ('Numerical Solution', 'Bed Elevation'), 'upper right', shadow=False) plot2 = subplot(312) plot(X,MomentumQ) #plot2.set_ylim([3.998,4.002]) legend( ('Numerical Solution', 'for momentum'), 'upper right', shadow=False) xlabel('Position') ylabel('Xmomentum') plot3 = subplot(313) plot(X,VelocityQ) #plot2.set_ylim([-5.0,30.0]) legend( ('Numerical Solution', 'for velocity'), 'upper right', shadow=False) xlabel('Position') ylabel('Velocity') file = "island_" file += str(finaltime) file += ".png" #savefig(file) show() print 'That took %.2f seconds'%(time.time()-t0) finaltime = finaltime + 10.0 raw_input("Press return key")