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

python interface for Vec3d #92

Closed hannorein closed 1 year ago

hannorein commented 1 year ago

Don't merge this yet! I've been playing around to simplify the python syntax when working with vectors. The changes here are a bit of a hack, but they allow the user to set and get params that are 3-vectors in a nicer way:

Instead of

particles.params['sx']  = 1
particles.params['sy']  = 2
particles.params['sz']  = 3

This would allow you to do

particles.params['Vec3d_s']  = [1,2,3]

Similarly, getter returns a Vec3d:

v = particles.params['Vec3d_s']

No changes on the c side are necessary but one could implement the same hack there.

We've talked about this sort of thing many times before. So I'm probably ignoring a ton of side effects.

Can you remind me, what was the reason not to implement a three vector type as an option for a param?

Side note: Unfortunately numpy doesn't convert Vec3d to a sensible numpy array when using np.array(v), so it can't easily be used in assignments. I have narrowed down the issue, but can't seem to find a workaround. The getter could just return a python list instead of a Vec3d to fix that.

dtamayo commented 1 year ago

I think all the complications came from trying to allow for lists of arbitrary shapes. I don't think there's any problem at all with using vec_3d as a rebx_type, and I do think that would actually give a much nicer interface...

hannorein commented 1 year ago

That makes sense. I guess before we had spin, there was little reason to give priority to a 3 vector, over say, a 3x3 matrix. But now there might be an argument to be made to add Vec3d. Well, not urgent...

dtamayo commented 1 year ago

Too many things to work on, too little time! :) This would be nice to get in for this effect. I have an all day meeting tomorrow at AAS...this might be the perfect mindless work for parts of it that don't really apply to the DDA :)

hannorein commented 1 year ago

Do you want me to do it? I have one more day before teaching starts ;-)

dtamayo commented 1 year ago

No you’ve done a ton! I’m at AAS all week. I can do it

On Sat, Jan 7, 2023 at 11:48 AM Hanno Rein @.***> wrote:

Do you want me to do it? I have one more day before teaching starts ;-)

— Reply to this email directly, view it on GitHub https://github.com/dtamayo/reboundx/pull/92#issuecomment-1374589923, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2ABF2Y6I2O7PNJQP2VJHDWRHB7XANCNFSM6AAAAAATUBMVJM . You are receiving this because you commented.Message ID: @.***>

-- Daniel Tamayo Assistant Professor Harvey Mudd College Chair, AAS Division on Dynamical Astronomy Pronouns: he/him/él