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()
def __init__(self, ambient_dim: int, *, dim: Optional[int] = None, precond: str = "left", yukawa_k_name: str = "k") -> None: from sumpy.kernel import YukawaKernel super().__init__( YukawaKernel(ambient_dim, yukawa_lambda_name=yukawa_k_name), dim=dim, precond=precond, kernel_arguments={yukawa_k_name: sym.var(yukawa_k_name)})
(LaplaceKernel(2), LaplaceConformingVolumeTaylorLocalExpansion, LaplaceConformingVolumeTaylorMultipoleExpansion), (LaplaceKernel(3), VolumeTaylorLocalExpansion, VolumeTaylorMultipoleExpansion), (LaplaceKernel(3), LaplaceConformingVolumeTaylorLocalExpansion, LaplaceConformingVolumeTaylorMultipoleExpansion), (HelmholtzKernel(2), VolumeTaylorLocalExpansion, VolumeTaylorMultipoleExpansion), (HelmholtzKernel(2), HelmholtzConformingVolumeTaylorLocalExpansion, HelmholtzConformingVolumeTaylorMultipoleExpansion), (HelmholtzKernel(2), H2DLocalExpansion, H2DMultipoleExpansion), (HelmholtzKernel(3), VolumeTaylorLocalExpansion, VolumeTaylorMultipoleExpansion), (HelmholtzKernel(3), HelmholtzConformingVolumeTaylorLocalExpansion, HelmholtzConformingVolumeTaylorMultipoleExpansion), (YukawaKernel(2), Y2DLocalExpansion, Y2DMultipoleExpansion), ]) def test_sumpy_fmm(ctx_getter, knl, local_expn_class, mpole_expn_class): logging.basicConfig(level=logging.INFO) ctx = ctx_getter() queue = cl.CommandQueue(ctx) nsources = 1000 ntargets = 300 dtype = np.float64 from boxtree.tools import (make_normal_particle_array as p_normal) sources = p_normal(queue, nsources, knl.dim, dtype, seed=15) if 1:
def get_sumpy_kernel(self, dim, kernel_type): """Sumpy (symbolic) version of the kernel. """ if kernel_type == "Laplace": from sumpy.kernel import LaplaceKernel return LaplaceKernel(dim) if kernel_type == "Laplace-Dx": from sumpy.kernel import LaplaceKernel, AxisTargetDerivative return AxisTargetDerivative(0, LaplaceKernel(dim)) if kernel_type == "Laplace-Dy": from sumpy.kernel import LaplaceKernel, AxisTargetDerivative return AxisTargetDerivative(1, LaplaceKernel(dim)) if kernel_type == "Laplace-Dz": from sumpy.kernel import LaplaceKernel, AxisTargetDerivative assert dim >= 3 return AxisTargetDerivative(2, LaplaceKernel(dim)) elif kernel_type == "Constant": return ConstantKernel(dim) elif kernel_type == "Yukawa": from sumpy.kernel import YukawaKernel return YukawaKernel(dim) elif kernel_type == "Yukawa-Dx": from sumpy.kernel import YukawaKernel, AxisTargetDerivative return AxisTargetDerivative(0, YukawaKernel(dim)) elif kernel_type == "Yukawa-Dy": from sumpy.kernel import YukawaKernel, AxisTargetDerivative return AxisTargetDerivative(1, YukawaKernel(dim)) elif kernel_type == "Cahn-Hilliard": from sumpy.kernel import FactorizedBiharmonicKernel return FactorizedBiharmonicKernel(dim) elif kernel_type == "Cahn-Hilliard-Laplacian": from sumpy.kernel import ( FactorizedBiharmonicKernel, LaplacianTargetDerivative, ) return LaplacianTargetDerivative(FactorizedBiharmonicKernel(dim)) elif kernel_type == "Cahn-Hilliard-Dx": from sumpy.kernel import FactorizedBiharmonicKernel, AxisTargetDerivative return AxisTargetDerivative(0, FactorizedBiharmonicKernel(dim)) elif kernel_type == "Cahn-Hilliard-Laplacian-Dx": from sumpy.kernel import ( FactorizedBiharmonicKernel, LaplacianTargetDerivative, ) from sumpy.kernel import AxisTargetDerivative return AxisTargetDerivative( 0, LaplacianTargetDerivative(FactorizedBiharmonicKernel(dim))) elif kernel_type == "Cahn-Hilliard-Laplacian-Dy": from sumpy.kernel import ( FactorizedBiharmonicKernel, LaplacianTargetDerivative, ) from sumpy.kernel import AxisTargetDerivative return AxisTargetDerivative( 1, LaplacianTargetDerivative(FactorizedBiharmonicKernel(dim))) elif kernel_type == "Cahn-Hilliard-Dy": from sumpy.kernel import FactorizedBiharmonicKernel, AxisTargetDerivative return AxisTargetDerivative(1, FactorizedBiharmonicKernel(dim)) elif kernel_type in self.supported_kernels: return None else: raise NotImplementedError("Kernel type not supported.")
def __init__(self, dim, lam): self.kernel = YukawaKernel(dim) self.lam = lam self.extra_kwargs = {"lam": lam}