gala
gala copied to clipboard
Add a way for spherical potentials to be called with just radius
Should internally promote to a (3,n) array
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
But then how is the gradient returned? In the input coordinates or?
Yes! dΦ/dr <--> dΦ/dx and dΦ/dR <--> dΦ/dx
One path to this:
- Define new
Symmetryobjects that know how to transform from input to a 3D cartesian coordinate. For example, a singlerarray -->xyzwithxyz[0]=r.
https://gist.github.com/adrn/29c82f19f34e4a5cff086ff43764f13e