import os from math import sqrt #from shallow_water_h import * 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=400 cell_len=L/N points=zeros(N+1, Float) for i in range(N+1): points[i]=i*cell_len domain=Domain(points) domain.default_order = 2 domain.default_time_order = 1 domain.cfl = 1.0 domain.limiter = "vanleer" def height(x): y=zeros(len(x), Float) for i in range (len(x)): if x[i]<=L/4.0: y[i]=0.0 #h0 elif x[i]<=3*L/4.0: y[i]=h1 else: y[i]=h0 return y domain.set_quantity('stage',height) #('height', height) 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=30.0 finaltime=20.0 print "integral", domain.quantities['stage'].get_integral() #['height'].get_integral() for t in domain.evolve(yieldstep=yieldstep, finaltime=finaltime): domain.write_time() print "integral", domain.quantities['stage'].get_integral() #['height'].get_integral() if t>0.0: HeightQ=domain.quantities['stage'].vertex_values #['height'].vertex_values MomentumQ=domain.quantities['xmomentum'].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 plot,title,xlabel,ylabel,legend,savefig,show,hold,subplot #print 'Test1' hold(False) #print 'test 2' plot1 = subplot(211) #print 'test 3' plot(X,h,X,HeightQ) #print 'Test4' plot1.set_ylim([0,11]) xlabel('Position') ylabel('Stage') #legend(('Analytical Solution', 'Numerical Solution'), # 'lower right', shadow=False) plot2 = subplot(212) plot(X,uh,X,MomentumQ) #plot2.set_ylim([-5,35]) legend(('Analytical Solution', 'Numerical Solution'), 'lower 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)