Coverage for gamdpy/interactions/potential_functions/make_IPL_n.py: 100%
6 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
1import numpy as np
2import numba
3import math
4from numba import cuda
6def make_IPL_n(n: float, first_parameter:int = 0) -> callable:
7 """ Inverse Power Law Potential
9 .. math::
11 u(r) = A_n r^{-n}
13 Parameters
14 ----------
16 n : float
17 Exponent in the potential
18 first_parameter : int
19 The index of the first parameter in the list of parameters. See usage in :func:`gamdpy.add_potential_functions`.
21 Returns
22 -------
24 potential_function : callable
25 A function that calculates the IPL potential,
26 u, s, umm = potential_function(dist, params).
27 where params = [A_n]
28 """
30 def IPL_n(dist, params): # pragma: no cover
31 # U(r) = An*r**-n
32 # Um(r) = n*An*r**-(n+1)
33 # s = -Um/r = n*An*r**-(n+2), Fx = s*dx
34 An = params[first_parameter]
35 invDist = numba.float32(1.0) / dist
37 u = An * invDist ** n
38 s = numba.float32(n) * An * invDist ** (n + 2)
39 umm = numba.float32(n * (n + 1)) * An * invDist ** (n + 2)
40 return u, s, umm # U(r), s == -U'(r)/r, U''(r)
42 return IPL_n