Skip to content

Commit

Permalink
Define cts_remake to remake ODEProblem manually
Browse files Browse the repository at this point in the history
SciMLBase changed the way remake(::AbstractODEProblem,...) works in
2.68.0. Previously, if the `f` kwarg was an AbstractODEFunction,
the problem was remade with f directly as its function. After 2.68.0,
remake(::AbstractODEProblem) calls a new remake method with
`f` and `prob.f` as arguments. This new function returns an
AbstarctSciMLFunction of the same type and properties as `prob.f`.

This commit replicates the behavior of DiffEqBase.remake on the provided
arguments before the change.
  • Loading branch information
imreddyTeja committed Dec 23, 2024
1 parent 0c57a2f commit d2540eb
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/solvers/multirate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,32 @@ struct MultirateCache{OC, II}
innerinteg::II
end

"""
cts_remake(prob::DiffEqBase.AbstractODEProblem; f::DiffEqBase.AbstractODEFunction)
Remake an ODE problem with a new function `f`.
"""
function cts_remake(prob::DiffEqBase.AbstractODEProblem; f::DiffEqBase.AbstractODEFunction)
return DiffEqBase.ODEProblem{DiffEqBase.isinplace(prob)}(
f,
prob.u0,
prob.tspan,
prob.p,
prob.problem_type;
prob.kwargs...,
)
end

function init_cache(prob::DiffEqBase.AbstractODEProblem, alg::Multirate; dt, fast_dt, kwargs...)

@assert prob.f isa DiffEqBase.SplitFunction

# subproblems
outerprob = DiffEqBase.remake(prob; f = prob.f.f2)
outerprob = cts_remake(prob; f = prob.f.f1)
outercache = init_cache(outerprob, alg.slow)

innerfun = init_inner(prob, outercache, dt)
innerprob = DiffEqBase.remake(prob; f = innerfun)
innerprob = cts_remake(prob; f = innerfun)
innerinteg = DiffEqBase.init(innerprob, alg.fast; dt = fast_dt, kwargs...)
return MultirateCache(outercache, innerinteg)
end
Expand Down

0 comments on commit d2540eb

Please sign in to comment.