Kernels

Kernel interface

class sumpy.kernel.Kernel(dim=None)[source]

Basic kernel interface.

is_complex_valued
dim
get_base_kernel()[source]

Return the kernel being wrapped by this one, or else self.

prepare_loopy_kernel(loopy_knl)[source]

Apply some changes (such as registering function manglers) to the kernel. Return the new kernel.

get_code_transformer()[source]

Return a function to postprocess the pymbolic expression generated from the result of get_expression() on the way to code generation.

get_expression(dist_vec)[source]

Return a sympy expression for the kernel.

has_efficient_scale_adjustment
adjust_for_kernel_scaling(expr, rscale, nderivatives)[source]

Consider a Taylor multipole expansion:

\[ f (x - y) = \sum_{i = 0}^{\infty} (\partial_y^i f) (x - y) \big|_{y = c} \frac{(y - c)^i}{i!} .\]

Now suppose we would like to use a scaled version \(g\) of the kernel \(f\):

\[\begin{split}\begin{eqnarray*} f (x) & = & g (x / \alpha),\\ f^{(i)} (x) & = & \frac{1}{\alpha^i} g^{(i)} (x / \alpha) . \end{eqnarray*}\end{split}\]

where \(\alpha\) is chosen to be on a length scale similar to \(x\) (for example by choosing \(\alpha\) proporitional to the size of the box for which the expansion is intended) so that \(x / \alpha\) is roughly of unit magnitude, to avoid arithmetic issues with small arguments. This yields

\[f (x - y) = \sum_{i = 0}^{\infty} (\partial_y^i g) \left( \frac{x - y}{\alpha} \right) \Bigg|_{y = c} \cdot \frac{(y - c)^i}{\alpha^i \cdot i!}.\]

Observe that the \((y - c)\) term is now scaled to unit magnitude, as is the argument of \(g\).

With \(\xi = x / \alpha\), we find

\[\begin{split}\begin{eqnarray*} g (\xi) & = & f (\alpha \xi),\\ g^{(i)} (\xi) & = & \alpha^i f^{(i)} (\alpha \xi) . \end{eqnarray*}\end{split}\]

Generically for all kernels, \(f^{(i)} (\alpha \xi)\) is computable by taking a sufficient number of symbolic derivatives of \(f\) and providing \(\alpha \xi = x\) as the argument.

Now, for some kernels, like \(f (x) = C \log x\), the powers of \(\alpha^i\) from the chain rule cancel with the ones from the argument substituted into the kernel derivative:

\[g^{(i)} (\xi) = \alpha^i f^{(i)} (\alpha \xi) = C' \cdot \alpha^i \cdot \frac{1}{(\alpha x)^i} \quad (i > 0),\]

making them what you might call scale-invariant. In this case, one may set has_efficient_scale_adjustment. For these kernels only, adjust_for_kernel_scaling() provides a shortcut for scaled kernel derivative computation. Given \(f^{(i)}\) as expr, it directly returns an expression for \(g^{(i)}\), where \(i\) is given as nderivatives.

Parameters

rscale – The scaling parameter \(\alpha\) above.

postprocess_at_source(expr, avec)[source]

Transform a kernel evaluation or expansion expression in a place where the vector a (something - source) is known. (“something” may be an expansion center or a target.)

The typical use of this function is to apply source-variable derivatives to the kernel.

postprocess_at_target(expr, bvec)[source]

Transform a kernel evaluation or expansion expression in a place where the vector b (target - something) is known. (“something” may be an expansion center or a target.)

The typical use of this function is to apply target-variable derivatives to the kernel.

get_global_scaling_const()[source]

Return a global scaling constant of the kernel. Typically, this ensures that the kernel is scaled so that \(\mathcal L(G)(x)=C\delta(x)\) with a constant of 1, where \(\mathcal L\) is the PDE operator associated with the kernel. Not to be confused with rscale, which keeps expansion coefficients benignly scaled.

get_args()[source]

Return list of KernelArgument instances describing extra arguments used by the kernel.

get_source_args()[source]

Return list of KernelArgument instances describing extra arguments used by kernel in picking up contributions from point sources.

class sumpy.kernel.KernelArgument(loopy_arg)[source]
loopy_arg

A loopy.Argument instance describing the type, name, and other features of this kernel argument when passed to a generated piece of code.

Symbolic kernels

class sumpy.kernel.ExpressionKernel(dim, expression, global_scaling_const, is_complex_valued)[source]

PDE kernels

class sumpy.kernel.LaplaceKernel(dim=None)[source]
class sumpy.kernel.BiharmonicKernel(dim=None)[source]
class sumpy.kernel.HelmholtzKernel(dim=None, helmholtz_k_name='k', allow_evanescent=False)[source]
class sumpy.kernel.YukawaKernel(dim=None, yukawa_lambda_name='lam')[source]
class sumpy.kernel.StokesletKernel(dim, icomp, jcomp, viscosity_mu_name='mu')[source]
class sumpy.kernel.StressletKernel(dim=None, icomp=None, jcomp=None, kcomp=None, viscosity_mu_name='mu')[source]

Derivatives

These objects wrap other kernels and take derivatives of them in the process.

class sumpy.kernel.DerivativeBase(inner_kernel)[source]
class sumpy.kernel.AxisTargetDerivative(axis, inner_kernel)[source]
class sumpy.kernel.DirectionalTargetDerivative(inner_kernel, dir_vec_name=None)[source]
class sumpy.kernel.DirectionalSourceDerivative(inner_kernel, dir_vec_name=None)[source]

Transforming kernels

class sumpy.kernel.KernelMapper[source]
class sumpy.kernel.KernelCombineMapper[source]
class sumpy.kernel.KernelIdentityMapper[source]
class sumpy.kernel.AxisTargetDerivativeRemover[source]
class sumpy.kernel.TargetDerivativeRemover[source]
class sumpy.kernel.DerivativeCounter[source]