Exemplo n.º 1
0
#     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://centralupwind*.png -mf type=png:fps=10 -ovc lavc ' + \
#           '-lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o centralupwind.avi')
# os.system('rm -rf centralupwind_*.png')


# interpolation based derivative
xx = numpy.zeros(2 * n + 1)
xx[:n] = x[:-1]
xx[n:] = x + x[-1] - x[0]
gamma = 2.0 / dx
da = interp_1d_grad_coef(n, xx[: n + 6], gamma)

u = numpy.ones(n + 1)
u[x < 0] = 0.0
u[-1] = u[0]
u0 = numpy.zeros(n + 1)
uu = numpy.zeros(3 * n + 1)
du = numpy.zeros([n + 1, nstage])
for i in range(20001):
    if i % 20 == 0:
        print "%d / %d" % (i, 20000)
        pylab.cla()
        pylab.plot(x, u, "+-")
        pylab.ylim([-0.5, 1.5])
        pylab.title("t = %f" % (i * dt))
        pylab.savefig("interpupwind_%04d.png" % int(i * dt * 10 / 2))
Exemplo n.º 2
0
#     uu[:n] = u[:-1]; uu[n:2*n] = u[:-1]; uu[2*n:] = u
#     du[:,istage] = -cp * uu[n+1:2*n+2] - cc * uu[n:2*n+1] - cm * uu[n-1:2*n]
#     u[:] = u0
#     for jstage in range(istage + 1):
#       u += du[:,jstage] * dt * stages.beta[istage][jstage]
# os.system('mencoder mf://centralrand_*.png -mf type=png:fps=10 -ovc lavc ' + \
#           '-lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o centralrand.avi')
# os.system('rm -rf centralrand_*.png')
# stop


# interpolation based derivative
gamma = 2.0 / (x[1:] - x[:-1]).mean()
da = numpy.zeros([2*n+1, n+1])
for i in range(n+1):
  da[:,i] = interp_1d_grad_coef(n,xx[i:2*n+1+i],gamma)

u = numpy.exp(-25*x**2)
#u[:] = 1.0
#u[x>0] = 0.0
#u[-1] = u[0]
u0 = numpy.zeros(n+1)
uu = numpy.zeros(3*n+1)
du = numpy.zeros([n+1, nstage])
for i in range(20001):
  if i % 2000 == 0:
    print '%d / %d' % (i, 20000)
    pylab.cla()
    pylab.plot(x,u,'+-')
    pylab.plot(linspace(-1,1,1000),numpy.exp(-25*linspace(-1,1,1000)**2),':k')
    pylab.ylim([-0.2,1.1])
Exemplo n.º 3
0
    ddddu = dddu[1:] - dddu[:-1]
    du[:,istage] += 0.002*dddu[n-2:2*n-1] / dx
    u[:] = u0
    for jstage in range(istage + 1):
      u += du[:,jstage] * dt * stages.beta[istage][jstage]
os.system('mencoder mf://centraldiff_*.png -mf type=png:fps=10 -ovc lavc ' + \
          '-lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o centraldiff.avi')
os.system('rm -rf centraldiff_*.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.ones(n+1)
u[x < 0] = 0.0
u[-1] = u[0]
u0 = numpy.zeros(n+1)
uu = numpy.zeros(3*n+1)
du = numpy.zeros([n+1, nstage])
for i in range(2001):
  if i % 20 == 0:
    print '%d / %d' % (i, 20000)
    pylab.cla()
    pylab.plot(x,u,'+-')
    pylab.ylim([-0.5,1.5])
    pylab.title('t = %f' % (i * dt))
    pylab.savefig('interpdiff_%04d.png' % int(i*dt*10/2))