“isoutofdomain
: Specifies a function isoutofdomain(u,p,t)
where, when it returns true, it will reject the timestep. Disabled by default.”
That is not really what I need — I don’t want the timestep to be rejected. Would there be any help in that? Won’t the next timestep just do the same thing? I could understand that a timestep perhaps should be rejected if there is some stochasticity involved, but my equation is deterministic, and I’d guess the solver would do the same the next time??
So a little bit more concrete, in my case, state u
(or x
or whatever) is a matrix, and I have a model with a first attempt similar to:
function model(du,u,p,t)
#... current attempt
u_ = constrain.(u)
du = f(u_)
end
where function constrain
does:
function constrain(u)
if u < 0
return 0
elseif u > 1
return 1
else
return u
end
end
But this doesn’t hinder the solution to drift out of the range [0,1]
.
So, what I look for is something like:
function model(du,u,p,t)
#... new attempt
du = f(u)
end
where I instead fix the problem via a solver modification.
Question: would the correct be to use a DiscreteCallback
with condition
and affect!
functions:
condition(u,t,integrator) = minimum(u) < 0 || maximum(u) > 1
affect!(integrator) = integrator.u = constrain.(integrator.u)
?