|
| 1 | +# Remake the nonlinear problem, then update |
| 2 | +function perform_step!(integrator, cache::IDSolveCache, repeat_step = false) |
| 3 | + @unpack alg, u, uprev, dt, t, f, p = integrator |
| 4 | + nlsolve = alg.nlsolve |
| 5 | + @unpack state, prob = cache |
| 6 | + state.u .= uprev |
| 7 | + state.t_next = t |
| 8 | + @show state |
| 9 | + prob = remake(prob, p = state) |
1 | 10 |
|
2 | | -# make a nonlinear problem and solve at every timestep. |
| 11 | + u = solve(prob, nlsolve) |
| 12 | + any(isnan, u) && (integrator.sol.retcode = SciMLBase.ReturnCode.Failure) |
| 13 | + integrator.u = u |
| 14 | +end |
| 15 | + |
| 16 | +function initialize!(integrator, cache::IDSolveCache) |
| 17 | + cache.state.u .= integrator.u |
| 18 | + cache.state.p .= integrator.p |
| 19 | + cache.state.t_next = integrator.t |
| 20 | + f = integrator.f |
3 | 21 |
|
4 | | -function CommonSolve.solve(prob::ImplicitDiscreteProblem) |
5 | | - |
| 22 | + _f = if isinplace(f) |
| 23 | + (resid, u_next, p) -> f(resid, u_next, p.u, p.p, p.t_next) |
| 24 | + else |
| 25 | + (u_next, p) -> f(u_next, p.u, p.p, p.t_next) |
| 26 | + end |
| 27 | + |
| 28 | + prob = if isinplace(f) |
| 29 | + NonlinearProblem{true}(_f, cache.state.u, cache.state) |
| 30 | + else |
| 31 | + NonlinearProblem{false}(_f, cache.state.u, cache.state) |
| 32 | + end |
| 33 | + cache.prob = prob |
6 | 34 | end |
| 35 | + |
| 36 | +#### unnecessary |
| 37 | +#function DiffEqBase.__init(prob::ImplicitDiscreteProblem, alg) |
| 38 | +# f = prob.f |
| 39 | +# t_i = prob.tspan[1] |
| 40 | +# u0 = state_values(prob) |
| 41 | +# p = parameter_values(prob) |
| 42 | +# |
| 43 | +# _f(resid, u_next, p) = f(resid, u_next, p.u, p.p, p.t) |
| 44 | +# state = ImplicitDiscreteState(u0, p, t_i) |
| 45 | +# nlprob = NonlinearProblem(_f, u0, state) |
| 46 | +#end |
0 commit comments