Kernels¶
Kernel interface¶
- class sumpy.kernel.KernelArgument(loopy_arg: KernelArgument)[source]¶
- loopy_arg: KernelArgument¶
A
loopy.KernelArgumentinstance describing the type, name, and other features of this kernel argument when passed to a generated piece of code.
- class sumpy.kernel.ScalarKernel(dim: int)[source]¶
Bases:
ABCScalar kernel interface.
- is_translation_invariant: ClassVar[bool] = True¶
A boolean flag indicating whether the kernel is translation invariant.
- abstract property is_complex_valued: bool¶
A boolean flag indicating whether this kernel is complex valued.
- get_base_kernel() ScalarKernel[source]¶
- Returns:
the kernel being wrapped by this one, or else self.
- replace_base_kernel(new_base_kernel: ScalarKernel) ScalarKernel[source]¶
- Returns:
the base kernel being wrapped by this one, or else new_base_kernel.
- get_pde_system_kernel() tuple[SystemKernel, tuple[int, ...]][source]¶
- Returns:
if the kernel is a component kernel of a
SystemKernel, this returns the system kernel and the index of the kernel in that system.
- prepare_loopy_kernel(loopy_knl: TranslationUnit) TranslationUnit[source]¶
Apply some changes (such as registering function manglers) to the kernel.
- Returns:
a new
loopykernel with the applied changes.
- get_code_transformer() Callable[[Expression], Expression][source]¶
- Returns:
a function to postprocess the
pymbolicexpression generated from the result ofget_expression()on the way to code generation.
- abstractmethod get_expression(dist_vec: MutableDenseMatrix) Expr[source]¶
- Returns:
a
sympyexpression for the kernel.
- postprocess_at_source(expr: Expr, avec: MutableDenseMatrix) Expr[source]¶
- postprocess_at_source(expr: ExprDerivativeTaker, avec: MutableDenseMatrix) DifferentiatedExprDerivativeTaker
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: Expr, bvec: MutableDenseMatrix) Expr[source]¶
- postprocess_at_target(expr: ExprDerivativeTaker | DifferentiatedExprDerivativeTaker, bvec: MutableDenseMatrix) DifferentiatedExprDerivativeTaker
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.
- abstractmethod get_global_scaling_const() Expr[source]¶
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() Sequence[KernelArgument][source]¶
- Returns:
list of
KernelArgumentinstances describing extra arguments used by the kernel.
- get_source_args() Sequence[KernelArgument][source]¶
- Returns:
list of
KernelArgumentinstances describing extra arguments used by kernel in picking up contributions from point sources.
- abstractmethod get_pde_as_diff_op() LinearPDESystemOperator[source]¶
- Returns:
the PDE for the kernel as a
sumpy.expansion.diff_op.LinearPDESystemOperatorobject \(\mathcal{L}\), where \(\mathcal{L}(u) = 0\) is the PDE.
- class sumpy.kernel.SystemKernel(dim: int)[source]¶
Bases:
ABCA kernel representing a vector PDE.
- __getitem__(index: tuple[int, ...], /) ScalarKernel[source]¶
- Returns:
the scalar kernel at index.
- get_expression(dist_vec: MutableDenseMatrix) ObjectArray[tuple[int, ...], Expr][source]¶
- Returns:
a
sympyexpression for each component the kernel.
- abstractmethod get_pde_as_diff_op() LinearPDESystemOperator[source]¶
- Returns:
the PDE that this kernel satisfies (see
ScalarKernel.get_pde_as_diff_op()as the scalar alternative).
Symbolic kernels¶
- class sumpy.kernel.ExpressionKernel(dim: int, expression: Expression, global_scaling_const: Expression)[source]¶
Bases:
ScalarKernel,ABC- expression: Expression¶
A
pymbolicexpression depending on variables d_1 through d_N where N equals dim. These variables match what is returned frompymbolic.primitives.make_sym_vector()with argument “d”. Any variable that is not d or aSpatialConstantwill be viewed as potentially spatially varying.
- global_scaling_const: Expression¶
A constant
pymbolicexpression for the global scaling 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.
Scalar PDE kernels¶
- class sumpy.kernel.LaplaceKernel(dim: int)[source]¶
Bases:
ExpressionKernelA kernel for the Laplace equation (see e.g. Theorem 6.2 from [Kress2013]).
\[\Delta K(\mathbf{x}, \mathbf{y}) = \delta(\mathbf{x} - \mathbf{y}).\]
- class sumpy.kernel.BiharmonicKernel(dim: int)[source]¶
Bases:
ExpressionKernelA kernel for the biharmonic equation.
\[\Delta^2 K(\mathbf{x}, \mathbf{y}) = \delta(\mathbf{x} - \mathbf{y}).\]
- class sumpy.kernel.HelmholtzKernel(dim: int, helmholtz_k_name: str = 'k', allow_evanescent: bool = False)[source]¶
Bases:
ExpressionKernelA kernel for the Helmholtz equation (see e.g. Example 12.14 in [Kress2013]).
\[\Delta K(\mathbf{x}, \mathbf{y}) + k^2 K(\mathbf{x}, \mathbf{y}) = \delta(\mathbf{x} - \mathbf{y}).\]
- class sumpy.kernel.YukawaKernel(dim: int, yukawa_lambda_name: str = 'lam')[source]¶
Bases:
ExpressionKernelA kernel for the Yukawa equation.
\[\Delta K(\mathbf{x}, \mathbf{y}) - \lambda^2 K(\mathbf{x}, \mathbf{y}) = \delta(\mathbf{x} - \mathbf{y}).\]
- class sumpy.kernel.StokesComponentKernelBase(dim: int, expression: Expression, global_scaling_const: Expression, viscosity_mu_name: str)[source]¶
Bases:
ExpressionKernelBase class for kernels of the Stokes equations (see e.g. Chapter 2 in [Pozrikidis1992]).
- class sumpy.kernel.StokesletComponentKernel(dim: int, icomp: int, jcomp: int, viscosity_mu_name: str = 'mu')[source]¶
Bases:
StokesComponentKernelBaseThe velocity kernel for the Stokes equations (see e.g. Chapter 2 in [Pozrikidis1992]).
\[\begin{split}\begin{cases} -\mu \Delta K_{ij}(\mathbf{x}, \mathbf{y}) + \nabla_i P_j(\mathbf{x}, \mathbf{y}) = \delta_{ij} \delta(\mathbf{x} - \mathbf{y}), \\ \nabla_i K_{ij}(\mathbf{x}, \mathbf{y}) = 0, \\ \end{cases}\end{split}\]where pressure kernel \(P_j = \partial_j K\) is the derivative of the Laplace kernel. This kernel is often called the Stokeslet or the Oseen-Burgers tensor and it represents the velocity field.
- class sumpy.kernel.StressletComponentKernel(dim: int, icomp: int, jcomp: int, kcomp: int, viscosity_mu_name: str = 'mu')[source]¶
Bases:
StokesComponentKernelBaseThe stress kernel for the Stokes equations (see e.g. Chapter 2 in [Pozrikidis1992]).
\[K_{ijk}(\mathbf{x}, \mathbf{y}) = -P_j \delta_{ik} + \mu (\partial_k K_{ij} + \partial_i K_{kj})\]where the two-index \(K_{ij}\) is the
StokesletComponentKernel. This kernel is often called the Stresslet and it represents the stress tensor.
- class sumpy.kernel.ElasticityComponentKernelBase(dim: int, expression: Expression, global_scaling_const: Expression, viscosity_mu_name: str, poisson_ratio_name: str)[source]¶
Bases:
ExpressionKernelBase kernel class for the linear elasticity (Navier-Cauchy) equations (see e.g. Section 2.2 in [Hsiao2008]).
- class sumpy.kernel.ElasticityComponentKernel(dim: int, icomp: int, jcomp: int, viscosity_mu_name: str = 'mu', poisson_ratio_name: str = 'nu')[source]¶
Bases:
ElasticityComponentKernelBaseThe displacement kernel for the linear elasticity (Navier-Cauchy) equations (see e.g. Section 2.2 in [Hsiao2008]).
\[\mu \Delta K_{ij}(\mathbf{x}, \mathbf{y}) + \frac{\mu}{1 - 2 \nu} \nabla (\nabla \cdot K_{ij}(\mathbf{x}, \mathbf{y})) = \delta_{ij} \delta(\mathbf{x} - \mathbf{y}).\]
- class sumpy.kernel.ElasticityStressComponentKernel(dim: int, icomp: int, jcomp: int, kcomp: int, viscosity_mu_name: str = 'mu', poisson_ratio_name: str = 'nu')[source]¶
Bases:
ElasticityComponentKernelBaseThe stress kernel for the linear elasticity (Navier-Cauchy) equations (see e.g. Section 2.2 in [Hsiao2008]).
\[K_{ijk}(\mathbf{x}, \mathbf{y}) = \lambda \partial_l K_{kl}(\mathbf{x}, \mathbf{y}) \delta_{ij} + \mu (\partial_j K_{ik}(\mathbf{x}, \mathbf{y}) + \partial_i K_{jk}(\mathbf{x}, \mathbf{y})),\]where the two-index \(K_{ij}\) is the
ElasticityComponentKernel.
- class sumpy.kernel.LineOfCompressionKernel(dim: int = 3, axis: int = 2, viscosity_mu_name: str = 'mu', poisson_ratio_name: str = 'nu')[source]¶
Bases:
ExpressionKernelA kernel for the line of compression or dilatation of constant strength along an axis from zero to negative infinity.
This is used for the explicit solution to half-space linear elasticity problem. See [Mindlin1936] for details.
[Mindlin1936]R. D. Mindlin (1936). Force at a Point in the Interior of a Semi-Infinite Solid. Physics. 7 (5): 195-202. doi:10.1063/1.1745385.
- viscosity_mu_name: str¶
The argument name to use for the dynamic viscosity \(\mu\) when generating functions to evaluate this kernel.
- class sumpy.kernel.BrinkmanComponentKernelBase(dim: int, expression: Expression, global_scaling_const: Expression, viscosity_mu_name: str, darcy_impermeability_name: str)[source]¶
Bases:
ExpressionKernelBase class for the Brinkman equations.
- class sumpy.kernel.BrinkmanletComponentKernel(dim: int, icomp: int, jcomp: int, viscosity_mu_name: str = 'mu', darcy_impermeability_name: str = 'k')[source]¶
Bases:
BrinkmanComponentKernelBaseThe velocity kernel for the Brinkman equations.
\[\begin{split}\begin{cases} -\mu (\Delta K_{ij}(\mathbf{x}, \mathbf{y}) - k^2 K_{ij}(\mathbf{x}, \mathbf{y})) + \nabla_i P_j(\mathbf{x}, \mathbf{y}) = \delta_{ij}(\mathbf{x} - \mathbf{y}), \\ \nabla_i K_{ij} = 0, \end{cases}\end{split}\]where \(P_j\) is the pressure kernel.
- class sumpy.kernel.BrinkmanStressComponentKernel(dim: int, icomp: int, jcomp: int, kcomp: int, viscosity_mu_name: str = 'mu', darcy_impermeability_name: str = 'k')[source]¶
Bases:
BrinkmanComponentKernelBaseA kernel for the Brinkman equations.
\[K_{ijk} = -p_j \delta_{ik} + \mu (\partial_k K_{ij} + \partial_i K_{jk}),\]where the two-index \(K_{ij}\) is the
BrinkmanletComponentKerneland \(P_j\) is the pressure kernel.
- class sumpy.kernel.HeatKernel(spatial_dims: int, heat_alpha_name: str = 'alpha')[source]¶
Bases:
ExpressionKernelThe Green’s function for the heat equation.
\[\frac{\partial}{\partial t} K(t, \mathbf{x}, \mathbf{y}) - \alpha \Delta K(t, \mathbf{x}, \mathbf{y}) = \delta(t) \delta(\mathbf{x} - \mathbf{y})\]Note
This kernel cannot be used in an FMM yet and can only be used in expansions and evaluations that occur forward in the time dimension.
System PDE Kernels¶
- class sumpy.kernel.ElasticitySystemKernel(dim: int, viscosity_mu_name: str = 'mu', poisson_ratio_name: str = 'nu')[source]¶
Bases:
SystemKernelThe displacement kernel for the linear elasticity (Navier-Cauchy) equations (see e.g. Section 2.2 in [Hsiao2008]).
This kernel uses
ElasticityComponentKernelfor its components.- viscosity_mu_name: str = 'mu'¶
The argument name to use for the dynamic viscosity \(\mu\) when generating functions to evaluate this kernel.
- class sumpy.kernel.ElasticityStressSystemKernel(dim: int, viscosity_mu_name: str = 'mu', poisson_ratio_name: str = 'nu')[source]¶
Bases:
SystemKernelThe stress kernel for the linear elasticity (Navier-Cauchy) equations (see e.g. Section 2.2 in [Hsiao2008]).
This kernel uses
ElasticityStressComponentKernelfor its components.- viscosity_mu_name: str = 'mu'¶
The argument name to use for the dynamic viscosity \(\mu\) when generating functions to evaluate this kernel.
- class sumpy.kernel.StokesletSystemKernel(dim: int, viscosity_mu_name: str = 'mu')[source]¶
Bases:
SystemKernelA kernel for the Stokes equations (see e.g. Chapter 2 in [Pozrikidis1992]).
This kernel uses
StokesletComponentKernelfor its components.
- class sumpy.kernel.StressletSystemKernel(dim: int, viscosity_mu_name: str = 'mu')[source]¶
Bases:
SystemKernelA kernel for the Stokes equations (see e.g. Chapter 2 in [Pozrikidis1992]).
This kernel uses
StressletComponentKernelfor its components.
- class sumpy.kernel.BrinkmanletSystemKernel(dim: int, viscosity_mu_name: str = 'mu', darcy_impermeability_name: str = 'k')[source]¶
Bases:
SystemKernelA kernel for the Brinkman equations.
This kernel uses
BrinkmanletComponentKernelfor its components.- viscosity_mu_name: str = 'mu'¶
The argument name to use for the dynamic viscosity when generating functions to evaluate this kernel.
- class sumpy.kernel.BrinkmanStressSystemKernel(dim: int, viscosity_mu_name: str = 'mu', darcy_impermeability_name: str = 'k')[source]¶
Bases:
SystemKernelA kernel for the Brinkman equations.
This kernel uses
BrinkmanStressComponentKernelfor its components.- viscosity_mu_name: str = 'mu'¶
The argument name to use for the dynamic viscosity when generating functions to evaluate this kernel.
Derivatives¶
These objects wrap other kernels and take derivatives of them in the process.
- class sumpy.kernel.DerivativeBase(inner_kernel: ScalarKernel)[source]¶
Bases:
ScalarKernel- inner_kernel: ScalarKernel¶
The kernel that is being wrapped (to take a derivative of, etc.).
- abstractmethod replace_inner_kernel(new_inner_kernel: ScalarKernel) ScalarKernel[source]¶
Replace the inner kernel of this wrapper.
This is essentially the same as
ScalarKernel.replace_base_kernel(), but it does not recurse.
- class sumpy.kernel.AxisTargetDerivative(axis: int, inner_kernel: ScalarKernel)[source]¶
Bases:
DerivativeBase
- class sumpy.kernel.AxisSourceDerivative(axis: int, inner_kernel: ScalarKernel)[source]¶
Bases:
DerivativeBase
- class sumpy.kernel.DirectionalDerivative(inner_kernel: ScalarKernel, dir_vec_name: str | None = None)[source]¶
Bases:
DerivativeBase
- class sumpy.kernel.DirectionalSourceDerivative(inner_kernel: ScalarKernel, dir_vec_name: str | None = None)[source]¶
Bases:
DirectionalDerivative
Transforming kernels¶
- class sumpy.kernel.TargetPointMultiplier(axis: int, inner_kernel: ScalarKernel)[source]¶
Bases:
ScalarKernelWraps a kernel \(G(x, y)\) and outputs \(x_j G(x, y)\) where \(x, y\) are targets and sources respectively.
- class sumpy.kernel.ResultT¶
alias of TypeVar(‘ResultT’)
- class sumpy.kernel.KernelMapper[source]¶
-
- __call__(kernel: ScalarKernel) ResultT[source]¶
Call self as a function.
- class sumpy.kernel.KernelCombineMapper[source]¶
Bases:
KernelMapper[ResultT],ABC
- class sumpy.kernel.KernelIdentityMapper[source]¶
Bases:
KernelMapper[ScalarKernel]
- class sumpy.kernel.AxisSourceDerivativeRemover[source]¶
Bases:
KernelIdentityMapperRemoves all axis source derivatives from the kernel.
- class sumpy.kernel.AxisTargetDerivativeRemover[source]¶
Bases:
KernelIdentityMapperRemoves all axis target derivatives from the kernel.
- class sumpy.kernel.SourceDerivativeRemover[source]¶
Bases:
AxisSourceDerivativeRemoverRemoves all source derivatives from the kernel.
- class sumpy.kernel.TargetDerivativeRemover[source]¶
Bases:
AxisTargetDerivativeRemoverRemoves all target derivatives from the kernel.
- class sumpy.kernel.TargetTransformationRemover[source]¶
Bases:
TargetDerivativeRemoverRemoves all target transformations from the kernel.
- class sumpy.kernel.DerivativeCounter[source]¶
Bases:
KernelCombineMapper[int]Counts the number of derivatives in the kernel.