tudat-team / tudatpy

A Python platform to perform astrodynamics and space research.

Home Page:https://tudat-space.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unfriendly error message for bad custom thrust function

gaffarelj opened this issue · comments

If a custom_thrust_magnitude or custom_thrust_direction setting is used, but one of the custom functions that is input (e.g. thrust_magnitude_function or specific_impulse_function) returns void instead of a float, the following warning is raised:

  File "...", line 251, in ...
    dynamics_simulator = numerical_simulation.SingleArcSimulator(
RuntimeError: Unable to cast Python instance to C++ type (compile in debug mode for details)

This does not give any real clue that the function that was input is the culprit of the numerical simulation failing.
I would suggest to add a test to make sure that the functions input by the user correctly return a float, and raising a friendlier error if they do not, during the custom thrust setup (and not when running the simulation).

Actually, giving this a little more thought, this check should probably be carried during the propagation and not the setup, since the custom thrust functions most often depend on the environment/vehicle at a given time.

I think a check could be made to check the type of the value that is returned by the function, instead of assuming that it is always a double.

The error is being raised by PyBind11, so we would either need to catch the Runtime error, and raise a more detailed error or do the check - both alternatives can only work in a pure Python wrapper. The check as you suggested, is more appealing to me right now.

These wrappers can get quite messy, and haven't existed since an earlier version of tudatpy. There is an example in an old commit in the init file.

With the new thrust interfaces, this is now taken care of. All of the classes that are referred to no longer exist :)