return dU # Set up for solving with TDMA if ST.quad == "GL": ck = ones(N[0]-2); ck[0] = 2 elif ST.quad == "GC": ck = ones(N[0]-2); ck[0] = 2; ck[-1] = 2 a0 = ones(N[0]-4)*(-pi/2) b0 = pi/2*(ck+1) c0 = a0.copy() bc = b0.copy() # For Neumann basis: kk = SN.wavenumbers(N[0]) ck = ones(N[0]-3) if SN.quad == "GC": ck[-1] = 2 a0N = ones(N[0]-5)*(-pi/2)*(kk[1:-2]/(kk[1:-2]+2))**2 b0N = pi/2*(1+ck*(kk[1:]/(kk[1:]+2))**4) c0N = a0N.copy() bcN = b0N.copy() # Prepare LU Helmholtz solver for velocity M = (N[0]-3)/2 u0 = zeros((2, M+1, U_hat.shape[2], U_hat.shape[3])) # Diagonal entries of U u1 = zeros((2, M, U_hat.shape[2], U_hat.shape[3])) # Diagonal+1 entries of U u2 = zeros((2, M-1, U_hat.shape[2], U_hat.shape[3])) # Diagonal+2 entries of U L0 = zeros((2, M, U_hat.shape[2], U_hat.shape[3])) # The single nonzero row of L SFTc.LU_Helmholtz_3D(N[0], 0, ST.quad=="GC", alfa1, u0, u1, u2, L0)
# Set up for solving with TDMA if ST.quad == "GC": ck = ones(N[0] - 2) ck[0] = 2 elif ST.quad == "GL": ck = ones(N[0] - 2) ck[0] = 2 ck[-1] = 2 a0 = ones(N[0] - 4) * (-pi / 2) b0 = pi / 2 * (ck + 1) c0 = a0.copy() bc = b0.copy() # For Neumann basis: kk = SN.wavenumbers(N[0]) ck = ones(N[0] - 3) if SN.quad == "GL": ck[-1] = 2 a0N = ones(N[0] - 5) * (-pi / 2) * (kk[1:-2] / (kk[1:-2] + 2))**2 b0N = pi / 2 * (1 + ck * (kk[1:] / (kk[1:] + 2))**4) c0N = a0N.copy() bcN = b0N.copy() # Prepare LU Helmholtz solver for velocity M = (N[0] - 3) / 2 u0 = zeros((2, M + 1, U_hat.shape[2], U_hat.shape[3])) # Diagonal entries of U u1 = zeros((2, M, U_hat.shape[2], U_hat.shape[3])) # Diagonal+1 entries of U u2 = zeros( (2, M - 1, U_hat.shape[2], U_hat.shape[3])) # Diagonal+2 entries of U L0 = zeros( (2, M, U_hat.shape[2], U_hat.shape[3])) # The single nonzero row of L
(\nabla^ u, \phi_k)_w = (f, \phi_k)_w """ # Use sympy to compute a rhs, given an analytical solution x = Symbol("x") u = cos(np.pi*x) f = u.diff(x, 2) N = 40 banded = False ST = ShenNeumannBasis() points, weights = ST.points_and_weights(N) k = ST.wavenumbers(N) # Gauss-Chebyshev quadrature to compute rhs (zero mean) fj = np.array([f.subs(x, j) for j in points], dtype=float) # Get f on quad points fj -= np.dot(fj, weights)/weights.sum() def solve_neumann(f): if banded: A = np.zeros((N-2, N-2)) A[-1, :] = -2*np.pi*(k+1)*k**2/(k+2) for i in range(2, N-3, 2): A[-i-1, i:] = -4*np.pi*(k[:-i]+i)**2*(k[:-i]+1)/(k[:-i]+2)**2 uk_hat = solve_banded((0, N-4), A[1:, 1:], f)
(\nabla^ u, \phi_k)_w = (f, \phi_k)_w """ # Use sympy to compute a rhs, given an analytical solution x = Symbol("x") u = cos(np.pi * x) f = u.diff(x, 2) N = 40 banded = False ST = ShenNeumannBasis() points, weights = ST.points_and_weights(N) k = ST.wavenumbers(N) # Gauss-Chebyshev quadrature to compute rhs (zero mean) fj = np.array([f.subs(x, j) for j in points], dtype=float) # Get f on quad points fj -= np.dot(fj, weights) / weights.sum() def solve_neumann(f): if banded: A = np.zeros((N - 2, N - 2)) A[-1, :] = -2 * np.pi * (k + 1) * k**2 / (k + 2) for i in range(2, N - 3, 2): A[-i - 1, i:] = -4 * np.pi * (k[:-i] + i)**2 * (k[:-i] + 1) / (k[:-i] +