# uu[:n] = u[:-1]; uu[n:2*n] = u[:-1]; uu[2*n:] = u # du[:,istage] = -(uu[n+1:2*n+2] - uu[n-1:2*n]) / (2.0*dx) # u[:] = u0 # for jstage in range(istage + 1): # u += du[:,jstage] * dt * stages.beta[istage][jstage] # os.system('mencoder mf://central_*.png -mf type=png:fps=10 -ovc lavc ' + \ # '-lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o central.avi') # os.system('rm -rf central_*.png') # interpolation based derivative gamma = 2.0 / dx xx = numpy.zeros(2*n+1) xx[:n] = x[:-1] xx[n:] = x + x[-1] - x[0] da = interp_1d_grad_coef(n,xx,gamma) u = numpy.exp(-25*x**2) u = numpy.cos(-25*x) u0 = numpy.zeros(n+1) uu = numpy.zeros(3*n+1) du = numpy.zeros([n+1, nstage]) for i in range(1001): if i % 20 == 0: print '%d / %d' % (i, 20000) pylab.cla() pylab.plot(x,u,'+-') pylab.ylim([-0.5,1.0]) pylab.title('t = %f' % (i * dt)) pylab.savefig('periodic_interp_%04d.png' % int(i*dt*10/2)) u0[:] = u
# du[:,1,istage] = (uu[2:,0] - uu[:-2,0]) / (2.0*dx) # u[:,:] = u0 # for jstage in range(istage + 1): # u += du[:,:,jstage] * dt * stages.beta[istage][jstage] # u[0,0] = 0.0; u[-1,0] = 0.0 # # u[0,1] = u[1,1]; u[-1,1] = u[-2,1] # os.system('mencoder mf://wave_central_*.png -mf type=png:fps=10 -ovc lavc ' + \ # '-lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o wave_central.avi') # os.system('rm -rf wave_central_*.png') # interpolation based derivative gamma = 2.0 / dx da = numpy.zeros([n+1, n+1]) for i in range(n+1): da[:,i] = interp_1d_grad_coef(i,x,gamma) u = numpy.zeros([n+1, 2]) u[:,0] = numpy.exp(-25*x**2) u[:,1] = u[:,0] u0 = numpy.zeros([n+1, 2]) du = numpy.zeros([n+1, 2, nstage]) for i in range(1001): if i % 20 == 0: print '%d / %d' % (i, 20000) pylab.cla() pylab.plot(x,u,'+-') pylab.ylim([-2.0,2.0]) pylab.title('t = %f' % (i * dt)) pylab.savefig('wave_interp_%04d.png' % int(i*dt*10/2)) u0[:,:] = u
# pylab.matplotlib.interactive(True) n = 50 s = numpy.linspace(-1, 1, n+1) dx = s[1] - s[0] gamma = 2.0 / dx dt = 0.005 stages = rungekutta.runge6 nstage = len(stages.alpha) # interpolation based derivative # x = numpy.sin(s * numpy.pi / 2) x = s da = numpy.zeros([n+1, n+1]) for i in range(1,n): if i < n - i: da[:2*i+1,i] = interp_1d_grad_coef(i,s[:2*i+1],gamma) else: # da[2*i-n:,i] = interp_1d_grad_coef(n-i,s[2*i-n:],gamma) da[:,i] = interp_1d_grad_coef(i,s,gamma) # da[:,i] /= numpy.cos(s[i] * numpy.pi / 2) pylab.plot(x, da, '+-') # pylab.show() # stop u = numpy.exp(-x**2*10) u = numpy.cos(-(x+1)*10) u0 = numpy.zeros(n+1) du = numpy.zeros([n+1, nstage]) for i in range(1001): if i % 20 == 0: print '%d / %d' % (i, 20000)
# for jstage in range(istage + 1): # u += du[:,:,jstage] * dt * stages.beta[istage][jstage] # u[0,0] = 0.0; u[-1,0] = 0.0 # # u[0,1] = u[1,1]; u[-1,1] = u[-2,1] # os.system('mencoder mf://wave_central_*.png -mf type=png:fps=10 -ovc lavc ' + \ # '-lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o wave_central.avi') # os.system('rm -rf wave_central_*.png') # interpolation based derivative gamma = 2.0 / dx da1 = numpy.zeros([n+1, n+1]) da2 = numpy.zeros([n+1, n+1]) for i in range(n+1): if i < n - i: da1[:2*i+1,i] = interp_1d_grad_coef(i,x[:2*i+1],gamma) da2[:,i] = interp_1d_grad_coef(i,x,gamma) else: da1[:,i] = interp_1d_grad_coef(i,x,gamma) da2[2*i-n:,i] = interp_1d_grad_coef(n-i,x[2*i-n:],gamma) #pylab.plot(da[:,0], '+-') #pylab.plot(da[:,n/2], '+-') #stop u = numpy.zeros([n+1, 2]) u[:,0] = numpy.exp(-25*x**2) u0 = numpy.zeros([n+1, 2]) du = numpy.zeros([n+1, 2, nstage]) for i in range(1001): if i % 10 == 0: print '%d / %d' % (i, 20000)