gala icon indicating copy to clipboard operation
gala copied to clipboard

Add a way for spherical potentials to be called with just radius

Open adrn opened this issue 9 years ago • 5 comments

Should internally promote to a (3,n) array

adrn avatar Apr 08 '16 02:04 adrn

Brainstorming API.

User-facing (spherical):

pot = HernquistPotential(...) # knows internally that it has spherical symmetry

r = np.logspace(-1, 1, 128)
xyz = np.zeros((3,r.size))
xyz[0] = r

# as positional argument, requires cartesian:
pot.value(xyz) 

# as kwarg, takes just a radius
pot.value(r=r)

User-facing (cylindrical):

R = np.linspace(4, 12, 128)
z = np.random.normal(0, 0.1, size=R.size)
xyz = np.zeros((3,R.size))
xyz[0] = R
xyz[2] = z

pot = MiyamotoNagaiPotential(...) # knows internally that it has cylindrical symmetry
pot.value(xyz) 
pot.value(R=R, z=z) 

What does the API look like for defining potential classes? Maybe:

class SomeNewPotential(PotentialBase):

    def __init__(self, a, units=None):
        parameters = OrderedDict()
        parameters['a'] = a
        super(SomeNewPotential, self).__init__(units=units,
                                                                         parameters=parameters,
                                                                         symmetry='spherical')

But really, define symmetry classes that define mappings between partial coordinates and cartesian. So, for example, SphericalSymmetry would map r to x or something:

  • Spherical symmetry = no phi, theta dependence
  • Cylindrical symmetry = no phi dependence

Might need to add a dimensionality mix-in class -- most are inherently 3D, but others (e.g., HarmonicOscillator) can be ND

adrn avatar Jul 18 '16 02:07 adrn

But then how is the gradient returned? In the input coordinates or?

adrn avatar Jul 18 '16 17:07 adrn

Yes! dΦ/dr <--> dΦ/dx and dΦ/dR <--> dΦ/dx

adrn avatar Jul 18 '16 17:07 adrn

One path to this:

  • Define new Symmetry objects that know how to transform from input to a 3D cartesian coordinate. For example, a single r array --> xyz with xyz[0]=r.

adrn avatar Dec 13 '16 04:12 adrn

https://gist.github.com/adrn/29c82f19f34e4a5cff086ff43764f13e

adrn avatar May 07 '19 19:05 adrn