hannorein / rebound

💫 An open-source multi-purpose N-body code.
https://rebound.readthedocs.io/
GNU General Public License v3.0
860 stars 220 forks source link

Unit conversion doesn't apply to particles radii #799

Closed alelatt closed 4 days ago

alelatt commented 2 weeks ago

Environment Which version of REBOUND are you using and on what operating system?

Hi all,

I've noticed that the function "convert_particle_units" doesn't apply changes to the length unit to the particles radii. If I understand correctly the function "units_convert_particle", called by "convert_particle_units", doesn't seem to convert the particles radii. Could you confirm if this is the case?

To reproduce:

sim = rebound.Simulation()
sim.units = ('AU', 'Mearth', 'yr')
sim.add(m = 333030, r = 0.00465047)
sim.add(m = 1, r = 4.26352e-5, a = 1)
print(sim.units)
print(sim.particles[0].r, sim.particles[1].r)
sim.convert_particle_units('km', 'Mearth', 'yr')
print(sim.units)
print(sim.particles[0].r, sim.particles[1].r)

with output

{'length': 'au', 'mass': 'mearth', 'time': 'yr'}
0.00465047 4.26352e-05
{'length': 'km', 'mass': 'mearth', 'time': 'yr'}
0.00465047 4.26352e-05

Thank you very much, Alessandro

hannorein commented 2 weeks ago

Yes. It does not convert the particle radii. I need to think about whether it makes sense to convert the radii as well. There are many other length scales in different variables that do not get converted either (box size, softening length, etc).

alelatt commented 2 weeks ago

Thank you very much! For the time being I'll change my code accordingly. Feel free to close this issue if you want, I'll leave it up.