def test_Helmholtz2(quad): M = 2*N SD = ShenDirichletBasis(M, quad=quad) kx = 12 uj = np.random.randn(M) u_hat = np.zeros(M) u_hat = SD.forward(uj, u_hat) uj = SD.backward(u_hat, uj) #from IPython import embed; embed() A = inner_product((SD, 0), (SD, 2)) B = inner_product((SD, 0), (SD, 0)) u1 = np.zeros(M) u1 = SD.forward(uj, u1) c0 = np.zeros_like(u1) c1 = np.zeros_like(u1) c = A.matvec(u1, c0)+kx**2*B.matvec(u1, c1) b = np.zeros(M) H = Helmholtz(M, kx, SD) b = H.matvec(u1, b) #LUsolve.Mult_Helmholtz_1D(M, SD.quad=="GL", 1, kx**2, u1, b) assert np.allclose(c, b) b = np.zeros((M, 4, 4), dtype=np.complex) u1 = u1.repeat(16).reshape((M, 4, 4)) +1j*u1.repeat(16).reshape((M, 4, 4)) kx = np.zeros((4, 4))+kx H = Helmholtz(M, kx, SD) b = H.matvec(u1, b) #LUsolve.Mult_Helmholtz_3D_complex(M, SD.quad=="GL", 1.0, kx**2, u1, b) assert np.linalg.norm(b[:, 2, 2].real - c)/(M*16) < 1e-12 assert np.linalg.norm(b[:, 2, 2].imag - c)/(M*16) < 1e-12
vb = BH.matvec(u, vb) sb = BH(sb, vb) errb += max(abs(sb - u)) / max(abs(u)) ### ss = SH(ss, vb) errs += max(abs(ss - u)) / max(abs(u)) ### #err += " & {:2.2e} ".format(errb/M) err += " & {:2.2e} & {:2.2e} ".format(errb / M, errs / M) err += " \\\ " print err print "\hline" for z in Z: err = str(z) for n in N: errh = 0 vh = zeros(n) sh = zeros(n) alfa = sqrt(z**2 + 2.0 / nu / dt) HS = Helmholtz(n, alfa, "GC") for m in range(M): u = random.randn(n) u[-2:] = 0 vh = HS.matvec(u, vh) sh = HS(sh, vh) errh += max(abs(sh - u)) / max(abs(u)) err += " & {:2.2e} ".format(errh / M) err += " \\\ " print err