def test_roots_sh_jacobi(): rf = lambda a, b: lambda n, mu: sc.roots_sh_jacobi(n, a, b, mu) ef = lambda a, b: lambda n, x: sc.eval_sh_jacobi(n, a, b, x) wf = lambda a, b: lambda x: (1. - x)**(a - b) * (x)**(b - 1.) vgq = verify_gauss_quad vgq(rf(-0.5, 0.25), ef(-0.5, 0.25), wf(-0.5, 0.25), 0., 1., 5) vgq(rf(-0.5, 0.25), ef(-0.5, 0.25), wf(-0.5, 0.25), 0., 1., 25, atol=1e-12) vgq(rf(-0.5, 0.25), ef(-0.5, 0.25), wf(-0.5, 0.25), 0., 1., 100, atol=1e-11) vgq(rf(0.5, 0.5), ef(0.5, 0.5), wf(0.5, 0.5), 0., 1., 5) vgq(rf(0.5, 0.5), ef(0.5, 0.5), wf(0.5, 0.5), 0., 1., 25, atol=1e-13) vgq(rf(0.5, 0.5), ef(0.5, 0.5), wf(0.5, 0.5), 0., 1., 100, atol=1e-12) vgq(rf(1, 0.5), ef(1, 0.5), wf(1, 0.5), 0., 1., 5) vgq(rf(1, 0.5), ef(1, 0.5), wf(1, 0.5), 0., 1., 25, atol=1.5e-13) vgq(rf(1, 0.5), ef(1, 0.5), wf(1, 0.5), 0., 1., 100, atol=2e-12) vgq(rf(2, 0.9), ef(2, 0.9), wf(2, 0.9), 0., 1., 5) vgq(rf(2, 0.9), ef(2, 0.9), wf(2, 0.9), 0., 1., 25, atol=1e-13) vgq(rf(2, 0.9), ef(2, 0.9), wf(2, 0.9), 0., 1., 100, atol=1e-12) vgq(rf(27.3, 18.24), ef(27.3, 18.24), wf(27.3, 18.24), 0., 1., 5) vgq(rf(27.3, 18.24), ef(27.3, 18.24), wf(27.3, 18.24), 0., 1., 25) vgq(rf(27.3, 18.24), ef(27.3, 18.24), wf(27.3, 18.24), 0., 1., 100, atol=1e-13) vgq(rf(47.1, 0.2), ef(47.1, 0.2), wf(47.1, 0.2), 0., 1., 5, atol=1e-12) vgq(rf(47.1, 0.2), ef(47.1, 0.2), wf(47.1, 0.2), 0., 1., 25, atol=1e-11) vgq(rf(47.1, 0.2), ef(47.1, 0.2), wf(47.1, 0.2), 0., 1., 100, atol=1e-10) vgq(rf(68.9, 2.25), ef(68.9, 2.25), wf(68.9, 2.25), 0., 1., 5, atol=3.5e-14) vgq(rf(68.9, 2.25), ef(68.9, 2.25), wf(68.9, 2.25), 0., 1., 25, atol=2e-13) vgq(rf(68.9, 2.25), ef(68.9, 2.25), wf(68.9, 2.25), 0., 1., 100, atol=1e-12) x, w = sc.roots_sh_jacobi(5, 3, 2, False) y, v, m = sc.roots_sh_jacobi(5, 3, 2, True) assert_allclose(x, y, 1e-14, 1e-14) assert_allclose(w, v, 1e-14, 1e-14) muI, muI_err = integrate.quad(wf(3,2), 0, 1) assert_allclose(m, muI, rtol=muI_err) assert_raises(ValueError, sc.roots_sh_jacobi, 0, 1, 1) assert_raises(ValueError, sc.roots_sh_jacobi, 3.3, 1, 1) assert_raises(ValueError, sc.roots_sh_jacobi, 3, 1, 2) # p - q <= -1 assert_raises(ValueError, sc.roots_sh_jacobi, 3, 2, -1) # q <= 0 assert_raises(ValueError, sc.roots_sh_jacobi, 3, -2, -1) # both
def test_roots_sh_jacobi(): rf = lambda a, b: lambda n, mu: sc.roots_sh_jacobi(n, a, b, mu) ef = lambda a, b: lambda n, x: orth.eval_sh_jacobi(n, a, b, x) wf = lambda a, b: lambda x: (1. - x)**(a - b) * (x)**(b - 1.) vgq = verify_gauss_quad vgq(rf(-0.5, 0.25), ef(-0.5, 0.25), wf(-0.5, 0.25), 0., 1., 5) vgq(rf(-0.5, 0.25), ef(-0.5, 0.25), wf(-0.5, 0.25), 0., 1., 25, atol=1e-12) vgq(rf(-0.5, 0.25), ef(-0.5, 0.25), wf(-0.5, 0.25), 0., 1., 100, atol=1e-11) vgq(rf(0.5, 0.5), ef(0.5, 0.5), wf(0.5, 0.5), 0., 1., 5) vgq(rf(0.5, 0.5), ef(0.5, 0.5), wf(0.5, 0.5), 0., 1., 25, atol=1e-13) vgq(rf(0.5, 0.5), ef(0.5, 0.5), wf(0.5, 0.5), 0., 1., 100, atol=1e-12) vgq(rf(1, 0.5), ef(1, 0.5), wf(1, 0.5), 0., 1., 5) vgq(rf(1, 0.5), ef(1, 0.5), wf(1, 0.5), 0., 1., 25, atol=1.5e-13) vgq(rf(1, 0.5), ef(1, 0.5), wf(1, 0.5), 0., 1., 100, atol=1e-12) vgq(rf(2, 0.9), ef(2, 0.9), wf(2, 0.9), 0., 1., 5) vgq(rf(2, 0.9), ef(2, 0.9), wf(2, 0.9), 0., 1., 25, atol=1e-13) vgq(rf(2, 0.9), ef(2, 0.9), wf(2, 0.9), 0., 1., 100, atol=1e-12) vgq(rf(27.3, 18.24), ef(27.3, 18.24), wf(27.3, 18.24), 0., 1., 5) vgq(rf(27.3, 18.24), ef(27.3, 18.24), wf(27.3, 18.24), 0., 1., 25) vgq(rf(27.3, 18.24), ef(27.3, 18.24), wf(27.3, 18.24), 0., 1., 100, atol=1e-13) vgq(rf(47.1, 0.2), ef(47.1, 0.2), wf(47.1, 0.2), 0., 1., 5, atol=1e-12) vgq(rf(47.1, 0.2), ef(47.1, 0.2), wf(47.1, 0.2), 0., 1., 25, atol=1e-11) vgq(rf(47.1, 0.2), ef(47.1, 0.2), wf(47.1, 0.2), 0., 1., 100, atol=1e-10) vgq(rf(68.9, 2.25), ef(68.9, 2.25), wf(68.9, 2.25), 0., 1., 5, atol=3.5e-14) vgq(rf(68.9, 2.25), ef(68.9, 2.25), wf(68.9, 2.25), 0., 1., 25, atol=2e-13) vgq(rf(68.9, 2.25), ef(68.9, 2.25), wf(68.9, 2.25), 0., 1., 100, atol=1e-12) x, w = sc.roots_sh_jacobi(5, 3, 2, False) y, v, m = sc.roots_sh_jacobi(5, 3, 2, True) assert_allclose(x, y, 1e-14, 1e-14) assert_allclose(w, v, 1e-14, 1e-14) muI, muI_err = integrate.quad(wf(3,2), 0, 1) assert_allclose(m, muI, rtol=muI_err) assert_raises(ValueError, sc.roots_sh_jacobi, 0, 1, 1) assert_raises(ValueError, sc.roots_sh_jacobi, 3.3, 1, 1) assert_raises(ValueError, sc.roots_sh_jacobi, 3, 1, 2) # p - q <= -1 assert_raises(ValueError, sc.roots_sh_jacobi, 3, 2, -1) # q <= 0 assert_raises(ValueError, sc.roots_sh_jacobi, 3, -2, -1) # both
def recur_colloc_symm(n_pts, a): """ For symmetric collocation problems, produce: rootsx = polynomial root locations Ax = 1st derivative operator Lx = 1-D Laplacian W = quadrature weights Reference: Michelsen and Villadsen 1971 sheet: a=1 cylinder: a=2 sphere: a=3 """ n_pts_m = n_pts - 1 # number of interior collocation points rootsu = np.zeros([n_pts]) rootsu[-1] = 1 # right bounary # Define optimal Jacobi polynomial for interior points p = 1.5 + (a - 1) / 2 q = p - 1 rootsu[:-1] = roots_sh_jacobi(n_pts_m, p, q)[0] # roots in u domain rootsx = np.sqrt(rootsu) # roots in x domain # define 3 by n_pts matrix of polynomial derivatives at collocation points # row index (k) is the k + 1 derivative px_mat = np.zeros((3, n_pts)) for ii in range(n_pts): px_mat[:, ii] = calc_px_column(rootsu[ii], rootsu) # Calculate derivative operators (A and B) in u domain Amat = np.zeros((n_pts, n_pts)) Bmat = np.zeros((n_pts, n_pts)) for ii in range(n_pts): for jj in range(n_pts): if ii == jj: # Eq. 12 Amat[ii, jj] = (1 / 2) * px_mat[1, ii] / px_mat[0, ii] Bmat[ii, jj] = (1 / 3) * px_mat[2, ii] / px_mat[0, ii] else: # Eqs. 13, 14 G = rootsu[ii] - rootsu[jj] Amat[ii, jj] = (1 / G) * px_mat[0, ii] / px_mat[0, jj] Bmat[ii, jj] = (1 / G) * (px_mat[1, ii] / px_mat[0, jj] - 2 * Amat[ii, jj]) Ax = np.zeros((n_pts, n_pts)) # First derivative operator in x domain Bx = np.zeros((n_pts, n_pts)) # 1-D Laplacian operator in x domain for ii in range(n_pts): for jj in range(n_pts): # Following Eq. 33 Ax[ii, jj] = 2 * rootsx[ii] * Amat[ii, jj] Bx[ii, jj] = 2 * a * Amat[ii, jj] + rootsu[ii] * 4 * Bmat[ii, jj] W = np.zeros(n_pts) for ii in range(n_pts): # Eq. 23 - 25 but omitting root at zero for nodal polynomial. wp_sum = (1 / (rootsu[:] * px_mat[0, :]**2)).sum() W[ii] = (1 / (rootsu[ii] * px_mat[0, ii]**2)) / wp_sum / (a) return (rootsx, Ax, Bx, W)