Skip to content

Allow users to flag a time step (x values) as invalid within the derivative function#44

Open
mind-bending-forks wants to merge 5 commits into
jacobwilliams:masterfrom
mind-bending-forks:flag-invalid
Open

Allow users to flag a time step (x values) as invalid within the derivative function#44
mind-bending-forks wants to merge 5 commits into
jacobwilliams:masterfrom
mind-bending-forks:flag-invalid

Conversation

@mind-bending-forks
Copy link
Copy Markdown

@mind-bending-forks mind-bending-forks commented Apr 21, 2026

See #43

Maybe something like this could work?

I've introduced a user-callable flag_invalid() function to rk_class. It can be called from within the derivative function, following the way stop() is implemented. This approach doesn't break existing code usage of the library. Behaviour should only be changed if the user introduced and calls the new flag_invalid() function. (Existing tests run and pass.)

For fixed timestep methods, calling flag_invalid() will throw an exception, since nothing can be done about it.

For variable timestep methods with variable step, it will result in the timestep being halved and the step retried. Existing limits on the smallest stepsize and on the maximum number of retries apply.

I've only added handling of the new private invalid parameter with rk_class after step() has been called.

The private stopped parameter of rk_class also has handling after calls to root_scalar() and solver_func(). I don't understand the code sufficiently to know whether handling of invalid is needed in those cases too. I have assumed not. If you know otherwise, then this pull request might need some additional work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant