Cubic Hermite interpolation

When passed to halmd.mdsim.forces.tabulated, this function calculates the potential energy and force from lattice points of precalculated potential energy points and coefficients at the lattice points.

In 1D the interpolated value \tilde V(x) is calculated by the following expression:

\tilde V(x) = \sum_{i=0}^1 h_i^{(0)}(x_r) V(x_r) + h_i^{(1)}(x_r) \partial_x V(x_i)

where V(x_0) and V(x_1) are the potential values at the neighbouring knots x_0 and x_1. \partial_x V(x_i) is the first derivative of V(x) at x_i. x_r is the reduced distance \frac{x - x_0}{x_1 - x_0}.

The functions h_i^{(0)}(x) and h_i^{(1)}(x) are defined as:

h_i^{(0)} &= \begin{cases}
           x^2(3-2x) & \text{if } i = 0 \\
          (x-1)^2(1+2x) & \text{if } i = 1
         \end{cases} \\
h_i^{(1)} &= \begin{cases}
         d x^2(x-1) & \text{if } i = 0 \\
         -d(1-x)^2 x & \text{if } i = 1
\end{cases}

where d = x_1 - x_0.

Coefficients

The Cubic Hermite interpolation needs 2^d coefficients per neighbour to determine the interpolated value. The coefficients must be given in the following order: V(r), \partial_x V(r), \partial_y V(r), \partial_x \partial_y V(r), \partial_z V(r), \partial_x \partial_z V(r), \partial_y \partial_z V(r), \partial_x \partial_y \partial_z V(r), where r is the position of the knot.

Note

The first derivatives are not the force, that is F(r) = -\nabla V(r)

In two dimensions only the first 4 coefficients are needed. The index of the first coefficient for a knot is given by 2^d \times multi_index_to_offset(index, nknots), which is followed by all other coefficients needed for the node at index.

[1]Martin H. Schultz, Spline Analysis (Ch. 3), Prentice-Hall (Englewood Cliffs, N.J) (1972), ISBN 0138354057
class halmd.mdsim.forces.interpolation.cubic_hermite(args)

Construct cubic hermite interpolator.

Parameters:
  • args (table) – keyword arguments
  • args.box – instance of halmd.mdsim.box
  • args.length (table) – length of the (optional, defaults to box.length)
  • args.lowest_corner (table) – distance of the box to the lowest_corner (optional, defaults to box.lowest_corner)
  • args.nknots (number table) – number of knots in each dimension, including edges
  • args.precision (string) – floating point number precision
Returns:

instance of cubic hermite interpolation scheme

If box is not given, the arguments length and lowest_corner have to be supplied. This enables the possibility to have a smaller “unit cell” of the interpolation area, while the simulation box may be multiples of this unit cell. length and lowest_corner both precede box.

The supported values for precision are “single” and “double”. In 3D simulations double precision is recommended also for the GPU as the number of mathematical operations is at the order of 64.

nknots

Returns the number of grid points in each spatial direction as a sequence.

total_knots

Returns the total number of grid knots needed.

grid_basis

Returns the edge lengths of one grid cell.

log(logger)

Output interpolation scheme to logger

Parameters:logger – instance of halmd.io.log.logger