Source code for py_core.kinetic_term

from numba import njit

[docs] @njit(boundscheck=True, fastmath=True) def fdiff_kinetic_improved(x, i, dt, m=1.0): r"""Computes the improved finite differences second time derivative times dt for x[i]. This term has O(dt^4) error, however it generates a ghost mode. Explicitly, the term is given by: :math:`\frac{1}{2} m x_{i}\left(\Delta^{(2)} - \frac{dt^2}{12}\left(\Delta^{(2)}\right)^2\right)x_{i} dt` Parameters ---------- x : ndarray current path i : int lattice site index dt : float time step m : float, optional mass of the particle. Defaults to 1.0. Returns ------- float The improved finite differences second time derivative times dt for x[i]. """ i1 = (i + 1) % x.size # PBC i2 = (i + 2) % x.size # PBC return ( -0.5 * m * ( # First the x[i] term, all contributions are included due to x[i] multiplying x[i] * ( x[i1] - 2 * x[i] + x[i - 1] - (x[i2] + x[i - 2] - 4 * x[i1] - 4 * x[i - 1] + 6 * x[i]) / 12 ) + # Now we must add all other contributions with corrections (i+1,i+2,i-1,i-2) x[i] * (16 * (x[i1] + x[i - 1]) - x[i2] - x[i - 2]) / 12 ) / dt )
# To remove ghosts, we perform the change of variables, # we must then rewrite the potential and the kinetic term
[docs] @njit(boundscheck=True, fastmath=True) def fdiff_kinetic_imp(x, i, dt, m=1.0): r"""Computes the improved kinetic term for x[i] after the change of variables used to remove the ghost mode. Explicitly, the term is given by: :math:`- m \frac{1}{2}x_{i} \Delta^{(2)} x_{i} dt` Parameters ---------- x : ndarray current path i : int lattice site index dt : float time step m : float, optional mass of the particle. Defaults to 1.0. Returns ------- float The improved kinetic term for x[i]. """ i1 = (i + 1) % x.size return -m * (x[i] * (x[i1] - x[i] + x[i - 1])) / dt
[docs] @njit(fastmath=True) def V_imp(x, dt, m=1.0, omega=1.0): r"""Computes the improved potential term for x after the change of variables used to remove the ghost mode. Explicitly, the term is given by: :math:`\frac{1}{2} m (\omega x)^2 \left(1 + \frac{dt^2 \omega^2}{12}\right)` Parameters ---------- x : float Current path value. dt : float Time step. m : float, optional Mass of the particle. Defaults to 1.0. omega : float, optional Angular frequency. Defaults to 1.0. Returns ------- float The improved potential term for x. """ return 0.5 * m * ((omega * x) ** 2) * (1 + ((dt * omega) ** 2) / 12)