# 6. plotting a travelling soliton print "creating video" figures = [] xsmin, xsmax = Xs.min(), Xs.max() # it turns out python can't accomodate a list bigger than 3000 if Ncycle < 1000: for i in range(Ncycle): fig = figure() ylim(xsmin, xsmax) plot(Xs[i]) print "video %d" %i figures.append(fig) createvideo(figures,prefix=0, outputdir=dirname) else: #we need to parallelize the loop, or else it will be too slow #http://stackoverflow.com/questions/6652124/naive-and-easiest-way-to-decompose-independent-loop-into-parallel-threads-proces cycles = split(arange(Ncycle), Ncycle / 1000) import time import tempfile directory = tempfile.mkdtemp() from multiprocessing import Pool def f(c): for i in c: figure() ylim(xsmin, xsmax) plot(Xs[i]) print "video %d" %i
dt = sqrt(.125) Time = linspace(0, Ncycle * dt, num=Ncycle) Cycles = Time * 2 * sin(pi / N / 2) alpha = 2.25 beta = 8 def evolve(X, t=0): D = centralderivative(dx, N) v = -alpha * dot(D, X) - 1. / 24 * dot(D * D * D, X) return v # the meat of the code is in this very single line Xs = odeint(evolve, Xs[0], Time) figures = [] xsmin, xsmax = Xs.min(), Xs.max() # it turns out python can't accomodate a list bigger than 3000 for i in range(Ncycle): fig = figure() ylim(xsmin, xsmax) plot(Xs[i]) print "video %d" %i figures.append(fig) createvideo(figures,prefix=0)
savefig(dirname + "/normalmodes.png") # 6. plotting a travelling soliton print "creating video" figures = [] xsmin, xsmax = Xs.min(), Xs.max() # it turns out python can't accomodate a list bigger than 3000 if Ncycle < 1000: for i in range(Ncycle): fig = figure() ylim(xsmin, xsmax) plot(Xs[i]) print "video %d" % i figures.append(fig) createvideo(figures, prefix=0, outputdir=dirname) else: #we need to parallelize the loop, or else it will be too slow #http://stackoverflow.com/questions/6652124/naive-and-easiest-way-to-decompose-independent-loop-into-parallel-threads-proces cycles = split(arange(Ncycle), Ncycle / 1000) import time import tempfile directory = tempfile.mkdtemp() from multiprocessing import Pool def f(c): for i in c: figure() ylim(xsmin, xsmax) plot(Xs[i]) print "video %d" % i