[5535] | 1 | import os |
---|
| 2 | from math import sqrt |
---|
[5587] | 3 | #from shallow_water_h import * |
---|
| 4 | from shallow_water_domain import * |
---|
[5535] | 5 | from Numeric import zeros, Float |
---|
| 6 | from analytic_dam_sudi import AnalyticDam |
---|
| 7 | |
---|
| 8 | h0=5.0 |
---|
| 9 | h1=10.0 |
---|
| 10 | |
---|
| 11 | analytical_sol=AnalyticDam(h0,h1) |
---|
| 12 | |
---|
| 13 | """ |
---|
| 14 | def newLinePlot(title='Simple Plot'): |
---|
| 15 | import Gnuplot |
---|
| 16 | gg=Gnuplot.Gnuplot(persist=0) |
---|
| 17 | gg.title(title) |
---|
| 18 | gg('set data style linespoints') |
---|
| 19 | gg.xlabel('x') |
---|
| 20 | gg.ylabel('y') |
---|
| 21 | return gg |
---|
| 22 | |
---|
| 23 | def linePlot(gg, x1, y1, x2, y2): |
---|
| 24 | import Gnuplot |
---|
| 25 | plot1=Gnuplot.PlotItems.Data(x1.flat, y1.flat, with="linespoints") |
---|
| 26 | plot2=Gnuplot.PlotItems.Data(x2.flat, y2.flat, with="lines 3") |
---|
| 27 | gg.plot(plot1, plot2) |
---|
| 28 | """ |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | print "TEST 1D-SOLUTION I" |
---|
| 32 | |
---|
| 33 | L=2000.0 |
---|
[5587] | 34 | N=400 |
---|
[5535] | 35 | |
---|
| 36 | cell_len=L/N |
---|
| 37 | |
---|
| 38 | points=zeros(N+1, Float) |
---|
| 39 | for i in range(N+1): |
---|
| 40 | points[i]=i*cell_len |
---|
| 41 | |
---|
| 42 | domain=Domain(points) |
---|
| 43 | |
---|
[5587] | 44 | domain.default_order = 2 |
---|
[5535] | 45 | domain.default_time_order = 1 |
---|
[5587] | 46 | domain.cfl = 1.0 |
---|
| 47 | domain.limiter = "vanleer" |
---|
[5535] | 48 | |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | def height(x): |
---|
| 52 | y=zeros(len(x), Float) |
---|
| 53 | for i in range (len(x)): |
---|
| 54 | if x[i]<=L/4.0: |
---|
| 55 | y[i]=0.0 #h0 |
---|
| 56 | elif x[i]<=3*L/4.0: |
---|
| 57 | y[i]=h1 |
---|
| 58 | else: |
---|
| 59 | y[i]=h0 |
---|
| 60 | return y |
---|
| 61 | |
---|
[5587] | 62 | domain.set_quantity('stage',height) #('height', height) |
---|
[5535] | 63 | domain.order=domain.default_order |
---|
| 64 | print "domain order", domain.order |
---|
| 65 | |
---|
| 66 | domain.set_boundary({'exterior':Reflective_boundary(domain)}) |
---|
| 67 | |
---|
| 68 | X=domain.vertices |
---|
| 69 | C=domain.centroids |
---|
| 70 | #plot1x=newLinePlot("Height") |
---|
| 71 | #plot2x=newLinePlot("Momentum") |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | import time |
---|
| 75 | t0=time.time() |
---|
| 76 | yieldstep=30.0 |
---|
[5587] | 77 | finaltime=20.0 |
---|
| 78 | print "integral", domain.quantities['stage'].get_integral() #['height'].get_integral() |
---|
[5535] | 79 | for t in domain.evolve(yieldstep=yieldstep, finaltime=finaltime): |
---|
| 80 | domain.write_time() |
---|
[5587] | 81 | print "integral", domain.quantities['stage'].get_integral() #['height'].get_integral() |
---|
[5535] | 82 | if t>0.0: |
---|
[5587] | 83 | HeightQ=domain.quantities['stage'].vertex_values #['height'].vertex_values |
---|
[5535] | 84 | MomentumQ=domain.quantities['xmomentum'].vertex_values |
---|
| 85 | h, uh=analytical_sol(X.flat, domain.time) |
---|
| 86 | #linePlot(plot1x, X, HeightQ, X, h) |
---|
| 87 | #linePlot(plot2x, X, MomentumQ, X, uh) |
---|
| 88 | #print "press return" |
---|
| 89 | #pass |
---|
| 90 | |
---|
| 91 | from pylab import plot,title,xlabel,ylabel,legend,savefig,show,hold,subplot |
---|
| 92 | #print 'Test1' |
---|
| 93 | hold(False) |
---|
| 94 | #print 'test 2' |
---|
| 95 | plot1 = subplot(211) |
---|
| 96 | #print 'test 3' |
---|
| 97 | |
---|
| 98 | plot(X,h,X,HeightQ) |
---|
| 99 | #print 'Test4' |
---|
| 100 | plot1.set_ylim([0,11]) |
---|
| 101 | xlabel('Position') |
---|
| 102 | ylabel('Stage') |
---|
| 103 | #legend(('Analytical Solution', 'Numerical Solution'), |
---|
| 104 | # 'lower right', shadow=False) |
---|
| 105 | plot2 = subplot(212) |
---|
| 106 | plot(X,uh,X,MomentumQ) |
---|
| 107 | #plot2.set_ylim([-5,35]) |
---|
| 108 | legend(('Analytical Solution', 'Numerical Solution'), |
---|
| 109 | 'lower right', shadow=False) |
---|
| 110 | |
---|
| 111 | xlabel('Position') |
---|
| 112 | ylabel('Xmomentum') |
---|
| 113 | |
---|
| 114 | file = "dam_h_" |
---|
| 115 | #file += str(number_of_cells[i]) |
---|
| 116 | file += ".eps" |
---|
| 117 | #savefig(file) |
---|
| 118 | show() |
---|
| 119 | |
---|
| 120 | print 'That took %.2f seconds'%(time.time()-t0) |
---|