コード例 #1
0
v = v_func(x, y)
ur = u_func(xr, yr)
vr = v_func(xr, yr)

# move xr, yr with the velocity field
dt = 0.01
xr2 = xr + dt*ur
yr2 = yr + dt*vr

# get the gradients of this
kxv = np.fft.fftfreq(grid.shape[0], grid.xh/(2*np.pi))
kyv = np.fft.fftfreq(grid.shape[1], grid.yh/(2*np.pi))
kx, ky = np.meshgrid(kxv, kyv, indexing='ij')
dx = lambda f: fourier(f, 1j*kx)
dy = lambda f: fourier(f, 1j*ky)
ux, uy, uxr, uyr = ebdy.gradient(u, ur, dx, dy)
vx, vy, vxr, vyr = ebdy.gradient(v, vr, dx, dy)
Jxx = 1+uxr
Jxy = uyr
Jyx = vxr
Jyy = 1+vyr
det = Jxx*Jyy - Jxy*Jyx

# get a function c
c = c_func(xr, yr)

# evaluate c at these new positions
c2 = c_func(xr2, yr2)

# get r, t coordinates for xr2, yr2
t, r = compute_local_coordinates(bdy.x, bdy.y, xr2, yr2, 1e-14, verbose=True)
コード例 #2
0
################################################################################
# Test derivatives

# radial gradient
frxe, frye = ebdy.radial_grid_derivatives(fr)
frxt = test_func_x(ebdy.radial_x, ebdy.radial_y)
fryt = test_func_y(ebdy.radial_x, ebdy.radial_y)
err_x = np.abs(frxt-frxe).max()
err_y = np.abs(fryt-frye).max()
err = max(err_x, err_y)
print('Error in radial grid differentiation:      {:0.2e}'.format(err))

# fourth order accurate gradient on whole domain
dx = lambda x: fd_x_4(x, grid.xh, periodic_fix=not interior)
dy = lambda x: fd_y_4(x, grid.yh, periodic_fix=not interior)
fxe, fye, fxre, fyre = ebdy.gradient(f, fr, dx, dy)
fxt = test_func_x(grid.xg, grid.yg)
fyt = test_func_y(grid.xg, grid.yg)
err_x = np.abs(fxt-fxe)[ebdy.phys].max()
err_y = np.abs(fyt-fye)[ebdy.phys].max()
err = max(err_x, err_y)
print('Error in gradient, 4th order FD:           {:0.2e}'.format(err))

# spectrally accurate gradient on whole domain
kxv = np.fft.fftfreq(grid.Nx, grid.xh/(2*np.pi))
kyv = np.fft.fftfreq(grid.Ny, grid.yh/(2*np.pi))
kx, ky = np.meshgrid(kxv, kyv, indexing='ij')
ikx, iky = 1j*kx, 1j*ky
dx = lambda x: fourier(x, ikx)
dy = lambda x: fourier(x, iky)
fxe, fye, fxre, fyre = ebdy.gradient(f, fr, dx, dy)