import os from math import sqrt, sin, cos, pi, exp from shallow_water_domain import * from Numeric import zeros, Float #from analytic_dam_sudi import AnalyticDam h0=5.0 h1=10.0 #analytical_sol=AnalyticDam(h0,h1) """ def newLinePlot(title='Simple Plot'): import Gnuplot gg=Gnuplot.Gnuplot(persist=0) gg.title(title) gg('set data style linespoints') gg.xlabel('x') gg.ylabel('y') return gg def linePlot(gg, x1, y1, x2, y2): import Gnuplot plot1=Gnuplot.PlotItems.Data(x1.flat, y1.flat, with="linespoints") plot2=Gnuplot.PlotItems.Data(x2.flat, y2.flat, with="lines 3") gg.plot(plot1, plot2) """ 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.default_time_order = 2 domain.cfl = 1.0 #domain.limiter = "vanleer" def stage(x): y=zeros(len(x), Float) for i in range(len(x)): if x[i]<=1000.0: y[i]=10.0 else: y[i]=5.0 return y def stage_perturb(x): y=zeros(len(x), Float) for i in range(len(x)): if 800.0 <= x[i] <=1200.0: y[i]=10.0 else: y[i]=5.0 return y def stage_sincos(x): y=zeros(len(x), Float) for i in range(len(x)): y[i] = 5+exp(cos(pi*x[i]*0.001))+sin(pi*x[i]*0.0005)*sin(pi*x[i]*0.0005) return y def elevation_box(x): y=zeros(len(x), Float) for i in range(len(x)): if 500.0 <= x[i] <= 1500.0: y[i] = 2.5 else: y[i] = 0.0 return y def elevation_parabol(x): y=zeros(len(x), Float) for i in range(len(x)): if 1400.0 <= x[i] <= 1600.0: y[i] = 1.25*(1+cos(0.01*pi*(x[i]-500))) else: y[i] = 0.0 return y def elevation_sincos(x): y=zeros(len(x), Float) for i in range(len(x)): y[i] = sin(pi*x[i]*0.0005)*sin(pi*x[i]*0.0005) return y def xmom_sincos(x): y=zeros(len(x), Float) for i in range(len(x)): y[i] = sin(cos(pi*x[i]*0.001)) return y domain.set_quantity('stage',stage_perturb) domain.set_quantity('elevation', elevation_box) #domain.set_quantity('xmomentum', xmom_sincos) #domain.order=domain.default_order print "domain order", domain.order domain.set_boundary({'exterior':Reflective_boundary(domain)}) X=domain.vertices C=domain.centroids #plot1x=newLinePlot("Height") #plot2x=newLinePlot("Momentum") import time t0=time.time() yieldstep=45.0 #30.0 finaltime=45.0 #20.0 print "integral", domain.quantities['stage'].get_integral() for t in domain.evolve(yieldstep=yieldstep, finaltime=finaltime): domain.write_time() print "integral", domain.quantities['stage'].get_integral() if t>0.0: HeightQ=domain.quantities['stage'].vertex_values MomentumQ=domain.quantities['xmomentum'].vertex_values ElevationQ=domain.quantities['elevation'].vertex_values #h, uh=analytical_sol(X.flat, domain.time) #linePlot(plot1x, X, HeightQ, X, h) #linePlot(plot2x, X, MomentumQ, X, uh) #print "press return" #pass from pylab import clf,plot,title,xlabel,ylabel,legend,savefig,show,hold,subplot,ion #print 'Test1' ion() hold(False) #clf() #print 'test 2' plot1 = subplot(211) #print 'test 3' #print 'Test4' plot(X,ElevationQ,X,HeightQ) #plot1.set_ylim([9.99,10.01]) xlabel('Position') ylabel('Stage') #legend( ('Bed Elevation', 'Numerical Solution'), # 'upper right', shadow=False) #legend(('Analytical Solution', 'Numerical Solution'), # 'lower right', shadow=False) plot2 = subplot(212) plot(X,MomentumQ) #plot2.set_ylim([-1,1]) #legend( ('Numerical Solution', 'for momentum'), # 'upper right', shadow=False) xlabel('Position') ylabel('Xmomentum') file = "dam_h_" #file += str(number_of_cells[i]) file += ".eps" #savefig(file) #show() print 'That took %.2f seconds'%(time.time()-t0) raw_input("Press any key")