Interpolation Tools#

Interpolate#

functional_tools.interpolate(x, y, xs)#

Performs interpolation

This is a utility function that performs a Pytorch based cubic hermite spline interpolation method. The implementation is based on this gist , and extends it to xs with any dimensions \(N \geq 1\).

Parameters:
  • x (torch.Tensor) – One-dimensional tensors such that y(x) is the function to be interpolated

  • y (torch.Tensor) – One-dimensional tensors such that y(x) is the function to be interpolated

  • xs (torch.Tensor) – \(N\)-dimensional tensor \((N \geq 1)\) for which y(xs) is to be interpolated for

Returns:

Interpolated quantity

Return type:

torch.Tensor

Field-dependent Kernel Spline#

The following utlity functions are used for a quasi-linear scaling implementation of non-local kinetic functionals which have a single-point density dependent kernel, such as the Huang-Carter and revised Huang-Carter functionals.

Interpolate Kernel#

functional_tools.interpolate_kernel(xi_sparse, f, xis)#

Performs kernel interpolation

Consider a function \(f(x,y,z,\xi)\) where the last argument \(\xi(x,y,z)\) is also a scalar field. Let us have

  1. a list of discrete \(\xi\) values, e.g. \(\xi_i \in \{\xi_1, \xi_2, \xi_3, \ldots\}\), represented by the argument xi_sparse

  2. a set of \(f(x,y,z,\xi_i)\) evaluated for specifc \(\xi_i\) values, where \(\xi(x,y,z) = \xi_i\) is constant over all space, represented by the argument f

  3. the function \(\xi(x,y,z)\) that could vary in space, represented by the argument xis

This function performs a cubic hermite interpolation to compute \(f(x,y,z,\xi)\) for \(\xi(x,y,z)\) using the set of \(f(x,y,z,\xi_i)\) values.

Parameters:
  • xi_sparse (torch.Tensor) – Tensor of \(\xi\) values with shape \((n_\xi)\)

  • f (torch.Tensor) – Tensor of \(f(x,y,z,\xi_i)\) values with shape \((n_1,n_2,n_3,n_\xi)\)

  • xis (torch.Tensor) – Tensor of the spatially varying \(\xi(x,y,z)\) with shape \((n_1,n_2,n_3)\)

Returns:

\(f(x,y,z,\xi)\) with shape \((n_1,n_2,n_3)\)

Return type:

torch.Tensor

Field-dependent Convolution#

functional_tools.field_dependent_convolution(k, f_tilde, g, xis, kappa, mode='arithmetic')#

Computes a field-dependent convolution

Computes a “field-dependent convolution”, which is an integral quantity

\[K(\mathbf{r}) = \int d^3\mathbf{r}' f(|\mathbf{r}-\mathbf{r}'|, \xi(\mathbf{r}))~g(\mathbf{r}')\]
Parameters:
  • k (torch.Tensor) – Wavevectors \(k=|\mathbf{k}|\) with shape \((m_1,m_2,m_3)\)

  • f_tilde (function) – A function \(\tilde{f}(k,\xi_i)\) which has to be able to broadcast inputs \(k\) with shape \((m_1,m_2,m_3)\) and \(\xi\) with shape \((n_\xi)\) to an output with shape \((m_1,m_2,m_3,n_\xi)\). Represents the fourier transform of \(f(|\mathbf{r}-\mathbf{r}'|, \xi = \xi_i)\) where \(\xi(\mathbf{r}) = \xi_i\) is constant over all space.

  • g (torch.Tensor) – \(g(\mathbf{r}')\) with shape \((n_1,n_2,n_3)\)

  • xis (torch.Tensor) – \(\xi(x,y,z)\) with shape \((n_1,n_2,n_3)\)

  • kappa (int) – Interval between the sparse \(\xi_i\)’s.

  • mode (str) – Whether the intervals of the sparse \(\xi_i\)’s correspond to an arithmetic (default) or geometric progression.

Returns:

\(K(\mathbf{r})\) with shape \((n_1,n_2,n_3)\)

Return type:

torch.Tensor