dtamayo / reboundx

A library for adding additional forces to the REBOUND N-body integration package
GNU General Public License v3.0
80 stars 60 forks source link

rebx_calculate_energy #37

Closed hannorein closed 5 years ago

hannorein commented 5 years ago

There is a convenience function defined on the python side which is msising from c:

rebx.calculate_energy()

dtamayo commented 5 years ago

Thanks. I removed this in the new version, and have removed it from master for consistency for now. That function was a placeholder for a function meant to automatically calculate the energy based on what effects you've added, but I think requires too much logic and overhead when adding new effects for it to be worth it. At the same time it's probably a useful function. Would love some feedback.

It would need a parallel list of unique effects, forces and operators should have a calculate energy function pointer field. There's also a distinction not only between conservative and dissipative effects, but also between conservative position and velocity dependent ones, because the former just have additive contributions to the potential, but the velocity dependent ones also change the kinetic terms. I guess one could rewrite the velocity dependent energy routines to subtract off the classical energy to just give the updates at the cost of large roundoff errors, or rewrite the routines to only calculate the update (not totally trivial).

hannorein commented 5 years ago

I agree. I think keeping some of the functions that calculate the energy around for some of the simpler effects such as gr potential would be helpful so that one doesn't need to reimplement them every time. But without any logic.

dtamayo commented 5 years ago

I agree, thanks!