GalacticDynamics-Oxford / Agama

Action-based galaxy modeling framework
Other
72 stars 35 forks source link

Logarithmic potential does support ActionFinder #5

Closed syrte closed 3 years ago

syrte commented 4 years ago

Hi Eugene,

Hope you are doing well!

I'm exploring the functionalities of actions in Agama. Runing the following code,

import agama
pot = agama.Potential(type='Logarithmic', scaleRadius=1, v0=1)
af = agama.ActionFinder(pot, interp=False)

I got such error,

ValueError: Error in ActionFinder initialization: Interpolator: can only work with potentials that tend to zero as r->infinity

I guess I can understand the interpolation won't work for infinitely deep potential like Logarithmic, since it is hard to define an appropriate interpolation table. However, I'm a bit surprised, because, naively, I thought we only need interpolation when interp=True is specified. Is this behavior expected? Thanks.

Best regards,

Zhaozhou

eugvas commented 4 years ago

The Logarithmic potential is peculiar not because it may have a singularity at origin, but rather because it doesn't tend to zero at large radii -- an assumption built into many of the routines in the library, including those of action finders. These construct various internal interpolation tables even if you don't use interpolated actions (e.g., for the focal distance and circular angular momentum), and don't work if Phi(infinity)!=0. However, one may construct an equivalent potential with a cutoff at large radii by a combination of two spheroids:

r0 = 7.0
v0 = 11.0
rcut = r0*1000
pot_log = agama.Potential(type='Logarithmic', scaleradius=r0, v0=v0)
pot_sph = agama.Potential(
    dict(type='Spheroid', gamma=0, beta=2, alpha=2, scaleradius=r0, densitynorm=3*(v0/r0)**2/4/numpy.pi, outercutoffradius=rcut), 
    dict(type='spheroid', gamma=-2, beta=2, alpha=2, scaleradius=r0, densitynorm=-2*(v0/r0)**2/4/numpy.pi, outercutoffradius=rcut) )

The two potentials have the same density profile for r<<rcut, but the second one is then exponentially cut off beyond rcut, and the potential properly tends to zero at r-->infinity. One cannot recreate a singular logarithmic potential with this trick, but I guess adding a very small core radius is an acceptable workaround.

syrte commented 4 years ago

Thanks for the quick response. Wow, it is really a nice trick!