Skip to content

Commit

Permalink
Merge pull request #342 from CliMA/tr/fix-prob-remake
Browse files Browse the repository at this point in the history
Remake problem manually during multirate init
  • Loading branch information
charleskawczynski authored Dec 23, 2024
2 parents 0c57a2f + d2540eb commit 95e6109
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 95e6109

Please sign in to comment.