Exemplo n.º 1
0
#nus = [.5, .1, .05, .01, .005, 0.001, .0005, .0001, .00005, .00001, .000005, .000001]
nus = [.5, .1, .05, .01, .005, 0.001, .0005, .00005, .00001]
#nus = [.5, .1, .05, .01, .005]
ET = 1.
nxs = []
for nu in nus:
    nx = 25
    oldqoi = None
    f, ax = plt.subplots(3)
    l, l2 = [], []
    qois = []
    while True:
        print(nu, nx)
        x = np.linspace(0, np.pi, nx + 2)[:-1]
        dx = x[1] - x[0]
        u = geturec(nu=nu, x=x, evolution_time=ET, n_save_t=1)[:, -1]
        l.append(ax[0].plot(x, u, label=nx, lw=.5)[0])
        gradu = u.copy()
        gradu[1:-1] = (u[2:] - u[:-2]) / (2 * dx)
        gradu[-1] = (u[0] - u[-2]) / (2 * dx)
        gradu[0] = (u[1] - u[-1]) / (2 * dx)
        l2.append(ax[1].plot(x, gradu, label=nx, lw=.5)[0])
        qoi = np.max(np.abs(gradu))
        #qoi = x[np.argmax(gradu)]
        qois.append(qoi)
        if oldqoi is not None:
            print(qoi, oldqoi, np.max(gradu), np.abs(qoi - oldqoi) / qoi)
            if np.abs(qoi - oldqoi) / qoi < 1e-2:
                #if np.sqrt(np.sum((u[0::2] - oldu)**2)/oldu.size) < 1e-2:
                break
        oldqoi = qoi
Exemplo n.º 2
0
    return np.max(np.abs(gradu))


x1 = np.linspace(0, np.pi, 5002)[:-1]
dx1 = x1[1] - x1[0]
x2 = np.linspace(0, np.pi, 50002)[:-1]
dx2 = x1[1] - x1[0]
ET = 1.
np.random.seed(299)
#nus = np.random.uniform(0.00001, .00000005, 2)
nus = np.random.uniform(1e-4, 1e-5, 500)
logg = open('sampsagainagain.dat', 'w')
logg.write('nu,nx5000_4,nx50000_2,nx50000_4\n')
for nu in nus:
    print(nu)
    u1 = geturec(x=x1, nu=nu, evolution_time=ET)
    qoi1 = mgrad(u1[:, -1], dx=dx1)
    u2 = geturec(x=x2,
                 nu=nu,
                 evolution_time=ET,
                 convstrategy='2c',
                 diffstrategy='3c',
                 timestrategy='fe')
    qoi2 = mgrad(u2[:, -1], dx=dx2)
    print('ok...')
    u3 = geturec(x=x2, nu=nu, evolution_time=ET)
    qoi3 = mgrad(u3[:, -1], dx=dx2)
    print(nu, qoi1, qoi2, qoi3)
    logg.write(','.join([str(s) for s in [nu, qoi1, qoi2, qoi3]]) + '\n')
logg.close()
Exemplo n.º 3
0
# x points
nx = 7000
x = np.linspace(0, np.pi, nx + 2)[:-1]
dx = x[1] - x[0]

# prescribe u dt / dx = 0.01
evolution_time = 1.

# baseline viscosity
nu = 1e-5

n_save_t = 20
u_record = np.load('./urec%f.npy' % nu)
#u_record = geturec(nu=nu, x=x, evolution_time=evolution_time)
#np.save('urec%f'%nu, u_record)
dt = geturec(nu=nu, x=x, evolution_time=evolution_time, returndt=True)
nt = int(evolution_time / dt)
divider = int(nt / float(n_save_t))

# SVD the covariance matrix
psi, D, phi = np.linalg.svd(u_record)  # P D Q is the approximation

S = np.zeros((nx + 1, u_record.shape[1]))
mm = min(nx + 1, u_record.shape[1])
S[:mm, :mm] = np.diag(D)
assert (np.allclose(u_record, np.dot(psi,
                                     np.dot(S, phi))))  # check that a = P D Q
Q = np.dot(S, phi.T)
phi = phi.T

# choose # of modes to keep
Exemplo n.º 4
0
logg.write('nu,TOL,ET,nx')
for TOL in [1e-2]:
 for ET in ETs:
  for nu in nus:
    nx = 25
    oldqoi = None
    f, ax = plt.subplots(3)
    plt.subplots_adjust(bottom=-.8)
    l, l2 = [], []
    qois = []
    nxs = [nx]
    while True:
        print(nu, nx)
        x = np.linspace(0, np.pi, nx+2)[:-1]
        dx = x[1] - x[0]
        u = geturec(nu=nu, x=x, evolution_time=ET, timestrategy='fe', diffstrategy='3c', convstrategy='2c', n_save_t=1)[:, -1]
        l.append(ax[0].plot(x, u, label=nx, lw=LW)[0])
        gradu = u.copy()
        gradu[1:-1] = (u[2:] - u[:-2]) / ( 2 * dx)
        gradu[-1] = (u[0] - u[-2]) / ( 2 * dx)
        gradu[0] = (u[1] - u[-1]) / ( 2 * dx)
        l2.append(ax[1].plot(x, np.abs(gradu), label=nx, lw=LW)[0])
        qoi = np.max(np.abs(gradu))
        #qoi = x[np.argmax(gradu)]
        qois.append(qoi)
        if oldqoi is not None:
            print(qoi, oldqoi, np.max(gradu), np.abs(qoi - oldqoi)/qoi < 1e-3, (qoi - oldqoi)/qoi)
            if np.abs(qoi - oldqoi)/qoi < TOL:
            #if np.sqrt(np.sum((u[0::2] - oldu)**2)/oldu.size) < 1e-2:
               break
        oldqoi = qoi
Exemplo n.º 5
0
# Let's evolve burgers' equation in time

# x points
nx = 7000
x = np.linspace(0, np.pi, nx + 2)[:-1]
dx = x[1] - x[0]

# prescribe u dt / dx = 0.01
evolution_time = 1.

# baseline viscosity
nu = 1e-5

n_save_t = 20
dt = geturec(nu=nu, x=x, evolution_time=evolution_time, returndt=True)
nt = int(evolution_time / dt)
divider = int(nt / float(n_save_t))
#u_record = geturec(nu=nu, x=x, evolution_time=evolution_time, n_save_t=100)
#np.save('urec%f'%nu, u_record)
u_record = np.load('./urec%f.npy' % nu)
ubar = u_record.mean(1)
u_record -= ubar.reshape(-1, 1)
print('flow fielded')

# SVD the covariance matrix
psi, D, phi = np.linalg.svd(u_record, full_matrices=False)
for ii in range(psi.shape[1]):
    psi[:, ii] /= np.sqrt(dx)
    phi[ii, :] *= np.sqrt(dx)
assert (np.allclose(u_record, np.dot(psi * D, phi)))