amusecode / amuse

Astrophysical Multipurpose Software Environment. This is the main repository for AMUSE
http://www.amusecode.org
Apache License 2.0
159 stars 101 forks source link

Making analytic potentials time dependent #318

Open eerovaher opened 6 years ago

eerovaher commented 6 years ago

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)

2) 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.

ipelupessy commented 6 years ago

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..

jobovy commented 5 years ago

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.

rieder commented 5 years ago

Thanks @jobovy! That looks great!

teuben commented 5 years ago

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

stale[bot] commented 2 years ago

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.

teuben commented 2 years ago

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 ;-)

rieder commented 2 years ago

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

teuben commented 2 years ago

maybe I should request a pinbot then :)