%matplotlib inline
import numpy as np
from clawpack import pyclaw
from clawpack import riemann
def setup(scheme='minmod',cfl_max=0.9,IC='gauss_square',mx=100):
if 'weno' in scheme:
solver = pyclaw.SharpClawSolver1D(riemann.advection_1D)
solver.weno_order = int(scheme[-1]) #weno5, weno7, ...
else:
solver = pyclaw.ClawSolver1D(riemann.advection_1D)
solver.bc_lower[0] = pyclaw.BC.periodic
solver.bc_upper[0] = pyclaw.BC.periodic
if scheme in ('minmod','superbee','MC','vanleer'):
solver.limiters = getattr(pyclaw.limiters.tvd,scheme)
#elif scheme == 'CT':
#solver.limiters = pyclaw.limiters.tvd.cada_torrilhon_limiter
elif scheme == 'Lax-Wendroff':
solver.limiters = 0
elif scheme == 'first-order':
solver.order = 1
else raise Exception('Unrecognized limiter')
solver.cfl_max = cfl_max
solver.cfl_desired = cfl_max*0.9
x = pyclaw.Dimension('x',0.0,1.0,mx)
domain = pyclaw.Domain(x)
num_eqn = 1
state = pyclaw.State(domain,num_eqn)
state.problem_data['u']=1.
grid = state.grid
xc = grid.x.centers
if IC=='gauss_square':
beta=200.; x0=0.3
state.q[0,:] = np.exp(-beta * (xc-x0)**2) + (xc>0.6)*(xc<0.8)
elif IC=='wavepacket':
beta=100.; x0=0.5
state.q[0,:] = np.exp(-beta * (xc-x0)**2) * np.sin(80.*xc)
else:
raise Exception('Unrecognized initial condition.')
claw = pyclaw.Controller()
claw.solution = pyclaw.Solution(state,domain)
claw.solver = solver
claw.keep_copy = True
claw.output_format = None
claw.tfinal =10.0
return claw
results = []
schemes = ('first-order','Lax-Wendroff','minmod','superbee','MC','vanleer','weno5','weno7','weno9')
for scheme in schemes:
claw = setup(scheme=scheme)
claw.run()
results.append(claw.frames)
2014-03-10 06:22:35,749 INFO CLAW: Solution 0 computed for time t=0.000000 2014-03-10 06:22:35,769 INFO CLAW: Solution 1 computed for time t=1.000000 2014-03-10 06:22:35,785 INFO CLAW: Solution 2 computed for time t=2.000000 2014-03-10 06:22:35,801 INFO CLAW: Solution 3 computed for time t=3.000000 2014-03-10 06:22:35,816 INFO CLAW: Solution 4 computed for time t=4.000000 2014-03-10 06:22:35,832 INFO CLAW: Solution 5 computed for time t=5.000000 2014-03-10 06:22:35,847 INFO CLAW: Solution 6 computed for time t=6.000000 2014-03-10 06:22:35,866 INFO CLAW: Solution 7 computed for time t=7.000000 2014-03-10 06:22:35,883 INFO CLAW: Solution 8 computed for time t=8.000000 2014-03-10 06:22:35,899 INFO CLAW: Solution 9 computed for time t=9.000000 2014-03-10 06:22:35,916 INFO CLAW: Solution 10 computed for time t=10.000000 2014-03-10 06:22:35,918 INFO CLAW: Solution 0 computed for time t=0.000000 2014-03-10 06:22:35,934 INFO CLAW: Solution 1 computed for time t=1.000000 2014-03-10 06:22:35,950 INFO CLAW: Solution 2 computed for time t=2.000000 2014-03-10 06:22:35,967 INFO CLAW: Solution 3 computed for time t=3.000000 2014-03-10 06:22:35,983 INFO CLAW: Solution 4 computed for time t=4.000000 2014-03-10 06:22:36,001 INFO CLAW: Solution 5 computed for time t=5.000000 2014-03-10 06:22:36,017 INFO CLAW: Solution 6 computed for time t=6.000000 2014-03-10 06:22:36,034 INFO CLAW: Solution 7 computed for time t=7.000000 2014-03-10 06:22:36,051 INFO CLAW: Solution 8 computed for time t=8.000000 2014-03-10 06:22:36,068 INFO CLAW: Solution 9 computed for time t=9.000000 2014-03-10 06:22:36,084 INFO CLAW: Solution 10 computed for time t=10.000000 2014-03-10 06:22:36,086 INFO CLAW: Solution 0 computed for time t=0.000000 2014-03-10 06:22:36,102 INFO CLAW: Solution 1 computed for time t=1.000000 2014-03-10 06:22:36,120 INFO CLAW: Solution 2 computed for time t=2.000000 2014-03-10 06:22:36,136 INFO CLAW: Solution 3 computed for time t=3.000000 2014-03-10 06:22:36,153 INFO CLAW: Solution 4 computed for time t=4.000000 2014-03-10 06:22:36,169 INFO CLAW: Solution 5 computed for time t=5.000000 2014-03-10 06:22:36,186 INFO CLAW: Solution 6 computed for time t=6.000000 2014-03-10 06:22:36,205 INFO CLAW: Solution 7 computed for time t=7.000000 2014-03-10 06:22:36,221 INFO CLAW: Solution 8 computed for time t=8.000000 2014-03-10 06:22:36,237 INFO CLAW: Solution 9 computed for time t=9.000000 2014-03-10 06:22:36,253 INFO CLAW: Solution 10 computed for time t=10.000000 2014-03-10 06:22:36,255 INFO CLAW: Solution 0 computed for time t=0.000000 2014-03-10 06:22:36,271 INFO CLAW: Solution 1 computed for time t=1.000000 2014-03-10 06:22:36,288 INFO CLAW: Solution 2 computed for time t=2.000000 2014-03-10 06:22:36,304 INFO CLAW: Solution 3 computed for time t=3.000000 2014-03-10 06:22:36,320 INFO CLAW: Solution 4 computed for time t=4.000000 2014-03-10 06:22:36,336 INFO CLAW: Solution 5 computed for time t=5.000000 2014-03-10 06:22:36,353 INFO CLAW: Solution 6 computed for time t=6.000000 2014-03-10 06:22:36,369 INFO CLAW: Solution 7 computed for time t=7.000000 2014-03-10 06:22:36,386 INFO CLAW: Solution 8 computed for time t=8.000000 2014-03-10 06:22:36,402 INFO CLAW: Solution 9 computed for time t=9.000000 2014-03-10 06:22:36,419 INFO CLAW: Solution 10 computed for time t=10.000000 2014-03-10 06:22:36,421 INFO CLAW: Solution 0 computed for time t=0.000000 2014-03-10 06:22:36,437 INFO CLAW: Solution 1 computed for time t=1.000000 2014-03-10 06:22:36,454 INFO CLAW: Solution 2 computed for time t=2.000000 2014-03-10 06:22:36,471 INFO CLAW: Solution 3 computed for time t=3.000000 2014-03-10 06:22:36,487 INFO CLAW: Solution 4 computed for time t=4.000000 2014-03-10 06:22:36,503 INFO CLAW: Solution 5 computed for time t=5.000000 2014-03-10 06:22:36,520 INFO CLAW: Solution 6 computed for time t=6.000000 2014-03-10 06:22:36,536 INFO CLAW: Solution 7 computed for time t=7.000000 2014-03-10 06:22:36,553 INFO CLAW: Solution 8 computed for time t=8.000000 2014-03-10 06:22:36,569 INFO CLAW: Solution 9 computed for time t=9.000000 2014-03-10 06:22:36,590 INFO CLAW: Solution 10 computed for time t=10.000000 2014-03-10 06:22:36,592 INFO CLAW: Solution 0 computed for time t=0.000000 2014-03-10 06:22:36,609 INFO CLAW: Solution 1 computed for time t=1.000000 2014-03-10 06:22:36,625 INFO CLAW: Solution 2 computed for time t=2.000000 2014-03-10 06:22:36,642 INFO CLAW: Solution 3 computed for time t=3.000000 2014-03-10 06:22:36,659 INFO CLAW: Solution 4 computed for time t=4.000000 2014-03-10 06:22:36,675 INFO CLAW: Solution 5 computed for time t=5.000000 2014-03-10 06:22:36,692 INFO CLAW: Solution 6 computed for time t=6.000000 2014-03-10 06:22:36,709 INFO CLAW: Solution 7 computed for time t=7.000000 2014-03-10 06:22:36,726 INFO CLAW: Solution 8 computed for time t=8.000000 2014-03-10 06:22:36,742 INFO CLAW: Solution 9 computed for time t=9.000000 2014-03-10 06:22:36,759 INFO CLAW: Solution 10 computed for time t=10.000000 2014-03-10 06:22:36,761 INFO CLAW: Solution 0 computed for time t=0.000000 2014-03-10 06:22:36,862 INFO CLAW: Solution 1 computed for time t=1.000000 2014-03-10 06:22:36,964 INFO CLAW: Solution 2 computed for time t=2.000000 2014-03-10 06:22:37,063 INFO CLAW: Solution 3 computed for time t=3.000000 2014-03-10 06:22:37,162 INFO CLAW: Solution 4 computed for time t=4.000000 2014-03-10 06:22:37,261 INFO CLAW: Solution 5 computed for time t=5.000000 2014-03-10 06:22:37,360 INFO CLAW: Solution 6 computed for time t=6.000000 2014-03-10 06:22:37,459 INFO CLAW: Solution 7 computed for time t=7.000000 2014-03-10 06:22:37,560 INFO CLAW: Solution 8 computed for time t=8.000000 2014-03-10 06:22:37,660 INFO CLAW: Solution 9 computed for time t=9.000000 2014-03-10 06:22:37,762 INFO CLAW: Solution 10 computed for time t=10.000000 2014-03-10 06:22:37,764 INFO CLAW: Solution 0 computed for time t=0.000000 2014-03-10 06:22:37,864 INFO CLAW: Solution 1 computed for time t=1.000000 2014-03-10 06:22:37,969 INFO CLAW: Solution 2 computed for time t=2.000000 2014-03-10 06:22:38,075 INFO CLAW: Solution 3 computed for time t=3.000000 2014-03-10 06:22:38,177 INFO CLAW: Solution 4 computed for time t=4.000000 2014-03-10 06:22:38,279 INFO CLAW: Solution 5 computed for time t=5.000000 2014-03-10 06:22:38,382 INFO CLAW: Solution 6 computed for time t=6.000000 2014-03-10 06:22:38,487 INFO CLAW: Solution 7 computed for time t=7.000000 2014-03-10 06:22:38,594 INFO CLAW: Solution 8 computed for time t=8.000000 2014-03-10 06:22:38,697 INFO CLAW: Solution 9 computed for time t=9.000000 2014-03-10 06:22:38,799 INFO CLAW: Solution 10 computed for time t=10.000000 2014-03-10 06:22:38,801 INFO CLAW: Solution 0 computed for time t=0.000000 2014-03-10 06:22:38,906 INFO CLAW: Solution 1 computed for time t=1.000000 2014-03-10 06:22:39,016 INFO CLAW: Solution 2 computed for time t=2.000000 2014-03-10 06:22:39,123 INFO CLAW: Solution 3 computed for time t=3.000000 2014-03-10 06:22:39,230 INFO CLAW: Solution 4 computed for time t=4.000000 2014-03-10 06:22:39,337 INFO CLAW: Solution 5 computed for time t=5.000000 2014-03-10 06:22:39,444 INFO CLAW: Solution 6 computed for time t=6.000000 2014-03-10 06:22:39,550 INFO CLAW: Solution 7 computed for time t=7.000000 2014-03-10 06:22:39,658 INFO CLAW: Solution 8 computed for time t=8.000000 2014-03-10 06:22:39,768 INFO CLAW: Solution 9 computed for time t=9.000000 2014-03-10 06:22:39,876 INFO CLAW: Solution 10 computed for time t=10.000000
import matplotlib
def animate(results,ymin=-0.1):
fig = plt.figure(figsize=(12,8))
gs1 = matplotlib.gridspec.GridSpec(3, 3)
gs1.update(wspace=0.,hspace=0.)
ax0 = plt.subplot(gs1[0,0]);
ax1 = plt.subplot(gs1[0,1]);
ax2 = plt.subplot(gs1[0,2]);
ax3 = plt.subplot(gs1[1,0]);
ax4 = plt.subplot(gs1[1,1])
ax5 = plt.subplot(gs1[1,2])
ax6 = plt.subplot(gs1[2,0])
ax7 = plt.subplot(gs1[2,1])
ax8 = plt.subplot(gs1[2,2])
axes = (ax0,ax1,ax2,ax3,ax4,ax5,ax6,ax7,ax8)
ax1.yaxis.set_ticklabels(())
ax2.yaxis.set_ticklabels(())
ax4.yaxis.set_ticklabels(())
ax5.yaxis.set_ticklabels(())
ax7.yaxis.set_ticklabels(())
ax8.yaxis.set_ticklabels(())
lines = [0]*len(schemes)
for i in range(len(lines)):
lines[i], = axes[i].plot([], [], lw=2)
for i,ax in enumerate(axes):
ax.set_xlim(0,1); ax.set_ylim(ymin,1.3)
#ax.legend( [schemes[i] ] )
ax.set_title(schemes[i], x = 0.5, y=0.85 )
xc = results[0][0].p_centers[0]
def fplot(frame_number):
for i, line in enumerate(lines):
line.set_data(xc,results[i][frame_number].q[0,:])
return lines,
return animation.FuncAnimation(fig, fplot, frames=len(claw.frames), interval=30)
animate(results)
results = []
for scheme in schemes:
claw = setup(scheme=scheme,IC='wavepacket',mx=300)
claw.run()
results.append(claw.frames)
2014-03-10 06:23:36,512 INFO CLAW: Solution 0 computed for time t=0.000000 2014-03-10 06:23:36,562 INFO CLAW: Solution 1 computed for time t=1.000000 2014-03-10 06:23:36,608 INFO CLAW: Solution 2 computed for time t=2.000000 2014-03-10 06:23:36,654 INFO CLAW: Solution 3 computed for time t=3.000000 2014-03-10 06:23:36,702 INFO CLAW: Solution 4 computed for time t=4.000000 2014-03-10 06:23:36,748 INFO CLAW: Solution 5 computed for time t=5.000000 2014-03-10 06:23:36,794 INFO CLAW: Solution 6 computed for time t=6.000000 2014-03-10 06:23:36,840 INFO CLAW: Solution 7 computed for time t=7.000000 2014-03-10 06:23:36,886 INFO CLAW: Solution 8 computed for time t=8.000000 2014-03-10 06:23:36,932 INFO CLAW: Solution 9 computed for time t=9.000000 2014-03-10 06:23:36,978 INFO CLAW: Solution 10 computed for time t=10.000000 2014-03-10 06:23:36,980 INFO CLAW: Solution 0 computed for time t=0.000000 2014-03-10 06:23:37,026 INFO CLAW: Solution 1 computed for time t=1.000000 2014-03-10 06:23:37,073 INFO CLAW: Solution 2 computed for time t=2.000000 2014-03-10 06:23:37,124 INFO CLAW: Solution 3 computed for time t=3.000000 2014-03-10 06:23:37,171 INFO CLAW: Solution 4 computed for time t=4.000000 2014-03-10 06:23:37,218 INFO CLAW: Solution 5 computed for time t=5.000000 2014-03-10 06:23:37,266 INFO CLAW: Solution 6 computed for time t=6.000000 2014-03-10 06:23:37,313 INFO CLAW: Solution 7 computed for time t=7.000000 2014-03-10 06:23:37,361 INFO CLAW: Solution 8 computed for time t=8.000000 2014-03-10 06:23:37,409 INFO CLAW: Solution 9 computed for time t=9.000000 2014-03-10 06:23:37,456 INFO CLAW: Solution 10 computed for time t=10.000000 2014-03-10 06:23:37,458 INFO CLAW: Solution 0 computed for time t=0.000000 2014-03-10 06:23:37,506 INFO CLAW: Solution 1 computed for time t=1.000000 2014-03-10 06:23:37,556 INFO CLAW: Solution 2 computed for time t=2.000000 2014-03-10 06:23:37,609 INFO CLAW: Solution 3 computed for time t=3.000000 2014-03-10 06:23:37,656 INFO CLAW: Solution 4 computed for time t=4.000000 2014-03-10 06:23:37,704 INFO CLAW: Solution 5 computed for time t=5.000000 2014-03-10 06:23:37,753 INFO CLAW: Solution 6 computed for time t=6.000000 2014-03-10 06:23:37,800 INFO CLAW: Solution 7 computed for time t=7.000000 2014-03-10 06:23:37,849 INFO CLAW: Solution 8 computed for time t=8.000000 2014-03-10 06:23:37,896 INFO CLAW: Solution 9 computed for time t=9.000000 2014-03-10 06:23:37,945 INFO CLAW: Solution 10 computed for time t=10.000000 2014-03-10 06:23:37,947 INFO CLAW: Solution 0 computed for time t=0.000000 2014-03-10 06:23:37,994 INFO CLAW: Solution 1 computed for time t=1.000000 2014-03-10 06:23:38,043 INFO CLAW: Solution 2 computed for time t=2.000000 2014-03-10 06:23:38,091 INFO CLAW: Solution 3 computed for time t=3.000000 2014-03-10 06:23:38,139 INFO CLAW: Solution 4 computed for time t=4.000000 2014-03-10 06:23:38,191 INFO CLAW: Solution 5 computed for time t=5.000000 2014-03-10 06:23:38,240 INFO CLAW: Solution 6 computed for time t=6.000000 2014-03-10 06:23:38,289 INFO CLAW: Solution 7 computed for time t=7.000000 2014-03-10 06:23:38,337 INFO CLAW: Solution 8 computed for time t=8.000000 2014-03-10 06:23:38,390 INFO CLAW: Solution 9 computed for time t=9.000000 2014-03-10 06:23:38,442 INFO CLAW: Solution 10 computed for time t=10.000000 2014-03-10 06:23:38,444 INFO CLAW: Solution 0 computed for time t=0.000000 2014-03-10 06:23:38,490 INFO CLAW: Solution 1 computed for time t=1.000000 2014-03-10 06:23:38,545 INFO CLAW: Solution 2 computed for time t=2.000000 2014-03-10 06:23:38,597 INFO CLAW: Solution 3 computed for time t=3.000000 2014-03-10 06:23:38,644 INFO CLAW: Solution 4 computed for time t=4.000000 2014-03-10 06:23:38,691 INFO CLAW: Solution 5 computed for time t=5.000000 2014-03-10 06:23:38,738 INFO CLAW: Solution 6 computed for time t=6.000000 2014-03-10 06:23:38,785 INFO CLAW: Solution 7 computed for time t=7.000000 2014-03-10 06:23:38,833 INFO CLAW: Solution 8 computed for time t=8.000000 2014-03-10 06:23:38,879 INFO CLAW: Solution 9 computed for time t=9.000000 2014-03-10 06:23:38,927 INFO CLAW: Solution 10 computed for time t=10.000000 2014-03-10 06:23:38,929 INFO CLAW: Solution 0 computed for time t=0.000000 2014-03-10 06:23:38,974 INFO CLAW: Solution 1 computed for time t=1.000000 2014-03-10 06:23:39,021 INFO CLAW: Solution 2 computed for time t=2.000000 2014-03-10 06:23:39,069 INFO CLAW: Solution 3 computed for time t=3.000000 2014-03-10 06:23:39,120 INFO CLAW: Solution 4 computed for time t=4.000000 2014-03-10 06:23:39,167 INFO CLAW: Solution 5 computed for time t=5.000000 2014-03-10 06:23:39,215 INFO CLAW: Solution 6 computed for time t=6.000000 2014-03-10 06:23:39,262 INFO CLAW: Solution 7 computed for time t=7.000000 2014-03-10 06:23:39,310 INFO CLAW: Solution 8 computed for time t=8.000000 2014-03-10 06:23:39,359 INFO CLAW: Solution 9 computed for time t=9.000000 2014-03-10 06:23:39,407 INFO CLAW: Solution 10 computed for time t=10.000000 2014-03-10 06:23:39,409 INFO CLAW: Solution 0 computed for time t=0.000000 2014-03-10 06:23:39,741 INFO CLAW: Solution 1 computed for time t=1.000000 2014-03-10 06:23:40,085 INFO CLAW: Solution 2 computed for time t=2.000000 2014-03-10 06:23:40,447 INFO CLAW: Solution 3 computed for time t=3.000000 2014-03-10 06:23:40,805 INFO CLAW: Solution 4 computed for time t=4.000000 2014-03-10 06:23:41,144 INFO CLAW: Solution 5 computed for time t=5.000000 2014-03-10 06:23:41,492 INFO CLAW: Solution 6 computed for time t=6.000000 2014-03-10 06:23:41,830 INFO CLAW: Solution 7 computed for time t=7.000000 2014-03-10 06:23:42,166 INFO CLAW: Solution 8 computed for time t=8.000000 2014-03-10 06:23:42,504 INFO CLAW: Solution 9 computed for time t=9.000000 2014-03-10 06:23:42,840 INFO CLAW: Solution 10 computed for time t=10.000000 2014-03-10 06:23:42,842 INFO CLAW: Solution 0 computed for time t=0.000000 2014-03-10 06:23:43,204 INFO CLAW: Solution 1 computed for time t=1.000000 2014-03-10 06:23:43,573 INFO CLAW: Solution 2 computed for time t=2.000000 2014-03-10 06:23:43,938 INFO CLAW: Solution 3 computed for time t=3.000000 2014-03-10 06:23:44,304 INFO CLAW: Solution 4 computed for time t=4.000000 2014-03-10 06:23:44,669 INFO CLAW: Solution 5 computed for time t=5.000000 2014-03-10 06:23:45,033 INFO CLAW: Solution 6 computed for time t=6.000000 2014-03-10 06:23:45,398 INFO CLAW: Solution 7 computed for time t=7.000000 2014-03-10 06:23:45,766 INFO CLAW: Solution 8 computed for time t=8.000000 2014-03-10 06:23:46,134 INFO CLAW: Solution 9 computed for time t=9.000000 2014-03-10 06:23:46,502 INFO CLAW: Solution 10 computed for time t=10.000000 2014-03-10 06:23:46,504 INFO CLAW: Solution 0 computed for time t=0.000000 2014-03-10 06:23:46,897 INFO CLAW: Solution 1 computed for time t=1.000000 2014-03-10 06:23:47,294 INFO CLAW: Solution 2 computed for time t=2.000000 2014-03-10 06:23:47,696 INFO CLAW: Solution 3 computed for time t=3.000000 2014-03-10 06:23:48,094 INFO CLAW: Solution 4 computed for time t=4.000000 2014-03-10 06:23:48,497 INFO CLAW: Solution 5 computed for time t=5.000000 2014-03-10 06:23:48,890 INFO CLAW: Solution 6 computed for time t=6.000000 2014-03-10 06:23:49,283 INFO CLAW: Solution 7 computed for time t=7.000000 2014-03-10 06:23:49,687 INFO CLAW: Solution 8 computed for time t=8.000000 2014-03-10 06:23:50,087 INFO CLAW: Solution 9 computed for time t=9.000000 2014-03-10 06:23:50,485 INFO CLAW: Solution 10 computed for time t=10.000000
animate(results,ymin=-1.2)