I’m trying to enforce positivity of my solution using the isoutofdomain solver option in the DifferentialEquations package, yet it seems that an error within my derivative function (which requires positivity at the time step) is still being thrown. I thought isoutofdomain should prevent this from occurring.
Here’s my setup:
rhs(m, par, t) = get_aerosol_growth_3mom(m, par, t, v_up) prob = ODEProblem(rhs, moments_S_init, tspan, ODE_parameters) sol = solve(prob, reltol = tol, abstol = tol, isoutofdomain = (m,p,t) -> any(x->x<0, m))
The derivative function “get_aerosol_growth_3mom(m, par, t, v_up)” throws an error and cannot proceed if any element of m is negative. When I run the script, this error is still being thrown (rather than being averted via isoutofdomain). Inserting some print statements for the arguments to the derivative function:
time: 0.0 prognostic moments: [100.0, 10825.08853082, 1.4756905287634078e6, 0.02] time: 3.5670907415192044e-6 prognostic moments: [100.0, 11008.214660723124, 1.4807861187372427e6, 0.02000000186343498] time: 0.0 prognostic moments: [100.0, 10825.08853082, 1.4756905287634078e6, 0.02] time: 1.7835453707596022e-6 prognostic moments: [100.0, 10916.651595771562, 1.4782383237503252e6, 0.020000000931717492] time: 3.884165474098689e-5 prognostic moments: [100.0, -14624.568385517678, 1.560013303242658e6, 0.02000002029073535] ERROR: LoadError: all moments need to be nonnegative.
So the second element is negative, despite the isoutofdomain option.
Can anyone see where I went wrong here? Thanks for the help.