hannorein / rebound

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

A wrong variable name in the documentation #757

Closed ruochengzhai closed 3 months ago

ruochengzhai commented 3 months ago

Dear developers, I found the "enum REB_STATUS status" in the "Variables" section might be wrong. "status" is the name of a function, while "_status" is the variable name in the source code.

Besides, perhaps it will be helpful to introduce more about the values of this variable and the errors it can raise in the documentation. Thanks.

hannorein commented 3 months ago

Thanks for opening an issue. I believe you are talking about python versus C variables. The variable is called _status in python because it should not be accessed directly. REBOUND's python API makes use of exception and therefore a user doesn't need the status variable. There is a status() function in python giving some status information, but not in C. Wheres maybe not ideally named, I don't think there is a bug or type. Maybe a note in the documentation would help!

ruochengzhai commented 3 months ago

Thank you so much for your reply. I'm curious if it is designed to be able to raise exceptions in the customized collision_solve function in Python, which seems to cause some errors. This is why I am using _status.

hannorein commented 3 months ago

If you want to raise a python exception from within the collision resolve function, you can set r->status=REB_STATUS_COLLISION in the collision resolve function. See for example: https://github.com/hannorein/rebound/blob/main/src/collision.c#L725

ruochengzhai commented 3 months ago

Now I am using Python only so I try to use a custom function like the example in https://rebound.readthedocs.io/en/latest/collisions/#__tabbed_9_2. In this case, I find it is a must to access _status to raise an exception. Is this true? Thank you!

hannorein commented 3 months ago

That's correct. That's a python limitation. You can't raise an exception in a function that gets called via a c function. And REBOUND is using C internally because of speed.

ruochengzhai commented 3 months ago

I got it. I appreciate your answering my questions!