amuse icon indicating copy to clipboard operation
amuse copied to clipboard

Making analytic potentials time dependent

Open eerovaher opened this issue 7 years ago • 8 comments

Is your feature request related to a problem? Please describe. The ability to create time dependent analytic potentials would be helpful for running N-body simulations, as it would allow to very easily implement potentials that rotate or decay in time.

Describe the solution you'd like The easiest solution seems to require the following changes

  1. In amuse/couple/bridge.py class GravityCodeInField the method kick_with_field_code() would need to be
    def kick_with_field_code(self, particles, field_code, dt):
        ax,ay,az=field_code.get_gravity_at_point(
            self._softening_lengths(particles),
            particles.x,
            particles.y,
            particles.z,
            self.time            # proposed addition
        )
        self.update_velocities(particles, dt, ax, ay, az)
  1. In amuse/ext/static_potentials.py class Abstract_Potential the method get_acceleration_at_point() should accept t with a default value such as t=0|units.s as an additional argument and pass it to the abstract method get_potential_at_point().

Describe alternatives you've considered Right now time dependent potentials can be implemented by changing the parameters of the analytic potential from the main script, but this needs to be done every time the potential is called. Implementing this proposal would allow to specify the time dependence when the potential is defined without having to explicitly demand that the potential gets properly updated every time it is needed.

Additional context If the analytic potential being implemented is not time dependent, then the implemented get_potential_at_point() method can simply ignore the additional time argument.

eerovaher avatar Oct 04 '18 15:10 eerovaher

the pattern we prefer for this is to construct the time dependent potential as a gravity code class with an evolve_model method. This evolve just changes the time variable (by changing the time parameter) of the model - conceptually the coupling between active particles and potential becomes like that between two dynamic codes that way..for an example see the examples/galaxie directory, where this is implemented for a timedependent potential of the milky way with bar and spiral arm patterns..

ipelupessy avatar Oct 04 '18 18:10 ipelupessy

Not a fix within AMUSE, but note that galpy now allows any analytical potential (including time-dependent ones) to be converted to an AMUSE format and used within the AMUSE framework:

https://galpy.readthedocs.io/en/v1.5.0/potential.html#new-in-v1-5-conversion-to-amuse-potentials

So if you can implement your use case using galpy potentials (or define your own, which is pretty easy, since you only need the Python implementation), this should do the trick here.

jobovy avatar Oct 29 '19 15:10 jobovy

Thanks @jobovy! That looks great!

rieder avatar Oct 29 '19 15:10 rieder

NEMO's potential descriptors are analytical and also allow a time-dependent component, but we separate rotation along the Z axis in a different way. Pattern speed is constant and passed to the inipotential() routine, whereas time is passed as an independent parameter to the actual potential() calculator. Example in the familiar Plummer sphere is here: https://github.com/teuben/nemo/blob/master/src/orbit/potential/data/plummer.c

teuben avatar Nov 06 '19 02:11 teuben

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 28 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Mar 04 '22 18:03 stale[bot]

i don't like a stale bot... that way you will loose sight of long standing but ignored issues. Of course after a few years your code looks in great shape, no issue left ;-)

teuben avatar Mar 04 '22 18:03 teuben

We can pin issues where needed :). And feature requests (if so labeled) won't get the 'stale' treatment.

rieder avatar Mar 04 '22 18:03 rieder

maybe I should request a pinbot then :)

teuben avatar Mar 04 '22 19:03 teuben