Spatial

Discretization of a spatial domain.

immunowave.spatial.laplacian_kernel_1d = array([ 1., -2.,  1.])

1D Laplacian kernel.

immunowave.spatial.laplacian_kernel_2d = array([[ 0.25,  0.5 ,  0.25],        [ 0.5 , -3.  ,  0.5 ],        [ 0.25,  0.5 ,  0.25]])

2D Laplacian kernel (isotropic 9-point stencil of Oono and Puri).

immunowave.spatial.laplacian_kernel_3d = array([[[ 0.07692308,  0.11538462,  0.07692308],         [ 0.11538462,  0.23076923,  0.11538462],         [ 0.07692308,  0.11538462,  0.07692308]],         [[ 0.11538462,  0.23076923,  0.11538462],         [ 0.23076923, -3.38461538,  0.23076923],         [ 0.11538462,  0.23076923,  0.11538462]],         [[ 0.07692308,  0.11538462,  0.07692308],         [ 0.11538462,  0.23076923,  0.11538462],         [ 0.07692308,  0.11538462,  0.07692308]]])

3D Laplacian kernel (isotropic 27-point stencil of O’Reilly and Beck).

immunowave.spatial.NDFn

Scalar function of 1, 2, or 3 variables.

alias of Callable[[float], float] | Callable[[float, float], float] | Callable[[float, float, float], float]

class immunowave.spatial.ScalarField(shape, lb, h, values=0.0, fn=None)[source]

Bases: Module

A scalar field \(f:\mathbb{R}^d\to\mathbb{R}\) on a \(d\)-dimensional spatial domain \(\mathcal{D}\subset\mathbb{R}^d\) discretized into a regular grid with spacing \(h\).

Parameters:
  • shape (Sequence[int]) – Grid shape.

  • lb (Float[list, 'ndim']) – Lower bounds of domain. Must be consistent via broadcasting with the dimension implied by shape.

  • h (float) – grid spacing.

  • values (Float[Array, '#l #m n']) – Values of the discretized function at each grid point. Must be broadcastable to shape.

  • fn (Callable[[float], float] | Callable[[float, float], float] | Callable[[float, float, float], float] | None) – Function \(f:\mathbb{R}^d\to\mathbb{R}\) to discretize (overrides values). Callable must accept ScalarField.ndim float arguments and return a scalar float. It must also be vectorizable with jax.vmap().

lb: Float[list, 'ndim']

Lower bounds of domain.

ndim: int

Number of dimensions.

h: float

Grid spacing.

ub: Float[list, 'ndim']

Upper bounds of domain.

values: Float[Array, '#l #m n']

Values of the discretized function at each grid point.

property domain: tuple[Float[Array, '...'], ...]

Discretized spatial domain \(\mathcal{D}\subset\mathbb{R}^d\).

check_aligned(other)[source]

Check if another field is spatially aligned with this one (i.e., it has the same domain parameters).

Parameters:

other (Self) – Other field.

Raises:

eqx.EquinoxTracetimeError – If other is not aligned.

Return type:

None

map(fn)[source]
exp()[source]
Return type:

Self

log()[source]
Return type:

Self

hill(K, n)[source]
Parameters:
Return type:

Self

binop(other, fn)[source]

Pointwise binary operation with another discretized function.

Parameters:
  • other (Self | Float[Array, '#l #m n']) – Another spatially discretized function.

  • fn (Callable[[Float[Array, '#l #m n'], Float[Array, '#l #m n']], Float[Array, '#l #m n']]) – Pointwise binary operation.

Returns:

Discretized function.

Return type:

Self

integral()[source]
Return type:

Array | ndarray | bool | number | bool | int | float | complex

laplacian(bc='dirichlet')[source]

Laplacian \(\nabla^2 f\).

Parameters:

bc (Literal['dirichlet', 'neumann']) – Zero boundary condition (either "dirichlet" or "neumann").

Returns:

Discretized Laplacian field \(\nabla^2 f\).

Return type:

Self

plot(time_idx=None, **kwargs)[source]

Plot the field with Matplotlib.

Parameters:
  • time_idx (int | None) – If self is derived from a Diffrax solution with a series of time points, this index specifies which time index to plot

  • kwargs (Any) – Keyword arguments passed to Matplotlib plotting function.

Return type:

None