How to keep u>0 when solving ODEs

I’m using Rodas3() to solve a stiff ODEs in Julia. du/dt = F(u). The Analytical expression of u should be positive. However, when I use julia to solve the ODE, u may be less equal 0. I suspect that the time step was too large.

I wonder if there is parameters. When solving ODE, if the u of a certain step size is less than 0, the step size will be recalculated by rolling it back.

Thany you!

isoutofdomain (Under the Miscellaneous heading) can do that, however it is often helpful to transform your problem using something like u⁺ = ln(u) and then whatever the value of u⁺, exp(u⁺) will be positive.

I’d recommend reading through Frequently Asked Questions · DifferentialEquations.jl?