@@ -58,6 +58,16 @@ def __init__(self, pot=None, denspot=None, rmax=1e4, scale=None, ro=None, vo=Non
5858 )
5959 self ._potInf = _evaluatePotentials (pot , self ._rmax , 0 )
6060 self ._Emin = _evaluatePotentials (pot , 0.0 , 0 )
61+ # Current calculation of the boundary term uses r -> inf limit
62+ try :
63+ self ._rInf = (
64+ numpy .inf
65+ if numpy .isfinite (self ._dnudr (numpy .inf ))
66+ and numpy .isfinite (_evaluateRforces (self ._pot , numpy .inf , 0 ))
67+ else 1e12
68+ )
69+ except ZeroDivisionError :
70+ self ._rInf = 1e12
6171 # Build interpolator r(pot)
6272 self ._rphi = self ._setup_rphi_interpolator ()
6373
@@ -129,6 +139,18 @@ def fE(self, E):
129139 for tE in Eint [indx ]
130140 ]
131141 )
142+ # Add boundary term ~ 1 / sqrt(-E) dnu / dpsi | psi=0
143+ boundary_term = numpy .zeros_like (Eint )
144+ boundary_term [indx ] = (
145+ self ._dnudr (self ._rInf )
146+ / _evaluateRforces (self ._pot , self ._rInf , 0 )
147+ / numpy .sqrt (- Eint [indx ])
148+ )
149+ # For some potentials, such as PowerSphericalPotential with infinite mass,
150+ # the boundary term as implemented is incorrect, but we'll just set it to zero,
151+ # because it essentially is
152+ boundary_term [~ numpy .isfinite (boundary_term )] = 0.0
153+ out -= boundary_term
132154 return - out / (numpy .sqrt (8.0 ) * numpy .pi ** 2.0 )
133155
134156
0 commit comments