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

New vec3d class #97

Closed hannorein closed 1 year ago

hannorein commented 1 year ago

This is related to what I tried on hannorein/rebound/new_reb3d.

I don't think we will be able to find a workaround for the stupid numpy issue that prevents us from doing numpy_array[1] = vec3d. At the very best we might hope for a fix in a new version, but whatever we do needs to be compatible for old numpy versions for many years.

In hannorein/rebound/new_reb3d, I simply created a new wrapper class Vec3d which is not a subclass of ctypes.structure. This way I can implement __array_interface__. The new Vec3d class has an attribute which of type _Vec3d - an internal class that is a subclass of ctypes.Structure.

From a user point of view this doesn't change anything. But it does add one extra stumbling block when writing code that accesses the c library. Those functions need the _Vec3d object, not the Vec3d one.

Have a look at the code an tell me what you think.