Beispiel #1
0
def test_pde_check_kernels(ctx_factory, knl_info, order=5):
    dim = knl_info.kernel.dim
    tctx = t.ToyContext(ctx_factory(), knl_info.kernel,
            extra_source_kwargs=knl_info.extra_kwargs)

    pt_src = t.PointSources(
            tctx,
            np.random.rand(dim, 50) - 0.5,
            np.ones(50))

    from pytools.convergence import EOCRecorder
    from sumpy.point_calculus import CalculusPatch
    eoc_rec = EOCRecorder()

    for h in [0.1, 0.05, 0.025]:
        cp = CalculusPatch(np.array([1, 0, 0])[:dim], h=h, order=order)
        pot = pt_src.eval(cp.points)

        pde = knl_info.pde_func(cp, pot)

        err = la.norm(pde)
        eoc_rec.add_data_point(h, err)

    print(eoc_rec)
    assert eoc_rec.order_estimate() > order - knl_info.nderivs + 1 - 0.1
Beispiel #2
0
def main():
    from sumpy.kernel import (  # noqa: F401
        YukawaKernel, HelmholtzKernel, LaplaceKernel)
    tctx = t.ToyContext(
        cl.create_some_context(),
        #LaplaceKernel(2),
        YukawaKernel(2),
        extra_kernel_kwargs={"lam": 5},
        #HelmholtzKernel(2), extra_kernel_kwargs={"k": 0.3},
    )

    pt_src = t.PointSources(tctx, np.random.rand(2, 50) - 0.5, np.ones(50))

    fp = FieldPlotter([3, 0], extent=8)

    if 0 and plt is not None:
        t.logplot(fp, pt_src, cmap="jet")
        plt.colorbar()
        plt.show()

    mexp = t.multipole_expand(pt_src, [0, 0], 5)
    mexp2 = t.multipole_expand(mexp, [0, 0.25])  # noqa: F841
    lexp = t.local_expand(mexp, [3, 0])
    lexp2 = t.local_expand(lexp, [3, 1], 3)

    #diff = mexp - pt_src
    #diff = mexp2 - pt_src
    diff = lexp2 - pt_src

    print(t.l_inf(diff, 1.2, center=lexp2.center))
    if 1 and plt is not None:
        t.logplot(fp, diff, cmap="jet", vmin=-3, vmax=0)
        plt.colorbar()
        plt.show()
Beispiel #3
0
def test_toy_p2e2e2p(ctx_factory, case):
    dim = case.dim

    src = case.source.reshape(dim, -1)
    tgt = case.target.reshape(dim, -1)

    if not 0 <= case.conv_factor <= 1:
        raise ValueError("convergence factor not in valid range: %e" %
                         case.conv_factor)

    from sumpy.expansion.local import VolumeTaylorLocalExpansion
    from sumpy.expansion.multipole import VolumeTaylorMultipoleExpansion

    cl_ctx = ctx_factory()
    ctx = t.ToyContext(cl_ctx, LaplaceKernel(dim),
                       VolumeTaylorMultipoleExpansion,
                       VolumeTaylorLocalExpansion)

    errors = []

    src_pot = t.PointSources(ctx, src, weights=np.array([1.]))
    pot_actual = src_pot.eval(tgt).item()

    for order in ORDERS_P2E2E2P:
        expn = case.expansion1(src_pot, case.center1, order=order)
        expn2 = case.expansion2(expn, case.center2, order=order)
        pot_p2e2e2p = expn2.eval(tgt).item()
        errors.append(np.abs(pot_actual - pot_p2e2e2p))

    conv_factor = approx_convergence_factor(1 + np.array(ORDERS_P2E2E2P),
                                            errors)